src/psio1.c
l_int32
convertSegmentedPagesToPS(const char  *pagedir,
                          const char  *pagestr,
                          const char  *maskdir,
                          const char  *maskstr,
                          l_int32      numpre,
                          l_int32      numpost,
                          l_int32      maxnum,
                          l_float32    textscale,
                          l_float32    imagescale,
                          l_int32      threshold,
                          const char  *fileout)
{
l_int32  pageno, i, npages;
PIX     *pixs, *pixm;
SARRAY  *sapage, *samask;

    PROCNAME("convertSegmentedPagesToPS");

    if (!pagedir)
        return ERROR_INT("pagedir not defined", procName, 1);
    if (!maskdir)
        return ERROR_INT("maskdir not defined", procName, 1);
    if (!fileout)
        return ERROR_INT("fileout not defined", procName, 1);
    if (threshold <= 0) {
        L_INFO("setting threshold to 190", procName);
        threshold = 190;
    }

        /* Get numbered full pathnames; max size of sarray is maxnum */
    sapage = getNumberedPathnamesInDirectory(pagedir, pagestr,
                                             numpre, numpost, maxnum);
    samask = getNumberedPathnamesInDirectory(maskdir, maskstr,
                                             numpre, numpost, maxnum);
    sarrayPadToSameSize(sapage, samask, (char *)"");
    if ((npages = sarrayGetCount(sapage)) == 0) {
        sarrayDestroy(&sapage);
        sarrayDestroy(&samask);
        return ERROR_INT("no matching pages found", procName, 1);
    }

        /* Generate the PS file */
    pageno = 1;
    for (i = 0; i < npages; i++) {
        if ((pixs = pixReadIndexed(sapage, i)) == NULL)
            continue;
        pixm = pixReadIndexed(samask, i);
        pixWriteSegmentedPageToPS(pixs, pixm, textscale, imagescale,
                                  threshold, pageno, fileout);
        pixDestroy(&pixs);
        pixDestroy(&pixm);
        pageno++;
    }

    sarrayDestroy(&sapage);
    sarrayDestroy(&samask);
    return 0;
}
/*
 *  convertSegmentedPagesToPS()
 *
 *      Input:  pagedir (input page image directory)
 *              pagestr (<optional> substring filter on page filenames;
 *                       can be NULL)
 *              maskdir (input mask image directory)
 *              maskstr (<optional> substring filter on mask filenames;
 *                       can be NULL)
 *              numpre (number of characters in name before number)
 *              numpost (number of characters in name after number)
 *              maxnum (only consider page numbers up to this value)
 *              textscale (scale of text output relative to pixs)
 *              imagescale (scale of image output relative to pixs)
 *              threshold (for binarization; typ. about 190; 0 for default)
 *              fileout (output ps file)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) This generates a PS file for all page image and mask files in two
 *          specified directories and that contain the page numbers as
 *          specified below.  The two directories can be the same, in which
 *          case the page and mask files are differentiated by the two
 *          substrings for string matches.
 *      (2) The page images are taken in lexicographic order.
 *          Mask images whose numbers match the page images are used to
 *          segment the page images.  Page images without a matching 
 *          mask image are scaled, thresholded and rendered entirely as text.
 *      (3) Each PS page is generated as a compressed representation of
 *          the page image, where the part of the image under the mask
 *          is suitably scaled and compressed as DCT (i.e., jpeg), and
 *          the remaining part of the page is suitably scaled, thresholded,
 *          compressed as G4 (i.e., tiff g4), and rendered by painting
 *          black through the resulting text mask.
 *      (4) The scaling is typically 2x down for the DCT component
 *          (@imagescale = 0.5) and 2x up for the G4 component
 *          (@textscale = 2.0).
 *      (5) The resolution is automatically set to fit to a
 *          letter-size (8.5 x 11 inch) page.
 *      (6) Both the DCT and the G4 encoding are PostScript level 2.
 *      (7) It is assumed that the page number is contained within
 *          the basename (the filename without directory or extension).
 *          @numpre is the number of characters in the basename
 *          preceeding the actual page numer; @numpost is the number
 *          following the page number.  Note: the same numbers must be
 *          applied to both the page and mask image names.
 *      (8) To render a page as is -- that is, with no thresholding
 *          of any pixels -- use a mask in the mask directory that is
 *          full size with all pixels set to 1.  If the page is 1 bpp,
 *          it is not necessary to have a mask.
 */


(1) This generates a PS file for all page image and mask files in two
specified directories and that contain the page numbers as
specified below.  The two directories can be the same, in which
case the page and mask files are differentiated by the two
substrings for string matches.
(2) The page images are taken in lexicographic order.
Mask images whose numbers match the page images are used to
segment the page images.  Page images without a matching
mask image are scaled, thresholded and rendered entirely as text.
(3) Each PS page is generated as a compressed representation of
the page image, where the part of the image under the mask
is suitably scaled and compressed as DCT , and
the remaining part of the page is suitably scaled, thresholded,
compressed as G4 , and rendered by painting
black through the resulting text mask.
(4) The scaling is typically 2x down for the DCT component
(@imagescale = 0.5) and 2x up for the G4 component
(@textscale = 2.0).
(5) The resolution is automatically set to fit to a
letter-size (8.5 x 11 inch) page.
(6) Both the DCT and the G4 encoding are PostScript level 2.
(7) It is assumed that the page number is contained within
the basename (the filename without directory or extension).
@numpre is the number of characters in the basename
preceeding the actual page numer; @numpost is the number
following the page number.  Note: the same numbers must be
applied to both the page and mask image names.
(8) To render a page as is -- that is, with no thresholding
of any pixels -- use a mask in the mask directory that is
full size with all pixels set to 1.  If the page is 1 bpp,
it is not necessary to have a mask.
( 1 ) This generates a PS file for all page image and mask files in two specified directories and that contain the page numbers as specified below . The two directories can be the same in which case the page and mask files are differentiated by the two substrings for string matches . ( 2 ) The page images are taken in lexicographic order . Mask images whose numbers match the page images are used to segment the page images . Page images without a matching mask image are scaled thresholded and rendered entirely as text . ( 3 ) Each PS page is generated as a compressed representation of the page image where the part of the image under the mask is suitably scaled and compressed as DCT and the remaining part of the page is suitably scaled thresholded compressed as G4 and rendered by painting black through the resulting text mask . ( 4 ) The scaling is typically 2x down for the DCT component ( @imagescale = 0 . 5 ) and 2x up for the G4 component ( @textscale = 2 . 0 ) . ( 5 ) The resolution is automatically set to fit to a letter - size ( 8 . 5 x 11 inch ) page . ( 6 ) Both the DCT and the G4 encoding are PostScript level 2 . ( 7 ) It is assumed that the page number is contained within the basename ( the filename without directory or extension ) . @numpre is the number of characters in the basename preceeding the actual page numer ; @numpost is the number following the page number . Note : the same numbers must be applied to both the page and mask image names . ( 8 ) To render a page as is -- that is with no thresholding of any pixels -- use a mask in the mask directory that is full size with all pixels set to 1 . If the page is 1 bpp it is not necessary to have a mask .
l_int32
convertSegmentedPagesToPS(const char  *pagedir,
                          const char  *pagestr,
                          const char  *maskdir,
                          const char  *maskstr,
                          l_int32      numpre,
                          l_int32      numpost,
                          l_int32      maxnum,
                          l_float32    textscale,
                          l_float32    imagescale,
                          l_int32      threshold,
                          const char  *fileout)
{
l_int32  pageno, i, npages;
PIX     *pixs, *pixm;
SARRAY  *sapage, *samask;
    PROCNAME("convertSegmentedPagesToPS");
    if (!pagedir)
        return ERROR_INT("pagedir not defined", procName, 1);
    if (!maskdir)
        return ERROR_INT("maskdir not defined", procName, 1);
    if (!fileout)
        return ERROR_INT("fileout not defined", procName, 1);
    if (threshold <= 0) {
        L_INFO("setting threshold to 190", procName);
        threshold = 190;
    }
    sapage = getNumberedPathnamesInDirectory(pagedir, pagestr,
                                             numpre, numpost, maxnum);
    samask = getNumberedPathnamesInDirectory(maskdir, maskstr,
                                             numpre, numpost, maxnum);
    sarrayPadToSameSize(sapage, samask, (char *)"");
    if ((npages = sarrayGetCount(sapage)) == 0) {
        sarrayDestroy(&sapage);
        sarrayDestroy(&samask);
        return ERROR_INT("no matching pages found", procName, 1);
    }
    pageno = 1;
    for (i = 0; i < npages; i++) {
        if ((pixs = pixReadIndexed(sapage, i)) == NULL)
            continue;
        pixm = pixReadIndexed(samask, i);
        pixWriteSegmentedPageToPS(pixs, pixm, textscale, imagescale,
                                  threshold, pageno, fileout);
        pixDestroy(&pixs);
        pixDestroy(&pixm);
        pageno++;
    }
    sarrayDestroy(&sapage);
    sarrayDestroy(&samask);
    return 0;
}
l_int32 convertSegmentedPagesToPS ( const char * pagedir , const char * pagestr , const char * maskdir , const char * maskstr , l_int32 numpre , l_int32 numpost , l_int32 maxnum , l_float32 textscale , l_float32 imagescale , l_int32 threshold , const char * fileout ) { l_int32 pageno , i , npages ; PIX * pixs , * pixm ; SARRAY * sapage , * samask ; PROCNAME ( " " ) ; if ( ! pagedir ) return ERROR_INT ( " " , procName , 1 ) ; if ( ! maskdir ) return ERROR_INT ( " " , procName , 1 ) ; if ( ! fileout ) return ERROR_INT ( " " , procName , 1 ) ; if ( threshold <= 0 ) { L_INFO ( " " , procName ) ; threshold = 190 ; } sapage = getNumberedPathnamesInDirectory ( pagedir , pagestr , numpre , numpost , maxnum ) ; samask = getNumberedPathnamesInDirectory ( maskdir , maskstr , numpre , numpost , maxnum ) ; sarrayPadToSameSize ( sapage , samask , ( char * ) " " ) ; if ( ( npages = sarrayGetCount ( sapage ) ) == 0 ) { sarrayDestroy ( & sapage ) ; sarrayDestroy ( & samask ) ; return ERROR_INT ( " " , procName , 1 ) ; } pageno = 1 ; for ( i = 0 ; i < npages ; i ++ ) { if ( ( pixs = pixReadIndexed ( sapage , i ) ) == NULL ) continue ; pixm = pixReadIndexed ( samask , i ) ; pixWriteSegmentedPageToPS ( pixs , pixm , textscale , imagescale , threshold , pageno , fileout ) ; pixDestroy ( & pixs ) ; pixDestroy ( & pixm ) ; pageno ++ ; } sarrayDestroy ( & sapage ) ; sarrayDestroy ( & samask ) ; return 0 ; }
convertSegmentedPagesToPS()
      Input:  pagedir (input page image directory)
              pagestr (<optional> substring filter on page filenames;
                       can be NULL)
              maskdir (input mask image directory)
              maskstr (<optional> substring filter on mask filenames;
                       can be NULL)
              numpre (number of characters in name before number)
              numpost (number of characters in name after number)
              maxnum (only consider page numbers up to this value)
              textscale (scale of text output relative to pixs)
              imagescale (scale of image output relative to pixs)
              threshold (for binarization; typ.
convertSegmentedPagesToPS () Input : pagedir ( input page image directory ) pagestr ( <optional > substring filter on page filenames ; can be NULL ) maskdir ( input mask image directory ) maskstr ( <optional > substring filter on mask filenames ; can be NULL ) numpre ( number of characters in name before number ) numpost ( number of characters in name after number ) maxnum ( only consider page numbers up to this value ) textscale ( scale of text output relative to pixs ) imagescale ( scale of image output relative to pixs ) threshold ( for binarization ; typ .
/* Get numbered full pathnames; max size of sarray is maxnum */ /* Generate the PS file */