Leptonica 1.68
C Image Processing Library
|
00001 /*====================================================================* 00002 - Copyright (C) 2001 Leptonica. All rights reserved. 00003 - This software is distributed in the hope that it will be 00004 - useful, but with NO WARRANTY OF ANY KIND. 00005 - No author or distributor accepts responsibility to anyone for the 00006 - consequences of using this software, or for whether it serves any 00007 - particular purpose or works at all, unless he or she says so in 00008 - writing. Everyone is granted permission to copy, modify and 00009 - redistribute this source code, for commercial or non-commercial 00010 - purposes, with the following restrictions: (1) the origin of this 00011 - source code must not be misrepresented; (2) modified versions must 00012 - be plainly marked as such; and (3) this notice may not be removed 00013 - or altered from any source or modified source distribution. 00014 *====================================================================*/ 00015 00016 /* 00017 * blendcmaptest.c 00018 * 00019 */ 00020 00021 #include <stdio.h> 00022 #include <stdlib.h> 00023 #include "allheaders.h" 00024 00025 #define NX 4 00026 #define NY 5 00027 00028 #define FADE_FRACTION 0.75 00029 00030 main(int argc, 00031 char **argv) 00032 { 00033 l_int32 i, j, sindex, wb, hb, ws, hs, delx, dely, x, y, y0; 00034 PIX *pixs, *pixb, *pixt0, *pixt1; 00035 PIXCMAP *cmap; 00036 static char mainName[] = "blendcmaptest"; 00037 00038 pixs = pixRead("rabi.png"); 00039 pixb = pixRead("weasel4.11c.png"); 00040 pixDisplayWrite(NULL, -1); 00041 00042 /* Fade the blender */ 00043 pixcmapShiftIntensity(pixGetColormap(pixb), FADE_FRACTION); 00044 00045 /* Downscale the input */ 00046 wb = pixGetWidth(pixb); 00047 hb = pixGetHeight(pixb); 00048 pixt0 = pixScaleToGray4(pixs); 00049 00050 /* Threshold to 5 levels, 4 bpp */ 00051 ws = pixGetWidth(pixt0); 00052 hs = pixGetHeight(pixt0); 00053 pixt1 = pixThresholdTo4bpp(pixt0, 5, 1); 00054 pixDisplayWriteFormat(pixt1, 1, IFF_PNG); 00055 pixDisplayWrite(pixb, 1); 00056 cmap = pixGetColormap(pixt1); 00057 pixcmapWriteStream(stderr, cmap); 00058 00059 /* Overwrite the white pixels (at sindex in pixt1) */ 00060 pixcmapGetIndex(cmap, 255, 255, 255, &sindex); 00061 delx = ws / NX; 00062 dely = hs / NY; 00063 for (i = 0; i < NY; i++) { 00064 y = 20 + i * dely; 00065 if (y >= hs + hb) 00066 continue; 00067 for (j = 0; j < NX; j++) { 00068 x = 30 + j * delx; 00069 y0 = y; 00070 if (j & 1) { 00071 y0 = y + dely / 2; 00072 if (y0 >= hs + hb) 00073 continue; 00074 } 00075 if (x >= ws + wb) 00076 continue; 00077 pixBlendCmap(pixt1, pixb, x, y0, sindex); 00078 } 00079 } 00080 pixDisplayWriteFormat(pixt1, 1, IFF_PNG); 00081 cmap = pixGetColormap(pixt1); 00082 pixcmapWriteStream(stderr, cmap); 00083 00084 pixDisplayMultiple("/tmp/junk_write_display*"); 00085 00086 pixDestroy(&pixs); 00087 pixDestroy(&pixb); 00088 pixDestroy(&pixt0); 00089 pixDestroy(&pixt1); 00090 return 0; 00091 } 00092