changeset 16476:6968aa3bf5ac

8047931: Remove unused medialib code Reviewed-by: bae
author vadim
date Fri, 13 May 2016 11:31:05 +0300
parents 877bccceacb9
children 4d5055837809
files make/lib/Awt2dLibraries.gmk src/java.desktop/share/native/libmlib_image/mlib_ImageAffine.c src/java.desktop/share/native/libmlib_image/mlib_ImageAffine.h src/java.desktop/share/native/libmlib_image/mlib_ImageAffineEdge.c src/java.desktop/share/native/libmlib_image/mlib_ImageCheck.h src/java.desktop/share/native/libmlib_image/mlib_ImageColorTrue2Index.c src/java.desktop/share/native/libmlib_image/mlib_ImageColormap.h src/java.desktop/share/native/libmlib_image/mlib_ImageConv.h src/java.desktop/share/native/libmlib_image/mlib_ImageConv2x2_f.c src/java.desktop/share/native/libmlib_image/mlib_ImageConv_16ext.c src/java.desktop/share/native/libmlib_image/mlib_ImageConv_16nw.c src/java.desktop/share/native/libmlib_image/mlib_ImageConv_32nw.c src/java.desktop/share/native/libmlib_image/mlib_ImageConv_8ext.c src/java.desktop/share/native/libmlib_image/mlib_ImageConv_8nw.c src/java.desktop/share/native/libmlib_image/mlib_ImageConv_D64nw.c src/java.desktop/share/native/libmlib_image/mlib_ImageConv_F32nw.c src/java.desktop/share/native/libmlib_image/mlib_ImageConv_u16ext.c src/java.desktop/share/native/libmlib_image/mlib_ImageConv_u16nw.c src/java.desktop/share/native/libmlib_image/mlib_c_ImageAffineIndex_BC.c src/java.desktop/share/native/libmlib_image/mlib_c_ImageAffineIndex_BL.c src/java.desktop/share/native/libmlib_image/mlib_c_ImageBlendTable.c src/java.desktop/share/native/libmlib_image/mlib_c_ImageBlendTable.h src/java.desktop/share/native/libmlib_image/mlib_c_ImageConv.h src/java.desktop/share/native/libmlib_image/mlib_c_ImageConv_f.c src/java.desktop/share/native/libmlib_image/mlib_c_ImageThresh1.h src/java.desktop/share/native/libmlib_image/mlib_c_ImageThresh1_U8.c src/java.desktop/share/native/libmlib_image/mlib_image.h src/java.desktop/share/native/libmlib_image/mlib_image_blend_proto.h src/java.desktop/share/native/libmlib_image/mlib_image_proto.h src/java.desktop/unix/native/libawt/awt/medialib/mlib_v_ImageCopy.c src/java.desktop/unix/native/libawt/awt/medialib/mlib_v_ImageCopy_blk.s src/java.desktop/unix/native/libawt/awt/medialib/vis_asi.h src/java.desktop/unix/native/libmlib_image/mlib_v_ImageAffineIndex_BC.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageAffine_BL.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageAffine_BL_S16.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageAffine_BL_U16.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageChannelExtract.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageChannelExtract.h src/java.desktop/unix/native/libmlib_image/mlib_v_ImageChannelExtract_1.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageChannelExtract_43.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageChannelExtract_f.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageChannelInsert.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageChannelInsert.h src/java.desktop/unix/native/libmlib_image/mlib_v_ImageChannelInsert_1.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageChannelInsert_34.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageConv.h src/java.desktop/unix/native/libmlib_image/mlib_v_ImageConvIndex3_8_16nw.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageConvIndex3_8_8nw.c src/java.desktop/unix/native/libmlib_image/mlib_v_ImageConv_8nw.c
diffstat 49 files changed, 18 insertions(+), 34857 deletions(-) [+]
line wrap: on
line diff
--- a/make/lib/Awt2dLibraries.gmk	Thu May 12 11:03:07 2016 -0700
+++ b/make/lib/Awt2dLibraries.gmk	Fri May 13 11:31:05 2016 +0300
@@ -96,10 +96,7 @@
       mlib_c_ImageAffine_BL.c \
       mlib_c_ImageAffine_BL_S16.c \
       mlib_c_ImageAffine_BL_U16.c \
-      mlib_c_ImageAffineIndex_BC.c \
-      mlib_c_ImageAffineIndex_BL.c \
       mlib_c_ImageAffine_NN.c \
-      mlib_c_ImageBlendTable.c \
       mlib_c_ImageConvClearEdge.c \
       mlib_c_ImageConvCopyEdge.c \
       mlib_c_ImageConv_f.c \
@@ -107,14 +104,6 @@
       mlib_c_ImageCopy.c \
       mlib_c_ImageLookUp.c \
       mlib_c_ImageLookUp_f.c \
-      mlib_v_ImageChannelExtract.c \
-      mlib_v_ImageChannelExtract_f.c \
-      mlib_v_ImageChannelInsert_34.c \
-      mlib_v_ImageChannelInsert.c \
-      mlib_v_ImageConvIndex3_8_16nw.c \
-      mlib_v_ImageConvIndex3_8_8nw.c \
-      mlib_v_ImageCopy.c \
-      mlib_v_ImageCopy_blk.s \
       #
 
   LIBMLIB_IMAGE_V_CFLAGS += $(filter-out -DMLIB_NO_LIBSUNMATH, $(BUILD_LIBMLIB_CFLAGS))
--- a/src/java.desktop/share/native/libmlib_image/mlib_ImageAffine.c	Thu May 12 11:03:07 2016 -0700
+++ b/src/java.desktop/share/native/libmlib_image/mlib_ImageAffine.c	Fri May 13 11:31:05 2016 +0300
@@ -73,7 +73,6 @@
  */
 
 #include "mlib_ImageCheck.h"
-#include "mlib_ImageColormap.h"
 #include "mlib_ImageAffine.h"
 
 
@@ -125,18 +124,6 @@
 };
 
 /***************************************************************/
-const type_affine_i_fun mlib_AffineFunArr_bc_i[] = {
-  mlib_ImageAffineIndex_U8_U8_3CH_BC,
-  mlib_ImageAffineIndex_U8_U8_4CH_BC,
-  mlib_ImageAffineIndex_S16_U8_3CH_BC,
-  mlib_ImageAffineIndex_S16_U8_4CH_BC,
-  mlib_ImageAffineIndex_U8_S16_3CH_BC,
-  mlib_ImageAffineIndex_U8_S16_4CH_BC,
-  mlib_ImageAffineIndex_S16_S16_3CH_BC,
-  mlib_ImageAffineIndex_S16_S16_4CH_BC
-};
-
-/***************************************************************/
 #ifdef i386 /* do not perform the coping by mlib_d64 data type for x86 */
 #define MAX_T_IND  2
 #else
@@ -148,8 +135,7 @@
                                       const mlib_image *src,
                                       const mlib_d64   *mtx,
                                       mlib_filter      filter,
-                                      mlib_edge        edge,
-                                      const void       *colormap)
+                                      mlib_edge        edge)
 {
   mlib_affine_param param[1];
   mlib_status res;
@@ -213,18 +199,6 @@
   else
     return MLIB_FAILURE; /* unknown image type */
 
-  if (colormap != NULL && filter != MLIB_NEAREST) {
-    if (t_ind != 0 && t_ind != 1)
-      return MLIB_FAILURE;
-
-    if (mlib_ImageGetLutType(colormap) == MLIB_SHORT)
-      t_ind += 2;
-    t_ind = 2 * t_ind;
-
-    if (mlib_ImageGetLutChannels(colormap) == 4)
-      t_ind++;
-  }
-
   if (type == MLIB_BIT) {
     mlib_s32 s_bitoff = mlib_ImageGetBitOffset(src);
     mlib_s32 d_bitoff = mlib_ImageGetBitOffset(dst);
@@ -253,25 +227,13 @@
 
       case MLIB_BILINEAR:
 
-        if (colormap != NULL) {
-          res = mlib_AffineFunArr_bl_i[t_ind] (param, colormap);
-        }
-        else {
-          res = mlib_AffineFunArr_bl[4 * t_ind + (nchan - 1)] (param);
-        }
-
+        res = mlib_AffineFunArr_bl[4 * t_ind + (nchan - 1)] (param);
         break;
 
       case MLIB_BICUBIC:
       case MLIB_BICUBIC2:
 
-        if (colormap != NULL) {
-          res = mlib_AffineFunArr_bc_i[t_ind] (param, colormap);
-        }
-        else {
-          res = mlib_AffineFunArr_bc[4 * t_ind + (nchan - 1)] (param);
-        }
-
+        res = mlib_AffineFunArr_bc[4 * t_ind + (nchan - 1)] (param);
         break;
     }
 
@@ -303,7 +265,7 @@
 
     switch (edge) {
       case MLIB_EDGE_DST_FILL_ZERO:
-        mlib_ImageAffineEdgeZero(param, param_e, colormap);
+        mlib_ImageAffineEdgeZero(param, param_e);
         break;
 
       case MLIB_EDGE_OP_NEAREST:
@@ -313,10 +275,10 @@
       case MLIB_EDGE_SRC_EXTEND:
 
         if (filter == MLIB_BILINEAR) {
-          res = mlib_ImageAffineEdgeExtend_BL(param, param_e, colormap);
+          res = mlib_ImageAffineEdgeExtend_BL(param, param_e);
         }
         else {
-          res = mlib_ImageAffineEdgeExtend_BC(param, param_e, colormap);
+          res = mlib_ImageAffineEdgeExtend_BC(param, param_e);
         }
 
         break;
@@ -355,7 +317,7 @@
     return MLIB_FAILURE;
   }
 
-  return mlib_ImageAffine_alltypes(dst, src, mtx, filter, edge, NULL);
+  return mlib_ImageAffine_alltypes(dst, src, mtx, filter, edge);
 }
 
 /***************************************************************/
--- a/src/java.desktop/share/native/libmlib_image/mlib_ImageAffine.h	Thu May 12 11:03:07 2016 -0700
+++ b/src/java.desktop/share/native/libmlib_image/mlib_ImageAffine.h	Fri May 13 11:31:05 2016 +0300
@@ -162,99 +162,25 @@
 
 /***************************************************************/
 void mlib_ImageAffineEdgeZero(mlib_affine_param *param,
-                              mlib_affine_param *param_e,
-                              const void        *colormap);
+                              mlib_affine_param *param_e);
 
 void mlib_ImageAffineEdgeNearest(mlib_affine_param *param,
                                  mlib_affine_param *param_e);
 
 mlib_status mlib_ImageAffineEdgeExtend_BL(mlib_affine_param *param,
-                                          mlib_affine_param *param_e,
-                                          const void        *colormap);
+                                          mlib_affine_param *param_e);
 
 mlib_status mlib_ImageAffineEdgeExtend_BC(mlib_affine_param *param,
-                                          mlib_affine_param *param_e,
-                                          const void        *colormap);
-
-mlib_status mlib_ImageAffineEdgeExtend_BC2(mlib_affine_param *param,
-                                           mlib_affine_param *param_e,
-                                           const void        *colormap);
-
-/***************************************************************/
-typedef mlib_status (*type_affine_i_fun)(mlib_affine_param *param, const void *colormap);
-
-mlib_status mlib_ImageAffine_u8_u8_i_bl(mlib_affine_param *param,
-                                        const void        *colormap);
-mlib_status mlib_ImageAffine_u8_s16_i_bl(mlib_affine_param *param,
-                                         const void        *colormap);
-mlib_status mlib_ImageAffine_s16_u8_i_bl(mlib_affine_param *param,
-                                         const void        *colormap);
-mlib_status mlib_ImageAffine_s16_s16_i_bl(mlib_affine_param *param,
-                                          const void        *colormap);
-
-mlib_status mlib_ImageAffine_u8_u8_i_bc(mlib_affine_param *param,
-                                        const void        *colormap);
-mlib_status mlib_ImageAffine_u8_s16_i_bc(mlib_affine_param *param,
-                                         const void        *colormap);
-mlib_status mlib_ImageAffine_s16_u8_i_bc(mlib_affine_param *param,
-                                         const void        *colormap);
-mlib_status mlib_ImageAffine_s16_s16_i_bc(mlib_affine_param *param,
-                                          const void        *colormap);
-
-void mlib_ImageAffineEdgeZeroIndex(mlib_affine_param *param,
-                                   mlib_affine_param *param_e,
-                                   const void        *colormap);
-
-void mlib_ImageAffineEdgeExtendIndex_BL(mlib_affine_param *param,
-                                        mlib_affine_param *param_e,
-                                        const void        *colormap);
-
-void mlib_ImageAffineEdgeExtendIndex_BC(mlib_affine_param *param,
-                                        mlib_affine_param *param_e,
-                                        const void        *colormap);
-
-void mlib_ImageAffineEdgeExtendIndex_BC2(mlib_affine_param *param,
-                                         mlib_affine_param *param_e,
-                                         const void        *colormap);
-
-/***************************************************************/
-#define PROT_AFFINEINDEX_BC(ITYPE, LTYPE, NCHAN)                                                 \
-  mlib_status mlib_ImageAffineIndex_##ITYPE##_##LTYPE##_##NCHAN##CH_BC(mlib_affine_param *param, \
-                                                                       const void        *colormap)
-
-PROT_AFFINEINDEX_BC(U8, U8, 3);
-PROT_AFFINEINDEX_BC(U8, S16, 3);
-PROT_AFFINEINDEX_BC(U8, U8, 4);
-PROT_AFFINEINDEX_BC(U8, S16, 4);
-PROT_AFFINEINDEX_BC(S16, U8, 3);
-PROT_AFFINEINDEX_BC(S16, S16, 3);
-PROT_AFFINEINDEX_BC(S16, U8, 4);
-PROT_AFFINEINDEX_BC(S16, S16, 4);
-
-/***************************************************************/
-#define PROT_AFFINEINDEX_BL(ITYPE, LTYPE, NCHAN)                                                 \
-  mlib_status mlib_ImageAffineIndex_##ITYPE##_##LTYPE##_##NCHAN##CH_BL(mlib_affine_param *param, \
-                                                                       const void        *colormap)
-
-PROT_AFFINEINDEX_BL(U8, U8, 3);
-PROT_AFFINEINDEX_BL(U8, S16, 3);
-PROT_AFFINEINDEX_BL(U8, U8, 4);
-PROT_AFFINEINDEX_BL(U8, S16, 4);
-PROT_AFFINEINDEX_BL(S16, U8, 3);
-PROT_AFFINEINDEX_BL(S16, S16, 3);
-PROT_AFFINEINDEX_BL(S16, U8, 4);
-PROT_AFFINEINDEX_BL(S16, S16, 4);
+                                          mlib_affine_param *param_e);
 
 /***************************************************************/
 mlib_status mlib_ImageAffine_alltypes(mlib_image       *dst,
                                       const mlib_image *src,
                                       const mlib_d64   *mtx,
                                       mlib_filter      filter,
-                                      mlib_edge        edge,
-                                      const void       *colormap);
+                                      mlib_edge        edge);
 
 /***************************************************************/
-extern const type_affine_i_fun mlib_AffineFunArr_bl_i[];
 extern const type_affine_fun mlib_AffineFunArr_nn[];
 extern const type_affine_fun mlib_AffineFunArr_bl[];
 extern const type_affine_fun mlib_AffineFunArr_bc[];
--- a/src/java.desktop/share/native/libmlib_image/mlib_ImageAffineEdge.c	Thu May 12 11:03:07 2016 -0700
+++ b/src/java.desktop/share/native/libmlib_image/mlib_ImageAffineEdge.c	Fri May 13 11:31:05 2016 +0300
@@ -73,7 +73,6 @@
  */
 
 #include "mlib_image.h"
-#include "mlib_ImageColormap.h"
 #include "mlib_ImageAffine.h"
 
 /***************************************************************/
@@ -218,97 +217,6 @@
   }
 
 /***************************************************************/
-#define LUT(k, ind) plut[channels*sp[ind] + k]
-
-/***************************************************************/
-#define MLIB_EDGE_INDEX(ITYPE, DTYPE, size)                             \
-  for (j = 0; j < size; j++) {                                          \
-    ySrc = ((Y - 32768) >> MLIB_SHIFT);                                 \
-    xSrc = ((X - 32768) >> MLIB_SHIFT);                                 \
-                                                                        \
-    t = ((X - 32768) & MLIB_MASK) * scale;                              \
-    u = ((Y - 32768) & MLIB_MASK) * scale;                              \
-                                                                        \
-    xDelta = (((xSrc + 1 - srcWidth )) >> MLIB_SIGN_SHIFT) & 1;         \
-    yDelta = (((ySrc + 1 - srcHeight)) >> MLIB_SIGN_SHIFT) & srcStride; \
-                                                                        \
-    xFlag = (xSrc >> (MLIB_SIGN_SHIFT - MLIB_SHIFT));                   \
-    xSrc = xSrc + (1 & xFlag);                                          \
-    xDelta = xDelta &~ xFlag;                                           \
-                                                                        \
-    yFlag = (ySrc >> (MLIB_SIGN_SHIFT - MLIB_SHIFT));                   \
-    ySrc = ySrc + (1 & yFlag);                                          \
-    yDelta = yDelta &~ yFlag;                                           \
-                                                                        \
-    sp = (ITYPE*)lineAddr[ySrc] + xSrc;                                 \
-                                                                        \
-    for (k = 0; k < channels; k++) {                                    \
-      a00  = LUT(k, 0);                                                 \
-      a01  = LUT(k, xDelta);                                            \
-      a10  = LUT(k, yDelta);                                            \
-      a11  = LUT(k, yDelta + xDelta);                                   \
-      pix0 = (a00 * (1 - t) + a01 * t) * (1 - u) +                      \
-             (a10 * (1 - t) + a11 * t) * u;                             \
-                                                                        \
-      pbuff[k] = (mlib_s32)pix0;                                        \
-    }                                                                   \
-    pbuff += channels;                                                  \
-                                                                        \
-    X += dX;                                                            \
-    Y += dY;                                                            \
-  }
-
-/***************************************************************/
-#define MLIB_EDGE_INDEX_u8i(ITYPE, Left, Right) {                              \
-  mlib_u8  *pbuff = buff;                                                      \
-                                                                               \
-  size = Right - Left;                                                         \
-                                                                               \
-  MLIB_EDGE_INDEX(ITYPE, mlib_u8, size);                                       \
-                                                                               \
-  dp = (ITYPE*)data + Left;                                                    \
-                                                                               \
-  if (channels == 3) {                                                         \
-    if (sizeof(ITYPE) == 1) {                                                  \
-      mlib_ImageColorTrue2IndexLine_U8_U8_3 (buff, (void*)dp, size, colormap); \
-    } else {                                                                   \
-      mlib_ImageColorTrue2IndexLine_U8_S16_3(buff, (void*)dp, size, colormap); \
-    }                                                                          \
-  } else {                                                                     \
-    if (sizeof(ITYPE) == 1) {                                                  \
-      mlib_ImageColorTrue2IndexLine_U8_U8_4 (buff, (void*)dp, size, colormap); \
-    } else {                                                                   \
-      mlib_ImageColorTrue2IndexLine_U8_S16_4(buff, (void*)dp, size, colormap); \
-    }                                                                          \
-  }                                                                            \
-}
-
-/***************************************************************/
-#define MLIB_EDGE_INDEX_s16i(ITYPE, Left, Right) {                              \
-  mlib_s16 *pbuff = buff;                                                       \
-                                                                                \
-  size = Right - Left;                                                          \
-                                                                                \
-  MLIB_EDGE_INDEX(ITYPE, mlib_s16, size);                                       \
-                                                                                \
-  dp = (ITYPE*)data + Left;                                                     \
-                                                                                \
-  if (channels == 3) {                                                          \
-    if (sizeof(ITYPE) == 1) {                                                   \
-      mlib_ImageColorTrue2IndexLine_S16_U8_3 (buff, (void*)dp, size, colormap); \
-    } else {                                                                    \
-      mlib_ImageColorTrue2IndexLine_S16_S16_3(buff, (void*)dp, size, colormap); \
-    }                                                                           \
-  } else {                                                                      \
-    if (sizeof(ITYPE) == 1) {                                                   \
-      mlib_ImageColorTrue2IndexLine_S16_U8_4 (buff, (void*)dp, size, colormap); \
-    } else {                                                                    \
-      mlib_ImageColorTrue2IndexLine_S16_S16_4(buff, (void*)dp, size, colormap); \
-    }                                                                           \
-  }                                                                             \
-}
-
-/***************************************************************/
 #define GET_FLT_TBL(X, xf0, xf1, xf2, xf3)                      \
   filterpos = ((X - 32768) >> flt_shift) & flt_mask;            \
   fptr = (mlib_f32 *) ((mlib_u8 *)flt_tbl + filterpos);         \
@@ -424,47 +332,6 @@
   MLIB_EDGE_BC_LINE(TYPE, Left, Right, GET_FLT_BC2)
 
 /***************************************************************/
-#define MLIB_EDGE_INDEX_BC(ITYPE, DTYPE, size)                  \
-  for (j = 0; j < size; j++) {                                  \
-    GET_FLT_TBL(X, xf0, xf1, xf2, xf3);                         \
-    GET_FLT_TBL(Y, yf0, yf1, yf2, yf3);                         \
-                                                                \
-    CALC_SRC_POS(X, Y, 1, srcStride);                           \
-                                                                \
-    sp = (ITYPE*)lineAddr[ySrc] + xSrc;                         \
-                                                                \
-    for (k = 0; k < channels; k++) {                            \
-      c0 = LUT(k, yDelta0 + xDelta0) * xf0 +                    \
-           LUT(k, yDelta0          ) * xf1 +                    \
-           LUT(k, yDelta0 + xDelta1) * xf2 +                    \
-           LUT(k, yDelta0 + xDelta2) * xf3;                     \
-                                                                \
-      c1 = LUT(k, xDelta0) * xf0 +                              \
-           LUT(k, 0      ) * xf1 +                              \
-           LUT(k, xDelta1) * xf2 +                              \
-           LUT(k, xDelta2) * xf3;                               \
-                                                                \
-      c2 = LUT(k, yDelta1 + xDelta0) * xf0 +                    \
-           LUT(k, yDelta1          ) * xf1 +                    \
-           LUT(k, yDelta1 + xDelta1) * xf2 +                    \
-           LUT(k, yDelta1 + xDelta2) * xf3;                     \
-                                                                \
-      c3 = LUT(k, yDelta2 + xDelta0) * xf0 +                    \
-           LUT(k, yDelta2          ) * xf1 +                    \
-           LUT(k, yDelta2 + xDelta1) * xf2 +                    \
-           LUT(k, yDelta2 + xDelta2) * xf3;                     \
-                                                                \
-      val0 = c0*yf0 + c1*yf1 + c2*yf2 + c3*yf3;                 \
-                                                                \
-      SAT##DTYPE(pbuff[k], val0);                               \
-    }                                                           \
-    pbuff += channels;                                          \
-                                                                \
-    X += dX;                                                    \
-    Y += dY;                                                    \
-  }
-
-/***************************************************************/
 #define MLIB_PROCESS_EDGES_ZERO(TYPE) {                         \
   TYPE *dp, *dstLineEnd;                                        \
                                                                 \
@@ -586,16 +453,11 @@
 
 /***************************************************************/
 void mlib_ImageAffineEdgeZero(mlib_affine_param *param,
-                              mlib_affine_param *param_e,
-                              const void        *colormap)
+                              mlib_affine_param *param_e)
 {
   GET_EDGE_PARAMS_ZERO();
   mlib_s32 zero = 0;
 
-  if (colormap != NULL) {
-    zero = mlib_ImageGetLutOffset(colormap);
-  }
-
   switch (type) {
     case MLIB_BYTE:
       MLIB_PROCESS_EDGES_ZERO(mlib_u8);
@@ -654,8 +516,7 @@
 
 /***************************************************************/
 mlib_status mlib_ImageAffineEdgeExtend_BL(mlib_affine_param *param,
-                                          mlib_affine_param *param_e,
-                                          const void        *colormap)
+                                          mlib_affine_param *param_e)
 {
   GET_EDGE_PARAMS();
   mlib_d64 scale = 1.0 / (mlib_d64) MLIB_PREC;
@@ -663,79 +524,6 @@
   mlib_d64 t, u, pix0;
   mlib_d64 a00, a01, a10, a11;
 
-  if (colormap != NULL) {
-    mlib_s32 max_xsize = param_e->max_xsize;
-    mlib_type ltype = mlib_ImageGetLutType(colormap);
-    mlib_d64 *plut = (mlib_d64 *) mlib_ImageGetLutDoubleData(colormap);
-    void *buff;
-
-    channels = mlib_ImageGetLutChannels(colormap);
-    plut -= channels * mlib_ImageGetLutOffset(colormap);
-
-    if (max_xsize == 0) {
-      return MLIB_SUCCESS;
-    }
-
-    if (ltype == MLIB_BYTE) {
-      buff = mlib_malloc(channels * max_xsize);
-    }
-    else if (ltype == MLIB_SHORT) {
-      buff = mlib_malloc(channels * max_xsize * sizeof(mlib_s16));
-    } else {
-      /* Unsupported type of lookup table. Report a failure */
-      return MLIB_FAILURE;
-    }
-
-    if (buff == NULL)
-      return MLIB_FAILURE;
-
-    switch (ltype) {
-      case MLIB_BYTE:
-        switch (type) {
-          case MLIB_BYTE:
-            MLIB_PROCESS_EDGES(MLIB_EDGE_INDEX_u8i, mlib_u8);
-            break;
-
-          case MLIB_SHORT:
-            srcStride >>= 1;
-            MLIB_PROCESS_EDGES(MLIB_EDGE_INDEX_u8i, mlib_s16);
-            break;
-        default:
-          /* Incompatible image type. Ignore it for now. */
-          break;
-        }
-
-        break;
-
-      case MLIB_SHORT:
-        switch (type) {
-          case MLIB_BYTE:
-            MLIB_PROCESS_EDGES(MLIB_EDGE_INDEX_s16i, mlib_u8);
-            break;
-
-          case MLIB_SHORT:
-            srcStride >>= 1;
-            MLIB_PROCESS_EDGES(MLIB_EDGE_INDEX_s16i, mlib_s16);
-            break;
-        default:
-          /* Incompatible image type. Ignore it for now. */
-          break;
-        }
-
-        break;
-    default:
-      /* Unsupported type of lookup table.
-       * Can not be here due to check on line 685,
-       * so just ignore it.
-       */
-      break;
-    }
-
-    mlib_free(buff);
-
-    return MLIB_SUCCESS;
-  }
-
   switch (type) {
     case MLIB_BYTE:
       MLIB_PROCESS_EDGES(MLIB_EDGE_BL, mlib_u8);
@@ -775,12 +563,8 @@
 }
 
 /***************************************************************/
-#undef  MLIB_EDGE_INDEX
-#define MLIB_EDGE_INDEX MLIB_EDGE_INDEX_BC
-
 mlib_status mlib_ImageAffineEdgeExtend_BC(mlib_affine_param *param,
-                                          mlib_affine_param *param_e,
-                                          const void        *colormap)
+                                          mlib_affine_param *param_e)
 {
   GET_EDGE_PARAMS();
   mlib_d64 scale = 1.0 / (mlib_d64) MLIB_PREC;
@@ -789,7 +573,6 @@
   mlib_d64 xf0, xf1, xf2, xf3;
   mlib_d64 yf0, yf1, yf2, yf3;
   mlib_d64 c0, c1, c2, c3, val0;
-  mlib_type ltype;
   mlib_filter filter = param->filter;
   mlib_f32 *fptr;
   mlib_f32 const *flt_tbl;
@@ -798,9 +581,7 @@
   mlib_s32 yDelta0, yDelta1, yDelta2;
   mlib_d64 sat;
 
-  ltype = (colormap != NULL) ? mlib_ImageGetLutType(colormap) : type;
-
-  if (ltype == MLIB_BYTE) {
+  if (type == MLIB_BYTE) {
     flt_shift = FLT_SHIFT_U8;
     flt_mask = FLT_MASK_U8;
     flt_tbl = (filter == MLIB_BICUBIC) ? mlib_filters_u8f_bc : mlib_filters_u8f_bc2;
@@ -813,78 +594,6 @@
     sat = (mlib_d64) 0x7FFF8000;                           /* saturation for U16 */
   }
 
-  if (colormap != NULL) {
-    mlib_s32 max_xsize = param_e->max_xsize;
-    mlib_d64 *plut = (mlib_d64 *) mlib_ImageGetLutDoubleData(colormap);
-    void *buff;
-
-    channels = mlib_ImageGetLutChannels(colormap);
-    plut -= channels * mlib_ImageGetLutOffset(colormap);
-
-    if (max_xsize == 0) {
-      return MLIB_SUCCESS;
-    }
-
-    if (ltype == MLIB_BYTE) {
-      buff = mlib_malloc(channels * max_xsize);
-    }
-    else if (ltype == MLIB_SHORT) {
-      buff = mlib_malloc(channels * max_xsize * sizeof(mlib_s16));
-    } else {
-      /* Unsupported type of lookup table. */
-      return MLIB_FAILURE;
-    }
-
-    if (buff == NULL)
-      return MLIB_FAILURE;
-
-    switch (ltype) {
-      case MLIB_BYTE:
-        switch (type) {
-          case MLIB_BYTE:
-            MLIB_PROCESS_EDGES(MLIB_EDGE_INDEX_u8i, mlib_u8);
-            break;
-
-          case MLIB_SHORT:
-            srcStride >>= 1;
-            MLIB_PROCESS_EDGES(MLIB_EDGE_INDEX_u8i, mlib_s16);
-            break;
-        default:
-          /* Ignore incomatible image type. */
-          break;
-        }
-
-        break;
-
-      case MLIB_SHORT:
-        switch (type) {
-          case MLIB_BYTE:
-            MLIB_PROCESS_EDGES(MLIB_EDGE_INDEX_s16i, mlib_u8);
-            break;
-
-          case MLIB_SHORT:
-            srcStride >>= 1;
-            MLIB_PROCESS_EDGES(MLIB_EDGE_INDEX_s16i, mlib_s16);
-            break;
-        default:
-          /* Ignore incomatible image type. */
-          break;
-        }
-
-        break;
-
-    default:
-      /* Unsupported type of lookup table.
-       * Can not be here due to check on line 836,
-       * so just ignore it.
-       */
-      break;
-    }
-
-    mlib_free(buff);
-
-    return MLIB_SUCCESS;
-  }
 
   switch (type) {
     case MLIB_BYTE:
--- a/src/java.desktop/share/native/libmlib_image/mlib_ImageCheck.h	Thu May 12 11:03:07 2016 -0700
+++ b/src/java.desktop/share/native/libmlib_image/mlib_ImageCheck.h	Fri May 13 11:31:05 2016 +0300
@@ -82,12 +82,6 @@
     return MLIB_FAILURE;                                        \
   }
 
-#define MLIB_IMAGE_AND_COLORMAP_ARE_COMPAT(image,colormap)                 \
-  if ((mlib_ImageGetChannels(image) != mlib_ImageGetLutChannels(colormap)) \
-    || (mlib_ImageGetLutType(colormap) != mlib_ImageGetType(image))) {     \
-    return MLIB_FAILURE;                                                   \
-  }
-
 #define MLIB_IMAGE_GET_ALL_PARAMS(image, type, nchan, width, height, stride, pdata) \
   type   = mlib_ImageGetType(image);                                                \
   nchan  = mlib_ImageGetChannels(image);                                            \
--- a/src/java.desktop/share/native/libmlib_image/mlib_ImageColorTrue2Index.c	Thu May 12 11:03:07 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4256 +0,0 @@
-/*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * FUNCTION
- *      mlib_ImageColorTrue2Index - convert a true color image to an indexed
- *                                  color image
- *
- * SYNOPSIS
- *      mlib_status mlib_ImageColorTrue2Index(mlib_image       *dst,
- *                                            const mlib_image *src,
- *                                            const void       *colormap)
- *
- * ARGUMENTS
- *      colormap  Internal data structure for inverse color mapping.
- *      dst       Pointer to destination image.
- *      src       Pointer to source image.
- *
- * DESCRIPTION
- *      Convert a true color image to a pseudo color image with the method
- *      of finding the nearest matched lut entry for each pixel.
- *
- *      The src can be an MLIB_BYTE or MLIB_SHORT image with 3 or 4 channels.
- *      The dst must be a 1-channel MLIB_BYTE or MLIB_SHORT image.
- *
- *      The lut might have either 3 or 4 channels. The type of the lut can be
- *      one of the following:
- *              MLIB_BYTE in, MLIB_BYTE out (i.e., BYTE-to-BYTE)
- *              MLIB_BYTE in, MLIB_SHORT out (i.e., BYTE-to-SHORT)
- *              MLIB_SHORT in, MLIB_SHORT out (i.e., SHORT-to-SHORT)
- *              MLIB_SHORT in, MLIB_BYTE out (i.e., SHORT-to-BYTE)
- *
- *      The src image and the lut must have same number of channels.
- */
-
-#include "mlib_image.h"
-#include "mlib_ImageColormap.h"
-#include "mlib_ImageCheck.h"
-
-/***************************************************************/
-
-/*#define USE_VIS_CODE*/
-
-#ifdef USE_VIS_CODE
-#include "vis_proto.h"
-#define VIS_ALIGNADDR(X, Y)  vis_alignaddr((void *)(X), (Y))
-#endif
-
-/***************************************************************/
-
-#define LUT_BYTE_COLORS_3CHANNELS  1000
-#define LUT_BYTE_COLORS_4CHANNELS  3000
-#define LUT_SHORT_COLORS_3CHANNELS 1000
-#define LUT_SHORT_COLORS_4CHANNELS 1000
-
-/***************************************************************/
-
-#define MAIN_COLORTRUE2INDEX_LOOP( FROM_TYPE, TO_TYPE, NCHANNELS )       \
-  for( y = 0; y < height; y++ )                                          \
-  {                                                                      \
-    mlib_ImageColorTrue2IndexLine_##FROM_TYPE##_##TO_TYPE##_##NCHANNELS( \
-      sdata, ddata, width, colormap );                                   \
-                                                                         \
-    sdata += sstride;                                                    \
-    ddata += dstride;                                                    \
-  }
-
-/***************************************************************/
-
-#define COLOR_CUBE_U8_3_SEARCH( TABLE_POINTER_TYPE, SHIFT, STEP ) \
-{                                                                 \
-  const mlib_u8 *c0, *c1, *c2;                                    \
-  TABLE_POINTER_TYPE *table = s->table;                           \
-  mlib_s32 bits = s->bits;                                        \
-  mlib_s32 nbits = 8 - bits;                                      \
-  mlib_s32 mask = ~( ( 1 << nbits ) - 1 );                        \
-  mlib_s32 j;                                                     \
-                                                                  \
-  c0 = src + SHIFT;                                               \
-  c1 = src + 1 + SHIFT;                                           \
-  c2 = src + 2 + SHIFT;                                           \
-                                                                  \
-  switch( bits )                                                  \
-  {                                                               \
-    case 1:                                                       \
-    case 2:                                                       \
-    {                                                             \
-      mlib_s32 bits0 = 8 - bits;                                  \
-      mlib_s32 bits1 = bits0 - bits;                              \
-      mlib_s32 bits2 = bits1 - bits;                              \
-                                                                  \
-      for( j = 0; j < length; j++ )                               \
-      {                                                           \
-        dst[ j ] = table[ ( ( *c0 & mask ) >> bits2 ) |           \
-          ( ( *c1 & mask ) >> bits1 ) |                           \
-          ( ( *c2 & mask ) >> bits0 ) ];                          \
-                                                                  \
-        c0 += STEP;                                               \
-        c1 += STEP;                                               \
-        c2 += STEP;                                               \
-      }                                                           \
-      break;                                                      \
-    }                                                             \
-    case 3:                                                       \
-    {                                                             \
-      for( j = 0; j < length; j++ )                               \
-      {                                                           \
-        dst[ j ] = table[ ( ( *c0 & mask ) << 1 ) |               \
-          ( ( *c1 & mask ) >> 2 ) |                               \
-          ( ( *c2 & mask ) >> 5 ) ];                              \
-                                                                  \
-        c0 += STEP;                                               \
-        c1 += STEP;                                               \
-        c2 += STEP;                                               \
-      }                                                           \
-      break;                                                      \
-    }                                                             \
-    case 4:                                                       \
-    {                                                             \
-      for( j = 0; j < length; j++ )                               \
-      {                                                           \
-        dst[ j ] = table[ ( ( *c0 & mask ) << 4 ) |               \
-          ( *c1 & mask ) |                                        \
-          ( ( *c2 & mask ) >> 4 ) ];                              \
-                                                                  \
-        c0 += STEP;                                               \
-        c1 += STEP;                                               \
-        c2 += STEP;                                               \
-      }                                                           \
-      break;                                                      \
-    }                                                             \
-    case 5:                                                       \
-    case 6:                                                       \
-    case 7:                                                       \
-    {                                                             \
-      mlib_s32 bits0 = 8 - bits;                                  \
-      mlib_s32 bits1 = bits * 2 - 8;                              \
-      mlib_s32 bits2 = bits1 + bits;                              \
-                                                                  \
-      for( j = 0; j < length; j++ )                               \
-      {                                                           \
-        dst[ j ] = table[ ( ( *c0 & mask ) << bits2 ) |           \
-          ( ( *c1 & mask ) << bits1 ) |                           \
-          ( ( *c2 & mask ) >> bits0 ) ];                          \
-                                                                  \
-        c0 += STEP;                                               \
-        c1 += STEP;                                               \
-        c2 += STEP;                                               \
-      }                                                           \
-      break;                                                      \
-    }                                                             \
-    case 8:                                                       \
-    {                                                             \
-      for( j = 0; j < length; j++ )                               \
-      {                                                           \
-        dst[ j ] = table[ ( ( *c0 & mask ) << 16 ) |              \
-          ( ( *c1 & mask ) << 8 ) |                               \
-          ( *c2 & mask ) ];                                       \
-                                                                  \
-        c0 += STEP;                                               \
-        c1 += STEP;                                               \
-        c2 += STEP;                                               \
-      }                                                           \
-      break;                                                      \
-    }                                                             \
-  }                                                               \
-}
-
-/***************************************************************/
-#define COLOR_CUBE_U8_4_SEARCH( TABLE_TYPE )                    \
-{                                                               \
-  const mlib_u8 *c0, *c1, *c2, *c3;                             \
-  TABLE_TYPE *table = s->table;                                 \
-  mlib_s32 bits = s->bits;                                      \
-  mlib_s32 nbits = 8 - bits;                                    \
-  mlib_s32 mask = ~( ( 1 << nbits ) - 1 );                      \
-  mlib_s32 j;                                                   \
-                                                                \
-  c0 = src;                                                     \
-  c1 = src + 1;                                                 \
-  c2 = src + 2;                                                 \
-  c3 = src + 3;                                                 \
-                                                                \
-  switch( bits )                                                \
-  {                                                             \
-    case 1:                                                     \
-    {                                                           \
-      for( j = 0; j < length; j++ )                             \
-      {                                                         \
-        dst[ j ] = table[ ( ( *c0 & mask ) >> 4 ) |             \
-          ( ( *c1 & mask ) >> 5 ) |                             \
-          ( ( *c2 & mask ) >> 6 ) |                             \
-          ( ( *c3 & mask ) >> 7 ) ];                            \
-                                                                \
-        c0 += 4;                                                \
-        c1 += 4;                                                \
-        c2 += 4;                                                \
-        c3 += 4;                                                \
-      }                                                         \
-      break;                                                    \
-    }                                                           \
-    case 2:                                                     \
-    {                                                           \
-      for( j = 0; j < length; j++ )                             \
-      {                                                         \
-        dst[ j ] = table[ ( *c0 & mask ) |                      \
-          ( ( *c1 & mask ) >> 2 ) |                             \
-          ( ( *c2 & mask ) >> 4 ) |                             \
-          ( ( *c3 & mask ) >> 6 ) ];                            \
-                                                                \
-        c0 += 4;                                                \
-        c1 += 4;                                                \
-        c2 += 4;                                                \
-        c3 += 4;                                                \
-          }                                                     \
-      break;                                                    \
-    }                                                           \
-    case 3:                                                     \
-    {                                                           \
-      for( j = 0; j < length; j++ )                             \
-      {                                                         \
-        dst[ j ] = table[ ( ( *c0 & mask ) << 4 ) |             \
-          ( ( *c1 & mask ) << 1 ) |                             \
-          ( ( *c2 & mask ) >> 2 ) |                             \
-          ( ( *c3 & mask ) >> 5 ) ];                            \
-                                                                \
-        c0 += 4;                                                \
-        c1 += 4;                                                \
-        c2 += 4;                                                \
-        c3 += 4;                                                \
-      }                                                         \
-      break;                                                    \
-    }                                                           \
-    case 4:                                                     \
-    {                                                           \
-      for( j = 0; j < length; j++ )                             \
-      {                                                         \
-        dst[ j ] = table[ ( ( *c0 & mask ) << 8 ) |             \
-          ( ( *c1 & mask ) << 4 ) |                             \
-          ( *c2 & mask ) |                                      \
-          ( ( *c3 & mask ) >> 4 ) ];                            \
-                                                                \
-        c0 += 4;                                                \
-        c1 += 4;                                                \
-        c2 += 4;                                                \
-        c3 += 4;                                                \
-      }                                                         \
-      break;                                                    \
-    }                                                           \
-    case 5:                                                     \
-    case 6:                                                     \
-    {                                                           \
-      mlib_s32 bits3 = bits * 4 - 8;                            \
-      mlib_s32 bits2 = bits3 - bits;                            \
-      mlib_s32 bits1 = bits2 - bits;                            \
-      mlib_s32 bits0 = 8 - bits;                                \
-                                                                \
-      for( j = 0; j < length; j++ )                             \
-      {                                                         \
-        dst[ j ] = table[ ( ( *c0 & mask ) << bits3 ) |         \
-          ( ( *c1 & mask ) << bits2 ) |                         \
-          ( ( *c2 & mask ) << bits1 ) |                         \
-          ( ( *c3 & mask ) >> bits0 ) ];                        \
-                                                                \
-        c0 += 4;                                                \
-        c1 += 4;                                                \
-        c2 += 4;                                                \
-        c3 += 4;                                                \
-      }                                                         \
-      break;                                                    \
-    }                                                           \
-    case 7:                                                     \
-    {                                                           \
-      for( j = 0; j < length; j++ )                             \
-      {                                                         \
-        dst[ j ] = table[ ( ( *c0 & mask ) << 20 ) |            \
-          ( ( *c1 & mask ) << 13 ) |                            \
-          ( ( *c2 & mask ) << 6 ) |                             \
-          ( ( *c3 & mask ) >> 1 ) ];                            \
-                                                                \
-        c0 += 4;                                                \
-        c1 += 4;                                                \
-        c2 += 4;                                                \
-        c3 += 4;                                                \
-      }                                                         \
-      break;                                                    \
-    }                                                           \
-    case 8: /* will never be called */                          \
-    {                                                           \
-      for( j = 0; j < length; j++ )                             \
-      {                                                         \
-        dst[ j ] = table[ ( ( *c0 & mask ) << 24 ) |            \
-          ( ( *c1 & mask ) << 16 ) |                            \
-          ( ( *c2 & mask ) << 8 ) |                             \
-          ( *c3 & mask ) ];                                     \
-                                                                \
-        c0 += 4;                                                \
-        c1 += 4;                                                \
-        c2 += 4;                                                \
-        c3 += 4;                                                \
-      }                                                         \
-      break;                                                    \
-    }                                                           \
-  }                                                             \
-}
-
-/***************************************************************/
-#define COLOR_CUBE_S16_3_SEARCH( TABLE_TYPE, SHIFT, STEP )                 \
-{                                                                          \
-  const mlib_s16 *c0, *c1, *c2;                                            \
-  mlib_s32 bits = s->bits;                                                 \
-  mlib_s32 nbits = 16 - bits;                                              \
-  mlib_s32 mask = ~( ( 1 << nbits ) - 1 );                                 \
-  TABLE_TYPE *table = s->table;                                            \
-  mlib_s32 j;                                                              \
-                                                                           \
-  c0 = src + SHIFT;                                                        \
-  c1 = src + 1 + SHIFT;                                                    \
-  c2 = src + 2 + SHIFT;                                                    \
-                                                                           \
-  switch( bits )                                                           \
-  {                                                                        \
-    case 1:                                                                \
-    case 2:                                                                \
-    case 3:                                                                \
-    case 4:                                                                \
-    case 5:                                                                \
-    {                                                                      \
-      mlib_s32 bits0 = 16 - bits;                                          \
-      mlib_s32 bits1 = bits0 - bits;                                       \
-      mlib_s32 bits2 = bits1 - bits;                                       \
-                                                                           \
-      for( j = 0; j < length; j++ )                                        \
-      {                                                                    \
-        dst[ j ] = table[ ( ( ( *c0 - MLIB_S16_MIN ) & mask ) >> bits2 ) | \
-          ( ( ( *c1 - MLIB_S16_MIN ) & mask ) >> bits1 ) |                 \
-          ( ( ( *c2 - MLIB_S16_MIN ) & mask ) >> bits0 ) ];                \
-                                                                           \
-        c0 += STEP;                                                        \
-        c1 += STEP;                                                        \
-        c2 += STEP;                                                        \
-      }                                                                    \
-      break;                                                               \
-    }                                                                      \
-    case 6:                                                                \
-    case 7:                                                                \
-    {                                                                      \
-      mlib_s32 bits0 = 16 - bits;                                          \
-      mlib_s32 bits1 = bits0 - bits;                                       \
-      mlib_s32 bits2 = bits * 3 - 16;                                      \
-                                                                           \
-      for( j = 0; j < length; j++ )                                        \
-      {                                                                    \
-        dst[ j ] = table[ ( ( ( *c0 - MLIB_S16_MIN ) & mask ) << bits2 ) | \
-          ( ( ( *c1 - MLIB_S16_MIN ) & mask ) >> bits1 ) |                 \
-          ( ( ( *c2 - MLIB_S16_MIN ) & mask ) >> bits0 ) ];                \
-                                                                           \
-        c0 += STEP;                                                        \
-        c1 += STEP;                                                        \
-        c2 += STEP;                                                        \
-      }                                                                    \
-      break;                                                               \
-    }                                                                      \
-    case 8:                                                                \
-    {                                                                      \
-      for( j = 0; j < length; j++ )                                        \
-      {                                                                    \
-        dst[ j ] = table[ ( ( ( *c0 - MLIB_S16_MIN ) & mask ) << 8 ) |     \
-          ( ( *c1 - MLIB_S16_MIN ) & mask ) |                              \
-          ( ( ( *c2 - MLIB_S16_MIN ) & mask ) >> 8 ) ];                    \
-                                                                           \
-        c0 += STEP;                                                        \
-        c1 += STEP;                                                        \
-        c2 += STEP;                                                        \
-      }                                                                    \
-      break;                                                               \
-    }                                                                      \
-    case 9:                                                                \
-    case 10:                                                               \
-    {                                                                      \
-      mlib_s32 bits0 = 16 - bits;                                          \
-      mlib_s32 bits1 = 2 * bits - 16;                                      \
-      mlib_s32 bits2 = bits1 + bits;                                       \
-                                                                           \
-      for( j = 0; j < length; j++ )                                        \
-      {                                                                    \
-        dst[ j ] = table[ ( ( ( *c0 - MLIB_S16_MIN ) & mask ) << bits2 ) | \
-          ( ( ( *c1 - MLIB_S16_MIN ) & mask ) << bits1 ) |                 \
-          ( ( ( *c2 - MLIB_S16_MIN ) & mask ) >> bits0 ) ];                \
-                                                                           \
-        c0 += STEP;                                                        \
-        c1 += STEP;                                                        \
-        c2 += STEP;                                                        \
-      }                                                                    \
-      break;                                                               \
-    }                                                                      \
-    /* Other cases may not be considered as the table size will be more    \
-       than 2^32 */                                                        \
-  }                                                                        \
-}
-
-/***************************************************************/
-#define COLOR_CUBE_S16_4_SEARCH( TABLE_TYPE )                              \
-{                                                                          \
-  const mlib_s16 *c0, *c1, *c2, *c3;                                       \
-  TABLE_TYPE *table = s->table;                                            \
-  mlib_s32 bits = s->bits;                                                 \
-  mlib_s32 nbits = 16 - bits;                                              \
-  mlib_s32 mask = ~( ( 1 << nbits ) - 1 );                                 \
-  mlib_s32 j;                                                              \
-                                                                           \
-  c0 = src;                                                                \
-  c1 = src + 1;                                                            \
-  c2 = src + 2;                                                            \
-  c3 = src + 3;                                                            \
-                                                                           \
-  switch( bits )                                                           \
-  {                                                                        \
-    case 1:                                                                \
-    case 2:                                                                \
-    case 3:                                                                \
-    {                                                                      \
-      mlib_s32 bits0 = 16 - bits;                                          \
-      mlib_s32 bits1 = bits0 - bits;                                       \
-      mlib_s32 bits2 = bits1 - bits;                                       \
-      mlib_s32 bits3 = bits2 - bits;                                       \
-                                                                           \
-      for( j = 0; j < length; j++ )                                        \
-      {                                                                    \
-        dst[ j ] = table[ ( ( ( *c0 - MLIB_S16_MIN ) & mask ) >> bits3 ) | \
-          ( ( ( *c1 - MLIB_S16_MIN ) & mask ) >> bits2 ) |                 \
-          ( ( ( *c2 - MLIB_S16_MIN ) & mask ) >> bits1 ) |                 \
-          ( ( ( *c3 - MLIB_S16_MIN ) & mask ) >> bits0 ) ];                \
-                                                                           \
-        c0 += 4;                                                           \
-        c1 += 4;                                                           \
-        c2 += 4;                                                           \
-        c3 += 4;                                                           \
-      }                                                                    \
-      break;                                                               \
-    }                                                                      \
-    case 4:                                                                \
-    {                                                                      \
-      for( j = 0; j < length; j++ )                                        \
-      {                                                                    \
-        dst[ j ] = table[ ( ( *c0 - MLIB_S16_MIN ) & mask ) |              \
-          ( ( ( *c1 - MLIB_S16_MIN ) & mask ) >> 4 ) |                     \
-          ( ( ( *c2 - MLIB_S16_MIN ) & mask ) >> 8 ) |                     \
-          ( ( ( *c3 - MLIB_S16_MIN ) & mask ) >> 12 ) ];                   \
-                                                                           \
-        c0 += 4;                                                           \
-        c1 += 4;                                                           \
-        c2 += 4;                                                           \
-        c3 += 4;                                                           \
-      }                                                                    \
-      break;                                                               \
-    }                                                                      \
-    case 5:                                                                \
-    {                                                                      \
-      for( j = 0; j < length; j++ )                                        \
-      {                                                                    \
-        dst[ j ] = table[ ( ( ( *c0 - MLIB_S16_MIN ) & mask ) << 4 ) |     \
-          ( ( ( *c1 - MLIB_S16_MIN ) & mask ) >> 1 ) |                     \
-          ( ( ( *c2 - MLIB_S16_MIN ) & mask ) >> 6 ) |                     \
-          ( ( ( *c3 - MLIB_S16_MIN ) & mask ) >> 11 ) ];                   \
-                                                                           \
-        c0 += 4;                                                           \
-        c1 += 4;                                                           \
-        c2 += 4;                                                           \
-        c3 += 4;                                                           \
-      }                                                                    \
-      break;                                                               \
-    }                                                                      \
-    case 6:                                                                \
-    case 7:                                                                \
-    {                                                                      \
-      mlib_s32 bits0 = 16 - bits;                                          \
-      mlib_s32 bits1 = bits0 - bits;                                       \
-      mlib_s32 bits3 = bits * 4 - 16;                                      \
-      mlib_s32 bits2 = bits3 - bits;                                       \
-                                                                           \
-      for( j = 0; j < length; j++ )                                        \
-      {                                                                    \
-        dst[ j ] = table[ ( ( ( *c0 - MLIB_S16_MIN ) & mask ) << bits3 ) | \
-          ( ( ( *c1 - MLIB_S16_MIN ) & mask ) << bits2 ) |                 \
-          ( ( ( *c2 - MLIB_S16_MIN ) & mask ) >> bits1 ) |                 \
-          ( ( ( *c3 - MLIB_S16_MIN ) & mask ) >> bits0 ) ];                \
-                                                                           \
-        c0 += 4;                                                           \
-        c1 += 4;                                                           \
-        c2 += 4;                                                           \
-        c3 += 4;                                                           \
-      }                                                                    \
-      break;                                                               \
-    }                                                                      \
-    case 8:                                                                \
-    {                                                                      \
-      for( j = 0; j < length; j++ )                                        \
-      {                                                                    \
-        dst[ j ] = table[ ( ( ( *c0 - MLIB_S16_MIN ) & mask ) << 16 ) |    \
-          ( ( ( *c1 - MLIB_S16_MIN ) & mask ) << 8 ) |                     \
-          ( ( *c2 - MLIB_S16_MIN ) & mask ) |                              \
-          ( ( ( *c3 - MLIB_S16_MIN ) & mask ) >> 8 ) ];                    \
-                                                                           \
-        c0 += 4;                                                           \
-        c1 += 4;                                                           \
-        c2 += 4;                                                           \
-        c3 += 4;                                                           \
-      }                                                                    \
-      break;                                                               \
-    }                                                                      \
-    /* Other cases may not be considered as the table size will be more    \
-       than 2^32 */                                                        \
-  }                                                                        \
-}
-
-/***************************************************************/
-#define BINARY_TREE_SEARCH_RIGHT( POSITION, COLOR_MAX, SHIFT )  \
-{                                                               \
-  if( ( distance >= ( ( ( position[ POSITION ] + current_size - \
-    c[ POSITION ] ) * ( position[ POSITION ] + current_size -   \
-    c[ POSITION ] ) ) >> SHIFT ) ) &&                           \
-    ( position[ POSITION ] + current_size != COLOR_MAX ) )      \
-    continue_up = 1;                                            \
-}
-
-/***************************************************************/
-#define BINARY_TREE_EXPLORE_RIGHT_3( POSITION, COLOR_MAX, IMAGE_TYPE,    \
-  FIRST_NEIBOUR, SECOND_NEIBOUR, SUBSTRACTION, SHIFT )                   \
-{                                                                        \
-  if( distance >= ( ( ( position[ POSITION ] + current_size -            \
-    c[ POSITION ] ) * ( position[ POSITION ] +                           \
-      current_size - c[ POSITION ] ) ) >> SHIFT ) )                      \
-  {                                                                      \
-    if( distance < ( ( ( COLOR_MAX - c[ POSITION ] ) *                   \
-      ( COLOR_MAX - c[ POSITION ] ) ) >> SHIFT ) )                       \
-    {                                                                    \
-      if( distance < ( ( ( position[ POSITION ] +                        \
-        current_size * 2 - c[ POSITION ] ) *                             \
-        ( position[ POSITION ] + current_size * 2 -                      \
-          c[ POSITION ] ) ) >> SHIFT ) )                                 \
-      {                                                                  \
-        /* Check only a part of quadrant */                              \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 1;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 1;                           \
-        check_corner += 1;                                               \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_3( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Only a part of quadrant needs checking */                   \
-          distance =                                                     \
-            mlib_search_quadrant_part_to_left_##IMAGE_TYPE##_3(          \
-              node->contents.quadrants[ qq ],                            \
-              distance, &found_color, c, p,                              \
-              position[ POSITION ] + current_size, pass - 1, POSITION ); \
-      }                                                                  \
-      else /* Check whole quadrant */                                    \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 2;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 2;                           \
-        check_corner += 2;                                               \
-        continue_up = 1;                                                 \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_3( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Here is a full node. Just explore it */                     \
-          distance = mlib_search_quadrant_##IMAGE_TYPE##_3(              \
-            node->contents.quadrants[ qq ],                              \
-            distance, &found_color, c[ 0 ], c[ 1 ], c[ 2 ], p );         \
-      }                                                                  \
-    }                                                                    \
-    else /* Cell is on the edge of the space */                          \
-    {                                                                    \
-      if( position[ POSITION ] + current_size * 2 ==                     \
-        COLOR_MAX )                                                      \
-      {                                                                  \
-        /* Check only a part of quadrant */                              \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 1;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 1;                           \
-        check_corner += 1;                                               \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_3( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Only a part of quadrant needs checking */                   \
-          distance =                                                     \
-            mlib_search_quadrant_part_to_left_##IMAGE_TYPE##_3(          \
-              node->contents.quadrants[ qq ],                            \
-              distance, &found_color, c, p,                              \
-              position[ POSITION ] + current_size,                       \
-              pass - 1, POSITION );                                      \
-      }                                                                  \
-      else /* Check whole quadrant */                                    \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 2;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 2;                           \
-        check_corner += 2;                                               \
-        continue_up = 1;                                                 \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_3( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Here is a full node. Just explore it */                     \
-          distance = mlib_search_quadrant_##IMAGE_TYPE##_3(              \
-            node->contents.quadrants[ qq ],                              \
-            distance, &found_color, c[ 0 ], c[ 1 ], c[ 2 ], p );         \
-      }                                                                  \
-    }                                                                    \
-  }                                                                      \
-}
-
-/***************************************************************/
-#define BINARY_TREE_EXPLORE_RIGHT_4( POSITION, COLOR_MAX, IMAGE_TYPE,    \
-  FIRST_NEIBOUR, SECOND_NEIBOUR, THIRD_NEIBOUR, SUBSTRACTION, SHIFT )    \
-{                                                                        \
-  if( distance >= ( ( ( position[ POSITION ] + current_size -            \
-    c[ POSITION ] ) * ( position[ POSITION ] +                           \
-      current_size - c[ POSITION ] ) ) >> SHIFT ) )                      \
-  {                                                                      \
-    if( distance < ( ( ( COLOR_MAX - c[ POSITION ] ) *                   \
-      ( COLOR_MAX - c[ POSITION ] ) ) >> SHIFT ) )                       \
-    {                                                                    \
-      if( distance < ( ( ( position[ POSITION ] +                        \
-        current_size * 2 - c[ POSITION ] ) *                             \
-        ( position[ POSITION ] + current_size * 2 -                      \
-          c[ POSITION ] ) ) >> SHIFT ) )                                 \
-      {                                                                  \
-        /* Check only a part of quadrant */                              \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 1;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 1;                           \
-        check_neibours[ THIRD_NEIBOUR ] += 1;                            \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_4( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, c[ 3 ],            \
-            p[ 3 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Only a part of quadrant needs checking */                   \
-          distance =                                                     \
-            mlib_search_quadrant_part_to_left_##IMAGE_TYPE##_4(          \
-              node->contents.quadrants[ qq ],                            \
-              distance, &found_color, c, p,                              \
-              position[ POSITION ] + current_size, pass - 1, POSITION ); \
-      }                                                                  \
-      else /* Check whole quadrant */                                    \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 2;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 2;                           \
-        check_neibours[ THIRD_NEIBOUR ] += 2;                            \
-        continue_up = 1;                                                 \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_4( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, c[ 3 ],            \
-            p[ 3 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Here is a full node. Just explore it */                     \
-          distance = mlib_search_quadrant_##IMAGE_TYPE##_4(              \
-            node->contents.quadrants[ qq ],                              \
-            distance, &found_color, c[ 0 ], c[ 1 ], c[ 2 ], c[ 3 ], p ); \
-      }                                                                  \
-    }                                                                    \
-    else /* Cell is on the edge of the space */                          \
-    {                                                                    \
-      if( position[ POSITION ] + current_size * 2 ==                     \
-        COLOR_MAX )                                                      \
-      {                                                                  \
-        /* Check only a part of quadrant */                              \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 1;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 1;                           \
-        check_neibours[ THIRD_NEIBOUR ] += 1;                            \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_4( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, c[ 3 ],            \
-            p[ 3 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Only a part of quadrant needs checking */                   \
-          distance =                                                     \
-            mlib_search_quadrant_part_to_left_##IMAGE_TYPE##_4(          \
-              node->contents.quadrants[ qq ],                            \
-              distance, &found_color, c, p,                              \
-              position[ POSITION ] + current_size,                       \
-              pass - 1, POSITION );                                      \
-      }                                                                  \
-      else /* Check whole quadrant */                                    \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 2;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 2;                           \
-        check_neibours[ THIRD_NEIBOUR ] += 2;                            \
-        continue_up = 1;                                                 \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_4( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, c[ 3 ],            \
-            p[ 3 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Here is a full node. Just explore it */                     \
-          distance = mlib_search_quadrant_##IMAGE_TYPE##_4(              \
-            node->contents.quadrants[ qq ],                              \
-            distance, &found_color, c[ 0 ], c[ 1 ], c[ 2 ], c[ 3 ], p ); \
-      }                                                                  \
-    }                                                                    \
-  }                                                                      \
-}
-
-/***************************************************************/
-#define BINARY_TREE_SEARCH_LEFT( POSITION, SHIFT )                \
-{                                                                 \
-  if( ( distance > ( ( ( position[ POSITION ] - c[ POSITION ] ) * \
-    ( position[ POSITION ] - c[ POSITION ] ) ) >> SHIFT ) )  &&   \
-    position[ POSITION ] )                                        \
-    continue_up = 1;                                              \
-}
-
-/***************************************************************/
-#define BINARY_TREE_EXPLORE_LEFT_3( POSITION, IMAGE_TYPE,                \
-  FIRST_NEIBOUR, SECOND_NEIBOUR, SUBSTRACTION, SHIFT )                   \
-{                                                                        \
-  if( distance >                                                         \
-    ( ( ( c[ POSITION ] - position[ POSITION ] ) *                       \
-    ( c[ POSITION ] - position[ POSITION ] ) ) >> SHIFT ) )              \
-  {                                                                      \
-    if( distance <= ( ( c[ POSITION ] * c[ POSITION ] ) >> SHIFT ) )     \
-    {                                                                    \
-      if( distance <= ( ( ( c[ POSITION ] + current_size -               \
-        position[ POSITION ] ) *                                         \
-        ( c[ POSITION ] + current_size -                                 \
-          position[ POSITION ] ) ) >> SHIFT ) )                          \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 1;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 1;                           \
-        check_corner += 1;                                               \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_3( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Only a part of quadrant needs checking */                   \
-          distance =                                                     \
-            mlib_search_quadrant_part_to_right_##IMAGE_TYPE##_3(         \
-              node->contents.quadrants[ qq ],                            \
-              distance, &found_color, c, p,                              \
-              position[ POSITION ] - current_size, pass - 1, POSITION ); \
-      }                                                                  \
-      else /* Check whole quadrant */                                    \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 2;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 2;                           \
-        check_corner += 2;                                               \
-        continue_up = 1;                                                 \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_3( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Here is a full node. Just explore it */                     \
-          distance = mlib_search_quadrant_##IMAGE_TYPE##_3(              \
-            node->contents.quadrants[ qq ],                              \
-            distance, &found_color, c[ 0 ], c[ 1 ], c[ 2 ], p );         \
-      }                                                                  \
-    }                                                                    \
-    else                                                                 \
-    {                                                                    \
-      if( !( position[ POSITION ] - current_size ) )                     \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 1;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 1;                           \
-        check_corner += 1;                                               \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_3( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Only a part of quadrant needs checking */                   \
-          distance =                                                     \
-            mlib_search_quadrant_part_to_right_##IMAGE_TYPE##_3(         \
-              node->contents.quadrants[ qq ],                            \
-              distance, &found_color, c, p,                              \
-              position[ POSITION ] - current_size, pass - 1, POSITION ); \
-      }                                                                  \
-      else                                                               \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 2;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 2;                           \
-        check_corner += 2;                                               \
-        continue_up = 1;                                                 \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_3( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Here is a full node. Just explore it */                     \
-          distance = mlib_search_quadrant_##IMAGE_TYPE##_3(              \
-            node->contents.quadrants[ qq ],                              \
-            distance, &found_color, c[ 0 ], c[ 1 ], c[ 2 ], p );         \
-      }                                                                  \
-    }                                                                    \
-  }                                                                      \
-}
-
-/***************************************************************/
-#define BINARY_TREE_EXPLORE_LEFT_4( POSITION, IMAGE_TYPE,                \
-  FIRST_NEIBOUR, SECOND_NEIBOUR, THIRD_NEIBOUR, SUBSTRACTION, SHIFT )    \
-{                                                                        \
-  if( distance >                                                         \
-    ( ( ( c[ POSITION ] - position[ POSITION ] ) *                       \
-    ( c[ POSITION ] - position[ POSITION ] ) ) >> SHIFT ) )              \
-  {                                                                      \
-    if( distance <= ( ( c[ POSITION ] * c[ POSITION ] ) >> SHIFT ) )     \
-    {                                                                    \
-      if( distance <= ( ( ( c[ POSITION ] + current_size -               \
-        position[ POSITION ] ) *                                         \
-        ( c[ POSITION ] + current_size -                                 \
-          position[ POSITION ] ) ) >> SHIFT ) )                          \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 1;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 1;                           \
-        check_neibours[ THIRD_NEIBOUR ] += 1;                            \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_4( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, c[ 3 ],            \
-            p[ 3 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Only a part of quadrant needs checking */                   \
-          distance =                                                     \
-            mlib_search_quadrant_part_to_right_##IMAGE_TYPE##_4(         \
-              node->contents.quadrants[ qq ],                            \
-              distance, &found_color, c, p,                              \
-              position[ POSITION ] - current_size, pass - 1, POSITION ); \
-      }                                                                  \
-      else /* Check whole quadrant */                                    \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 2;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 2;                           \
-        check_neibours[ THIRD_NEIBOUR ] += 2;                            \
-        continue_up = 1;                                                 \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_4( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, c[ 3 ],            \
-            p[ 3 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Here is a full node. Just explore it */                     \
-          distance = mlib_search_quadrant_##IMAGE_TYPE##_4(              \
-            node->contents.quadrants[ qq ],                              \
-            distance, &found_color, c[ 0 ], c[ 1 ], c[ 2 ], c[ 3 ], p ); \
-      }                                                                  \
-    }                                                                    \
-    else                                                                 \
-    {                                                                    \
-      if( !( position[ POSITION ] - current_size ) )                     \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 1;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 1;                           \
-        check_neibours[ THIRD_NEIBOUR ] += 1;                            \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_4( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, c[ 3 ],            \
-            p[ 3 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Only a part of quadrant needs checking */                   \
-          distance =                                                     \
-            mlib_search_quadrant_part_to_right_##IMAGE_TYPE##_4(         \
-              node->contents.quadrants[ qq ],                            \
-              distance, &found_color, c, p,                              \
-              position[ POSITION ] - current_size, pass - 1, POSITION ); \
-      }                                                                  \
-      else                                                               \
-      {                                                                  \
-        mlib_s32 qq = q ^ ( 1 << POSITION );                             \
-                                                                         \
-        check_neibours[ FIRST_NEIBOUR ] += 2;                            \
-        check_neibours[ SECOND_NEIBOUR ] += 2;                           \
-        check_neibours[ THIRD_NEIBOUR ] += 2;                            \
-        continue_up = 1;                                                 \
-        if( node->tag & ( 1 << qq ) )                                    \
-        {                                                                \
-          /* Here is another color cell.                                 \
-             Check the distance */                                       \
-          mlib_s32 new_found_color =                                     \
-            node->contents.index[ qq ];                                  \
-          mlib_u32 newdistance = FIND_DISTANCE_4( c[ 0 ],                \
-            p[ 0 ][ new_found_color ] - SUBSTRACTION, c[ 1 ],            \
-            p[ 1 ][ new_found_color ] - SUBSTRACTION, c[ 2 ],            \
-            p[ 2 ][ new_found_color ] - SUBSTRACTION, c[ 3 ],            \
-            p[ 3 ][ new_found_color ] - SUBSTRACTION, SHIFT );           \
-                                                                         \
-          if( newdistance < distance )                                   \
-          {                                                              \
-            found_color = new_found_color;                               \
-            distance = newdistance;                                      \
-          }                                                              \
-        }                                                                \
-        else if( node->contents.quadrants[ qq ] )                        \
-          /* Here is a full node. Just explore it */                     \
-          distance = mlib_search_quadrant_##IMAGE_TYPE##_4(              \
-            node->contents.quadrants[ qq ],                              \
-            distance, &found_color, c[ 0 ], c[ 1 ], c[ 2 ], c[ 3 ], p ); \
-      }                                                                  \
-    }                                                                    \
-  }                                                                      \
-}
-
-/***************************************************************/
-#define CHECK_QUADRANT_U8_3( qq )                               \
-{                                                               \
-  if( node->tag & ( 1 << qq ) )                                 \
-  {                                                             \
-    /* Here is another color cell. Check the distance */        \
-    mlib_s32 new_found_color = node->contents.index[ qq ];      \
-    mlib_u32 newdistance = FIND_DISTANCE_3( c[ 0 ],             \
-      p[ 0 ][ new_found_color ], c[ 1 ],                        \
-      p[ 1 ][ new_found_color ], c[ 2 ],                        \
-      p[ 2 ][ new_found_color ], 0 );                           \
-                                                                \
-    if( newdistance < distance )                                \
-    {                                                           \
-      found_color = new_found_color;                            \
-      distance = newdistance;                                   \
-    }                                                           \
-  }                                                             \
-  else if( node->contents.quadrants[ qq ] )                     \
-    /* Here is a full node. Just explore it all */              \
-    distance = mlib_search_quadrant_U8_3(                       \
-      node->contents.quadrants[ qq ], distance, &found_color,   \
-      c[ 0 ], c[ 1 ], c[ 2 ], p );                              \
-/* Else there is just an empty cell */                          \
-}
-
-/***************************************************************/
-#define CHECK_QUADRANT_S16_3( qq )                              \
-{                                                               \
-  if( node->tag & ( 1 << qq ) )                                 \
-  {                                                             \
-    /* Here is another color cell. Check the distance */        \
-    mlib_s32 new_found_color = node->contents.index[ qq ];      \
-    mlib_u32 palc0, palc1, palc2, newdistance;                  \
-                                                                \
-    palc0 = p[ 0 ][ new_found_color ] - MLIB_S16_MIN;           \
-    palc1 = p[ 1 ][ new_found_color ] - MLIB_S16_MIN;           \
-    palc2 = p[ 2 ][ new_found_color ] - MLIB_S16_MIN;           \
-                                                                \
-    newdistance = FIND_DISTANCE_3( c[ 0 ], palc0,               \
-      c[ 1 ], palc1,                                            \
-      c[ 2 ], palc2, 2 );                                       \
-                                                                \
-    if( newdistance < distance )                                \
-    {                                                           \
-      found_color = new_found_color;                            \
-      distance = newdistance;                                   \
-    }                                                           \
-  }                                                             \
-  else if( node->contents.quadrants[ qq ] )                     \
-    /* Here is a full node. Just explore it all */              \
-    distance = mlib_search_quadrant_S16_3(                      \
-      node->contents.quadrants[ qq ], distance, &found_color,   \
-      c[ 0 ], c[ 1 ], c[ 2 ], p );                              \
-/* Else there is just an empty cell */                          \
-}
-
-/***************************************************************/
-#define BINARY_TREE_SEARCH_3( SOURCE_IMAGE, POINTER_TYPE, BITS,              \
-  COLOR_MAX, SUBTRACTION, POINTER_SHIFT, STEP, SHIFT )                       \
-{                                                                            \
-  const POINTER_TYPE *channels[ 3 ], *p[ 3 ];                                \
-  mlib_u32 c[ 3 ];                                                           \
-  mlib_s32 j;                                                                \
-                                                                             \
-  p[ 0 ] = s->lut[ 0 ];                                                      \
-  p[ 1 ] = s->lut[ 1 ];                                                      \
-  p[ 2 ] = s->lut[ 2 ];                                                      \
-  channels[ 0 ] = src + POINTER_SHIFT;                                       \
-  channels[ 1 ] = src + 1 + POINTER_SHIFT;                                   \
-  channels[ 2 ] = src + 2 + POINTER_SHIFT;                                   \
-                                                                             \
-  for( j = 0; j < length; j++ )                                              \
-  {                                                                          \
-    mlib_s32 pass = BITS - 1;                                                \
-    mlib_u32 position[ 3 ] = { 0, 0, 0 };                                    \
-    mlib_s32 we_found_it = 0;                                                \
-    struct lut_node_3 *node = s->table;                                      \
-    /* Stack pointer pointers to the first free element of stack. */         \
-    /* The node we are in is in the `node' */                                \
-    struct                                                                   \
-    {                                                                        \
-      struct lut_node_3 *node;                                               \
-      mlib_s32 q;                                                            \
-    } stack[ BITS ];                                                         \
-    mlib_s32 stack_pointer = 0;                                              \
-                                                                             \
-    c[ 0 ] = *channels[ 0 ] - SUBTRACTION;                                   \
-    c[ 1 ] = *channels[ 1 ] - SUBTRACTION;                                   \
-    c[ 2 ] = *channels[ 2 ] - SUBTRACTION;                                   \
-                                                                             \
-    do                                                                       \
-    {                                                                        \
-      mlib_s32 q;                                                            \
-      mlib_u32 current_size = 1 << pass;                                     \
-                                                                             \
-      q = ( ( c[ 0 ] >> pass ) & 1 ) |                                       \
-        ( ( ( c[ 1 ] << 1 ) >> pass ) & 2 ) |                                \
-        ( ( ( c[ 2 ] << 2 ) >> pass ) & 4 );                                 \
-                                                                             \
-      position[ 0 ] |= c[ 0 ] & current_size;                                \
-      position[ 1 ] |= c[ 1 ] & current_size;                                \
-      position[ 2 ] |= c[ 2 ] & current_size;                                \
-                                                                             \
-      if( node->tag & ( 1 << q ) )                                           \
-      {                                                                      \
-        /*                                                                   \
-          Here is a cell with one color. We need to be sure it's             \
-          the one that is the closest to our color                           \
-        */                                                                   \
-        mlib_s32 palindex = node->contents.index[ q ];                       \
-        mlib_u32 palc[ 3 ];                                                  \
-        mlib_s32 identical;                                                  \
-                                                                             \
-        palc[ 0 ] = p[ 0 ][ palindex ] - SUBTRACTION;                        \
-        palc[ 1 ] = p[ 1 ][ palindex ] - SUBTRACTION;                        \
-        palc[ 2 ] = p[ 2 ][ palindex ] - SUBTRACTION;                        \
-                                                                             \
-        identical = ( palc[ 0 ] - c[ 0 ] ) | ( palc[ 1 ] - c[ 1 ] ) |        \
-          ( palc[ 2 ] - c[ 2 ] );                                            \
-                                                                             \
-        if( !identical || BITS - pass == bits )                              \
-        {                                                                    \
-          /* Oh, here it is :) */                                            \
-          dst[ j ] = palindex + s->offset;                                   \
-          we_found_it = 1;                                                   \
-        }                                                                    \
-        else                                                                 \
-        {                                                                    \
-          mlib_u32 distance;                                                 \
-          /* First index is the channel, second is the number of the         \
-             side */                                                         \
-          mlib_s32 found_color;                                              \
-          mlib_s32 continue_up;                                              \
-                                                                             \
-          distance = FIND_DISTANCE_3( c[ 0 ], palc[ 0 ],                     \
-            c[ 1 ], palc[ 1 ], c[ 2 ], palc[ 2 ], SHIFT );                   \
-          found_color = palindex;                                            \
-                                                                             \
-          do                                                                 \
-          {                                                                  \
-            mlib_s32 check_corner;                                           \
-                                                                             \
-            /*                                                               \
-              Neibours are enumerated in a cicle:                            \
-              0 - between quadrants 0 and 1,                                 \
-              1 - between quadrants 1 and 2 and                              \
-              2 - between quadrants 2 and 0                                  \
-            */                                                               \
-            mlib_s32 check_neibours[ 3 ];                                    \
-                                                                             \
-            /*                                                               \
-              Others are three two neibour quadrants                         \
-                                                                             \
-              Side number is [ <number of the coordinate >][ <the bit        \
-              in the quadrant number of the corner, corresponding to         \
-              this coordinate> ], e.g. 2 is 0..010b, so the sides it has     \
-              near are:                                                      \
-              [ 0 (coordinate number) ][ 0 (bit 0 in the number) ]           \
-              [ 1 (coordinate number) ][ 1 (bit 1 in the number) ]           \
-                                                                             \
-              Now we can look in the three nearest quadrants. Do             \
-              we really need it ? Check it.                                  \
-            */                                                               \
-                                                                             \
-            check_corner = check_neibours[ 0 ] = check_neibours[ 1 ] =       \
-              check_neibours[ 2 ] = 0;                                       \
-            continue_up = 0;                                                 \
-                                                                             \
-            if( q & 1 )                                                      \
-            {                                                                \
-              BINARY_TREE_EXPLORE_LEFT_3( 0, SOURCE_IMAGE, 2, 0,             \
-                SUBTRACTION, SHIFT );                                        \
-            }                                                                \
-            else                                                             \
-            {                                                                \
-              BINARY_TREE_EXPLORE_RIGHT_3( 0, COLOR_MAX, SOURCE_IMAGE, 2, 0, \
-                SUBTRACTION, SHIFT );                                        \
-            }                                                                \
-                                                                             \
-            if( q & 2 )                                                      \
-            {                                                                \
-              BINARY_TREE_EXPLORE_LEFT_3( 1, SOURCE_IMAGE, 0, 1,             \
-                SUBTRACTION, SHIFT );                                        \
-            }                                                                \
-            else                                                             \
-            {                                                                \
-              BINARY_TREE_EXPLORE_RIGHT_3( 1, COLOR_MAX, SOURCE_IMAGE, 0, 1, \
-                SUBTRACTION, SHIFT );                                        \
-            }                                                                \
-                                                                             \
-            if( q & 4 )                                                      \
-            {                                                                \
-              BINARY_TREE_EXPLORE_LEFT_3( 2, SOURCE_IMAGE, 1, 2,             \
-                SUBTRACTION, SHIFT );                                        \
-            }                                                                \
-            else                                                             \
-            {                                                                \
-              BINARY_TREE_EXPLORE_RIGHT_3( 2, COLOR_MAX, SOURCE_IMAGE, 1, 2, \
-                SUBTRACTION, SHIFT );                                        \
-            }                                                                \
-                                                                             \
-            if( check_neibours[ 0 ] >= 2 )                                   \
-            {                                                                \
-              mlib_s32 qq = q ^ 3;                                           \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_3( qq );                       \
-            }                                                                \
-                                                                             \
-            if( check_neibours[ 1 ] >= 2 )                                   \
-            {                                                                \
-              mlib_s32 qq = q ^ 6;                                           \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_3( qq );                       \
-            }                                                                \
-                                                                             \
-            if( check_neibours[ 2 ] >= 2 )                                   \
-            {                                                                \
-              mlib_s32 qq = q ^ 5;                                           \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_3( qq );                       \
-            }                                                                \
-                                                                             \
-            if( check_corner >= 3 )                                          \
-            {                                                                \
-              mlib_s32 qq = q ^ 7;                                           \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_3( qq );                       \
-            }                                                                \
-                                                                             \
-            if( q & 1 )                                                      \
-            {                                                                \
-              BINARY_TREE_SEARCH_RIGHT( 0, COLOR_MAX, SHIFT );               \
-            }                                                                \
-            else                                                             \
-            {                                                                \
-              BINARY_TREE_SEARCH_LEFT( 0, SHIFT );                           \
-            }                                                                \
-                                                                             \
-            if( q & 2 )                                                      \
-            {                                                                \
-              BINARY_TREE_SEARCH_RIGHT( 1, COLOR_MAX, SHIFT );               \
-            }                                                                \
-            else                                                             \
-            {                                                                \
-              BINARY_TREE_SEARCH_LEFT( 1, SHIFT );                           \
-            }                                                                \
-                                                                             \
-            if( q & 4 )                                                      \
-            {                                                                \
-              BINARY_TREE_SEARCH_RIGHT( 2, COLOR_MAX, SHIFT );               \
-            }                                                                \
-            else                                                             \
-            {                                                                \
-              BINARY_TREE_SEARCH_LEFT( 2, SHIFT );                           \
-            }                                                                \
-                                                                             \
-            position[ 0 ] &= ~( c[ 0 ] & current_size );                     \
-            position[ 1 ] &= ~( c[ 1 ] & current_size );                     \
-            position[ 2 ] &= ~( c[ 2 ] & current_size );                     \
-                                                                             \
-            current_size <<= 1;                                              \
-                                                                             \
-            pass++;                                                          \
-                                                                             \
-            stack_pointer--;                                                 \
-            q = stack[ stack_pointer ].q;                                    \
-            node = stack[ stack_pointer ].node;                              \
-          } while( continue_up );                                            \
-                                                                             \
-          dst[ j ] = found_color + s->offset;                                \
-                                                                             \
-          we_found_it = 1;                                                   \
-        }                                                                    \
-      }                                                                      \
-      else if( node->contents.quadrants[ q ] )                               \
-      {                                                                      \
-        /* Descend one level */                                              \
-        stack[ stack_pointer ].node = node;                                  \
-        stack[ stack_pointer++ ].q = q;                                      \
-        node = node->contents.quadrants[ q ];                                \
-      }                                                                      \
-      else                                                                   \
-      {                                                                      \
-        /* Found the empty quadrant. Look around */                          \
-        mlib_u32 distance = MLIB_U32_MAX;                                    \
-        mlib_s32 found_color;                                                \
-        mlib_s32 continue_up;                                                \
-                                                                             \
-        /*                                                                   \
-          As we had come to this level, it is warranted that there           \
-          are other points on this level near the empty quadrant             \
-        */                                                                   \
-        do                                                                   \
-        {                                                                    \
-          mlib_s32 check_corner;                                             \
-          mlib_s32 check_neibours[ 3 ];                                      \
-                                                                             \
-          check_corner = check_neibours[ 0 ] = check_neibours[ 1 ] =         \
-            check_neibours[ 2 ] = 0;                                         \
-          continue_up = 0;                                                   \
-                                                                             \
-          if( q & 1 )                                                        \
-          {                                                                  \
-            BINARY_TREE_EXPLORE_LEFT_3( 0, SOURCE_IMAGE, 2, 0,               \
-              SUBTRACTION, SHIFT );                                          \
-          }                                                                  \
-          else                                                               \
-          {                                                                  \
-            BINARY_TREE_EXPLORE_RIGHT_3( 0, COLOR_MAX, SOURCE_IMAGE, 2, 0,   \
-              SUBTRACTION, SHIFT );                                          \
-          }                                                                  \
-                                                                             \
-          if( q & 2 )                                                        \
-          {                                                                  \
-            BINARY_TREE_EXPLORE_LEFT_3( 1, SOURCE_IMAGE, 0, 1,               \
-              SUBTRACTION, SHIFT );                                          \
-          }                                                                  \
-          else                                                               \
-          {                                                                  \
-            BINARY_TREE_EXPLORE_RIGHT_3( 1, COLOR_MAX, SOURCE_IMAGE, 0, 1,   \
-              SUBTRACTION, SHIFT );                                          \
-          }                                                                  \
-                                                                             \
-          if( q & 4 )                                                        \
-          {                                                                  \
-            BINARY_TREE_EXPLORE_LEFT_3( 2, SOURCE_IMAGE, 1, 2,               \
-              SUBTRACTION, SHIFT );                                          \
-          }                                                                  \
-          else                                                               \
-          {                                                                  \
-            BINARY_TREE_EXPLORE_RIGHT_3( 2, COLOR_MAX, SOURCE_IMAGE, 1, 2,   \
-              SUBTRACTION, SHIFT );                                          \
-          }                                                                  \
-                                                                             \
-          if( check_neibours[ 0 ] >= 2 )                                     \
-          {                                                                  \
-            mlib_s32 qq = q ^ 3;                                             \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_3( qq );                         \
-          }                                                                  \
-                                                                             \
-          if( check_neibours[ 1 ] >= 2 )                                     \
-          {                                                                  \
-            mlib_s32 qq = q ^ 6;                                             \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_3( qq );                         \
-          }                                                                  \
-                                                                             \
-          if( check_neibours[ 2 ] >= 2 )                                     \
-          {                                                                  \
-            mlib_s32 qq = q ^ 5;                                             \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_3( qq );                         \
-          }                                                                  \
-                                                                             \
-          if( check_corner >= 3 )                                            \
-          {                                                                  \
-            mlib_s32 qq = q ^ 7;                                             \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_3( qq );                         \
-          }                                                                  \
-                                                                             \
-          if( q & 1 )                                                        \
-          {                                                                  \
-            BINARY_TREE_SEARCH_RIGHT( 0, COLOR_MAX, SHIFT );                 \
-          }                                                                  \
-          else                                                               \
-          {                                                                  \
-            BINARY_TREE_SEARCH_LEFT( 0, SHIFT );                             \
-          }                                                                  \
-                                                                             \
-          if( q & 2 )                                                        \
-          {                                                                  \
-            BINARY_TREE_SEARCH_RIGHT( 1, COLOR_MAX, SHIFT );                 \
-          }                                                                  \
-          else                                                               \
-          {                                                                  \
-            BINARY_TREE_SEARCH_LEFT( 1, SHIFT );                             \
-          }                                                                  \
-                                                                             \
-          if( q & 4 )                                                        \
-          {                                                                  \
-            BINARY_TREE_SEARCH_RIGHT( 2, COLOR_MAX, SHIFT );                 \
-          }                                                                  \
-          else                                                               \
-          {                                                                  \
-            BINARY_TREE_SEARCH_LEFT( 2, SHIFT );                             \
-          }                                                                  \
-                                                                             \
-          position[ 0 ] &= ~( c[ 0 ] & current_size );                       \
-          position[ 1 ] &= ~( c[ 1 ] & current_size );                       \
-          position[ 2 ] &= ~( c[ 2 ] & current_size );                       \
-                                                                             \
-          current_size <<= 1;                                                \
-                                                                             \
-          pass++;                                                            \
-                                                                             \
-          stack_pointer--;                                                   \
-          q = stack[ stack_pointer ].q;                                      \
-          node = stack[ stack_pointer ].node;                                \
-        } while( continue_up );                                              \
-                                                                             \
-        dst[ j ] = found_color + s->offset;                                  \
-        we_found_it = 1;                                                     \
-      }                                                                      \
-                                                                             \
-      pass--;                                                                \
-                                                                             \
-    } while( !we_found_it );                                                 \
-                                                                             \
-    channels[ 0 ] += STEP;                                                   \
-    channels[ 1 ] += STEP;                                                   \
-    channels[ 2 ] += STEP;                                                   \
-  }                                                                          \
-}
-
-/***************************************************************/
-#define CHECK_QUADRANT_U8_4( qq )                               \
-{                                                               \
-  if( node->tag & ( 1 << qq ) )                                 \
-  {                                                             \
-    /* Here is another color cell. Check the distance */        \
-    mlib_s32 new_found_color = node->contents.index[ qq ];      \
-    mlib_u32 newdistance = FIND_DISTANCE_4( c[ 0 ],             \
-      p[ 0 ][ new_found_color ], c[ 1 ],                        \
-      p[ 1 ][ new_found_color ], c[ 2 ],                        \
-      p[ 2 ][ new_found_color ], c[ 3 ],                        \
-      p[ 3 ][ new_found_color ], 0 );                           \
-                                                                \
-    if( newdistance < distance )                                \
-    {                                                           \
-      found_color = new_found_color;                            \
-      distance = newdistance;                                   \
-    }                                                           \
-  }                                                             \
-  else if( node->contents.quadrants[ qq ] )                     \
-    /* Here is a full node. Just explore it all */              \
-    distance = mlib_search_quadrant_U8_4(                       \
-      node->contents.quadrants[ qq ], distance, &found_color,   \
-      c[ 0 ], c[ 1 ], c[ 2 ], c[ 3 ], p );                      \
-/* Else there is just an empty cell */                          \
-}
-
-/***************************************************************/
-#define CHECK_QUADRANT_S16_4( qq )                              \
-{                                                               \
-  if( node->tag & ( 1 << qq ) )                                 \
-  {                                                             \
-    /* Here is another color cell. Check the distance */        \
-    mlib_s32 new_found_color = node->contents.index[ qq ];      \
-    mlib_u32 palc0, palc1, palc2, palc3, newdistance;           \
-                                                                \
-    palc0 = p[ 0 ][ new_found_color ] - MLIB_S16_MIN;           \
-    palc1 = p[ 1 ][ new_found_color ] - MLIB_S16_MIN;           \
-    palc2 = p[ 2 ][ new_found_color ] - MLIB_S16_MIN;           \
-    palc3 = p[ 3 ][ new_found_color ] - MLIB_S16_MIN;           \
-                                                                \
-    newdistance = FIND_DISTANCE_4( c[ 0 ], palc0,               \
-      c[ 1 ], palc1,                                            \
-      c[ 2 ], palc2,                                            \
-      c[ 3 ], palc3, 2 );                                       \
-                                                                \
-    if( newdistance < distance )                                \
-    {                                                           \
-      found_color = new_found_color;                            \
-      distance = newdistance;                                   \
-    }                                                           \
-  }                                                             \
-  else if( node->contents.quadrants[ qq ] )                     \
-    /* Here is a full node. Just explore it all */              \
-    distance = mlib_search_quadrant_S16_4(                      \
-      node->contents.quadrants[ qq ], distance, &found_color,   \
-      c[ 0 ], c[ 1 ], c[ 2 ], c[ 3 ], p );                      \
-/* Else there is just an empty cell */                          \
-}
-
-/***************************************************************/
-#define BINARY_TREE_SEARCH_4( SOURCE_IMAGE, POINTER_TYPE, BITS,               \
-  COLOR_MAX, SUBTRACTION, SHIFT )                                             \
-{                                                                             \
-  const POINTER_TYPE *channels[ 4 ], *p[ 4 ];                                 \
-  mlib_u32 c[ 4 ];                                                            \
-  mlib_s32 j;                                                                 \
-                                                                              \
-  p[ 0 ] = s->lut[ 0 ];                                                       \
-  p[ 1 ] = s->lut[ 1 ];                                                       \
-  p[ 2 ] = s->lut[ 2 ];                                                       \
-  p[ 3 ] = s->lut[ 3 ];                                                       \
-  channels[ 0 ] = src;                                                        \
-  channels[ 1 ] = src + 1;                                                    \
-  channels[ 2 ] = src + 2;                                                    \
-  channels[ 3 ] = src + 3;                                                    \
-                                                                              \
-  for( j = 0; j < length; j++ )                                               \
-  {                                                                           \
-    mlib_s32 pass = BITS - 1;                                                 \
-    mlib_u32 position[ 4 ] = { 0, 0, 0, 0 };                                  \
-    mlib_s32 we_found_it = 0;                                                 \
-    struct lut_node_4 *node = s->table;                                       \
-    /* Stack pointer pointers to the first free element of stack. */          \
-    /* The node we are in is in the `node' */                                 \
-    struct                                                                    \
-    {                                                                         \
-      struct lut_node_4 *node;                                                \
-      mlib_s32 q;                                                             \
-    } stack[ BITS ];                                                          \
-    mlib_s32 stack_pointer = 0;                                               \
-                                                                              \
-    c[ 0 ] = *channels[ 0 ] - SUBTRACTION;                                    \
-    c[ 1 ] = *channels[ 1 ] - SUBTRACTION;                                    \
-    c[ 2 ] = *channels[ 2 ] - SUBTRACTION;                                    \
-    c[ 3 ] = *channels[ 3 ] - SUBTRACTION;                                    \
-                                                                              \
-    do                                                                        \
-    {                                                                         \
-      mlib_s32 q;                                                             \
-      mlib_u32 current_size = 1 << pass;                                      \
-                                                                              \
-      q = ( ( c[ 0 ] >> pass ) & 1 ) |                                        \
-        ( ( ( c[ 1 ] << 1 ) >> pass ) & 2 ) |                                 \
-        ( ( ( c[ 2 ] << 2 ) >> pass ) & 4 ) |                                 \
-        ( ( ( c[ 3 ] << 3 ) >> pass ) & 8 );                                  \
-                                                                              \
-      position[ 0 ] |= c[ 0 ] & current_size;                                 \
-      position[ 1 ] |= c[ 1 ] & current_size;                                 \
-      position[ 2 ] |= c[ 2 ] & current_size;                                 \
-      position[ 3 ] |= c[ 3 ] & current_size;                                 \
-                                                                              \
-      if( node->tag & ( 1 << q ) )                                            \
-      {                                                                       \
-        /*                                                                    \
-          Here is a cell with one color. We need to be sure it's              \
-          the one that is the closest to our color                            \
-        */                                                                    \
-        mlib_s32 palindex = node->contents.index[ q ];                        \
-        mlib_u32 palc[ 4 ];                                                   \
-        mlib_s32 identical;                                                   \
-                                                                              \
-        palc[ 0 ] = p[ 0 ][ palindex ] - SUBTRACTION;                         \
-        palc[ 1 ] = p[ 1 ][ palindex ] - SUBTRACTION;                         \
-        palc[ 2 ] = p[ 2 ][ palindex ] - SUBTRACTION;                         \
-        palc[ 3 ] = p[ 3 ][ palindex ] - SUBTRACTION;                         \
-                                                                              \
-        identical = ( palc[ 0 ] - c[ 0 ] ) | ( palc[ 1 ] - c[ 1 ] ) |         \
-          ( palc[ 2 ] - c[ 2 ] ) | ( palc[ 3 ] - c[ 3 ] );                    \
-                                                                              \
-        if( !identical || BITS - pass == bits )                               \
-        {                                                                     \
-          /* Oh, here it is :) */                                             \
-          dst[ j ] = palindex + s->offset;                                    \
-          we_found_it = 1;                                                    \
-        }                                                                     \
-        else                                                                  \
-        {                                                                     \
-          mlib_u32 distance;                                                  \
-          /* First index is the channel, second is the number of the          \
-             side */                                                          \
-          mlib_s32 found_color;                                               \
-          mlib_s32 continue_up;                                               \
-                                                                              \
-          distance = FIND_DISTANCE_4( c[ 0 ], palc[ 0 ],                      \
-            c[ 1 ], palc[ 1 ], c[ 2 ], palc[ 2 ], c[ 3 ], palc[ 3 ], SHIFT ); \
-          found_color = palindex;                                             \
-                                                                              \
-          do                                                                  \
-          {                                                                   \
-            mlib_s32 check_corner;                                            \
-            mlib_s32 check_neibours[ 6 ];                                     \
-            mlib_s32 check_far_neibours[ 4 ];                                 \
-                                                                              \
-            /*                                                                \
-              Check neibours: quadrants that are different by 2 bits          \
-              from the quadrant, that we are in:                              \
-              3 -  0                                                          \
-              5 -  1                                                          \
-              6 -  2                                                          \
-              9 -  3                                                          \
-              10 - 4                                                          \
-              12 - 5                                                          \
-              Far quadrants: different by 3 bits:                             \
-              7  - 0                                                          \
-              11 - 1                                                          \
-              13 - 2                                                          \
-              14 - 3                                                          \
-            */                                                                \
-                                                                              \
-            check_neibours[ 0 ] = check_neibours[ 1 ] =                       \
-              check_neibours[ 2 ] = check_neibours[ 3 ] =                     \
-              check_neibours[ 4 ] = check_neibours[ 5 ] = 0;                  \
-            continue_up = 0;                                                  \
-                                                                              \
-            if( q & 1 )                                                       \
-            {                                                                 \
-              BINARY_TREE_EXPLORE_LEFT_4( 0, SOURCE_IMAGE, 0, 1, 3,           \
-                SUBTRACTION, SHIFT );                                         \
-            }                                                                 \
-            else                                                              \
-            {                                                                 \
-              BINARY_TREE_EXPLORE_RIGHT_4( 0, COLOR_MAX, SOURCE_IMAGE,        \
-                0, 1, 3, SUBTRACTION, SHIFT );                                \
-            }                                                                 \
-                                                                              \
-            if( q & 2 )                                                       \
-            {                                                                 \
-              BINARY_TREE_EXPLORE_LEFT_4( 1, SOURCE_IMAGE, 0, 2, 4,           \
-                SUBTRACTION, SHIFT );                                         \
-            }                                                                 \
-            else                                                              \
-            {                                                                 \
-              BINARY_TREE_EXPLORE_RIGHT_4( 1, COLOR_MAX, SOURCE_IMAGE,        \
-                0, 2, 4, SUBTRACTION, SHIFT );                                \
-            }                                                                 \
-                                                                              \
-            if( q & 4 )                                                       \
-            {                                                                 \
-              BINARY_TREE_EXPLORE_LEFT_4( 2, SOURCE_IMAGE, 1, 2, 5,           \
-                SUBTRACTION, SHIFT );                                         \
-            }                                                                 \
-            else                                                              \
-            {                                                                 \
-              BINARY_TREE_EXPLORE_RIGHT_4( 2, COLOR_MAX, SOURCE_IMAGE,        \
-                1, 2, 5, SUBTRACTION, SHIFT );                                \
-            }                                                                 \
-                                                                              \
-            if( q & 8 )                                                       \
-            {                                                                 \
-              BINARY_TREE_EXPLORE_LEFT_4( 3, SOURCE_IMAGE, 3, 4, 5,           \
-                SUBTRACTION, SHIFT );                                         \
-            }                                                                 \
-            else                                                              \
-            {                                                                 \
-              BINARY_TREE_EXPLORE_RIGHT_4( 3, COLOR_MAX, SOURCE_IMAGE,        \
-                3, 4, 5, SUBTRACTION, SHIFT );                                \
-            }                                                                 \
-                                                                              \
-            check_far_neibours[ 0 ] = check_neibours[ 0 ] +                   \
-              check_neibours[ 1 ] + check_neibours[ 2 ];                      \
-            check_far_neibours[ 1 ] = check_neibours[ 0 ] +                   \
-              check_neibours[ 3 ] + check_neibours[ 4 ];                      \
-            check_far_neibours[ 2 ] = check_neibours[ 1 ] +                   \
-              check_neibours[ 3 ] + check_neibours[ 5 ];                      \
-            check_far_neibours[ 3 ] = check_neibours[ 2 ] +                   \
-              check_neibours[ 4 ] + check_neibours[ 5 ];                      \
-                                                                              \
-            check_corner = check_far_neibours[ 0 ] +                          \
-              check_far_neibours[ 1 ] +                                       \
-              check_far_neibours[ 2 ] +                                       \
-              check_far_neibours[ 3 ];                                        \
-                                                                              \
-            if( check_neibours[ 0 ] >= 2 )                                    \
-            {                                                                 \
-              mlib_s32 qq = q ^ 3;                                            \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                        \
-            }                                                                 \
-                                                                              \
-            if( check_neibours[ 1 ] >= 2 )                                    \
-            {                                                                 \
-              mlib_s32 qq = q ^ 5;                                            \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                        \
-            }                                                                 \
-                                                                              \
-            if( check_neibours[ 2 ] >= 2 )                                    \
-            {                                                                 \
-              mlib_s32 qq = q ^ 6;                                            \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                        \
-            }                                                                 \
-                                                                              \
-            if( check_neibours[ 3 ] >= 2 )                                    \
-            {                                                                 \
-              mlib_s32 qq = q ^ 9;                                            \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                        \
-            }                                                                 \
-                                                                              \
-            if( check_neibours[ 4 ] >= 2 )                                    \
-            {                                                                 \
-              mlib_s32 qq = q ^ 10;                                           \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                        \
-            }                                                                 \
-                                                                              \
-            if( check_neibours[ 5 ] >= 2 )                                    \
-            {                                                                 \
-              mlib_s32 qq = q ^ 12;                                           \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                        \
-            }                                                                 \
-                                                                              \
-            if( check_far_neibours[ 0 ] >= 3 )                                \
-            {                                                                 \
-              mlib_s32 qq = q ^ 7;                                            \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                        \
-            }                                                                 \
-                                                                              \
-            if( check_far_neibours[ 1 ] >= 3 )                                \
-            {                                                                 \
-              mlib_s32 qq = q ^ 11;                                           \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                        \
-            }                                                                 \
-                                                                              \
-            if( check_far_neibours[ 2 ] >= 3 )                                \
-            {                                                                 \
-              mlib_s32 qq = q ^ 13;                                           \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                        \
-            }                                                                 \
-                                                                              \
-            if( check_far_neibours[ 3 ] >= 3 )                                \
-            {                                                                 \
-              mlib_s32 qq = q ^ 14;                                           \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                        \
-            }                                                                 \
-                                                                              \
-            if( check_corner >= 4 )                                           \
-            {                                                                 \
-              mlib_s32 qq = q ^ 15;                                           \
-              CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                        \
-            }                                                                 \
-                                                                              \
-            if( q & 1 )                                                       \
-            {                                                                 \
-              BINARY_TREE_SEARCH_RIGHT( 0, COLOR_MAX, SHIFT );                \
-            }                                                                 \
-            else                                                              \
-            {                                                                 \
-              BINARY_TREE_SEARCH_LEFT( 0, SHIFT );                            \
-            }                                                                 \
-                                                                              \
-            if( q & 2 )                                                       \
-            {                                                                 \
-              BINARY_TREE_SEARCH_RIGHT( 1, COLOR_MAX, SHIFT );                \
-            }                                                                 \
-            else                                                              \
-            {                                                                 \
-              BINARY_TREE_SEARCH_LEFT( 1, SHIFT );                            \
-            }                                                                 \
-                                                                              \
-            if( q & 4 )                                                       \
-            {                                                                 \
-              BINARY_TREE_SEARCH_RIGHT( 2, COLOR_MAX, SHIFT );                \
-            }                                                                 \
-            else                                                              \
-            {                                                                 \
-              BINARY_TREE_SEARCH_LEFT( 2, SHIFT );                            \
-            }                                                                 \
-                                                                              \
-            if( q & 8 )                                                       \
-            {                                                                 \
-              BINARY_TREE_SEARCH_RIGHT( 3, COLOR_MAX, SHIFT );                \
-            }                                                                 \
-            else                                                              \
-            {                                                                 \
-              BINARY_TREE_SEARCH_LEFT( 3, SHIFT );                            \
-            }                                                                 \
-                                                                              \
-            position[ 0 ] &= ~( c[ 0 ] & current_size );                      \
-            position[ 1 ] &= ~( c[ 1 ] & current_size );                      \
-            position[ 2 ] &= ~( c[ 2 ] & current_size );                      \
-            position[ 3 ] &= ~( c[ 3 ] & current_size );                      \
-                                                                              \
-            current_size <<= 1;                                               \
-                                                                              \
-            pass++;                                                           \
-                                                                              \
-            stack_pointer--;                                                  \
-            q = stack[ stack_pointer ].q;                                     \
-            node = stack[ stack_pointer ].node;                               \
-          } while( continue_up );                                             \
-                                                                              \
-          dst[ j ] = found_color + s->offset;                                 \
-          we_found_it = 1;                                                    \
-        }                                                                     \
-      }                                                                       \
-      else if( node->contents.quadrants[ q ] )                                \
-      {                                                                       \
-        /* Descend one level */                                               \
-        stack[ stack_pointer ].node = node;                                   \
-        stack[ stack_pointer++ ].q = q;                                       \
-        node = node->contents.quadrants[ q ];                                 \
-      }                                                                       \
-      else                                                                    \
-      {                                                                       \
-        /* Found the empty quadrant. Look around */                           \
-        mlib_u32 distance = MLIB_U32_MAX;                                     \
-        mlib_s32 found_color;                                                 \
-        mlib_s32 continue_up;                                                 \
-                                                                              \
-        /*                                                                    \
-          As we had come to this level, it is warranted that there            \
-          are other points on this level near the empty quadrant              \
-        */                                                                    \
-        do                                                                    \
-        {                                                                     \
-          mlib_s32 check_corner;                                              \
-          mlib_s32 check_neibours[ 6 ];                                       \
-          mlib_s32 check_far_neibours[ 4 ];                                   \
-                                                                              \
-          /*                                                                  \
-            Check neibours: quadrants that are different by 2 bits            \
-            from the quadrant, that we are in:                                \
-            3 -  0                                                            \
-            5 -  1                                                            \
-            6 -  2                                                            \
-            9 -  3                                                            \
-            10 - 4                                                            \
-            12 - 5                                                            \
-            Far quadrants: different by 3 bits:                               \
-            7  - 0                                                            \
-            11 - 1                                                            \
-            13 - 2                                                            \
-            14 - 3                                                            \
-          */                                                                  \
-                                                                              \
-          check_neibours[ 0 ] = check_neibours[ 1 ] =                         \
-            check_neibours[ 2 ] = check_neibours[ 3 ] =                       \
-            check_neibours[ 4 ] = check_neibours[ 5 ] = 0;                    \
-          continue_up = 0;                                                    \
-                                                                              \
-          if( q & 1 )                                                         \
-          {                                                                   \
-            BINARY_TREE_EXPLORE_LEFT_4( 0, SOURCE_IMAGE, 0, 1, 3,             \
-              SUBTRACTION, SHIFT );                                           \
-          }                                                                   \
-          else                                                                \
-          {                                                                   \
-            BINARY_TREE_EXPLORE_RIGHT_4( 0, COLOR_MAX, SOURCE_IMAGE,          \
-              0, 1, 3, SUBTRACTION, SHIFT );                                  \
-          }                                                                   \
-                                                                              \
-          if( q & 2 )                                                         \
-          {                                                                   \
-            BINARY_TREE_EXPLORE_LEFT_4( 1, SOURCE_IMAGE, 0, 2, 4,             \
-              SUBTRACTION, SHIFT );                                           \
-          }                                                                   \
-          else                                                                \
-          {                                                                   \
-            BINARY_TREE_EXPLORE_RIGHT_4( 1, COLOR_MAX, SOURCE_IMAGE,          \
-              0, 2, 4, SUBTRACTION, SHIFT );                                  \
-          }                                                                   \
-                                                                              \
-          if( q & 4 )                                                         \
-          {                                                                   \
-            BINARY_TREE_EXPLORE_LEFT_4( 2, SOURCE_IMAGE, 1, 2, 5,             \
-              SUBTRACTION, SHIFT );                                           \
-          }                                                                   \
-          else                                                                \
-          {                                                                   \
-            BINARY_TREE_EXPLORE_RIGHT_4( 2, COLOR_MAX, SOURCE_IMAGE,          \
-              1, 2, 5, SUBTRACTION, SHIFT );                                  \
-          }                                                                   \
-                                                                              \
-          if( q & 8 )                                                         \
-          {                                                                   \
-            BINARY_TREE_EXPLORE_LEFT_4( 3, SOURCE_IMAGE, 3, 4, 5,             \
-              SUBTRACTION, SHIFT );                                           \
-          }                                                                   \
-          else                                                                \
-          {                                                                   \
-            BINARY_TREE_EXPLORE_RIGHT_4( 3, COLOR_MAX, SOURCE_IMAGE,          \
-              3, 4, 5, SUBTRACTION, SHIFT );                                  \
-          }                                                                   \
-                                                                              \
-          check_far_neibours[ 0 ] = check_neibours[ 0 ] +                     \
-            check_neibours[ 1 ] + check_neibours[ 2 ];                        \
-          check_far_neibours[ 1 ] = check_neibours[ 0 ] +                     \
-            check_neibours[ 3 ] + check_neibours[ 4 ];                        \
-          check_far_neibours[ 2 ] = check_neibours[ 1 ] +                     \
-            check_neibours[ 3 ] + check_neibours[ 5 ];                        \
-          check_far_neibours[ 3 ] = check_neibours[ 2 ] +                     \
-            check_neibours[ 4 ] + check_neibours[ 5 ];                        \
-                                                                              \
-          check_corner = check_far_neibours[ 0 ] +                            \
-            check_far_neibours[ 1 ] +                                         \
-            check_far_neibours[ 2 ] +                                         \
-            check_far_neibours[ 3 ];                                          \
-                                                                              \
-          if( check_neibours[ 0 ] >= 2 )                                      \
-          {                                                                   \
-            mlib_s32 qq = q ^ 3;                                              \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                          \
-          }                                                                   \
-                                                                              \
-          if( check_neibours[ 1 ] >= 2 )                                      \
-          {                                                                   \
-            mlib_s32 qq = q ^ 5;                                              \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                          \
-          }                                                                   \
-                                                                              \
-          if( check_neibours[ 2 ] >= 2 )                                      \
-          {                                                                   \
-            mlib_s32 qq = q ^ 6;                                              \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                          \
-          }                                                                   \
-                                                                              \
-          if( check_neibours[ 3 ] >= 2 )                                      \
-          {                                                                   \
-            mlib_s32 qq = q ^ 9;                                              \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                          \
-          }                                                                   \
-                                                                              \
-          if( check_neibours[ 4 ] >= 2 )                                      \
-          {                                                                   \
-            mlib_s32 qq = q ^ 10;                                             \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                          \
-          }                                                                   \
-                                                                              \
-          if( check_neibours[ 5 ] >= 2 )                                      \
-          {                                                                   \
-            mlib_s32 qq = q ^ 12;                                             \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                          \
-          }                                                                   \
-                                                                              \
-          if( check_far_neibours[ 0 ] >= 3 )                                  \
-          {                                                                   \
-            mlib_s32 qq = q ^ 7;                                              \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                          \
-          }                                                                   \
-                                                                              \
-          if( check_far_neibours[ 1 ] >= 3 )                                  \
-          {                                                                   \
-            mlib_s32 qq = q ^ 11;                                             \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                          \
-          }                                                                   \
-                                                                              \
-          if( check_far_neibours[ 2 ] >= 3 )                                  \
-          {                                                                   \
-            mlib_s32 qq = q ^ 13;                                             \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                          \
-          }                                                                   \
-                                                                              \
-          if( check_far_neibours[ 3 ] >= 3 )                                  \
-          {                                                                   \
-            mlib_s32 qq = q ^ 14;                                             \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                          \
-          }                                                                   \
-                                                                              \
-          if( check_corner >= 4 )                                             \
-          {                                                                   \
-            mlib_s32 qq = q ^ 15;                                             \
-            CHECK_QUADRANT_##SOURCE_IMAGE##_4( qq );                          \
-          }                                                                   \
-                                                                              \
-          if( q & 1 )                                                         \
-          {                                                                   \
-            BINARY_TREE_SEARCH_RIGHT( 0, COLOR_MAX, SHIFT );                  \
-          }                                                                   \
-          else                                                                \
-          {                                                                   \
-            BINARY_TREE_SEARCH_LEFT( 0, SHIFT );                              \
-          }                                                                   \
-                                                                              \
-          if( q & 2 )                                                         \
-          {                                                                   \
-            BINARY_TREE_SEARCH_RIGHT( 1, COLOR_MAX, SHIFT );                  \
-          }                                                                   \
-          else                                                                \
-          {                                                                   \
-            BINARY_TREE_SEARCH_LEFT( 1, SHIFT );                              \
-          }                                                                   \
-                                                                              \
-          if( q & 4 )                                                         \
-          {                                                                   \
-            BINARY_TREE_SEARCH_RIGHT( 2, COLOR_MAX, SHIFT );                  \
-          }                                                                   \
-          else                                                                \
-          {                                                                   \
-            BINARY_TREE_SEARCH_LEFT( 2, SHIFT );                              \
-          }                                                                   \
-                                                                              \
-          if( q & 8 )                                                         \
-          {                                                                   \
-            BINARY_TREE_SEARCH_RIGHT( 3, COLOR_MAX, SHIFT );                  \
-          }                                                                   \
-          else                                                                \
-          {                                                                   \
-            BINARY_TREE_SEARCH_LEFT( 3, SHIFT );                              \
-          }                                                                   \
-                                                                              \
-          position[ 0 ] &= ~( c[ 0 ] & current_size );                        \
-          position[ 1 ] &= ~( c[ 1 ] & current_size );                        \
-          position[ 2 ] &= ~( c[ 2 ] & current_size );                        \
-          position[ 3 ] &= ~( c[ 3 ] & current_size );                        \
-                                                                              \
-          current_size <<= 1;                                                 \
-                                                                              \
-          pass++;                                                             \
-                                                                              \
-          stack_pointer--;                                                    \
-          q = stack[ stack_pointer ].q;                                       \
-          node = stack[ stack_pointer ].node;                                 \
-        } while( continue_up );                                               \
-                                                                              \
-        dst[ j ] = found_color + s->offset;                                   \
-        we_found_it = 1;                                                      \
-      }                                                                       \
-                                                                              \
-      pass--;                                                                 \
-                                                                              \
-    } while( !we_found_it );                                                  \
-                                                                              \
-    channels[ 0 ] += 4;                                                       \
-    channels[ 1 ] += 4;                                                       \
-    channels[ 2 ] += 4;                                                       \
-    channels[ 3 ] += 4;                                                       \
-  }                                                                           \
-}
-
-/***************************************************************/
-#define FIND_NEAREST_U8_3_C( SHIFT, STEP )                      \
-  mlib_s32 i, k, k_min, min_dist, diff, mask;                   \
-  mlib_s32 offset = mlib_ImageGetLutOffset( s ) - 1;            \
-  mlib_s32 entries = s -> lutlength;                            \
-  mlib_d64 *double_lut = mlib_ImageGetLutDoubleData( s );       \
-  mlib_d64 col0, col1, col2;                                    \
-  mlib_d64 dist, len0, len1, len2;                              \
-                                                                \
-  for ( i = 0; i < length; i++ ) {                              \
-    col0 = src[ STEP * i + SHIFT ];                             \
-    col1 = src[ STEP * i + 1 + SHIFT ];                         \
-    col2 = src[ STEP * i + 2 + SHIFT ];                         \
-    min_dist = MLIB_S32_MAX;                                    \
-    k_min = 1;                                                  \
-    len0 = double_lut[ 0 ] - col0;                              \
-    len1 = double_lut[ 1 ] - col1;                              \
-    len2 = double_lut[ 2 ] - col2;                              \
-                                                                \
-    for ( k = 1; k <= entries; k++ ) {                          \
-      dist = len0 * len0;                                       \
-      len0 = double_lut[ 3 * k ] - col0;                        \
-      dist += len1 * len1;                                      \
-      len1 = double_lut[ 3 * k + 1 ] - col1;                    \
-      dist += len2 * len2;                                      \
-      len2 = double_lut[ 3 * k + 2 ] - col2;                    \
-      diff = ( mlib_s32 )dist - min_dist;                       \
-      mask = diff >> 31;                                        \
-      min_dist += diff & mask;                                  \
-      k_min += ( k - k_min ) & mask;                            \
-    }                                                           \
-                                                                \
-    dst[ i ] = k_min + offset;                                  \
-  }
-
-/***************************************************************/
-#define FIND_NEAREST_U8_4_C                                     \
-  mlib_s32 i, k, k_min, min_dist, diff, mask;                   \
-  mlib_s32 offset = mlib_ImageGetLutOffset( s ) - 1;            \
-  mlib_s32 entries = s -> lutlength;                            \
-  mlib_d64 *double_lut = mlib_ImageGetLutDoubleData( s );       \
-  mlib_d64 col0, col1, col2, col3;                              \
-  mlib_d64 dist, len0, len1, len2, len3;                        \
-                                                                \
-  for ( i = 0; i < length; i++ ) {                              \
-    col0 = src[ 4 * i ];                                        \
-    col1 = src[ 4 * i + 1 ];                                    \
-    col2 = src[ 4 * i + 2 ];                                    \
-    col3 = src[ 4 * i + 3 ];                                    \
-    min_dist = MLIB_S32_MAX;                                    \
-    k_min = 1;                                                  \
-    len0 = double_lut[ 0 ] - col0;                              \
-    len1 = double_lut[ 1 ] - col1;                              \
-    len2 = double_lut[ 2 ] - col2;                              \
-    len3 = double_lut[ 3 ] - col3;                              \
-                                                                \
-    for ( k = 1; k <= entries; k++ ) {                          \
-      dist = len0 * len0;                                       \
-      len0 =  double_lut[ 4 * k ] - col0;                       \
-      dist += len1 * len1;                                      \
-      len1 = double_lut[ 4 * k + 1 ] - col1;                    \
-      dist += len2 * len2;                                      \
-      len2 =  double_lut[ 4 * k + 2 ] - col2;                   \
-      dist += len3 * len3;                                      \
-      len3 =  double_lut[ 4 * k + 3 ] - col3;                   \
-      diff = ( mlib_s32 )dist - min_dist;                       \
-      mask = diff >> 31;                                        \
-      min_dist += diff & mask;                                  \
-      k_min += ( k - k_min ) & mask;                            \
-    }                                                           \
-                                                                \
-    dst[ i ] = k_min + offset;                                  \
-  }
-
-/***************************************************************/
-#define FSQR_S16_HI(dsrc)                                                   \
-  vis_fpadd32( vis_fmuld8ulx16( vis_read_hi( dsrc ), vis_read_hi( dsrc ) ), \
-    vis_fmuld8sux16( vis_read_hi( dsrc ), vis_read_hi( dsrc ) ) )
-
-/***************************************************************/
-#define FSQR_S16_LO(dsrc)                                                  \
-  vis_fpadd32( vis_fmuld8ulx16( vis_read_lo( dsrc ), vis_read_lo( dsrc) ), \
-    vis_fmuld8sux16( vis_read_lo( dsrc ), vis_read_lo( dsrc ) ) )
-
-/***************************************************************/
-#define FIND_NEAREST_U8_3                                             \
-{                                                                     \
-  mlib_d64 *dpsrc, dsrc, dsrc1, ddist, ddist1, ddist2, ddist3;        \
-  mlib_d64 dcolor, dind, dres, dres1, dpind[1], dpmin[1];             \
-  mlib_d64 done = vis_to_double_dup( 1 ),                             \
-           dmax = vis_to_double_dup( MLIB_S32_MAX );                  \
-  mlib_f32 *lut = ( mlib_f32 * )mlib_ImageGetLutNormalTable( s );     \
-  mlib_f32 fone = vis_to_float( 0x100 );                              \
-  mlib_s32 i, k, mask;                                                \
-  mlib_s32 gsr[1];                                                    \
-  mlib_s32 offset = mlib_ImageGetLutOffset( s ) - 1;                  \
-  mlib_s32 entries = s->lutlength;                                    \
-                                                                      \
-  gsr[0] = vis_read_gsr();                                            \
-  for( i = 0; i <= ( length-2 ); i += 2 )                             \
-  {                                                                   \
-    dpsrc = VIS_ALIGNADDR( src, -1 );                                 \
-    src += 6;                                                         \
-    dsrc = dpsrc[ 0 ];                                                \
-    dsrc1 = dpsrc[ 1 ];                                               \
-    dsrc1 = vis_faligndata( dsrc, dsrc1 );                            \
-    dsrc = vis_fmul8x16al( vis_read_hi( dsrc1 ), fone );              \
-    VIS_ALIGNADDR( dpsrc, 3 );                                        \
-    dsrc1 = vis_faligndata( dsrc1, dsrc1 );                           \
-    dsrc1 = vis_fmul8x16al( vis_read_hi( dsrc1 ), fone );             \
-    dpind[ 0 ] = dind = done;                                         \
-    dpmin[ 0 ] = dmax;                                                \
-    dcolor = vis_fmul8x16al( lut[ 0 ], fone );                        \
-    for( k = 1; k <= entries; k++ )                                   \
-    {                                                                 \
-      ddist1 = vis_fpsub16( dcolor, dsrc );                           \
-      ddist = FSQR_S16_HI( ddist1 );                                  \
-      ddist1 = FSQR_S16_LO( ddist1 );                                 \
-      dres = vis_fpadd32( ddist, ddist1 );                            \
-      ddist3 = vis_fpsub16( dcolor, dsrc1 );                          \
-      ddist2 = FSQR_S16_HI( ddist3 );                                 \
-      ddist3 = FSQR_S16_LO( ddist3 );                                 \
-      dres1 = vis_fpadd32( ddist2, ddist3 );                          \
-      dcolor = vis_fmul8x16al( lut[ k ], fone );                      \
-      dres = vis_freg_pair(                                           \
-        vis_fpadd32s( vis_read_hi( dres ), vis_read_lo( dres ) ),     \
-        vis_fpadd32s( vis_read_hi( dres1 ), vis_read_lo( dres1 ) ) ); \
-      mask = vis_fcmplt32( dres, dpmin[ 0 ] );                        \
-      vis_pst_32( dind, ( void * )dpind, mask );                      \
-      dind = vis_fpadd32( dind, done );                               \
-      vis_pst_32( dres, ( void * )dpmin, mask );                      \
-    }                                                                 \
-    dst[ i ] = ( ( mlib_s32 * )dpind )[ 0 ] + offset;                 \
-    dst[ i + 1 ] = ( ( mlib_s32 * )dpind)[ 1 ] + offset;              \
-  }                                                                   \
-  if( i < length )                                                    \
-  {                                                                   \
-    dpsrc = VIS_ALIGNADDR( src, -1 );                                 \
-    dsrc = dpsrc[ 0 ];                                                \
-    dsrc1 = dpsrc[ 1 ];                                               \
-    dsrc1 = vis_faligndata( dsrc, dsrc1 );                            \
-    dsrc = vis_fmul8x16al( vis_read_hi( dsrc1 ), fone );              \
-    dpind[ 0 ] = dind = done;                                         \
-    dpmin[ 0 ] = dmax;                                                \
-    for( k = 0; k < entries; k++ )                                    \
-    {                                                                 \
-      dcolor = vis_fmul8x16al( lut[ k ], fone );                      \
-      ddist1 = vis_fpsub16( dcolor, dsrc );                           \
-      ddist = FSQR_S16_HI( ddist1 );                                  \
-      ddist1 = FSQR_S16_LO( ddist1 );                                 \
-      dres = vis_fpadd32( ddist, ddist1 );                            \
-      dres = vis_write_lo( dres,                                      \
-        vis_fpadd32s( vis_read_hi( dres ), vis_read_lo( dres ) ) );   \
-      mask = vis_fcmplt32( dres, dpmin[ 0 ] );                        \
-      vis_pst_32( dind, ( void * )dpind, mask );                      \
-      dind = vis_fpadd32( dind, done );                               \
-      vis_pst_32( dres, ( void * )dpmin, mask );                      \
-    }                                                                 \
-    dst[ i ] = ( ( mlib_s32 * )dpind)[ 1 ] + offset;                  \
-  }                                                                   \
-  vis_write_gsr(gsr[0]);                                              \
-}
-
-/***************************************************************/
-#define FIND_NEAREST_U8_3_IN4                                         \
-{                                                                     \
-  mlib_d64 *dpsrc, dsrc, dsrc1, ddist, ddist1, ddist2, ddist3;        \
-  mlib_d64 dcolor, dind, dres, dres1, dpind[1], dpmin[1];             \
-  mlib_d64 done = vis_to_double_dup( 1 ),                             \
-           dmax = vis_to_double_dup( MLIB_S32_MAX );                  \
-  mlib_f32 *lut = ( mlib_f32 * )mlib_ImageGetLutNormalTable( s );     \
-  mlib_f32 fone = vis_to_float( 0x100 );                              \
-  mlib_s32 i, k, mask, gsr[1];                                        \
-  mlib_s32 offset = mlib_ImageGetLutOffset( s ) - 1;                  \
-  mlib_s32 entries = s->lutlength;                                    \
-                                                                      \
-  gsr[0] = vis_read_gsr();                                            \
-  dpsrc = VIS_ALIGNADDR( src, 0 );                                    \
-  for( i = 0; i <= ( length-2 ); i += 2 )                             \
-  {                                                                   \
-    dsrc = dpsrc[ 0 ];                                                \
-    dsrc1 = dpsrc[ 1 ];                                               \
-    dsrc1 = vis_faligndata( dsrc, dsrc1 );                            \
-    dpsrc++;                                                          \
-    dsrc = vis_fmul8x16al( vis_read_hi( dsrc1 ), fone );              \
-    dsrc1 = vis_fmul8x16al( vis_read_lo( dsrc1 ), fone );             \
-    dpind[ 0 ] = dind = done;                                         \
-    dpmin[ 0 ] = dmax;                                                \
-    dcolor = vis_fmul8x16al( lut[ 0 ], fone );                        \
-    for( k = 1; k <= entries; k++ )                                   \
-    {                                                                 \
-      ddist1 = vis_fpsub16( dcolor, dsrc );                           \
-      ddist = FSQR_S16_HI( ddist1 );                                  \
-      ddist1 = FSQR_S16_LO( ddist1 );                                 \
-      dres = vis_fpadd32( ddist, ddist1 );                            \
-      ddist3 = vis_fpsub16( dcolor, dsrc1 );                          \
-      ddist2 = FSQR_S16_HI( ddist3 );                                 \
-      ddist3 = FSQR_S16_LO( ddist3 );                                 \
-      dres1 = vis_fpadd32( ddist2, ddist3 );                          \
-      dcolor = vis_fmul8x16al( lut[ k ], fone );                      \
-      dres = vis_freg_pair(                                           \
-        vis_fpadd32s( vis_read_hi( dres ), vis_read_lo( dres ) ),     \
-        vis_fpadd32s( vis_read_hi( dres1 ), vis_read_lo( dres1 ) ) ); \
-      mask = vis_fcmplt32( dres, dpmin[ 0 ] );                        \
-      vis_pst_32( dind, ( void * )dpind, mask );                      \
-      dind = vis_fpadd32( dind, done );                               \
-      vis_pst_32( dres, ( void * )dpmin, mask );                      \
-    }                                                                 \
-    dst[ i ] = ( ( mlib_s32 * )dpind )[ 0 ] + offset;                 \
-    dst[ i + 1 ] = ( ( mlib_s32 * )dpind)[ 1 ] + offset;              \
-  }                                                                   \
-  if( i < length )                                                    \
-  {                                                                   \
-    dsrc = dpsrc[ 0 ];                                                \
-    dsrc1 = dpsrc[ 1 ];                                               \
-    dsrc1 = vis_faligndata( dsrc, dsrc1 );                            \
-    dsrc = vis_fmul8x16al( vis_read_hi( dsrc1 ), fone );              \
-    dpind[ 0 ] = dind = done;                                         \
-    dpmin[ 0 ] = dmax;                                                \
-    for( k = 0; k < entries; k++ )                                    \
-    {                                                                 \
-      dcolor = vis_fmul8x16al( lut[ k ], fone );                      \
-      ddist1 = vis_fpsub16( dcolor, dsrc );                           \
-      ddist = FSQR_S16_HI( ddist1 );                                  \
-      ddist1 = FSQR_S16_LO( ddist1 );                                 \
-      dres = vis_fpadd32( ddist, ddist1 );                            \
-      dres = vis_write_lo( dres,                                      \
-        vis_fpadd32s( vis_read_hi( dres ), vis_read_lo( dres ) ) );   \
-      mask = vis_fcmplt32( dres, dpmin[ 0 ] );                        \
-      vis_pst_32( dind, ( void * )dpind, mask );                      \
-      dind = vis_fpadd32( dind, done );                               \
-      vis_pst_32( dres, ( void * )dpmin, mask );                      \
-    }                                                                 \
-    dst[ i ] = ( ( mlib_s32 * )dpind)[ 1 ] + offset;                  \
-  }                                                                   \
-  vis_write_gsr(gsr[0]);                                              \
-}
-
-/***************************************************************/
-#define FIND_NEAREST_U8_4                                             \
-{                                                                     \
-  mlib_d64 *dpsrc, dsrc, dsrc1, ddist, ddist1, ddist2, ddist3;        \
-  mlib_d64 dcolor, dind, dres, dres1, dpind[ 1 ], dpmin[ 1 ];         \
-  mlib_d64 done = vis_to_double_dup( 1 ),                             \
-           dmax = vis_to_double_dup( MLIB_S32_MAX );                  \
-  mlib_f32 *lut = ( mlib_f32 * )mlib_ImageGetLutNormalTable( s );     \
-  mlib_f32 fone = vis_to_float( 0x100 );                              \
-  mlib_s32 i, k, mask, gsr[1];                                        \
-  mlib_s32 offset = mlib_ImageGetLutOffset( s ) - 1;                  \
-  mlib_s32 entries = s->lutlength;                                    \
-                                                                      \
-  gsr[0] = vis_read_gsr();                                            \
-  dpsrc = VIS_ALIGNADDR( src, 0 );                                    \
-  for( i = 0; i <= ( length-2 ); i += 2 )                             \
-  {                                                                   \
-    dsrc = dpsrc[ 0 ];                                                \
-    dsrc1 = dpsrc[ 1 ];                                               \
-    dsrc1 = vis_faligndata( dsrc, dsrc1 );                            \
-    dpsrc++;                                                          \
-    dsrc = vis_fmul8x16al( vis_read_hi( dsrc1 ), fone );              \
-    dsrc1 = vis_fmul8x16al( vis_read_lo( dsrc1 ), fone );             \
-    dpind[ 0 ] = dind = done;                                         \
-    dpmin[ 0 ] = dmax;                                                \
-    dcolor = vis_fmul8x16al(lut[0], fone);                            \
-    for( k = 1; k <= entries; k++ )                                   \
-    {                                                                 \
-      ddist1 = vis_fpsub16( dcolor, dsrc );                           \
-      ddist = FSQR_S16_HI( ddist1 );                                  \
-      ddist1 = FSQR_S16_LO( ddist1 );                                 \
-      dres = vis_fpadd32( ddist, ddist1 );                            \
-      ddist3 = vis_fpsub16( dcolor, dsrc1 );                          \
-      ddist2 = FSQR_S16_HI( ddist3 );                                 \
-      ddist3 = FSQR_S16_LO( ddist3 );                                 \
-      dres1 = vis_fpadd32( ddist2, ddist3 );                          \
-      dcolor = vis_fmul8x16al( lut[ k ], fone );                      \
-      dres = vis_freg_pair(                                           \
-        vis_fpadd32s( vis_read_hi( dres ), vis_read_lo( dres ) ),     \
-        vis_fpadd32s( vis_read_hi( dres1 ), vis_read_lo( dres1 ) ) ); \
-      mask = vis_fcmplt32( dres, dpmin[ 0 ] );                        \
-      vis_pst_32( dind, ( void * )dpind, mask );                      \
-      dind = vis_fpadd32( dind, done );                               \
-      vis_pst_32( dres, ( void * )dpmin, mask );                      \
-    }                                                                 \
-    dst[ i ] = ( ( mlib_s32 * )dpind )[ 0 ] + offset;                 \
-    dst[ i + 1 ] = ( ( mlib_s32 * )dpind )[ 1 ] + offset;             \
-  }                                                                   \
-  if( i < length )                                                    \
-  {                                                                   \
-    dsrc = dpsrc[ 0 ];                                                \
-    dsrc1 = dpsrc[ 1 ];                                               \
-    dsrc1 = vis_faligndata( dsrc, dsrc1 );                            \
-    dsrc = vis_fmul8x16al( vis_read_hi( dsrc1 ), fone );              \
-    dpind[ 0 ] = dind = done;                                         \
-    dpmin[ 0 ] = dmax;                                                \
-    for( k = 0; k < entries; k++ )                                    \
-    {                                                                 \
-      dcolor = vis_fmul8x16al( lut[ k ], fone );                      \
-      ddist1 = vis_fpsub16( dcolor, dsrc );                           \
-      ddist = FSQR_S16_HI( ddist1 );                                  \
-      ddist1 = FSQR_S16_LO( ddist1 );                                 \
-      dres = vis_fpadd32( ddist, ddist1 );                            \
-      dres = vis_write_lo( dres,                                      \
-        vis_fpadd32s( vis_read_hi( dres ), vis_read_lo( dres ) ) );   \
-      mask = vis_fcmplt32( dres, dpmin[ 0 ] );                        \
-      vis_pst_32( dind, ( void * )dpind, mask );                      \
-      dind = vis_fpadd32( dind, done );                               \
-      vis_pst_32( dres, ( void * )dpmin, mask );                      \
-    }                                                                 \
-    dst[ i ] = ( ( mlib_s32 * )dpind )[ 1 ] + offset;                 \
-  }                                                                   \
-  vis_write_gsr(gsr[0]);                                              \
-}
-
-/***************************************************************/
-#define FIND_NEAREST_S16_3( SHIFT, STEP )                       \
-  mlib_s32 i, k, k_min, min_dist, diff, mask;                   \
-  mlib_s32 offset = mlib_ImageGetLutOffset( s ) - 1;            \
-  mlib_s32 entries = s->lutlength;                              \
-  mlib_d64 *double_lut = mlib_ImageGetLutDoubleData( s );       \
-  mlib_d64 col0, col1, col2;                                    \
-  mlib_d64 dist, len0, len1, len2;                              \
-                                                                \
-  for( i = 0; i < length; i++ )                                 \
-  {                                                             \
-    col0 = src[ STEP * i + SHIFT ];                             \
-    col1 = src[ STEP * i + 1 + SHIFT ];                         \
-    col2 = src[ STEP * i + 2 + SHIFT ];                         \
-    min_dist = MLIB_S32_MAX;                                    \
-    k_min = 1;                                                  \
-    len0 = double_lut[ 0 ] - col0;                              \
-    len1 = double_lut[ 1 ] - col1;                              \
-    len2 = double_lut[ 2 ] - col2;                              \
-    for( k = 1; k <= entries; k++ )                             \
-    {                                                           \
-      dist = len0 * len0;                                       \
-      len0 = double_lut[ 3 * k ] - col0;                        \
-      dist += len1 * len1;                                      \
-      len1 = double_lut[ 3 * k + 1 ] - col1;                    \
-      dist += len2 * len2;                                      \
-      len2 = double_lut[ 3 * k + 2 ] - col2;                    \
-      diff = ( mlib_s32 )( dist * 0.125 ) - min_dist;           \
-      mask = diff >> 31;                                        \
-      min_dist += diff & mask;                                  \
-      k_min += ( k - k_min ) & mask;                            \
-    }                                                           \
-    dst[ i ] = k_min + offset;                                  \
-  }
-
-/***************************************************************/
-#define FIND_NEAREST_S16_4                                      \
-  mlib_s32 i, k, k_min, min_dist, diff, mask;                   \
-  mlib_s32 offset = mlib_ImageGetLutOffset( s ) - 1;            \
-  mlib_s32 entries = s->lutlength;                              \
-  mlib_d64 *double_lut = mlib_ImageGetLutDoubleData( s );       \
-  mlib_d64 col0, col1, col2, col3;                              \
-  mlib_d64 dist, len0, len1, len2, len3;                        \
-                                                                \
-  for( i = 0; i < length; i++ )                                 \
-  {                                                             \
-    col0 = src[ 4 * i ];                                        \
-    col1 = src[ 4 * i + 1 ];                                    \
-    col2 = src[ 4 * i + 2 ];                                    \
-    col3 = src[ 4 * i + 3 ];                                    \
-    min_dist = MLIB_S32_MAX;                                    \
-    k_min = 1;                                                  \
-    len0 = double_lut[ 0 ] - col0;                              \
-    len1 = double_lut[ 1 ] - col1;                              \
-    len2 = double_lut[ 2 ] - col2;                              \
-    len3 = double_lut[ 3 ] - col3;                              \
-    for( k = 1; k <= entries; k++ )                             \
-    {                                                           \
-      dist = len0 * len0;                                       \
-      len0 =  double_lut[ 4 * k ] - col0;                       \
-      dist += len1 * len1;                                      \
-      len1 = double_lut[ 4 * k + 1 ] - col1;                    \
-      dist += len2 * len2;                                      \
-      len2 =  double_lut[ 4 * k + 2 ] - col2;                   \
-      dist += len3 * len3;                                      \
-      len3 =  double_lut[ 4 * k + 3 ] - col3;                   \
-      diff = ( mlib_s32 )( dist * 0.125 ) - min_dist;           \
-      mask = diff >> 31;                                        \
-      min_dist += diff & mask;                                  \
-      k_min += ( k - k_min ) & mask;                            \
-    }                                                           \
-    dst[ i ] = k_min + offset;                                  \
-  }
-
-/***************************************************************/
-mlib_status mlib_ImageColorTrue2Index(mlib_image       *dst,
-                                      const mlib_image *src,
-                                      const void       *colormap)
-{
-  mlib_s32 y, width, height, sstride, dstride, schann;
-  mlib_colormap *s = (mlib_colormap *)colormap;
-  mlib_s32 channels;
-  mlib_type stype, dtype;
-
-  MLIB_IMAGE_CHECK(src);
-  MLIB_IMAGE_CHECK(dst);
-  MLIB_IMAGE_SIZE_EQUAL(src, dst);
-  MLIB_IMAGE_HAVE_CHAN(dst, 1);
-
-  if (!colormap)
-    return MLIB_NULLPOINTER;
-
-  channels = s->channels;
-  stype = mlib_ImageGetType(src);
-  dtype = mlib_ImageGetType(dst);
-  width = mlib_ImageGetWidth(src);
-  height = mlib_ImageGetHeight(src);
-  sstride = mlib_ImageGetStride(src);
-  dstride = mlib_ImageGetStride(dst);
-  schann = mlib_ImageGetChannels(src);
-
-  if (stype != s->intype || dtype != s->outtype)
-    return MLIB_FAILURE;
-
-  if (channels != schann)
-    return MLIB_FAILURE;
-
-  switch (stype) {
-    case MLIB_BYTE:
-      {
-        mlib_u8 *sdata = mlib_ImageGetData(src);
-
-        switch (dtype) {
-          case MLIB_BYTE:
-            {
-              mlib_u8 *ddata = mlib_ImageGetData(dst);
-
-              switch (channels) {
-                case 3:
-                  {
-                    MAIN_COLORTRUE2INDEX_LOOP(U8, U8, 3);
-                    return MLIB_SUCCESS;
-                  }
-
-                case 4:
-                  {
-                    MAIN_COLORTRUE2INDEX_LOOP(U8, U8, 4);
-                    return MLIB_SUCCESS;
-                  }
-
-                default:
-                  return MLIB_FAILURE;
-              }
-            }
-
-          case MLIB_SHORT:
-            {
-              mlib_s16 *ddata = mlib_ImageGetData(dst);
-
-              dstride /= 2;
-              switch (channels) {
-                case 3:
-                  {
-                    MAIN_COLORTRUE2INDEX_LOOP(U8, S16, 3);
-                    return MLIB_SUCCESS;
-                  }
-
-                case 4:
-                  {
-                    MAIN_COLORTRUE2INDEX_LOOP(U8, S16, 4);
-                    return MLIB_SUCCESS;
-                  }
-
-                default:
-                  return MLIB_FAILURE;
-              }
-            }
-        default:
-          /* Unsupported type of destination image */
-          return MLIB_FAILURE;
-        }
-      }
-
-    case MLIB_SHORT:
-      {
-        mlib_s16 *sdata = mlib_ImageGetData(src);
-
-        sstride /= 2;
-        switch (dtype) {
-          case MLIB_BYTE:
-            {
-              mlib_u8 *ddata = mlib_ImageGetData(dst);
-
-              switch (channels) {
-                case 3:
-                  {
-                    MAIN_COLORTRUE2INDEX_LOOP(S16, U8, 3);
-                    return MLIB_SUCCESS;
-                  }
-
-                case 4:
-                  {
-                    MAIN_COLORTRUE2INDEX_LOOP(S16, U8, 4);
-                    return MLIB_SUCCESS;
-                  }
-
-                default:
-                  return MLIB_FAILURE;
-              }
-            }
-
-          case MLIB_SHORT:
-            {
-              mlib_s16 *ddata = mlib_ImageGetData(dst);
-
-              dstride /= 2;
-              switch (channels) {
-                case 3:
-                  {
-                    MAIN_COLORTRUE2INDEX_LOOP(S16, S16, 3);
-                    return MLIB_SUCCESS;
-                  }
-
-                case 4:
-                  {
-                    MAIN_COLORTRUE2INDEX_LOOP(S16, S16, 4);
-                    return MLIB_SUCCESS;
-                  }
-
-                default:
-                  return MLIB_FAILURE;
-              }
-            }
-        default:
-          /* Unsupported type of destination image */
-          return MLIB_FAILURE;
-        }
-      }
-
-    default:
-      return MLIB_FAILURE;
-  }
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_U8_3(struct lut_node_3 *node,
-                                   mlib_u32          distance,
-                                    mlib_s32    *found_color,
-                                   mlib_u32          c0,
-                                   mlib_u32          c1,
-                                   mlib_u32          c2,
-                                   const mlib_u8     **base)
-{
-  mlib_s32 i;
-
-  for (i = 0; i < 8; i++) {
-
-    if (node->tag & (1 << i)) {
-      /* Here is alone color cell. Check the distance */
-      mlib_s32 newindex = node->contents.index[i];
-      mlib_u32 newpalc0, newpalc1, newpalc2;
-      mlib_u32 newdistance;
-
-      newpalc0 = base[0][newindex];
-      newpalc1 = base[1][newindex];
-      newpalc2 = base[2][newindex];
-      newdistance = FIND_DISTANCE_3(c0, newpalc0, c1, newpalc1, c2, newpalc2, 0);
-
-      if (distance > newdistance) {
-        *found_color = newindex;
-        distance = newdistance;
-      }
-    }
-    else if (node->contents.quadrants[i])
-      distance =
-        mlib_search_quadrant_U8_3(node->contents.quadrants[i], distance,
-                                  found_color, c0, c1, c2, base);
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_part_to_left_U8_3(struct lut_node_3 *node,
-                                                mlib_u32          distance,
-                                                 mlib_s32    *found_color,
-                                                const mlib_u32    *c,
-                                                const mlib_u8     **base,
-                                                mlib_u32          position,
-                                                mlib_s32          pass,
-                                                mlib_s32          dir_bit)
-{
-  mlib_u32 current_size = 1 << pass;
-  mlib_s32 i;
-  static mlib_s32 opposite_quadrants[3][4] = {
-    {0, 2, 4, 6},
-    {0, 1, 4, 5},
-    {0, 1, 2, 3}
-  };
-
-/* Search only quadrant's half untill it is necessary to check the
-  whole quadrant */
-
-  if (distance < (position + current_size - c[dir_bit]) * (position + current_size - c[dir_bit])) { /* Search half of quadrant */
-    for (i = 0; i < 4; i++) {
-      mlib_s32 qq = opposite_quadrants[dir_bit][i];
-
-      if (node->tag & (1 << qq)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[qq];
-        mlib_u32 newpalc0, newpalc1, newpalc2;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex];
-        newpalc1 = base[1][newindex];
-        newpalc2 = base[2][newindex];
-        newdistance = FIND_DISTANCE_3(c[0], newpalc0, c[1], newpalc1, c[2], newpalc2, 0);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[qq])
-        distance =
-          mlib_search_quadrant_part_to_left_U8_3(node->contents.quadrants[qq],
-                                                 distance, found_color, c, base,
-                                                 position, pass - 1, dir_bit);
-    }
-  }
-  else {                                    /* Search whole quadrant */
-
-    mlib_s32 mask = 1 << dir_bit;
-
-    for (i = 0; i < 8; i++) {
-
-      if (node->tag & (1 << i)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[i];
-        mlib_u32 newpalc0, newpalc1, newpalc2;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex];
-        newpalc1 = base[1][newindex];
-        newpalc2 = base[2][newindex];
-        newdistance = FIND_DISTANCE_3(c[0], newpalc0, c[1], newpalc1, c[2], newpalc2, 0);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[i]) {
-
-        if (i & mask)
-          /* This quadrant may require partial checking */
-          distance =
-            mlib_search_quadrant_part_to_left_U8_3(node->contents.quadrants[i],
-                                                   distance, found_color, c,
-                                                   base,
-                                                   position + current_size,
-                                                   pass - 1, dir_bit);
-        else
-          /* Here we should check all */
-          distance =
-            mlib_search_quadrant_U8_3(node->contents.quadrants[i], distance,
-                                      found_color, c[0], c[1], c[2], base);
-      }
-    }
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_part_to_right_U8_3(struct lut_node_3 *node,
-                                                 mlib_u32          distance,
-                                                  mlib_s32    *found_color,
-                                                 const mlib_u32    *c,
-                                                 const mlib_u8     **base,
-                                                 mlib_u32          position,
-                                                 mlib_s32          pass,
-                                                 mlib_s32          dir_bit)
-{
-  mlib_u32 current_size = 1 << pass;
-  mlib_s32 i;
-  static mlib_s32 opposite_quadrants[3][4] = {
-    {1, 3, 5, 7},
-    {2, 3, 6, 7},
-    {4, 5, 6, 7}
-  };
-
-/* Search only quadrant's half untill it is necessary to check the
-  whole quadrant */
-
-  if (distance <= (c[dir_bit] - position - current_size) * (c[dir_bit] - position - current_size)) { /* Search half of quadrant */
-    for (i = 0; i < 4; i++) {
-      mlib_s32 qq = opposite_quadrants[dir_bit][i];
-
-      if (node->tag & (1 << qq)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[qq];
-        mlib_u32 newpalc0, newpalc1, newpalc2;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex];
-        newpalc1 = base[1][newindex];
-        newpalc2 = base[2][newindex];
-        newdistance = FIND_DISTANCE_3(c[0], newpalc0, c[1], newpalc1, c[2], newpalc2, 0);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[qq])
-        distance =
-          mlib_search_quadrant_part_to_right_U8_3(node->contents.quadrants[qq],
-                                                  distance, found_color, c,
-                                                  base, position + current_size,
-                                                  pass - 1, dir_bit);
-    }
-  }
-  else {                                    /* Search whole quadrant */
-
-    mlib_s32 mask = 1 << dir_bit;
-
-    for (i = 0; i < 8; i++) {
-
-      if (node->tag & (1 << i)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[i];
-        mlib_u32 newpalc0, newpalc1, newpalc2;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex];
-        newpalc1 = base[1][newindex];
-        newpalc2 = base[2][newindex];
-        newdistance = FIND_DISTANCE_3(c[0], newpalc0, c[1], newpalc1, c[2], newpalc2, 0);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[i]) {
-
-        if (i & mask)
-          /* Here we should check all */
-          distance =
-            mlib_search_quadrant_U8_3(node->contents.quadrants[i], distance,
-                                      found_color, c[0], c[1], c[2], base);
-        else
-          /* This quadrant may require partial checking */
-          distance =
-            mlib_search_quadrant_part_to_right_U8_3(node->contents.quadrants[i],
-                                                    distance, found_color, c,
-                                                    base, position, pass - 1, dir_bit);
-      }
-    }
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_S16_3(struct lut_node_3 *node,
-                                    mlib_u32          distance,
-                                     mlib_s32    *found_color,
-                                    mlib_u32          c0,
-                                    mlib_u32          c1,
-                                    mlib_u32          c2,
-                                    const mlib_s16    **base)
-{
-  mlib_s32 i;
-
-  for (i = 0; i < 8; i++) {
-
-    if (node->tag & (1 << i)) {
-      /* Here is alone color cell. Check the distance */
-      mlib_s32 newindex = node->contents.index[i];
-      mlib_u32 newpalc0, newpalc1, newpalc2;
-      mlib_u32 newdistance;
-
-      newpalc0 = base[0][newindex] - MLIB_S16_MIN;
-      newpalc1 = base[1][newindex] - MLIB_S16_MIN;
-      newpalc2 = base[2][newindex] - MLIB_S16_MIN;
-      newdistance = FIND_DISTANCE_3(c0, newpalc0, c1, newpalc1, c2, newpalc2, 2);
-
-      if (distance > newdistance) {
-        *found_color = newindex;
-        distance = newdistance;
-      }
-    }
-    else if (node->contents.quadrants[i])
-      distance =
-        mlib_search_quadrant_S16_3(node->contents.quadrants[i], distance,
-                                   found_color, c0, c1, c2, base);
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_part_to_left_S16_3(struct lut_node_3 *node,
-                                                 mlib_u32          distance,
-                                                  mlib_s32    *found_color,
-                                                 const mlib_u32    *c,
-                                                 const mlib_s16    **base,
-                                                 mlib_u32          position,
-                                                 mlib_s32          pass,
-                                                 mlib_s32          dir_bit)
-{
-  mlib_u32 current_size = 1 << pass;
-  mlib_s32 i;
-  static mlib_s32 opposite_quadrants[3][4] = {
-    {0, 2, 4, 6},
-    {0, 1, 4, 5},
-    {0, 1, 2, 3}
-  };
-
-/* Search only quadrant's half untill it is necessary to check the
-  whole quadrant */
-
-  if (distance < (((position + current_size - c[dir_bit]) * (position + current_size - c[dir_bit])) >> 2)) { /* Search half of quadrant */
-    for (i = 0; i < 4; i++) {
-      mlib_s32 qq = opposite_quadrants[dir_bit][i];
-
-      if (node->tag & (1 << qq)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[qq];
-        mlib_u32 newpalc0, newpalc1, newpalc2;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex] - MLIB_S16_MIN;
-        newpalc1 = base[1][newindex] - MLIB_S16_MIN;
-        newpalc2 = base[2][newindex] - MLIB_S16_MIN;
-        newdistance = FIND_DISTANCE_3(c[0], newpalc0, c[1], newpalc1, c[2], newpalc2, 2);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[qq])
-        distance =
-          mlib_search_quadrant_part_to_left_S16_3(node->contents.quadrants[qq],
-                                                  distance, found_color, c,
-                                                  base, position, pass - 1, dir_bit);
-    }
-  }
-  else {                                    /* Search whole quadrant */
-
-    mlib_s32 mask = 1 << dir_bit;
-
-    for (i = 0; i < 8; i++) {
-
-      if (node->tag & (1 << i)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[i];
-        mlib_u32 newpalc0, newpalc1, newpalc2;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex] - MLIB_S16_MIN;
-        newpalc1 = base[1][newindex] - MLIB_S16_MIN;
-        newpalc2 = base[2][newindex] - MLIB_S16_MIN;
-        newdistance = FIND_DISTANCE_3(c[0], newpalc0, c[1], newpalc1, c[2], newpalc2, 2);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[i]) {
-
-        if (i & mask)
-          /* This quadrant may require partial checking */
-          distance =
-            mlib_search_quadrant_part_to_left_S16_3(node->contents.quadrants[i],
-                                                    distance, found_color, c,
-                                                    base,
-                                                    position + current_size,
-                                                    pass - 1, dir_bit);
-        else
-          /* Here we should check all */
-          distance =
-            mlib_search_quadrant_S16_3(node->contents.quadrants[i], distance,
-                                       found_color, c[0], c[1], c[2], base);
-      }
-    }
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_part_to_right_S16_3(struct lut_node_3 *node,
-                                                  mlib_u32          distance,
-                                                   mlib_s32    *found_color,
-                                                  const mlib_u32    *c,
-                                                  const mlib_s16    **base,
-                                                  mlib_u32          position,
-                                                  mlib_s32          pass,
-                                                  mlib_s32          dir_bit)
-{
-  mlib_u32 current_size = 1 << pass;
-  mlib_s32 i;
-  static mlib_s32 opposite_quadrants[3][4] = {
-    {1, 3, 5, 7},
-    {2, 3, 6, 7},
-    {4, 5, 6, 7}
-  };
-
-/* Search only quadrant's half untill it is necessary to check the
-  whole quadrant */
-
-  if (distance <= (((c[dir_bit] - position - current_size) * (c[dir_bit] - position - current_size)) >> 2)) { /* Search half of quadrant */
-    for (i = 0; i < 4; i++) {
-      mlib_s32 qq = opposite_quadrants[dir_bit][i];
-
-      if (node->tag & (1 << qq)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[qq];
-        mlib_u32 newpalc0, newpalc1, newpalc2;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex] - MLIB_S16_MIN;
-        newpalc1 = base[1][newindex] - MLIB_S16_MIN;
-        newpalc2 = base[2][newindex] - MLIB_S16_MIN;
-        newdistance = FIND_DISTANCE_3(c[0], newpalc0, c[1], newpalc1, c[2], newpalc2, 2);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[qq])
-        distance =
-          mlib_search_quadrant_part_to_right_S16_3(node->contents.quadrants[qq],
-                                                   distance, found_color, c,
-                                                   base,
-                                                   position + current_size,
-                                                   pass - 1, dir_bit);
-    }
-  }
-  else {                                    /* Search whole quadrant */
-
-    mlib_s32 mask = 1 << dir_bit;
-
-    for (i = 0; i < 8; i++) {
-
-      if (node->tag & (1 << i)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[i];
-        mlib_u32 newpalc0, newpalc1, newpalc2;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex] - MLIB_S16_MIN;
-        newpalc1 = base[1][newindex] - MLIB_S16_MIN;
-        newpalc2 = base[2][newindex] - MLIB_S16_MIN;
-        newdistance = FIND_DISTANCE_3(c[0], newpalc0, c[1], newpalc1, c[2], newpalc2, 2);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[i]) {
-
-        if (i & mask)
-          /* Here we should check all */
-          distance =
-            mlib_search_quadrant_S16_3(node->contents.quadrants[i], distance,
-                                       found_color, c[0], c[1], c[2], base);
-        else
-          /* This quadrant may require partial checking */
-          distance =
-            mlib_search_quadrant_part_to_right_S16_3(node->contents.
-                                                     quadrants[i], distance,
-                                                     found_color, c, base,
-                                                     position, pass - 1, dir_bit);
-      }
-    }
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_U8_4(struct lut_node_4 *node,
-                                   mlib_u32          distance,
-                                    mlib_s32    *found_color,
-                                   mlib_u32          c0,
-                                   mlib_u32          c1,
-                                   mlib_u32          c2,
-                                   mlib_u32          c3,
-                                   const mlib_u8     **base)
-{
-  mlib_s32 i;
-
-  for (i = 0; i < 16; i++) {
-
-    if (node->tag & (1 << i)) {
-      /* Here is alone color cell. Check the distance */
-      mlib_s32 newindex = node->contents.index[i];
-      mlib_u32 newpalc0, newpalc1, newpalc2, newpalc3;
-      mlib_u32 newdistance;
-
-      newpalc0 = base[0][newindex];
-      newpalc1 = base[1][newindex];
-      newpalc2 = base[2][newindex];
-      newpalc3 = base[3][newindex];
-      newdistance = FIND_DISTANCE_4(c0, newpalc0,
-                                    c1, newpalc1, c2, newpalc2, c3, newpalc3, 0);
-
-      if (distance > newdistance) {
-        *found_color = newindex;
-        distance = newdistance;
-      }
-    }
-    else if (node->contents.quadrants[i])
-      distance =
-        mlib_search_quadrant_U8_4(node->contents.quadrants[i], distance,
-                                  found_color, c0, c1, c2, c3, base);
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_part_to_left_U8_4(struct lut_node_4 *node,
-                                                mlib_u32          distance,
-                                                 mlib_s32    *found_color,
-                                                const mlib_u32    *c,
-                                                const mlib_u8     **base,
-                                                mlib_u32          position,
-                                                mlib_s32          pass,
-                                                mlib_s32          dir_bit)
-{
-  mlib_u32 current_size = 1 << pass;
-  mlib_s32 i;
-  static mlib_s32 opposite_quadrants[4][8] = {
-    {0, 2, 4, 6, 8, 10, 12, 14},
-    {0, 1, 4, 5, 8, 9, 12, 13},
-    {0, 1, 2, 3, 8, 9, 10, 11},
-    {0, 1, 2, 3, 4, 5, 6, 7}
-  };
-
-/* Search only quadrant's half untill it is necessary to check the
-  whole quadrant */
-
-  if (distance < (position + current_size - c[dir_bit]) * (position + current_size - c[dir_bit])) { /* Search half of quadrant */
-    for (i = 0; i < 8; i++) {
-      mlib_s32 qq = opposite_quadrants[dir_bit][i];
-
-      if (node->tag & (1 << qq)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[qq];
-        mlib_u32 newpalc0, newpalc1, newpalc2, newpalc3;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex];
-        newpalc1 = base[1][newindex];
-        newpalc2 = base[2][newindex];
-        newpalc3 = base[3][newindex];
-        newdistance = FIND_DISTANCE_4(c[0], newpalc0,
-                                      c[1], newpalc1, c[2], newpalc2, c[3], newpalc3, 0);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[qq])
-        distance =
-          mlib_search_quadrant_part_to_left_U8_4(node->contents.quadrants[qq],
-                                                 distance, found_color, c, base,
-                                                 position, pass - 1, dir_bit);
-    }
-  }
-  else {                                    /* Search whole quadrant */
-
-    mlib_s32 mask = 1 << dir_bit;
-
-    for (i = 0; i < 16; i++) {
-
-      if (node->tag & (1 << i)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[i];
-        mlib_u32 newpalc0, newpalc1, newpalc2, newpalc3;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex];
-        newpalc1 = base[1][newindex];
-        newpalc2 = base[2][newindex];
-        newpalc3 = base[3][newindex];
-        newdistance = FIND_DISTANCE_4(c[0], newpalc0,
-                                      c[1], newpalc1, c[2], newpalc2, c[3], newpalc3, 0);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[i]) {
-
-        if (i & mask)
-          /* This quadrant may require partial checking */
-          distance =
-            mlib_search_quadrant_part_to_left_U8_4(node->contents.quadrants[i],
-                                                   distance, found_color, c,
-                                                   base,
-                                                   position + current_size,
-                                                   pass - 1, dir_bit);
-        else
-          /* Here we should check all */
-          distance =
-            mlib_search_quadrant_U8_4(node->contents.quadrants[i], distance,
-                                      found_color, c[0], c[1], c[2], c[3], base);
-      }
-    }
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_part_to_right_U8_4(struct lut_node_4 *node,
-                                                 mlib_u32          distance,
-                                                  mlib_s32    *found_color,
-                                                 const mlib_u32    *c,
-                                                 const mlib_u8     **base,
-                                                 mlib_u32          position,
-                                                 mlib_s32          pass,
-                                                 mlib_s32          dir_bit)
-{
-  mlib_u32 current_size = 1 << pass;
-  mlib_s32 i;
-  static mlib_s32 opposite_quadrants[4][8] = {
-    {1, 3, 5, 7, 9, 11, 13, 15},
-    {2, 3, 6, 7, 10, 11, 14, 15},
-    {4, 5, 6, 7, 12, 13, 14, 15},
-    {8, 9, 10, 11, 12, 13, 14, 15}
-  };
-
-/* Search only quadrant's half untill it is necessary to check the
-  whole quadrant */
-
-  if (distance <= (c[dir_bit] - position - current_size) * (c[dir_bit] - position - current_size)) { /* Search half of quadrant */
-    for (i = 0; i < 8; i++) {
-      mlib_s32 qq = opposite_quadrants[dir_bit][i];
-
-      if (node->tag & (1 << qq)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[qq];
-        mlib_u32 newpalc0, newpalc1, newpalc2, newpalc3;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex];
-        newpalc1 = base[1][newindex];
-        newpalc2 = base[2][newindex];
-        newpalc3 = base[3][newindex];
-        newdistance = FIND_DISTANCE_4(c[0], newpalc0,
-                                      c[1], newpalc1, c[2], newpalc2, c[3], newpalc3, 0);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[qq])
-        distance =
-          mlib_search_quadrant_part_to_right_U8_4(node->contents.quadrants[qq],
-                                                  distance, found_color, c,
-                                                  base, position + current_size,
-                                                  pass - 1, dir_bit);
-    }
-  }
-  else {                                    /* Search whole quadrant */
-
-    mlib_s32 mask = 1 << dir_bit;
-
-    for (i = 0; i < 16; i++) {
-
-      if (node->tag & (1 << i)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[i];
-        mlib_u32 newpalc0, newpalc1, newpalc2, newpalc3;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex];
-        newpalc1 = base[1][newindex];
-        newpalc2 = base[2][newindex];
-        newpalc3 = base[3][newindex];
-        newdistance = FIND_DISTANCE_4(c[0], newpalc0,
-                                      c[1], newpalc1, c[2], newpalc2, c[3], newpalc3, 0);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[i]) {
-
-        if (i & mask)
-          /* Here we should check all */
-          distance =
-            mlib_search_quadrant_U8_4(node->contents.quadrants[i], distance,
-                                      found_color, c[0], c[1], c[2], c[3], base);
-        else
-          /* This quadrant may require partial checking */
-          distance =
-            mlib_search_quadrant_part_to_right_U8_4(node->contents.quadrants[i],
-                                                    distance, found_color, c,
-                                                    base, position, pass - 1, dir_bit);
-      }
-    }
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_S16_4(struct lut_node_4 *node,
-                                    mlib_u32          distance,
-                                     mlib_s32    *found_color,
-                                    mlib_u32          c0,
-                                    mlib_u32          c1,
-                                    mlib_u32          c2,
-                                    mlib_u32          c3,
-                                    const mlib_s16    **base)
-{
-  mlib_s32 i;
-
-  for (i = 0; i < 16; i++) {
-
-    if (node->tag & (1 << i)) {
-      /* Here is alone color cell. Check the distance */
-      mlib_s32 newindex = node->contents.index[i];
-      mlib_u32 newpalc0, newpalc1, newpalc2, newpalc3;
-      mlib_u32 newdistance;
-
-      newpalc0 = base[0][newindex] - MLIB_S16_MIN;
-      newpalc1 = base[1][newindex] - MLIB_S16_MIN;
-      newpalc2 = base[2][newindex] - MLIB_S16_MIN;
-      newpalc3 = base[3][newindex] - MLIB_S16_MIN;
-      newdistance = FIND_DISTANCE_4(c0, newpalc0,
-                                    c1, newpalc1, c2, newpalc2, c3, newpalc3, 2);
-
-      if (distance > newdistance) {
-        *found_color = newindex;
-        distance = newdistance;
-      }
-    }
-    else if (node->contents.quadrants[i])
-      distance =
-        mlib_search_quadrant_S16_4(node->contents.quadrants[i], distance,
-                                   found_color, c0, c1, c2, c3, base);
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_part_to_left_S16_4(struct lut_node_4 *node,
-                                                 mlib_u32          distance,
-                                                  mlib_s32    *found_color,
-                                                 const mlib_u32    *c,
-                                                 const mlib_s16    **base,
-                                                 mlib_u32          position,
-                                                 mlib_s32          pass,
-                                                 mlib_s32          dir_bit)
-{
-  mlib_u32 current_size = 1 << pass;
-  mlib_s32 i;
-  static mlib_s32 opposite_quadrants[4][8] = {
-    {0, 2, 4, 6, 8, 10, 12, 14},
-    {0, 1, 4, 5, 8, 9, 12, 13},
-    {0, 1, 2, 3, 8, 9, 10, 11},
-    {0, 1, 2, 3, 4, 5, 6, 7}
-  };
-
-/* Search only quadrant's half untill it is necessary to check the
-  whole quadrant */
-
-  if (distance < (((position + current_size - c[dir_bit]) * (position + current_size - c[dir_bit])) >> 2)) { /* Search half of quadrant */
-    for (i = 0; i < 8; i++) {
-      mlib_s32 qq = opposite_quadrants[dir_bit][i];
-
-      if (node->tag & (1 << qq)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[qq];
-        mlib_u32 newpalc0, newpalc1, newpalc2, newpalc3;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex] - MLIB_S16_MIN;
-        newpalc1 = base[1][newindex] - MLIB_S16_MIN;
-        newpalc2 = base[2][newindex] - MLIB_S16_MIN;
-        newpalc3 = base[3][newindex] - MLIB_S16_MIN;
-        newdistance = FIND_DISTANCE_4(c[0], newpalc0,
-                                      c[1], newpalc1, c[2], newpalc2, c[3], newpalc3, 2);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[qq])
-        distance =
-          mlib_search_quadrant_part_to_left_S16_4(node->contents.quadrants[qq],
-                                                  distance, found_color, c,
-                                                  base, position, pass - 1, dir_bit);
-    }
-  }
-  else {                                    /* Search whole quadrant */
-
-    mlib_s32 mask = 1 << dir_bit;
-
-    for (i = 0; i < 16; i++) {
-
-      if (node->tag & (1 << i)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[i];
-        mlib_u32 newpalc0, newpalc1, newpalc2, newpalc3;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex] - MLIB_S16_MIN;
-        newpalc1 = base[1][newindex] - MLIB_S16_MIN;
-        newpalc2 = base[2][newindex] - MLIB_S16_MIN;
-        newpalc3 = base[3][newindex] - MLIB_S16_MIN;
-        newdistance = FIND_DISTANCE_4(c[0], newpalc0,
-                                      c[1], newpalc1, c[2], newpalc2, c[3], newpalc3, 2);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[i]) {
-
-        if (i & mask)
-          /* This quadrant may require partial checking */
-          distance =
-            mlib_search_quadrant_part_to_left_S16_4(node->contents.quadrants[i],
-                                                    distance, found_color, c,
-                                                    base,
-                                                    position + current_size,
-                                                    pass - 1, dir_bit);
-        else
-          /* Here we should check all */
-          distance =
-            mlib_search_quadrant_S16_4(node->contents.quadrants[i], distance,
-                                       found_color, c[0], c[1], c[2], c[3], base);
-      }
-    }
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-mlib_u32 mlib_search_quadrant_part_to_right_S16_4(struct lut_node_4 *node,
-                                                  mlib_u32          distance,
-                                                   mlib_s32    *found_color,
-                                                  const mlib_u32    *c,
-                                                  const mlib_s16    **base,
-                                                  mlib_u32          position,
-                                                  mlib_s32          pass,
-                                                  mlib_s32          dir_bit)
-{
-  mlib_u32 current_size = 1 << pass;
-  mlib_s32 i;
-  static mlib_s32 opposite_quadrants[4][8] = {
-    {1, 3, 5, 7, 9, 11, 13, 15},
-    {2, 3, 6, 7, 10, 11, 14, 15},
-    {4, 5, 6, 7, 12, 13, 14, 15},
-    {8, 9, 10, 11, 12, 13, 14, 15}
-  };
-
-/* Search only quadrant's half untill it is necessary to check the
-  whole quadrant */
-
-  if (distance <= (((c[dir_bit] - position - current_size) * (c[dir_bit] - position - current_size)) >> 2)) { /* Search half of quadrant */
-    for (i = 0; i < 8; i++) {
-      mlib_s32 qq = opposite_quadrants[dir_bit][i];
-
-      if (node->tag & (1 << qq)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[qq];
-        mlib_u32 newpalc0, newpalc1, newpalc2, newpalc3;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex] - MLIB_S16_MIN;
-        newpalc1 = base[1][newindex] - MLIB_S16_MIN;
-        newpalc2 = base[2][newindex] - MLIB_S16_MIN;
-        newpalc3 = base[3][newindex] - MLIB_S16_MIN;
-        newdistance = FIND_DISTANCE_4(c[0], newpalc0,
-                                      c[1], newpalc1, c[2], newpalc2, c[3], newpalc3, 2);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[qq])
-        distance =
-          mlib_search_quadrant_part_to_right_S16_4(node->contents.quadrants[qq],
-                                                   distance, found_color, c,
-                                                   base,
-                                                   position + current_size,
-                                                   pass - 1, dir_bit);
-    }
-  }
-  else {                                    /* Search whole quadrant */
-
-    mlib_s32 mask = 1 << dir_bit;
-
-    for (i = 0; i < 16; i++) {
-
-      if (node->tag & (1 << i)) {
-        /* Here is alone color cell. Check the distance */
-        mlib_s32 newindex = node->contents.index[i];
-        mlib_u32 newpalc0, newpalc1, newpalc2, newpalc3;
-        mlib_u32 newdistance;
-
-        newpalc0 = base[0][newindex] - MLIB_S16_MIN;
-        newpalc1 = base[1][newindex] - MLIB_S16_MIN;
-        newpalc2 = base[2][newindex] - MLIB_S16_MIN;
-        newpalc3 = base[3][newindex] - MLIB_S16_MIN;
-        newdistance = FIND_DISTANCE_4(c[0], newpalc0,
-                                      c[1], newpalc1, c[2], newpalc2, c[3], newpalc3, 2);
-
-        if (distance > newdistance) {
-          *found_color = newindex;
-          distance = newdistance;
-        }
-      }
-      else if (node->contents.quadrants[i]) {
-
-        if (i & mask)
-          /* Here we should check all */
-          distance =
-            mlib_search_quadrant_S16_4(node->contents.quadrants[i], distance,
-                                       found_color, c[0], c[1], c[2], c[3], base);
-        else
-          /* This quadrant may require partial checking */
-          distance =
-            mlib_search_quadrant_part_to_right_S16_4(node->contents.
-                                                     quadrants[i], distance,
-                                                     found_color, c, base,
-                                                     position, pass - 1, dir_bit);
-      }
-    }
-  }
-
-  return distance;
-}
-
-/***************************************************************/
-
-#define TAB_SIZE_mlib_u8   256
-#define TAB_SIZE_mlib_s16 1024
-
-#define SRC_mlib_u8(i)    src[i]
-#define SRC_mlib_s16(i)   (((mlib_u16*)src)[i] >> 6)
-
-/***************************************************************/
-
-#define DIMENSIONS_SEARCH_3(STYPE, DTYPE, STEP)                 \
-{                                                               \
-  DTYPE  *tab0 = ((mlib_colormap *)state)->table;               \
-  DTYPE  *tab1 = tab0 + TAB_SIZE_##STYPE;                       \
-  DTYPE  *tab2 = tab1 + TAB_SIZE_##STYPE;                       \
-  mlib_s32 i;                                                   \
-                                                                \
-  for (i = 0; i < length; i++) {                                \
-    dst[i] = tab0[SRC_##STYPE(0)] + tab1[SRC_##STYPE(1)] +      \
-             tab2[SRC_##STYPE(2)];                              \
-    src += STEP;                                                \
-  }                                                             \
-}
-
-/***************************************************************/
-
-#define DIMENSIONS_SEARCH_4(STYPE, DTYPE)                       \
-{                                                               \
-  DTYPE  *tab0 = ((mlib_colormap *)state)->table;               \
-  DTYPE  *tab1 = tab0 + TAB_SIZE_##STYPE;                       \
-  DTYPE  *tab2 = tab1 + TAB_SIZE_##STYPE;                       \
-  DTYPE  *tab3 = tab2 + TAB_SIZE_##STYPE;                       \
-  mlib_s32 i;                                                   \
-                                                                \
-  for (i = 0; i < length; i++) {                                \
-    dst[i] = tab0[SRC_##STYPE(0)] + tab1[SRC_##STYPE(1)] +      \
-             tab2[SRC_##STYPE(2)] + tab3[SRC_##STYPE(3)];       \
-    src += 4;                                                   \
-  }                                                             \
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_U8_U8_3(const mlib_u8 *src,
-                                           mlib_u8       *dst,
-                                           mlib_s32      length,
-                                           const void    *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-
-  switch (s->method) {
-#if LUT_BYTE_COLORS_3CHANNELS <= 256
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        mlib_s32 bits = s->bits;
-        BINARY_TREE_SEARCH_3(U8, mlib_u8, 8, (MLIB_U8_MAX + 1), 0, 0, 3, 0);
-      }
-      break;
-
-#endif /* LUT_BYTE_COLORS_3CHANNELS <= 256 */
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        COLOR_CUBE_U8_3_SEARCH(mlib_u8, 0, 3);
-      }
-      break;
-
-    case LUT_STUPID_SEARCH:
-      {
-#ifdef USE_VIS_CODE
-        FIND_NEAREST_U8_3;
-#else
-        FIND_NEAREST_U8_3_C(0, 3);
-#endif
-      }
-      break;
-
-    case LUT_COLOR_DIMENSIONS:
-      DIMENSIONS_SEARCH_3(mlib_u8, mlib_u8, 3)
-      break;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_U8_U8_3_in_4(const mlib_u8 *src,
-                                                mlib_u8       *dst,
-                                                mlib_s32      length,
-                                                const void    *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-
-  switch (s->method) {
-#if LUT_BYTE_COLORS_3CHANNELS <= 256
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        mlib_s32 bits = s->bits;
-        BINARY_TREE_SEARCH_3(U8, mlib_u8, 8, (MLIB_U8_MAX + 1), 0, 1, 4, 0);
-        break;
-      }
-
-#endif /* LUT_BYTE_COLORS_3CHANNELS <= 256 */
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        COLOR_CUBE_U8_3_SEARCH(mlib_u8, 1, 4);
-        break;
-      }
-
-    case LUT_STUPID_SEARCH:
-      {
-#ifdef USE_VIS_CODE
-        FIND_NEAREST_U8_3_IN4;
-#else
-        FIND_NEAREST_U8_3_C(1, 4);
-#endif
-        break;
-      }
-
-    case LUT_COLOR_DIMENSIONS:
-      src++;
-      DIMENSIONS_SEARCH_3(mlib_u8, mlib_u8, 4)
-      break;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_U8_U8_4(const mlib_u8 *src,
-                                           mlib_u8       *dst,
-                                           mlib_s32      length,
-                                           const void    *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-
-  switch (s->method) {
-#if LUT_BYTE_COLORS_4CHANNELS <= 256
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        mlib_s32 bits = s->bits;
-        BINARY_TREE_SEARCH_4(U8, mlib_u8, 8, (MLIB_U8_MAX + 1), 0, 0);
-        break;
-      }
-
-#endif /* LUT_BYTE_COLORS_4CHANNELS <= 256 */
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        COLOR_CUBE_U8_4_SEARCH(mlib_u8);
-        break;
-      }
-
-    case LUT_STUPID_SEARCH:
-      {
-#ifdef USE_VIS_CODE
-        FIND_NEAREST_U8_4;
-#else
-        FIND_NEAREST_U8_4_C;
-#endif
-        break;
-      }
-
-    case LUT_COLOR_DIMENSIONS:
-      DIMENSIONS_SEARCH_4(mlib_u8, mlib_u8)
-      break;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_U8_S16_3(const mlib_u8 *src,
-                                            mlib_s16      *dst,
-                                            mlib_s32      length,
-                                            const void    *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-  mlib_s32 bits = s->bits;
-
-  switch (s->method) {
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        BINARY_TREE_SEARCH_3(U8, mlib_u8, 8, (MLIB_U8_MAX + 1), 0, 0, 3, 0);
-        break;
-      }
-
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        switch (s->indexsize) {
-          case 1:
-            {
-              COLOR_CUBE_U8_3_SEARCH(mlib_u8, 0, 3);
-              break;
-            }
-
-          case 2:
-            {
-              COLOR_CUBE_U8_3_SEARCH(mlib_s16, 0, 3);
-              break;
-            }
-        }
-
-        break;
-      }
-
-    case LUT_STUPID_SEARCH:
-      {
-#ifdef USE_VIS_CODE
-        FIND_NEAREST_U8_3;
-#else
-        FIND_NEAREST_U8_3_C(0, 3);
-#endif
-        break;
-      }
-
-    case LUT_COLOR_DIMENSIONS:
-      DIMENSIONS_SEARCH_3(mlib_u8, mlib_s16, 3)
-      break;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_U8_S16_3_in_4(const mlib_u8 *src,
-                                                 mlib_s16      *dst,
-                                                 mlib_s32      length,
-                                                 const void    *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-  mlib_s32 bits = s->bits;
-
-  switch (s->method) {
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        BINARY_TREE_SEARCH_3(U8, mlib_u8, 8, (MLIB_U8_MAX + 1), 0, 1, 4, 0);
-        break;
-      }
-
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        switch (s->indexsize) {
-          case 1:
-            {
-              COLOR_CUBE_U8_3_SEARCH(mlib_u8, 1, 4);
-              break;
-            }
-
-          case 2:
-            {
-              COLOR_CUBE_U8_3_SEARCH(mlib_s16, 1, 4);
-              break;
-            }
-        }
-
-        break;
-      }
-
-    case LUT_STUPID_SEARCH:
-      {
-#ifdef USE_VIS_CODE
-        FIND_NEAREST_U8_3_IN4;
-#else
-        FIND_NEAREST_U8_3_C(1, 4);
-#endif
-        break;
-      }
-
-    case LUT_COLOR_DIMENSIONS:
-      src++;
-      DIMENSIONS_SEARCH_3(mlib_u8, mlib_s16, 4)
-      break;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_U8_S16_4(const mlib_u8 *src,
-                                            mlib_s16      *dst,
-                                            mlib_s32      length,
-                                            const void    *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-  mlib_s32 bits = s->bits;
-
-  switch (s->method) {
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        BINARY_TREE_SEARCH_4(U8, mlib_u8, 8, (MLIB_U8_MAX + 1), 0, 0);
-        break;
-      }
-
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        switch (s->indexsize) {
-          case 1:
-            {
-              COLOR_CUBE_U8_4_SEARCH(mlib_u8);
-              break;
-            }
-
-          case 2:
-            {
-              COLOR_CUBE_U8_4_SEARCH(mlib_s16);
-              break;
-            }
-        }
-
-        break;
-      }
-
-    case LUT_STUPID_SEARCH:
-      {
-#ifdef USE_VIS_CODE
-        FIND_NEAREST_U8_4;
-#else
-        FIND_NEAREST_U8_4_C;
-#endif
-        break;
-      }
-
-    case LUT_COLOR_DIMENSIONS:
-      DIMENSIONS_SEARCH_4(mlib_u8, mlib_s16)
-      break;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_S16_S16_3(const mlib_s16 *src,
-                                             mlib_s16       *dst,
-                                             mlib_s32       length,
-                                             const void     *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-  mlib_s32 bits = s->bits;
-
-  switch (s->method) {
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        BINARY_TREE_SEARCH_3(S16, mlib_s16, 16, ((MLIB_S16_MAX + 1) * 2),
-                             MLIB_S16_MIN, 0, 3, 2);
-        break;
-      }
-
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        switch (s->indexsize) {
-          case 1:
-            {
-              COLOR_CUBE_S16_3_SEARCH(mlib_u8, 0, 3);
-              break;
-            }
-
-          case 2:
-            {
-              COLOR_CUBE_S16_3_SEARCH(mlib_s16, 0, 3);
-              break;
-            }
-        }
-
-        break;
-      }
-
-    case LUT_STUPID_SEARCH:
-      {
-        FIND_NEAREST_S16_3(0, 3);
-        break;
-      }
-
-    case LUT_COLOR_DIMENSIONS:
-      DIMENSIONS_SEARCH_3(mlib_s16, mlib_s16, 3)
-      break;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_S16_S16_3_in_4(const mlib_s16 *src,
-                                                  mlib_s16       *dst,
-                                                  mlib_s32       length,
-                                                  const void     *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-  mlib_s32 bits = s->bits;
-
-  switch (s->method) {
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        BINARY_TREE_SEARCH_3(S16, mlib_s16, 16, ((MLIB_S16_MAX + 1) * 2),
-                             MLIB_S16_MIN, 1, 4, 2);
-        break;
-      }
-
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        switch (s->indexsize) {
-          case 1:
-            {
-              COLOR_CUBE_S16_3_SEARCH(mlib_u8, 1, 4);
-              break;
-            }
-
-          case 2:
-            {
-              COLOR_CUBE_S16_3_SEARCH(mlib_s16, 1, 4);
-              break;
-            }
-        }
-
-        break;
-      }
-
-    case LUT_STUPID_SEARCH:
-      {
-        FIND_NEAREST_S16_3(1, 4);
-        break;
-      }
-
-    case LUT_COLOR_DIMENSIONS:
-      src++;
-      DIMENSIONS_SEARCH_3(mlib_s16, mlib_s16, 4)
-      break;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_S16_S16_4(const mlib_s16 *src,
-                                             mlib_s16       *dst,
-                                             mlib_s32       length,
-                                             const void     *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-  mlib_s32 bits = s->bits;
-
-  switch (s->method) {
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        BINARY_TREE_SEARCH_4(S16, mlib_s16, 16, ((MLIB_S16_MAX + 1) * 2),
-                             MLIB_S16_MIN, 2);
-        break;
-      }
-
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        switch (s->indexsize) {
-          case 1:
-            {
-              COLOR_CUBE_S16_4_SEARCH(mlib_u8);
-              break;
-            }
-
-          case 2:
-            {
-              COLOR_CUBE_S16_4_SEARCH(mlib_s16);
-              break;
-            }
-        }
-
-        break;
-      }
-
-    case LUT_STUPID_SEARCH:
-      {
-        FIND_NEAREST_S16_4;
-        break;
-      }
-
-    case LUT_COLOR_DIMENSIONS:
-      DIMENSIONS_SEARCH_4(mlib_s16, mlib_s16)
-      break;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_S16_U8_3(const mlib_s16 *src,
-                                            mlib_u8        *dst,
-                                            mlib_s32       length,
-                                            const void     *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-
-  switch (s->method) {
-#if LUT_SHORT_COLORS_3CHANNELS <= 256
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        mlib_s32 bits = s->bits;
-        BINARY_TREE_SEARCH_3(S16, mlib_s16, 16, ((MLIB_S16_MAX + 1) * 2),
-                             MLIB_S16_MIN, 0, 3, 2);
-        break;
-      }
-
-#endif /* LUT_SHORT_COLORS_3CHANNELS <= 256 */
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        COLOR_CUBE_S16_3_SEARCH(mlib_u8, 0, 3);
-        break;
-      }
-
-    case LUT_STUPID_SEARCH:
-      {
-        FIND_NEAREST_S16_3(0, 3);
-        break;
-      }
-
-    case LUT_COLOR_DIMENSIONS:
-      DIMENSIONS_SEARCH_3(mlib_s16, mlib_u8, 3)
-      break;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_S16_U8_3_in_4(const mlib_s16 *src,
-                                                 mlib_u8        *dst,
-                                                 mlib_s32       length,
-                                                 const void     *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-
-  switch (s->method) {
-#if LUT_SHORT_COLORS_3CHANNELS <= 256
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        mlib_s32 bits = s->bits;
-        BINARY_TREE_SEARCH_3(S16, mlib_s16, 16, ((MLIB_S16_MAX + 1) * 2),
-                             MLIB_S16_MIN, 1, 4, 2);
-        break;
-      }
-
-#endif /* LUT_SHORT_COLORS_3CHANNELS <= 256 */
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        COLOR_CUBE_S16_3_SEARCH(mlib_u8, 1, 4);
-        break;
-      }
-
-    case LUT_STUPID_SEARCH:
-      {
-        FIND_NEAREST_S16_3(1, 4);
-        break;
-      }
-
-    case LUT_COLOR_DIMENSIONS:
-      src++;
-      DIMENSIONS_SEARCH_3(mlib_s16, mlib_u8, 4)
-      break;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageColorTrue2IndexLine_S16_U8_4(const mlib_s16 *src,
-                                            mlib_u8        *dst,
-                                            mlib_s32       length,
-                                            const void     *state)
-{
-  mlib_colormap *s = (mlib_colormap *)state;
-
-  switch (s->method) {
-#if LUT_SHORT_COLORS_4CHANNELS <= 256
-    case LUT_BINARY_TREE_SEARCH:
-      {
-        mlib_s32 bits = s->bits;
-        BINARY_TREE_SEARCH_4(S16, mlib_s16, 16, ((MLIB_S16_MAX + 1) * 2),
-                             MLIB_S16_MIN, 2);
-        break;
-      }
-
-#endif /* LUT_SHORT_COLORS_4CHANNELS <= 256 */
-    case LUT_COLOR_CUBE_SEARCH:
-      {
-        COLOR_CUBE_S16_4_SEARCH(mlib_u8);
-        break;
-      }
-
-    case LUT_STUPID_SEARCH:
-      {
-        FIND_NEAREST_S16_4;
-        break;
-      }
-
-    case LUT_COLOR_DIMENSIONS:
-      DIMENSIONS_SEARCH_4(mlib_s16, mlib_u8)
-      break;
-  }
-}
-
-/***************************************************************/
-
-#ifndef VIS
-
-void mlib_c_ImageThresh1_U81_1B(void     *psrc,
-                                void     *pdst,
-                                mlib_s32 src_stride,
-                                mlib_s32 dst_stride,
-                                mlib_s32 width,
-                                mlib_s32 height,
-                                void     *thresh,
-                                void     *ghigh,
-                                void     *glow,
-                                mlib_s32 dbit_off);
-
-/***************************************************************/
-
-void mlib_ImageColorTrue2IndexLine_U8_BIT_1(const mlib_u8 *src,
-                                            mlib_u8       *dst,
-                                            mlib_s32      bit_offset,
-                                            mlib_s32      length,
-                                            const void    *state)
-{
-  mlib_u8  *lut = ((mlib_colormap *)state)->table;
-  mlib_s32 thresh[1];
-  mlib_s32 ghigh[1];
-  mlib_s32 glow[1];
-
-  thresh[0] = lut[2];
-
-  glow[0]  = lut[0] - lut[1];
-  ghigh[0] = lut[1] - lut[0];
-
-  mlib_c_ImageThresh1_U81_1B((void*)src, dst, 0, 0, length, 1,
-                             thresh, ghigh, glow, bit_offset);
-}
-
-#else
-
-/***************************************************************/
-
-void mlib_v_ImageThresh1B_U8_1(const mlib_u8  *src,
-                               mlib_s32       slb,
-                               mlib_u8        *dst,
-                               mlib_s32       dlb,
-                               mlib_s32       xsize,
-                               mlib_s32       ysize,
-                               mlib_s32       dbit_off,
-                               const mlib_s32 *th,
-                               mlib_s32       hc,
-                               mlib_s32       lc);
-
-/***************************************************************/
-
-void mlib_ImageColorTrue2IndexLine_U8_BIT_1(const mlib_u8 *src,
-                                            mlib_u8       *dst,
-                                            mlib_s32      bit_offset,
-                                            mlib_s32      length,
-                                            const void    *state)
-{
-  mlib_u8  *lut = ((mlib_colormap *)state)->table;
-  mlib_s32 thresh[4];
-  mlib_s32 ghigh[1];
-  mlib_s32 glow[1];
-
-  thresh[0] = thresh[1] = thresh[2] = thresh[3] = lut[2];
-
-  glow[0]  = (lut[1] < lut[0]) ? 0xFF : 0;
-  ghigh[0] = (lut[1] < lut[0]) ? 0 : 0xFF;
-
-  mlib_v_ImageThresh1B_U8_1((void*)src, 0, dst, 0, length, 1,
-                            bit_offset, thresh, ghigh[0], glow[0]);
-}
-
-/***************************************************************/
-
-#endif
--- a/src/java.desktop/share/native/libmlib_image/mlib_ImageColormap.h	Thu May 12 11:03:07 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,221 +0,0 @@
-/*
- * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-
-#ifndef __MLIB_IMAGECOLORMAP_H
-#define __MLIB_IMAGECOLORMAP_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-typedef struct {
-  void **lut;
-  mlib_s32 channels;
-  mlib_type intype;
-  mlib_s32 offset;
-  void *table;
-  mlib_s32 bits;
-  mlib_s32 method;
-  mlib_s32 lutlength;
-  mlib_s32 indexsize;
-  mlib_type outtype;
-  void *normal_table;
-  mlib_d64 *double_lut;
-} mlib_colormap;
-
-/***************************************************************/
-#define LUT_COLOR_CUBE_SEARCH  0
-#define LUT_BINARY_TREE_SEARCH 1
-#define LUT_STUPID_SEARCH      2
-#define LUT_COLOR_DIMENSIONS   3
-
-/***************************************************************/
-
-/* Bit set in the tag denotes that the corresponding quadrant is a
-   palette index, not node. If the bit is clear, this means that that
-   is a pointer to the down level node. If the bit is clear and the
-   corresponding quadrant is NULL, then there is no way down there and
-   this quadrant is clear. */
-
-struct lut_node_3 {
-  mlib_u8 tag;
-  union {
-    struct lut_node_3 *quadrants[8];
-    long index[8];
-  } contents;
-};
-
-struct lut_node_4 {
-  mlib_u16 tag;
-  union {
-    struct lut_node_4 *quadrants[16];
-    long index[16];
-  } contents;
-};
-
-/***************************************************************/
-
-#define mlib_ImageGetLutData(colormap)                          \
-  ((void **)((( mlib_colormap *)( colormap))->lut))
-
-/***************************************************************/
-#define mlib_ImageGetLutNormalTable(colormap)                   \
-  ((void *)((( mlib_colormap *)( colormap))->normal_table))
-
-/***************************************************************/
-#define mlib_ImageGetLutInversTable(colormap)                   \
-  ((void *)((( mlib_colormap *)( colormap))->table))
-
-/***************************************************************/
-#define mlib_ImageGetLutChannels(colormap)                      \
-  ((mlib_s32)((( mlib_colormap *)( colormap))->channels))
-
-/***************************************************************/
-#define mlib_ImageGetLutType(colormap)                          \
-  ((mlib_type)((( mlib_colormap *)( colormap))->intype))
-
-/***************************************************************/
-#define mlib_ImageGetIndexSize(colormap)                        \
-  ((mlib_s32)((( mlib_colormap *)( colormap))->indexsize))
-
-/***************************************************************/
-#define mlib_ImageGetOutType(colormap)                          \
-  ((mlib_type)((( mlib_colormap *)( colormap))->outtype))
-
-/***************************************************************/
-#define mlib_ImageGetLutOffset(colormap)                        \
-  ((mlib_s32)((( mlib_colormap *)( colormap))->offset))
-
-/***************************************************************/
-#define mlib_ImageGetBits(colormap)                             \
-  ((mlib_s32)((( mlib_colormap *)( colormap))->bits))
-
-/***************************************************************/
-#define mlib_ImageGetMethod(colormap)                           \
-  ((mlib_s32)((( mlib_colormap *)( colormap))->method))
-
-/***************************************************************/
-#define mlib_ImageGetLutDoubleData(colormap)                    \
-  ((mlib_d64 *)((( mlib_colormap *)( colormap))->double_lut))
-
-/***************************************************************/
-#define FIND_DISTANCE_3( x1, x2, y1, y2, z1, z2, SHIFT )        \
- (( ( ( ( x1 ) - ( x2 ) ) * ( ( x1 ) - ( x2 ) ) ) >> SHIFT ) +  \
-  ( ( ( ( y1 ) - ( y2 ) ) * ( ( y1 ) - ( y2 ) ) ) >> SHIFT ) +  \
-  ( ( ( ( z1 ) - ( z2 ) ) * ( ( z1 ) - ( z2 ) ) ) >> SHIFT ) )
-
-/***************************************************************/
-#define FIND_DISTANCE_4( x1, x2, y1, y2, z1, z2, w1, w2, SHIFT ) \
-  (( ( ( ( x1 ) - ( x2 ) ) * ( ( x1 ) - ( x2 ) ) ) >> SHIFT ) +  \
-   ( ( ( ( y1 ) - ( y2 ) ) * ( ( y1 ) - ( y2 ) ) ) >> SHIFT ) +  \
-   ( ( ( ( z1 ) - ( z2 ) ) * ( ( z1 ) - ( z2 ) ) ) >> SHIFT ) +  \
-   ( ( ( ( w1 ) - ( w2 ) ) * ( ( w1 ) - ( w2 ) ) ) >> SHIFT ) )
-
-/***************************************************************/
-
-void mlib_ImageColorTrue2IndexLine_U8_BIT_1(const mlib_u8 *src,
-                                            mlib_u8       *dst,
-                                            mlib_s32      bit_offset,
-                                            mlib_s32      length,
-                                            const void    *state);
-
-
-void mlib_ImageColorTrue2IndexLine_U8_U8_3(const mlib_u8 *src,
-                                           mlib_u8       *dst,
-                                           mlib_s32      length,
-                                           const void    *colormap);
-
-
-void mlib_ImageColorTrue2IndexLine_U8_U8_3_in_4(const mlib_u8 *src,
-                                                mlib_u8       *dst,
-                                                mlib_s32      length,
-                                                const void    *colormap);
-
-
-void mlib_ImageColorTrue2IndexLine_U8_U8_4(const mlib_u8 *src,
-                                           mlib_u8       *dst,
-                                           mlib_s32      length,
-                                           const void    *colormap);
-
-
-void mlib_ImageColorTrue2IndexLine_U8_S16_3(const mlib_u8 *src,
-                                            mlib_s16      *dst,
-                                            mlib_s32      length,
-                                            const void    *colormap);
-
-
-void mlib_ImageColorTrue2IndexLine_U8_S16_3_in_4(const mlib_u8 *src,
-                                                 mlib_s16      *dst,
-                                                 mlib_s32      length,
-                                                 const void    *colormap);
-
-
-void mlib_ImageColorTrue2IndexLine_U8_S16_4(const mlib_u8 *src,
-                                            mlib_s16      *dst,
-                                            mlib_s32      length,
-                                            const void    *colormap);
-
-
-void mlib_ImageColorTrue2IndexLine_S16_S16_3(const mlib_s16 *src,
-                                             mlib_s16       *dst,
-                                             mlib_s32       length,
-                                             const void     *colormap);
-
-
-void mlib_ImageColorTrue2IndexLine_S16_S16_3_in_4(const mlib_s16 *src,
-                                                  mlib_s16       *dst,
-                                                  mlib_s32       length,
-                                                  const void     *colormap);
-
-
-void mlib_ImageColorTrue2IndexLine_S16_S16_4(const mlib_s16 *src,
-                                             mlib_s16       *dst,
-                                             mlib_s32       length,
-                                             const void     *colormap);
-
-
-void mlib_ImageColorTrue2IndexLine_S16_U8_3(const mlib_s16 *src,
-                                            mlib_u8        *dst,
-                                            mlib_s32       length,
-                                            const void     *colormap);
-
-
-void mlib_ImageColorTrue2IndexLine_S16_U8_3_in_4(const mlib_s16 *src,
-                                                 mlib_u8        *dst,
-                                                 mlib_s32       length,
-                                                 const void     *colormap);
-
-
-void mlib_ImageColorTrue2IndexLine_S16_U8_4(const mlib_s16 *src,
-                                            mlib_u8        *dst,
-                                            mlib_s32       length,
-                                            const void     *colormap);
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __MLIB_IMAGECOLORMAP_H */
--- a/src/java.desktop/share/native/libmlib_image/mlib_ImageConv.h	Thu May 12 11:03:07 2016 -0700
+++ b/src/java.desktop/share/native/libmlib_image/mlib_ImageConv.h	Fri May 13 11:31:05 2016 +0300
@@ -41,466 +41,6 @@
 }
 #endif /* FREE_AND_RETURN_STATUS */
 
-void mlib_ImageXor80_aa(mlib_u8  *dl,
-                        mlib_s32 wid,
-                        mlib_s32 hgt,
-                        mlib_s32 str);
-
-void mlib_ImageXor80(mlib_u8  *dl,
-                     mlib_s32 wid,
-                     mlib_s32 hgt,
-                     mlib_s32 str,
-                     mlib_s32 nchan,
-                     mlib_s32 cmask);
-
-mlib_status mlib_conv2x2ext_d64(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_d64   *kern,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv2x2ext_f32(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_d64   *kern,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv2x2ext_s16(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv2x2ext_s32(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv2x2ext_u16(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv2x2ext_u8(mlib_image       *dst,
-                               const mlib_image *src,
-                               mlib_s32         dx_l,
-                               mlib_s32         dx_r,
-                               mlib_s32         dy_t,
-                               mlib_s32         dy_b,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv2x2nw_d64(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_d64   *kern,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv2x2nw_f32(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_d64   *kern,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv2x2nw_s16(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv2x2nw_s32(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv2x2nw_u16(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv2x2nw_u8(mlib_image       *dst,
-                              const mlib_image *src,
-                              const mlib_s32   *kern,
-                              mlib_s32         scale,
-                              mlib_s32         cmask);
-
-mlib_status mlib_conv3x3ext_bit(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv3x3ext_d64(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_d64   *kern,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv3x3ext_f32(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_d64   *kern,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv3x3ext_s16(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv3x3ext_s32(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv3x3ext_u16(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv3x3ext_u8(mlib_image       *dst,
-                               const mlib_image *src,
-                               mlib_s32         dx_l,
-                               mlib_s32         dx_r,
-                               mlib_s32         dy_t,
-                               mlib_s32         dy_b,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv3x3nw_bit(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv3x3nw_d64(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_d64   *kern,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv3x3nw_f32(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_d64   *kern,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv3x3nw_s16(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv3x3nw_s32(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv3x3nw_u16(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv3x3nw_u8(mlib_image       *dst,
-                              const mlib_image *src,
-                              const mlib_s32   *kern,
-                              mlib_s32         scale,
-                              mlib_s32         cmask);
-
-mlib_status mlib_conv4x4ext_d64(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_d64   *kern,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv4x4ext_f32(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_d64   *kern,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv4x4ext_s16(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv4x4ext_s32(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv4x4ext_u16(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv4x4ext_u8(mlib_image       *dst,
-                               const mlib_image *src,
-                               mlib_s32         dx_l,
-                               mlib_s32         dx_r,
-                               mlib_s32         dy_t,
-                               mlib_s32         dy_b,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv4x4nw_d64(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_d64   *kern,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv4x4nw_f32(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_d64   *kern,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv4x4nw_s16(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv4x4nw_s32(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv4x4nw_u16(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv4x4nw_u8(mlib_image       *dst,
-                              const mlib_image *src,
-                              const mlib_s32   *kern,
-                              mlib_s32         scale,
-                              mlib_s32         cmask);
-
-mlib_status mlib_conv5x5ext_d64(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_d64   *kern,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv5x5ext_f32(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_d64   *kern,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv5x5ext_s16(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv5x5ext_s32(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv5x5ext_u16(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv5x5ext_u8(mlib_image       *dst,
-                               const mlib_image *src,
-                               mlib_s32         dx_l,
-                               mlib_s32         dx_r,
-                               mlib_s32         dy_t,
-                               mlib_s32         dy_b,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv5x5nw_d64(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_d64   *kern,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv5x5nw_f32(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_d64   *kern,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv5x5nw_s16(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv5x5nw_s32(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv5x5nw_u16(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv5x5nw_u8(mlib_image       *dst,
-                              const mlib_image *src,
-                              const mlib_s32   *kern,
-                              mlib_s32         scale,
-                              mlib_s32         cmask);
-
-mlib_status mlib_conv7x7ext_s16(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv7x7ext_s32(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv7x7ext_u16(mlib_image       *dst,
-                                const mlib_image *src,
-                                mlib_s32         dx_l,
-                                mlib_s32         dx_r,
-                                mlib_s32         dy_t,
-                                mlib_s32         dy_b,
-                                const mlib_s32   *kern,
-                                mlib_s32         scale,
-                                mlib_s32         cmask);
-
-mlib_status mlib_conv7x7ext_u8(mlib_image       *dst,
-                               const mlib_image *src,
-                               mlib_s32         dx_l,
-                               mlib_s32         dx_r,
-                               mlib_s32         dy_t,
-                               mlib_s32         dy_b,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv7x7nw_s16(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv7x7nw_s32(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv7x7nw_u16(mlib_image       *dst,
-                               const mlib_image *src,
-                               const mlib_s32   *kern,
-                               mlib_s32         scale,
-                               mlib_s32         cmask);
-
-mlib_status mlib_conv7x7nw_u8(mlib_image       *dst,
-                              const mlib_image *src,
-                              const mlib_s32   *kern,
-                              mlib_s32         scale,
-                              mlib_s32         cmask);
-
 mlib_status mlib_convMxNext_s32(mlib_image       *dst,
                                 const mlib_image *src,
                                 const mlib_s32   *kernel,
--- a/src/java.desktop/share/native/libmlib_image/mlib_ImageConv2x2_f.c	Thu May 12 11:03:07 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1118 +0,0 @@
-/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-
-/*
- * FUNCTION
- *      Internal functions for mlib_ImageConv2x2 on U8/S16/U16 types
- *      and MLIB_EDGE_DST_NO_WRITE mask.
- */
-
-#include "mlib_image.h"
-#include "mlib_ImageConv.h"
-#include "mlib_c_ImageConv.h"
-
-/***************************************************************/
-#ifdef i386 /* do not copy by mlib_d64 data type for x86 */
-
-typedef struct {
-  mlib_s32 int0, int1;
-} two_int;
-
-#define TYPE_64BIT two_int
-
-#else /* i386 */
-
-#define TYPE_64BIT mlib_d64
-
-#endif /* i386 ( do not copy by mlib_d64 data type for x86 ) */
-
-/***************************************************************/
-#define LOAD_KERNEL_INTO_DOUBLE()                                        \
-  while (scalef_expon > 30) {                                            \
-    scalef /= (1 << 30);                                                 \
-    scalef_expon -= 30;                                                  \
-  }                                                                      \
-                                                                         \
-  scalef /= (1 << scalef_expon);                                         \
-                                                                         \
-  /* keep kernel in regs */                                              \
-  k0 = scalef * kern[0];  k1 = scalef * kern[1];  k2 = scalef * kern[2]; \
-  k3 = scalef * kern[3]
-
-/***************************************************************/
-#define GET_SRC_DST_PARAMETERS(type)                            \
-  hgt = mlib_ImageGetHeight(src);                               \
-  wid = mlib_ImageGetWidth(src);                                \
-  nchannel = mlib_ImageGetChannels(src);                        \
-  sll = mlib_ImageGetStride(src) / sizeof(type);                \
-  dll = mlib_ImageGetStride(dst) / sizeof(type);                \
-  adr_src = (type *)mlib_ImageGetData(src);                     \
-  adr_dst = (type *)mlib_ImageGetData(dst)
-
-/***************************************************************/
-#ifndef MLIB_USE_FTOI_CLAMPING
-
-#define CLAMP_S32(x)                                            \
-  (((x) <= MLIB_S32_MIN) ? MLIB_S32_MIN :                       \
-  (((x) >= MLIB_S32_MAX) ? MLIB_S32_MAX : (mlib_s32)(x)))
-
-#else
-
-#define CLAMP_S32(x) ((mlib_s32)(x))
-
-#endif /* MLIB_USE_FTOI_CLAMPING */
-
-/***************************************************************/
-#if defined(_LITTLE_ENDIAN) && !defined(_NO_LONGLONG)
-
-/* NB: Explicit cast to DTYPE is necessary to avoid warning from Microsoft VC compiler.
-      And we need to explicitly define cast behavior if source exceeds destination range.
-      (it is undefined according to C99 spec). We use mask here because this macro is typically
-      used to extract bit regions. */
-
-#define STORE2(res0, res1)                                      \
-  dp[0    ] = (DTYPE) ((res1) & DTYPE_MASK);                      \
-  dp[chan1] = (DTYPE) ((res0) & DTYPE_MASK)
-
-#else
-
-#define STORE2(res0, res1)                                      \
-  dp[0    ] = (DTYPE) ((res0) & DTYPE_MASK);                      \
-  dp[chan1] = (DTYPE) ((res1) & DTYPE_MASK)
-
-#endif /* defined(_LITTLE_ENDIAN) && !defined(_NO_LONGLONG) */
-
-/***************************************************************/
-#ifdef _NO_LONGLONG
-
-#define LOAD_BUFF(buff)                                         \
-  buff[i    ] = sp[0];                                          \
-  buff[i + 1] = sp[chan1]
-
-#else /* _NO_LONGLONG */
-
-#ifdef _LITTLE_ENDIAN
-
-#define LOAD_BUFF(buff)                                         \
-  *(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) | ((mlib_s64)sp[0] & 0xffffffff)
-
-#else /* _LITTLE_ENDIAN */
-
-#define LOAD_BUFF(buff)                                         \
-  *(mlib_s64*)(buff + i) = (((mlib_s64)sp[0]) << 32) | ((mlib_s64)sp[chan1] & 0xffffffff)
-
-#endif /* _LITTLE_ENDIAN */
-
-#endif /* _NO_LONGLONG */
-
-/***************************************************************/
-typedef union {
-  TYPE_64BIT d64;
-  struct {
-    mlib_s32 i0, i1;
-  } i32s;
-} d64_2x32;
-
-/***************************************************************/
-#define D_KER     1
-
-#define BUFF_LINE 256
-
-/***************************************************************/
-#define XOR_80(x) x ^= 0x80
-
-void mlib_ImageXor80_aa(mlib_u8  *dl,
-                        mlib_s32 wid,
-                        mlib_s32 hgt,
-                        mlib_s32 str)
-{
-  mlib_u8  *dp, *dend;
-#ifdef _NO_LONGLONG
-  mlib_u32 cadd = 0x80808080;
-#else /* _NO_LONGLONG */
-  mlib_u64 cadd = MLIB_U64_CONST(0x8080808080808080);
-#endif /* _NO_LONGLONG */
-  mlib_s32 j;
-
-  if (wid == str) {
-    wid *= hgt;
-    hgt = 1;
-  }
-
-  for (j = 0; j < hgt; j++) {
-    dend = dl + wid;
-
-    for (dp = dl; ((mlib_addr)dp & 7) && (dp < dend); dp++) XOR_80(dp[0]);
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (; dp <= (dend - 8); dp += 8) {
-#ifdef _NO_LONGLONG
-      *((mlib_s32*)dp) ^= cadd;
-      *((mlib_s32*)dp+1) ^= cadd;
-#else /* _NO_LONGLONG */
-      *((mlib_u64*)dp) ^= cadd;
-#endif /* _NO_LONGLONG */
-    }
-
-    for (; (dp < dend); dp++) XOR_80(dp[0]);
-
-    dl += str;
-  }
-}
-
-/***************************************************************/
-void mlib_ImageXor80(mlib_u8  *dl,
-                     mlib_s32 wid,
-                     mlib_s32 hgt,
-                     mlib_s32 str,
-                     mlib_s32 nchan,
-                     mlib_s32 cmask)
-{
-  mlib_s32 i, j, c;
-
-  for (j = 0; j < hgt; j++) {
-    for (c = 0; c < nchan; c++) {
-      if (cmask & (1 << (nchan - 1 - c))) {
-        mlib_u8 *dp = dl + c;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-        for (i = 0; i < wid; i++) XOR_80(dp[i*nchan]);
-      }
-    }
-
-    dl += str;
-  }
-}
-
-/***************************************************************/
-#define DTYPE mlib_s16
-#define DTYPE_MASK 0xffff
-
-mlib_status mlib_c_conv2x2nw_s16(mlib_image       *dst,
-                                 const mlib_image *src,
-                                 const mlib_s32   *kern,
-                                 mlib_s32         scalef_expon,
-                                 mlib_s32         cmask)
-{
-  mlib_d64 buff_arr[2*BUFF_LINE];
-  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
-  DTYPE    *adr_src, *sl, *sp, *sl1;
-  DTYPE    *adr_dst, *dl, *dp;
-  mlib_d64 k0, k1, k2, k3, scalef = 65536.0;
-  mlib_d64 p00, p01, p02,
-           p10, p11, p12;
-  mlib_s32 wid, hgt, sll, dll, wid1;
-  mlib_s32 nchannel, chan1, chan2;
-  mlib_s32 i, j, c;
-  LOAD_KERNEL_INTO_DOUBLE();
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  wid1 = (wid + 1) &~ 1;
-
-  if (wid1 > BUFF_LINE) {
-    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buffo = pbuff;
-  buff0 = buffo + wid1;
-  buff1 = buff0 + wid1;
-  buff2 = buff1 + wid1;
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  wid -= D_KER;
-  hgt -= D_KER;
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    sl1 = sl + sll;
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < wid + D_KER; i++) {
-      buff0[i - 1] = (mlib_s32)sl[i*chan1];
-      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
-    }
-
-    sl += (D_KER + 1)*sll;
-
-    for (j = 0; j < hgt; j++) {
-      sp = sl;
-      dp = dl;
-
-      buff2[-1] = (mlib_s32)sp[0];
-      sp += chan1;
-
-      p02 = buff0[-1];
-      p12 = buff1[-1];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-#ifdef _NO_LONGLONG
-        mlib_s32 o64_1, o64_2;
-#else /* _NO_LONGLONG */
-        mlib_s64 o64;
-#endif /* _NO_LONGLONG */
-        d64_2x32 sd0, sd1, dd;
-
-        p00 = p02; p10 = p12;
-
-        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
-        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
-        p01 = (mlib_d64)sd0.i32s.i0;
-        p02 = (mlib_d64)sd0.i32s.i1;
-        p11 = (mlib_d64)sd1.i32s.i0;
-        p12 = (mlib_d64)sd1.i32s.i1;
-
-        LOAD_BUFF(buff2);
-
-        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3);
-        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3);
-        *(TYPE_64BIT*)(buffo + i) = dd.d64;
-
-#ifdef _NO_LONGLONG
-
-        o64_1 = buffo[i];
-        o64_2 = buffo[i+1];
-        STORE2(o64_1 >> 16, o64_2 >> 16);
-
-#else /* _NO_LONGLONG */
-
-        o64 = *(mlib_s64*)(buffo + i);
-        STORE2(o64 >> 48, o64 >> 16);
-
-#endif /* _NO_LONGLONG */
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      for (; i < wid; i++) {
-        p00 = buff0[i - 1]; p10 = buff1[i - 1];
-        p01 = buff0[i];     p11 = buff1[i];
-
-        buff2[i] = (mlib_s32)sp[0];
-
-        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3);
-        dp[0] = buffo[i] >> 16;
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buffT;
-    }
-  }
-
-  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
-mlib_status mlib_c_conv2x2ext_s16(mlib_image       *dst,
-                                  const mlib_image *src,
-                                  mlib_s32         dx_l,
-                                  mlib_s32         dx_r,
-                                  mlib_s32         dy_t,
-                                  mlib_s32         dy_b,
-                                  const mlib_s32   *kern,
-                                  mlib_s32         scalef_expon,
-                                  mlib_s32         cmask)
-{
-  mlib_d64 buff_arr[2*BUFF_LINE];
-  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
-  DTYPE    *adr_src, *sl, *sp, *sl1;
-  DTYPE    *adr_dst, *dl, *dp;
-  mlib_d64 k0, k1, k2, k3, scalef = 65536.0;
-  mlib_d64 p00, p01, p02,
-           p10, p11, p12;
-  mlib_s32 wid, hgt, sll, dll, wid1;
-  mlib_s32 nchannel, chan1, chan2;
-  mlib_s32 i, j, c, swid;
-  LOAD_KERNEL_INTO_DOUBLE();
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  swid = wid + D_KER;
-
-  wid1 = (swid + 1) &~ 1;
-
-  if (wid1 > BUFF_LINE) {
-    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buffo = pbuff;
-  buff0 = buffo + wid1;
-  buff1 = buff0 + wid1;
-  buff2 = buff1 + wid1;
-
-  swid -= dx_r;
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    if ((hgt - dy_b) > 0) sl1 = sl + sll;
-    else sl1 = sl;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < swid; i++) {
-      buff0[i - 1] = (mlib_s32)sl[i*chan1];
-      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
-    }
-
-    if (dx_r != 0) {
-      buff0[swid - 1] = buff0[swid - 2];
-      buff1[swid - 1] = buff1[swid - 2];
-    }
-
-    if ((hgt - dy_b) > 1) sl = sl1 + sll;
-    else sl = sl1;
-
-    for (j = 0; j < hgt; j++) {
-      sp = sl;
-      dp = dl;
-
-      buff2[-1] = (mlib_s32)sp[0];
-      sp += chan1;
-
-      p02 = buff0[-1];
-      p12 = buff1[-1];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-#ifdef _NO_LONGLONG
-        mlib_s32 o64_1, o64_2;
-#else /* _NO_LONGLONG */
-        mlib_s64 o64;
-#endif /* _NO_LONGLONG */
-        d64_2x32 sd0, sd1, dd;
-
-        p00 = p02; p10 = p12;
-
-        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
-        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
-        p01 = (mlib_d64)sd0.i32s.i0;
-        p02 = (mlib_d64)sd0.i32s.i1;
-        p11 = (mlib_d64)sd1.i32s.i0;
-        p12 = (mlib_d64)sd1.i32s.i1;
-
-        LOAD_BUFF(buff2);
-
-        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3);
-        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3);
-        *(TYPE_64BIT*)(buffo + i) = dd.d64;
-
-#ifdef _NO_LONGLONG
-
-        o64_1 = buffo[i];
-        o64_2 = buffo[i+1];
-        STORE2(o64_1 >> 16, o64_2 >> 16);
-
-#else /* _NO_LONGLONG */
-
-        o64 = *(mlib_s64*)(buffo + i);
-        STORE2(o64 >> 48, o64 >> 16);
-
-#endif /* _NO_LONGLONG */
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      for (; i < wid; i++) {
-        p00 = buff0[i - 1]; p10 = buff1[i - 1];
-        p01 = buff0[i];     p11 = buff1[i];
-
-        buff2[i] = (mlib_s32)sp[0];
-
-        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3);
-        dp[0] = buffo[i] >> 16;
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      if (dx_r != 0) buff2[swid - 1] = buff2[swid - 2];
-
-      if (j < hgt - dy_b - 2) sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buffT;
-    }
-  }
-
-  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
-#undef  DTYPE
-#define DTYPE mlib_u16
-
-mlib_status mlib_c_conv2x2nw_u16(mlib_image       *dst,
-                                 const mlib_image *src,
-                                 const mlib_s32   *kern,
-                                 mlib_s32         scalef_expon,
-                                 mlib_s32         cmask)
-{
-  mlib_d64 buff_arr[2*BUFF_LINE];
-  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
-  DTYPE    *adr_src, *sl, *sp, *sl1;
-  DTYPE    *adr_dst, *dl, *dp;
-  mlib_d64 k0, k1, k2, k3, scalef = 65536.0;
-  mlib_d64 p00, p01, p02,
-           p10, p11, p12;
-  mlib_s32 wid, hgt, sll, dll, wid1;
-  mlib_s32 nchannel, chan1, chan2;
-  mlib_s32 i, j, c;
-  mlib_d64 doff = 0x7FFF8000;
-  LOAD_KERNEL_INTO_DOUBLE();
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  wid1 = (wid + 1) &~ 1;
-
-  if (wid1 > BUFF_LINE) {
-    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buffo = pbuff;
-  buff0 = buffo + wid1;
-  buff1 = buff0 + wid1;
-  buff2 = buff1 + wid1;
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  wid -= D_KER;
-  hgt -= D_KER;
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    sl1 = sl + sll;
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < wid + D_KER; i++) {
-      buff0[i - 1] = (mlib_s32)sl[i*chan1];
-      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
-    }
-
-    sl += (D_KER + 1)*sll;
-
-    for (j = 0; j < hgt; j++) {
-      sp = sl;
-      dp = dl;
-
-      buff2[-1] = (mlib_s32)sp[0];
-      sp += chan1;
-
-      p02 = buff0[-1];
-      p12 = buff1[-1];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-#ifdef _NO_LONGLONG
-        mlib_s32 o64_1, o64_2;
-#else /* _NO_LONGLONG */
-        mlib_s64 o64;
-#endif /* _NO_LONGLONG */
-        d64_2x32 sd0, sd1, dd;
-
-        p00 = p02; p10 = p12;
-
-        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
-        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
-        p01 = (mlib_d64)sd0.i32s.i0;
-        p02 = (mlib_d64)sd0.i32s.i1;
-        p11 = (mlib_d64)sd1.i32s.i0;
-        p12 = (mlib_d64)sd1.i32s.i1;
-
-        LOAD_BUFF(buff2);
-
-        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - doff);
-        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3 - doff);
-        *(TYPE_64BIT*)(buffo + i) = dd.d64;
-
-#ifdef _NO_LONGLONG
-
-        o64_1 = buffo[i];
-        o64_2 = buffo[i+1];
-        o64_1 = o64_1 ^ 0x80000000U;
-        o64_2 = o64_2 ^ 0x80000000U;
-        STORE2(o64_1 >> 16, o64_2 >> 16);
-
-#else /* _NO_LONGLONG */
-
-        o64 = *(mlib_s64*)(buffo + i);
-        o64 = o64 ^ MLIB_U64_CONST(0x8000000080000000);
-        STORE2(o64 >> 48, o64 >> 16);
-
-#endif /* _NO_LONGLONG */
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      for (; i < wid; i++) {
-        p00 = buff0[i - 1]; p10 = buff1[i - 1];
-        p01 = buff0[i];     p11 = buff1[i];
-
-        buff2[i] = (mlib_s32)sp[0];
-
-        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - doff);
-        dp[0] = (buffo[i] >> 16) ^ 0x8000;
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buffT;
-    }
-  }
-
-  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
-mlib_status mlib_c_conv2x2ext_u16(mlib_image       *dst,
-                                  const mlib_image *src,
-                                  mlib_s32         dx_l,
-                                  mlib_s32         dx_r,
-                                  mlib_s32         dy_t,
-                                  mlib_s32         dy_b,
-                                  const mlib_s32   *kern,
-                                  mlib_s32         scalef_expon,
-                                  mlib_s32         cmask)
-{
-  mlib_d64 buff_arr[2*BUFF_LINE];
-  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
-  DTYPE    *adr_src, *sl, *sp, *sl1;
-  DTYPE    *adr_dst, *dl, *dp;
-  mlib_d64 k0, k1, k2, k3, scalef = 65536.0;
-  mlib_d64 p00, p01, p02,
-           p10, p11, p12;
-  mlib_s32 wid, hgt, sll, dll, wid1;
-  mlib_s32 nchannel, chan1, chan2;
-  mlib_s32 i, j, c, swid;
-  mlib_d64 doff = 0x7FFF8000;
-  LOAD_KERNEL_INTO_DOUBLE();
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  swid = wid + D_KER;
-
-  wid1 = (swid + 1) &~ 1;
-
-  if (wid1 > BUFF_LINE) {
-    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buffo = pbuff;
-  buff0 = buffo + wid1;
-  buff1 = buff0 + wid1;
-  buff2 = buff1 + wid1;
-
-  swid -= dx_r;
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    if ((hgt - dy_b) > 0) sl1 = sl + sll;
-    else sl1 = sl;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < swid; i++) {
-      buff0[i - 1] = (mlib_s32)sl[i*chan1];
-      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
-    }
-
-    if (dx_r != 0) {
-      buff0[swid - 1] = buff0[swid - 2];
-      buff1[swid - 1] = buff1[swid - 2];
-    }
-
-    if ((hgt - dy_b) > 1) sl = sl1 + sll;
-    else sl = sl1;
-
-    for (j = 0; j < hgt; j++) {
-      sp = sl;
-      dp = dl;
-
-      buff2[-1] = (mlib_s32)sp[0];
-      sp += chan1;
-
-      p02 = buff0[-1];
-      p12 = buff1[-1];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-#ifdef _NO_LONGLONG
-        mlib_s32 o64_1, o64_2;
-#else /* _NO_LONGLONG */
-        mlib_s64 o64;
-#endif /* _NO_LONGLONG */
-        d64_2x32 sd0, sd1, dd;
-
-        p00 = p02; p10 = p12;
-
-        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
-        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
-        p01 = (mlib_d64)sd0.i32s.i0;
-        p02 = (mlib_d64)sd0.i32s.i1;
-        p11 = (mlib_d64)sd1.i32s.i0;
-        p12 = (mlib_d64)sd1.i32s.i1;
-
-        LOAD_BUFF(buff2);
-
-        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - doff);
-        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3 - doff);
-        *(TYPE_64BIT*)(buffo + i) = dd.d64;
-
-#ifdef _NO_LONGLONG
-
-        o64_1 = buffo[i];
-        o64_2 = buffo[i+1];
-        o64_1 = o64_1 ^ 0x80000000U;
-        o64_2 = o64_2 ^ 0x80000000U;
-        STORE2(o64_1 >> 16, o64_2 >> 16);
-
-#else /* _NO_LONGLONG */
-
-        o64 = *(mlib_s64*)(buffo + i);
-        o64 = o64 ^ MLIB_U64_CONST(0x8000000080000000);
-        STORE2(o64 >> 48, o64 >> 16);
-
-#endif /* _NO_LONGLONG */
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      for (; i < wid; i++) {
-        p00 = buff0[i - 1]; p10 = buff1[i - 1];
-        p01 = buff0[i];     p11 = buff1[i];
-
-        buff2[i] = (mlib_s32)sp[0];
-
-        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - doff);
-        dp[0] = (buffo[i] >> 16) ^ 0x8000;
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      if (dx_r != 0) buff2[swid - 1] = buff2[swid - 2];
-
-      if (j < hgt - dy_b - 2) sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buffT;
-    }
-  }
-
-  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
-#undef  DTYPE
-#define DTYPE mlib_u8
-
-mlib_status mlib_c_conv2x2nw_u8(mlib_image       *dst,
-                                const mlib_image *src,
-                                const mlib_s32   *kern,
-                                mlib_s32         scalef_expon,
-                                mlib_s32         cmask)
-{
-  mlib_d64 buff_arr[2*BUFF_LINE];
-  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
-  DTYPE    *adr_src, *sl, *sp, *sl1;
-  DTYPE    *adr_dst, *dl, *dp;
-  mlib_d64 k0, k1, k2, k3, scalef = (1 << 24);
-  mlib_d64 p00, p01, p02,
-           p10, p11, p12;
-  mlib_s32 wid, hgt, sll, dll, wid1;
-  mlib_s32 nchannel, chan1, chan2;
-  mlib_s32 i, j, c;
-  LOAD_KERNEL_INTO_DOUBLE();
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  wid1 = (wid + 1) &~ 1;
-
-  if (wid1 > BUFF_LINE) {
-    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buffo = pbuff;
-  buff0 = buffo + wid1;
-  buff1 = buff0 + wid1;
-  buff2 = buff1 + wid1;
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  wid -= D_KER;
-  hgt -= D_KER;
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    sl1 = sl + sll;
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < wid + D_KER; i++) {
-      buff0[i - 1] = (mlib_s32)sl[i*chan1];
-      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
-    }
-
-    sl += (D_KER + 1)*sll;
-
-    for (j = 0; j < hgt; j++) {
-      sp = sl;
-      dp = dl;
-
-      buff2[-1] = (mlib_s32)sp[0];
-      sp += chan1;
-
-      p02 = buff0[-1];
-      p12 = buff1[-1];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-#ifdef _NO_LONGLONG
-        mlib_s32 o64_1, o64_2;
-#else /* _NO_LONGLONG */
-        mlib_s64 o64;
-#endif /* _NO_LONGLONG */
-        d64_2x32 sd0, sd1, dd;
-
-        p00 = p02; p10 = p12;
-
-        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
-        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
-        p01 = (mlib_d64)sd0.i32s.i0;
-        p02 = (mlib_d64)sd0.i32s.i1;
-        p11 = (mlib_d64)sd1.i32s.i0;
-        p12 = (mlib_d64)sd1.i32s.i1;
-
-        LOAD_BUFF(buff2);
-
-        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - (1u << 31));
-        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3 - (1u << 31));
-        *(TYPE_64BIT*)(buffo + i) = dd.d64;
-
-#ifdef _NO_LONGLONG
-
-        o64_1 = buffo[i];
-        o64_2 = buffo[i+1];
-        STORE2(o64_1 >> 24, o64_2 >> 24);
-
-#else /* _NO_LONGLONG */
-
-        o64 = *(mlib_s64*)(buffo + i);
-        STORE2(o64 >> 56, o64 >> 24);
-
-#endif /* _NO_LONGLONG */
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      for (; i < wid; i++) {
-        p00 = buff0[i - 1]; p10 = buff1[i - 1];
-        p01 = buff0[i];     p11 = buff1[i];
-
-        buff2[i] = (mlib_s32)sp[0];
-
-        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - (1u << 31));
-        dp[0] = (buffo[i] >> 24);
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buffT;
-    }
-  }
-
-  {
-    mlib_s32 amask = (1 << nchannel) - 1;
-
-    if ((cmask & amask) != amask) {
-      mlib_ImageXor80(adr_dst, wid, hgt, dll, nchannel, cmask);
-    } else {
-      mlib_ImageXor80_aa(adr_dst, wid*nchannel, hgt, dll);
-    }
-  }
-
-  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
-mlib_status mlib_c_conv2x2ext_u8(mlib_image       *dst,
-                                 const mlib_image *src,
-                                 mlib_s32         dx_l,
-                                 mlib_s32         dx_r,
-                                 mlib_s32         dy_t,
-                                 mlib_s32         dy_b,
-                                 const mlib_s32   *kern,
-                                 mlib_s32         scalef_expon,
-                                 mlib_s32         cmask)
-{
-  mlib_d64 buff_arr[4*BUFF_LINE];
-  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
-  DTYPE    *adr_src, *sl, *sp, *sl1;
-  DTYPE    *adr_dst, *dl, *dp;
-  mlib_d64 k0, k1, k2, k3, scalef = (1 << 24);
-  mlib_d64 p00, p01, p02,
-           p10, p11, p12;
-  mlib_s32 wid, hgt, sll, dll, wid1;
-  mlib_s32 nchannel, chan1, chan2;
-  mlib_s32 i, j, c, swid;
-  LOAD_KERNEL_INTO_DOUBLE();
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  swid = wid + D_KER;
-
-  wid1 = (swid + 1) &~ 1;
-
-  if (wid1 > BUFF_LINE) {
-    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buffo = pbuff;
-  buff0 = buffo + wid1;
-  buff1 = buff0 + wid1;
-  buff2 = buff1 + wid1;
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  swid -= dx_r;
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    if ((hgt - dy_b) > 0) sl1 = sl + sll;
-    else sl1 = sl;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < swid; i++) {
-      buff0[i - 1] = (mlib_s32)sl[i*chan1];
-      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
-    }
-
-    if (dx_r != 0) {
-      buff0[swid - 1] = buff0[swid - 2];
-      buff1[swid - 1] = buff1[swid - 2];
-    }
-
-    if ((hgt - dy_b) > 1) sl = sl1 + sll;
-    else sl = sl1;
-
-    for (j = 0; j < hgt; j++) {
-      sp = sl;
-      dp = dl;
-
-      buff2[-1] = (mlib_s32)sp[0];
-      sp += chan1;
-
-      p02 = buff0[-1];
-      p12 = buff1[-1];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-#ifdef _NO_LONGLONG
-        mlib_s32 o64_1, o64_2;
-#else /* _NO_LONGLONG */
-        mlib_s64 o64;
-#endif /* _NO_LONGLONG */
-        d64_2x32 sd0, sd1, dd;
-
-        p00 = p02; p10 = p12;
-
-        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
-        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
-        p01 = (mlib_d64)sd0.i32s.i0;
-        p02 = (mlib_d64)sd0.i32s.i1;
-        p11 = (mlib_d64)sd1.i32s.i0;
-        p12 = (mlib_d64)sd1.i32s.i1;
-
-        LOAD_BUFF(buff2);
-
-        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - (1u << 31));
-        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3 - (1u << 31));
-        *(TYPE_64BIT*)(buffo + i) = dd.d64;
-
-#ifdef _NO_LONGLONG
-
-        o64_1 = buffo[i];
-        o64_2 = buffo[i+1];
-        STORE2(o64_1 >> 24, o64_2 >> 24);
-
-#else /* _NO_LONGLONG */
-
-        o64 = *(mlib_s64*)(buffo + i);
-        STORE2(o64 >> 56, o64 >> 24);
-
-#endif /* _NO_LONGLONG */
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      for (; i < wid; i++) {
-        p00 = buff0[i - 1]; p10 = buff1[i - 1];
-        p01 = buff0[i];     p11 = buff1[i];
-
-        buff2[i] = (mlib_s32)sp[0];
-
-        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - (1u << 31));
-        dp[0] = (buffo[i] >> 24);
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      if (dx_r != 0) buff2[swid - 1] = buff2[swid - 2];
-
-      if (j < hgt - dy_b - 2) sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buffT;
-    }
-  }
-
-  {
-    mlib_s32 amask = (1 << nchannel) - 1;
-
-    if ((cmask & amask) != amask) {
-      mlib_ImageXor80(adr_dst, wid, hgt, dll, nchannel, cmask);
-    } else {
-      mlib_ImageXor80_aa(adr_dst, wid*nchannel, hgt, dll);
-    }
-  }
-
-  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
--- a/src/java.desktop/share/native/libmlib_image/mlib_ImageConv_16ext.c	Thu May 12 11:03:07 2016 -0700
+++ b/src/java.desktop/share/native/libmlib_image/mlib_ImageConv_16ext.c	Fri May 13 11:31:05 2016 +0300
@@ -80,9 +80,6 @@
 #endif /* IMG_TYPE == 1 */
 
 /***************************************************************/
-#define KSIZE1 (KSIZE - 1)
-
-/***************************************************************/
 #define PARAM                                                   \
   mlib_image       *dst,                                        \
   const mlib_image *src,                                        \
@@ -163,9 +160,6 @@
 #endif /* _NO_LONGLONG */
 
 /***************************************************************/
-#define MLIB_D2_24 16777216.0f
-
-/***************************************************************/
 typedef union {
   mlib_d64 d64;
   struct {
@@ -175,52 +169,6 @@
 } d64_2x32;
 
 /***************************************************************/
-#define BUFF_LINE 256
-
-/***************************************************************/
-#define DEF_VARS(type)                                          \
-  type     *adr_src, *sl, *sp, *sl1;                            \
-  type     *adr_dst, *dl, *dp;                                  \
-  FTYPE    *pbuff = buff;                                       \
-  mlib_s32 *buffi, *buffo;                                      \
-  mlib_s32 wid, hgt, sll, dll;                                  \
-  mlib_s32 nchannel, chan1, chan2;                              \
-  mlib_s32 i, j, c, swid
-
-/***************************************************************/
-#define LOAD_KERNEL3()                                                   \
-  FTYPE    scalef = DSCALE;                                              \
-  FTYPE    k0, k1, k2, k3, k4, k5, k6, k7, k8;                           \
-  FTYPE    p00, p01, p02, p03,                                           \
-           p10, p11, p12, p13,                                           \
-           p20, p21, p22, p23;                                           \
-                                                                         \
-  while (scalef_expon > 30) {                                            \
-    scalef /= (1 << 30);                                                 \
-    scalef_expon -= 30;                                                  \
-  }                                                                      \
-                                                                         \
-  scalef /= (1 << scalef_expon);                                         \
-                                                                         \
-  /* keep kernel in regs */                                              \
-  k0 = scalef * kern[0];  k1 = scalef * kern[1];  k2 = scalef * kern[2]; \
-  k3 = scalef * kern[3];  k4 = scalef * kern[4];  k5 = scalef * kern[5]; \
-  k6 = scalef * kern[6];  k7 = scalef * kern[7];  k8 = scalef * kern[8]
-
-/***************************************************************/
-#define LOAD_KERNEL(SIZE)                                       \
-  FTYPE    scalef = DSCALE;                                     \
-                                                                \
-  while (scalef_expon > 30) {                                   \
-    scalef /= (1 << 30);                                        \
-    scalef_expon -= 30;                                         \
-  }                                                             \
-                                                                \
-  scalef /= (1 << scalef_expon);                                \
-                                                                \
-  for (j = 0; j < SIZE; j++) k[j] = scalef * kern[j]
-
-/***************************************************************/
 #define GET_SRC_DST_PARAMETERS(type)                            \
   hgt = mlib_ImageGetHeight(src);                               \
   wid = mlib_ImageGetWidth(src);                                \
@@ -278,1334 +226,6 @@
 #endif /* __sparc */
 
 /***************************************************************/
-#define KSIZE  3
-
-mlib_status CONV_FUNC(3x3)
-{
-  FTYPE    buff[(KSIZE + 2)*BUFF_LINE], *buff0, *buff1, *buff2, *buff3, *buffT;
-  DEF_VARS(DTYPE);
-  DTYPE *sl2;
-#ifndef __sparc
-  mlib_s32 d0, d1;
-#endif /* __sparc */
-  LOAD_KERNEL3();
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  swid = wid + KSIZE1;
-
-  if (swid > BUFF_LINE) {
-    pbuff = mlib_malloc((KSIZE + 2)*sizeof(FTYPE   )*swid);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buff0 = pbuff;
-  buff1 = buff0 + swid;
-  buff2 = buff1 + swid;
-  buff3 = buff2 + swid;
-  buffo = (mlib_s32*)(buff3 + swid);
-  buffi = buffo + (swid &~ 1);
-
-  swid -= (dx_l + dx_r);
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    if ((1 > dy_t) && (1 < hgt + KSIZE1 - dy_b)) sl1 = sl + sll;
-    else sl1 = sl;
-
-    if ((hgt - dy_b) > 0) sl2 = sl1 + sll;
-    else sl2 = sl1;
-
-    for (i = 0; i < dx_l; i++) {
-      buff0[i] = (FTYPE)sl[0];
-      buff1[i] = (FTYPE)sl1[0];
-      buff2[i] = (FTYPE)sl2[0];
-    }
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < swid; i++) {
-      buff0[i + dx_l] = (FTYPE)sl[i*chan1];
-      buff1[i + dx_l] = (FTYPE)sl1[i*chan1];
-      buff2[i + dx_l] = (FTYPE)sl2[i*chan1];
-    }
-
-    for (i = 0; i < dx_r; i++) {
-      buff0[swid + dx_l + i] = buff0[swid + dx_l - 1];
-      buff1[swid + dx_l + i] = buff1[swid + dx_l - 1];
-      buff2[swid + dx_l + i] = buff2[swid + dx_l - 1];
-    }
-
-    if ((hgt - dy_b) > 1) sl = sl2 + sll;
-    else sl = sl2;
-
-    for (j = 0; j < hgt; j++) {
-      FTYPE    s0, s1;
-
-      p02 = buff0[0];
-      p12 = buff1[0];
-      p22 = buff2[0];
-
-      p03 = buff0[1];
-      p13 = buff1[1];
-      p23 = buff2[1];
-
-      s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-      s1 = p03 * k0 + p13 * k3 + p23 * k6;
-
-      sp = sl;
-      dp = dl;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-#ifdef __sparc
-#ifdef _NO_LONGLONG
-        mlib_s32 o64_1, o64_2;
-#else /* _NO_LONGLONG */
-        mlib_s64 o64;
-#endif /* _NO_LONGLONG */
-#endif /* __sparc */
-        d64_2x32 dd;
-
-        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2];
-        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3];
-
-        LOAD_BUFF(buffi);
-
-        dd.d64 = *(FTYPE   *)(buffi + i);
-        buff3[i + dx_l    ] = (FTYPE)dd.i32s.i0;
-        buff3[i + dx_l + 1] = (FTYPE)dd.i32s.i1;
-
-#ifndef __sparc
-
-        d0 = D2I(s0 + p02 * k2 + p12 * k5 + p22 * k8);
-        d1 = D2I(s1 + p02 * k1 + p03 * k2 + p12 * k4 + p13 * k5 + p22 * k7 + p23 * k8);
-
-        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-        s1 = p03 * k0 + p13 * k3 + p23 * k6;
-
-        dp[0    ] = FROM_S32(d0);
-        dp[chan1] = FROM_S32(d1);
-
-#else /* __sparc */
-
-        dd.i32s.i0 = D2I(s0 + p02 * k2 + p12 * k5 + p22 * k8);
-        dd.i32s.i1 = D2I(s1 + p02 * k1 + p03 * k2 + p12 * k4 + p13 * k5 + p22 * k7 + p23 * k8);
-        *(FTYPE   *)(buffo + i) = dd.d64;
-
-        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-        s1 = p03 * k0 + p13 * k3 + p23 * k6;
-
-#ifdef _NO_LONGLONG
-
-        o64_1 = buffo[i];
-        o64_2 = buffo[i+1];
-#if IMG_TYPE != 1
-        STORE2(FROM_S32(o64_1), FROM_S32(o64_2));
-#else
-        STORE2(o64_1 >> 24, o64_2 >> 24);
-#endif /* IMG_TYPE != 1 */
-
-#else /* _NO_LONGLONG */
-
-        o64 = *(mlib_s64*)(buffo + i);
-#if IMG_TYPE != 1
-        STORE2(FROM_S32(o64 >> 32), FROM_S32(o64));
-#else
-        STORE2(o64 >> 56, o64 >> 24);
-#endif /* IMG_TYPE != 1 */
-#endif /* _NO_LONGLONG */
-#endif /* __sparc */
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      for (; i < wid; i++) {
-        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];
-        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1];
-        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2];
-
-        buffi[i] = (mlib_s32)sp[0];
-        buff3[i + dx_l] = (FTYPE)buffi[i];
-
-#ifndef __sparc
-
-        d0 = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p10 * k3 + p11 * k4 +
-                 p12 * k5 + p20 * k6 + p21 * k7 + p22 * k8);
-
-        dp[0] = FROM_S32(d0);
-
-#else  /* __sparc */
-
-        buffo[i] = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p10 * k3 + p11 * k4 +
-                       p12 * k5 + p20 * k6 + p21 * k7 + p22 * k8);
-#if IMG_TYPE != 1
-        dp[0] = FROM_S32(buffo[i]);
-#else
-        dp[0] = buffo[i] >> 24;
-#endif /* IMG_TYPE != 1 */
-#endif /* __sparc */
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      for (; i < swid; i++) {
-        buffi[i] = (mlib_s32)sp[0];
-        buff3[i + dx_l] = (FTYPE)buffi[i];
-        sp += chan1;
-      }
-
-      for (i = 0; i < dx_l; i++) buff3[i] = buff3[dx_l];
-      for (i = 0; i < dx_r; i++) buff3[swid + dx_l + i] = buff3[swid + dx_l - 1];
-
-      if (j < hgt - dy_b - 2) sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buff3;
-      buff3 = buffT;
-    }
-  }
-
-#ifdef __sparc
-#if IMG_TYPE == 1
-  {
-    mlib_s32 amask = (1 << nchannel) - 1;
-
-    if ((cmask & amask) != amask) {
-      mlib_ImageXor80(adr_dst, wid, hgt, dll, nchannel, cmask);
-    } else {
-      mlib_ImageXor80_aa(adr_dst, wid*nchannel, hgt, dll);
-    }
-  }
-
-#endif /* IMG_TYPE == 1 */
-#endif /* __sparc */
-
-  if (pbuff != buff) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
-#ifndef __sparc /* for x86, using integer multiplies is faster */
-
-mlib_status CONV_FUNC_I(3x3)
-{
-  DTYPE    *adr_src, *sl, *sp0, *sp1, *sp2, *sp_1, *sp_2;
-  DTYPE    *adr_dst, *dl, *dp;
-  mlib_s32 wid, hgt, sll, dll;
-  mlib_s32 nchannel, chan1, chan2, delta_chan;
-  mlib_s32 i, j, c;
-  mlib_s32 shift1, shift2;
-  mlib_s32 k0, k1, k2, k3, k4, k5, k6, k7, k8;
-  mlib_s32 p02, p03,
-           p12, p13,
-           p22, p23;
-
-#if IMG_TYPE != 1
-  shift1 = 16;
-#else
-  shift1 = 8;
-#endif /* IMG_TYPE != 1 */
-
-  shift2 = scalef_expon - shift1;
-
-  /* keep kernel in regs */
-  k0 = kern[0] >> shift1;  k1 = kern[1] >> shift1;  k2 = kern[2] >> shift1;
-  k3 = kern[3] >> shift1;  k4 = kern[4] >> shift1;  k5 = kern[5] >> shift1;
-  k6 = kern[6] >> shift1;  k7 = kern[7] >> shift1;  k8 = kern[8] >> shift1;
-
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-  delta_chan = 0;
-
-  if ((1 > dx_l) && (1 < wid + KSIZE1 - dx_r)) delta_chan = chan1;
-
-  for (c = 0; c < chan1; c++) {
-    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    sp_1 = sl;
-
-    if ((1 > dy_t) && (1 < hgt + KSIZE1 - dy_b)) sl += sll;
-    sp_2 = sl;
-
-    if ((hgt - dy_b) > 0) sl += sll;
-
-    for (j = 0; j < hgt; j++) {
-      mlib_s32 s0, s1;
-      mlib_s32 pix0, pix1;
-
-      dp  = dl;
-      sp0 = sp_1;
-      sp_1 = sp_2;
-      sp_2 = sl;
-
-      sp1 = sp_1;
-      sp2 = sp_2;
-
-      p02 = sp0[0];
-      p12 = sp1[0];
-      p22 = sp2[0];
-
-      p03 = sp0[delta_chan];
-      p13 = sp1[delta_chan];
-      p23 = sp2[delta_chan];
-
-      s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-      s1 = p03 * k0 + p13 * k3 + p23 * k6;
-
-      sp0 += (chan1 + delta_chan);
-      sp1 += (chan1 + delta_chan);
-      sp2 += (chan1 + delta_chan);
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - dx_r - 2); i += 2) {
-        p02 = sp0[0];     p12 = sp1[0];     p22 = sp2[0];
-        p03 = sp0[chan1]; p13 = sp1[chan1]; p23 = sp2[chan1];
-
-        pix0 = (s0 + p02 * k2 + p12 * k5 + p22 * k8) >> shift2;
-        pix1 = (s1 + p02 * k1 + p03 * k2 + p12 * k4 +
-                p13 * k5 + p22 * k7 + p23 * k8) >> shift2;
-
-        CLAMP_STORE(dp[0],     pix0);
-        CLAMP_STORE(dp[chan1], pix1);
-
-        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-        s1 = p03 * k0 + p13 * k3 + p23 * k6;
-
-        sp0 += chan2;
-        sp1 += chan2;
-        sp2 += chan2;
-        dp += chan2;
-      }
-
-      p02 = p03; p12 = p13; p22 = p23;
-
-      for (; i < wid - dx_r; i++) {
-        p03 = sp0[0]; p13 = sp1[0]; p23 = sp2[0];
-        pix0 = (s0 + p03 * k2 + p13 * k5 + p23 * k8) >> shift2;
-        CLAMP_STORE(dp[0], pix0);
-        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-        p02 = p03; p12 = p13; p22 = p23;
-        sp0 += chan1;
-        sp1 += chan1;
-        sp2 += chan1;
-        dp += chan1;
-      }
-
-      sp0 -= chan1;
-      sp1 -= chan1;
-      sp2 -= chan1;
-
-      for (; i < wid; i++) {
-        p03 = sp0[0]; p13 = sp1[0]; p23 = sp2[0];
-        pix0 = (s0 + p03 * k2 + p13 * k5 + p23 * k8) >> shift2;
-        CLAMP_STORE(dp[0], pix0);
-        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-        p02 = p03; p12 = p13; p22 = p23;
-        dp += chan1;
-      }
-
-      if (j < hgt - dy_b - 1) sl += sll;
-      dl += dll;
-    }
-  }
-
-  return MLIB_SUCCESS;
-}
-
-#endif /* __sparc ( for x86, using integer multiplies is faster ) */
-
-/***************************************************************/
-#undef  KSIZE
-#define KSIZE 4
-
-mlib_status CONV_FUNC(4x4)
-{
-  FTYPE    buff[(KSIZE + 3)*BUFF_LINE];
-  FTYPE    *buff0, *buff1, *buff2, *buff3, *buff4, *buffd, *buffT;
-  FTYPE    k[KSIZE*KSIZE];
-  mlib_s32 d0, d1;
-  FTYPE    k0, k1, k2, k3, k4, k5, k6, k7;
-  FTYPE    p00, p01, p02, p03, p04,
-           p10, p11, p12, p13, p14,
-           p20, p21, p22, p23,
-           p30, p31, p32, p33;
-  DEF_VARS(DTYPE);
-  DTYPE *sl2, *sl3;
-  LOAD_KERNEL(KSIZE*KSIZE);
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  swid = wid + KSIZE1;
-
-  if (swid > BUFF_LINE) {
-    pbuff = mlib_malloc((KSIZE + 3)*sizeof(FTYPE   )*swid);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buff0 = pbuff;
-  buff1 = buff0 + swid;
-  buff2 = buff1 + swid;
-  buff3 = buff2 + swid;
-  buff4 = buff3 + swid;
-  buffd = buff4 + swid;
-  buffo = (mlib_s32*)(buffd + swid);
-  buffi = buffo + (swid &~ 1);
-
-  swid -= (dx_l + dx_r);
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    if ((1 > dy_t) && (1 < hgt + KSIZE1 - dy_b)) sl1 = sl + sll;
-    else sl1 = sl;
-
-    if ((2 > dy_t) && (2 < hgt + KSIZE1 - dy_b)) sl2 = sl1 + sll;
-    else sl2 = sl1;
-
-    if ((hgt - dy_b) > 0) sl3 = sl2 + sll;
-    else sl3 = sl2;
-
-    for (i = 0; i < dx_l; i++) {
-      buff0[i] = (FTYPE)sl[0];
-      buff1[i] = (FTYPE)sl1[0];
-      buff2[i] = (FTYPE)sl2[0];
-      buff3[i] = (FTYPE)sl3[0];
-    }
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < swid; i++) {
-      buff0[i + dx_l] = (FTYPE)sl[i*chan1];
-      buff1[i + dx_l] = (FTYPE)sl1[i*chan1];
-      buff2[i + dx_l] = (FTYPE)sl2[i*chan1];
-      buff3[i + dx_l] = (FTYPE)sl3[i*chan1];
-    }
-
-    for (i = 0; i < dx_r; i++) {
-      buff0[swid + dx_l + i] = buff0[swid + dx_l - 1];
-      buff1[swid + dx_l + i] = buff1[swid + dx_l - 1];
-      buff2[swid + dx_l + i] = buff2[swid + dx_l - 1];
-      buff3[swid + dx_l + i] = buff3[swid + dx_l - 1];
-    }
-
-    if ((hgt - dy_b) > 1) sl = sl3 + sll;
-    else sl = sl3;
-
-    for (j = 0; j < hgt; j++) {
-      d64_2x32 dd;
-
-      /*
-       *  First loop on two first lines of kernel
-       */
-      k0 = k[0]; k1 = k[1]; k2 = k[2]; k3 = k[3];
-      k4 = k[4]; k5 = k[5]; k6 = k[6]; k7 = k[7];
-
-      sp = sl;
-      dp = dl;
-
-      p02 = buff0[0];
-      p12 = buff1[0];
-      p03 = buff0[1];
-      p13 = buff1[1];
-      p04 = buff0[2];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = buff1[i + 2];
-        p03 = buff0[i + 3]; p13 = buff1[i + 3];
-        p04 = buff0[i + 4]; p14 = buff1[i + 4];
-
-        LOAD_BUFF(buffi);
-
-        dd.d64 = *(FTYPE   *)(buffi + i);
-        buff4[i + dx_l    ] = (FTYPE)dd.i32s.i0;
-        buff4[i + dx_l + 1] = (FTYPE)dd.i32s.i1;
-
-        buffd[i    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
-                        p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7);
-        buffd[i + 1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 +
-                        p11 * k4 + p12 * k5 + p13 * k6 + p14 * k7);
-
-        sp += chan2;
-      }
-
-      /*
-       *  Second loop on two last lines of kernel
-       */
-      k0 = k[ 8]; k1 = k[ 9]; k2 = k[10]; k3 = k[11];
-      k4 = k[12]; k5 = k[13]; k6 = k[14]; k7 = k[15];
-
-      p02 = buff2[0];
-      p12 = buff3[0];
-      p03 = buff2[1];
-      p13 = buff3[1];
-      p04 = buff2[2];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = buff3[i + 2];
-        p03 = buff2[i + 3]; p13 = buff3[i + 3];
-        p04 = buff2[i + 4]; p14 = buff3[i + 4];
-
-        d0 = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
-                 p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7 + buffd[i]);
-        d1 = D2I(p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 +
-                 p11 * k4 + p12 * k5 + p13 * k6 + p14 * k7 + buffd[i + 1]);
-
-        dp[0    ] = FROM_S32(d0);
-        dp[chan1] = FROM_S32(d1);
-
-        dp += chan2;
-      }
-
-      /* last pixels */
-      for (; i < wid; i++) {
-        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];     p30 = buff3[i];
-        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1]; p31 = buff3[i + 1];
-        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2]; p32 = buff3[i + 2];
-        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3]; p33 = buff3[i + 3];
-
-        buff4[i + dx_l] = (FTYPE)sp[0];
-
-        buffo[i] = D2I(p00 * k[0] + p01 * k[1] + p02 * k[2] + p03 * k[3] +
-                       p10 * k[4] + p11 * k[5] + p12 * k[6] + p13 * k[7] +
-                       p20 * k[ 8] + p21 * k[ 9] + p22 * k[10] + p23 * k[11] +
-                       p30 * k[12] + p31 * k[13] + p32 * k[14] + p33 * k[15]);
-
-        dp[0] = FROM_S32(buffo[i]);
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      for (; i < swid; i++) {
-        buff4[i + dx_l] = (FTYPE)sp[0];
-        sp += chan1;
-      }
-
-      for (i = 0; i < dx_l; i++) buff4[i] = buff4[dx_l];
-      for (i = 0; i < dx_r; i++) buff4[swid + dx_l + i] = buff4[swid + dx_l - 1];
-
-      /* next line */
-
-      if (j < hgt - dy_b - 2) sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buff3;
-      buff3 = buff4;
-      buff4 = buffT;
-    }
-  }
-
-  if (pbuff != buff) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
-#undef  KSIZE
-#define KSIZE 5
-
-mlib_status CONV_FUNC(5x5)
-{
-  FTYPE    buff[(KSIZE + 3)*BUFF_LINE];
-  FTYPE    *buff0, *buff1, *buff2, *buff3, *buff4, *buff5, *buffd, *buffT;
-  FTYPE    k[KSIZE*KSIZE];
-  mlib_s32 d0, d1;
-  FTYPE    k0, k1, k2, k3, k4, k5, k6, k7, k8, k9;
-  FTYPE    p00, p01, p02, p03, p04, p05,
-           p10, p11, p12, p13, p14, p15,
-           p20, p21, p22, p23, p24,
-           p30, p31, p32, p33, p34,
-           p40, p41, p42, p43, p44;
-  DEF_VARS(DTYPE);
-  DTYPE *sl2, *sl3, *sl4;
-  LOAD_KERNEL(KSIZE*KSIZE);
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  swid = wid + KSIZE1;
-
-  if (swid > BUFF_LINE) {
-    pbuff = mlib_malloc((KSIZE + 3)*sizeof(FTYPE   )*swid);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buff0 = pbuff;
-  buff1 = buff0 + swid;
-  buff2 = buff1 + swid;
-  buff3 = buff2 + swid;
-  buff4 = buff3 + swid;
-  buff5 = buff4 + swid;
-  buffd = buff5 + swid;
-  buffo = (mlib_s32*)(buffd + swid);
-  buffi = buffo + (swid &~ 1);
-
-  swid -= (dx_l + dx_r);
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    if ((1 > dy_t) && (1 < hgt + KSIZE1 - dy_b)) sl1 = sl + sll;
-    else sl1 = sl;
-
-    if ((2 > dy_t) && (2 < hgt + KSIZE1 - dy_b)) sl2 = sl1 + sll;
-    else sl2 = sl1;
-
-    if ((3 > dy_t) && (3 < hgt + KSIZE1 - dy_b)) sl3 = sl2 + sll;
-    else sl3 = sl2;
-
-    if ((hgt - dy_b) > 0) sl4 = sl3 + sll;
-    else sl4 = sl3;
-
-    for (i = 0; i < dx_l; i++) {
-      buff0[i] = (FTYPE)sl[0];
-      buff1[i] = (FTYPE)sl1[0];
-      buff2[i] = (FTYPE)sl2[0];
-      buff3[i] = (FTYPE)sl3[0];
-      buff4[i] = (FTYPE)sl4[0];
-    }
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < swid; i++) {
-      buff0[i + dx_l] = (FTYPE)sl[i*chan1];
-      buff1[i + dx_l] = (FTYPE)sl1[i*chan1];
-      buff2[i + dx_l] = (FTYPE)sl2[i*chan1];
-      buff3[i + dx_l] = (FTYPE)sl3[i*chan1];
-      buff4[i + dx_l] = (FTYPE)sl4[i*chan1];
-    }
-
-    for (i = 0; i < dx_r; i++) {
-      buff0[swid + dx_l + i] = buff0[swid + dx_l - 1];
-      buff1[swid + dx_l + i] = buff1[swid + dx_l - 1];
-      buff2[swid + dx_l + i] = buff2[swid + dx_l - 1];
-      buff3[swid + dx_l + i] = buff3[swid + dx_l - 1];
-      buff4[swid + dx_l + i] = buff4[swid + dx_l - 1];
-    }
-
-    if ((hgt - dy_b) > 1) sl = sl4 + sll;
-    else sl = sl4;
-
-    for (j = 0; j < hgt; j++) {
-      d64_2x32 dd;
-
-      /*
-       *  First loop
-       */
-      k0 = k[0]; k1 = k[1]; k2 = k[2]; k3 = k[3]; k4 = k[4];
-      k5 = k[5]; k6 = k[6]; k7 = k[7]; k8 = k[8]; k9 = k[9];
-
-      sp = sl;
-      dp = dl;
-
-      p02 = buff0[0];
-      p12 = buff1[0];
-      p03 = buff0[1];
-      p13 = buff1[1];
-      p04 = buff0[2];
-      p14 = buff1[2];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = p14;
-
-        LOAD_BUFF(buffi);
-
-        p03 = buff0[i + 3]; p13 = buff1[i + 3];
-        p04 = buff0[i + 4]; p14 = buff1[i + 4];
-        p05 = buff0[i + 5]; p15 = buff1[i + 5];
-
-        buffd[i    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                        p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-        buffd[i + 1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
-                        p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
-
-        sp += chan2;
-      }
-
-      /*
-       *  Second loop
-       */
-      k0 = k[10]; k1 = k[11]; k2 = k[12]; k3 = k[13]; k4 = k[14];
-      k5 = k[15]; k6 = k[16]; k7 = k[17]; k8 = k[18]; k9 = k[19];
-
-      p02 = buff2[0];
-      p12 = buff3[0];
-      p03 = buff2[1];
-      p13 = buff3[1];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-
-        p02 = buff2[i + 2]; p12 = buff3[i + 2];
-        p03 = buff2[i + 3]; p13 = buff3[i + 3];
-        p04 = buff2[i + 4]; p14 = buff3[i + 4];
-        p05 = buff2[i + 5]; p15 = buff3[i + 5];
-
-        dd.d64 = *(FTYPE   *)(buffi + i);
-        buff5[i + dx_l    ] = (FTYPE)dd.i32s.i0;
-        buff5[i + dx_l + 1] = (FTYPE)dd.i32s.i1;
-
-        buffd[i    ] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                         p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-        buffd[i + 1] += (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
-                         p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
-      }
-
-      /*
-       *  3 loop
-       */
-      k0 = k[20]; k1 = k[21]; k2 = k[22]; k3 = k[23]; k4 = k[24];
-
-      p02 = buff4[0];
-      p03 = buff4[1];
-      p04 = buff4[2];
-      p05 = buff4[3];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p01 = p03; p02 = p04; p03 = p05;
-
-        p04 = buff4[i + 4]; p05 = buff4[i + 5];
-
-        d0 = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 + buffd[i]);
-        d1 = D2I(p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 + buffd[i + 1]);
-
-        dp[0    ] = FROM_S32(d0);
-        dp[chan1] = FROM_S32(d1);
-
-        dp += chan2;
-      }
-
-      /* last pixels */
-      for (; i < wid; i++) {
-        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];     p30 = buff3[i];
-        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1]; p31 = buff3[i + 1];
-        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2]; p32 = buff3[i + 2];
-        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3]; p33 = buff3[i + 3];
-        p04 = buff0[i + 4]; p14 = buff1[i + 4]; p24 = buff2[i + 4]; p34 = buff3[i + 4];
-
-        p40 = buff4[i];     p41 = buff4[i + 1]; p42 = buff4[i + 2];
-        p43 = buff4[i + 3]; p44 = buff4[i + 4];
-
-        buff5[i + dx_l] = (FTYPE)sp[0];
-
-        buffo[i] = D2I(p00 * k[0] + p01 * k[1] + p02 * k[2] + p03 * k[3] + p04 * k[4] +
-                       p10 * k[5] + p11 * k[6] + p12 * k[7] + p13 * k[8] + p14 * k[9] +
-                       p20 * k[10] + p21 * k[11] + p22 * k[12] + p23 * k[13] + p24 * k[14] +
-                       p30 * k[15] + p31 * k[16] + p32 * k[17] + p33 * k[18] + p34 * k[19] +
-                       p40 * k[20] + p41 * k[21] + p42 * k[22] + p43 * k[23] + p44 * k[24]);
-
-        dp[0] = FROM_S32(buffo[i]);
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      for (; i < swid; i++) {
-        buff5[i + dx_l] = (FTYPE)sp[0];
-        sp += chan1;
-      }
-
-      for (i = 0; i < dx_l; i++) buff5[i] = buff5[dx_l];
-      for (i = 0; i < dx_r; i++) buff5[swid + dx_l + i] = buff5[swid + dx_l - 1];
-
-      /* next line */
-
-      if (j < hgt - dy_b - 2) sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buff3;
-      buff3 = buff4;
-      buff4 = buff5;
-      buff5 = buffT;
-    }
-  }
-
-  if (pbuff != buff) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
-#ifndef __sparc /* for x86, using integer multiplies is faster */
-
-mlib_status CONV_FUNC_I(5x5)
-{
-  mlib_s32 buff[BUFF_LINE];
-  mlib_s32 *buffd;
-  mlib_s32 k[KSIZE*KSIZE];
-  mlib_s32 shift1, shift2;
-  mlib_s32 k0, k1, k2, k3, k4, k5, k6, k7, k8, k9;
-  mlib_s32 p00, p01, p02, p03, p04, p05,
-           p10, p11, p12, p13, p14, p15;
-  DTYPE    *adr_src, *sl, *sp0, *sp1, *sp2, *sp3, *sp4;
-  DTYPE    *sp_1, *sp_2, *sp_3, *sp_4;
-  DTYPE    *adr_dst, *dl, *dp;
-  mlib_s32 *pbuff = buff;
-  mlib_s32 wid, hgt, sll, dll;
-  mlib_s32 nchannel, chan1, chan2, chan4;
-  mlib_s32 delta_chan1, delta_chan2, delta_chan3;
-  mlib_s32 i, j, c;
-
-#if IMG_TYPE != 1
-  shift1 = 16;
-#else
-  shift1 = 8;
-#endif /* IMG_TYPE != 1 */
-
-  shift2 = scalef_expon - shift1;
-
-  for (j = 0; j < KSIZE*KSIZE; j++) k[j] = kern[j] >> shift1;
-
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  if (wid > BUFF_LINE) {
-    pbuff = mlib_malloc(sizeof(mlib_s32)*wid);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buffd = pbuff;
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  if ((1 > dx_l) && (1 < wid + KSIZE1 - dx_r)) delta_chan1 = chan1;
-  else delta_chan1 = 0;
-
-  if ((2 > dx_l) && (2 < wid + KSIZE1 - dx_r)) delta_chan2 = delta_chan1 + chan1;
-  else delta_chan2 = delta_chan1;
-
-  if ((3 > dx_l) && (3 < wid + KSIZE1 - dx_r)) delta_chan3 = delta_chan2 + chan1;
-  else delta_chan3 = delta_chan2;
-
-  chan4 = chan1 + delta_chan3;
-
-  for (c = 0; c < chan1; c++) {
-    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    sp_1 = sl;
-
-    if ((1 > dy_t) && (1 < hgt + KSIZE1 - dy_b)) sl += sll;
-    sp_2 = sl;
-
-    if ((2 > dy_t) && (2 < hgt + KSIZE1 - dy_b)) sl += sll;
-    sp_3 = sl;
-
-    if ((3 > dy_t) && (3 < hgt + KSIZE1 - dy_b)) sl += sll;
-    sp_4 = sl;
-
-    if ((hgt - dy_b) > 0) sl += sll;
-
-    for (j = 0; j < hgt; j++) {
-      mlib_s32 pix0, pix1;
-
-      dp  = dl;
-      sp0 = sp_1;
-      sp_1 = sp_2;
-      sp_2 = sp_3;
-      sp_3 = sp_4;
-      sp_4 = sl;
-
-      sp1 = sp_1;
-      sp2 = sp_2;
-      sp3 = sp_3;
-      sp4 = sp_4;
-
-      /*
-       *  First loop
-       */
-
-      k0 = k[0]; k1 = k[1]; k2 = k[2]; k3 = k[3]; k4 = k[4];
-      k5 = k[5]; k6 = k[6]; k7 = k[7]; k8 = k[8]; k9 = k[9];
-
-      p02 = sp0[0];           p12 = sp1[0];
-      p03 = sp0[delta_chan1]; p13 = sp1[delta_chan1];
-      p04 = sp0[delta_chan2]; p14 = sp1[delta_chan2];
-      p05 = sp0[delta_chan3]; p15 = sp1[delta_chan3];
-
-      sp0 += chan4;
-      sp1 += chan4;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - dx_r - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = p14;
-        p03 = p05; p13 = p15;
-
-        p04 = sp0[0];     p14 = sp1[0];
-        p05 = sp0[chan1]; p15 = sp1[chan1];
-
-        buffd[i    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                        p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-        buffd[i + 1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
-                        p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
-
-        sp0 += chan2;
-        sp1 += chan2;
-      }
-
-      p01 = p02; p02 = p03; p03 = p04; p04 = p05;
-      p11 = p12; p12 = p13; p13 = p14; p14 = p15;
-
-      for (; i < wid - dx_r; i++) {
-        p00 = p01; p10 = p11;
-        p01 = p02; p11 = p12;
-        p02 = p03; p12 = p13;
-        p03 = p04; p13 = p14;
-
-        p04 = sp0[0];     p14 = sp1[0];
-
-        buffd[i] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                    p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-
-        sp0 += chan1;
-        sp1 += chan1;
-      }
-
-      sp0 -= chan1;
-      sp1 -= chan1;
-
-      for (; i < wid; i++) {
-        p00 = p01; p10 = p11;
-        p01 = p02; p11 = p12;
-        p02 = p03; p12 = p13;
-        p03 = p04; p13 = p14;
-
-        p04 = sp0[0];     p14 = sp1[0];
-
-        buffd[i] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                    p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-      }
-
-      /*
-       *  Second loop
-       */
-
-      k0 = k[10]; k1 = k[11]; k2 = k[12]; k3 = k[13]; k4 = k[14];
-      k5 = k[15]; k6 = k[16]; k7 = k[17]; k8 = k[18]; k9 = k[19];
-
-      p02 = sp2[0];           p12 = sp3[0];
-      p03 = sp2[delta_chan1]; p13 = sp3[delta_chan1];
-      p04 = sp2[delta_chan2]; p14 = sp3[delta_chan2];
-      p05 = sp2[delta_chan3]; p15 = sp3[delta_chan3];
-
-      sp2 += chan4;
-      sp3 += chan4;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - dx_r - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = p14;
-        p03 = p05; p13 = p15;
-
-        p04 = sp2[0];     p14 = sp3[0];
-        p05 = sp2[chan1]; p15 = sp3[chan1];
-
-        buffd[i    ] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                         p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-        buffd[i + 1] += (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
-                         p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
-
-        sp2 += chan2;
-        sp3 += chan2;
-      }
-
-      p01 = p02; p02 = p03; p03 = p04; p04 = p05;
-      p11 = p12; p12 = p13; p13 = p14; p14 = p15;
-
-      for (; i < wid - dx_r; i++) {
-        p00 = p01; p10 = p11;
-        p01 = p02; p11 = p12;
-        p02 = p03; p12 = p13;
-        p03 = p04; p13 = p14;
-
-        p04 = sp2[0];     p14 = sp3[0];
-
-        buffd[i] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                     p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-
-        sp2 += chan1;
-        sp3 += chan1;
-      }
-
-      sp2 -= chan1;
-      sp3 -= chan1;
-
-      for (; i < wid; i++) {
-        p00 = p01; p10 = p11;
-        p01 = p02; p11 = p12;
-        p02 = p03; p12 = p13;
-        p03 = p04; p13 = p14;
-
-        p04 = sp2[0];     p14 = sp3[0];
-
-        buffd[i] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                     p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-      }
-
-      /*
-       *  3 loop
-       */
-
-      k0 = k[20]; k1 = k[21]; k2 = k[22]; k3 = k[23]; k4 = k[24];
-
-      p02 = sp4[0];
-      p03 = sp4[delta_chan1];
-      p04 = sp4[delta_chan2];
-      p05 = sp4[delta_chan3];
-
-      sp4 += chan4;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - dx_r - 2); i += 2) {
-        p00 = p02; p01 = p03; p02 = p04; p03 = p05;
-
-        p04 = sp4[0]; p05 = sp4[chan1];
-
-        pix0 = (buffd[i    ] + p00 * k0 + p01 * k1 + p02 * k2 +
-                p03 * k3 + p04 * k4) >> shift2;
-        pix1 = (buffd[i + 1] + p01 * k0 + p02 * k1 + p03 * k2 +
-                p04 * k3 + p05 * k4) >> shift2;
-
-        CLAMP_STORE(dp[0],     pix0);
-        CLAMP_STORE(dp[chan1], pix1);
-
-        dp  += chan2;
-        sp4 += chan2;
-      }
-
-      p01 = p02; p02 = p03; p03 = p04; p04 = p05;
-
-      for (; i < wid - dx_r; i++) {
-        p00 = p01; p01 = p02; p02 = p03; p03 = p04;
-
-        p04 = sp4[0];
-
-        pix0 = (buffd[i    ] + p00 * k0 + p01 * k1 + p02 * k2 +
-                p03 * k3 + p04 * k4) >> shift2;
-        CLAMP_STORE(dp[0],     pix0);
-
-        dp  += chan1;
-        sp4 += chan1;
-      }
-
-      sp4 -= chan1;
-
-      for (; i < wid; i++) {
-        p00 = p01; p01 = p02; p02 = p03; p03 = p04;
-
-        p04 = sp4[0];
-
-        pix0 = (buffd[i    ] + p00 * k0 + p01 * k1 + p02 * k2 +
-                p03 * k3 + p04 * k4) >> shift2;
-        CLAMP_STORE(dp[0],     pix0);
-
-        dp  += chan1;
-      }
-
-      /* next line */
-
-      if (j < hgt - dy_b - 1) sl += sll;
-      dl += dll;
-    }
-  }
-
-  if (pbuff != buff) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-#endif /* __sparc ( for x86, using integer multiplies is faster ) */
-
-/***************************************************************/
-#if IMG_TYPE == 1
-
-#undef  KSIZE
-#define KSIZE 7
-
-mlib_status CONV_FUNC(7x7)
-{
-  FTYPE    buff[(KSIZE + 3)*BUFF_LINE], *buffs[2*(KSIZE + 1)], *buffd;
-  FTYPE    k[KSIZE*KSIZE];
-  mlib_s32 l, m, buff_ind;
-  mlib_s32 d0, d1;
-  FTYPE    k0, k1, k2, k3, k4, k5, k6;
-  FTYPE    p0, p1, p2, p3, p4, p5, p6, p7;
-  DTYPE *sl2, *sl3, *sl4, *sl5, *sl6;
-  DEF_VARS(DTYPE);
-  LOAD_KERNEL(KSIZE*KSIZE);
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  swid = wid + KSIZE1;
-
-  if (wid > BUFF_LINE) {
-    pbuff = mlib_malloc((KSIZE + 3)*sizeof(FTYPE   )*wid);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  for (l = 0; l < KSIZE + 1; l++) buffs[l] = pbuff + l*swid;
-  for (l = 0; l < KSIZE + 1; l++) buffs[l + (KSIZE + 1)] = buffs[l];
-  buffd = buffs[KSIZE] + swid;
-  buffo = (mlib_s32*)(buffd + swid);
-  buffi = buffo + (swid &~ 1);
-
-  swid -= (dx_l + dx_r);
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    if ((1 > dy_t) && (1 < hgt + KSIZE1 - dy_b)) sl1 = sl + sll;
-    else sl1 = sl;
-
-    if ((2 > dy_t) && (2 < hgt + KSIZE1 - dy_b)) sl2 = sl1 + sll;
-    else sl2 = sl1;
-
-    if ((3 > dy_t) && (3 < hgt + KSIZE1 - dy_b)) sl3 = sl2 + sll;
-    else sl3 = sl2;
-
-    if ((4 > dy_t) && (4 < hgt + KSIZE1 - dy_b)) sl4 = sl3 + sll;
-    else sl4 = sl3;
-
-    if ((5 > dy_t) && (5 < hgt + KSIZE1 - dy_b)) sl5 = sl4 + sll;
-    else sl5 = sl4;
-
-    if ((hgt - dy_b) > 0) sl6 = sl5 + sll;
-    else sl6 = sl5;
-
-    for (i = 0; i < dx_l; i++) {
-      buffs[0][i] = (FTYPE)sl[0];
-      buffs[1][i] = (FTYPE)sl1[0];
-      buffs[2][i] = (FTYPE)sl2[0];
-      buffs[3][i] = (FTYPE)sl3[0];
-      buffs[4][i] = (FTYPE)sl4[0];
-      buffs[5][i] = (FTYPE)sl5[0];
-      buffs[6][i] = (FTYPE)sl6[0];
-    }
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < swid; i++) {
-      buffs[0][i + dx_l] = (FTYPE)sl[i*chan1];
-      buffs[1][i + dx_l] = (FTYPE)sl1[i*chan1];
-      buffs[2][i + dx_l] = (FTYPE)sl2[i*chan1];
-      buffs[3][i + dx_l] = (FTYPE)sl3[i*chan1];
-      buffs[4][i + dx_l] = (FTYPE)sl4[i*chan1];
-      buffs[5][i + dx_l] = (FTYPE)sl5[i*chan1];
-      buffs[6][i + dx_l] = (FTYPE)sl6[i*chan1];
-    }
-
-    for (i = 0; i < dx_r; i++) {
-      buffs[0][swid + dx_l + i] = buffs[0][swid + dx_l - 1];
-      buffs[1][swid + dx_l + i] = buffs[1][swid + dx_l - 1];
-      buffs[2][swid + dx_l + i] = buffs[2][swid + dx_l - 1];
-      buffs[3][swid + dx_l + i] = buffs[3][swid + dx_l - 1];
-      buffs[4][swid + dx_l + i] = buffs[4][swid + dx_l - 1];
-      buffs[5][swid + dx_l + i] = buffs[5][swid + dx_l - 1];
-      buffs[6][swid + dx_l + i] = buffs[6][swid + dx_l - 1];
-    }
-
-    buff_ind = 0;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < wid; i++) buffd[i] = 0.0;
-
-    if ((hgt - dy_b) > 1) sl = sl6 + sll;
-    else sl = sl6;
-
-    for (j = 0; j < hgt; j++) {
-      FTYPE    **buffc = buffs + buff_ind;
-      FTYPE    *buffn = buffc[KSIZE];
-      FTYPE    *pk = k;
-
-      for (l = 0; l < KSIZE; l++) {
-        FTYPE    *buff = buffc[l];
-        d64_2x32 dd;
-
-        sp = sl;
-        dp = dl;
-
-        p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
-        p5 = buff[3]; p6 = buff[4]; p7 = buff[5];
-
-        k0 = *pk++; k1 = *pk++; k2 = *pk++; k3 = *pk++;
-        k4 = *pk++; k5 = *pk++; k6 = *pk++;
-
-        if (l < (KSIZE - 1)) {
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-          for (i = 0; i <= (wid - 2); i += 2) {
-            p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
-
-            p6 = buff[i + 6]; p7 = buff[i + 7];
-
-            buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
-            buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
-          }
-
-        } else {
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-          for (i = 0; i <= (wid - 2); i += 2) {
-            p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
-
-            p6 = buff[i + 6]; p7 = buff[i + 7];
-
-            LOAD_BUFF(buffi);
-
-            dd.d64 = *(FTYPE   *)(buffi + i);
-            buffn[i + dx_l    ] = (FTYPE)dd.i32s.i0;
-            buffn[i + dx_l + 1] = (FTYPE)dd.i32s.i1;
-
-            d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6 + buffd[i    ]);
-            d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6 + buffd[i + 1]);
-
-            dp[0    ] = FROM_S32(d0);
-            dp[chan1] = FROM_S32(d1);
-
-            buffd[i    ] = 0.0;
-            buffd[i + 1] = 0.0;
-
-            sp += chan2;
-            dp += chan2;
-          }
-        }
-      }
-
-      /* last pixels */
-      for (; i < wid; i++) {
-        FTYPE    *pk = k, s = 0;
-        mlib_s32 d0;
-
-        for (l = 0; l < KSIZE; l++) {
-          FTYPE    *buff = buffc[l] + i;
-
-          for (m = 0; m < KSIZE; m++) s += buff[m] * (*pk++);
-        }
-
-        d0 = D2I(s);
-        dp[0] = FROM_S32(d0);
-
-        buffn[i + dx_l] = (FTYPE)sp[0];
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      for (; i < swid; i++) {
-        buffn[i + dx_l] = (FTYPE)sp[0];
-        sp += chan1;
-      }
-
-      for (i = 0; i < dx_l; i++) buffn[i] = buffn[dx_l];
-      for (i = 0; i < dx_r; i++) buffn[swid + dx_l + i] = buffn[swid + dx_l - 1];
-
-      /* next line */
-
-      if (j < hgt - dy_b - 2) sl += sll;
-      dl += dll;
-
-      buff_ind++;
-
-      if (buff_ind >= KSIZE + 1) buff_ind = 0;
-    }
-  }
-
-  if (pbuff != buff) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-#endif /* IMG_TYPE == 1 */
-
-/***************************************************************/
 #define MAX_KER   7
 #define MAX_N    15
 #define BUFF_SIZE   1600
--- a/src/java.desktop/share/native/libmlib_image/mlib_ImageConv_16nw.c	Thu May 12 11:03:07 2016 -0700
+++ b/src/java.desktop/share/native/libmlib_image/mlib_ImageConv_16nw.c	Fri May 13 11:31:05 2016 +0300
@@ -144,9 +144,6 @@
 } d64_2x32;
 
 /***************************************************************/
-#define BUFF_LINE 256
-
-/***************************************************************/
 #define DEF_VARS(type)                                          \
   type     *adr_src, *sl, *sp = NULL;                           \
   type     *adr_dst, *dl, *dp = NULL;                           \
@@ -156,39 +153,6 @@
   mlib_s32 i, j, c
 
 /***************************************************************/
-#define LOAD_KERNEL3()                                                   \
-  FTYPE    scalef = DSCALE;                                              \
-  FTYPE    k0, k1, k2, k3, k4, k5, k6, k7, k8;                           \
-  FTYPE    p00, p01, p02, p03,                                           \
-           p10, p11, p12, p13,                                           \
-           p20, p21, p22, p23;                                           \
-                                                                         \
-  while (scalef_expon > 30) {                                            \
-    scalef /= (1 << 30);                                                 \
-    scalef_expon -= 30;                                                  \
-  }                                                                      \
-                                                                         \
-  scalef /= (1 << scalef_expon);                                         \
-                                                                         \
-  /* keep kernel in regs */                                              \
-  k0 = scalef * kern[0];  k1 = scalef * kern[1];  k2 = scalef * kern[2]; \
-  k3 = scalef * kern[3];  k4 = scalef * kern[4];  k5 = scalef * kern[5]; \
-  k6 = scalef * kern[6];  k7 = scalef * kern[7];  k8 = scalef * kern[8]
-
-/***************************************************************/
-#define LOAD_KERNEL(SIZE)                                       \
-  FTYPE    scalef = DSCALE;                                     \
-                                                                \
-  while (scalef_expon > 30) {                                   \
-    scalef /= (1 << 30);                                        \
-    scalef_expon -= 30;                                         \
-  }                                                             \
-                                                                \
-  scalef /= (1 << scalef_expon);                                \
-                                                                \
-  for (j = 0; j < SIZE; j++) k[j] = scalef * kern[j]
-
-/***************************************************************/
 #define GET_SRC_DST_PARAMETERS(type)                            \
   hgt = mlib_ImageGetHeight(src);                               \
   wid = mlib_ImageGetWidth(src);                                \
@@ -246,1162 +210,6 @@
 #endif /* __sparc */
 
 /***************************************************************/
-#define KSIZE  3
-
-mlib_status CONV_FUNC(3x3)(mlib_image       *dst,
-                           const mlib_image *src,
-                           const mlib_s32   *kern,
-                           mlib_s32         scalef_expon,
-                           mlib_s32         cmask)
-{
-  FTYPE    buff[(KSIZE + 2)*BUFF_LINE], *buff0, *buff1, *buff2, *buff3, *buffT;
-  DEF_VARS(DTYPE);
-  DTYPE *sl1;
-  mlib_s32 chan2;
-  mlib_s32 *buffo, *buffi;
-  DTYPE *sl2;
-#ifndef __sparc
-  mlib_s32 d0, d1;
-#endif /* __sparc */
-  LOAD_KERNEL3();
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  if (wid > BUFF_LINE) {
-    pbuff = mlib_malloc((KSIZE + 2)*sizeof(FTYPE)*wid);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buff0 = pbuff;
-  buff1 = buff0 + wid;
-  buff2 = buff1 + wid;
-  buff3 = buff2 + wid;
-  buffo = (mlib_s32*)(buff3 + wid);
-  buffi = buffo + (wid &~ 1);
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  wid -= (KSIZE - 1);
-  hgt -= (KSIZE - 1);
-
-  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    sl1 = sl  + sll;
-    sl2 = sl1 + sll;
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < wid + (KSIZE - 1); i++) {
-      buff0[i] = (FTYPE)sl[i*chan1];
-      buff1[i] = (FTYPE)sl1[i*chan1];
-      buff2[i] = (FTYPE)sl2[i*chan1];
-    }
-
-    sl += KSIZE*sll;
-
-    for (j = 0; j < hgt; j++) {
-      FTYPE    s0, s1;
-
-      p02 = buff0[0];
-      p12 = buff1[0];
-      p22 = buff2[0];
-
-      p03 = buff0[1];
-      p13 = buff1[1];
-      p23 = buff2[1];
-
-      s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-      s1 = p03 * k0 + p13 * k3 + p23 * k6;
-
-      sp = sl;
-      dp = dl;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-#ifdef __sparc
-#ifdef _NO_LONGLONG
-        mlib_s32 o64_1, o64_2;
-#else /* _NO_LONGLONG */
-        mlib_s64 o64;
-#endif /* _NO_LONGLONG */
-#endif /* __sparc */
-        d64_2x32 dd;
-
-        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2];
-        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3];
-
-        LOAD_BUFF(buffi);
-
-        dd.d64 = *(FTYPE   *)(buffi + i);
-        buff3[i    ] = (FTYPE)dd.i32s.i0;
-        buff3[i + 1] = (FTYPE)dd.i32s.i1;
-
-#ifndef __sparc
-        d0 = D2I(s0 + p02 * k2 + p12 * k5 + p22 * k8);
-        d1 = D2I(s1 + p02 * k1 + p03 * k2 + p12 * k4 + p13 * k5 + p22 * k7 + p23 * k8);
-
-        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-        s1 = p03 * k0 + p13 * k3 + p23 * k6;
-
-        dp[0    ] = FROM_S32(d0);
-        dp[chan1] = FROM_S32(d1);
-
-#else /* __sparc */
-
-        dd.i32s.i0 = D2I(s0 + p02 * k2 + p12 * k5 + p22 * k8);
-        dd.i32s.i1 = D2I(s1 + p02 * k1 + p03 * k2 + p12 * k4 + p13 * k5 + p22 * k7 + p23 * k8);
-        *(FTYPE   *)(buffo + i) = dd.d64;
-
-        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-        s1 = p03 * k0 + p13 * k3 + p23 * k6;
-
-#ifdef _NO_LONGLONG
-
-        o64_1 = buffo[i];
-        o64_2 = buffo[i+1];
-#if IMG_TYPE != 1
-        STORE2(FROM_S32(o64_1), FROM_S32(o64_2));
-#else
-        STORE2(o64_1 >> 24, o64_2 >> 24);
-#endif /* IMG_TYPE != 1 */
-
-#else /* _NO_LONGLONG */
-
-        o64 = *(mlib_s64*)(buffo + i);
-#if IMG_TYPE != 1
-        STORE2(FROM_S32(o64 >> 32), FROM_S32(o64));
-#else
-        STORE2(o64 >> 56, o64 >> 24);
-#endif /* IMG_TYPE != 1 */
-#endif /* _NO_LONGLONG */
-#endif /* __sparc */
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      for (; i < wid; i++) {
-        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];
-        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1];
-        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2];
-
-        buffi[i] = (mlib_s32)sp[0];
-        buff3[i] = (FTYPE)buffi[i];
-
-#ifndef __sparc
-
-        d0 = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p10 * k3 + p11 * k4 +
-                 p12 * k5 + p20 * k6 + p21 * k7 + p22 * k8);
-
-        dp[0] = FROM_S32(d0);
-
-#else  /* __sparc */
-
-        buffo[i] = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p10 * k3 + p11 * k4 +
-                       p12 * k5 + p20 * k6 + p21 * k7 + p22 * k8);
-#if IMG_TYPE != 1
-        dp[0] = FROM_S32(buffo[i]);
-#else
-        dp[0] = buffo[i] >> 24;
-#endif /* IMG_TYPE != 1 */
-#endif /* __sparc */
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      buffi[wid] = (mlib_s32)sp[0];
-      buff3[wid] = (FTYPE)buffi[wid];
-      buffi[wid + 1] = (mlib_s32)sp[chan1];
-      buff3[wid + 1] = (FTYPE)buffi[wid + 1];
-
-      sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buff3;
-      buff3 = buffT;
-    }
-  }
-
-#ifdef __sparc
-#if IMG_TYPE == 1
-  {
-    mlib_s32 amask = (1 << nchannel) - 1;
-
-    if ((cmask & amask) != amask) {
-      mlib_ImageXor80(adr_dst, wid, hgt, dll, nchannel, cmask);
-    } else {
-      mlib_ImageXor80_aa(adr_dst, wid*nchannel, hgt, dll);
-    }
-  }
-
-#endif /* IMG_TYPE == 1 */
-#endif /* __sparc */
-
-  if (pbuff != buff) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
-#ifndef __sparc /* for x86, using integer multiplies is faster */
-
-mlib_status CONV_FUNC_I(3x3)(mlib_image       *dst,
-                             const mlib_image *src,
-                             const mlib_s32   *kern,
-                             mlib_s32         scalef_expon,
-                             mlib_s32         cmask)
-{
-  DTYPE    *adr_src, *sl, *sp0, *sp1, *sp2;
-  DTYPE    *adr_dst, *dl, *dp;
-  mlib_s32 wid, hgt, sll, dll;
-  mlib_s32 nchannel, chan1, chan2;
-  mlib_s32 i, j, c;
-  mlib_s32 shift1, shift2;
-  mlib_s32 k0, k1, k2, k3, k4, k5, k6, k7, k8;
-  mlib_s32 p02, p03,
-           p12, p13,
-           p22, p23;
-
-#if IMG_TYPE != 1
-  shift1 = 16;
-#else
-  shift1 = 8;
-#endif /* IMG_TYPE != 1 */
-
-  shift2 = scalef_expon - shift1;
-
-  /* keep kernel in regs */
-  k0 = kern[0] >> shift1;  k1 = kern[1] >> shift1;  k2 = kern[2] >> shift1;
-  k3 = kern[3] >> shift1;  k4 = kern[4] >> shift1;  k5 = kern[5] >> shift1;
-  k6 = kern[6] >> shift1;  k7 = kern[7] >> shift1;  k8 = kern[8] >> shift1;
-
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  wid -= (KSIZE - 1);
-  hgt -= (KSIZE - 1);
-
-  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
-
-  for (c = 0; c < chan1; c++) {
-    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    for (j = 0; j < hgt; j++) {
-      mlib_s32 s0, s1;
-      mlib_s32 pix0, pix1;
-
-      dp  = dl;
-      sp0 = sl;
-      sp1 = sp0 + sll;
-      sp2 = sp1 + sll;
-
-      p02 = sp0[0];
-      p12 = sp1[0];
-      p22 = sp2[0];
-
-      p03 = sp0[chan1];
-      p13 = sp1[chan1];
-      p23 = sp2[chan1];
-
-      s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-      s1 = p03 * k0 + p13 * k3 + p23 * k6;
-
-      sp0 += chan2;
-      sp1 += chan2;
-      sp2 += chan2;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p02 = sp0[0];     p12 = sp1[0];     p22 = sp2[0];
-        p03 = sp0[chan1]; p13 = sp1[chan1]; p23 = sp2[chan1];
-
-        pix0 = (s0 + p02 * k2 + p12 * k5 + p22 * k8) >> shift2;
-        pix1 = (s1 + p02 * k1 + p03 * k2 + p12 * k4 +
-                p13 * k5 + p22 * k7 + p23 * k8) >> shift2;
-
-        CLAMP_STORE(dp[0],     pix0);
-        CLAMP_STORE(dp[chan1], pix1);
-
-        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
-        s1 = p03 * k0 + p13 * k3 + p23 * k6;
-
-        sp0 += chan2;
-        sp1 += chan2;
-        sp2 += chan2;
-        dp += chan2;
-      }
-
-      if (wid & 1) {
-        p02 = sp0[0]; p12 = sp1[0]; p22 = sp2[0];
-        pix0 = (s0 + p02 * k2 + p12 * k5 + p22 * k8) >> shift2;
-        CLAMP_STORE(dp[0], pix0);
-      }
-
-      sl += sll;
-      dl += dll;
-    }
-  }
-
-  return MLIB_SUCCESS;
-}
-
-#endif /* __sparc ( for x86, using integer multiplies is faster ) */
-
-/***************************************************************/
-#undef  KSIZE
-#define KSIZE 4
-
-mlib_status CONV_FUNC(4x4)(mlib_image       *dst,
-                           const mlib_image *src,
-                           const mlib_s32   *kern,
-                           mlib_s32         scalef_expon,
-                           mlib_s32         cmask)
-{
-  FTYPE    buff[(KSIZE + 3)*BUFF_LINE];
-  FTYPE    *buff0, *buff1, *buff2, *buff3, *buff4, *buffd, *buffT;
-  FTYPE    k[KSIZE*KSIZE];
-  mlib_s32 d0, d1;
-  FTYPE    k0, k1, k2, k3, k4, k5, k6, k7;
-  FTYPE    p00, p01, p02, p03, p04,
-           p10, p11, p12, p13, p14,
-           p20, p21, p22, p23,
-           p30, p31, p32, p33;
-  DEF_VARS(DTYPE);
-  DTYPE *sl1;
-  mlib_s32 chan2;
-  mlib_s32 *buffo, *buffi;
-  DTYPE *sl2, *sl3;
-  LOAD_KERNEL(KSIZE*KSIZE);
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  if (wid > BUFF_LINE) {
-    pbuff = mlib_malloc((KSIZE + 3)*sizeof(FTYPE)*wid);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buff0 = pbuff;
-  buff1 = buff0 + wid;
-  buff2 = buff1 + wid;
-  buff3 = buff2 + wid;
-  buff4 = buff3 + wid;
-  buffd = buff4 + wid;
-  buffo = (mlib_s32*)(buffd + wid);
-  buffi = buffo + (wid &~ 1);
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  wid -= (KSIZE - 1);
-  hgt -= (KSIZE - 1);
-
-  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    sl1 = sl  + sll;
-    sl2 = sl1 + sll;
-    sl3 = sl2 + sll;
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < wid + (KSIZE - 1); i++) {
-      buff0[i] = (FTYPE)sl[i*chan1];
-      buff1[i] = (FTYPE)sl1[i*chan1];
-      buff2[i] = (FTYPE)sl2[i*chan1];
-      buff3[i] = (FTYPE)sl3[i*chan1];
-    }
-
-    sl += KSIZE*sll;
-
-    for (j = 0; j < hgt; j++) {
-      d64_2x32 dd;
-
-      /*
-       *  First loop on two first lines of kernel
-       */
-      k0 = k[0]; k1 = k[1]; k2 = k[2]; k3 = k[3];
-      k4 = k[4]; k5 = k[5]; k6 = k[6]; k7 = k[7];
-
-      sp = sl;
-      dp = dl;
-
-      p02 = buff0[0];
-      p12 = buff1[0];
-      p03 = buff0[1];
-      p13 = buff1[1];
-      p04 = buff0[2];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = buff1[i + 2];
-        p03 = buff0[i + 3]; p13 = buff1[i + 3];
-        p04 = buff0[i + 4]; p14 = buff1[i + 4];
-
-        LOAD_BUFF(buffi);
-
-        dd.d64 = *(FTYPE   *)(buffi + i);
-        buff4[i    ] = (FTYPE)dd.i32s.i0;
-        buff4[i + 1] = (FTYPE)dd.i32s.i1;
-
-        buffd[i    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
-                        p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7);
-        buffd[i + 1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 +
-                        p11 * k4 + p12 * k5 + p13 * k6 + p14 * k7);
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      /*
-       *  Second loop on two last lines of kernel
-       */
-      k0 = k[ 8]; k1 = k[ 9]; k2 = k[10]; k3 = k[11];
-      k4 = k[12]; k5 = k[13]; k6 = k[14]; k7 = k[15];
-
-      sp = sl;
-      dp = dl;
-
-      p02 = buff2[0];
-      p12 = buff3[0];
-      p03 = buff2[1];
-      p13 = buff3[1];
-      p04 = buff2[2];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = buff3[i + 2];
-        p03 = buff2[i + 3]; p13 = buff3[i + 3];
-        p04 = buff2[i + 4]; p14 = buff3[i + 4];
-
-        d0 = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
-                 p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7 + buffd[i]);
-        d1 = D2I(p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 +
-                 p11 * k4 + p12 * k5 + p13 * k6 + p14 * k7 + buffd[i + 1]);
-
-        dp[0    ] = FROM_S32(d0);
-        dp[chan1] = FROM_S32(d1);
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      /* last pixels */
-      for (; i < wid; i++) {
-        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];     p30 = buff3[i];
-        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1]; p31 = buff3[i + 1];
-        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2]; p32 = buff3[i + 2];
-        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3]; p33 = buff3[i + 3];
-
-        buff4[i] = (FTYPE)sp[0];
-
-        buffo[i] = D2I(p00 * k[0] + p01 * k[1] + p02 * k[2] + p03 * k[3] +
-                       p10 * k[4] + p11 * k[5] + p12 * k[6] + p13 * k[7] +
-                       p20 * k[ 8] + p21 * k[ 9] + p22 * k[10] + p23 * k[11] +
-                       p30 * k[12] + p31 * k[13] + p32 * k[14] + p33 * k[15]);
-
-        dp[0] = FROM_S32(buffo[i]);
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      buff4[wid    ] = (FTYPE)sp[0];
-      buff4[wid + 1] = (FTYPE)sp[chan1];
-      buff4[wid + 2] = (FTYPE)sp[chan2];
-
-      /* next line */
-      sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buff3;
-      buff3 = buff4;
-      buff4 = buffT;
-    }
-  }
-
-  if (pbuff != buff) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
-#undef  KSIZE
-#define KSIZE 5
-
-mlib_status CONV_FUNC(5x5)(mlib_image       *dst,
-                           const mlib_image *src,
-                           const mlib_s32   *kern,
-                           mlib_s32         scalef_expon,
-                           mlib_s32         cmask)
-{
-  FTYPE    buff[(KSIZE + 3)*BUFF_LINE];
-  FTYPE    *buff0, *buff1, *buff2, *buff3, *buff4, *buff5, *buffd, *buffT;
-  FTYPE    k[KSIZE*KSIZE];
-  mlib_s32 d0, d1;
-  FTYPE    k0, k1, k2, k3, k4, k5, k6, k7, k8, k9;
-  FTYPE    p00, p01, p02, p03, p04, p05,
-           p10, p11, p12, p13, p14, p15,
-           p20, p21, p22, p23, p24,
-           p30, p31, p32, p33, p34,
-           p40, p41, p42, p43, p44;
-  DEF_VARS(DTYPE);
-  DTYPE *sl1;
-  mlib_s32 chan2;
-  mlib_s32 *buffo, *buffi;
-  DTYPE *sl2, *sl3, *sl4;
-  LOAD_KERNEL(KSIZE*KSIZE);
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  if (wid > BUFF_LINE) {
-    pbuff = mlib_malloc((KSIZE + 3)*sizeof(FTYPE)*wid);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buff0 = pbuff;
-  buff1 = buff0 + wid;
-  buff2 = buff1 + wid;
-  buff3 = buff2 + wid;
-  buff4 = buff3 + wid;
-  buff5 = buff4 + wid;
-  buffd = buff5 + wid;
-  buffo = (mlib_s32*)(buffd + wid);
-  buffi = buffo + (wid &~ 1);
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  wid -= (KSIZE - 1);
-  hgt -= (KSIZE - 1);
-
-  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    sl1 = sl  + sll;
-    sl2 = sl1 + sll;
-    sl3 = sl2 + sll;
-    sl4 = sl3 + sll;
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < wid + (KSIZE - 1); i++) {
-      buff0[i] = (FTYPE)sl[i*chan1];
-      buff1[i] = (FTYPE)sl1[i*chan1];
-      buff2[i] = (FTYPE)sl2[i*chan1];
-      buff3[i] = (FTYPE)sl3[i*chan1];
-      buff4[i] = (FTYPE)sl4[i*chan1];
-    }
-
-    sl += KSIZE*sll;
-
-    for (j = 0; j < hgt; j++) {
-      d64_2x32 dd;
-
-      /*
-       *  First loop
-       */
-      k0 = k[0]; k1 = k[1]; k2 = k[2]; k3 = k[3]; k4 = k[4];
-      k5 = k[5]; k6 = k[6]; k7 = k[7]; k8 = k[8]; k9 = k[9];
-
-      sp = sl;
-      dp = dl;
-
-      p02 = buff0[0];
-      p12 = buff1[0];
-      p03 = buff0[1];
-      p13 = buff1[1];
-      p04 = buff0[2];
-      p14 = buff1[2];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = p14;
-
-        LOAD_BUFF(buffi);
-
-        p03 = buff0[i + 3]; p13 = buff1[i + 3];
-        p04 = buff0[i + 4]; p14 = buff1[i + 4];
-        p05 = buff0[i + 5]; p15 = buff1[i + 5];
-
-        buffd[i    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                        p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-        buffd[i + 1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
-                        p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      /*
-       *  Second loop
-       */
-      k0 = k[10]; k1 = k[11]; k2 = k[12]; k3 = k[13]; k4 = k[14];
-      k5 = k[15]; k6 = k[16]; k7 = k[17]; k8 = k[18]; k9 = k[19];
-
-      sp = sl;
-      dp = dl;
-
-      p02 = buff2[0];
-      p12 = buff3[0];
-      p03 = buff2[1];
-      p13 = buff3[1];
-      p04 = buff2[2];
-      p14 = buff3[2];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-
-        p02 = buff2[i + 2]; p12 = buff3[i + 2];
-        p03 = buff2[i + 3]; p13 = buff3[i + 3];
-        p04 = buff2[i + 4]; p14 = buff3[i + 4];
-        p05 = buff2[i + 5]; p15 = buff3[i + 5];
-
-        dd.d64 = *(FTYPE   *)(buffi + i);
-        buff5[i    ] = (FTYPE)dd.i32s.i0;
-        buff5[i + 1] = (FTYPE)dd.i32s.i1;
-
-        buffd[i    ] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                         p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-        buffd[i + 1] += (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
-                         p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      /*
-       *  3 loop
-       */
-      k0 = k[20]; k1 = k[21]; k2 = k[22]; k3 = k[23]; k4 = k[24];
-
-      sp = sl;
-      dp = dl;
-
-      p02 = buff4[0];
-      p03 = buff4[1];
-      p04 = buff4[2];
-      p05 = buff4[3];
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p01 = p03; p02 = p04; p03 = p05;
-
-        p04 = buff4[i + 4]; p05 = buff4[i + 5];
-
-        d0 = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 + buffd[i]);
-        d1 = D2I(p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 + buffd[i + 1]);
-
-        dp[0    ] = FROM_S32(d0);
-        dp[chan1] = FROM_S32(d1);
-
-        sp += chan2;
-        dp += chan2;
-      }
-
-      /* last pixels */
-      for (; i < wid; i++) {
-        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];     p30 = buff3[i];
-        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1]; p31 = buff3[i + 1];
-        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2]; p32 = buff3[i + 2];
-        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3]; p33 = buff3[i + 3];
-        p04 = buff0[i + 4]; p14 = buff1[i + 4]; p24 = buff2[i + 4]; p34 = buff3[i + 4];
-
-        p40 = buff4[i];     p41 = buff4[i + 1]; p42 = buff4[i + 2];
-        p43 = buff4[i + 3]; p44 = buff4[i + 4];
-
-        buff5[i] = (FTYPE)sp[0];
-
-        buffo[i] = D2I(p00 * k[0] + p01 * k[1] + p02 * k[2] + p03 * k[3] + p04 * k[4] +
-                       p10 * k[5] + p11 * k[6] + p12 * k[7] + p13 * k[8] + p14 * k[9] +
-                       p20 * k[10] + p21 * k[11] + p22 * k[12] + p23 * k[13] + p24 * k[14] +
-                       p30 * k[15] + p31 * k[16] + p32 * k[17] + p33 * k[18] + p34 * k[19] +
-                       p40 * k[20] + p41 * k[21] + p42 * k[22] + p43 * k[23] + p44 * k[24]);
-
-        dp[0] = FROM_S32(buffo[i]);
-
-        sp += chan1;
-        dp += chan1;
-      }
-
-      buff5[wid    ] = (FTYPE)sp[0];
-      buff5[wid + 1] = (FTYPE)sp[chan1];
-      buff5[wid + 2] = (FTYPE)sp[chan2];
-      buff5[wid + 3] = (FTYPE)sp[chan2 + chan1];
-
-      /* next line */
-      sl += sll;
-      dl += dll;
-
-      buffT = buff0;
-      buff0 = buff1;
-      buff1 = buff2;
-      buff2 = buff3;
-      buff3 = buff4;
-      buff4 = buff5;
-      buff5 = buffT;
-    }
-  }
-
-  if (pbuff != buff) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-/***************************************************************/
-#ifndef __sparc /* for x86, using integer multiplies is faster */
-
-mlib_status CONV_FUNC_I(5x5)(mlib_image       *dst,
-                             const mlib_image *src,
-                             const mlib_s32   *kern,
-                             mlib_s32         scalef_expon,
-                             mlib_s32         cmask)
-{
-  mlib_s32 buff[BUFF_LINE];
-  mlib_s32 *buffd;
-  mlib_s32 k[KSIZE*KSIZE];
-  mlib_s32 shift1, shift2;
-  mlib_s32 k0, k1, k2, k3, k4, k5, k6, k7, k8, k9;
-  mlib_s32 p00, p01, p02, p03, p04, p05,
-           p10, p11, p12, p13, p14, p15;
-  DTYPE    *adr_src, *sl, *sp0, *sp1;
-  DTYPE    *adr_dst, *dl, *dp;
-  mlib_s32 *pbuff = buff;
-  mlib_s32 wid, hgt, sll, dll;
-  mlib_s32 nchannel, chan1, chan2, chan3, chan4;
-  mlib_s32 i, j, c;
-
-#if IMG_TYPE != 1
-  shift1 = 16;
-#else
-  shift1 = 8;
-#endif /* IMG_TYPE != 1 */
-
-  shift2 = scalef_expon - shift1;
-
-  for (j = 0; j < KSIZE*KSIZE; j++) k[j] = kern[j] >> shift1;
-
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  if (wid > BUFF_LINE) {
-    pbuff = mlib_malloc(sizeof(mlib_s32)*wid);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  buffd = pbuff;
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-  chan3 = chan2 + chan1;
-  chan4 = chan3 + chan1;
-
-  wid -= (KSIZE - 1);
-  hgt -= (KSIZE - 1);
-
-  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
-
-  for (c = 0; c < chan1; c++) {
-    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    for (j = 0; j < hgt; j++) {
-      mlib_s32 pix0, pix1;
-      /*
-       *  First loop
-       */
-      sp0 = sl;
-      sp1 = sp0 + sll;
-      dp = dl;
-
-      k0 = k[0]; k1 = k[1]; k2 = k[2]; k3 = k[3]; k4 = k[4];
-      k5 = k[5]; k6 = k[6]; k7 = k[7]; k8 = k[8]; k9 = k[9];
-
-      p02 = sp0[0];     p12 = sp1[0];
-      p03 = sp0[chan1]; p13 = sp1[chan1];
-      p04 = sp0[chan2]; p14 = sp1[chan2];
-      p05 = sp0[chan3]; p15 = sp1[chan3];
-
-      sp0 += chan4;
-      sp1 += chan4;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = p14;
-        p03 = p05; p13 = p15;
-
-        p04 = sp0[0];     p14 = sp1[0];
-        p05 = sp0[chan1]; p15 = sp1[chan1];
-
-        buffd[i    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                        p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-        buffd[i + 1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
-                        p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
-
-        sp0 += chan2;
-        sp1 += chan2;
-        dp += chan2;
-      }
-
-      if (wid & 1) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = p14;
-        p03 = p05; p13 = p15;
-
-        p04 = sp0[0];     p14 = sp1[0];
-
-        buffd[i] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                    p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-      }
-
-      /*
-       *  Second loop
-       */
-      sp0 = sl + 2*sll;
-      sp1 = sp0 + sll;
-      dp = dl;
-
-      k0 = k[10]; k1 = k[11]; k2 = k[12]; k3 = k[13]; k4 = k[14];
-      k5 = k[15]; k6 = k[16]; k7 = k[17]; k8 = k[18]; k9 = k[19];
-
-      p02 = sp0[0];     p12 = sp1[0];
-      p03 = sp0[chan1]; p13 = sp1[chan1];
-      p04 = sp0[chan2]; p14 = sp1[chan2];
-      p05 = sp0[chan3]; p15 = sp1[chan3];
-
-      sp0 += chan4;
-      sp1 += chan4;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = p14;
-        p03 = p05; p13 = p15;
-
-        p04 = sp0[0];     p14 = sp1[0];
-        p05 = sp0[chan1]; p15 = sp1[chan1];
-
-        buffd[i    ] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                         p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-        buffd[i + 1] += (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
-                         p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
-
-        sp0 += chan2;
-        sp1 += chan2;
-        dp += chan2;
-      }
-
-      if (wid & 1) {
-        p00 = p02; p10 = p12;
-        p01 = p03; p11 = p13;
-        p02 = p04; p12 = p14;
-        p03 = p05; p13 = p15;
-
-        p04 = sp0[0];     p14 = sp1[0];
-
-        buffd[i] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
-                     p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
-      }
-
-      /*
-       *  3 loop
-       */
-      dp = dl;
-      sp0 = sl + 4*sll;
-
-      k0 = k[20]; k1 = k[21]; k2 = k[22]; k3 = k[23]; k4 = k[24];
-
-      p02 = sp0[0];
-      p03 = sp0[chan1];
-      p04 = sp0[chan2];
-      p05 = sp0[chan3];
-
-      sp0 += chan2 + chan2;
-
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-      for (i = 0; i <= (wid - 2); i += 2) {
-        p00 = p02; p01 = p03; p02 = p04; p03 = p05;
-
-        p04 = sp0[0]; p05 = sp0[chan1];
-
-        pix0 = (buffd[i    ] + p00 * k0 + p01 * k1 + p02 * k2 +
-                p03 * k3 + p04 * k4) >> shift2;
-        pix1 = (buffd[i + 1] + p01 * k0 + p02 * k1 + p03 * k2 +
-                p04 * k3 + p05 * k4) >> shift2;
-
-        CLAMP_STORE(dp[0],     pix0);
-        CLAMP_STORE(dp[chan1], pix1);
-
-        dp  += chan2;
-        sp0 += chan2;
-      }
-
-      if (wid & 1) {
-        p00 = p02; p01 = p03; p02 = p04; p03 = p05;
-
-        p04 = sp0[0];
-
-        pix0 = (buffd[i    ] + p00 * k0 + p01 * k1 + p02 * k2 +
-                p03 * k3 + p04 * k4) >> shift2;
-        CLAMP_STORE(dp[0],     pix0);
-      }
-
-      /* next line */
-      sl += sll;
-      dl += dll;
-    }
-  }
-
-  if (pbuff != buff) mlib_free(pbuff);
-
-  return MLIB_SUCCESS;
-}
-
-#endif /* __sparc ( for x86, using integer multiplies is faster ) */
-
-/***************************************************************/
-#if IMG_TYPE == 1
-
-#undef  KSIZE
-#define KSIZE 7
-
-mlib_status CONV_FUNC(7x7)(mlib_image       *dst,
-                           const mlib_image *src,
-                           const mlib_s32   *kern,
-                           mlib_s32         scalef_expon,
-                           mlib_s32         cmask)
-{
-  FTYPE    buff[(KSIZE + 3)*BUFF_LINE], *buffs[2*(KSIZE + 1)], *buffd;
-  FTYPE    k[KSIZE*KSIZE];
-  mlib_s32 l, m, buff_ind;
-  mlib_s32 d0, d1;
-  FTYPE    k0, k1, k2, k3, k4, k5, k6;
-  FTYPE    p0, p1, p2, p3, p4, p5, p6, p7;
-  DTYPE *sl2, *sl3, *sl4, *sl5, *sl6;
-  DEF_VARS(DTYPE);
-  DTYPE *sl1;
-  mlib_s32 chan2;
-  mlib_s32 *buffo, *buffi;
-  LOAD_KERNEL(KSIZE*KSIZE);
-  GET_SRC_DST_PARAMETERS(DTYPE);
-
-  if (wid > BUFF_LINE) {
-    pbuff = mlib_malloc((KSIZE + 3)*sizeof(FTYPE)*wid);
-
-    if (pbuff == NULL) return MLIB_FAILURE;
-  }
-
-  for (l = 0; l < KSIZE + 1; l++) buffs[l] = pbuff + l*wid;
-  for (l = 0; l < KSIZE + 1; l++) buffs[l + (KSIZE + 1)] = buffs[l];
-  buffd = buffs[KSIZE] + wid;
-  buffo = (mlib_s32*)(buffd + wid);
-  buffi = buffo + (wid &~ 1);
-
-  chan1 = nchannel;
-  chan2 = chan1 + chan1;
-
-  wid -= (KSIZE - 1);
-  hgt -= (KSIZE - 1);
-
-  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
-
-  for (c = 0; c < nchannel; c++) {
-    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
-
-    sl = adr_src + c;
-    dl = adr_dst + c;
-
-    sl1 = sl  + sll;
-    sl2 = sl1 + sll;
-    sl3 = sl2 + sll;
-    sl4 = sl3 + sll;
-    sl5 = sl4 + sll;
-    sl6 = sl5 + sll;
-#ifdef __SUNPRO_C
-#pragma pipeloop(0)
-#endif /* __SUNPRO_C */
-    for (i = 0; i < wid + (KSIZE - 1); i++) {
-      buffs[0][i] = (FTYPE)sl[i*chan1];
-      buffs[1][i] = (FTYPE)sl1[i*chan1];
-      buffs[2][i] = (FTYPE)sl2[i*chan1];
-      buffs[3][i] = (FTYPE)sl3[i*chan1];
-      buffs[4][i] = (FTYPE)sl4[i*chan1];
-      buffs[5][i] = (FTYPE)sl5[i*chan1];
-      buffs[6][i] = (FTYPE)sl6[i*chan1];
-    }
-
-    buff_ind = 0;
-