106 #include "allheaders.h" 154 convertFilesToPS(
const char *dirin,
161 PROCNAME(
"convertFilesToPS");
164 return ERROR_INT(
"dirin not defined", procName, 1);
166 return ERROR_INT(
"fileout not defined", procName, 1);
168 L_INFO(
"setting res to 300 ppi\n", procName);
171 if (res < 10 || res > 4000)
172 L_WARNING(
"res is typically in the range 300-600 ppi\n", procName);
178 l_psWriteBoundingBox(FALSE);
179 sarrayConvertFilesToPS(sa, res, fileout);
180 l_psWriteBoundingBox(TRUE);
201 sarrayConvertFilesToPS(
SARRAY *sa,
206 l_int32 i, nfiles, index, firstfile, ret, format;
208 PROCNAME(
"sarrayConvertFilesToPS");
211 return ERROR_INT(
"sa not defined", procName, 1);
213 return ERROR_INT(
"fileout not defined", procName, 1);
215 L_INFO(
"setting res to 300 ppi\n", procName);
218 if (res < 10 || res > 4000)
219 L_WARNING(
"res is typically in the range 300-600 ppi\n", procName);
223 for (i = 0, index = 0; i < nfiles; i++) {
225 ret =
pixReadHeader(fname, &format, NULL, NULL, NULL, NULL, NULL);
227 if (format == IFF_UNKNOWN)
230 writeImageCompressedToPSFile(fname, fileout, res, &firstfile, &index);
269 convertFilesFittedToPS(
const char *dirin,
277 PROCNAME(
"convertFilesFittedToPS");
280 return ERROR_INT(
"dirin not defined", procName, 1);
282 return ERROR_INT(
"fileout not defined", procName, 1);
284 L_INFO(
"setting xpts to 612.0 ppi\n", procName);
288 L_INFO(
"setting ypts to 792.0 ppi\n", procName);
291 if (xpts < 100.0 || xpts > 2000.0 || ypts < 100.0 || ypts > 2000.0)
292 L_WARNING(
"xpts,ypts are typically in the range 500-800\n", procName);
298 l_psWriteBoundingBox(FALSE);
299 sarrayConvertFilesFittedToPS(sa, xpts, ypts, fileout);
300 l_psWriteBoundingBox(TRUE);
321 sarrayConvertFilesFittedToPS(
SARRAY *sa,
327 l_int32 ret, i, w, h, nfiles, index, firstfile, format, res;
329 PROCNAME(
"sarrayConvertFilesFittedToPS");
332 return ERROR_INT(
"sa not defined", procName, 1);
334 return ERROR_INT(
"fileout not defined", procName, 1);
336 L_INFO(
"setting xpts to 612.0\n", procName);
340 L_INFO(
"setting ypts to 792.0\n", procName);
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", procName);
348 for (i = 0, index = 0; i < nfiles; i++) {
350 ret =
pixReadHeader(fname, &format, &w, &h, NULL, NULL, NULL);
352 if (format == IFF_UNKNOWN)
356 if (xpts * h < ypts * w)
357 res = (l_int32)((l_float32)w * 72.0 / xpts);
359 res = (l_int32)((l_float32)h * 72.0 / ypts);
361 writeImageCompressedToPSFile(fname, fileout, res, &firstfile, &index);
391 writeImageCompressedToPSFile(
const char *filein,
398 l_int32 format, retval;
400 PROCNAME(
"writeImageCompressedToPSFile");
402 if (!pfirstfile || !pindex)
403 return ERROR_INT(
"&firstfile and &index not defined", procName, 1);
406 if (format == IFF_UNKNOWN) {
407 L_ERROR(
"format of %s not known\n", procName, filein);
411 op = (*pfirstfile == TRUE) ?
"w" :
"a";
412 if (format == IFF_JFIF_JPEG) {
414 res, 1.0, *pindex + 1, TRUE);
419 }
else if (format == IFF_TIFF_G4) {
421 res, 1.0, *pindex + 1, FALSE, TRUE);
428 res, 1.0, *pindex + 1, TRUE);
498 convertSegmentedPagesToPS(
const char *pagedir,
507 l_float32 imagescale,
511 l_int32 pageno, i, npages;
515 PROCNAME(
"convertSegmentedPagesToPS");
518 return ERROR_INT(
"pagedir not defined", procName, 1);
520 return ERROR_INT(
"maskdir not defined", procName, 1);
522 return ERROR_INT(
"fileout not defined", procName, 1);
523 if (threshold <= 0) {
524 L_INFO(
"setting threshold to 190\n", procName);
530 page_numpre, numpost, maxnum);
532 mask_numpre, numpost, maxnum);
537 return ERROR_INT(
"no matching pages found", procName, 1);
542 for (i = 0; i < npages; i++) {
546 pixWriteSegmentedPageToPS(pixs, pixm, textscale, imagescale,
547 threshold, pageno, fileout);
596 pixWriteSegmentedPageToPS(
PIX *pixs,
599 l_float32 imagescale,
604 l_int32 alltext, notext, d, ret;
606 l_float32 scaleratio;
607 PIX *pixmi, *pixmis, *pixt, *pixg, *pixsc, *pixb, *pixc;
609 PROCNAME(
"pixWriteSegmentedPageToPS");
612 return ERROR_INT(
"pixs not defined", procName, 1);
614 return ERROR_INT(
"fileout not defined", procName, 1);
615 if (imagescale <= 0.0 || textscale <= 0.0)
616 return ERROR_INT(
"relative scales must be > 0.0", procName, 1);
634 scaleratio = textscale / imagescale;
638 if (pixGetDepth(pixs) == 1) {
647 if (notext == FALSE) {
648 d = pixGetDepth(pixt);
655 if (textscale == 1.0)
657 else if (textscale >= 0.7)
669 if (imagescale == 1.0)
672 pixsc =
pixScale(pixt, imagescale, imagescale);
683 if (notext == FALSE) {
684 pixmis =
pixScale(pixm, imagescale, imagescale);
686 val = (d == 8) ? 0xff : 0xffffff00;
700 l_psWriteBoundingBox(FALSE);
701 ret = pixWriteMixedToPS(pixb, pixc, scaleratio, pageno, fileout);
702 l_psWriteBoundingBox(TRUE);
747 pixWriteMixedToPS(
PIX *pixb,
755 l_int32 resb, resc, endpage, maskop, ret;
757 PROCNAME(
"pixWriteMixedToPS");
760 return ERROR_INT(
"pixb and pixc both undefined", procName, 1);
762 return ERROR_INT(
"fileout not defined", procName, 1);
770 resb = (l_int32)(scale * resc);
776 pixWrite(tname, pixc, IFF_JFIF_JPEG);
777 endpage = (pixb) ? FALSE : TRUE;
778 op = (pageno <= 1) ?
"w" :
"a";
784 return ERROR_INT(
"jpeg data not written", procName, 1);
791 pixWrite(tname, pixb, IFF_TIFF_G4);
792 op = (pageno <= 1 && !pixc) ?
"w" :
"a";
793 maskop = (pixc) ? 1 : 0;
799 return ERROR_INT(
"tiff data not written", procName, 1);
834 convertToPSEmbed(
const char *filein,
842 PROCNAME(
"convertToPSEmbed");
845 return ERROR_INT(
"filein not defined", procName, 1);
847 return ERROR_INT(
"fileout not defined", procName, 1);
848 if (level != 1 && level != 2 && level != 3) {
849 L_ERROR(
"invalid level specified; using level 2\n", procName);
860 if (format == IFF_JFIF_JPEG) {
863 }
else if (format == IFF_TIFF_G4) {
866 }
else if (format == IFF_UNKNOWN) {
867 L_ERROR(
"format of %s not known\n", procName, filein);
878 if ((pixs =
pixRead(filein)) == NULL)
879 return ERROR_INT(
"image not read from file", procName, 1);
880 d = pixGetDepth(pixs);
881 if ((d == 2 || d == 4) && !pixGetColormap(pixs))
888 d = pixGetDepth(pix);
891 pixWrite(tname, pix, IFF_TIFF_G4);
894 pixWrite(tname, pix, IFF_JFIF_JPEG);
935 pixaWriteCompressedToPS(
PIXA *pixa,
941 l_int32 i, n, firstfile, index, writeout, d;
945 PROCNAME(
"pixaWriteCompressedToPS");
948 return ERROR_INT(
"pixa not defined", procName, 1);
950 return ERROR_INT(
"fileout not defined", procName, 1);
951 if (level != 2 && level != 3) {
952 L_ERROR(
"only levels 2 and 3 permitted; using level 2\n", procName);
960 for (i = 0; i < n; i++) {
963 d = pixGetDepth(pix);
964 cmap = pixGetColormap(pix);
966 pixWrite(tname, pix, IFF_TIFF_G4);
970 pixWrite(tname, pixt, IFF_JFIF_JPEG);
973 pixWrite(tname, pix, IFF_PNG);
975 }
else if (d == 16) {
977 L_WARNING(
"d = 16; must write out flate\n", procName);
978 pixWrite(tname, pix, IFF_PNG);
979 }
else if (d == 2 || d == 4) {
982 pixWrite(tname, pixt, IFF_JFIF_JPEG);
985 pixWrite(tname, pix, IFF_PNG);
987 }
else if (d == 8 || d == 32) {
988 pixWrite(tname, pix, IFF_JFIF_JPEG);
990 L_ERROR(
"invalid depth: %d\n", procName, d);
996 writeImageCompressedToPSFile(tname, fileout, res,
PIX * pixConvertRGBToLuminance(PIX *pixs)
pixConvertRGBToLuminance()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
l_ok 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_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()
char * l_makeTempFilename()
l_makeTempFilename()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
l_ok pixZero(PIX *pix, l_int32 *pempty)
pixZero()
PIX * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
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()