111 #include <config_auto.h>
115 #include "allheaders.h"
163 convertFilesToPS(
const char *dirin,
171 return ERROR_INT(
"dirin not defined", __func__, 1);
173 return ERROR_INT(
"fileout not defined", __func__, 1);
175 L_INFO(
"setting res to 300 ppi\n", __func__);
178 if (res < 10 || res > 4000)
179 L_WARNING(
"res is typically in the range 300-600 ppi\n", __func__);
185 l_psWriteBoundingBox(FALSE);
186 sarrayConvertFilesToPS(sa, res, fileout);
187 l_psWriteBoundingBox(TRUE);
208 sarrayConvertFilesToPS(
SARRAY *sa,
213 l_int32 i, nfiles, index, ret, format;
216 return ERROR_INT(
"sa not defined", __func__, 1);
218 return ERROR_INT(
"fileout not defined", __func__, 1);
220 L_INFO(
"setting res to 300 ppi\n", __func__);
223 if (res < 10 || res > 4000)
224 L_WARNING(
"res is typically in the range 300-600 ppi\n", __func__);
227 for (i = 0, index = 0; i < nfiles; i++) {
229 ret =
pixReadHeader(fname, &format, NULL, NULL, NULL, NULL, NULL);
231 if (format == IFF_UNKNOWN)
234 writeImageCompressedToPSFile(fname, fileout, res, &index);
273 convertFilesFittedToPS(
const char *dirin,
282 return ERROR_INT(
"dirin not defined", __func__, 1);
284 return ERROR_INT(
"fileout not defined", __func__, 1);
286 L_INFO(
"setting xpts to 612.0 ppi\n", __func__);
290 L_INFO(
"setting ypts to 792.0 ppi\n", __func__);
293 if (xpts < 100.0 || xpts > 2000.0 || ypts < 100.0 || ypts > 2000.0)
294 L_WARNING(
"xpts,ypts are typically in the range 500-800\n", __func__);
300 l_psWriteBoundingBox(FALSE);
301 sarrayConvertFilesFittedToPS(sa, xpts, ypts, fileout);
302 l_psWriteBoundingBox(TRUE);
323 sarrayConvertFilesFittedToPS(
SARRAY *sa,
329 l_int32 ret, i, w, h, nfiles, index, format, res;
332 return ERROR_INT(
"sa not defined", __func__, 1);
334 return ERROR_INT(
"fileout not defined", __func__, 1);
336 L_INFO(
"setting xpts to 612.0\n", __func__);
340 L_INFO(
"setting ypts to 792.0\n", __func__);
343 if (xpts < 100.0 || xpts > 2000.0 || ypts < 100.0 || ypts > 2000.0)
344 L_WARNING(
"xpts,ypts are typically in the range 500-800\n", __func__);
347 for (i = 0, index = 0; i < nfiles; i++) {
349 ret =
pixReadHeader(fname, &format, &w, &h, NULL, NULL, NULL);
351 if (format == IFF_UNKNOWN)
355 if (xpts * h < ypts * w)
356 res = (l_int32)((l_float32)w * 72.0 / xpts);
358 res = (l_int32)((l_float32)h * 72.0 / ypts);
360 writeImageCompressedToPSFile(fname, fileout, res, &index);
389 writeImageCompressedToPSFile(
const char *filein,
395 l_int32 format, retval;
398 return ERROR_INT(
"&index not defined", __func__, 1);
401 if (format == IFF_UNKNOWN) {
402 L_ERROR(
"format of %s not known\n", __func__, filein);
406 op = (*pindex == 0) ?
"w" :
"a";
407 if (format == IFF_JFIF_JPEG) {
409 res, 1.0, *pindex + 1, TRUE);
410 }
else if (format == IFF_TIFF_G4) {
412 res, 1.0, *pindex + 1, FALSE, TRUE);
415 res, 1.0, *pindex + 1, TRUE);
417 if (retval == 0) (*pindex)++;
482 convertSegmentedPagesToPS(
const char *pagedir,
491 l_float32 imagescale,
495 l_int32 pageno, i, npages;
500 return ERROR_INT(
"pagedir not defined", __func__, 1);
502 return ERROR_INT(
"maskdir not defined", __func__, 1);
504 return ERROR_INT(
"fileout not defined", __func__, 1);
505 if (threshold <= 0) {
506 L_INFO(
"setting threshold to 190\n", __func__);
512 page_numpre, numpost, maxnum);
514 mask_numpre, numpost, maxnum);
519 return ERROR_INT(
"no matching pages found", __func__, 1);
524 for (i = 0; i < npages; i++) {
528 pixWriteSegmentedPageToPS(pixs, pixm, textscale, imagescale,
529 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;
592 return ERROR_INT(
"pixs not defined", __func__, 1);
594 return ERROR_INT(
"fileout not defined", __func__, 1);
595 if (imagescale <= 0.0 || textscale <= 0.0)
596 return ERROR_INT(
"relative scales must be > 0.0", __func__, 1);
614 scaleratio = textscale / imagescale;
618 if (pixGetDepth(pixs) == 1) {
627 if (notext == FALSE) {
628 d = pixGetDepth(pixt);
635 if (textscale == 1.0)
637 else if (textscale >= 0.7)
649 if (imagescale == 1.0)
652 pixsc =
pixScale(pixt, imagescale, imagescale);
663 if (notext == FALSE) {
664 pixmis =
pixScale(pixm, imagescale, imagescale);
666 val = (d == 8) ? 0xff : 0xffffff00;
680 l_psWriteBoundingBox(FALSE);
681 ret = pixWriteMixedToPS(pixb, pixc, scaleratio, pageno, fileout);
682 l_psWriteBoundingBox(TRUE);
727 pixWriteMixedToPS(
PIX *pixb,
735 l_int32 resb, resc, endpage, maskop, ret;
738 return ERROR_INT(
"pixb and pixc both undefined", __func__, 1);
740 return ERROR_INT(
"fileout not defined", __func__, 1);
748 resb = (l_int32)(scale * resc);
754 pixWrite(tname, pixc, IFF_JFIF_JPEG);
755 endpage = (pixb) ? FALSE : TRUE;
756 op = (pageno <= 1) ?
"w" :
"a";
762 return ERROR_INT(
"jpeg data not written", __func__, 1);
769 pixWrite(tname, pixb, IFF_TIFF_G4);
770 op = (pageno <= 1 && !pixc) ?
"w" :
"a";
771 maskop = (pixc) ? 1 : 0;
777 return ERROR_INT(
"tiff data not written", __func__, 1);
812 convertToPSEmbed(
const char *filein,
821 return ERROR_INT(
"filein not defined", __func__, 1);
823 return ERROR_INT(
"fileout not defined", __func__, 1);
824 if (level != 1 && level != 2 && level != 3) {
825 L_ERROR(
"invalid level specified; using level 2\n", __func__);
836 if (format == IFF_JFIF_JPEG) {
839 }
else if (format == IFF_TIFF_G4) {
842 }
else if (format == IFF_UNKNOWN) {
843 L_ERROR(
"format of %s not known\n", __func__, filein);
854 if ((pixs =
pixRead(filein)) == NULL)
855 return ERROR_INT(
"image not read from file", __func__, 1);
856 d = pixGetDepth(pixs);
857 if ((d == 2 || d == 4) && !pixGetColormap(pixs))
865 return ERROR_INT(
"converted pix not made", __func__, 1);
867 d = pixGetDepth(pix);
870 if (pixWrite(tname, pix, IFF_TIFF_G4)) {
873 return ERROR_INT(
"g4 tiff not written", __func__, 1);
877 if (pixWrite(tname, pix, IFF_JFIF_JPEG)) {
880 return ERROR_INT(
"jpeg not written", __func__, 1);
914 pixaWriteCompressedToPS(
PIXA *pixa,
919 l_int32 i, n, index, ret;
923 return ERROR_INT(
"pixa not defined", __func__, 1);
925 return ERROR_INT(
"fileout not defined", __func__, 1);
926 if (level != 2 && level != 3) {
927 L_ERROR(
"only levels 2 and 3 permitted; using level 2\n", __func__);
933 for (i = 0; i < n; i++) {
935 ret = pixWriteCompressedToPS(pix, fileout, res, level, &index);
936 if (ret) L_ERROR(
"PS string not written for image %d\n", __func__, i);
986 pixWriteCompressedToPS(
PIX *pix,
998 return ERROR_INT(
"pix not defined", __func__, 1);
1000 return ERROR_INT(
"fileout not defined", __func__, 1);
1001 if (level != 2 && level != 3) {
1002 L_ERROR(
"only levels 2 and 3 permitted; using level 2\n", __func__);
1006 return ERROR_INT(
"&index not defined", __func__, 1);
1010 d = pixGetDepth(pix);
1011 cmap = pixGetColormap(pix);
1013 if (pixWrite(tname, pix, IFF_TIFF_G4))
1015 }
else if (level == 3) {
1016 if (pixWrite(tname, pix, IFF_PNG))
1021 if (pixWrite(tname, pixt, IFF_JFIF_JPEG))
1024 }
else if (d == 16) {
1025 L_WARNING(
"d = 16; converting to 8 bpp for jpeg\n", __func__);
1027 if (pixWrite(tname, pixt, IFF_JFIF_JPEG))
1030 }
else if (d == 2 || d == 4) {
1032 if (pixWrite(tname, pixt, IFF_JFIF_JPEG))
1035 }
else if (d == 8 || d == 32) {
1036 if (pixWrite(tname, pix, IFF_JFIF_JPEG))
1039 L_ERROR(
"invalid depth with level 2: %d\n", __func__, d);
1045 writeImageCompressedToPSFile(tname, fileout, res, pindex);
1048 L_ERROR(
"temp file %s was not deleted\n", __func__, tname);
1050 return (writeout) ? 0 : 1;
PIX * pixThresholdToBinary(PIX *pixs, l_int32 thresh)
pixThresholdToBinary()
void pixDestroy(PIX **ppix)
pixDestroy()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixClone(PIX *pixs)
pixClone()
l_ok pixZero(PIX *pix, l_int32 *pempty)
pixZero()
PIX * pixInvert(PIX *pixd, PIX *pixs)
pixInvert()
l_ok pixSetMasked(PIX *pixd, PIX *pixm, l_uint32 val)
pixSetMasked()
@ REMOVE_CMAP_BASED_ON_SRC
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
PIX * pixConvertTo8Or32(PIX *pixs, l_int32 copyflag, l_int32 warnflag)
pixConvertTo8Or32()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
PIX * pixConvertForPSWrap(PIX *pixs)
pixConvertForPSWrap()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
PIX * pixConvertRGBToLuminance(PIX *pixs)
pixConvertRGBToLuminance()
PIX * pixConvert16To8(PIX *pixs, l_int32 type)
pixConvert16To8()
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()
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 pixWritePSEmbed(const char *filein, const char *fileout)
pixWritePSEmbed()
l_ok convertFlateToPSEmbed(const char *filein, const char *fileout)
convertFlateToPSEmbed()
l_ok convertG4ToPSEmbed(const char *filein, const char *fileout)
convertG4ToPSEmbed()
l_ok convertJpegToPSEmbed(const char *filein, const char *fileout)
convertJpegToPSEmbed()
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()
l_int32 getResLetterPage(l_int32 w, l_int32 h, l_float32 fillfract)
getResLetterPage()
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_ok findFileFormat(const char *filename, l_int32 *pformat)
findFileFormat()
PIX * pixRead(const char *filename)
pixRead()
PIX * pixReadIndexed(SARRAY *sa, l_int32 index)
pixReadIndexed()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_ok sarrayPadToSameSize(SARRAY *sa1, SARRAY *sa2, const char *padstring)
sarrayPadToSameSize()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
SARRAY * getSortedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
getSortedPathnamesInDirectory()
SARRAY * getNumberedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 numpre, l_int32 numpost, l_int32 maxnum)
getNumberedPathnamesInDirectory()
PIX * pixScale(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScale()
PIX * pixScaleGrayLI(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleGrayLI()
PIX * pixScaleAreaMap(PIX *pix, l_float32 scalex, l_float32 scaley)
pixScaleAreaMap()
l_int32 lept_rmfile(const char *filepath)
lept_rmfile()
char * l_makeTempFilename(void)
l_makeTempFilename()