Leptonica 1.68
C Image Processing Library

snapcolortest.c

Go to the documentation of this file.
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  * snapcolortest.c
00018  *
00019  *    This tests the color snapping in blend.c.
00020  *    It is used here to color the background on images in index.html.
00021  */
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include "allheaders.h"
00026 
00027 static const l_uint32   LEPTONICA_YELLOW = 0xffffe400;
00028 
00029 main(int    argc,
00030      char **argv)
00031 {
00032 PIX         *pixs, *pixc, *pixd;
00033 PIXA        *pixa;
00034 static char  mainName[] = "snapcolortest";
00035 
00036     if (argc != 1)
00037         exit(ERROR_INT(" Syntax:  snapcolortest", mainName, 1));
00038 
00039     if ((pixs = pixRead("Leptonica.jpg")) == NULL)
00040         exit(ERROR_INT("pixs not made", mainName, 1));
00041 
00042     pixa = pixaCreate(0);
00043 
00044         /* First, snap the color directly on the input rgb image. */
00045     pixSaveTiledOutline(pixs, pixa, 1, 1, 25, 2, 32);
00046     pixd = pixSnapColor(NULL, pixs, 0xffffff00, LEPTONICA_YELLOW, 30);
00047     pixSaveTiledOutline(pixd, pixa, 1, 0, 25, 2, 32);
00048     pixWrite("/tmp/junklogo1.jpg", pixd, IFF_JFIF_JPEG);
00049     pixDestroy(&pixd);
00050 
00051         /* Then make a colormapped version and snap the color */
00052     pixd = pixOctreeQuantNumColors(pixs, 250, 0);
00053     pixSaveTiledOutline(pixd, pixa, 1, 1, 25, 2, 32);
00054     pixSnapColor(pixd, pixd, 0xffffff00, LEPTONICA_YELLOW, 30);
00055     pixSaveTiledOutline(pixd, pixa, 1, 0, 25, 2, 32);
00056     pixWrite("/tmp/junklogo2.png", pixd, IFF_PNG);
00057     pixDestroy(&pixd);
00058     pixDestroy(&pixs);
00059 
00060 
00061         /* Set the background of the google searchbox to yellow.
00062          * The input image is colormapped with all 256 colors used. */
00063     if ((pixs = pixRead("google-searchbox.png")) == NULL)
00064         exit(ERROR_INT("pixs not made", mainName, 1));
00065     pixSaveTiledOutline(pixs, pixa, 1, 1, 25, 2, 32);
00066     pixd = pixSnapColor(NULL, pixs, 0xffffff00, LEPTONICA_YELLOW, 30);
00067     pixSaveTiledOutline(pixd, pixa, 1, 0, 25, 2, 32);
00068     pixWrite("/tmp/junklogo3.png", pixd, IFF_PNG);
00069     pixDestroy(&pixd);
00070     pixDestroy(&pixs);
00071 
00072         /* A couple of more, setting pixels near white to strange colors */
00073     pixs = pixRead("weasel4.11c.png");
00074     pixSaveTiledOutline(pixs, pixa, 1, 1, 25, 2, 32);
00075     pixd = pixSnapColor(NULL, pixs, 0xfefefe00, 0x80800000, 50);
00076     pixSaveTiledOutline(pixd, pixa, 1, 0, 25, 2, 32);
00077     pixDestroy(&pixs);
00078     pixDestroy(&pixd);
00079 
00080     pixs = pixRead("wyom.jpg");
00081     pixc = pixFixedOctcubeQuant256(pixs, 0);
00082     pixSaveTiledOutline(pixc, pixa, 1, 1, 25, 2, 32);
00083     pixd = pixSnapColor(NULL, pixc, 0xf0f0f000, 0x80008000, 100);
00084     pixSaveTiledOutline(pixd, pixa, 1, 0, 25, 2, 32);
00085     pixDestroy(&pixs);
00086     pixDestroy(&pixc);
00087     pixDestroy(&pixd);
00088 
00089         /* --- Display results --- */
00090     pixd = pixaDisplay(pixa, 0, 0);
00091     pixDisplay(pixd, 100, 100);
00092     pixWrite("/tmp/junksnap.jpg", pixd, IFF_PNG);
00093     pixDestroy(&pixd);
00094     pixaDestroy(&pixa);
00095 
00096     return 0;
00097 }
00098 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines