2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * mlib_ImageColorTrue2Index - convert a true color image to an indexed 0N/A * mlib_status mlib_ImageColorTrue2Index(mlib_image *dst, 0N/A * const mlib_image *src, 0N/A * const void *colormap) 0N/A * colormap Internal data structure for inverse color mapping. 0N/A * dst Pointer to destination image. 0N/A * src Pointer to source image. 0N/A * Convert a true color image to a pseudo color image with the method 0N/A * of finding the nearest matched lut entry for each pixel. 0N/A * The src can be an MLIB_BYTE or MLIB_SHORT image with 3 or 4 channels. 0N/A * The dst must be a 1-channel MLIB_BYTE or MLIB_SHORT image. 0N/A * The lut might have either 3 or 4 channels. The type of the lut can be 0N/A * one of the following: 0N/A * MLIB_BYTE in, MLIB_BYTE out (i.e., BYTE-to-BYTE) 0N/A * MLIB_BYTE in, MLIB_SHORT out (i.e., BYTE-to-SHORT) 0N/A * MLIB_SHORT in, MLIB_SHORT out (i.e., SHORT-to-SHORT) 0N/A * MLIB_SHORT in, MLIB_BYTE out (i.e., SHORT-to-BYTE) 0N/A * The src image and the lut must have same number of channels. 0N/A/***************************************************************/ 0N/A/*#define USE_VIS_CODE*/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A case 8:
/* will never be called */ \
0N/A/***************************************************************/ 0N/A /* Other cases may not be considered as the table size will be more \ 0N/A/***************************************************************/ 0N/A /* Other cases may not be considered as the table size will be more \ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A /* Check only a part of quadrant */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Only a part of quadrant needs checking */ \
0N/A else /* Check whole quadrant */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Here is a full node. Just explore it */ \
0N/A else /* Cell is on the edge of the space */ \
0N/A /* Check only a part of quadrant */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Only a part of quadrant needs checking */ \
0N/A else /* Check whole quadrant */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Here is a full node. Just explore it */ \
0N/A/***************************************************************/ 0N/A /* Check only a part of quadrant */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Only a part of quadrant needs checking */ \
0N/A else /* Check whole quadrant */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Here is a full node. Just explore it */ \
0N/A else /* Cell is on the edge of the space */ \
0N/A /* Check only a part of quadrant */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Only a part of quadrant needs checking */ \
0N/A else /* Check whole quadrant */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Here is a full node. Just explore it */ \
0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Only a part of quadrant needs checking */ \
0N/A else /* Check whole quadrant */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Here is a full node. Just explore it */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Only a part of quadrant needs checking */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Here is a full node. Just explore it */ \
0N/A/***************************************************************/ 0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Only a part of quadrant needs checking */ \
0N/A else /* Check whole quadrant */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Here is a full node. Just explore it */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Only a part of quadrant needs checking */ \
0N/A /* Here is another color cell. \ 0N/A Check the distance */ \
0N/A /* Here is a full node. Just explore it */ \
0N/A/***************************************************************/ 0N/A /* Here is another color cell. Check the distance */ \
0N/A /* Here is a full node. Just explore it all */ \
0N/A c[ 0 ], c[
1 ], c[
2 ], p ); \
0N/A/* Else there is just an empty cell */ \
0N/A/***************************************************************/ 0N/A /* Here is another color cell. Check the distance */ \
0N/A /* Here is a full node. Just explore it all */ \
0N/A c[ 0 ], c[
1 ], c[
2 ], p ); \
0N/A/* Else there is just an empty cell */ \
0N/A/***************************************************************/ 0N/A /* Stack pointer pointers to the first free element of stack. */ \
0N/A /* The node we are in is in the `node' */ \
0N/A ( ( ( c[
1 ] <<
1 ) >>
pass ) &
2 ) | \
0N/A ( ( ( c[
2 ] <<
2 ) >>
pass ) &
4 ); \
0N/A Here is a cell with one color. We need to be sure it's \ 0N/A the one that is the closest to our color \ 0N/A /* Oh, here it is :) */ \
0N/A /* First index is the channel, second is the number of the \ 0N/A Neibours are enumerated in a cicle: \ 0N/A 0 - between quadrants 0 and 1, \ 0N/A 1 - between quadrants 1 and 2 and \ 0N/A 2 - between quadrants 2 and 0 \ 0N/A Others are three two neibour quadrants \ 0N/A Side number is [ <number of the coordinate >][ <the bit \ 0N/A in the quadrant number of the corner, corresponding to \ 0N/A this coordinate> ], e.g. 2 is 0..010b, so the sides it has \ 0N/A [ 0 (coordinate number) ][ 0 (bit 0 in the number) ] \ 0N/A [ 1 (coordinate number) ][ 1 (bit 1 in the number) ] \ 0N/A Now we can look in the three nearest quadrants. Do \ 0N/A we really need it ? Check it. \ 0N/A /* Descend one level */ \
0N/A /* Found the empty quadrant. Look around */ \
0N/A As we had come to this level, it is warranted that there \ 0N/A are other points on this level near the empty quadrant \ 0N/A/***************************************************************/ 0N/A /* Here is another color cell. Check the distance */ \
0N/A /* Here is a full node. Just explore it all */ \
0N/A c[ 0 ], c[
1 ], c[
2 ], c[
3 ], p ); \
0N/A/* Else there is just an empty cell */ \
0N/A/***************************************************************/ 0N/A /* Here is another color cell. Check the distance */ \
0N/A /* Here is a full node. Just explore it all */ \
0N/A c[ 0 ], c[
1 ], c[
2 ], c[
3 ], p ); \
0N/A/* Else there is just an empty cell */ \
0N/A/***************************************************************/ 0N/A /* Stack pointer pointers to the first free element of stack. */ \
0N/A /* The node we are in is in the `node' */ \
0N/A ( ( ( c[
1 ] <<
1 ) >>
pass ) &
2 ) | \
0N/A ( ( ( c[
2 ] <<
2 ) >>
pass ) &
4 ) | \
0N/A ( ( ( c[
3 ] <<
3 ) >>
pass ) &
8 ); \
0N/A Here is a cell with one color. We need to be sure it's \ 0N/A the one that is the closest to our color \ 0N/A /* Oh, here it is :) */ \
0N/A /* First index is the channel, second is the number of the \ 0N/A Check neibours: quadrants that are different by 2 bits \ 0N/A from the quadrant, that we are in: \ 0N/A Far quadrants: different by 3 bits: \ 0N/A /* Descend one level */ \
0N/A /* Found the empty quadrant. Look around */ \
0N/A As we had come to this level, it is warranted that there \ 0N/A are other points on this level near the empty quadrant \ 0N/A Check neibours: quadrants that are different by 2 bits \ 0N/A from the quadrant, that we are in: \ 0N/A Far quadrants: different by 3 bits: \ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 3813N/A /* Unsupported type of destination image */ 3813N/A /* Unsupported type of destination image */ 0N/A/***************************************************************/ 0N/A for (i = 0; i <
8; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A/***************************************************************/ 0N/A/* Search only quadrant's half untill it is necessary to check the 0N/A for (i = 0; i <
4; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A else {
/* Search whole quadrant */ 0N/A for (i = 0; i <
8; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A /* This quadrant may require partial checking */ 0N/A /* Here we should check all */ 0N/A/***************************************************************/ 0N/A/* Search only quadrant's half untill it is necessary to check the 0N/A for (i = 0; i <
4; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A else {
/* Search whole quadrant */ 0N/A for (i = 0; i <
8; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A /* Here we should check all */ 0N/A /* This quadrant may require partial checking */ 0N/A/***************************************************************/ 0N/A for (i = 0; i <
8; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A/***************************************************************/ 0N/A/* Search only quadrant's half untill it is necessary to check the 0N/A for (i = 0; i <
4; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A else {
/* Search whole quadrant */ 0N/A for (i = 0; i <
8; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A /* This quadrant may require partial checking */ 0N/A /* Here we should check all */ 0N/A/***************************************************************/ 0N/A/* Search only quadrant's half untill it is necessary to check the 0N/A for (i = 0; i <
4; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A else {
/* Search whole quadrant */ 0N/A for (i = 0; i <
8; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A /* Here we should check all */ 0N/A /* This quadrant may require partial checking */ 0N/A/***************************************************************/ 0N/A for (i = 0; i <
16; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A/***************************************************************/ 0N/A {0,
2,
4,
6,
8,
10,
12,
14},
0N/A {0,
1,
4,
5,
8,
9,
12,
13},
0N/A {0,
1,
2,
3,
8,
9,
10,
11},
0N/A {0,
1,
2,
3,
4,
5,
6,
7}
0N/A/* Search only quadrant's half untill it is necessary to check the 0N/A for (i = 0; i <
8; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A else {
/* Search whole quadrant */ 0N/A for (i = 0; i <
16; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A /* This quadrant may require partial checking */ 0N/A /* Here we should check all */ 0N/A/***************************************************************/ 0N/A {
1,
3,
5,
7,
9,
11,
13,
15},
0N/A {
2,
3,
6,
7,
10,
11,
14,
15},
0N/A {
4,
5,
6,
7,
12,
13,
14,
15},
0N/A {
8,
9,
10,
11,
12,
13,
14,
15}
0N/A/* Search only quadrant's half untill it is necessary to check the 0N/A for (i = 0; i <
8; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A else {
/* Search whole quadrant */ 0N/A for (i = 0; i <
16; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A /* Here we should check all */ 0N/A /* This quadrant may require partial checking */ 0N/A/***************************************************************/ 0N/A for (i = 0; i <
16; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A/***************************************************************/ 0N/A {0,
2,
4,
6,
8,
10,
12,
14},
0N/A {0,
1,
4,
5,
8,
9,
12,
13},
0N/A {0,
1,
2,
3,
8,
9,
10,
11},
0N/A {0,
1,
2,
3,
4,
5,
6,
7}
0N/A/* Search only quadrant's half untill it is necessary to check the 0N/A for (i = 0; i <
8; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A else {
/* Search whole quadrant */ 0N/A for (i = 0; i <
16; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A /* This quadrant may require partial checking */ 0N/A /* Here we should check all */ 0N/A/***************************************************************/ 0N/A {
1,
3,
5,
7,
9,
11,
13,
15},
0N/A {
2,
3,
6,
7,
10,
11,
14,
15},
0N/A {
4,
5,
6,
7,
12,
13,
14,
15},
0N/A {
8,
9,
10,
11,
12,
13,
14,
15}
0N/A/* Search only quadrant's half untill it is necessary to check the 0N/A for (i = 0; i <
8; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A else {
/* Search whole quadrant */ 0N/A for (i = 0; i <
16; i++) {
0N/A /* Here is alone color cell. Check the distance */ 0N/A /* Here we should check all */ 0N/A /* This quadrant may require partial checking */ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A#
endif /* LUT_BYTE_COLORS_3CHANNELS <= 256 */ 0N/A/***************************************************************/ 0N/A#
endif /* LUT_BYTE_COLORS_3CHANNELS <= 256 */ 0N/A/***************************************************************/ 0N/A#
endif /* LUT_BYTE_COLORS_4CHANNELS <= 256 */ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A#
endif /* LUT_SHORT_COLORS_3CHANNELS <= 256 */ 0N/A/***************************************************************/ 0N/A#
endif /* LUT_SHORT_COLORS_3CHANNELS <= 256 */ 0N/A/***************************************************************/ 0N/A#
endif /* LUT_SHORT_COLORS_4CHANNELS <= 256 */ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/ 0N/A/***************************************************************/