95#include <config_auto.h>
100#include "allheaders.h"
107static const l_int32 DefaultInputRes = 300;
117static l_int32
l_generatePdf(l_uint8 **pdata,
size_t *pnbytes,
119static void generateFixedStringsPdf(L_PDF_DATA *lpd);
121static void generateMediaboxPdf(L_PDF_DATA *lpd);
122static l_int32 generatePageStringPdf(L_PDF_DATA *lpd);
123static l_int32 generateContentStringPdf(L_PDF_DATA *lpd);
124static l_int32 generatePreXStringsPdf(L_PDF_DATA *lpd);
125static l_int32 generateColormapStringsPdf(L_PDF_DATA *lpd);
126static void generateTrailerPdf(L_PDF_DATA *lpd);
127static char *makeTrailerStringPdf(
L_DNA *daloc);
132static char *generatePagesObjStringPdf(
NUMA *napage);
135static L_PDF_DATA *pdfdataCreate(
const char *title);
136static void pdfdataDestroy(L_PDF_DATA **plpd);
137static L_COMP_DATA *pdfdataGetCid(L_PDF_DATA *lpd, l_int32 index);
142static l_int32 var_WRITE_G4_IMAGE_MASK = 1;
144static l_int32 var_WRITE_DATE_AND_VERSION = 1;
146#define L_SMALLBUF 256
151#define DEBUG_MULTIPAGE 0
202l_int32 pixres, w, h, ret;
203l_float32 xpt, ypt, wpt, hpt;
204L_COMP_DATA *cid = NULL;
205L_PDF_DATA *lpd = NULL;
208 return ERROR_INT(
"&data not defined", __func__, 1);
211 return ERROR_INT(
"&nbytes not defined", __func__, 1);
214 return ERROR_INT(
"pix not defined", __func__, 1);
217 selectDefaultPdfEncoding(pix, &type);
219 if (quality < 0 || quality > 100)
220 return ERROR_INT(
"invalid quality", __func__, 1);
231 return ERROR_INT(
"cid not made", __func__, 1);
240 res = (pixres > 0) ? pixres : DefaultInputRes;
248 if ((lpd = pdfdataCreate(title)) == NULL)
249 return ERROR_INT(
"lpd not made", __func__, 1);
251 if ((lpd = pdfdataCreate(title)) == NULL)
252 return ERROR_INT(
"lpd not made", __func__, 1);
259 ptraAdd(lpd->
cida, cid);
261 ptaAddPt(lpd->
xy, xpt, ypt);
262 ptaAddPt(lpd->
wh, wpt, hpt);
268 pdfdataDestroy(&lpd);
269 if (plpd) *plpd = NULL;
271 return ERROR_INT(
"pdf output not made", __func__, 1);
323char *fname, *str_pages, *str_trailer;
324l_uint8 *pdfdata, *data;
325l_int32 i, j, index, nobj, npages;
326l_int32 *sizes, *locs;
328L_BYTEA *bas, *bad, *bat1, *bat2;
329L_DNA *da_locs, *da_sizes, *da_outlocs, *da;
331NUMA *na_objs, *napage;
335 return ERROR_INT(
"&data not defined", __func__, 1);
338 return ERROR_INT(
"&nbytes not defined", __func__, 1);
341 return ERROR_INT(
"pa_data not defined", __func__, 1);
345 ptraGetActualCount(pa_data, &npages);
346 daa_locs = l_dnaaCreate(npages);
347 for (i = 0; i < npages; i++) {
348 bas = (
L_BYTEA *)ptraGetPtrToItem(pa_data, i);
351 l_byteaDestroy(&bas);
353 fname = sarrayGetString(sa, i,
L_NOCOPY);
354 L_ERROR(
"can't parse file %s; skipping\n", __func__, fname);
356 L_ERROR(
"can't parse file %d; skipping\n", __func__, i);
359 l_dnaaAddDna(daa_locs, da_locs,
L_INSERT);
364 ptraCompactArray(pa_data);
365 ptraGetActualCount(pa_data, &npages);
367 l_dnaaDestroy(&daa_locs);
368 return ERROR_INT(
"no parsable pdf files found", __func__, 1);
372 naa_objs = numaaCreate(npages);
373 napage = numaCreate(npages);
375 for (i = 0; i < npages; i++) {
376 da = l_dnaaGetDna(daa_locs, i,
L_CLONE);
377 nobj = l_dnaGetCount(da);
379 numaAddNumber(napage, 4);
380 na_objs = numaMakeSequence(0.0, 1.0, nobj - 1);
383 numaAddNumber(napage, index);
384 na_objs = numaMakeConstant(0.0, nobj - 1);
385 numaReplaceNumber(na_objs, 3, 3);
386 for (j = 4; j < nobj - 1; j++)
387 numaSetValue(na_objs, j, index++);
389 numaaAddNuma(naa_objs, na_objs,
L_INSERT);
394 str_pages = generatePagesObjStringPdf(napage);
397 bad = l_byteaCreate(5000);
398 da_outlocs = l_dnaCreate(0);
399 for (i = 0; i < npages; i++) {
400 bas = (
L_BYTEA *)ptraGetPtrToItem(pa_data, i);
401 pdfdata = l_byteaGetData(bas, &size);
402 da_locs = l_dnaaGetDna(daa_locs, i,
L_CLONE);
403 na_objs = numaaGetNuma(naa_objs, i,
L_CLONE);
404 nobj = l_dnaGetCount(da_locs) - 1;
405 da_sizes = l_dnaDiffAdjValues(da_locs);
406 sizes = l_dnaGetIArray(da_sizes);
407 locs = l_dnaGetIArray(da_locs);
409 l_byteaAppendData(bad, pdfdata, sizes[0]);
410 l_byteaAppendData(bad, pdfdata + locs[1], sizes[1]);
411 l_byteaAppendData(bad, pdfdata + locs[2], sizes[2]);
412 l_byteaAppendString(bad, str_pages);
413 for (j = 0; j < 4; j++)
414 l_dnaAddNumber(da_outlocs, locs[j]);
416 for (j = 4; j < nobj; j++) {
417 l_dnaAddNumber(da_outlocs, l_byteaGetSize(bad));
418 bat1 = l_byteaInitFromMem(pdfdata + locs[j], sizes[j]);
420 data = l_byteaGetData(bat2, &size);
421 l_byteaAppendData(bad, data, size);
422 l_byteaDestroy(&bat1);
423 l_byteaDestroy(&bat2);
426 l_dnaAddNumber(da_outlocs, l_byteaGetSize(bad));
429 l_dnaDestroy(&da_locs);
430 numaDestroy(&na_objs);
431 l_dnaDestroy(&da_sizes);
435 str_trailer = makeTrailerStringPdf(da_outlocs);
436 l_byteaAppendString(bad, str_trailer);
439 *pdata = l_byteaCopyData(bad, pnbytes);
440 l_byteaDestroy(&bad);
443 lept_stderr(
"******** object mapper **********");
444 numaaWriteStream(stderr, naa_objs);
446 lept_stderr(
"******** Page object numbers ***********");
447 numaWriteStderr(napage);
449 lept_stderr(
"******** Pages object ***********\n");
450 lept_stderr(
"%s\n", str_pages);
453 numaDestroy(&napage);
454 numaaDestroy(&naa_objs);
455 l_dnaDestroy(&da_outlocs);
456 l_dnaaDestroy(&daa_locs);
457 LEPT_FREE(str_pages);
458 LEPT_FREE(str_trailer);
487 if ((fp = fopenReadStream(filein)) == NULL)
488 return ERROR_INT(
"file not found", __func__, 1);
489 istiff = fileFormatIsTiff(fp);
492 return ERROR_INT(
"file not tiff format", __func__, 1);
494 pixa = pixaReadMultipageTiff(filein);
495 pixaConvertToPdf(pixa, 0, 1.0, 0, 0,
"weasel2", fileout);
542 return ERROR_INT(
"&cid not defined", __func__, 1);
545 return ERROR_INT(
"neither fname nor pix are defined", __func__, 1);
549 if (fname && strcmp(fname,
"-") != 0 && strcmp(fname,
"stdin") != 0) {
550 findFileFormat(fname, &format);
551 if (format == IFF_UNKNOWN)
552 L_WARNING(
"file %s format is unknown\n", __func__, fname);
553 if (format == IFF_PS || format == IFF_LPDF) {
554 L_ERROR(
"file %s is unsupported format %d\n",
555 __func__, fname, format);
558 if (format == IFF_JFIF_JPEG) {
560 }
else if (format == IFF_JP2) {
562 }
else if (format == IFF_PNG) {
570 pixt = pixRead(fname);
572 pixt = pixClone(pix);
574 return ERROR_INT(
"pixt not made", __func__, 1);
575 if (selectDefaultPdfEncoding(pixt, &type)) {
582 return ERROR_INT(
"cid not made from pix", __func__, 1);
620l_int32 format, d, bps, spp, iscmap;
625 return ERROR_INT(
"&cid not defined", __func__, 1);
628 return ERROR_INT(
"fname not defined", __func__, 1);
631 return ERROR_INT(
"invalid conversion type", __func__, 1);
632 if (ascii85 != 0 && ascii85 != 1)
633 return ERROR_INT(
"invalid ascii85", __func__, 1);
636 pixReadHeader(fname, &format, NULL, NULL, &bps, &spp, &iscmap);
640 L_WARNING(
"pixs has cmap; using flate encoding\n", __func__);
643 L_WARNING(
"pixs has < 8 bpp; using flate encoding\n", __func__);
646 L_WARNING(
"pixs has < 8 bpp; using flate encoding\n", __func__);
649 L_WARNING(
"pixs has > 1 bpp; using flate encoding\n", __func__);
654 if (format == IFF_JFIF_JPEG) {
657 if ((pix = pixRead(fname)) == NULL)
658 return ERROR_INT(
"pix not returned for JPEG", __func__, 1);
663 return ERROR_INT(
"jpeg data not made", __func__, 1);
665 if (format == IFF_JP2) {
668 if ((pix = pixRead(fname)) == NULL)
669 return ERROR_INT(
"pix not returned for JP2K", __func__, 1);
674 return ERROR_INT(
"jp2k data not made", __func__, 1);
676 if ((pix = pixRead(fname)) == NULL)
677 return ERROR_INT(
"pix not returned for G4", __func__, 1);
681 return ERROR_INT(
"g4 data not made", __func__, 1);
684 return ERROR_INT(
"flate data not made", __func__, 1);
686 return ERROR_INT(
"invalid conversion type", __func__, 1);
719l_uint8 *pngcomp = NULL;
720l_uint8 *datacomp = NULL;
721l_uint8 *cmapdata = NULL;
722char *cmapdatahex = NULL;
724l_int32 format, interlaced;
728l_int32 w, h, cmapflag;
730size_t nbytescomp = 0, nbytespng = 0;
737 return (L_COMP_DATA *)ERROR_PTR(
"fname not defined", __func__, NULL);
739 findFileFormat(fname, &format);
743 if (format == IFF_PNG) {
744 isPngInterlaced(fname, &interlaced);
745 if (readHeaderPng(fname, NULL, NULL, &bps, &spp, NULL))
746 return (L_COMP_DATA *)ERROR_PTR(
"bad png input", __func__, NULL);
757 if (format != IFF_PNG ||
758 (format == IFF_PNG && (interlaced || bps == 1 || spp == 4 || spp == 2)))
761 pix = pixRead(fname);
763 pix = pixClone(pixs);
765 return (L_COMP_DATA *)ERROR_PTR(
"pix not made", __func__, NULL);
774 if ((fp = fopenReadStream(fname)) == NULL)
775 return (L_COMP_DATA *)ERROR_PTR(
"stream not opened", __func__, NULL);
776 freadHeaderPng(fp, &w, &h, &bps, &spp, &cmapflag);
777 fgetPngResolution(fp, &xres, &yres);
785 if ((pngcomp = l_binaryRead(fname, &nbytespng)) == NULL)
786 return (L_COMP_DATA *)ERROR_PTR(
"unable to read file",
795 if ((datacomp = (l_uint8 *)LEPT_CALLOC(1, nbytespng)) == NULL) {
797 return (L_COMP_DATA *)ERROR_PTR(
"unable to allocate memory",
811 for (i = 16; i < nbytespng; i += 12) {
813 n = pngcomp[i - 8] << 24;
814 n += pngcomp[i - 7] << 16;
815 n += pngcomp[i - 6] << 8;
816 n += pngcomp[i - 5] << 0;
817 if (n >= nbytespng - i) {
820 pixcmapDestroy(&cmap);
821 L_ERROR(
"invalid png: i = %d, n = %d, nbytes = %zu\n", __func__,
827 if (memcmp(pngcomp + i - 4,
"IDAT", 4) == 0) {
828 memcpy(datacomp + nbytescomp, pngcomp + i, n);
833 if (cmapflag && !cmap &&
834 memcmp(pngcomp + i - 4,
"PLTE", 4) == 0) {
835 if ((n / 3) > (1 << bps)) {
838 pixcmapDestroy(&cmap);
839 L_ERROR(
"invalid png: i = %d, n = %d, cmapsize = %d\n",
840 __func__, i, n, (1 << bps));
843 cmap = pixcmapCreate(bps);
844 for (j = i; j < i + n; j += 3) {
845 pixcmapAddColor(cmap, pngcomp[j], pngcomp[j + 1],
853 if (nbytescomp == 0) {
855 pixcmapDestroy(&cmap);
856 return (L_COMP_DATA *)ERROR_PTR(
"invalid PNG file", __func__, NULL);
862 pixcmapSerializeToMemory(cmap, 3, &ncolors, &cmapdata);
863 pixcmapDestroy(&cmap);
866 return (L_COMP_DATA *)ERROR_PTR(
"cmapdata not made",
869 cmapdatahex = pixcmapConvertToHex(cmapdata, ncolors);
880 cid = (L_COMP_DATA *)LEPT_CALLOC(1,
sizeof(L_COMP_DATA));
918l_int32 w, h, xres, yres, bps, spp;
919size_t nbytes, nbytes85;
924 return (L_COMP_DATA *)ERROR_PTR(
"fname not defined", __func__, NULL);
926 if (ascii85flag != 0 && ascii85flag != 1)
927 return (L_COMP_DATA *)ERROR_PTR(
"wrong ascii85flags", __func__, NULL);
930 if (readHeaderJpeg(fname, &w, &h, &spp, NULL, NULL))
931 return (L_COMP_DATA *)ERROR_PTR(
"bad jpeg metadata", __func__, NULL);
933 if ((fp = fopenReadStream(fname)) == NULL)
934 return (L_COMP_DATA *)ERROR_PTR(
"stream not opened", __func__, NULL);
935 fgetJpegResolution(fp, &xres, &yres);
940 if ((data = l_binaryRead(fname, &nbytes)) == NULL)
941 return (L_COMP_DATA *)ERROR_PTR(
"data not extracted", __func__, NULL);
944 if (ascii85flag == 1) {
945 data85 = encodeAscii85(data, nbytes, &nbytes85);
948 return (L_COMP_DATA *)ERROR_PTR(
"data85 not made", __func__, NULL);
950 data85[nbytes85 - 1] =
'\0';
953 cid = (L_COMP_DATA *)LEPT_CALLOC(1,
sizeof(L_COMP_DATA));
954 if (ascii85flag == 0) {
992l_int32 w, h, xres, yres, bps, spp;
997 return (L_COMP_DATA *)ERROR_PTR(
"data not defined", __func__, NULL);
1000 if (readHeaderMemJpeg(data, nbytes, &w, &h, &spp, NULL, NULL)) {
1002 return (L_COMP_DATA *)ERROR_PTR(
"bad jpeg metadata", __func__, NULL);
1005 readResolutionMemJpeg(data, nbytes, &xres, &yres);
1008 if (ascii85flag == 1) {
1009 data85 = encodeAscii85(data, nbytes, &nbytes85);
1012 return (L_COMP_DATA *)ERROR_PTR(
"data85 not made", __func__, NULL);
1014 data85[nbytes85 - 1] =
'\0';
1017 cid = (L_COMP_DATA *)LEPT_CALLOC(1,
sizeof(L_COMP_DATA));
1018 if (ascii85flag == 0) {
1049l_int32 w, h, bps, spp, xres, yres;
1055 return (L_COMP_DATA *)ERROR_PTR(
"fname not defined", __func__, NULL);
1057 if (readHeaderJp2k(fname, &w, &h, &bps, &spp, NULL))
1058 return (L_COMP_DATA *)ERROR_PTR(
"bad jp2k metadata", __func__, NULL);
1061 cid = (L_COMP_DATA *)LEPT_CALLOC(1,
sizeof(L_COMP_DATA));
1062 if ((cid->
datacomp = l_binaryRead(fname, &nbytes)) == NULL) {
1064 return (L_COMP_DATA *)ERROR_PTR(
"data not extracted", __func__, NULL);
1068 if ((fp = fopenReadStream(fname)) != NULL) {
1069 fgetJp2kResolution(fp, &xres, &yres);
1100 l_int32 ascii85flag)
1102l_uint8 *datacomp = NULL;
1104l_int32 w, h, xres, yres, npages;
1106size_t nbytes85, nbytescomp;
1111 return (L_COMP_DATA *)ERROR_PTR(
"fname not defined", __func__, NULL);
1114 if ((fp = fopenReadStream(fname)) == NULL)
1115 return (L_COMP_DATA *)ERROR_PTR(
"stream not opened", __func__, NULL);
1116 tiffGetCount(fp, &npages);
1119 L_ERROR(
" %d page tiff; only works with 1 page\n", __func__, npages);
1124 if ((fp = fopenReadStream(fname)) == NULL)
1125 return (L_COMP_DATA *)ERROR_PTR(
"stream not opened", __func__, NULL);
1126 getTiffResolution(fp, &xres, &yres);
1132 if (extractG4DataFromFile(fname, &datacomp, &nbytescomp,
1133 &w, &h, &minisblack)) {
1134 return (L_COMP_DATA *)ERROR_PTR(
"datacomp not extracted",
1139 if (ascii85flag == 1) {
1140 data85 = encodeAscii85(datacomp, nbytescomp, &nbytes85);
1141 LEPT_FREE(datacomp);
1143 return (L_COMP_DATA *)ERROR_PTR(
"data85 not made", __func__, NULL);
1145 data85[nbytes85 - 1] =
'\0';
1148 cid = (L_COMP_DATA *)LEPT_CALLOC(1,
sizeof(L_COMP_DATA));
1149 if (ascii85flag == 0) {
1194l_int32 w, h, d, maxAsp;
1198 return ERROR_INT(
"&cid not defined", __func__, 1);
1201 return ERROR_INT(
"pixs not defined", __func__, 1);
1204 selectDefaultPdfEncoding(pixs, &type);
1206 if (ascii85 != 0 && ascii85 != 1)
1207 return ERROR_INT(
"invalid ascii85", __func__, 1);
1208 pixGetDimensions(pixs, &w, &h, NULL);
1209 if (w == 0 || h == 0)
1210 return ERROR_INT(
"invalid w or h", __func__, 1);
1211 maxAsp = L_MAX(w / h, h / w);
1213 return ERROR_INT(
"max asperity > 10", __func__, 1);
1217#if defined(HAVE_LIBZ)
1218# if !defined(HAVE_LIBJPEG)
1220 L_WARNING(
"no libjpeg; using flate encoding\n", __func__);
1224# if !defined(HAVE_LIBJP2K)
1226 L_WARNING(
"no libjp2k; using flate encoding\n", __func__);
1230# if !defined(HAVE_LIBTIFF)
1232 L_WARNING(
"no libtiff; using flate encoding\n", __func__);
1239 d = pixGetDepth(pixs);
1240 cmap = pixGetColormap(pixs);
1242 L_WARNING(
"pixs has cmap; using flate encoding\n", __func__);
1245 L_WARNING(
"pixs has < 8 bpp; using flate encoding\n", __func__);
1248 L_WARNING(
"pixs has > 1 bpp; using flate encoding\n", __func__);
1254 return ERROR_INT(
"jpeg data not made", __func__, 1);
1257 return ERROR_INT(
"jp2k data not made", __func__, 1);
1260 return ERROR_INT(
"g4 data not made", __func__, 1);
1263 return ERROR_INT(
"flate data not made", __func__, 1);
1291 l_int32 ascii85flag)
1297 return (L_COMP_DATA *)ERROR_PTR(
"fname not defined", __func__, NULL);
1299 if ((pixs = pixRead(fname)) == NULL)
1300 return (L_COMP_DATA *)ERROR_PTR(
"pixs not made", __func__, NULL);
1326 l_int32 ascii85flag)
1328l_uint8 *data = NULL;
1329l_uint8 *datacomp = NULL;
1331l_uint8 *cmapdata = NULL;
1332char *cmapdata85 = NULL;
1333char *cmapdatahex = NULL;
1337l_int32 w, h, d, cmapflag;
1338size_t ncmapbytes85 = 0;
1340size_t nbytes, nbytescomp;
1346 return (L_COMP_DATA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1353 pixGetDimensions(pixs, &w, &h, &d);
1354 cmap = pixGetColormap(pixs);
1355 cmapflag = (cmap) ? 1 : 0;
1356 if (d == 2 || d == 4 || d == 16) {
1357 pixt = pixConvertTo8(pixs, cmapflag);
1358 cmap = pixGetColormap(pixt);
1359 d = pixGetDepth(pixt);
1360 }
else if (d == 32 && pixGetSpp(pixs) == 4) {
1361 pixt = pixAlphaBlendUniform(pixs, 0xffffff00);
1363 pixt = pixClone(pixs);
1366 return (L_COMP_DATA *)ERROR_PTR(
"pixt not made", __func__, NULL);
1367 spp = (d == 32) ? 3 : 1;
1368 bps = (d == 32) ? 8 : d;
1373 pixcmapSerializeToMemory(cmap, 3, &ncolors, &cmapdata);
1376 return (L_COMP_DATA *)ERROR_PTR(
"cmapdata not made",
1380 cmapdata85 = encodeAscii85(cmapdata, 3 * ncolors, &ncmapbytes85);
1381 cmapdatahex = pixcmapConvertToHex(cmapdata, ncolors);
1382 LEPT_FREE(cmapdata);
1386 pixGetRasterData(pixt, &data, &nbytes);
1389 LEPT_FREE(cmapdata85);
1390 LEPT_FREE(cmapdatahex);
1391 return (L_COMP_DATA *)ERROR_PTR(
"data not returned", __func__, NULL);
1393 datacomp = zlibCompress(data, nbytes, &nbytescomp);
1396 LEPT_FREE(cmapdata85);
1397 LEPT_FREE(cmapdatahex);
1398 return (L_COMP_DATA *)ERROR_PTR(
"datacomp not made", __func__, NULL);
1402 if (ascii85flag == 1) {
1403 data85 = encodeAscii85(datacomp, nbytescomp, &nbytes85);
1404 LEPT_FREE(datacomp);
1406 LEPT_FREE(cmapdata85);
1407 LEPT_FREE(cmapdatahex);
1408 return (L_COMP_DATA *)ERROR_PTR(
"data85 not made", __func__, NULL);
1410 data85[nbytes85 - 1] =
'\0';
1414 cid = (L_COMP_DATA *)LEPT_CALLOC(1,
sizeof(L_COMP_DATA));
1415 if (ascii85flag == 0) {
1430 cid->
res = pixGetXRes(pixs);
1454 l_int32 ascii85flag,
1462 return (L_COMP_DATA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1463 if (pixGetColormap(pixs))
1464 return (L_COMP_DATA *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
1465 d = pixGetDepth(pixs);
1466 if (d != 8 && d != 16 && d != 32)
1467 return (L_COMP_DATA *)ERROR_PTR(
"pixs not 8, 16 or 32 bpp",
1471 fname = l_makeTempFilename();
1472 if (pixWriteJpeg(fname, pixs, quality, 0)) {
1479 if (lept_rmfile(fname) != 0)
1480 L_ERROR(
"temp file %s was not deleted\n", __func__, fname);
1509 return (L_COMP_DATA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1510 if (pixGetColormap(pixs))
1511 return (L_COMP_DATA *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
1512 d = pixGetDepth(pixs);
1513 if (d != 8 && d != 32)
1514 return (L_COMP_DATA *)ERROR_PTR(
"pixs not 8 or 32 bpp", __func__, NULL);
1517 fname = l_makeTempFilename();
1518 if (pixWriteJp2k(fname, pixs, quality, 5, 0, 0)) {
1525 if (lept_rmfile(fname) != 0)
1526 L_ERROR(
"temp file %s was not deleted\n", __func__, fname);
1548 l_int32 ascii85flag)
1554 return (L_COMP_DATA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1555 if (pixGetDepth(pixs) != 1)
1556 return (L_COMP_DATA *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
1557 if (pixGetColormap(pixs))
1558 return (L_COMP_DATA *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
1561 fname = l_makeTempFilename();
1562 if (pixWrite(fname, pixs, IFF_TIFF_G4)) {
1568 if (lept_rmfile(fname) != 0)
1569 L_ERROR(
"temp file %s was not deleted\n", __func__, fname);
1598L_PDF_DATA *lpd = NULL;
1600 if (!pdata || !pnbytes)
1601 return ERROR_INT(
"&data and &nbytes not both defined", __func__, 1);
1605 return ERROR_INT(
"cid not defined", __func__, 1);
1610 res = DefaultInputRes;
1611 wpt = cid->
w * 72. / res;
1612 hpt = cid->
h * 72. / res;
1615 if ((lpd = pdfdataCreate(title)) == NULL)
1616 return ERROR_INT(
"lpd not made", __func__, 1);
1617 ptraAdd(lpd->
cida, cid);
1619 ptaAddPt(lpd->
xy, 0, 0);
1620 ptaAddPt(lpd->
wh, wpt, hpt);
1624 pdfdataDestroy(&lpd);
1626 return ERROR_INT(
"pdf output not made", __func__, 1);
1643 L_WARNING(
"ptr address is null!\n", __func__);
1646 if ((cid = *pcid) == NULL)
1688 return ERROR_INT(
"&data not defined", __func__, 1);
1691 return ERROR_INT(
"&nbytes not defined", __func__, 1);
1694 return ERROR_INT(
"lpd not defined", __func__, 1);
1696 generateFixedStringsPdf(lpd);
1697 generateMediaboxPdf(lpd);
1698 generatePageStringPdf(lpd);
1699 generateContentStringPdf(lpd);
1700 generatePreXStringsPdf(lpd);
1701 generateColormapStringsPdf(lpd);
1702 generateTrailerPdf(lpd);
1708generateFixedStringsPdf(L_PDF_DATA *lpd)
1710char buf[L_SMALLBUF];
1711char *version, *datestr;
1715 lpd->
id = stringNew(
"%PDF-1.5\n");
1716 l_dnaAddNumber(lpd->
objsize, strlen(lpd->
id));
1718 lpd->
obj1 = stringNew(
"1 0 obj\n"
1726 sa = sarrayCreate(0);
1727 sarrayAddString(sa,
"2 0 obj\n"
1729 if (var_WRITE_DATE_AND_VERSION) {
1730 datestr = l_getFormattedDate();
1731 snprintf(buf,
sizeof(buf),
"/CreationDate (D:%s)\n", datestr);
1732 sarrayAddString(sa, buf,
L_COPY);
1734 version = getLeptonicaVersion();
1735 snprintf(buf,
sizeof(buf),
1736 "/Producer (leptonica: %s)\n", version);
1739 snprintf(buf,
sizeof(buf),
"/Producer (leptonica)\n");
1741 sarrayAddString(sa, buf,
L_COPY);
1745 snprintf(buf,
sizeof(buf),
"/Title %s\n", hexstr);
1746 sarrayAddString(sa, buf,
L_COPY);
1748 L_ERROR(
"title string is not ascii\n", __func__);
1752 sarrayAddString(sa,
">>\n"
1754 lpd->
obj2 = sarrayToString(sa, 0);
1758 lpd->
obj3 = stringNew(
"3 0 obj\n"
1795l_int32 i, nchar, buflen;
1798 return (
char *)ERROR_PTR(
"str not defined", __func__, NULL);
1799 nchar = strlen(str);
1800 for (i = 0; i < nchar; i++) {
1802 return (
char *)ERROR_PTR(
"str not all ascii", __func__, NULL);
1805 buflen = 4 * nchar + 10;
1806 buffer = (
char *)LEPT_CALLOC(buflen,
sizeof(
char));
1807 stringCat(buffer, buflen,
"<feff");
1808 for (i = 0; i < nchar; i++) {
1809 snprintf(smallbuf,
sizeof(smallbuf),
"%04x", str[i]);
1810 stringCat(buffer, buflen, smallbuf);
1812 stringCat(buffer, buflen,
">");
1818generateMediaboxPdf(L_PDF_DATA *lpd)
1821l_float32 xpt, ypt, wpt, hpt, maxx, maxy;
1826 for (i = 0; i < lpd->
n; i++) {
1827 ptaGetPt(lpd->
xy, i, &xpt, &ypt);
1828 ptaGetPt(lpd->
wh, i, &wpt, &hpt);
1829 maxx = L_MAX(maxx, xpt + wpt);
1830 maxy = L_MAX(maxy, ypt + hpt);
1833 lpd->
mediabox = boxCreate(0, 0, (l_int32)(maxx + 0.5),
1834 (l_int32)(maxy + 0.5));
1840 for (i = 0; i < lpd->
n; i++) {
1841 ptaGetPt(lpd->
xy, i, &xpt, &ypt);
1842 ptaGetPt(lpd->
wh, i, &wpt, &hpt);
1843 ptaSetPt(lpd->
xy, i, xpt, maxy - ypt - hpt);
1849generatePageStringPdf(L_PDF_DATA *lpd)
1853l_int32 bufsize, i, wpt, hpt;
1859 bufsize = 1000 + 50 * lpd->
n;
1860 if ((buf = (
char *)LEPT_CALLOC(bufsize,
sizeof(
char))) == NULL)
1861 return ERROR_INT(
"calloc fail for buf", __func__, 1);
1863 boxGetGeometry(lpd->
mediabox, NULL, NULL, &wpt, &hpt);
1864 sa = sarrayCreate(lpd->
n);
1865 for (i = 0; i < lpd->
n; i++) {
1866 snprintf(buf, bufsize,
"/Im%d %d 0 R ", i + 1, 6 + i);
1867 sarrayAddString(sa, buf,
L_COPY);
1869 xstr = sarrayToString(sa, 0);
1873 return ERROR_INT(
"xstr not made", __func__, 1);
1876 snprintf(buf, bufsize,
"4 0 obj\n"
1880 "/MediaBox [%d %d %d %d]\n"
1884 "/XObject << %s >>\n"
1885 "/ProcSet [ /ImageB /ImageI /ImageC ]\n"
1889 0, 0, wpt, hpt, xstr);
1891 lpd->
obj4 = stringNew(buf);
1901generateContentStringPdf(L_PDF_DATA *lpd)
1906l_float32 xpt, ypt, wpt, hpt;
1909 bufsize = 1000 + 200 * lpd->
n;
1910 if ((buf = (
char *)LEPT_CALLOC(bufsize,
sizeof(
char))) == NULL)
1911 return ERROR_INT(
"calloc fail for buf", __func__, 1);
1913 sa = sarrayCreate(lpd->
n);
1914 for (i = 0; i < lpd->
n; i++) {
1915 ptaGetPt(lpd->
xy, i, &xpt, &ypt);
1916 ptaGetPt(lpd->
wh, i, &wpt, &hpt);
1917 snprintf(buf, bufsize,
1918 "q %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d Do Q\n",
1919 wpt, 0.0, 0.0, hpt, xpt, ypt, i + 1);
1920 sarrayAddString(sa, buf,
L_COPY);
1922 cstr = sarrayToString(sa, 0);
1926 return ERROR_INT(
"cstr not made", __func__, 1);
1929 snprintf(buf, bufsize,
"5 0 obj\n"
1930 "<< /Length %d >>\n"
1935 (l_int32)strlen(cstr), cstr);
1937 lpd->
obj5 = stringNew(buf);
1947generatePreXStringsPdf(L_PDF_DATA *lpd)
1951char *cstr, *bstr, *fstr, *pstr, *xstr, *photometry;
1957 cmindex = 6 + lpd->
n;
1958 for (i = 0; i < lpd->
n; i++) {
1960 if ((cid = pdfdataGetCid(lpd, i)) == NULL)
1961 return ERROR_INT(
"cid not found", __func__, 1);
1964 if (var_WRITE_G4_IMAGE_MASK) {
1965 cstr = stringNew(
"/ImageMask true\n"
1966 "/ColorSpace /DeviceGray");
1968 cstr = stringNew(
"/ColorSpace /DeviceGray");
1970 bstr = stringNew(
"/BitsPerComponent 1\n"
1971 "/Interpolate true");
1978 photometry = (cid->
minisblack) ? stringNew(
"true")
1979 : stringNew(
"false");
1980 snprintf(buff,
sizeof(buff),
1981 "/Filter /CCITTFaxDecode\n"
1987 ">>", photometry, cid->
w);
1988 fstr = stringNew(buff);
1989 LEPT_FREE(photometry);
1992 cstr = stringNew(
"/ColorSpace /DeviceGray");
1993 else if (cid->
spp == 3)
1994 cstr = stringNew(
"/ColorSpace /DeviceRGB");
1995 else if (cid->
spp == 4)
1996 cstr = stringNew(
"/ColorSpace /DeviceCMYK");
1998 L_ERROR(
"in jpeg: spp != 1, 3 or 4\n", __func__);
1999 bstr = stringNew(
"/BitsPerComponent 8");
2000 fstr = stringNew(
"/Filter /DCTDecode");
2003 cstr = stringNew(
"/ColorSpace /DeviceGray");
2004 else if (cid->
spp == 3)
2005 cstr = stringNew(
"/ColorSpace /DeviceRGB");
2007 L_ERROR(
"in jp2k: spp != 1 && spp != 3\n", __func__);
2008 bstr = stringNew(
"/BitsPerComponent 8");
2009 fstr = stringNew(
"/Filter /JPXDecode");
2012 snprintf(buff,
sizeof(buff),
"/ColorSpace %d 0 R", cmindex++);
2013 cstr = stringNew(buff);
2015 if (cid->
spp == 1 && cid->
bps == 1)
2016 cstr = stringNew(
"/ColorSpace /DeviceGray\n"
2018 else if (cid->
spp == 1)
2019 cstr = stringNew(
"/ColorSpace /DeviceGray");
2020 else if (cid->
spp == 3)
2021 cstr = stringNew(
"/ColorSpace /DeviceRGB");
2023 L_ERROR(
"unknown colorspace: spp = %d\n",
2024 __func__, cid->
spp);
2026 snprintf(buff,
sizeof(buff),
"/BitsPerComponent %d", cid->
bps);
2027 bstr = stringNew(buff);
2028 fstr = stringNew(
"/Filter /FlateDecode");
2030 snprintf(buff,
sizeof(buff),
2036 " /BitsPerComponent %d\n"
2037 ">>\n", cid->
w, cid->
spp, cid->
bps);
2038 pstr = stringNew(buff);
2042 pstr = stringNew(
"");
2044 snprintf(buf,
sizeof(buf),
2058 cid->
w, cid->
h, bstr, fstr, pstr);
2059 xstr = stringNew(buf);
2060 sarrayAddString(sa, xstr,
L_INSERT);
2074generateColormapStringsPdf(L_PDF_DATA *lpd)
2078l_int32 i, cmindex, ncmap;
2086 cmindex = 6 + lpd->
n;
2088 for (i = 0; i < lpd->
n; i++) {
2089 if ((cid = pdfdataGetCid(lpd, i)) == NULL)
2090 return ERROR_INT(
"cid not found", __func__, 1);
2091 if (cid->
ncolors == 0)
continue;
2094 snprintf(buf,
sizeof(buf),
"%d 0 obj\n"
2095 "[ /Indexed /DeviceRGB\n"
2102 cmstr = stringNew(buf);
2103 l_dnaAddNumber(lpd->
objsize, strlen(cmstr));
2104 sarrayAddString(sa, cmstr,
L_INSERT);
2113generateTrailerPdf(L_PDF_DATA *lpd)
2115l_int32 i, n, size, linestart;
2116L_DNA *daloc, *dasize;
2139 l_dnaAddNumber(daloc, linestart);
2140 n = l_dnaGetCount(dasize);
2141 for (i = 0; i < n; i++) {
2142 l_dnaGetIValue(dasize, i, &size);
2144 l_dnaAddNumber(daloc, linestart);
2146 l_dnaGetIValue(daloc, n, &lpd->
xrefloc);
2149 lpd->
trailer = makeTrailerStringPdf(daloc);
2154makeTrailerStringPdf(
L_DNA *daloc)
2158l_int32 i, n, linestart, xrefloc;
2162 return (
char *)ERROR_PTR(
"daloc not defined", __func__, NULL);
2163 n = l_dnaGetCount(daloc) - 1;
2165 sa = sarrayCreate(0);
2166 snprintf(buf,
sizeof(buf),
"xref\n"
2168 "0000000000 65535 f \n", n);
2169 sarrayAddString(sa, buf,
L_COPY);
2170 for (i = 1; i < n; i++) {
2171 l_dnaGetIValue(daloc, i, &linestart);
2172 snprintf(buf,
sizeof(buf),
"%010d 00000 n \n", linestart);
2173 sarrayAddString(sa, buf,
L_COPY);
2176 l_dnaGetIValue(daloc, n, &xrefloc);
2177 snprintf(buf,
sizeof(buf),
"trailer\n"
2185 "%%%%EOF\n", n, xrefloc);
2186 sarrayAddString(sa, buf,
L_COPY);
2187 outstr = sarrayToString(sa, 0);
2213l_int32 nimages, i, len;
2214l_int32 *sizes, *locs;
2219 return ERROR_INT(
"&data not defined", __func__, 1);
2222 return ERROR_INT(
"&nbytes not defined", __func__, 1);
2225 if ((data = (l_uint8 *)LEPT_CALLOC(nbytes,
sizeof(l_uint8))) == NULL)
2226 return ERROR_INT(
"calloc fail for data", __func__, 1);
2229 sizes = l_dnaGetIArray(lpd->
objsize);
2230 locs = l_dnaGetIArray(lpd->
objloc);
2231 memcpy(data, lpd->
id, sizes[0]);
2232 memcpy(data + locs[1], lpd->
obj1, sizes[1]);
2233 memcpy(data + locs[2], lpd->
obj2, sizes[2]);
2234 memcpy(data + locs[3], lpd->
obj3, sizes[3]);
2235 memcpy(data + locs[4], lpd->
obj4, sizes[4]);
2236 memcpy(data + locs[5], lpd->
obj5, sizes[5]);
2241 for (i = 0; i < nimages; i++) {
2242 if ((cid = pdfdataGetCid(lpd, i)) == NULL) {
2245 return ERROR_INT(
"cid not found", __func__, 1);
2249 memcpy(data + locs[6 + i], str, len);
2250 memcpy(data + locs[6 + i] + len,
2252 memcpy(data + locs[6 + i] + len + cid->
nbytescomp,
2257 for (i = 0; i < lpd->
ncmap; i++) {
2259 memcpy(data + locs[6 + nimages + i], str, strlen(str));
2287l_int32 i, j, start, startloc, xrefloc, found, loc, nobj, objno, trailer_ok;
2289L_DNA *da, *daobj, *daxref;
2293 return ERROR_INT(
"&da not defined", __func__, 1);
2296 return ERROR_INT(
"bas not defined", __func__, 1);
2297 data = l_byteaGetData(bas, &size);
2298 if (memcmp(data,
"%PDF-1.", 7) != 0)
2299 return ERROR_INT(
"PDF header signature not found", __func__, 1);
2305 arrayFindSequence(data + start, size - start,
2306 (l_uint8 *)
"startxref\n", 10, &loc, &found);
2308 return ERROR_INT(
"startxref not found!", __func__, 1);
2309 if (sscanf((
char *)(data + start + loc + 10),
"%d\n", &xrefloc) != 1)
2310 return ERROR_INT(
"xrefloc not found!", __func__, 1);
2311 if (xrefloc < 0 || xrefloc >= size)
2312 return ERROR_INT(
"invalid xrefloc!", __func__, 1);
2313 sa = sarrayCreateLinesFromString((
char *)(data + xrefloc), 0);
2314 str = sarrayGetString(sa, 1,
L_NOCOPY);
2315 if ((sscanf(str,
"0 %d", &nobj)) != 1) {
2317 return ERROR_INT(
"nobj not found", __func__, 1);
2322 da = l_dnaCreate(nobj + 1);
2324 for (i = 0; i < nobj; i++) {
2325 str = sarrayGetString(sa, i + 2,
L_NOCOPY);
2326 sscanf(str,
"%d", &startloc);
2327 l_dnaAddNumber(da, startloc);
2329 l_dnaAddNumber(da, xrefloc);
2332 lept_stderr(
"************** Trailer string ************\n");
2333 lept_stderr(
"xrefloc = %d", xrefloc);
2334 sarrayWriteStderr(sa);
2336 lept_stderr(
"************** Object locations ************");
2337 l_dnaWriteStderr(da);
2343 for (i = 1; i < nobj; i++) {
2344 l_dnaGetIValue(da, i, &startloc);
2345 if ((sscanf((
char *)(data + startloc),
"%d 0 obj", &objno)) != 1) {
2346 L_ERROR(
"bad trailer for object %d\n", __func__, i);
2354 L_INFO(
"rebuilding pdf trailer\n", __func__);
2356 l_dnaAddNumber(da, 0);
2357 l_byteaFindEachSequence(bas, (l_uint8 *)
" 0 obj\n", 7, &daobj);
2358 nobj = l_dnaGetCount(daobj);
2359 for (i = 0; i < nobj; i++) {
2360 l_dnaGetIValue(daobj, i, &loc);
2361 for (j = loc - 1; j > 0; j--) {
2365 l_dnaAddNumber(da, j + 1);
2367 l_byteaFindEachSequence(bas, (l_uint8 *)
"xref", 4, &daxref);
2368 l_dnaGetIValue(daxref, 0, &loc);
2369 l_dnaAddNumber(da, loc);
2370 l_dnaDestroy(&daobj);
2371 l_dnaDestroy(&daxref);
2379generatePagesObjStringPdf(
NUMA *napage)
2383l_int32 i, n, index, bufsize;
2387 return (
char *)ERROR_PTR(
"napage not defined", __func__, NULL);
2389 n = numaGetCount(napage);
2390 bufsize = 100 + 16 * n;
2391 buf = (
char *)LEPT_CALLOC(bufsize,
sizeof(
char));
2392 sa = sarrayCreate(n);
2393 for (i = 0; i < n; i++) {
2394 numaGetIValue(napage, i, &index);
2395 snprintf(buf, bufsize,
" %d 0 R ", index);
2396 sarrayAddString(sa, buf,
L_COPY);
2399 str = sarrayToString(sa, 0);
2400 snprintf(buf, bufsize - 1,
"3 0 obj\n"
2438l_int32 start, nrepl, i, j, nobjs, objin, objout, found;
2439l_int32 *objs, *matches;
2445 return (
L_BYTEA *)ERROR_PTR(
"bas not defined", __func__, NULL);
2447 return (
L_BYTEA *)ERROR_PTR(
"na_objs not defined", __func__, NULL);
2449 datas = l_byteaGetData(bas, &size);
2450 bad = l_byteaCreate(100);
2451 objs = numaGetIArray(na_objs);
2452 nobjs = numaGetCount(na_objs);
2455 sscanf((
char *)datas,
"%d", &objin);
2456 if (objin < 0 || objin >= nobjs) {
2457 L_ERROR(
"index %d into array of size %d\n", __func__, objin, nobjs);
2461 objout = objs[objin];
2462 snprintf((
char *)buf, 32,
"%d", objout);
2463 l_byteaAppendString(bad, (
char *)buf);
2466 arrayFindSequence(datas, size, &space, 1, &start, &found);
2467 da_match = arrayFindEachSequence(datas, size, (l_uint8 *)
" 0 R", 4);
2469 l_byteaAppendData(bad, datas + start, size - start);
2475 nrepl = l_dnaGetCount(da_match);
2476 matches = l_dnaGetIArray(da_match);
2477 for (i = 0; i < nrepl; i++) {
2479 for (j = matches[i] - 1; j > 0; j--) {
2480 if (datas[j] == space)
2484 l_byteaAppendData(bad, datas + start, j - start + 1);
2485 sscanf((
char *)(datas + j + 1),
"%d", &objin);
2486 if (objin < 0 || objin >= nobjs) {
2487 L_ERROR(
"index %d into array of size %d\n", __func__, objin, nobjs);
2490 l_dnaDestroy(&da_match);
2493 objout = objs[objin];
2494 snprintf((
char *)buf, 32,
"%d", objout);
2495 l_byteaAppendString(bad, (
char *)buf);
2498 l_byteaAppendData(bad, datas + start, size - start);
2502 l_dnaDestroy(&da_match);
2511pdfdataCreate(
const char *title)
2515 lpd = (L_PDF_DATA *)LEPT_CALLOC(1,
sizeof(L_PDF_DATA));
2516 if (title) lpd->
title = stringNew(title);
2517 lpd->
cida = ptraCreate(10);
2518 lpd->
xy = ptaCreate(10);
2519 lpd->
wh = ptaCreate(10);
2520 lpd->
saprex = sarrayCreate(10);
2521 lpd->
sacmap = sarrayCreate(10);
2522 lpd->
objsize = l_dnaCreate(20);
2523 lpd->
objloc = l_dnaCreate(20);
2528pdfdataDestroy(L_PDF_DATA **plpd)
2535 L_WARNING(
"ptr address is null!\n", __func__);
2538 if ((lpd = *plpd) == NULL)
2542 for (i = 0; i < lpd->
n; i++) {
2547 ptraDestroy(&lpd->
cida, 0, 0);
2548 if (lpd->
id) LEPT_FREE(lpd->
id);
2549 if (lpd->
obj1) LEPT_FREE(lpd->
obj1);
2550 if (lpd->
obj2) LEPT_FREE(lpd->
obj2);
2551 if (lpd->
obj3) LEPT_FREE(lpd->
obj3);
2552 if (lpd->
obj4) LEPT_FREE(lpd->
obj4);
2553 if (lpd->
obj5) LEPT_FREE(lpd->
obj5);
2556 if (lpd->
xy) ptaDestroy(&lpd->
xy);
2557 if (lpd->
wh) ptaDestroy(&lpd->
wh);
2569pdfdataGetCid(L_PDF_DATA *lpd,
2573 return (L_COMP_DATA *)ERROR_PTR(
"lpd not defined", __func__, NULL);
2574 if (index < 0 || index >= lpd->
n)
2575 return (L_COMP_DATA *)ERROR_PTR(
"invalid image index", __func__, NULL);
2577 return (L_COMP_DATA *)ptraGetPtrToItem(lpd->
cida, index);
2601 var_WRITE_G4_IMAGE_MASK = flag;
2621 var_WRITE_DATE_AND_VERSION = flag;
void l_CIDataDestroy(L_COMP_DATA **pcid)
l_CIDataDestroy()
L_COMP_DATA * l_generateJpegDataMem(l_uint8 *data, size_t nbytes, l_int32 ascii85flag)
l_generateJpegDataMem()
l_ok pixGenerateCIData(PIX *pixs, l_int32 type, l_int32 quality, l_int32 ascii85, L_COMP_DATA **pcid)
pixGenerateCIData()
static L_COMP_DATA * pixGenerateFlateData(PIX *pixs, l_int32 ascii85flag)
pixGenerateFlateData()
L_COMP_DATA * l_generateFlateData(const char *fname, l_int32 ascii85flag)
l_generateFlateData()
l_ok pixConvertToPdfData(PIX *pix, l_int32 type, l_int32 quality, l_uint8 **pdata, size_t *pnbytes, l_int32 x, l_int32 y, l_int32 res, const char *title, L_PDF_DATA **plpd, l_int32 position)
pixConvertToPdfData()
L_COMP_DATA * l_generateJpegData(const char *fname, l_int32 ascii85flag)
l_generateJpegData()
static char * generateEscapeString(const char *str)
generateEscapeString()
L_COMP_DATA * l_generateG4Data(const char *fname, l_int32 ascii85flag)
l_generateG4Data()
static L_COMP_DATA * pixGenerateJpegData(PIX *pixs, l_int32 ascii85flag, l_int32 quality)
pixGenerateJpegData()
void l_pdfSetDateAndVersion(l_int32 flag)
l_pdfSetDateAndVersion()
static L_BYTEA * substituteObjectNumbers(L_BYTEA *bas, NUMA *na_objs)
substituteObjectNumbers()
l_ok convertTiffMultipageToPdf(const char *filein, const char *fileout)
convertTiffMultipageToPdf()
l_ok l_generateCIData(const char *fname, l_int32 type, l_int32 quality, l_int32 ascii85, L_COMP_DATA **pcid)
l_generateCIData()
l_ok ptraConcatenatePdfToData(L_PTRA *pa_data, SARRAY *sa, l_uint8 **pdata, size_t *pnbytes)
ptraConcatenatePdfToData()
static l_int32 parseTrailerPdf(L_BYTEA *bas, L_DNA **pda)
parseTrailerPdf()
static L_COMP_DATA * pixGenerateG4Data(PIX *pixs, l_int32 ascii85flag)
pixGenerateG4Data()
void l_pdfSetG4ImageMask(l_int32 flag)
l_pdfSetG4ImageMask()
l_ok cidConvertToPdfData(L_COMP_DATA *cid, const char *title, l_uint8 **pdata, size_t *pnbytes)
cidConvertToPdfData()
static L_COMP_DATA * l_generateJp2kData(const char *fname)
l_generateJp2kData()
L_COMP_DATA * l_generateFlateDataPdf(const char *fname, PIX *pixs)
l_generateFlateDataPdf()
static l_int32 l_generatePdf(l_uint8 **pdata, size_t *pnbytes, L_PDF_DATA *lpd)
l_generatePdf()
l_ok l_generateCIDataForPdf(const char *fname, PIX *pix, l_int32 quality, L_COMP_DATA **pcid)
l_generateCIDataForPdf()
static l_int32 generateOutputDataPdf(l_uint8 **pdata, size_t *pnbytes, L_PDF_DATA *lpd)
generateOutputDataPdf()
static L_COMP_DATA * pixGenerateJp2kData(PIX *pixs, l_int32 quality)
pixGenerateJp2kData()
struct PixColormap PIXCMAP