예제 #1
0
int main(int    argc,
         char **argv)
{
l_int32      ret;
char        *filein, *tempfile, *printer;
char         buf[512];
static char  mainName[] = "printtiff";

    if (argc != 2 && argc != 3)
        return ERROR_INT(" Syntax:  printtiff filein [printer]", mainName, 1);
    filein = argv[1];
    if (argc == 3)
        printer = argv[2];

    fprintf(stderr,
         "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
         "   Warning: this program should only be used for testing,\n"
         "     and not in a production environment, because of a\n"
         "      potential vulnerability with the 'system' call.\n"
         "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n");

    setLeptDebugOK(1);
    (void)lept_rm(NULL, TEMP_PS);
    tempfile = genPathname("/tmp", TEMP_PS);
    convertTiffMultipageToPS(filein, tempfile, FILL_FACTOR);

    if (argc == 3) {
        snprintf(buf, sizeof(buf), "lpr -P%s %s &", printer, tempfile);
        ret = system(buf);
    }

    lept_free(tempfile);
    return 0;
}
예제 #2
0
int main(int argc,
         char **argv) {
    char *filein, *tempfile, *printer;
    char buf[512];
    l_int32 ignore;
    static char mainName[] = "printtiff";

    if (argc != 2 && argc != 3)
        return ERROR_INT(" Syntax:  printtiff filein [printer]", mainName, 1);

    filein = argv[1];
    if (argc == 3)
        printer = argv[2];

    lept_rm(NULL, TEMP_PS);
    tempfile = genPathname("/tmp", TEMP_PS);
    convertTiffMultipageToPS(filein, tempfile, NULL, FILL_FACTOR);

    if (argc == 3) {
        sprintf(buf, "lpr -P%s %s &", printer, tempfile);
        ignore = system(buf);
    }

    lept_free(tempfile);
    return 0;
}
예제 #3
0
int main(int    argc,
         char **argv)
{
char        *filein, *fileout, *fname;
char         buffer[512];
const char  *psfile = "/tmp/junk_split_image.ps";
l_int32      nx, ny, i, w, h, d, ws, hs, n, res, ignore;
l_float32    scale;
PIX         *pixs, *pixt, *pixr;
PIXA        *pixa;
static char  mainName[] = "splitimage2pdf";

    if (argc != 5)
        return ERROR_INT(" Syntax:  splitimage2pdf filein nx ny fileout",
                         mainName, 1);

    filein = argv[1];
    nx = atoi(argv[2]);
    ny = atoi(argv[3]);
    fileout = argv[4];

    lept_rm(NULL, "junk_split_image.ps");

    if ((pixs = pixRead(filein)) == NULL)
        return ERROR_INT("pixs not made", mainName, 1);
    d = pixGetDepth(pixs);
    if (d == 1 )
        lept_rm(NULL, "junk_split_image.tif");
    else if (d == 8 || d == 32)
        lept_rm(NULL, "junk_split_image.jpg");
    else
        return ERROR_INT("d not in {1,8,32} bpp", mainName, 1);

    pixGetDimensions(pixs, &ws, &hs, NULL);
    if (ny * ws > nx * hs)
        pixr = pixRotate90(pixs, 1);
    else
        pixr = pixClone(pixs);

    pixa = pixaSplitPix(pixr, nx, ny, 0, 0);
    n = pixaGetCount(pixa);
    res = 300;
    for (i = 0; i < n; i++) {
        pixt = pixaGetPix(pixa, i, L_CLONE);
        pixGetDimensions(pixt, &w, &h, NULL);
        scale = L_MIN(FILL_FACTOR * 2550 / w, FILL_FACTOR * 3300 / h);
        fname = NULL;
        if (d == 1) {
            fname = genPathname("/tmp", "junk_split_image.tif");
            pixWrite(fname, pixt, IFF_TIFF_G4);
            if (i == 0) {
                convertG4ToPS(fname, psfile, "w", 0, 0, 300,
                              scale, 1, FALSE, TRUE);
            } else {
                convertG4ToPS(fname, psfile, "a", 0, 0, 300,
                              scale, 1, FALSE, TRUE);
            }
        } else {
            fname = genPathname("/tmp", "junk_split_image.jpg");
            pixWrite(fname, pixt, IFF_JFIF_JPEG);
            if (i == 0) {
                convertJpegToPS(fname, psfile, "w", 0, 0, 300,
                                scale, 1, TRUE);
            } else {
                convertJpegToPS(fname, psfile, "a", 0, 0, 300,
                                scale, 1, TRUE);
            }
        }
        lept_free(fname);
        pixDestroy(&pixt);
    }

    snprintf(buffer, sizeof(buffer), "ps2pdf %s %s", psfile, fileout);
    ignore = system(buffer);  /* ps2pdf */

    pixaDestroy(&pixa);
    pixDestroy(&pixr);
    pixDestroy(&pixs);
    return 0;
}
예제 #4
0
l_int32 main(int    argc,
             char **argv)
{
char          buf[512];
l_int32       delx, dely, etransx, etransy, w, h, area1, area2;
l_int32      *stab, *ctab;
l_float32     cx1, cy1, cx2, cy2, score;
PIX          *pix0, *pix1, *pix2;
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 */
    regTestCheckFile(rp, "/tmp/junkcorrel_5.png");   /* 2 */
    lept_rm(NULL, "junkcorrel_5.png");
    FREE(stab);
    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 */
    regTestCheckFile(rp, "/tmp/junkcmp.pdf");   /* 5 */
    regTestCheckFile(rp, "/tmp/junkcorrel.pdf");  /* 6 */

    return regTestCleanup(rp);
}
예제 #5
0
int main(int    argc,
         char **argv)
{
char        *filein, *fname, *argp, *argn;
char         buffer[512];
l_int32      i, w, h, ignore;
l_float32    scale;
FILE        *fp;
PIX         *pixs, *pixt;
static char  mainName[] = "printimage";

    if (argc < 2 || argc > 4)
        return ERROR_INT(
            " Syntax:  printimage filein [-P<printer>] [-#<number>]",
            mainName, 1);

        /* parse args */
    filein = argv[1];
    argp = argn = NULL;
    if (argc > 2) {
        for (i = 2; i < argc; i++) {
            if (argv[i][1] == 'P')
                argp = argv[i];
            else if (argv[i][1] == '#')
                argn = argv[i];
        }
    }

    lept_rm(NULL, "print_image.ps");

    if ((pixs = pixRead(filein)) == NULL)
        return ERROR_INT("pixs not made", mainName, 1);

    pixGetDimensions(pixs, &w, &h, NULL);
    if (w > h) {
        pixt = pixRotate90(pixs, 1);
        pixGetDimensions(pixt, &w, &h, NULL);
    }
    else {
        pixt = pixClone(pixs);
    }
    scale = L_MIN(FILL_FACTOR * 2550 / w, FILL_FACTOR * 3300 / h);
    fname = genPathname("/tmp", "print_image.ps");
    fp = lept_fopen(fname, "wb+");
    pixWriteStreamPS(fp, pixt, NULL, 300, scale);
    lept_fclose(fp);

        /* print it out */
    if (argp && !argn) {
        sprintf(buffer, "lpr %s %s &", argp, fname);
        ignore = system(buffer);
    } else if (!argp && argn) {
        sprintf(buffer, "lpr %s %s &", argn, fname);
        ignore = system(buffer);
    } else if (argp && argn) {
        sprintf(buffer, "lpr %s %s %s &", argp, argn, fname);
        ignore = system(buffer);
    }

    lept_free(fname);
    pixDestroy(&pixs);
    pixDestroy(&pixt);
    return 0;
}
예제 #6
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);
}