152#include <config_auto.h>
156#include "allheaders.h"
160static const l_uint32 MaxPtrArraySize = 1000000;
164static const size_t MaxDataSize = 1000000000;
167extern l_int32 NumImageFileFormatExtensions;
168extern const char *ImageFileFormatExtensions[];
173 l_uint8 **pdata,
size_t *pnbytes);
205 return (
PIXC *)ERROR_PTR(
"pix not defined", __func__, NULL);
206 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
207 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
208 return (
PIXC *)ERROR_PTR(
"invalid comptype", __func__, NULL);
210 pixc = (
PIXC *)LEPT_CALLOC(1,
sizeof(
PIXC));
211 pixGetDimensions(pix, &pixc->
w, &pixc->
h, &pixc->
d);
212 pixGetResolution(pix, &pixc->
xres, &pixc->
yres);
213 if (pixGetColormap(pix))
215 if ((text = pixGetText(pix)) != NULL)
216 pixc->
text = stringNew(text);
220 ret = pixWriteMem(&data, &size, pix, format);
222 L_ERROR(
"write to memory failed\n", __func__);
253l_int32 format, w, h, d, bps, spp, iscmap;
257 return (
PIXC *)ERROR_PTR(
"data not defined", __func__, NULL);
259 return (
PIXC *)ERROR_PTR(
"invalid copyflag", __func__, NULL);
261 if (pixReadHeaderMem(data, size, &format, &w, &h, &bps, &spp, &iscmap) == 1)
262 return (
PIXC *)ERROR_PTR(
"header data not read", __func__, NULL);
263 pixc = (
PIXC *)LEPT_CALLOC(1,
sizeof(
PIXC));
264 d = (spp == 3) ? 32 : bps * spp;
273 pixc->
data = l_binaryCopy(data, size);
305 return (
PIXC *)ERROR_PTR(
"filename not defined", __func__, NULL);
306 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
307 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
308 return (
PIXC *)ERROR_PTR(
"invalid comptype", __func__, NULL);
310 findFileFormat(filename, &format);
311 if (format == IFF_UNKNOWN) {
312 L_ERROR(
"unreadable file: %s\n", __func__, filename);
320 if ((format == IFF_TIFF_G4 && comptype != IFF_PNG) ||
321 (format == IFF_JFIF_JPEG && comptype != IFF_PNG))
323 if (comptype != IFF_DEFAULT && comptype == format) {
324 data = l_binaryRead(filename, &nbytes);
327 return (
PIXC *)ERROR_PTR(
"pixc not made (string)", __func__, NULL);
333 if ((pix = pixRead(filename)) == NULL)
334 return (
PIXC *)ERROR_PTR(
"pix not read", __func__, NULL);
337 return (
PIXC *)ERROR_PTR(
"pixc not made", __func__, NULL);
361 L_WARNING(
"ptr address is null!\n", __func__);
365 if ((pixc = *ppixc) == NULL)
368 LEPT_FREE(pixc->
data);
370 LEPT_FREE(pixc->
text);
391l_uint8 *datas, *datad;
395 return (
PIXC *)ERROR_PTR(
"pixcs not defined", __func__, NULL);
397 if (size > MaxDataSize)
398 return (
PIXC *)ERROR_PTR(
"size > 1 GB; too big", __func__, NULL);
400 pixcd = (
PIXC *)LEPT_CALLOC(1,
sizeof(
PIXC));
407 if (pixcs->
text != NULL)
408 pixcd->
text = stringNew(pixcs->
text);
413 if ((datad = (l_uint8 *)LEPT_CALLOC(size,
sizeof(l_int8))) == NULL) {
415 return (
PIXC *)ERROR_PTR(
"pixcd not made", __func__, NULL);
417 memcpy(datad, datas, size);
441 return ERROR_INT(
"pixc not defined", __func__, 1);
442 if (pw) *pw = pixc->
w;
443 if (ph) *ph = pixc->
h;
444 if (pd) *pd = pixc->
d;
464 return ERROR_INT(
"pixc not defined", __func__, 1);
465 if (pxres) *pxres = pixc->
xres;
466 if (pyres) *pyres = pixc->
yres;
467 if (pcomptype) *pcomptype = pixc->
comptype;
468 if (pcmapflag) *pcmapflag = pixc->
cmapflag;
508 return ERROR_INT(
"&format not defined", __func__, 1);
510 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
511 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
512 return ERROR_INT(
"invalid comptype", __func__, 1);
514 if (comptype == IFF_DEFAULT) {
516 *pformat = IFF_TIFF_G4;
519 else if (d >= 8 && !cmapflag)
520 *pformat = IFF_JFIF_JPEG;
521 }
else if (comptype == IFF_TIFF_G4 && d == 1) {
522 *pformat = IFF_TIFF_G4;
523 }
else if (comptype == IFF_JFIF_JPEG && d >= 8 && !cmapflag) {
524 *pformat = IFF_JFIF_JPEG;
543l_int32 w, h, d, cmapinpix, format;
547 return (
PIX *)ERROR_PTR(
"pixc not defined", __func__, NULL);
549 if ((pix = pixReadMem(pixc->
data, pixc->
size)) == NULL)
550 return (
PIX *)ERROR_PTR(
"pix not read", __func__, NULL);
551 pixSetResolution(pix, pixc->
xres, pixc->
yres);
553 pixSetText(pix, pixc->
text);
556 pixGetDimensions(pix, &w, &h, &d);
558 L_INFO(
"pix width %d != pixc width %d\n", __func__, w, pixc->
w);
559 L_ERROR(
"pix width %d != pixc width\n", __func__, w);
562 L_ERROR(
"pix height %d != pixc height\n", __func__, h);
565 L_WARNING(
"pix depth %d != pixc depth 16\n", __func__, d);
567 L_ERROR(
"pix depth %d != pixc depth\n", __func__, d);
569 cmapinpix = (pixGetColormap(pix) != NULL);
571 L_ERROR(
"pix cmap flag inconsistent\n", __func__);
572 format = pixGetInputFormat(pix);
574 L_ERROR(
"pix comptype %d not equal to pixc comptype\n",
596 if (n <= 0 || n > (l_int32)MaxPtrArraySize)
599 pixac = (
PIXAC *)LEPT_CALLOC(1,
sizeof(
PIXAC));
603 if ((pixac->
pixc = (
PIXC **)LEPT_CALLOC(n,
sizeof(
PIXC *))) == NULL) {
605 return (
PIXAC *)ERROR_PTR(
"pixc ptrs not made", __func__, NULL);
607 if ((pixac->
boxa = boxaCreate(n)) == NULL) {
609 return (
PIXAC *)ERROR_PTR(
"boxa not made", __func__, NULL);
665 if (n <= 0 || n > (l_int32)MaxPtrArraySize)
666 return (
PIXAC *)ERROR_PTR(
"n out of valid bounds", __func__, NULL);
668 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
669 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
670 return (
PIXAC *)ERROR_PTR(
"invalid comptype", __func__, NULL);
672 comptype = IFF_TIFF_G4;
675 L_WARNING(
"offset < 0; setting to 0\n", __func__);
680 return (
PIXAC *)ERROR_PTR(
"pixac not made", __func__, NULL);
683 pixt = pixClone(pix);
685 pixt = pixCreate(1, 1, 1);
686 for (i = 0; i < n; i++) {
727 return (
PIXAC *)ERROR_PTR(
"pixa not defined", __func__, NULL);
728 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
729 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
730 return (
PIXAC *)ERROR_PTR(
"invalid comptype", __func__, NULL);
733 return (
PIXAC *)ERROR_PTR(
"invalid accesstype", __func__, NULL);
735 n = pixaGetCount(pixa);
737 return (
PIXAC *)ERROR_PTR(
"pixac not made", __func__, NULL);
738 for (i = 0; i < n; i++) {
739 pix = pixaGetPix(pixa, i,
L_CLONE);
743 if ((boxa = pixaGetBoxa(pixa, accesstype)) != NULL) {
744 boxaDestroy(&pixac->
boxa);
782 return (
PIXAC *)ERROR_PTR(
"dirname not defined", __func__, NULL);
783 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
784 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
785 return (
PIXAC *)ERROR_PTR(
"invalid comptype", __func__, NULL);
787 if ((sa = getSortedPathnamesInDirectory(dirname, substr, 0, 0)) == NULL)
788 return (
PIXAC *)ERROR_PTR(
"sa not made", __func__, NULL);
820 return (
PIXAC *)ERROR_PTR(
"sarray not defined", __func__, NULL);
821 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
822 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
823 return (
PIXAC *)ERROR_PTR(
"invalid comptype", __func__, NULL);
825 n = sarrayGetCount(sa);
827 for (i = 0; i < n; i++) {
828 str = sarrayGetString(sa, i,
L_NOCOPY);
830 L_ERROR(
"pixc not read from file: %s\n", __func__, str);
856 if (ppixac == NULL) {
857 L_WARNING(
"ptr address is NULL!\n", __func__);
861 if ((pixac = *ppixac) == NULL)
864 for (i = 0; i < pixac->
n; i++)
866 LEPT_FREE(pixac->
pixc);
867 boxaDestroy(&pixac->
boxa);
898l_int32 cmapflag, format;
902 return ERROR_INT(
"pixac not defined", __func__, 1);
904 return ERROR_INT(
"pix not defined", __func__, 1);
905 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
906 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
907 return ERROR_INT(
"invalid format", __func__, 1);
909 cmapflag = pixGetColormap(pix) ? 1 : 0;
912 return ERROR_INT(
"pixc not made", __func__, 1);
941 return ERROR_INT(
"pixac not defined", __func__, 1);
943 return ERROR_INT(
"pixc not defined", __func__, 1);
945 return ERROR_INT(
"invalid copyflag", __func__, 1);
950 return ERROR_INT(
"extension failed", __func__, 1);
954 pixac->
pixc[n] = pixc;
981size_t oldsize, newsize;
984 return ERROR_INT(
"pixac not defined", __func__, 1);
985 if (pixac->
nalloc > (l_int32)MaxPtrArraySize)
986 return ERROR_INT(
"pixac has too many ptrs", __func__, 1);
988 newsize = 2 * oldsize;
989 if (newsize > 8 * MaxPtrArraySize)
990 return ERROR_INT(
"newsize > 8 MB; too large", __func__, 1);
992 if ((pixac->
pixc = (
PIXC **)reallocNew((
void **)&pixac->
pixc,
993 oldsize, newsize)) == NULL)
994 return ERROR_INT(
"new ptr array not returned", __func__, 1);
996 boxaExtendArray(pixac->
boxa);
1028 return ERROR_INT(
"pixac not defined", __func__, 1);
1030 aindex = index - pixac->
offset;
1031 if (aindex < 0 || aindex >= n)
1032 return ERROR_INT(
"array index out of bounds", __func__, 1);
1034 return ERROR_INT(
"pix not defined", __func__, 1);
1035 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
1036 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
1037 return ERROR_INT(
"invalid format", __func__, 1);
1070 return ERROR_INT(
"pixac not defined", __func__, 1);
1072 aindex = index - pixac->
offset;
1073 if (aindex < 0 || aindex >= n)
1074 return ERROR_INT(
"array index out of bounds", __func__, 1);
1076 return ERROR_INT(
"pixc not defined", __func__, 1);
1080 pixac->
pixc[aindex] = pixc;
1100 return ERROR_INT(
"pixac not defined", __func__, 1);
1102 return ERROR_INT(
"box not defined", __func__, 1);
1104 return ERROR_INT(
"invalid copyflag", __func__, 1);
1106 boxaAddBox(pixac->
boxa, box, copyflag);
1124 return ERROR_INT(
"pixac not defined", __func__, 0);
1154 return (
PIXC *)ERROR_PTR(
"pixac not defined", __func__, NULL);
1156 return (
PIXC *)ERROR_PTR(
"invalid copyflag", __func__, NULL);
1157 aindex = index - pixac->
offset;
1158 if (aindex < 0 || aindex >= pixac->
n)
1159 return (
PIXC *)ERROR_PTR(
"array index not valid", __func__, NULL);
1162 return pixac->
pixc[aindex];
1189 return (
PIX *)ERROR_PTR(
"pixac not defined", __func__, NULL);
1190 aindex = index - pixac->
offset;
1191 if (aindex < 0 || aindex >= pixac->
n)
1192 return (
PIX *)ERROR_PTR(
"array index not valid", __func__, NULL);
1225 return ERROR_INT(
"pixac not defined", __func__, 1);
1226 aindex = index - pixac->
offset;
1227 if (aindex < 0 || aindex >= pixac->
n)
1228 return ERROR_INT(
"array index not valid", __func__, 1);
1230 if ((pixc = pixac->
pixc[aindex]) == NULL)
1231 return ERROR_INT(
"pixc not found!", __func__, 1);
1249 return (
BOXA *)ERROR_PTR(
"pixac not defined", __func__, NULL);
1251 return (
BOXA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
1254 return (
BOXA *)ERROR_PTR(
"invalid accesstype", __func__, NULL);
1256 return boxaCopy(pixac->
boxa, accesstype);
1270 return ERROR_INT(
"pixac not defined", __func__, 0);
1272 return boxaGetCount(pixac->
boxa);
1308 return (
BOX *)ERROR_PTR(
"pixac not defined", __func__, NULL);
1310 return (
BOX *)ERROR_PTR(
"boxa not defined", __func__, NULL);
1311 aindex = index - pixac->
offset;
1312 if (aindex < 0 || aindex >= pixac->
boxa->
n)
1313 return (
BOX *)ERROR_PTR(
"array index not valid", __func__, NULL);
1315 return (
BOX *)ERROR_PTR(
"invalid accesstype", __func__, NULL);
1317 box = pixac->
boxa->
box[aindex];
1319 if (accesstype ==
L_COPY)
1320 return boxCopy(box);
1322 return boxClone(box);
1356 return ERROR_INT(
"pixac not defined", __func__, 1);
1357 aindex = index - pixac->
offset;
1358 if (aindex < 0 || aindex >= pixac->
n)
1359 return ERROR_INT(
"array index not valid", __func__, 1);
1362 return ERROR_INT(
"box not found!", __func__, 1);
1363 boxGetGeometry(box, px, py, pw, ph);
1386 return ERROR_INT(
"pixac not defined", __func__, 0);
1410 return ERROR_INT(
"pixac not defined", __func__, 1);
1411 pixac->
offset = L_MAX(0, offset);
1437l_int32 i, n, offset;
1442 return (
PIXA *)ERROR_PTR(
"pixac not defined", __func__, NULL);
1445 return (
PIXA *)ERROR_PTR(
"invalid accesstype", __func__, NULL);
1450 if ((pixa = pixaCreate(n)) == NULL)
1451 return (
PIXA *)ERROR_PTR(
"pixa not made", __func__, NULL);
1452 for (i = 0; i < n; i++) {
1454 L_WARNING(
"pix %d not made\n", __func__, i);
1460 boxaDestroy(&pixa->
boxa);
1500 return ERROR_INT(
"pixacd not defined", __func__, 1);
1506 if (iend < 0 || iend >= n)
1509 return ERROR_INT(
"istart > iend; nothing to add", __func__, 1);
1511 for (i = istart; i <= iend; i++) {
1519 iend = L_MIN(iend, nb - 1);
1520 boxaJoin(boxad, boxas, istart, iend);
1521 boxaDestroy(&boxas);
1522 boxaDestroy(&boxad);
1544l_int32 i, n1, n2, n, nb1, nb2;
1550 return (
PIXAC *)ERROR_PTR(
"pixac1 not defined", __func__, NULL);
1552 return (
PIXAC *)ERROR_PTR(
"pixac2 not defined", __func__, NULL);
1557 return (
PIXAC *)ERROR_PTR(
"at least one input pixac is empty",
1560 L_WARNING(
"counts differ: %d != %d\n", __func__, n1, n2);
1565 for (i = 0; i < n; i++) {
1607 return (
PIXAC *)ERROR_PTR(
"filename not defined", __func__, NULL);
1609 if ((fp = fopenReadStream(filename)) == NULL)
1610 return (
PIXAC *)ERROR_PTR_1(
"stream not opened",
1611 filename, __func__, NULL);
1615 return (
PIXAC *)ERROR_PTR_1(
"pixac not read",
1616 filename, __func__, NULL);
1637l_int32 n, offset, i, w, h, d, ignore;
1638l_int32 comptype, cmapflag, version, xres, yres;
1645 return (
PIXAC *)ERROR_PTR(
"stream not defined", __func__, NULL);
1647 if (fscanf(fp,
"\nPixacomp Version %d\n", &version) != 1)
1648 return (
PIXAC *)ERROR_PTR(
"not a pixacomp file", __func__, NULL);
1650 return (
PIXAC *)ERROR_PTR(
"invalid pixacomp version", __func__, NULL);
1651 if (fscanf(fp,
"Number of pixcomp = %d\n", &n) != 1)
1652 return (
PIXAC *)ERROR_PTR(
"not a pixacomp file", __func__, NULL);
1653 if (fscanf(fp,
"Offset of index into array = %d", &offset) != 1)
1654 return (
PIXAC *)ERROR_PTR(
"offset not read", __func__, NULL);
1656 return (
PIXAC *)ERROR_PTR(
"num pixcomp ptrs < 0", __func__, NULL);
1657 if (n > (l_int32)MaxPtrArraySize)
1658 return (
PIXAC *)ERROR_PTR(
"too many pixcomp ptrs", __func__, NULL);
1659 if (n == 0) L_INFO(
"the pixacomp is empty\n", __func__);
1662 return (
PIXAC *)ERROR_PTR(
"pixac not made", __func__, NULL);
1663 if ((boxa = boxaReadStream(fp)) == NULL) {
1665 return (
PIXAC *)ERROR_PTR(
"boxa not made", __func__, NULL);
1667 boxaDestroy(&pixac->
boxa);
1671 for (i = 0; i < n; i++) {
1672 if (fscanf(fp,
"\nPixcomp[%d]: w = %d, h = %d, d = %d\n",
1673 &ignore, &w, &h, &d) != 4) {
1675 return (
PIXAC *)ERROR_PTR(
"dimension reading", __func__, NULL);
1677 if (fscanf(fp,
" comptype = %d, size = %zu, cmapflag = %d\n",
1678 &comptype, &size, &cmapflag) != 3) {
1680 return (
PIXAC *)ERROR_PTR(
"comptype/size reading", __func__, NULL);
1682 if (size > MaxDataSize) {
1684 L_ERROR(
"data size = %zu is too big", __func__, size);
1693 if (fgets(buf,
sizeof(buf), fp) == NULL) {
1695 return (
PIXAC *)ERROR_PTR(
"fgets read fail", __func__, NULL);
1697 if (sscanf(buf,
" xres = %d, yres = %d\n", &xres, &yres) != 2) {
1699 return (
PIXAC *)ERROR_PTR(
"read fail for res", __func__, NULL);
1701 if ((data = (l_uint8 *)LEPT_CALLOC(1, size)) == NULL) {
1703 return (
PIXAC *)ERROR_PTR(
"calloc fail for data", __func__, NULL);
1705 if (fread(data, 1, size, fp) != size) {
1708 return (
PIXAC *)ERROR_PTR(
"error reading data", __func__, NULL);
1711 pixc = (
PIXC *)LEPT_CALLOC(1,
sizeof(
PIXC));
1747 return (
PIXAC *)ERROR_PTR(
"data not defined", __func__, NULL);
1748 if ((fp = fopenReadFromMemory(data, size)) == NULL)
1749 return (
PIXAC *)ERROR_PTR(
"stream not opened", __func__, NULL);
1753 if (!pixac) L_ERROR(
"pixac not read\n", __func__);
1780 return ERROR_INT(
"filename not defined", __func__, 1);
1782 return ERROR_INT(
"pixacomp not defined", __func__, 1);
1784 if ((fp = fopenWriteStream(filename,
"wb")) == NULL)
1785 return ERROR_INT_1(
"stream not opened", filename, __func__, 1);
1789 return ERROR_INT_1(
"pixacomp not written to stream",
1790 filename, __func__, 1);
1810 return ERROR_INT(
"stream not defined", __func__, 1);
1812 return ERROR_INT(
"pixac not defined", __func__, 1);
1816 fprintf(fp,
"Number of pixcomp = %d\n", n);
1817 fprintf(fp,
"Offset of index into array = %d", pixac->
offset);
1818 boxaWriteStream(fp, pixac->
boxa);
1819 for (i = 0; i < n; i++) {
1822 return ERROR_INT(
"pixc not found", __func__, 1);
1823 fprintf(fp,
"\nPixcomp[%d]: w = %d, h = %d, d = %d\n",
1824 i, pixc->
w, pixc->
h, pixc->
d);
1825 fprintf(fp,
" comptype = %d, size = %zu, cmapflag = %d\n",
1827 fprintf(fp,
" xres = %d, yres = %d\n", pixc->
xres, pixc->
yres);
1828 fwrite(pixc->
data, 1, pixc->
size, fp);
1856 if (pdata) *pdata = NULL;
1857 if (psize) *psize = 0;
1859 return ERROR_INT(
"&data not defined", __func__, 1);
1861 return ERROR_INT(
"&size not defined", __func__, 1);
1863 return ERROR_INT(
"&pixac not defined", __func__, 1);
1866 if ((fp = open_memstream((
char **)pdata, psize)) == NULL)
1867 return ERROR_INT(
"stream not opened", __func__, 1);
1871 if (*psize > 0) *psize = *psize - 1;
1873 L_INFO(
"no fmemopen API --> work-around: write to temp file\n", __func__);
1875 if ((fp = fopenWriteWinTempfile()) == NULL)
1876 return ERROR_INT(
"tmpfile stream not opened", __func__, 1);
1878 if ((fp = tmpfile()) == NULL)
1879 return ERROR_INT(
"tmpfile stream not opened", __func__, 1);
1883 *pdata = l_binaryReadStream(fp, psize);
1928 l_float32 scalefactor,
1932 const char *fileout)
1939 return ERROR_INT(
"pixac not defined", __func__, 1);
1942 title, &data, &nbytes);
1945 return ERROR_INT(
"conversion to pdf failed", __func__, 1);
1948 ret = l_binaryWrite(fileout,
"w", data, nbytes);
1951 L_ERROR(
"pdf data not written to file\n", __func__);
1979 l_float32 scalefactor,
1987l_int32 i, n, ret, scaledres, pagetype;
1994 return ERROR_INT(
"&data not defined", __func__, 1);
1997 return ERROR_INT(
"&nbytes not defined", __func__, 1);
2000 return ERROR_INT(
"pixac not defined", __func__, 1);
2001 if (scalefactor <= 0.0) scalefactor = 1.0;
2005 L_WARNING(
"invalid compression type; using per-page default\n",
2012 pa_data = ptraCreate(n);
2013 for (i = 0; i < n; i++) {
2016 L_ERROR(
"pix[%d] not retrieved\n", __func__, i);
2019 if (pixGetWidth(pixs) == 1) {
2020 L_INFO(
"placeholder image[%d] has w = 1\n", __func__, i);
2024 if (scalefactor != 1.0)
2025 pix = pixScale(pixs, scalefactor, scalefactor);
2027 pix = pixClone(pixs);
2029 scaledres = (l_int32)(res * scalefactor);
2034 }
else if (selectDefaultPdfEncoding(pix, &pagetype) != 0) {
2035 L_ERROR(
"encoding type selection failed for pix[%d]\n",
2041 ret = pixConvertToPdfData(pix, pagetype, quality, &imdata, &imbytes,
2042 0, 0, scaledres, title, NULL, 0);
2045 L_ERROR(
"pdf encoding failed for pix[%d]\n", __func__, i);
2048 ba = l_byteaInitFromMem(imdata, imbytes);
2050 ptraAdd(pa_data, ba);
2052 ptraGetActualCount(pa_data, &n);
2054 L_ERROR(
"no pdf files made\n", __func__);
2055 ptraDestroy(&pa_data, FALSE, FALSE);
2060 ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes);
2062 ptraGetActualCount(pa_data, &n);
2063 for (i = 0; i < n; i++) {
2065 l_byteaDestroy(&ba);
2067 ptraDestroy(&pa_data, FALSE, FALSE);
2097l_int32 i, n, ret, comptype;
2104 return ERROR_INT(
"&data not defined", __func__, 1);
2107 return ERROR_INT(
"&nbytes not defined", __func__, 1);
2110 return ERROR_INT(
"pixac not defined", __func__, 1);
2114 pa_data = ptraCreate(n);
2115 for (i = 0; i < n; i++) {
2117 L_ERROR(
"pixc[%d] not retrieved\n", __func__, i);
2121 if (comptype != IFF_JFIF_JPEG) {
2122 L_ERROR(
"pixc[%d] not jpeg compressed\n", __func__, i);
2127 L_ERROR(
"pdf encoding failed for pixc[%d]\n", __func__, i);
2130 ba = l_byteaInitFromMem(imdata, imbytes);
2132 ptraAdd(pa_data, ba);
2134 ptraGetActualCount(pa_data, &n);
2136 L_ERROR(
"no pdf files made\n", __func__);
2137 ptraDestroy(&pa_data, FALSE, FALSE);
2142 ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes);
2145 ptraGetActualCount(pa_data, &n);
2146 for (i = 0; i < n; i++) {
2148 l_byteaDestroy(&ba);
2150 ptraDestroy(&pa_data, FALSE, FALSE);
2183 return ERROR_INT(
"&data not defined", __func__, 1);
2186 return ERROR_INT(
"&nbytes not defined", __func__, 1);
2189 return ERROR_INT(
"pixc not defined", __func__, 1);
2192 data = l_binaryCopy(pixc->
data, pixc->
size);
2193 cid = l_generateJpegDataMem(data, pixc->
size, 0);
2196 return cidConvertToPdfData(cid, title, pdata, pnbytes);
2216l_int32 i, n, nboxes;
2220 return ERROR_INT(
"fp not defined", __func__, 1);
2222 return ERROR_INT(
"pixac not defined", __func__, 1);
2225 fprintf(fp,
"Pixacomp Info for %s:\n", text);
2227 fprintf(fp,
"Pixacomp Info:\n");
2230 fprintf(fp,
"Number of pixcomp: %d\n", n);
2231 fprintf(fp,
"Size of pixcomp array alloc: %d\n", pixac->
nalloc);
2232 fprintf(fp,
"Offset of index into array: %d\n", pixac->
offset);
2234 fprintf(fp,
"Boxa has %d boxes\n", nboxes);
2236 fprintf(fp,
"Boxa is empty\n");
2237 for (i = 0; i < n; i++) {
2259 return ERROR_INT(
"fp not defined", __func__, 1);
2261 return ERROR_INT(
"pixc not defined", __func__, 1);
2264 fprintf(fp,
" Pixcomp Info for %s:", text);
2266 fprintf(fp,
" Pixcomp Info:");
2267 fprintf(fp,
" width = %d, height = %d, depth = %d\n",
2268 pixc->
w, pixc->
h, pixc->
d);
2269 fprintf(fp,
" xres = %d, yres = %d, size in bytes = %zu\n",
2272 fprintf(fp,
" has colormap\n");
2274 fprintf(fp,
" no colormap\n");
2275 if (pixc->
comptype < NumImageFileFormatExtensions) {
2276 fprintf(fp,
" comptype = %s (%d)\n",
2279 fprintf(fp,
" Error!! Invalid comptype index: %d\n", pixc->
comptype);
2320 return (
PIX *)ERROR_PTR(
"pixac not defined", __func__, NULL);
2323 return (
PIX *)ERROR_PTR(
"pixa not made", __func__, NULL);
2325 pixd = pixaDisplayTiledAndScaled(pixa, outdepth, tilewidth, ncols,
2326 background, spacing, border);
2348 return ERROR_INT(
"pixac not defined", __func__, 1);
2350 if (lept_mkdir(subdir) > 0)
2351 return ERROR_INT(
"invalid subdir", __func__, 1);
2354 for (i = 0; i < n; i++) {
2356 snprintf(buf,
sizeof(buf),
"/tmp/%s/%03d", subdir, i);
2362extern const char *ImageFileFormatExtensions[];
2384 return ERROR_INT(
"pixc not defined", __func__, 1);
2386 snprintf(buf,
sizeof(buf),
"%s.%s", rootname,
2387 ImageFileFormatExtensions[pixc->
comptype]);
2388 l_binaryWrite(buf,
"w", pixc->
data, pixc->
size);
#define PIXACOMP_VERSION_NUMBER
l_ok pixacompJoin(PIXAC *pixacd, PIXAC *pixacs, l_int32 istart, l_int32 iend)
pixacompJoin()
PIXAC * pixacompCreateFromFiles(const char *dirname, const char *substr, l_int32 comptype)
pixacompCreateFromFiles()
void pixacompDestroy(PIXAC **ppixac)
pixacompDestroy()
l_ok pixacompFastConvertToPdfData(PIXAC *pixac, const char *title, l_uint8 **pdata, size_t *pnbytes)
pixacompFastConvertToPdfData()
l_ok pixacompWriteStream(FILE *fp, PIXAC *pixac)
pixacompWriteStream()
l_ok pixacompWrite(const char *filename, PIXAC *pixac)
pixacompWrite()
void pixcompDestroy(PIXC **ppixc)
pixcompDestroy()
l_ok pixacompWriteMem(l_uint8 **pdata, size_t *psize, PIXAC *pixac)
pixacompWriteMem()
static const l_int32 InitialPtrArraySize
PIX * pixacompDisplayTiledAndScaled(PIXAC *pixac, l_int32 outdepth, l_int32 tilewidth, l_int32 ncols, l_int32 background, l_int32 spacing, l_int32 border)
pixacompDisplayTiledAndScaled()
PIXC * pixcompCreateFromFile(const char *filename, l_int32 comptype)
pixcompCreateFromFile()
BOXA * pixacompGetBoxa(PIXAC *pixac, l_int32 accesstype)
pixacompGetBoxa()
l_ok pixacompConvertToPdfData(PIXAC *pixac, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, l_uint8 **pdata, size_t *pnbytes)
pixacompConvertToPdfData()
PIXAC * pixacompReadStream(FILE *fp)
pixacompReadStream()
PIX * pixCreateFromPixcomp(PIXC *pixc)
pixCreateFromPixcomp()
PIXAC * pixacompCreateFromPixa(PIXA *pixa, l_int32 comptype, l_int32 accesstype)
pixacompCreateFromPixa()
l_int32 pixacompGetBoxaCount(PIXAC *pixac)
pixacompGetBoxaCount()
PIXC * pixacompGetPixcomp(PIXAC *pixac, l_int32 index, l_int32 copyflag)
pixacompGetPixcomp()
PIXAC * pixacompInterleave(PIXAC *pixac1, PIXAC *pixac2)
pixacompInterleave()
l_ok pixcompGetParameters(PIXC *pixc, l_int32 *pxres, l_int32 *pyres, l_int32 *pcomptype, l_int32 *pcmapflag)
pixcompGetParameters()
l_ok pixcompWriteFile(const char *rootname, PIXC *pixc)
pixcompWriteFile()
l_ok pixacompReplacePix(PIXAC *pixac, l_int32 index, PIX *pix, l_int32 comptype)
pixacompReplacePix()
PIXAC * pixacompRead(const char *filename)
pixacompRead()
PIXC * pixcompCreateFromPix(PIX *pix, l_int32 comptype)
pixcompCreateFromPix()
static l_int32 pixacompExtendArray(PIXAC *pixac)
pixacompExtendArray()
l_ok pixcompGetDimensions(PIXC *pixc, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixcompGetDimensions()
l_ok pixacompConvertToPdf(PIXAC *pixac, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, const char *fileout)
pixacompConvertToPdf()
l_ok pixacompSetOffset(PIXAC *pixac, l_int32 offset)
pixacompSetOffset()
static l_int32 pixcompFastConvertToPdfData(PIXC *pixc, const char *title, l_uint8 **pdata, size_t *pnbytes)
pixcompFastConvertToPdfData()
PIXAC * pixacompCreateWithInit(l_int32 n, l_int32 offset, PIX *pix, l_int32 comptype)
pixacompCreateWithInit()
l_ok pixacompWriteStreamInfo(FILE *fp, PIXAC *pixac, const char *text)
pixacompWriteStreamInfo()
PIXA * pixaCreateFromPixacomp(PIXAC *pixac, l_int32 accesstype)
pixaCreateFromPixacomp()
PIXC * pixcompCreateFromString(l_uint8 *data, size_t size, l_int32 copyflag)
pixcompCreateFromString()
l_ok pixacompGetBoxGeometry(PIXAC *pixac, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
pixacompGetBoxGeometry()
l_int32 pixacompGetOffset(PIXAC *pixac)
pixacompGetOffset()
l_int32 pixacompGetCount(PIXAC *pixac)
pixacompGetCount()
l_ok pixacompAddPix(PIXAC *pixac, PIX *pix, l_int32 comptype)
pixacompAddPix()
l_ok pixacompAddBox(PIXAC *pixac, BOX *box, l_int32 copyflag)
pixacompAddBox()
l_ok pixacompAddPixcomp(PIXAC *pixac, PIXC *pixc, l_int32 copyflag)
pixacompAddPixcomp()
l_ok pixcompDetermineFormat(l_int32 comptype, l_int32 d, l_int32 cmapflag, l_int32 *pformat)
pixcompDetermineFormat()
PIXAC * pixacompCreateFromSA(SARRAY *sa, l_int32 comptype)
pixacompCreateFromSA()
PIXAC * pixacompReadMem(const l_uint8 *data, size_t size)
pixacompReadMem()
l_ok pixacompWriteFiles(PIXAC *pixac, const char *subdir)
pixacompWriteFiles()
PIX * pixacompGetPix(PIXAC *pixac, l_int32 index)
pixacompGetPix()
BOX * pixacompGetBox(PIXAC *pixac, l_int32 index, l_int32 accesstype)
pixacompGetBox()
l_ok pixcompWriteStreamInfo(FILE *fp, PIXC *pixc, const char *text)
pixcompWriteStreamInfo()
l_ok pixacompReplacePixcomp(PIXAC *pixac, l_int32 index, PIXC *pixc)
pixacompReplacePixcomp()
l_ok pixacompGetPixDimensions(PIXAC *pixac, l_int32 index, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixacompGetPixDimensions()
PIXC * pixcompCopy(PIXC *pixcs)
pixcompCopy()
PIXAC * pixacompCreate(l_int32 n)
pixacompCreate()