Leptonica 1.68
C Image Processing Library

psioseg_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  * psioseg_reg.c
00018  *
00019  *   This tests the PostScript output for images with mixed
00020  *   text and images, coming from source of different depths,
00021  *   with and without colormaps.
00022  *
00023  *   Both convertFilesFittedToPS() and convertSegmentedPagesToPS()
00024  *   generate a compressed PostScript file from a subset of images in
00025  *   a directory.  However, the latter function can also accept 1 bpp
00026  *   masks that delineate image (as opposed to text) regions in
00027  *   the corresponding page image file.  Then, for page images that
00028  *   are not 1 bpp, it generates mixed raster PostScript with
00029  *   g4 encoding for the text and jpeg ("DCT") encoding for the
00030  *   remaining image parts.
00031  *
00032  *   Although not required for 'success' on the regression test,
00033  *   this program uses ps2pdf to generate the pdf output.
00034  */
00035 
00036 #include "allheaders.h"
00037 
00038 main(int    argc,
00039      char **argv)
00040 {
00041 char          buf[512];
00042 char         *psname, *pdfname;
00043 l_int32       i, j, w, h, wc, hc, ret;
00044 l_float32     scalefactor;
00045 PIX          *pixs, *pixc, *pixht, *pixtxt, *pixmfull;
00046 PIX          *pix4c, *pix8c, *pix8g, *pix32, *pixcs, *pixcs2;
00047 L_REGPARAMS  *rp;
00048 
00049     if (regTestSetup(argc, argv, &rp))
00050         return 1;
00051 
00052         /* Source for generating images */
00053     pixs = pixRead("pageseg2.tif");   /* 1 bpp */
00054     pixc = pixRead("tetons.jpg");     /* 32 bpp */
00055 
00056         /* Get a halftone segmentation mask for pixs */
00057     pixGetRegionsBinary(pixs, &pixht, NULL, NULL, 0);
00058     pixtxt = pixSubtract(NULL, pixs, pixht);
00059 
00060         /* Construct a 32 bpp image in full page size, along with
00061          * a mask that can be used to render it. */
00062     pixGetDimensions(pixs, &w, &h, NULL);
00063     pixGetDimensions(pixc, &wc, NULL, NULL);
00064     scalefactor = (l_float32)w / (l_float32)wc;
00065     pixcs = pixScale(pixc, scalefactor, scalefactor);
00066     pixGetDimensions(pixcs, &wc, &hc, NULL);
00067     pixcs2 = pixCreate(w, h, 32);
00068     pixRasterop(pixcs2, 0, 0, w, hc, PIX_SRC, pixcs, 0, 0);
00069     pixRasterop(pixcs2, 0, hc, w, hc, PIX_SRC, pixcs, 0, 0);
00070     regTestWritePixAndCheck(rp, pixcs2, IFF_JFIF_JPEG);  /* 0 */
00071     pixmfull = pixCreate(w, h, 1);
00072     pixSetAll(pixmfull);  /* use as mask to render the color image */
00073     
00074          /* Now make a 32 bpp input image, taking text parts from the
00075           * page image and image parts from pixcs2. */
00076     pix32 = pixConvertTo32(pixtxt);
00077     pixCombineMasked(pix32, pixcs2, pixht);
00078     regTestWritePixAndCheck(rp, pix32, IFF_JFIF_JPEG);  /* 1 */
00079     
00080          /* Make an 8 bpp gray version */
00081     pix8g = pixConvertRGBToLuminance(pix32);
00082     regTestWritePixAndCheck(rp, pix8g, IFF_JFIF_JPEG);  /* 2 */
00083     
00084          /* Make an 8 bpp colormapped version */
00085     pix8c = pixOctreeColorQuant(pix32, 240, 0);
00086     regTestWritePixAndCheck(rp, pix8c, IFF_PNG);  /* 3 */
00087     
00088          /* Make a 4 bpp colormapped version */
00089     pix4c = pixOctreeQuantNumColors(pix32, 16, 4);
00090     regTestWritePixAndCheck(rp, pix4c, IFF_PNG);  /* 4 */
00091 
00092          /* Write out the files to be imaged */
00093     lept_mkdir("imagedir");
00094     lept_mkdir("maskdir");
00095     pixWrite("/tmp/imagedir/001.tif", pixs, IFF_TIFF_G4);
00096     pixWrite("/tmp/imagedir/002.tif", pixht, IFF_TIFF_G4);
00097     pixWrite("/tmp/imagedir/003.tif", pixtxt, IFF_TIFF_G4);
00098     pixWrite("/tmp/imagedir/004.jpg", pixcs2, IFF_JFIF_JPEG);
00099     pixWrite("/tmp/maskdir/004.tif", pixmfull, IFF_TIFF_G4);
00100     pixWrite("/tmp/imagedir/005.jpg", pix32, IFF_JFIF_JPEG);
00101     pixWrite("/tmp/maskdir/005.tif", pixht, IFF_TIFF_G4);
00102     pixWrite("/tmp/imagedir/006.jpg", pix8g, IFF_JFIF_JPEG);
00103     pixWrite("/tmp/maskdir/006.tif", pixht, IFF_TIFF_G4);
00104     pixWrite("/tmp/imagedir/007.png", pix8c, IFF_PNG);
00105     pixWrite("/tmp/maskdir/007.tif", pixht, IFF_TIFF_G4);
00106     pixWrite("/tmp/imagedir/008.png", pix4c, IFF_PNG);
00107     pixWrite("/tmp/maskdir/008.tif", pixht, IFF_TIFF_G4);
00108     pixDestroy(&pixs);
00109     pixDestroy(&pixc);
00110     pixDestroy(&pixht);
00111     pixDestroy(&pixtxt);
00112     pixDestroy(&pixcs);
00113     pixDestroy(&pixcs2);
00114     pixDestroy(&pixmfull);
00115     pixDestroy(&pix32);
00116     pixDestroy(&pix8g);
00117     pixDestroy(&pix8c);
00118     pixDestroy(&pix4c);
00119     
00120         /* Generate the 8 page ps and pdf files */
00121     convertSegmentedPagesToPS("/tmp/imagedir", NULL,
00122                               "/tmp/maskdir", NULL,
00123                               0, 0, 10, 2.0, 0.15, 190, "/tmp/junkseg.ps");
00124     regTestCheckFile(rp, "/tmp/junkseg.ps");  /* 5 */
00125     fprintf(stderr, "ps file made: /tmp/junkseg.ps\n");
00126     psname = genPathname("/tmp", "junkseg.ps");
00127     pdfname = genPathname("/tmp", "junkseg.pdf");
00128     snprintf(buf, sizeof(buf), "ps2pdf %s %s", psname, pdfname);
00129     ret = system(buf);
00130     lept_free(psname);
00131     lept_free(pdfname);
00132     fprintf(stderr, "pdf file made: /tmp/junkseg.pdf\n");
00133 
00134     regTestCleanup(rp);
00135     return ret;
00136 }
00137 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines