main(int argc, char **argv) { char *file1, *file2, *fileout; l_int32 d; l_float32 fract; PIX *pixs1, *pixs2, *pixt1, *pixt2, *pixt3, *pixt4, *pixd; static char mainName[] = "blendtest1"; if (argc != 5) exit(ERROR_INT(" Syntax: blendtest1 file1 file2 fract fileout", mainName, 1)); file1 = argv[1]; file2 = argv[2]; fract = atof(argv[3]); fileout = argv[4]; if ((pixs1 = pixRead(file1)) == NULL) exit(ERROR_INT("pixs1 not made", mainName, 1)); if ((pixs2 = pixRead(file2)) == NULL) exit(ERROR_INT("pixs2 not made", mainName, 1)); #if 0 d = pixGetDepth(pixs2); if (d == 1) { pixt1 = pixBlend(pixs1, pixs2, X, Y, fract); pixt2 = pixBlend(pixt1, pixs2, X, Y + 60, fract); pixt3 = pixBlend(pixt2, pixs2, X, Y + 120, fract); pixt4 = pixBlend(pixt3, pixs2, X, Y + 180, fract); pixt5 = pixBlend(pixt4, pixs2, X, Y + 240, fract); pixd = pixBlend(pixt5, pixs2, X, Y + 300, fract); pixWrite(fileout, pixd, IFF_DEFAULT); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); pixDestroy(&pixt5); } else { pixt1 = pixBlend(pixs1, pixs2, X, Y, fract); pixt2 = pixBlend(pixt1, pixs2, X + 80, Y + 80, fract); pixt3 = pixBlend(pixt2, pixs2, X + 160, Y + 160, fract); pixt4 = pixBlend(pixt3, pixs2, X + 240, Y + 240, fract); pixt5 = pixBlend(pixt4, pixs2, X + 320, Y + 320, fract); pixd = pixBlend(pixt5, pixs2, X + 360, Y + 360, fract); pixWrite(fileout, pixd, IFF_DEFAULT); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); pixDestroy(&pixt5); } pixDestroy(&pixd); #endif #if 1 /* e.g., weasel8.png with fract = 0.3 */ pixSnapColor(pixs2, pixs2, 0xff, 0xff, 50); pixBlendGray(pixs1, pixs1, pixs2, 200, 100, fract, L_BLEND_GRAY, 1, 0xff); pixBlendGray(pixs1, pixs1, pixs2, 200, 200, fract, L_BLEND_GRAY, 1, 0xff); pixBlendGray(pixs1, pixs1, pixs2, 200, 260, fract, L_BLEND_GRAY, 1, 0xff); pixBlendGray(pixs1, pixs1, pixs2, 200, 340, fract, L_BLEND_GRAY, 1, 0xff); pixWrite(fileout, pixs1, IFF_JFIF_JPEG); pixDisplay(pixs1, 200, 200); #endif #if 0 /* e.g., weasel8.png with fract = 0.5 */ pixSnapColor(pixs2, pixs2, 0xff, 0xff, 50); pixBlendGray(pixs1, pixs1, pixs2, 200, 100, fract, L_BLEND_GRAY_WITH_INVERSE, 1, 0xff); pixBlendGray(pixs1, pixs1, pixs2, 200, 200, fract, L_BLEND_GRAY_WITH_INVERSE, 1, 0xff); pixBlendGray(pixs1, pixs1, pixs2, 200, 260, fract, L_BLEND_GRAY_WITH_INVERSE, 1, 0xff); pixBlendGray(pixs1, pixs1, pixs2, 200, 340, fract, L_BLEND_GRAY_WITH_INVERSE, 1, 0xff); pixWrite(fileout, pixs1, IFF_JFIF_JPEG); pixDisplay(pixs1, 200, 200); #endif #if 0 /* e.g., weasel32.png with fract = 0.2 */ pixSnapColor(pixs2, pixs2, 0xffffff00, 0xffffff00, 50); pixBlendColor(pixs1, pixs1, pixs2, 200, 100, fract, 1, 0xffffff00); pixBlendColor(pixs1, pixs1, pixs2, 200, 200, fract, 1, 0xffffff00); pixBlendColor(pixs1, pixs1, pixs2, 200, 260, fract, 1, 0xffffff00); pixBlendColor(pixs1, pixs1, pixs2, 200, 340, fract, 1, 0xffffff00); pixWrite(fileout, pixs1, IFF_JFIF_JPEG); pixDisplay(pixs1, 200, 200); #endif pixDestroy(&pixs1); pixDestroy(&pixs2); exit(0); }
int main(int argc, char **argv) { PIX *pixs, *pixc, *pixd; PIXA *pixa; static char mainName[] = "snapcolortest"; if (argc != 1) return ERROR_INT(" Syntax: snapcolortest", mainName, 1); if ((pixs = pixRead("Leptonica.jpg")) == NULL) return ERROR_INT("pixs not made", mainName, 1); pixa = pixaCreate(0); /* First, snap the color directly on the input rgb image. */ pixSaveTiledOutline(pixs, pixa, 1.0, 1, 25, 2, 32); pixd = pixSnapColor(NULL, pixs, 0xffffff00, LEPTONICA_YELLOW, 30); pixSaveTiledOutline(pixd, pixa, 1.0, 0, 25, 2, 32); pixWrite("/tmp/logo1.jpg", pixd, IFF_JFIF_JPEG); pixDestroy(&pixd); /* Then make a colormapped version and snap the color */ pixd = pixOctreeQuantNumColors(pixs, 250, 0); pixSaveTiledOutline(pixd, pixa, 1.0, 1, 25, 2, 32); pixSnapColor(pixd, pixd, 0xffffff00, LEPTONICA_YELLOW, 30); pixSaveTiledOutline(pixd, pixa, 1.0, 0, 25, 2, 32); pixWrite("/tmp/logo2.png", pixd, IFF_PNG); pixDestroy(&pixd); pixDestroy(&pixs); /* Set the background of the google searchbox to yellow. * The input image is colormapped with all 256 colors used. */ if ((pixs = pixRead("google-searchbox.png")) == NULL) return ERROR_INT("pixs not made", mainName, 1); pixSaveTiledOutline(pixs, pixa, 1.0, 1, 25, 2, 32); pixd = pixSnapColor(NULL, pixs, 0xffffff00, LEPTONICA_YELLOW, 30); pixSaveTiledOutline(pixd, pixa, 1.0, 0, 25, 2, 32); pixWrite("/tmp/logo3.png", pixd, IFF_PNG); pixDestroy(&pixd); pixDestroy(&pixs); /* A couple of more, setting pixels near white to strange colors */ pixs = pixRead("weasel4.11c.png"); pixSaveTiledOutline(pixs, pixa, 1.0, 1, 25, 2, 32); pixd = pixSnapColor(NULL, pixs, 0xfefefe00, 0x80800000, 50); pixSaveTiledOutline(pixd, pixa, 1.0, 0, 25, 2, 32); pixDestroy(&pixs); pixDestroy(&pixd); pixs = pixRead("wyom.jpg"); pixc = pixFixedOctcubeQuant256(pixs, 0); pixSaveTiledOutline(pixc, pixa, 1.0, 1, 25, 2, 32); pixd = pixSnapColor(NULL, pixc, 0xf0f0f000, 0x80008000, 100); pixSaveTiledOutline(pixd, pixa, 1.0, 0, 25, 2, 32); pixDestroy(&pixs); pixDestroy(&pixc); pixDestroy(&pixd); /* --- Display results --- */ pixd = pixaDisplay(pixa, 0, 0); pixDisplay(pixd, 100, 100); pixWrite("/tmp/snap.jpg", pixd, IFF_PNG); pixDestroy(&pixd); pixaDestroy(&pixa); return 0; }