Exemplo n.º 1
0
main(int    argc,
     char **argv)
{
char         buffer[512];
char        *tempfile1, *tempfile2;
l_uint8     *data;
l_int32      i, j, w, h, seq, ret, same;
size_t       nbytes;
const char  *title;
BOX         *box;
BOXA        *boxa1, *boxa2;
L_BYTEA     *ba;
L_PDF_DATA  *lpd;
PIX         *pix1, *pix2, *pix3, *pix4, *pix5, *pix6;
PIX         *pixs, *pixt, *pixg, *pixgc, *pixc;
static char  mainName[] = "pdfiotest";

    if (argc != 1)
        exit(ERROR_INT("syntax: pdfiotest", mainName, 1));
    l_pdfSetDateAndVersion(0);

#if 1
    /* ---------------  Single image tests  ------------------- */
    fprintf(stderr, "\n*** Writing single images as pdf files\n");

    convertToPdf("weasel2.4c.png", L_FLATE_ENCODE, 0, "/tmp/pdffile01.pdf",
                 0, 0, 72, NULL, 0, "weasel2.4c.png");
    convertToPdf("test24.jpg", L_JPEG_ENCODE, 0, "/tmp/pdffile02.pdf",
                 0, 0, 72, NULL, 0, "test24.jpg");
    convertToPdf("feyn.tif", L_G4_ENCODE, 0, "/tmp/pdffile03.pdf",
                 0, 0, 300, NULL, 0, "feyn.tif");

    pixs = pixRead("feyn.tif");
    pixConvertToPdf(pixs, L_G4_ENCODE, 0, "/tmp/pdffile04.pdf", 0, 0, 300,
                    NULL, 0, "feyn.tif");
    pixDestroy(&pixs);

    pixs = pixRead("test24.jpg");
    pixConvertToPdf(pixs, L_JPEG_ENCODE, 5, "/tmp/pdffile05.pdf", 0, 0, 72,
                    NULL, 0, "test24.jpg");
    pixDestroy(&pixs);

    pixs = pixRead("feyn.tif");
    pixt = pixScaleToGray2(pixs);
    pixWrite("junkfeyn8.png", pixt, IFF_PNG);
    convertToPdf("junkfeyn8.png", L_JPEG_ENCODE, 0, "/tmp/pdffile06.pdf",
                 0, 0, 150, NULL, 0, "junkfeyn8.png");
    pixDestroy(&pixs);
    pixDestroy(&pixt);
    
    convertToPdf("weasel4.16g.png", L_FLATE_ENCODE, 0, "/tmp/pdffile07.pdf",
                 0, 0, 30, NULL, 0, "weasel4.16g.png");

    pixs = pixRead("test24.jpg");
    pixg = pixConvertTo8(pixs, 0);
    box = boxCreate(100, 100, 100, 100);
    pixc = pixClipRectangle(pixs, box, NULL);
    pixgc = pixClipRectangle(pixg, box, NULL);
    pixWrite("junkpix32.jpg", pixc, IFF_JFIF_JPEG);
    pixWrite("junkpix8.jpg", pixgc, IFF_JFIF_JPEG);
    convertToPdf("junkpix32.jpg", L_FLATE_ENCODE, 0, "/tmp/pdffile08.pdf",
                 0, 0, 72, NULL, 0, "junkpix32.jpg");
    convertToPdf("junkpix8.jpg", L_FLATE_ENCODE, 0, "/tmp/pdffile09.pdf",
                 0, 0, 72, NULL, 0, "junkpix8.jpg");
    pixDestroy(&pixs);
    pixDestroy(&pixg);
    pixDestroy(&pixc);
    pixDestroy(&pixgc);
    boxDestroy(&box);
#endif


#if 1
    /* ---------------  Multiple image tests  ------------------- */
    fprintf(stderr, "\n*** Writing multiple images as single page pdf files\n");

    pix1 = pixRead("feyn-fract.tif");
    pix2 = pixRead("weasel8.240c.png");

/*    l_pdfSetDateAndVersion(0); */
        /* First, write the 1 bpp image through the mask onto the weasels */
    for (i = 0; i < 5; i++) {
        for (j = 0; j < 10; j++) {
            seq = (i == 0 && j == 0) ? L_FIRST_IMAGE : L_NEXT_IMAGE;
            title = (i == 0 && j == 0) ? "feyn-fract.tif" : NULL;
            pixConvertToPdf(pix2, L_FLATE_ENCODE, 0, NULL, 100 * j,
                            100 * i, 70, &lpd, seq, title);
        }
    }
    pixConvertToPdf(pix1, L_G4_ENCODE, 0, "/tmp/pdffile10.pdf", 0, 0, 80, &lpd,
                    L_LAST_IMAGE, NULL);

        /* Now, write the 1 bpp image over the weasels */
    l_pdfSetG4ImageMask(0);
    for (i = 0; i < 5; i++) {
        for (j = 0; j < 10; j++) {
            seq = (i == 0 && j == 0) ? L_FIRST_IMAGE : L_NEXT_IMAGE;
            title = (i == 0 && j == 0) ? "feyn-fract.tif" : NULL;
            pixConvertToPdf(pix2, L_FLATE_ENCODE, 0, NULL, 100 * j,
                            100 * i, 70, &lpd, seq, title);
        }
    }
    pixConvertToPdf(pix1, L_G4_ENCODE, 0, "/tmp/pdffile11.pdf", 0, 0, 80, &lpd,
                    L_LAST_IMAGE, NULL);
    l_pdfSetG4ImageMask(1);
    pixDestroy(&pix1);
    pixDestroy(&pix2);
#endif

#if 1
    /* -------- pdf convert segmented with no image regions -------- */
    fprintf(stderr, "\n*** Writing segmented images without image regions\n");

    pix1 = pixRead("rabi.png");
    pix2 = pixScaleToGray2(pix1);
    pixWrite("/tmp/rabi8.jpg", pix2, IFF_JFIF_JPEG);
    pix3 = pixThresholdTo4bpp(pix2, 16, 1);
    pixWrite("/tmp/rabi4.png", pix3, IFF_PNG);
    pixDestroy(&pix1);
    pixDestroy(&pix2);
    pixDestroy(&pix3);

        /* 1 bpp input */
    convertToPdfSegmented("rabi.png", 300, L_G4_ENCODE, 128, NULL, 0, 0,
                          "/tmp/pdffile12.pdf");
    convertToPdfSegmented("rabi.png", 300, L_JPEG_ENCODE, 128, NULL, 0, 0,
                          "/tmp/pdffile13.pdf");
    convertToPdfSegmented("rabi.png", 300, L_FLATE_ENCODE, 128, NULL, 0, 0,
                          "/tmp/pdffile14.pdf");

        /* 8 bpp input, no cmap */
    convertToPdfSegmented("/tmp/rabi8.jpg", 150, L_G4_ENCODE, 128,
                          NULL, 0, 0, "/tmp/pdffile15.pdf");
    convertToPdfSegmented("/tmp/rabi8.jpg", 150, L_JPEG_ENCODE, 128,
                          NULL, 0, 0, "/tmp/pdffile16.pdf");
    convertToPdfSegmented("/tmp/rabi8.jpg", 150, L_FLATE_ENCODE, 128,
                          NULL, 0, 0, "/tmp/pdffile17.pdf");

        /* 4 bpp input, cmap */
    convertToPdfSegmented("/tmp/rabi4.png", 150, L_G4_ENCODE, 128,
                          NULL, 0, 0, "/tmp/pdffile18.pdf");
    convertToPdfSegmented("/tmp/rabi4.png", 150, L_JPEG_ENCODE, 128,
                          NULL, 0, 0, "/tmp/pdffile19.pdf");
    convertToPdfSegmented("/tmp/rabi4.png", 150, L_FLATE_ENCODE, 128,
                          NULL, 0, 0, "/tmp/pdffile20.pdf");

#endif

#if 1
    /* ---------- pdf convert segmented with image regions ---------- */
    fprintf(stderr, "\n*** Writing segmented images with image regions\n");

        /* Get the image region(s) for rabi.png.  There are two
         * small bogus regions at the top, but we'll keep them for
         * the demonstration. */
    pix1 = pixRead("rabi.png");
    pixSetResolution(pix1, 300, 300);
    pixGetDimensions(pix1, &w, &h, NULL);
    pix2 = pixGenHalftoneMask(pix1, NULL, NULL, 0);
    pix3 = pixMorphSequence(pix2, "c20.1 + c1.20", 0);
    boxa1 = pixConnComp(pix3, NULL, 8);
    boxa2 = boxaTransform(boxa1, 0, 0, 0.5, 0.5);
    pixDestroy(&pix1);
    pixDestroy(&pix2);
    pixDestroy(&pix3);

        /* 1 bpp input */
    convertToPdfSegmented("rabi.png", 300, L_G4_ENCODE, 128, boxa1,
                          0, 0.25, "/tmp/pdffile21.pdf");
    convertToPdfSegmented("rabi.png", 300, L_JPEG_ENCODE, 128, boxa1,
                          0, 0.25, "/tmp/pdffile22.pdf");
    convertToPdfSegmented("rabi.png", 300, L_FLATE_ENCODE, 128, boxa1,
                          0, 0.25, "/tmp/pdffile23.pdf");

        /* 8 bpp input, no cmap */
    convertToPdfSegmented("/tmp/rabi8.jpg", 150, L_G4_ENCODE, 128, boxa2,
                          0, 0.5, "/tmp/pdffile24.pdf");
    convertToPdfSegmented("/tmp/rabi8.jpg", 150, L_JPEG_ENCODE, 128, boxa2,
                          0, 0.5, "/tmp/pdffile25.pdf");
    convertToPdfSegmented("/tmp/rabi8.jpg", 150, L_FLATE_ENCODE, 128, boxa2,
                          0, 0.5, "/tmp/pdffile26.pdf");

        /* 4 bpp input, cmap */
    convertToPdfSegmented("/tmp/rabi4.png", 150, L_G4_ENCODE, 128, boxa2,
                          0, 0.5, "/tmp/pdffile27.pdf");
    convertToPdfSegmented("/tmp/rabi4.png", 150, L_JPEG_ENCODE, 128, boxa2,
                          0, 0.5, "/tmp/pdffile28.pdf");
    convertToPdfSegmented("/tmp/rabi4.png", 150, L_FLATE_ENCODE, 128, boxa2,
                          0, 0.5, "/tmp/pdffile29.pdf");

        /* 4 bpp input, cmap, data output */
    data = NULL;
    convertToPdfDataSegmented("/tmp/rabi4.png", 150, L_G4_ENCODE, 128, boxa2,
                              0, 0.5, &data, &nbytes);
    l_binaryWrite("/tmp/pdffile30.pdf", "w", data, nbytes);
    lept_free(data);
    convertToPdfDataSegmented("/tmp/rabi4.png", 150, L_JPEG_ENCODE, 128, boxa2,
                              0, 0.5, &data, &nbytes);
    l_binaryWrite("/tmp/pdffile31.pdf", "w", data, nbytes);
    lept_free(data);
    convertToPdfDataSegmented("/tmp/rabi4.png", 150, L_FLATE_ENCODE, 128, boxa2,
                              0, 0.5, &data, &nbytes);
    l_binaryWrite("/tmp/pdffile32.pdf", "w", data, nbytes);
    lept_free(data);

    boxaDestroy(&boxa1);
    boxaDestroy(&boxa2);
#endif

        
#if 1
    /* -------- pdf convert segmented from color image -------- */
    fprintf(stderr, "\n*** Writing color segmented images\n");

    pix1 = pixRead("candelabrum-11.jpg");
    pix2 = pixScale(pix1, 3.0, 3.0);
    pixWrite("/tmp/candelabrum3.jpg", pix2, IFF_JFIF_JPEG);
    GetImageMask(pix2, 200, &boxa1, "/tmp/seg1.jpg");
    convertToPdfSegmented("/tmp/candelabrum3.jpg", 200, L_G4_ENCODE,
                          100, boxa1, 0, 0.25, "/tmp/pdffile33.pdf");
    convertToPdfSegmented("/tmp/candelabrum3.jpg", 200, L_JPEG_ENCODE,
                          100, boxa1, 0, 0.25, "/tmp/pdffile34.pdf");
    convertToPdfSegmented("/tmp/candelabrum3.jpg", 200, L_FLATE_ENCODE,
                          100, boxa1, 0, 0.25, "/tmp/pdffile35.pdf");

    pixDestroy(&pix1);
    pixDestroy(&pix2);
    boxaDestroy(&boxa1);

    pix1 = pixRead("lion-page.00016.jpg");
    pix2 = pixScale(pix1, 3.0, 3.0);
    pixWrite("/tmp/lion16.jpg", pix2, IFF_JFIF_JPEG);
    pix3 = pixRead("lion-mask.00016.tif");
    boxa1 = pixConnComp(pix3, NULL, 8);
    boxa2 = boxaTransform(boxa1, 0, 0, 3.0, 3.0);
    convertToPdfSegmented("/tmp/lion16.jpg", 200, L_G4_ENCODE,
                          190, boxa2, 0, 0.5, "/tmp/pdffile36.pdf");
    convertToPdfSegmented("/tmp/lion16.jpg", 200, L_JPEG_ENCODE,
                          190, boxa2, 0, 0.5, "/tmp/pdffile37.pdf");
    convertToPdfSegmented("/tmp/lion16.jpg", 200, L_FLATE_ENCODE,
                          190, boxa2, 0, 0.5, "/tmp/pdffile38.pdf");

        /* Quantize the non-image part and flate encode.
         * This is useful because it results in a smaller file than
         * when you flate-encode the un-quantized non-image regions. */
    pix4 = pixScale(pix3, 3.0, 3.0);  /* higher res mask, for combining */
    pix5 = QuantizeNonImageRegion(pix2, pix4, 12);
    pixWrite("/tmp/lion16-quant.png", pix5, IFF_PNG);
    convertToPdfSegmented("/tmp/lion16-quant.png", 200, L_FLATE_ENCODE,
                          190, boxa2, 0, 0.5, "/tmp/pdffile39.pdf");

    pixDestroy(&pix1);
    pixDestroy(&pix2);
    pixDestroy(&pix3);
    pixDestroy(&pix4);
    pixDestroy(&pix5);
    boxaDestroy(&boxa1);
    boxaDestroy(&boxa2);
#endif

#if 1
    /* ------------------ Test multipage pdf generation ----------------- */
    fprintf(stderr, "\n*** Writing multipage pdfs from single page pdfs\n");

        /* Generate a multi-page pdf from all these files */
    startTimer();
    concatenatePdf("/tmp", "pdffile", "/tmp/cat_lept.pdf");
    fprintf(stderr, "Time: %7.3f\n", stopTimer());

        /* Put two good pdf files in a directory */
    lept_mkdir("good");
    lept_cp("testfile1.pdf", "/tmp/good");
    lept_cp("testfile2.pdf", "/tmp/good");
    concatenatePdf("/tmp/good", "file", "/tmp/good.pdf");

        /* Make a version with the pdf id removed, so that it is not
         * recognized as a pdf */
    ba = l_byteaInitFromFile("testfile2.pdf");
    data = l_byteaGetData(ba, &nbytes);
    l_binaryWrite("testfile0.notpdf.pdf", "w", data + 10, nbytes - 10);

        /* Make a version with a corrupted trailer */
    data[2297] = '2';  /* munge trailer object 6: change 458 --> 428 */
    l_binaryWrite("testfile2.bad.pdf", "w", data, nbytes);

        /* Put these two bad files, along with a good file, in a directory */
    lept_mkdir("bad");
    lept_mv("testfile0.notpdf.pdf", "/tmp/bad");
    lept_cp("testfile1.pdf", "/tmp/bad");
    lept_mv("testfile2.bad.pdf", "/tmp/bad");
    l_byteaDestroy(&ba);

        /* Run concat on the bad files.   In the /tmp/bad/ directory,
         * the "not pdf" file should be ignored, and the corrupted pdf
         * file should be properly parsed, so the resulting
         * concatenated files should be identical.  */
    fprintf(stderr, "\nWe attempt to build from the bad directory\n");
    concatenatePdf("/tmp/bad", "file", "/tmp/bad.pdf");
    filesAreIdentical("/tmp/good.pdf", "/tmp/bad.pdf", &same);
    if (same)
        fprintf(stderr, "Fixed: files are the same\n"
                        "Attempt succeeded\n\n");
    else
        fprintf(stderr, "Busted: files are different\n");

        /* pdftk fails because the first file is not a pdf */
    fprintf(stderr, "pdftk attempts to build from the bad directory\n");
    tempfile1 = genPathname("/tmp/bad", "*.pdf");
    tempfile2 = genPathname("/tmp", "pdftk.bad.pdf");
    snprintf(buffer, sizeof(buffer), "pdftk %s output %s",
             tempfile1, tempfile2);
    ret = system(buffer);
    lept_free(tempfile1);
    lept_free(tempfile2);
    fprintf(stderr, "Attempt failed\n\n");

#endif

#if 1
    fprintf(stderr, "\n*** pdftk writes multipage pdfs from images\n");
    tempfile1 = genPathname("/tmp", "pdffile*.pdf");
    tempfile2 = genPathname("/tmp", "cat_pdftk.pdf");
    snprintf(buffer, sizeof(buffer), "pdftk %s output %s",
             tempfile1, tempfile2);
    ret = system(buffer);
    lept_free(tempfile1);
    lept_free(tempfile2);
#endif

#if 1
    /* -- Test simple interface for generating multi-page pdf from images -- */
    fprintf(stderr, "\n*** Writing multipage pdfs from images\n");

        /* Put four image files in a directory.  They will be encoded thus:
         *     file1.png:  flate (8 bpp, only 10 colors)
         *     file2.jpg:  dct (8 bpp, 256 colors because of the jpeg encoding)
         *     file3.tif:  g4 (1 bpp)
         *     file4.jpg:  dct (32 bpp)    */
    lept_mkdir("image");
    pix1 = pixRead("feyn.tif");
    pix2 = pixRead("rabi.png");
    pix3 = pixScaleToGray3(pix1);
    pix4 = pixScaleToGray3(pix2);
    pix5 = pixScale(pix1, 0.33, 0.33);
    pix6 = pixRead("test24.jpg");
    pixWrite("/tmp/image/file1.png", pix3, IFF_PNG);  /* 10 colors */
    pixWrite("/tmp/image/file2.jpg", pix4, IFF_JFIF_JPEG);  /* 256 colors */
    pixWrite("/tmp/image/file3.tif", pix5, IFF_TIFF_G4);
    pixWrite("/tmp/image/file4.jpg", pix6, IFF_JFIF_JPEG);

    startTimer();
    convertFilesToPdf("/tmp/image", "file", 100, 0.8, 75, "4 file test",
                      "/tmp/fourimages.pdf");
    fprintf(stderr, "Time: %7.3f\n", stopTimer());
    pixDestroy(&pix1);
    pixDestroy(&pix2);
    pixDestroy(&pix3);
    pixDestroy(&pix4);
    pixDestroy(&pix5);
    pixDestroy(&pix6);
#endif

    return 0;
}
Exemplo n.º 2
0
void TestLeptCpRm(L_REGPARAMS  *rp,
                  const char   *srctail,
                  const char   *newdir,
                  const char   *newtail)
{
char     realnewdir[256], newnewdir[256];
char    *realtail, *newsrc, *fname;
l_int32  nfiles1, nfiles2, nfiles3;
SARRAY  *sa;

        /* Remove old version if it exists */
    realtail = (newtail) ? stringNew(newtail) : stringNew(srctail);
    lept_rm(newdir, realtail);
    makeTempDirname(realnewdir, 256, newdir);
    if (rp->display) {
        fprintf(stderr, "\nInput: srctail = %s, newdir = %s, newtail = %s\n",
                srctail, newdir, newtail);
        fprintf(stderr, "  realnewdir = %s, realtail = %s\n",
                realnewdir, realtail);
    }
    sa = getFilenamesInDirectory(realnewdir);
    nfiles1 = sarrayGetCount(sa);
    sarrayDestroy(&sa);

        /* Copy */
    lept_cp(srctail, newdir, newtail, &fname);
    sa = getFilenamesInDirectory(realnewdir);
    nfiles2 = sarrayGetCount(sa);
    if (rp->display) {
        fprintf(stderr, "  File copied to directory: %s\n", realnewdir);
        fprintf(stderr, "  ... with this filename: %s\n", fname);
        fprintf(stderr, "  delta files should be 1: %d\n", nfiles2 - nfiles1);
    }
    regTestCompareValues(rp, 1, nfiles2 - nfiles1, 0.0);  /* '1' */
    sarrayDestroy(&sa);
    lept_free(fname);

        /* Remove it */
    lept_rm(newdir, realtail);
    sa = getFilenamesInDirectory(realnewdir);
    nfiles2 = sarrayGetCount(sa);
    if (rp->display) {
        fprintf(stderr, "  File removed from directory: %s\n", realnewdir);
        fprintf(stderr, "  delta files should be 0: %d\n", nfiles2 - nfiles1);
    }
    regTestCompareValues(rp, 0, nfiles2 - nfiles1, 0.0);  /* '2' */
    sarrayDestroy(&sa);

        /* Copy it again ... */
    lept_cp(srctail, newdir, newtail, &fname);
    if (rp->display)
        fprintf(stderr, "  File copied to: %s\n", fname);

        /* move it elsewhere ... */
    lept_rmdir("junko");  /* clear out this directory */
    lept_mkdir("junko");
    newsrc = pathJoin(realnewdir, realtail);
    lept_mv(newsrc, "junko", NULL, &fname);
    if (rp->display) {
        fprintf(stderr, "  Move file at: %s\n", newsrc);
        fprintf(stderr, "  ... to: %s\n", fname);
    }
    lept_free(fname);
    lept_free(newsrc);
    makeTempDirname(newnewdir, 256, "junko");
    if (rp->display) fprintf(stderr, "  In this directory: %s\n", newnewdir);
    sa = getFilenamesInDirectory(newnewdir);  /* check if it landed ok */
    nfiles3 = sarrayGetCount(sa);
    if (rp->display) fprintf(stderr, "  num files should be 1: %d\n", nfiles3);
    regTestCompareValues(rp, 1, nfiles3, 0.0);  /* '3' */
    sarrayDestroy(&sa);

        /* and verify it was removed from the original location */
    sa = getFilenamesInDirectory(realnewdir);  /* check if it was removed */
    nfiles2 = sarrayGetCount(sa);
    if (rp->display) {
        fprintf(stderr, "  In this directory: %s\n", realnewdir);
        fprintf(stderr, "  delta files should be 0: %d\n", nfiles2 - nfiles1);
    }
    regTestCompareValues(rp, 0, nfiles2 - nfiles1, 0.0);  /* '4' */
    sarrayDestroy(&sa);
    lept_free(realtail);
}
Exemplo n.º 3
0
l_int32 main(int    argc,
             char **argv)
{
l_int32       delx, dely, etransx, etransy, w, h, area1, area2;
l_int32      *stab, *ctab;
l_float32     cx1, cy1, cx2, cy2, score, fract;
PIX          *pix0, *pix1, *pix2, *pix3, *pix4, *pix5;
L_REGPARAMS  *rp;

    if (regTestSetup(argc, argv, &rp))
        return 1;


    /* ------------ Test of pixBestCorrelation() --------------- */
    pix0 = pixRead("harmoniam100-11.png");
    pix1 = pixConvertTo1(pix0, 160);
    pixGetDimensions(pix1, &w, &h, NULL);

        /* Now make a smaller image, translated by (-32, -12)
         * Except for the resizing, this is equivalent to
         *     pix2 = pixTranslate(NULL, pix1, -32, -12, L_BRING_IN_WHITE);  */
    pix2 = pixCreate(w - 10, h, 1);
    pixRasterop(pix2, 0, 0, w, h, PIX_SRC, pix1, 32, 12);

        /* Get the number of FG pixels and the centroid locations */
    stab = makePixelSumTab8();
    ctab = makePixelCentroidTab8();
    pixCountPixels(pix1, &area1, stab);
    pixCountPixels(pix2, &area2, stab);
    pixCentroid(pix1, ctab, stab, &cx1, &cy1);
    pixCentroid(pix2, ctab, stab, &cx2, &cy2);
    etransx = lept_roundftoi(cx1 - cx2);
    etransy = lept_roundftoi(cy1 - cy2);
    fprintf(stderr, "delta cx = %d, delta cy = %d\n",
            etransx, etransy);

        /* Get the best correlation, searching around the translation
         * where the centroids coincide */
    pixBestCorrelation(pix1, pix2, area1, area2, etransx, etransy,
                       4, stab, &delx, &dely, &score, 5);
    fprintf(stderr, "delx = %d, dely = %d, score = %7.4f\n",
            delx, dely, score);
    regTestCompareValues(rp, 32, delx, 0);   /* 0 */
    regTestCompareValues(rp, 12, dely, 0);   /* 1 */
    lept_mv("/tmp/lept/correl_5.png", "regout", NULL, NULL);
    regTestCheckFile(rp, "/tmp/regout/correl_5.png");   /* 2 */
    lept_free(stab);
    lept_free(ctab);
    pixDestroy(&pix0);
    pixDestroy(&pix1);
    pixDestroy(&pix2);


    /* ------------ Test of pixCompareWithTranslation() ------------ */
        /* Now use the pyramid to get the result.  Do a translation
         * to remove pixels at the bottom from pix2, so that the
         * centroids are initially far apart. */
    pix1 = pixRead("harmoniam-11.tif");
    pix2 = pixTranslate(NULL, pix1, -45, 25, L_BRING_IN_WHITE);
    l_pdfSetDateAndVersion(0);
    pixCompareWithTranslation(pix1, pix2, 160, &delx, &dely, &score, 1);
    pixDestroy(&pix1);
    pixDestroy(&pix2);
    fprintf(stderr, "delx = %d, dely = %d\n", delx, dely);
    regTestCompareValues(rp, 45, delx, 0);   /* 3 */
    regTestCompareValues(rp, -25, dely, 0);   /* 4 */
    lept_mv("/tmp/lept/correl.pdf", "regout", NULL, NULL);
    lept_mv("/tmp/lept/compare.pdf", "regout", NULL, NULL);
    regTestCheckFile(rp, "/tmp/regout/compare.pdf");   /* 5 */
    regTestCheckFile(rp, "/tmp/regout/correl.pdf");  /* 6 */

    /* ------------ Test of pixGetPerceptualDiff() --------------- */
    pix0 = pixRead("greencover.jpg");
    pix1 = pixRead("redcover.jpg");  /* pre-scaled to the same size */
        /* Apply directly to the color images */
    pixGetPerceptualDiff(pix0, pix1, 1, 3, 20, &fract, &pix2, &pix3);
    fprintf(stderr, "Fraction of color pixels = %f\n", fract);
    regTestCompareValues(rp, 0.061252, fract, 0.01);  /* 7 */
    regTestWritePixAndCheck(rp, pix2, IFF_JFIF_JPEG);  /* 8 */
    regTestWritePixAndCheck(rp, pix3, IFF_TIFF_G4);  /* 9 */
    pixDestroy(&pix2);
    pixDestroy(&pix3);
        /* Apply to grayscale images */
    pix2 = pixConvertTo8(pix0, 0);
    pix3 = pixConvertTo8(pix1, 0);
    pixGetPerceptualDiff(pix2, pix3, 1, 3, 20, &fract, &pix4, &pix5);
    fprintf(stderr, "Fraction of grayscale pixels = %f\n", fract);
    regTestCompareValues(rp, 0.046928, fract, 0.0002);  /* 10 */
    regTestWritePixAndCheck(rp, pix4, IFF_JFIF_JPEG);  /* 11 */
    regTestWritePixAndCheck(rp, pix5, IFF_TIFF_G4);  /* 12 */
    pixDestroy(&pix0);
    pixDestroy(&pix1);
    pixDestroy(&pix2);
    pixDestroy(&pix3);
    pixDestroy(&pix4);
    pixDestroy(&pix5);

    return regTestCleanup(rp);
}