Leptonica 1.68
C Image Processing Library

psio_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  * psio_reg.c
00018  *
00019  *   Tests writing of images in PS, with arbitrary scaling and
00020  *   translation, in the following formats:
00021  *
00022  *      - uncompressed
00023  *      - DCT compressed (jpeg for 8 bpp grayscale and RGB)
00024  *      - CCITT-G4 compressed (g4 fax compression for 1 bpp)
00025  *      - Flate compressed (gzip compression)
00026  */
00027 
00028 #include "allheaders.h"
00029 
00030 char *WeaselNames[] = {(char *)"weasel2.4c.png",
00031                        (char *)"weasel2.4g.png",
00032                        (char *)"weasel2.png",
00033                        (char *)"weasel4.11c.png",
00034                        (char *)"weasel4.8g.png",
00035                        (char *)"weasel4.16g.png",
00036                        (char *)"weasel8.16g.png",
00037                        (char *)"weasel8.149g.png",
00038                        (char *)"weasel8.240c.png",
00039                        (char *)"weasel8.png",
00040                        (char *)"weasel32.png"};
00041 main(int    argc,
00042      char **argv)
00043 {
00044 l_int32       i, w, h;
00045 l_float32     factor, scale;
00046 BOX          *box;
00047 FILE         *fp1;
00048 PIX          *pixs, *pixt;
00049 PIXA         *pixa;
00050 SARRAY       *sa;
00051 L_REGPARAMS  *rp;
00052 
00053     if (regTestSetup(argc, argv, &rp))
00054         return 1;
00055 
00056     factor = 0.95;
00057 
00058         /* Uncompressed PS with scaling but centered on the page */
00059     pixs = pixRead("feyn-fract.tif");
00060     pixGetDimensions(pixs, &w, &h, NULL);
00061     scale = L_MIN(factor * 2550 / w, factor * 3300 / h);
00062     fp1 = lept_fopen("/tmp/psio0.ps", "wb+");
00063     pixWriteStreamPS(fp1, pixs, NULL, 300, scale);
00064     lept_fclose(fp1);
00065     regTestCheckFile(rp, "/tmp/psio0.ps");  /* 0 */
00066     pixDestroy(&pixs);
00067 
00068         /* Uncompressed PS with scaling, with LL corner at (1500, 1500) mils */
00069     pixs = pixRead("weasel4.11c.png");
00070     pixGetDimensions(pixs, &w, &h, NULL);
00071     scale = L_MIN(factor * 2550 / w, factor * 3300 / h);
00072     box = boxCreate(1500, 1500, (l_int32)(1000 * scale * w / 300),
00073                     (l_int32)(1000 * scale * h / 300));
00074     fp1 = lept_fopen("/tmp/psio1.ps", "wb+");
00075     pixWriteStreamPS(fp1, pixs, box, 300, 1.0);
00076     lept_fclose(fp1);
00077     regTestCheckFile(rp, "/tmp/psio1.ps");  /* 1 */
00078     boxDestroy(&box);
00079     pixDestroy(&pixs);
00080 
00081         /* DCT compressed PS with LL corner at (300, 1000) pixels */
00082     pixs = pixRead("marge.jpg");
00083     pixt = pixConvertTo32(pixs);
00084     pixWrite("/tmp/psio2.jpg", pixt, IFF_JFIF_JPEG);
00085     convertJpegToPS("/tmp/psio2.jpg", "/tmp/psio3.ps",
00086                     "w", 300, 1000, 0, 4.0, 1, 1);
00087     regTestCheckFile(rp, "/tmp/psio2.jpg");  /* 2 */
00088     regTestCheckFile(rp, "/tmp/psio3.ps");  /* 3 */
00089     pixDestroy(&pixt);
00090     pixDestroy(&pixs);
00091 
00092         /* For each page, apply tiff g4 image first; then jpeg or png over it */
00093     convertG4ToPS("feyn.tif", "/tmp/psio4.ps", "w", 0, 0, 0, 1.0, 1, 1, 0);
00094     convertJpegToPS("marge.jpg", "/tmp/psio4.ps",
00095                     "a", 500, 100, 300, 2.0, 1,  0);
00096     convertFlateToPS("weasel4.11c.png", "/tmp/psio4.ps",
00097                      "a", 300, 400, 300, 6.0, 1,  0);
00098     convertJpegToPS("marge.jpg", "/tmp/psio4.ps",
00099                     "a", 100, 800, 300, 1.5, 1, 1);
00100 
00101     convertG4ToPS("feyn.tif", "/tmp/psio4.ps", "a", 0, 0, 0, 1.0, 2, 1, 0);
00102     convertJpegToPS("marge.jpg", "/tmp/psio4.ps",
00103                     "a", 1000, 700, 300, 2.0, 2, 0);
00104     convertJpegToPS("marge.jpg", "/tmp/psio4.ps",
00105                     "a", 100, 200, 300, 2.0, 2, 1);
00106 
00107     convertG4ToPS("feyn.tif", "/tmp/psio4.ps", "a", 0, 0, 0, 1.0, 3, 1, 0);
00108     convertJpegToPS("marge.jpg", "/tmp/psio4.ps",
00109                     "a", 200, 200, 300, 2.0, 3, 0);
00110     convertJpegToPS("marge.jpg", "/tmp/psio4.ps",
00111                     "a", 200, 900, 300, 2.0, 3, 1);
00112     regTestCheckFile(rp, "/tmp/psio4.ps");  /* 4 */
00113 
00114         /* Now apply jpeg first; then paint through a g4 mask.
00115          * For gv, the first image with a b.b. determines the
00116          * window size for the canvas, so we put down the largest
00117          * image first.  If we had rendered a small image first,
00118          * gv and evince will not show the entire page.  However, after
00119          * conversion to pdf, everything works fine, regardless of the
00120          * order in which images are placed into the PS.  That is
00121          * because the pdf interpreter is robust to bad hints, ignoring
00122          * the page hints and computing the bounding box from the
00123          * set of images rendered on the page.
00124          *
00125          * Concatenate several pages, with colormapped png, color
00126          * jpeg and tiffg4 images (with the g4 image acting as a mask
00127          * that we're painting black through.  If the text layer
00128          * is painted first, the following images occlude it; otherwise,
00129          * the images remain in the background of the text. */
00130     pixs = pixRead("wyom.jpg");
00131     pixt = pixScaleToSize(pixs, 2528, 3300);
00132     pixWrite("/tmp/psio5.jpg", pixt, IFF_JFIF_JPEG);
00133     pixDestroy(&pixs);
00134     pixDestroy(&pixt);
00135     convertJpegToPS("/tmp/psio5.jpg", "/tmp/psio5.ps",
00136                       "w", 0, 0, 300, 1.0, 1, 0);
00137     convertFlateToPS("weasel8.240c.png", "/tmp/psio5.ps",
00138                      "a", 100, 100, 300, 5.0, 1, 0);
00139     convertFlateToPS("weasel8.149g.png", "/tmp/psio5.ps",
00140                      "a", 200, 300, 300, 5.0, 1, 0);
00141     convertFlateToPS("weasel4.11c.png", "/tmp/psio5.ps",
00142                      "a", 300, 500, 300, 5.0, 1, 0);
00143     convertG4ToPS("feyn.tif", "/tmp/psio5.ps", "a", 0, 0, 0, 1.0, 1, 1, 1);
00144 
00145     convertJpegToPS("marge.jpg", "/tmp/psio5.ps",
00146                     "a", 500, 100, 300, 2.0, 2,  0);
00147     convertFlateToPS("weasel4.11c.png", "/tmp/psio5.ps",
00148                      "a", 300, 400, 300, 6.0, 2,  0);
00149     convertJpegToPS("marge.jpg", "/tmp/psio5.ps",
00150                     "a", 100, 800, 300, 1.5, 2, 0);
00151     convertG4ToPS("feyn.tif", "/tmp/psio5.ps", "a", 0, 0, 0, 1.0, 2, 1, 1);
00152 
00153     convertJpegToPS("marge.jpg", "/tmp/psio5.ps",
00154                     "a", 500, 100, 300, 2.0, 3,  0);
00155     convertJpegToPS("marge.jpg", "/tmp/psio5.ps",
00156                     "a", 100, 800, 300, 2.0, 3, 0);
00157     convertG4ToPS("feyn.tif", "/tmp/psio5.ps", "a", 0, 0, 0, 1.0, 3, 1, 1);
00158 
00159     convertJpegToPS("marge.jpg", "/tmp/psio5.ps",
00160                     "a", 700, 700, 300, 2.0, 4, 0);
00161     convertFlateToPS("weasel8.149g.png", "/tmp/psio5.ps",
00162                      "a", 400, 400, 300, 5.0, 4, 0);
00163     convertG4ToPS("feyn.tif", "/tmp/psio5.ps", "a", 0, 0, 0, 1.0, 4, 1, 0);
00164     convertFlateToPS("weasel8.240c.png", "/tmp/psio5.ps",
00165                      "a", 100, 220, 300, 5.0, 4, 0);
00166     convertJpegToPS("marge.jpg", "/tmp/psio5.ps",
00167                     "a", 100, 200, 300, 2.0, 4, 1);
00168 
00169     convertJpegToPS("marge.jpg", "/tmp/psio5.ps",
00170                     "a", 200, 200, 300, 1.5, 5, 0);
00171     convertFlateToPS("weasel8.240c.png", "/tmp/psio5.ps",
00172                      "a", 140, 80, 300, 7.0, 5, 0);
00173     convertG4ToPS("feyn.tif", "/tmp/psio5.ps", "a", 0, 0, 0, 1.0, 5, 1, 0);
00174     convertFlateToPS("weasel8.149g.png", "/tmp/psio5.ps",
00175                      "a", 280, 310, 300, 5.0, 4, 0);
00176     convertJpegToPS("marge.jpg", "/tmp/psio5.ps",
00177                     "a", 200, 900, 300, 2.0, 5, 1);
00178     regTestCheckFile(rp, "/tmp/psio5.ps");  /* 5 */
00179  
00180         /* Generation using segmentation masks */
00181     convertSegmentedPagesToPS(".", "lion-page", ".", "lion-mask",
00182                               10, 0, 100, 2.0, 0.8, 190, "/tmp/psio6.ps");
00183     regTestCheckFile(rp, "/tmp/psio6.ps");  /* 6 */
00184 
00185         /* PS generation for embeddding */
00186     convertJpegToPSEmbed("tetons.jpg", "/tmp/psio7.ps");
00187     regTestCheckFile(rp, "/tmp/psio7.ps");  /* 7 */
00188 
00189     convertG4ToPSEmbed("feyn-fract.tif", "/tmp/psio8.ps");
00190     regTestCheckFile(rp, "/tmp/psio8.ps");  /* 8 */
00191 
00192     convertFlateToPSEmbed("weasel8.240c.png", "/tmp/psio9.ps");
00193     regTestCheckFile(rp, "/tmp/psio9.ps");  /* 9 */
00194 
00195         /* Writing compressed from a pixa */
00196     sa = sarrayCreate(0);
00197     for (i = 0; i < 11; i++)
00198         sarrayAddString(sa, WeaselNames[i], L_COPY); 
00199     pixa = pixaReadFilesSA(sa);
00200     pixaWriteCompressedToPS(pixa, "/tmp/psio10.ps", 0, 3);
00201     regTestCheckFile(rp, "/tmp/psio10.ps");  /* 10 */
00202     pixaDestroy(&pixa);
00203     sarrayDestroy(&sa);
00204 
00205     regTestCleanup(rp);
00206     return 0;
00207 }
00208 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines