Leptonica 1.68
C Image Processing Library

paintmask_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 #include <stdio.h>
00017 #include <stdlib.h>
00018 #include "allheaders.h"
00019 
00020 /*
00021  *  paintmask_reg.c
00022  *
00023  *    Regression test for painting through a mask onto various
00024  *    depth images.
00025  *
00026  *    This file shows how one can start with a 32 bpp RGB image and
00027  *    derive from it the following:
00028  *       8 bpp color, cmapped
00029  *       4 bpp color, cmapped
00030  *       2 bpp color, cmapped
00031  *       8 bpp gray
00032  *       4 bpp gray
00033  *       4 bpp gray, cmapped
00034  *       2 bpp gray
00035  *       2 bpp gray, cmapped
00036  *
00037  *    For each of these, pixClipMasked() is used to place a 1 bpp
00038  *    mask over part of the image, clip out the rectangular region
00039  *    supporting the mask, and paint a given color through the
00040  *    mask onto the result.
00041  *
00042  *    Finally we do a clip/mask operation on 1 bpp sources.
00043  */
00044 
00045 
00046 main(int    argc,
00047 char **argv)
00048 {
00049 BOX         *box;
00050 PIX         *pixs, *pixs8, *pixm, *pixg, *pixt1, *pixt2, *pixd;
00051 static char  mainName[] = "paintmask_reg";
00052 
00053     pixDisplayWrite(NULL, -1);  /* reset */
00054 
00055         /* Start with a 32 bpp image and a mask.  Use the
00056          * same mask for all clip/masked operations. */
00057     pixs = pixRead("test24.jpg");
00058     pixt1 = pixRead("rabi.png");
00059     box = boxCreate(303, 1983, 800, 500);
00060     pixm = pixClipRectangle(pixt1, box, NULL);
00061     pixInvert(pixm, pixm);
00062     boxDestroy(&box);
00063     box = boxCreate(100, 100, 800, 500);  /* clips on pixs and derivatives */
00064     pixt2 = pixClipRectangle(pixs, box, NULL);
00065     pixDisplayWrite(pixt2, 1);
00066     pixDestroy(&pixt1);
00067     pixDestroy(&pixt2);
00068 
00069         /* Clip 32 bpp RGB */
00070     pixd = pixClipMasked(pixs, pixm, 100, 100, 0x03c08000);
00071     pixDisplayWrite(pixd, 1);
00072     pixDestroy(&pixd);
00073 
00074         /* Clip 8 bpp colormapped */
00075     pixt1 = pixMedianCutQuant(pixs, 0);
00076     pixt2 = pixClipRectangle(pixt1, box, NULL);
00077     pixDisplayWrite(pixt2, 1);
00078     pixd = pixClipMasked(pixt1, pixm, 100, 100, 0x03c08000);
00079     pixDisplayWrite(pixd, 1);
00080     pixDestroy(&pixt1);
00081     pixDestroy(&pixt2);
00082     pixDestroy(&pixd);
00083 
00084         /* Clip 4 bpp colormapped */
00085     pixt1 = pixOctreeQuantNumColors(pixs, 16, 1);
00086     pixt2 = pixClipRectangle(pixt1, box, NULL);
00087     pixDisplayWrite(pixt2, 1);
00088     pixd = pixClipMasked(pixt1, pixm, 100, 100, 0x03c08000);
00089     pixDisplayWrite(pixd, 1);
00090     pixDestroy(&pixt1);
00091     pixDestroy(&pixt2);
00092     pixDestroy(&pixd);
00093 
00094         /* Clip 2 bpp colormapped */
00095     pixt1 = pixMedianCutQuantGeneral(pixs, 0, 2, 4, 5, 1, 1);
00096     pixt2 = pixClipRectangle(pixt1, box, NULL);
00097     pixDisplayWrite(pixt2, 1);
00098     pixd = pixClipMasked(pixt1, pixm, 100, 100, 0x03608000);
00099     pixDisplayWrite(pixd, 1);
00100     pixDestroy(&pixt1);
00101     pixDestroy(&pixt2);
00102     pixDestroy(&pixd);
00103 
00104         /* Clip 8 bpp gray */
00105     pixs8 = pixConvertRGBToLuminance(pixs);
00106     pixt2 = pixClipRectangle(pixs8, box, NULL);
00107     pixDisplayWrite(pixt2, 1);
00108     pixd = pixClipMasked(pixs8, pixm, 100, 100, 90);
00109     pixDisplayWrite(pixd, 1);
00110     pixDestroy(&pixt2);
00111     pixDestroy(&pixd);
00112 
00113         /* Clip 4 bpp gray */
00114     pixt1 = pixThresholdTo4bpp(pixs8, 16, 0);
00115     pixt2 = pixClipRectangle(pixt1, box, NULL);
00116     pixDisplayWrite(pixt2, 1);
00117     pixd = pixClipMasked(pixt1, pixm, 100, 100, 0);
00118     pixDisplayWrite(pixd, 1);
00119     pixDestroy(&pixd);
00120     pixd = pixClipMasked(pixt1, pixm, 100, 100, 5);
00121     pixDisplayWrite(pixd, 1);
00122     pixDestroy(&pixd);
00123     pixd = pixClipMasked(pixt1, pixm, 100, 100, 15);
00124     pixDisplayWrite(pixd, 1);
00125     pixDestroy(&pixt1);
00126     pixDestroy(&pixt2);
00127     pixDestroy(&pixd);
00128 
00129         /* Clip 4 bpp gray, colormapped */
00130     pixt1 = pixThresholdTo4bpp(pixs8, 16, 1);
00131     pixt2 = pixClipRectangle(pixt1, box, NULL);
00132     pixDisplayWrite(pixt2, 1);
00133     pixd = pixClipMasked(pixt1, pixm, 100, 100, 0x55555500);
00134     pixDisplayWrite(pixd, 1);
00135     pixDestroy(&pixt1);
00136     pixDestroy(&pixt2);
00137     pixDestroy(&pixd);
00138 
00139         /* Clip 2 bpp gray */
00140     pixt1 = pixThresholdTo2bpp(pixs8, 4, 0);
00141     pixt2 = pixClipRectangle(pixt1, box, NULL);
00142     pixDisplayWrite(pixt2, 1);
00143     pixd = pixClipMasked(pixt1, pixm, 100, 100, 1);
00144     pixDisplayWrite(pixd, 1);
00145     pixDestroy(&pixt1);
00146     pixDestroy(&pixt2);
00147     pixDestroy(&pixd);
00148 
00149         /* Clip 2 bpp gray, colormapped */
00150     pixt1 = pixThresholdTo2bpp(pixs8, 4, 1);
00151     pixt2 = pixClipRectangle(pixt1, box, NULL);
00152     pixDisplayWrite(pixt2, 1);
00153     pixd = pixClipMasked(pixt1, pixm, 100, 100, 0x55555500);
00154     pixDisplayWrite(pixd, 1);
00155     pixDestroy(&pixt1);
00156     pixDestroy(&pixt2);
00157     pixDestroy(&pixd);
00158 
00159     pixDestroy(&pixm);
00160     pixDestroy(&pixs);
00161     pixDestroy(&pixs8);
00162     boxDestroy(&box);
00163 
00164         /* Finally, do the 1 bpp painting through clipped region.
00165          * We start with two 1 bpp text sources, use the inverse
00166          * of the 2nd for the mask (so we take all of the 1st
00167          * pixels under this mask), and for the remainder, which
00168          * are the fg pixels in the 2nd, we paint them black (1).
00169          * So this is a simple and fast blending of two 1 bpp pix. */
00170     pixs = pixRead("feyn.tif");
00171     box = boxCreate(670, 827, 800, 500);
00172     pixt2 = pixClipRectangle(pixs, box, NULL);
00173     boxDestroy(&box);
00174     pixDisplayWrite(pixt2, 1);
00175     pixt1 = pixRead("rabi.png");
00176     box = boxCreate(303, 1983, 800, 500);
00177     pixm = pixClipRectangle(pixt1, box, NULL);
00178     pixInvert(pixm, pixm);
00179     pixDisplayWrite(pixm, 1);
00180     pixd = pixClipMasked(pixs, pixm, 670, 827, 1);
00181     pixDisplayWrite(pixd, 1);
00182     pixDestroy(&pixs);
00183     pixDestroy(&pixt1);
00184     pixDestroy(&pixt2);
00185     pixDestroy(&pixm);
00186     pixDestroy(&pixd);
00187     boxDestroy(&box);
00188 
00189     pixDisplayMultiple("/tmp/junk_write_display*");
00190     return 0;
00191 }
00192 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines