Leptonica 1.68
C Image Processing Library

paint_reg.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  * paint_reg.c
00018  *
00019  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include "allheaders.h"
00024 
00025 
00026 main(int    argc,
00027      char **argv)
00028 {
00029 l_int32      index;
00030 l_uint32     val32;
00031 BOX         *box, *box1, *box2, *box3, *box4, *box5;
00032 PIX         *pixs, *pixg, *pixb, *pixt, *pixt1, *pixt2, *pixt3;
00033 PIXCMAP     *cmap;
00034 static char  mainName[] = "paint_reg";
00035 
00036     if (argc != 1)
00037         exit(ERROR_INT(" Syntax: paint_reg", mainName, 1));
00038 
00039     if ((pixs = pixRead("lucasta-frag.jpg")) == NULL)
00040         exit(ERROR_INT("pixs not made", mainName, 1));
00041     pixDisplayWrite(NULL, -1);
00042     pixDisplayWrite(pixs, 1);
00043 
00044         /* Color non-white pixels on RGB */
00045     pixt = pixConvert8To32(pixs);
00046     box = boxCreate(120, 30, 200, 200);
00047     pixColorGray(pixt, box, L_PAINT_DARK, 220, 0, 0, 255);
00048     pixDisplayWrite(pixt, 1);
00049     pixColorGray(pixt, NULL, L_PAINT_DARK, 220, 255, 100, 100);
00050     pixDisplayWrite(pixt, 1);
00051     pixDestroy(&pixt);
00052     boxDestroy(&box);
00053 
00054         /* Color non-white pixels on colormap */
00055     pixt = pixThresholdTo4bpp(pixs, 6, 1);
00056     box = boxCreate(120, 30, 200, 200);
00057     pixColorGray(pixt, box, L_PAINT_DARK, 220, 0, 0, 255);
00058     pixDisplayWrite(pixt, 1);
00059     pixColorGray(pixt, NULL, L_PAINT_DARK, 220, 255, 100, 100);
00060     pixDisplayWrite(pixt, 1);
00061     pixDestroy(&pixt);
00062     boxDestroy(&box);
00063 
00064         /* Color non-black pixels on RGB */
00065     pixt = pixConvert8To32(pixs);
00066     box = boxCreate(120, 30, 200, 200);
00067     pixColorGray(pixt, box, L_PAINT_LIGHT, 20, 0, 0, 255);
00068     pixDisplayWrite(pixt, 1);
00069     pixColorGray(pixt, NULL, L_PAINT_LIGHT, 80, 255, 100, 100);
00070     pixDisplayWrite(pixt, 1);
00071     pixDestroy(&pixt);
00072     boxDestroy(&box);
00073 
00074         /* Color non-black pixels on colormap */
00075     pixt = pixThresholdTo4bpp(pixs, 6, 1);
00076     box = boxCreate(120, 30, 200, 200);
00077     pixColorGray(pixt, box, L_PAINT_LIGHT, 20, 0, 0, 255);
00078     pixDisplayWrite(pixt, 1);
00079     pixColorGray(pixt, NULL, L_PAINT_LIGHT, 20, 255, 100, 100);
00080     pixDisplayWrite(pixt, 1);
00081     pixDestroy(&pixt);
00082     boxDestroy(&box);
00083 
00084         /* Add highlight color to RGB */
00085     pixt = pixConvert8To32(pixs);
00086     box = boxCreate(507, 5, 385, 45);
00087     pixg = pixClipRectangle(pixs, box, NULL);
00088     pixb = pixThresholdToBinary(pixg, 180);
00089     pixInvert(pixb, pixb);
00090     pixDisplayWrite(pixb, 1);
00091     composeRGBPixel(50, 0, 250, &val32);
00092     pixPaintThroughMask(pixt, pixb, box->x, box->y, val32);
00093     boxDestroy(&box);
00094     pixDestroy(&pixg);
00095     pixDestroy(&pixb);
00096     box = boxCreate(236, 107, 262, 40);
00097     pixg = pixClipRectangle(pixs, box, NULL);
00098     pixb = pixThresholdToBinary(pixg, 180);
00099     pixInvert(pixb, pixb);
00100     composeRGBPixel(250, 0, 50, &val32);
00101     pixPaintThroughMask(pixt, pixb, box->x, box->y, val32);
00102     boxDestroy(&box);
00103     pixDestroy(&pixg);
00104     pixDestroy(&pixb);
00105     box = boxCreate(222, 208, 247, 43);
00106     pixg = pixClipRectangle(pixs, box, NULL);
00107     pixb = pixThresholdToBinary(pixg, 180);
00108     pixInvert(pixb, pixb);
00109     composeRGBPixel(60, 250, 60, &val32);
00110     pixPaintThroughMask(pixt, pixb, box->x, box->y, val32);
00111     boxDestroy(&box);
00112     pixDestroy(&pixg);
00113     pixDestroy(&pixb);
00114     pixDisplayWrite(pixt, 1);
00115     pixDestroy(&pixt);
00116 
00117         /* Add highlight color to colormap */
00118     pixt = pixThresholdTo4bpp(pixs, 5, 1);
00119     cmap = pixGetColormap(pixt);
00120     pixcmapGetIndex(cmap, 255, 255, 255, &index);
00121     box = boxCreate(507, 5, 385, 45);
00122     pixSetSelectCmap(pixt, box, index, 50, 0, 250);
00123     boxDestroy(&box);
00124     box = boxCreate(236, 107, 262, 40);
00125     pixSetSelectCmap(pixt, box, index, 250, 0, 50);
00126     boxDestroy(&box);
00127     box = boxCreate(222, 208, 247, 43);
00128     pixSetSelectCmap(pixt, box, index, 60, 250, 60);
00129     boxDestroy(&box);
00130     pixDisplayWrite(pixt, 1);
00131     pixDestroy(&pixt);
00132 
00133         /* Paint lines on RGB */
00134     pixt = pixConvert8To32(pixs);
00135     pixRenderLineArb(pixt, 450, 20, 850, 320, 5, 200, 50, 125);
00136     pixRenderLineArb(pixt, 30, 40, 440, 40, 5, 100, 200, 25);
00137     box = boxCreate(70, 80, 300, 245);
00138     pixRenderBoxArb(pixt, box, 3, 200, 200, 25);
00139     pixDisplayWrite(pixt, 1);
00140     pixDestroy(&pixt);
00141     boxDestroy(&box);
00142 
00143         /* Paint lines on colormap */
00144     pixt = pixThresholdTo4bpp(pixs, 5, 1);
00145     pixRenderLineArb(pixt, 450, 20, 850, 320, 5, 200, 50, 125);
00146     pixRenderLineArb(pixt, 30, 40, 440, 40, 5, 100, 200, 25);
00147     box = boxCreate(70, 80, 300, 245);
00148     pixRenderBoxArb(pixt, box, 3, 200, 200, 25);
00149     pixDisplayWrite(pixt, 1);
00150     pixDestroy(&pixt);
00151     boxDestroy(&box);
00152 
00153         /* Blend lines on RGB */
00154     pixt = pixConvert8To32(pixs);
00155     pixRenderLineBlend(pixt, 450, 20, 850, 320, 5, 200, 50, 125, 0.35);
00156     pixRenderLineBlend(pixt, 30, 40, 440, 40, 5, 100, 200, 25, 0.35);
00157     box = boxCreate(70, 80, 300, 245);
00158     pixRenderBoxBlend(pixt, box, 3, 200, 200, 25, 0.6);
00159     pixDisplayWrite(pixt, 1);
00160     pixDestroy(&pixt);
00161     boxDestroy(&box);
00162 
00163         /* Colorize gray on cmapped image. */
00164     pixt1 = pixRead("lucasta.150.jpg");
00165     pixt2 = pixThresholdTo4bpp(pixt1, 7, 1);
00166     box1 = boxCreate(73, 206, 140, 27);
00167     pixColorGrayCmap(pixt2, box1, L_PAINT_LIGHT, 130, 207, 43);
00168     pixDisplayWrite(pixt2, 1);
00169     pixPrintStreamInfo(stderr, pixt2, "One box added");
00170 
00171     box2 = boxCreate(255, 404, 197, 25);
00172     pixColorGrayCmap(pixt2, box2, L_PAINT_LIGHT, 230, 67, 119);
00173     pixDisplayWrite(pixt2, 1);
00174     pixPrintStreamInfo(stderr, pixt2, "Two boxes added");
00175 
00176     box3 = boxCreate(122, 756, 224, 22);
00177     pixColorGrayCmap(pixt2, box3, L_PAINT_DARK, 230, 67, 119);
00178     pixDisplayWrite(pixt2, 1);
00179     pixPrintStreamInfo(stderr, pixt2, "Three boxes added");
00180 
00181     box4 = boxCreate(11, 780, 147, 22);
00182     pixColorGrayCmap(pixt2, box4, L_PAINT_LIGHT, 70, 137, 229);
00183     pixDisplayWrite(pixt2, 1);
00184     pixPrintStreamInfo(stderr, pixt2, "Four boxes added");
00185 
00186     box5 = boxCreate(163, 605, 78, 22);
00187     pixColorGrayCmap(pixt2, box5, L_PAINT_LIGHT, 70, 137, 229);
00188     pixDisplayWrite(pixt2, 1);
00189     pixPrintStreamInfo(stderr, pixt2, "Five boxes added");
00190     pixDestroy(&pixt1);
00191     pixDestroy(&pixt2);
00192     boxDestroy(&box1);
00193     boxDestroy(&box2);
00194     boxDestroy(&box3);
00195     boxDestroy(&box4);
00196     boxDestroy(&box5);
00197 
00198     pixDisplayMultiple("/tmp/junk_write_display*");
00199     pixDestroy(&pixs);
00200     return 0;
00201 }
00202 
00203 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines