src/psio1.c
l_int32
pixWriteMixedToPS(PIX         *pixb,
                  PIX         *pixc,
                  l_float32    scale,
                  l_int32      pageno,
                  const char  *fileout)
{
const char   tnameb[] = "/tmp/junk_pix_write_mixed.tif";
const char   tnamec[] = "/tmp/junk_pix_write_mixed.jpg";
const char  *op;
l_int32      resb, resc, endpage, maskop, ret;

    PROCNAME("pixWriteMixedToPS");

    if (!pixb && !pixc)
        return ERROR_INT("pixb and pixc both undefined", procName, 1);
    if (!fileout)
        return ERROR_INT("fileout not defined", procName, 1);

        /* Compute the resolution that fills a letter-size page. */
    if (!pixc)
       resb = getResLetterPage(pixGetWidth(pixb), pixGetHeight(pixb), 0);
    else {
       resc = getResLetterPage(pixGetWidth(pixc), pixGetHeight(pixc), 0);
       if (pixb)
           resb = (l_int32)(scale * resc);
    }

        /* Write the jpeg image first */
    if (pixc) {
        pixWrite(tnamec, pixc, IFF_JFIF_JPEG);
        endpage = (pixb) ? FALSE : TRUE;
        op = (pageno <= 1) ? "w" : "a";
        ret = convertJpegToPS(tnamec, fileout, op, 0, 0, resc, 1.0,
                              pageno, endpage);
        if (ret)
            return ERROR_INT("jpeg data not written", procName, 1);
    }

        /* Write the binary data, either directly or, if there is
         * a jpeg image on the page, through the mask. */
    if (pixb) {
        pixWrite(tnameb, pixb, IFF_TIFF_G4);
        op = (pageno <= 1 && !pixc) ? "w" : "a";
        maskop = (pixc) ? 1 : 0;
        ret = convertG4ToPS(tnameb, fileout, op, 0, 0, resb, 1.0,
                            pageno, maskop, 1);
        if (ret)
            return ERROR_INT("tiff data not written", procName, 1);
    }

    return 0;
}
/*
 *  pixWriteMixedToPS()
 *
 *      Input:  pixb (<optionall> 1 bpp "mask"; typically for text)
 *              pixc (<optional> 8 or 32 bpp image regions)
 *              scale (relative scale factor for rendering pixb
 *                    relative to pixc; typ. 4.0)
 *              pageno (page number in set; use 1 for new output file)
 *              fileout (output ps file)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) This low level function generates the PS string for a mixed
 *          text/image page, and adds it to an existing file if
 *          @pageno > 1.
 *      (2) The two images (pixb and pixc) are typically generated at the
 *          resolution that they will be rendered in the PS file.
 *      (3) pixb is the text component.  In the PostScript world, we think of
 *          it as a mask through which we paint black.
 *      (4) pixc is the (typically halftone) image component.  It is
 *          white in the rest of the page.  To minimize the size of the
 *          PS file, it should be rendered at a resolution that is at
 *          least equal to its actual resolution.
 *      (5) @scale gives the ratio of resolution of pixb to pixc.
 *          Typical resolutions are: 600 ppi for pixb, 150 ppi for pixc;
 *          so @scale = 4.0.  If one of the images is not defined,
 *          the value of @scale is ignored.
 *      (6) We write pixc with DCT compression (jpeg).  This is followed
 *          by painting the text as black through the mask pixb.  If
 *          pixc doesn't exist (alltext), we write the text with the
 *          PS "image" operator instead of the "imagemask" operator,
 *          because ghostscript's ps2pdf is flaky when the latter is used.
 *      (7) The actual output resolution is determined by fitting the
 *          result to a letter-size (8.5 x 11 inch) page.
 */
pixWriteMixedToPS()
Input:  pixb ( 1 bpp "mask"; typically for text)
pixc ( 8 or 32 bpp image regions)
scale (relative scale factor for rendering pixb
relative to pixc; typ. 4.0)
pageno (page number in set; use 1 for new output file)
fileout (output ps file)
Return: 0 if OK, 1 on error

(1) This low level function generates the PS string for a mixed
text/image page, and adds it to an existing file if
@pageno > 1.
(2) The two images (pixb and pixc) are typically generated at the
resolution that they will be rendered in the PS file.
(3) pixb is the text component.  In the PostScript world, we think of
it as a mask through which we paint black.
(4) pixc is the (typically halftone) image component.  It is
white in the rest of the page.  To minimize the size of the
PS file, it should be rendered at a resolution that is at
least equal to its actual resolution.
(5) @scale gives the ratio of resolution of pixb to pixc.
Typical resolutions are: 600 ppi for pixb, 150 ppi for pixc;
so @scale = 4.0.  If one of the images is not defined,
the value of @scale is ignored.
(6) We write pixc with DCT compression (jpeg).  This is followed
by painting the text as black through the mask pixb.  If
pixc doesn't exist (alltext), we write the text with the
PS "image" operator instead of the "imagemask" operator,
because ghostscript's ps2pdf is flaky when the latter is used.
(7) The actual output resolution is determined by fitting the
result to a letter-size (8.5 x 11 inch) page.
pixWriteMixedToPS () Input : pixb ( 1 bpp " mask " ; typically for text ) pixc ( 8 or 32 bpp image regions ) scale ( relative scale factor for rendering pixb relative to pixc ; typ . 4 . 0 ) pageno ( page number in set ; use 1 for new output file ) fileout ( output ps file ) Return : 0 if OK 1 on error ( 1 ) This low level function generates the PS string for a mixed text / image page and adds it to an existing file if @pageno > 1 . ( 2 ) The two images ( pixb and pixc ) are typically generated at the resolution that they will be rendered in the PS file . ( 3 ) pixb is the text component . In the PostScript world we think of it as a mask through which we paint black . ( 4 ) pixc is the ( typically halftone ) image component . It is white in the rest of the page . To minimize the size of the PS file it should be rendered at a resolution that is at least equal to its actual resolution . ( 5 ) @scale gives the ratio of resolution of pixb to pixc . Typical resolutions are : 600 ppi for pixb 150 ppi for pixc ; so @scale = 4 . 0 . If one of the images is not defined the value of @scale is ignored . ( 6 ) We write pixc with DCT compression ( jpeg ) . This is followed by painting the text as black through the mask pixb . If pixc doesn ' t exist ( alltext ) we write the text with the PS " image " operator instead of the " imagemask " operator because ghostscript ' s ps2pdf is flaky when the latter is used . ( 7 ) The actual output resolution is determined by fitting the result to a letter - size ( 8 . 5 x 11 inch ) page .
l_int32
pixWriteMixedToPS(PIX         *pixb,
                  PIX         *pixc,
                  l_float32    scale,
                  l_int32      pageno,
                  const char  *fileout)
{
const char   tnameb[] = "/tmp/junk_pix_write_mixed.tif";
const char   tnamec[] = "/tmp/junk_pix_write_mixed.jpg";
const char  *op;
l_int32      resb, resc, endpage, maskop, ret;
    PROCNAME("pixWriteMixedToPS");
    if (!pixb && !pixc)
        return ERROR_INT("pixb and pixc both undefined", procName, 1);
    if (!fileout)
        return ERROR_INT("fileout not defined", procName, 1);
    if (!pixc)
       resb = getResLetterPage(pixGetWidth(pixb), pixGetHeight(pixb), 0);
    else {
       resc = getResLetterPage(pixGetWidth(pixc), pixGetHeight(pixc), 0);
       if (pixb)
           resb = (l_int32)(scale * resc);
    }
    if (pixc) {
        pixWrite(tnamec, pixc, IFF_JFIF_JPEG);
        endpage = (pixb) ? FALSE : TRUE;
        op = (pageno <= 1) ? "w" : "a";
        ret = convertJpegToPS(tnamec, fileout, op, 0, 0, resc, 1.0,
                              pageno, endpage);
        if (ret)
            return ERROR_INT("jpeg data not written", procName, 1);
    }
    if (pixb) {
        pixWrite(tnameb, pixb, IFF_TIFF_G4);
        op = (pageno <= 1 && !pixc) ? "w" : "a";
        maskop = (pixc) ? 1 : 0;
        ret = convertG4ToPS(tnameb, fileout, op, 0, 0, resb, 1.0,
                            pageno, maskop, 1);
        if (ret)
            return ERROR_INT("tiff data not written", procName, 1);
    }
    return 0;
}
l_int32 pixWriteMixedToPS ( PIX * pixb , PIX * pixc , l_float32 scale , l_int32 pageno , const char * fileout ) { const char tnameb [ ] = " " ; const char tnamec [ ] = " " ; const char * op ; l_int32 resb , resc , endpage , maskop , ret ; PROCNAME ( " " ) ; if ( ! pixb && ! pixc ) return ERROR_INT ( " " , procName , 1 ) ; if ( ! fileout ) return ERROR_INT ( " " , procName , 1 ) ; if ( ! pixc ) resb = getResLetterPage ( pixGetWidth ( pixb ) , pixGetHeight ( pixb ) , 0 ) ; else { resc = getResLetterPage ( pixGetWidth ( pixc ) , pixGetHeight ( pixc ) , 0 ) ; if ( pixb ) resb = ( l_int32 ) ( scale * resc ) ; } if ( pixc ) { pixWrite ( tnamec , pixc , IFF_JFIF_JPEG ) ; endpage = ( pixb ) ? FALSE : TRUE ; op = ( pageno <= 1 ) ? " " : " " ; ret = convertJpegToPS ( tnamec , fileout , op , 0 , 0 , resc , 1.0 , pageno , endpage ) ; if ( ret ) return ERROR_INT ( " " , procName , 1 ) ; } if ( pixb ) { pixWrite ( tnameb , pixb , IFF_TIFF_G4 ) ; op = ( pageno <= 1 && ! pixc ) ? " " : " " ; maskop = ( pixc ) ? 1 : 0 ; ret = convertG4ToPS ( tnameb , fileout , op , 0 , 0 , resb , 1.0 , pageno , maskop , 1 ) ; if ( ret ) return ERROR_INT ( " " , procName , 1 ) ; } return 0 ; }
pixWriteMixedToPS()
      Input:  pixb (<optionall> 1 bpp "mask"; typically for text)
              pixc (<optional> 8 or 32 bpp image regions)
              scale (relative scale factor for rendering pixb
                    relative to pixc; typ.
pixWriteMixedToPS () Input : pixb ( <optionall > 1 bpp " mask " ; typically for text ) pixc ( <optional > 8 or 32 bpp image regions ) scale ( relative scale factor for rendering pixb relative to pixc ; typ .
/* Compute the resolution that fills a letter-size page. */ /* Write the jpeg image first */ /* Write the binary data, either directly or, if there is
         * a jpeg image on the page, through the mask. */