104 #include "allheaders.h" 150 convertFilesToPS(
const char *dirin,
157 PROCNAME(
"convertFilesToPS");
160 return ERROR_INT(
"dirin not defined", procName, 1);
162 return ERROR_INT(
"fileout not defined", procName, 1);
164 L_INFO(
"setting res to 300 ppi\n", procName);
167 if (res < 10 || res > 4000)
168 L_WARNING(
"res is typically in the range 300-600 ppi\n", procName);
174 l_psWriteBoundingBox(FALSE);
175 sarrayConvertFilesToPS(sa, res, fileout);
176 l_psWriteBoundingBox(TRUE);
194 sarrayConvertFilesToPS(
SARRAY *sa,
199 l_int32 i, nfiles, index, firstfile, ret, format;
201 PROCNAME(
"sarrayConvertFilesToPS");
204 return ERROR_INT(
"sa not defined", procName, 1);
206 return ERROR_INT(
"fileout not defined", procName, 1);
208 L_INFO(
"setting res to 300 ppi\n", procName);
211 if (res < 10 || res > 4000)
212 L_WARNING(
"res is typically in the range 300-600 ppi\n", procName);
216 for (i = 0, index = 0; i < nfiles; i++) {
218 ret =
pixReadHeader(fname, &format, NULL, NULL, NULL, NULL, NULL);
220 if (format == IFF_UNKNOWN)
223 writeImageCompressedToPSFile(fname, fileout, res, &firstfile, &index);
259 convertFilesFittedToPS(
const char *dirin,
267 PROCNAME(
"convertFilesFittedToPS");
270 return ERROR_INT(
"dirin not defined", procName, 1);
272 return ERROR_INT(
"fileout not defined", procName, 1);
274 L_INFO(
"setting xpts to 612.0 ppi\n", procName);
278 L_INFO(
"setting ypts to 792.0 ppi\n", procName);
281 if (xpts < 100.0 || xpts > 2000.0 || ypts < 100.0 || ypts > 2000.0)
282 L_WARNING(
"xpts,ypts are typically in the range 500-800\n", procName);
288 l_psWriteBoundingBox(FALSE);
289 sarrayConvertFilesFittedToPS(sa, xpts, ypts, fileout);
290 l_psWriteBoundingBox(TRUE);
308 sarrayConvertFilesFittedToPS(
SARRAY *sa,
314 l_int32 ret, i, w, h, nfiles, index, firstfile, format, res;
316 PROCNAME(
"sarrayConvertFilesFittedToPS");
319 return ERROR_INT(
"sa not defined", procName, 1);
321 return ERROR_INT(
"fileout not defined", procName, 1);
323 L_INFO(
"setting xpts to 612.0\n", procName);
327 L_INFO(
"setting ypts to 792.0\n", procName);
330 if (xpts < 100.0 || xpts > 2000.0 || ypts < 100.0 || ypts > 2000.0)
331 L_WARNING(
"xpts,ypts are typically in the range 500-800\n", procName);
335 for (i = 0, index = 0; i < nfiles; i++) {
337 ret =
pixReadHeader(fname, &format, &w, &h, NULL, NULL, NULL);
339 if (format == IFF_UNKNOWN)
343 if (xpts * h < ypts * w)
344 res = (l_int32)((l_float32)w * 72.0 / xpts);
346 res = (l_int32)((l_float32)h * 72.0 / ypts);
348 writeImageCompressedToPSFile(fname, fileout, res, &firstfile, &index);
377 writeImageCompressedToPSFile(
const char *filein,
384 l_int32 format, retval;
386 PROCNAME(
"writeImageCompressedToPSFile");
388 if (!pfirstfile || !pindex)
389 return ERROR_INT(
"&firstfile and &index not defined", procName, 1);
392 if (format == IFF_UNKNOWN) {
393 L_ERROR(
"format of %s not known\n", procName, filein);
397 op = (*pfirstfile == TRUE) ?
"w" :
"a";
398 if (format == IFF_JFIF_JPEG) {
400 res, 1.0, *pindex + 1, TRUE);
405 }
else if (format == IFF_TIFF_G4) {
407 res, 1.0, *pindex + 1, FALSE, TRUE);
414 res, 1.0, *pindex + 1, TRUE);
482 convertSegmentedPagesToPS(
const char *pagedir,
491 l_float32 imagescale,
495 l_int32 pageno, i, npages;
499 PROCNAME(
"convertSegmentedPagesToPS");
502 return ERROR_INT(
"pagedir not defined", procName, 1);
504 return ERROR_INT(
"maskdir not defined", procName, 1);
506 return ERROR_INT(
"fileout not defined", procName, 1);
507 if (threshold <= 0) {
508 L_INFO(
"setting threshold to 190\n", procName);
514 page_numpre, numpost, maxnum);
516 mask_numpre, numpost, maxnum);
521 return ERROR_INT(
"no matching pages found", procName, 1);
526 for (i = 0; i < npages; i++) {
530 pixWriteSegmentedPageToPS(pixs, pixm, textscale, imagescale,
531 threshold, pageno, fileout);
578 pixWriteSegmentedPageToPS(
PIX *pixs,
581 l_float32 imagescale,
586 l_int32 alltext, notext, d, ret;
588 l_float32 scaleratio;
589 PIX *pixmi, *pixmis, *pixt, *pixg, *pixsc, *pixb, *pixc;
591 PROCNAME(
"pixWriteSegmentedPageToPS");
594 return ERROR_INT(
"pixs not defined", procName, 1);
596 return ERROR_INT(
"fileout not defined", procName, 1);
597 if (imagescale <= 0.0 || textscale <= 0.0)
598 return ERROR_INT(
"relative scales must be > 0.0", procName, 1);
616 scaleratio = textscale / imagescale;
620 if (pixGetDepth(pixs) == 1) {
629 if (notext == FALSE) {
630 d = pixGetDepth(pixt);
637 if (textscale == 1.0)
639 else if (textscale >= 0.7)
651 if (imagescale == 1.0)
654 pixsc =
pixScale(pixt, imagescale, imagescale);
665 if (notext == FALSE) {
666 pixmis =
pixScale(pixm, imagescale, imagescale);
668 val = (d == 8) ? 0xff : 0xffffff00;
682 l_psWriteBoundingBox(FALSE);
683 ret = pixWriteMixedToPS(pixb, pixc, scaleratio, pageno, fileout);
684 l_psWriteBoundingBox(TRUE);
727 pixWriteMixedToPS(
PIX *pixb,
735 l_int32 resb, resc, endpage, maskop, ret;
737 PROCNAME(
"pixWriteMixedToPS");
740 return ERROR_INT(
"pixb and pixc both undefined", procName, 1);
742 return ERROR_INT(
"fileout not defined", procName, 1);
750 resb = (l_int32)(scale * resc);
755 tname = l_makeTempFilename();
756 pixWrite(tname, pixc, IFF_JFIF_JPEG);
757 endpage = (pixb) ? FALSE : TRUE;
758 op = (pageno <= 1) ?
"w" :
"a";
764 return ERROR_INT(
"jpeg data not written", procName, 1);
770 tname = l_makeTempFilename();
771 pixWrite(tname, pixb, IFF_TIFF_G4);
772 op = (pageno <= 1 && !pixc) ?
"w" :
"a";
773 maskop = (pixc) ? 1 : 0;
779 return ERROR_INT(
"tiff data not written", procName, 1);
812 convertToPSEmbed(
const char *filein,
820 PROCNAME(
"convertToPSEmbed");
823 return ERROR_INT(
"filein not defined", procName, 1);
825 return ERROR_INT(
"fileout not defined", procName, 1);
826 if (level != 1 && level != 2 && level != 3) {
827 L_ERROR(
"invalid level specified; using level 2\n", procName);
838 if (format == IFF_JFIF_JPEG) {
841 }
else if (format == IFF_TIFF_G4) {
844 }
else if (format == IFF_UNKNOWN) {
845 L_ERROR(
"format of %s not known\n", procName, filein);
856 if ((pixs =
pixRead(filein)) == NULL)
857 return ERROR_INT(
"image not read from file", procName, 1);
858 d = pixGetDepth(pixs);
859 if ((d == 2 || d == 4) && !pixGetColormap(pixs))
866 d = pixGetDepth(pix);
867 tname = l_makeTempFilename();
869 pixWrite(tname, pix, IFF_TIFF_G4);
872 pixWrite(tname, pix, IFF_JFIF_JPEG);
911 pixaWriteCompressedToPS(
PIXA *pixa,
917 l_int32 i, n, firstfile, index, writeout, d;
921 PROCNAME(
"pixaWriteCompressedToPS");
924 return ERROR_INT(
"pixa not defined", procName, 1);
926 return ERROR_INT(
"fileout not defined", procName, 1);
927 if (level != 2 && level != 3) {
928 L_ERROR(
"only levels 2 and 3 permitted; using level 2\n", procName);
935 tname = l_makeTempFilename();
936 for (i = 0; i < n; i++) {
939 d = pixGetDepth(pix);
940 cmap = pixGetColormap(pix);
942 pixWrite(tname, pix, IFF_TIFF_G4);
946 pixWrite(tname, pixt, IFF_JFIF_JPEG);
949 pixWrite(tname, pix, IFF_PNG);
951 }
else if (d == 16) {
953 L_WARNING(
"d = 16; must write out flate\n", procName);
954 pixWrite(tname, pix, IFF_PNG);
955 }
else if (d == 2 || d == 4) {
958 pixWrite(tname, pixt, IFF_JFIF_JPEG);
961 pixWrite(tname, pix, IFF_PNG);
963 }
else if (d == 8 || d == 32) {
964 pixWrite(tname, pix, IFF_JFIF_JPEG);
966 L_ERROR(
"invalid depth: %d\n", procName, d);
972 writeImageCompressedToPSFile(tname, fileout, res,
PIX * pixConvertRGBToLuminance(PIX *pixs)
pixConvertRGBToLuminance()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
l_int32 pixWritePSEmbed(const char *filein, const char *fileout)
pixWritePSEmbed()
l_int32 pixZero(PIX *pix, l_int32 *pempty)
pixZero()
l_int32 pixSetMasked(PIX *pixd, PIX *pixm, l_uint32 val)
pixSetMasked()
PIX * pixReadIndexed(SARRAY *sa, l_int32 index)
pixReadIndexed()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
l_int32 convertJpegToPSEmbed(const char *filein, const char *fileout)
convertJpegToPSEmbed()
PIX * pixScaleAreaMap(PIX *pix, l_float32 scalex, l_float32 scaley)
pixScaleAreaMap()
PIX * pixInvert(PIX *pixd, PIX *pixs)
pixInvert()
PIX * pixThresholdToBinary(PIX *pixs, l_int32 thresh)
pixThresholdToBinary()
l_int32 convertFlateToPS(const char *filein, const char *fileout, const char *operation, l_int32 x, l_int32 y, l_int32 res, l_float32 scale, l_int32 pageno, l_int32 endpage)
convertFlateToPS()
l_int32 convertJpegToPS(const char *filein, const char *fileout, const char *operation, l_int32 x, l_int32 y, l_int32 res, l_float32 scale, l_int32 pageno, l_int32 endpage)
convertJpegToPS()
l_int32 findFileFormat(const char *filename, l_int32 *pformat)
findFileFormat()
SARRAY * getNumberedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 numpre, l_int32 numpost, l_int32 maxnum)
getNumberedPathnamesInDirectory()
l_int32 pixReadHeader(const char *filename, l_int32 *pformat, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *piscmap)
pixReadHeader()
l_int32 convertFlateToPSEmbed(const char *filein, const char *fileout)
convertFlateToPSEmbed()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_int32 getResLetterPage(l_int32 w, l_int32 h, l_float32 fillfract)
getResLetterPage()
PIX * pixClone(PIX *pixs)
pixClone()
void pixDestroy(PIX **ppix)
pixDestroy()
l_int32 convertG4ToPSEmbed(const char *filein, const char *fileout)
convertG4ToPSEmbed()
SARRAY * getSortedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
getSortedPathnamesInDirectory()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
PIX * pixScaleGrayLI(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleGrayLI()
PIX * pixRead(const char *filename)
pixRead()
PIX * pixConvertForPSWrap(PIX *pixs)
pixConvertForPSWrap()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
PIX * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
l_int32 convertG4ToPS(const char *filein, const char *fileout, const char *operation, l_int32 x, l_int32 y, l_int32 res, l_float32 scale, l_int32 pageno, l_int32 maskflag, l_int32 endpage)
convertG4ToPS()
PIX * pixConvert16To8(PIX *pixs, l_int32 type)
pixConvert16To8()
l_int32 sarrayPadToSameSize(SARRAY *sa1, SARRAY *sa2, char *padstring)
sarrayPadToSameSize()
PIX * pixScale(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScale()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
PIX * pixConvertTo8Or32(PIX *pixs, l_int32 copyflag, l_int32 warnflag)
pixConvertTo8Or32()
l_int32 lept_rmfile(const char *filepath)
lept_rmfile()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()