1 /*
   2  * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 #ifndef __MLIB_IMAGECOLORMAP_H
  28 #define __MLIB_IMAGECOLORMAP_H
  29 
  30 #ifdef __cplusplus
  31 extern "C" {
  32 #endif /* __cplusplus */
  33 
  34 typedef struct {
  35   void **lut;
  36   mlib_s32 channels;
  37   mlib_type intype;
  38   mlib_s32 offset;
  39   void *table;
  40   mlib_s32 bits;
  41   mlib_s32 method;
  42   mlib_s32 lutlength;
  43   mlib_s32 indexsize;
  44   mlib_type outtype;
  45   void *normal_table;
  46   mlib_d64 *double_lut;
  47 } mlib_colormap;
  48 
  49 /***************************************************************/
  50 #define LUT_COLOR_CUBE_SEARCH  0
  51 #define LUT_BINARY_TREE_SEARCH 1
  52 #define LUT_STUPID_SEARCH      2
  53 #define LUT_COLOR_DIMENSIONS   3
  54 
  55 /***************************************************************/
  56 
  57 /* Bit set in the tag denotes that the corresponding quadrant is a
  58    palette index, not node. If the bit is clear, this means that that
  59    is a pointer to the down level node. If the bit is clear and the
  60    corresponding quadrant is NULL, then there is no way down there and
  61    this quadrant is clear. */
  62 
  63 struct lut_node_3 {
  64   mlib_u8 tag;
  65   union {
  66     struct lut_node_3 *quadrants[8];
  67     long index[8];
  68   } contents;
  69 };
  70 
  71 struct lut_node_4 {
  72   mlib_u16 tag;
  73   union {
  74     struct lut_node_4 *quadrants[16];
  75     long index[16];
  76   } contents;
  77 };
  78 
  79 /***************************************************************/
  80 
  81 #define mlib_ImageGetLutData(colormap)                          \
  82   ((void **)((( mlib_colormap *)( colormap))->lut))
  83 
  84 /***************************************************************/
  85 #define mlib_ImageGetLutNormalTable(colormap)                   \
  86   ((void *)((( mlib_colormap *)( colormap))->normal_table))
  87 
  88 /***************************************************************/
  89 #define mlib_ImageGetLutInversTable(colormap)                   \
  90   ((void *)((( mlib_colormap *)( colormap))->table))
  91 
  92 /***************************************************************/
  93 #define mlib_ImageGetLutChannels(colormap)                      \
  94   ((mlib_s32)((( mlib_colormap *)( colormap))->channels))
  95 
  96 /***************************************************************/
  97 #define mlib_ImageGetLutType(colormap)                          \
  98   ((mlib_type)((( mlib_colormap *)( colormap))->intype))
  99 
 100 /***************************************************************/
 101 #define mlib_ImageGetIndexSize(colormap)                        \
 102   ((mlib_s32)((( mlib_colormap *)( colormap))->indexsize))
 103 
 104 /***************************************************************/
 105 #define mlib_ImageGetOutType(colormap)                          \
 106   ((mlib_type)((( mlib_colormap *)( colormap))->outtype))
 107 
 108 /***************************************************************/
 109 #define mlib_ImageGetLutOffset(colormap)                        \
 110   ((mlib_s32)((( mlib_colormap *)( colormap))->offset))
 111 
 112 /***************************************************************/
 113 #define mlib_ImageGetBits(colormap)                             \
 114   ((mlib_s32)((( mlib_colormap *)( colormap))->bits))
 115 
 116 /***************************************************************/
 117 #define mlib_ImageGetMethod(colormap)                           \
 118   ((mlib_s32)((( mlib_colormap *)( colormap))->method))
 119 
 120 /***************************************************************/
 121 #define mlib_ImageGetLutDoubleData(colormap)                    \
 122   ((mlib_d64 *)((( mlib_colormap *)( colormap))->double_lut))
 123 
 124 /***************************************************************/
 125 #define FIND_DISTANCE_3( x1, x2, y1, y2, z1, z2, SHIFT )        \
 126  (( ( ( ( x1 ) - ( x2 ) ) * ( ( x1 ) - ( x2 ) ) ) >> SHIFT ) +  \
 127   ( ( ( ( y1 ) - ( y2 ) ) * ( ( y1 ) - ( y2 ) ) ) >> SHIFT ) +  \
 128   ( ( ( ( z1 ) - ( z2 ) ) * ( ( z1 ) - ( z2 ) ) ) >> SHIFT ) )
 129 
 130 /***************************************************************/
 131 #define FIND_DISTANCE_4( x1, x2, y1, y2, z1, z2, w1, w2, SHIFT ) \
 132   (( ( ( ( x1 ) - ( x2 ) ) * ( ( x1 ) - ( x2 ) ) ) >> SHIFT ) +  \
 133    ( ( ( ( y1 ) - ( y2 ) ) * ( ( y1 ) - ( y2 ) ) ) >> SHIFT ) +  \
 134    ( ( ( ( z1 ) - ( z2 ) ) * ( ( z1 ) - ( z2 ) ) ) >> SHIFT ) +  \
 135    ( ( ( ( w1 ) - ( w2 ) ) * ( ( w1 ) - ( w2 ) ) ) >> SHIFT ) )
 136 
 137 /***************************************************************/
 138 
 139 void mlib_ImageColorTrue2IndexLine_U8_BIT_1(const mlib_u8 *src,
 140                                             mlib_u8       *dst,
 141                                             mlib_s32      bit_offset,
 142                                             mlib_s32      length,
 143                                             const void    *state);
 144 
 145 
 146 void mlib_ImageColorTrue2IndexLine_U8_U8_3(const mlib_u8 *src,
 147                                            mlib_u8       *dst,
 148                                            mlib_s32      length,
 149                                            const void    *colormap);
 150 
 151 
 152 void mlib_ImageColorTrue2IndexLine_U8_U8_3_in_4(const mlib_u8 *src,
 153                                                 mlib_u8       *dst,
 154                                                 mlib_s32      length,
 155                                                 const void    *colormap);
 156 
 157 
 158 void mlib_ImageColorTrue2IndexLine_U8_U8_4(const mlib_u8 *src,
 159                                            mlib_u8       *dst,
 160                                            mlib_s32      length,
 161                                            const void    *colormap);
 162 
 163 
 164 void mlib_ImageColorTrue2IndexLine_U8_S16_3(const mlib_u8 *src,
 165                                             mlib_s16      *dst,
 166                                             mlib_s32      length,
 167                                             const void    *colormap);
 168 
 169 
 170 void mlib_ImageColorTrue2IndexLine_U8_S16_3_in_4(const mlib_u8 *src,
 171                                                  mlib_s16      *dst,
 172                                                  mlib_s32      length,
 173                                                  const void    *colormap);
 174 
 175 
 176 void mlib_ImageColorTrue2IndexLine_U8_S16_4(const mlib_u8 *src,
 177                                             mlib_s16      *dst,
 178                                             mlib_s32      length,
 179                                             const void    *colormap);
 180 
 181 
 182 void mlib_ImageColorTrue2IndexLine_S16_S16_3(const mlib_s16 *src,
 183                                              mlib_s16       *dst,
 184                                              mlib_s32       length,
 185                                              const void     *colormap);
 186 
 187 
 188 void mlib_ImageColorTrue2IndexLine_S16_S16_3_in_4(const mlib_s16 *src,
 189                                                   mlib_s16       *dst,
 190                                                   mlib_s32       length,
 191                                                   const void     *colormap);
 192 
 193 
 194 void mlib_ImageColorTrue2IndexLine_S16_S16_4(const mlib_s16 *src,
 195                                              mlib_s16       *dst,
 196                                              mlib_s32       length,
 197                                              const void     *colormap);
 198 
 199 
 200 void mlib_ImageColorTrue2IndexLine_S16_U8_3(const mlib_s16 *src,
 201                                             mlib_u8        *dst,
 202                                             mlib_s32       length,
 203                                             const void     *colormap);
 204 
 205 
 206 void mlib_ImageColorTrue2IndexLine_S16_U8_3_in_4(const mlib_s16 *src,
 207                                                  mlib_u8        *dst,
 208                                                  mlib_s32       length,
 209                                                  const void     *colormap);
 210 
 211 
 212 void mlib_ImageColorTrue2IndexLine_S16_U8_4(const mlib_s16 *src,
 213                                             mlib_u8        *dst,
 214                                             mlib_s32       length,
 215                                             const void     *colormap);
 216 
 217 
 218 #ifdef __cplusplus
 219 }
 220 #endif /* __cplusplus */
 221 #endif /* __MLIB_IMAGECOLORMAP_H */