111 #include <config_auto.h> 115 #include "allheaders.h" 163 convertFilesToPS(
const char *dirin,
170 PROCNAME(
"convertFilesToPS");
173 return ERROR_INT(
"dirin not defined", procName, 1);
175 return ERROR_INT(
"fileout not defined", procName, 1);
177 L_INFO(
"setting res to 300 ppi\n", procName);
180 if (res < 10 || res > 4000)
181 L_WARNING(
"res is typically in the range 300-600 ppi\n", procName);
187 l_psWriteBoundingBox(FALSE);
188 sarrayConvertFilesToPS(sa, res, fileout);
189 l_psWriteBoundingBox(TRUE);
210 sarrayConvertFilesToPS(
SARRAY *sa,
215 l_int32 i, nfiles, index, ret, format;
217 PROCNAME(
"sarrayConvertFilesToPS");
220 return ERROR_INT(
"sa not defined", procName, 1);
222 return ERROR_INT(
"fileout not defined", procName, 1);
224 L_INFO(
"setting res to 300 ppi\n", procName);
227 if (res < 10 || res > 4000)
228 L_WARNING(
"res is typically in the range 300-600 ppi\n", procName);
231 for (i = 0, index = 0; i < nfiles; i++) {
233 ret =
pixReadHeader(fname, &format, NULL, NULL, NULL, NULL, NULL);
235 if (format == IFF_UNKNOWN)
238 writeImageCompressedToPSFile(fname, fileout, res, &index);
277 convertFilesFittedToPS(
const char *dirin,
285 PROCNAME(
"convertFilesFittedToPS");
288 return ERROR_INT(
"dirin not defined", procName, 1);
290 return ERROR_INT(
"fileout not defined", procName, 1);
292 L_INFO(
"setting xpts to 612.0 ppi\n", procName);
296 L_INFO(
"setting ypts to 792.0 ppi\n", procName);
299 if (xpts < 100.0 || xpts > 2000.0 || ypts < 100.0 || ypts > 2000.0)
300 L_WARNING(
"xpts,ypts are typically in the range 500-800\n", procName);
306 l_psWriteBoundingBox(FALSE);
307 sarrayConvertFilesFittedToPS(sa, xpts, ypts, fileout);
308 l_psWriteBoundingBox(TRUE);
329 sarrayConvertFilesFittedToPS(
SARRAY *sa,
335 l_int32 ret, i, w, h, nfiles, index, format, res;
337 PROCNAME(
"sarrayConvertFilesFittedToPS");
340 return ERROR_INT(
"sa not defined", procName, 1);
342 return ERROR_INT(
"fileout not defined", procName, 1);
344 L_INFO(
"setting xpts to 612.0\n", procName);
348 L_INFO(
"setting ypts to 792.0\n", procName);
351 if (xpts < 100.0 || xpts > 2000.0 || ypts < 100.0 || ypts > 2000.0)
352 L_WARNING(
"xpts,ypts are typically in the range 500-800\n", procName);
355 for (i = 0, index = 0; i < nfiles; i++) {
357 ret =
pixReadHeader(fname, &format, &w, &h, NULL, NULL, NULL);
359 if (format == IFF_UNKNOWN)
363 if (xpts * h < ypts * w)
364 res = (l_int32)((l_float32)w * 72.0 / xpts);
366 res = (l_int32)((l_float32)h * 72.0 / ypts);
368 writeImageCompressedToPSFile(fname, fileout, res, &index);
397 writeImageCompressedToPSFile(
const char *filein,
403 l_int32 format, retval;
405 PROCNAME(
"writeImageCompressedToPSFile");
408 return ERROR_INT(
"&index not defined", procName, 1);
411 if (format == IFF_UNKNOWN) {
412 L_ERROR(
"format of %s not known\n", procName, filein);
416 op = (*pindex == 0) ?
"w" :
"a";
417 if (format == IFF_JFIF_JPEG) {
419 res, 1.0, *pindex + 1, TRUE);
420 }
else if (format == IFF_TIFF_G4) {
422 res, 1.0, *pindex + 1, FALSE, TRUE);
425 res, 1.0, *pindex + 1, TRUE);
427 if (retval == 0) (*pindex)++;
492 convertSegmentedPagesToPS(
const char *pagedir,
501 l_float32 imagescale,
505 l_int32 pageno, i, npages;
509 PROCNAME(
"convertSegmentedPagesToPS");
512 return ERROR_INT(
"pagedir not defined", procName, 1);
514 return ERROR_INT(
"maskdir not defined", procName, 1);
516 return ERROR_INT(
"fileout not defined", procName, 1);
517 if (threshold <= 0) {
518 L_INFO(
"setting threshold to 190\n", procName);
524 page_numpre, numpost, maxnum);
526 mask_numpre, numpost, maxnum);
531 return ERROR_INT(
"no matching pages found", procName, 1);
536 for (i = 0; i < npages; i++) {
540 pixWriteSegmentedPageToPS(pixs, pixm, textscale, imagescale,
541 threshold, pageno, fileout);
590 pixWriteSegmentedPageToPS(
PIX *pixs,
593 l_float32 imagescale,
598 l_int32 alltext, notext, d, ret;
600 l_float32 scaleratio;
601 PIX *pixmi, *pixmis, *pixt, *pixg, *pixsc, *pixb, *pixc;
603 PROCNAME(
"pixWriteSegmentedPageToPS");
606 return ERROR_INT(
"pixs not defined", procName, 1);
608 return ERROR_INT(
"fileout not defined", procName, 1);
609 if (imagescale <= 0.0 || textscale <= 0.0)
610 return ERROR_INT(
"relative scales must be > 0.0", procName, 1);
628 scaleratio = textscale / imagescale;
632 if (pixGetDepth(pixs) == 1) {
641 if (notext == FALSE) {
642 d = pixGetDepth(pixt);
649 if (textscale == 1.0)
651 else if (textscale >= 0.7)
663 if (imagescale == 1.0)
666 pixsc =
pixScale(pixt, imagescale, imagescale);
677 if (notext == FALSE) {
678 pixmis =
pixScale(pixm, imagescale, imagescale);
680 val = (d == 8) ? 0xff : 0xffffff00;
694 l_psWriteBoundingBox(FALSE);
695 ret = pixWriteMixedToPS(pixb, pixc, scaleratio, pageno, fileout);
696 l_psWriteBoundingBox(TRUE);
741 pixWriteMixedToPS(
PIX *pixb,
749 l_int32 resb, resc, endpage, maskop, ret;
751 PROCNAME(
"pixWriteMixedToPS");
754 return ERROR_INT(
"pixb and pixc both undefined", procName, 1);
756 return ERROR_INT(
"fileout not defined", procName, 1);
764 resb = (l_int32)(scale * resc);
770 pixWrite(tname, pixc, IFF_JFIF_JPEG);
771 endpage = (pixb) ? FALSE : TRUE;
772 op = (pageno <= 1) ?
"w" :
"a";
778 return ERROR_INT(
"jpeg data not written", procName, 1);
785 pixWrite(tname, pixb, IFF_TIFF_G4);
786 op = (pageno <= 1 && !pixc) ?
"w" :
"a";
787 maskop = (pixc) ? 1 : 0;
793 return ERROR_INT(
"tiff data not written", procName, 1);
828 convertToPSEmbed(
const char *filein,
836 PROCNAME(
"convertToPSEmbed");
839 return ERROR_INT(
"filein not defined", procName, 1);
841 return ERROR_INT(
"fileout not defined", procName, 1);
842 if (level != 1 && level != 2 && level != 3) {
843 L_ERROR(
"invalid level specified; using level 2\n", procName);
854 if (format == IFF_JFIF_JPEG) {
857 }
else if (format == IFF_TIFF_G4) {
860 }
else if (format == IFF_UNKNOWN) {
861 L_ERROR(
"format of %s not known\n", procName, filein);
872 if ((pixs =
pixRead(filein)) == NULL)
873 return ERROR_INT(
"image not read from file", procName, 1);
874 d = pixGetDepth(pixs);
875 if ((d == 2 || d == 4) && !pixGetColormap(pixs))
883 return ERROR_INT(
"converted pix not made", procName, 1);
885 d = pixGetDepth(pix);
888 if (pixWrite(tname, pix, IFF_TIFF_G4)) {
891 return ERROR_INT(
"g4 tiff not written", procName, 1);
895 if (pixWrite(tname, pix, IFF_JFIF_JPEG)) {
898 return ERROR_INT(
"jpeg not written", procName, 1);
932 pixaWriteCompressedToPS(
PIXA *pixa,
937 l_int32 i, n, index, ret;
940 PROCNAME(
"pixaWriteCompressedToPS");
943 return ERROR_INT(
"pixa not defined", procName, 1);
945 return ERROR_INT(
"fileout not defined", procName, 1);
946 if (level != 2 && level != 3) {
947 L_ERROR(
"only levels 2 and 3 permitted; using level 2\n", procName);
953 for (i = 0; i < n; i++) {
955 ret = pixWriteCompressedToPS(pix, fileout, res, level, &index);
956 if (ret) L_ERROR(
"PS string not written for image %d\n", procName, i);
1006 pixWriteCompressedToPS(
PIX *pix,
1007 const char *fileout,
1013 l_int32 writeout, d;
1017 PROCNAME(
"pixWriteCompressedToPS");
1020 return ERROR_INT(
"pix not defined", procName, 1);
1022 return ERROR_INT(
"fileout not defined", procName, 1);
1023 if (level != 2 && level != 3) {
1024 L_ERROR(
"only levels 2 and 3 permitted; using level 2\n", procName);
1028 return ERROR_INT(
"&index not defined", procName, 1);
1032 d = pixGetDepth(pix);
1033 cmap = pixGetColormap(pix);
1035 if (pixWrite(tname, pix, IFF_TIFF_G4))
1037 }
else if (level == 3) {
1038 if (pixWrite(tname, pix, IFF_PNG))
1043 if (pixWrite(tname, pixt, IFF_JFIF_JPEG))
1046 }
else if (d == 16) {
1047 L_WARNING(
"d = 16; converting to 8 bpp for jpeg\n", procName);
1049 if (pixWrite(tname, pixt, IFF_JFIF_JPEG))
1052 }
else if (d == 2 || d == 4) {
1054 if (pixWrite(tname, pixt, IFF_JFIF_JPEG))
1057 }
else if (d == 8 || d == 32) {
1058 if (pixWrite(tname, pix, IFF_JFIF_JPEG))
1061 L_ERROR(
"invalid depth with level 2: %d\n", procName, d);
1067 writeImageCompressedToPSFile(tname, fileout, res, pindex);
1070 L_ERROR(
"temp file %s was not deleted\n", procName, tname);
1072 return (writeout) ? 0 : 1;
PIX * pixConvertRGBToLuminance(PIX *pixs)
pixConvertRGBToLuminance()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
l_ok pixSetMasked(PIX *pixd, PIX *pixm, l_uint32 val)
pixSetMasked()
char * l_makeTempFilename(void)
l_makeTempFilename()
PIX * pixReadIndexed(SARRAY *sa, l_int32 index)
pixReadIndexed()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
l_ok convertJpegToPSEmbed(const char *filein, const char *fileout)
convertJpegToPSEmbed()
PIX * pixScaleAreaMap(PIX *pix, l_float32 scalex, l_float32 scaley)
pixScaleAreaMap()
l_ok convertFlateToPSEmbed(const char *filein, const char *fileout)
convertFlateToPSEmbed()
PIX * pixInvert(PIX *pixd, PIX *pixs)
pixInvert()
l_ok pixWritePSEmbed(const char *filein, const char *fileout)
pixWritePSEmbed()
PIX * pixThresholdToBinary(PIX *pixs, l_int32 thresh)
pixThresholdToBinary()
l_ok sarrayPadToSameSize(SARRAY *sa1, SARRAY *sa2, const char *padstring)
sarrayPadToSameSize()
SARRAY * getNumberedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 numpre, l_int32 numpost, l_int32 maxnum)
getNumberedPathnamesInDirectory()
l_ok convertG4ToPSEmbed(const char *filein, const char *fileout)
convertG4ToPSEmbed()
l_ok 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_ok findFileFormat(const char *filename, l_int32 *pformat)
findFileFormat()
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()
l_ok 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()
void pixDestroy(PIX **ppix)
pixDestroy()
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()
l_ok pixZero(PIX *pix, l_int32 *pempty)
pixZero()
l_ok 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()
PIX * pixConvert16To8(PIX *pixs, l_int32 type)
pixConvert16To8()
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_ok 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 lept_rmfile(const char *filepath)
lept_rmfile()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()