Leptonica 1.82.0
Image processing and image analysis suite
pixcomp.c
Go to the documentation of this file.
1/*====================================================================*
2 - Copyright (C) 2001 Leptonica. All rights reserved.
3 -
4 - Redistribution and use in source and binary forms, with or without
5 - modification, are permitted provided that the following conditions
6 - are met:
7 - 1. Redistributions of source code must retain the above copyright
8 - notice, this list of conditions and the following disclaimer.
9 - 2. Redistributions in binary form must reproduce the above
10 - copyright notice, this list of conditions and the following
11 - disclaimer in the documentation and/or other materials
12 - provided with the distribution.
13 -
14 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *====================================================================*/
26
151#ifdef HAVE_CONFIG_H
152#include <config_auto.h>
153#endif /* HAVE_CONFIG_H */
154
155#include <string.h>
156#include "allheaders.h"
157
158 /* Bounds on pixacomp array size */
159static const l_uint32 MaxPtrArraySize = 1000000;
160static const l_int32 InitialPtrArraySize = 20;
162 /* Bound on size for a compressed data string */
163static const size_t MaxDataSize = 1000000000; /* 1 GB */
164
165 /* These two globals are defined in writefile.c */
166extern l_int32 NumImageFileFormatExtensions;
167extern const char *ImageFileFormatExtensions[];
168
169 /* Static functions */
170static l_int32 pixacompExtendArray(PIXAC *pixac);
171static l_int32 pixcompFastConvertToPdfData(PIXC *pixc, const char *title,
172 l_uint8 **pdata, size_t *pnbytes);
173
174
175/*---------------------------------------------------------------------*
176 * Pixcomp creation and destruction *
177 *---------------------------------------------------------------------*/
193PIXC *
195 l_int32 comptype)
196{
197size_t size;
198char *text;
199l_int32 ret, format;
200l_uint8 *data;
201PIXC *pixc;
202
203 PROCNAME("pixcompCreateFromPix");
204
205 if (!pix)
206 return (PIXC *)ERROR_PTR("pix not defined", procName, NULL);
207 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
208 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
209 return (PIXC *)ERROR_PTR("invalid comptype", procName, NULL);
210
211 pixc = (PIXC *)LEPT_CALLOC(1, sizeof(PIXC));
212 pixGetDimensions(pix, &pixc->w, &pixc->h, &pixc->d);
213 pixGetResolution(pix, &pixc->xres, &pixc->yres);
214 if (pixGetColormap(pix))
215 pixc->cmapflag = 1;
216 if ((text = pixGetText(pix)) != NULL)
217 pixc->text = stringNew(text);
218
219 pixcompDetermineFormat(comptype, pixc->d, pixc->cmapflag, &format);
220 pixc->comptype = format;
221 ret = pixWriteMem(&data, &size, pix, format);
222 if (ret) {
223 L_ERROR("write to memory failed\n", procName);
224 pixcompDestroy(&pixc);
225 return NULL;
226 }
227 pixc->data = data;
228 pixc->size = size;
229
230 return pixc;
231}
232
233
249PIXC *
251 size_t size,
252 l_int32 copyflag)
253{
254l_int32 format, w, h, d, bps, spp, iscmap;
255PIXC *pixc;
256
257 PROCNAME("pixcompCreateFromString");
258
259 if (!data)
260 return (PIXC *)ERROR_PTR("data not defined", procName, NULL);
261 if (copyflag != L_INSERT && copyflag != L_COPY)
262 return (PIXC *)ERROR_PTR("invalid copyflag", procName, NULL);
263
264 if (pixReadHeaderMem(data, size, &format, &w, &h, &bps, &spp, &iscmap) == 1)
265 return (PIXC *)ERROR_PTR("header data not read", procName, NULL);
266 pixc = (PIXC *)LEPT_CALLOC(1, sizeof(PIXC));
267 d = (spp == 3) ? 32 : bps * spp;
268 pixc->w = w;
269 pixc->h = h;
270 pixc->d = d;
271 pixc->comptype = format;
272 pixc->cmapflag = iscmap;
273 if (copyflag == L_INSERT)
274 pixc->data = data;
275 else
276 pixc->data = l_binaryCopy(data, size);
277 pixc->size = size;
278 return pixc;
279}
280
281
297PIXC *
298pixcompCreateFromFile(const char *filename,
299 l_int32 comptype)
300{
301l_int32 format;
302size_t nbytes;
303l_uint8 *data;
304PIX *pix;
305PIXC *pixc;
306
307 PROCNAME("pixcompCreateFromFile");
308
309 if (!filename)
310 return (PIXC *)ERROR_PTR("filename not defined", procName, NULL);
311 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
312 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
313 return (PIXC *)ERROR_PTR("invalid comptype", procName, NULL);
314
315 findFileFormat(filename, &format);
316 if (format == IFF_UNKNOWN) {
317 L_ERROR("unreadable file: %s\n", procName, filename);
318 return NULL;
319 }
320
321 /* Can we accept the encoded file directly? Remember that
322 * png is the "universal" compression type, so if requested
323 * it takes precedence. Otherwise, if the file is already
324 * compressed in g4 or jpeg, just accept the string. */
325 if ((format == IFF_TIFF_G4 && comptype != IFF_PNG) ||
326 (format == IFF_JFIF_JPEG && comptype != IFF_PNG))
327 comptype = format;
328 if (comptype != IFF_DEFAULT && comptype == format) {
329 data = l_binaryRead(filename, &nbytes);
330 if ((pixc = pixcompCreateFromString(data, nbytes, L_INSERT)) == NULL) {
331 LEPT_FREE(data);
332 return (PIXC *)ERROR_PTR("pixc not made (string)", procName, NULL);
333 }
334 return pixc;
335 }
336
337 /* Need to recompress in the default format */
338 if ((pix = pixRead(filename)) == NULL)
339 return (PIXC *)ERROR_PTR("pix not read", procName, NULL);
340 if ((pixc = pixcompCreateFromPix(pix, comptype)) == NULL) {
341 pixDestroy(&pix);
342 return (PIXC *)ERROR_PTR("pixc not made", procName, NULL);
343 }
344 pixDestroy(&pix);
345 return pixc;
346}
347
348
360void
362{
363PIXC *pixc;
364
365 PROCNAME("pixcompDestroy");
366
367 if (!ppixc) {
368 L_WARNING("ptr address is null!\n", procName);
369 return;
370 }
371
372 if ((pixc = *ppixc) == NULL)
373 return;
374
375 LEPT_FREE(pixc->data);
376 if (pixc->text)
377 LEPT_FREE(pixc->text);
378 LEPT_FREE(pixc);
379 *ppixc = NULL;
380}
381
382
394PIXC *
396{
397size_t size;
398l_uint8 *datas, *datad;
399PIXC *pixcd;
400
401 PROCNAME("pixcompCopy");
402
403 if (!pixcs)
404 return (PIXC *)ERROR_PTR("pixcs not defined", procName, NULL);
405 size = pixcs->size;
406 if (size > MaxDataSize)
407 return (PIXC *)ERROR_PTR("size > 1 GB; too big", procName, NULL);
408
409 pixcd = (PIXC *)LEPT_CALLOC(1, sizeof(PIXC));
410 pixcd->w = pixcs->w;
411 pixcd->h = pixcs->h;
412 pixcd->d = pixcs->d;
413 pixcd->xres = pixcs->xres;
414 pixcd->yres = pixcs->yres;
415 pixcd->comptype = pixcs->comptype;
416 if (pixcs->text != NULL)
417 pixcd->text = stringNew(pixcs->text);
418 pixcd->cmapflag = pixcs->cmapflag;
419
420 /* Copy image data */
421 datas = pixcs->data;
422 if ((datad = (l_uint8 *)LEPT_CALLOC(size, sizeof(l_int8))) == NULL) {
423 pixcompDestroy(&pixcd);
424 return (PIXC *)ERROR_PTR("pixcd not made", procName, NULL);
425 }
426 memcpy(datad, datas, size);
427 pixcd->data = datad;
428 pixcd->size = size;
429 return pixcd;
430}
431
432
433/*---------------------------------------------------------------------*
434 * Pixcomp accessors *
435 *---------------------------------------------------------------------*/
443l_ok
445 l_int32 *pw,
446 l_int32 *ph,
447 l_int32 *pd)
448{
449 PROCNAME("pixcompGetDimensions");
450
451 if (!pixc)
452 return ERROR_INT("pixc not defined", procName, 1);
453 if (pw) *pw = pixc->w;
454 if (ph) *ph = pixc->h;
455 if (pd) *pd = pixc->d;
456 return 0;
457}
458
459
467l_ok
469 l_int32 *pxres,
470 l_int32 *pyres,
471 l_int32 *pcomptype,
472 l_int32 *pcmapflag)
473{
474 PROCNAME("pixcompGetParameters");
475
476 if (!pixc)
477 return ERROR_INT("pixc not defined", procName, 1);
478 if (pxres) *pxres = pixc->xres;
479 if (pyres) *pyres = pixc->yres;
480 if (pcomptype) *pcomptype = pixc->comptype;
481 if (pcmapflag) *pcmapflag = pixc->cmapflag;
482 return 0;
483}
484
485
486/*---------------------------------------------------------------------*
487 * Pixcomp compression selection *
488 *---------------------------------------------------------------------*/
513l_ok
514pixcompDetermineFormat(l_int32 comptype,
515 l_int32 d,
516 l_int32 cmapflag,
517 l_int32 *pformat)
518{
519
520 PROCNAME("pixcompDetermineFormat");
521
522 if (!pformat)
523 return ERROR_INT("&format not defined", procName, 1);
524 *pformat = IFF_PNG; /* init value and default */
525 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
526 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
527 return ERROR_INT("invalid comptype", procName, 1);
528
529 if (comptype == IFF_DEFAULT) {
530 if (d == 1)
531 *pformat = IFF_TIFF_G4;
532 else if (d == 16)
533 *pformat = IFF_PNG;
534 else if (d >= 8 && !cmapflag)
535 *pformat = IFF_JFIF_JPEG;
536 } else if (comptype == IFF_TIFF_G4 && d == 1) {
537 *pformat = IFF_TIFF_G4;
538 } else if (comptype == IFF_JFIF_JPEG && d >= 8 && !cmapflag) {
539 *pformat = IFF_JFIF_JPEG;
540 }
541
542 return 0;
543}
544
545
546/*---------------------------------------------------------------------*
547 * Pixcomp conversion to Pix *
548 *---------------------------------------------------------------------*/
555PIX *
557{
558l_int32 w, h, d, cmapinpix, format;
559PIX *pix;
560
561 PROCNAME("pixCreateFromPixcomp");
562
563 if (!pixc)
564 return (PIX *)ERROR_PTR("pixc not defined", procName, NULL);
565
566 if ((pix = pixReadMem(pixc->data, pixc->size)) == NULL)
567 return (PIX *)ERROR_PTR("pix not read", procName, NULL);
568 pixSetResolution(pix, pixc->xres, pixc->yres);
569 if (pixc->text)
570 pixSetText(pix, pixc->text);
571
572 /* Check fields for consistency */
573 pixGetDimensions(pix, &w, &h, &d);
574 if (pixc->w != w) {
575 L_INFO("pix width %d != pixc width %d\n", procName, w, pixc->w);
576 L_ERROR("pix width %d != pixc width\n", procName, w);
577 }
578 if (pixc->h != h)
579 L_ERROR("pix height %d != pixc height\n", procName, h);
580 if (pixc->d != d) {
581 if (pixc->d == 16) /* we strip 16 --> 8 bpp by default */
582 L_WARNING("pix depth %d != pixc depth 16\n", procName, d);
583 else
584 L_ERROR("pix depth %d != pixc depth\n", procName, d);
585 }
586 cmapinpix = (pixGetColormap(pix) != NULL);
587 if ((cmapinpix && !pixc->cmapflag) || (!cmapinpix && pixc->cmapflag))
588 L_ERROR("pix cmap flag inconsistent\n", procName);
589 format = pixGetInputFormat(pix);
590 if (format != pixc->comptype) {
591 L_ERROR("pix comptype %d not equal to pixc comptype\n",
592 procName, format);
593 }
594
595 return pix;
596}
597
598
599/*---------------------------------------------------------------------*
600 * Pixacomp creation and destruction *
601 *---------------------------------------------------------------------*/
608PIXAC *
610{
611PIXAC *pixac;
612
613 PROCNAME("pixacompCreate");
614
615 if (n <= 0 || n > MaxPtrArraySize)
617
618 pixac = (PIXAC *)LEPT_CALLOC(1, sizeof(PIXAC));
619 pixac->n = 0;
620 pixac->nalloc = n;
621 pixac->offset = 0;
622 if ((pixac->pixc = (PIXC **)LEPT_CALLOC(n, sizeof(PIXC *))) == NULL) {
623 pixacompDestroy(&pixac);
624 return (PIXAC *)ERROR_PTR("pixc ptrs not made", procName, NULL);
625 }
626 if ((pixac->boxa = boxaCreate(n)) == NULL) {
627 pixacompDestroy(&pixac);
628 return (PIXAC *)ERROR_PTR("boxa not made", procName, NULL);
629 }
630
631 return pixac;
632}
633
634
673PIXAC *
675 l_int32 offset,
676 PIX *pix,
677 l_int32 comptype)
678{
679l_int32 i;
680PIX *pixt;
681PIXC *pixc;
682PIXAC *pixac;
683
684 PROCNAME("pixacompCreateWithInit");
685
686 if (n <= 0 || n > MaxPtrArraySize)
687 return (PIXAC *)ERROR_PTR("n out of valid bounds", procName, NULL);
688 if (pix) {
689 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
690 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
691 return (PIXAC *)ERROR_PTR("invalid comptype", procName, NULL);
692 } else {
693 comptype = IFF_TIFF_G4;
694 }
695 if (offset < 0) {
696 L_WARNING("offset < 0; setting to 0\n", procName);
697 offset = 0;
698 }
699
700 if ((pixac = pixacompCreate(n)) == NULL)
701 return (PIXAC *)ERROR_PTR("pixac not made", procName, NULL);
702 pixacompSetOffset(pixac, offset);
703 if (pix)
704 pixt = pixClone(pix);
705 else
706 pixt = pixCreate(1, 1, 1);
707 for (i = 0; i < n; i++) {
708 pixc = pixcompCreateFromPix(pixt, comptype);
709 pixacompAddPixcomp(pixac, pixc, L_INSERT);
710 }
711 pixDestroy(&pixt);
712
713 return pixac;
714}
715
716
737PIXAC *
739 l_int32 comptype,
740 l_int32 accesstype)
741{
742l_int32 i, n;
743BOXA *boxa;
744PIX *pix;
745PIXAC *pixac;
746
747 PROCNAME("pixacompCreateFromPixa");
748
749 if (!pixa)
750 return (PIXAC *)ERROR_PTR("pixa not defined", procName, NULL);
751 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
752 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
753 return (PIXAC *)ERROR_PTR("invalid comptype", procName, NULL);
754 if (accesstype != L_COPY && accesstype != L_CLONE &&
755 accesstype != L_COPY_CLONE)
756 return (PIXAC *)ERROR_PTR("invalid accesstype", procName, NULL);
757
758 n = pixaGetCount(pixa);
759 if ((pixac = pixacompCreate(n)) == NULL)
760 return (PIXAC *)ERROR_PTR("pixac not made", procName, NULL);
761 for (i = 0; i < n; i++) {
762 pix = pixaGetPix(pixa, i, L_CLONE);
763 pixacompAddPix(pixac, pix, comptype);
764 pixDestroy(&pix);
765 }
766 if ((boxa = pixaGetBoxa(pixa, accesstype)) != NULL) {
767 boxaDestroy(&pixac->boxa);
768 pixac->boxa = boxa;
769 }
770
771 return pixac;
772}
773
774
796PIXAC *
797pixacompCreateFromFiles(const char *dirname,
798 const char *substr,
799 l_int32 comptype)
800{
801PIXAC *pixac;
802SARRAY *sa;
803
804 PROCNAME("pixacompCreateFromFiles");
805
806 if (!dirname)
807 return (PIXAC *)ERROR_PTR("dirname not defined", procName, NULL);
808 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
809 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
810 return (PIXAC *)ERROR_PTR("invalid comptype", procName, NULL);
811
812 if ((sa = getSortedPathnamesInDirectory(dirname, substr, 0, 0)) == NULL)
813 return (PIXAC *)ERROR_PTR("sa not made", procName, NULL);
814 pixac = pixacompCreateFromSA(sa, comptype);
815 sarrayDestroy(&sa);
816 return pixac;
817}
818
819
835PIXAC *
837 l_int32 comptype)
838{
839char *str;
840l_int32 i, n;
841PIXC *pixc;
842PIXAC *pixac;
843
844 PROCNAME("pixacompCreateFromSA");
845
846 if (!sa)
847 return (PIXAC *)ERROR_PTR("sarray not defined", procName, NULL);
848 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
849 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
850 return (PIXAC *)ERROR_PTR("invalid comptype", procName, NULL);
851
852 n = sarrayGetCount(sa);
853 pixac = pixacompCreate(n);
854 for (i = 0; i < n; i++) {
855 str = sarrayGetString(sa, i, L_NOCOPY);
856 if ((pixc = pixcompCreateFromFile(str, comptype)) == NULL) {
857 L_ERROR("pixc not read from file: %s\n", procName, str);
858 continue;
859 }
860 pixacompAddPixcomp(pixac, pixc, L_INSERT);
861 }
862 return pixac;
863}
864
865
877void
879{
880l_int32 i;
881PIXAC *pixac;
882
883 PROCNAME("pixacompDestroy");
884
885 if (ppixac == NULL) {
886 L_WARNING("ptr address is NULL!\n", procName);
887 return;
888 }
889
890 if ((pixac = *ppixac) == NULL)
891 return;
892
893 for (i = 0; i < pixac->n; i++)
894 pixcompDestroy(&pixac->pixc[i]);
895 LEPT_FREE(pixac->pixc);
896 boxaDestroy(&pixac->boxa);
897 LEPT_FREE(pixac);
898 *ppixac = NULL;
899}
900
901
902/*---------------------------------------------------------------------*
903 * Pixacomp addition *
904 *---------------------------------------------------------------------*/
922l_ok
924 PIX *pix,
925 l_int32 comptype)
926{
927l_int32 cmapflag, format;
928PIXC *pixc;
929
930 PROCNAME("pixacompAddPix");
931
932 if (!pixac)
933 return ERROR_INT("pixac not defined", procName, 1);
934 if (!pix)
935 return ERROR_INT("pix not defined", procName, 1);
936 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
937 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
938 return ERROR_INT("invalid format", procName, 1);
939
940 cmapflag = pixGetColormap(pix) ? 1 : 0;
941 pixcompDetermineFormat(comptype, pixGetDepth(pix), cmapflag, &format);
942 if ((pixc = pixcompCreateFromPix(pix, format)) == NULL)
943 return ERROR_INT("pixc not made", procName, 1);
944 pixacompAddPixcomp(pixac, pixc, L_INSERT);
945 return 0;
946}
947
948
964l_ok
966 PIXC *pixc,
967 l_int32 copyflag)
968{
969l_int32 n;
970
971 PROCNAME("pixacompAddPixcomp");
972
973 if (!pixac)
974 return ERROR_INT("pixac not defined", procName, 1);
975 if (!pixc)
976 return ERROR_INT("pixc not defined", procName, 1);
977 if (copyflag != L_INSERT && copyflag != L_COPY)
978 return ERROR_INT("invalid copyflag", procName, 1);
979
980 n = pixac->n;
981 if (n >= pixac->nalloc) {
982 if (pixacompExtendArray(pixac))
983 return ERROR_INT("extension failed", procName, 1);
984 }
985
986 if (copyflag == L_INSERT)
987 pixac->pixc[n] = pixc;
988 else /* L_COPY */
989 pixac->pixc[n] = pixcompCopy(pixc);
990 pixac->n++;
991
992 return 0;
993}
994
995
1011static l_int32
1013{
1014size_t oldsize, newsize;
1015
1016 PROCNAME("pixacompExtendArray");
1017
1018 if (!pixac)
1019 return ERROR_INT("pixac not defined", procName, 1);
1020 if (pixac->nalloc > MaxPtrArraySize) /* belt & suspenders */
1021 return ERROR_INT("pixac has too many ptrs", procName, 1);
1022 oldsize = pixac->nalloc * sizeof(PIXC *);
1023 newsize = 2 * oldsize;
1024 if (newsize > 8 * MaxPtrArraySize) /* ptrs for 1M pixcomp */
1025 return ERROR_INT("newsize > 8 MB; too large", procName, 1);
1026
1027 if ((pixac->pixc = (PIXC **)reallocNew((void **)&pixac->pixc,
1028 oldsize, newsize)) == NULL)
1029 return ERROR_INT("new ptr array not returned", procName, 1);
1030 pixac->nalloc *= 2;
1031 boxaExtendArray(pixac->boxa);
1032 return 0;
1033}
1034
1035
1053l_ok
1055 l_int32 index,
1056 PIX *pix,
1057 l_int32 comptype)
1058{
1059l_int32 n, aindex;
1060PIXC *pixc;
1061
1062 PROCNAME("pixacompReplacePix");
1063
1064 if (!pixac)
1065 return ERROR_INT("pixac not defined", procName, 1);
1066 n = pixacompGetCount(pixac);
1067 aindex = index - pixac->offset;
1068 if (aindex < 0 || aindex >= n)
1069 return ERROR_INT("array index out of bounds", procName, 1);
1070 if (!pix)
1071 return ERROR_INT("pix not defined", procName, 1);
1072 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
1073 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
1074 return ERROR_INT("invalid format", procName, 1);
1075
1076 pixc = pixcompCreateFromPix(pix, comptype);
1077 pixacompReplacePixcomp(pixac, index, pixc);
1078 return 0;
1079}
1080
1081
1098l_ok
1100 l_int32 index,
1101 PIXC *pixc)
1102{
1103l_int32 n, aindex;
1104PIXC *pixct;
1105
1106 PROCNAME("pixacompReplacePixcomp");
1107
1108 if (!pixac)
1109 return ERROR_INT("pixac not defined", procName, 1);
1110 n = pixacompGetCount(pixac);
1111 aindex = index - pixac->offset;
1112 if (aindex < 0 || aindex >= n)
1113 return ERROR_INT("array index out of bounds", procName, 1);
1114 if (!pixc)
1115 return ERROR_INT("pixc not defined", procName, 1);
1116
1117 pixct = pixacompGetPixcomp(pixac, index, L_NOCOPY); /* use %index */
1118 pixcompDestroy(&pixct);
1119 pixac->pixc[aindex] = pixc; /* replace; use array index */
1120
1121 return 0;
1122}
1123
1124
1133l_ok
1135 BOX *box,
1136 l_int32 copyflag)
1137{
1138 PROCNAME("pixacompAddBox");
1139
1140 if (!pixac)
1141 return ERROR_INT("pixac not defined", procName, 1);
1142 if (!box)
1143 return ERROR_INT("box not defined", procName, 1);
1144 if (copyflag != L_INSERT && copyflag != L_COPY)
1145 return ERROR_INT("invalid copyflag", procName, 1);
1146
1147 boxaAddBox(pixac->boxa, box, copyflag);
1148 return 0;
1149}
1150
1151
1152/*---------------------------------------------------------------------*
1153 * Pixacomp accessors *
1154 *---------------------------------------------------------------------*/
1161l_int32
1163{
1164 PROCNAME("pixacompGetCount");
1165
1166 if (!pixac)
1167 return ERROR_INT("pixac not defined", procName, 0);
1168
1169 return pixac->n;
1170}
1171
1172
1189PIXC *
1191 l_int32 index,
1192 l_int32 copyflag)
1193{
1194l_int32 aindex;
1195
1196 PROCNAME("pixacompGetPixcomp");
1197
1198 if (!pixac)
1199 return (PIXC *)ERROR_PTR("pixac not defined", procName, NULL);
1200 if (copyflag != L_NOCOPY && copyflag != L_COPY)
1201 return (PIXC *)ERROR_PTR("invalid copyflag", procName, NULL);
1202 aindex = index - pixac->offset;
1203 if (aindex < 0 || aindex >= pixac->n)
1204 return (PIXC *)ERROR_PTR("array index not valid", procName, NULL);
1205
1206 if (copyflag == L_NOCOPY)
1207 return pixac->pixc[aindex];
1208 else /* L_COPY */
1209 return pixcompCopy(pixac->pixc[aindex]);
1210}
1211
1212
1226PIX *
1228 l_int32 index)
1229{
1230l_int32 aindex;
1231PIXC *pixc;
1232
1233 PROCNAME("pixacompGetPix");
1234
1235 if (!pixac)
1236 return (PIX *)ERROR_PTR("pixac not defined", procName, NULL);
1237 aindex = index - pixac->offset;
1238 if (aindex < 0 || aindex >= pixac->n)
1239 return (PIX *)ERROR_PTR("array index not valid", procName, NULL);
1240
1241 pixc = pixacompGetPixcomp(pixac, index, L_NOCOPY);
1242 return pixCreateFromPixcomp(pixc);
1243}
1244
1245
1261l_ok
1263 l_int32 index,
1264 l_int32 *pw,
1265 l_int32 *ph,
1266 l_int32 *pd)
1267{
1268l_int32 aindex;
1269PIXC *pixc;
1270
1271 PROCNAME("pixacompGetPixDimensions");
1272
1273 if (!pixac)
1274 return ERROR_INT("pixac not defined", procName, 1);
1275 aindex = index - pixac->offset;
1276 if (aindex < 0 || aindex >= pixac->n)
1277 return ERROR_INT("array index not valid", procName, 1);
1278
1279 if ((pixc = pixac->pixc[aindex]) == NULL)
1280 return ERROR_INT("pixc not found!", procName, 1);
1281 pixcompGetDimensions(pixc, pw, ph, pd);
1282 return 0;
1283}
1284
1285
1293BOXA *
1295 l_int32 accesstype)
1296{
1297 PROCNAME("pixacompGetBoxa");
1298
1299 if (!pixac)
1300 return (BOXA *)ERROR_PTR("pixac not defined", procName, NULL);
1301 if (!pixac->boxa)
1302 return (BOXA *)ERROR_PTR("boxa not defined", procName, NULL);
1303 if (accesstype != L_COPY && accesstype != L_CLONE &&
1304 accesstype != L_COPY_CLONE)
1305 return (BOXA *)ERROR_PTR("invalid accesstype", procName, NULL);
1306
1307 return boxaCopy(pixac->boxa, accesstype);
1308}
1309
1310
1317l_int32
1319{
1320 PROCNAME("pixacompGetBoxaCount");
1321
1322 if (!pixac)
1323 return ERROR_INT("pixac not defined", procName, 0);
1324
1325 return boxaGetCount(pixac->boxa);
1326}
1327
1328
1352BOX *
1354 l_int32 index,
1355 l_int32 accesstype)
1356{
1357l_int32 aindex;
1358BOX *box;
1359
1360 PROCNAME("pixacompGetBox");
1361
1362 if (!pixac)
1363 return (BOX *)ERROR_PTR("pixac not defined", procName, NULL);
1364 if (!pixac->boxa)
1365 return (BOX *)ERROR_PTR("boxa not defined", procName, NULL);
1366 aindex = index - pixac->offset;
1367 if (aindex < 0 || aindex >= pixac->boxa->n)
1368 return (BOX *)ERROR_PTR("array index not valid", procName, NULL);
1369 if (accesstype != L_COPY && accesstype != L_CLONE)
1370 return (BOX *)ERROR_PTR("invalid accesstype", procName, NULL);
1371
1372 box = pixac->boxa->box[aindex];
1373 if (box) {
1374 if (accesstype == L_COPY)
1375 return boxCopy(box);
1376 else /* accesstype == L_CLONE */
1377 return boxClone(box);
1378 } else {
1379 return NULL;
1380 }
1381}
1382
1383
1399l_ok
1401 l_int32 index,
1402 l_int32 *px,
1403 l_int32 *py,
1404 l_int32 *pw,
1405 l_int32 *ph)
1406{
1407l_int32 aindex;
1408BOX *box;
1409
1410 PROCNAME("pixacompGetBoxGeometry");
1411
1412 if (!pixac)
1413 return ERROR_INT("pixac not defined", procName, 1);
1414 aindex = index - pixac->offset;
1415 if (aindex < 0 || aindex >= pixac->n)
1416 return ERROR_INT("array index not valid", procName, 1);
1417
1418 if ((box = pixacompGetBox(pixac, aindex, L_CLONE)) == NULL)
1419 return ERROR_INT("box not found!", procName, 1);
1420 boxGetGeometry(box, px, py, pw, ph);
1421 boxDestroy(&box);
1422 return 0;
1423}
1424
1425
1439l_int32
1441{
1442 PROCNAME("pixacompGetOffset");
1443
1444 if (!pixac)
1445 return ERROR_INT("pixac not defined", procName, 0);
1446 return pixac->offset;
1447}
1448
1449
1464l_ok
1466 l_int32 offset)
1467{
1468 PROCNAME("pixacompSetOffset");
1469
1470 if (!pixac)
1471 return ERROR_INT("pixac not defined", procName, 1);
1472 pixac->offset = L_MAX(0, offset);
1473 return 0;
1474}
1475
1476
1477/*---------------------------------------------------------------------*
1478 * Pixacomp conversion to Pixa *
1479 *---------------------------------------------------------------------*/
1494PIXA *
1496 l_int32 accesstype)
1497{
1498l_int32 i, n, offset;
1499PIX *pix;
1500PIXA *pixa;
1501
1502 PROCNAME("pixaCreateFromPixacomp");
1503
1504 if (!pixac)
1505 return (PIXA *)ERROR_PTR("pixac not defined", procName, NULL);
1506 if (accesstype != L_COPY && accesstype != L_CLONE &&
1507 accesstype != L_COPY_CLONE)
1508 return (PIXA *)ERROR_PTR("invalid accesstype", procName, NULL);
1509
1510 n = pixacompGetCount(pixac);
1511 offset = pixacompGetOffset(pixac);
1512 pixacompSetOffset(pixac, 0);
1513 if ((pixa = pixaCreate(n)) == NULL)
1514 return (PIXA *)ERROR_PTR("pixa not made", procName, NULL);
1515 for (i = 0; i < n; i++) {
1516 if ((pix = pixacompGetPix(pixac, i)) == NULL) {
1517 L_WARNING("pix %d not made\n", procName, i);
1518 continue;
1519 }
1520 pixaAddPix(pixa, pix, L_INSERT);
1521 }
1522 if (pixa->boxa) {
1523 boxaDestroy(&pixa->boxa);
1524 pixa->boxa = pixacompGetBoxa(pixac, accesstype);
1525 }
1526 pixacompSetOffset(pixac, offset);
1527
1528 return pixa;
1529}
1530
1531
1532/*---------------------------------------------------------------------*
1533 * Combining pixacomp
1534 *---------------------------------------------------------------------*/
1552l_ok
1554 PIXAC *pixacs,
1555 l_int32 istart,
1556 l_int32 iend)
1557{
1558l_int32 i, n, nb;
1559BOXA *boxas, *boxad;
1560PIXC *pixc;
1561
1562 PROCNAME("pixacompJoin");
1563
1564 if (!pixacd)
1565 return ERROR_INT("pixacd not defined", procName, 1);
1566 if (!pixacs || ((n = pixacompGetCount(pixacs)) == 0))
1567 return 0;
1568
1569 if (istart < 0)
1570 istart = 0;
1571 if (iend < 0 || iend >= n)
1572 iend = n - 1;
1573 if (istart > iend)
1574 return ERROR_INT("istart > iend; nothing to add", procName, 1);
1575
1576 for (i = istart; i <= iend; i++) {
1577 pixc = pixacompGetPixcomp(pixacs, i, L_NOCOPY);
1578 pixacompAddPixcomp(pixacd, pixc, L_COPY);
1579 }
1580
1581 boxas = pixacompGetBoxa(pixacs, L_CLONE);
1582 boxad = pixacompGetBoxa(pixacd, L_CLONE);
1583 nb = pixacompGetBoxaCount(pixacs);
1584 iend = L_MIN(iend, nb - 1);
1585 boxaJoin(boxad, boxas, istart, iend);
1586 boxaDestroy(&boxas); /* just the clones */
1587 boxaDestroy(&boxad); /* ditto */
1588 return 0;
1589}
1590
1591
1605PIXAC *
1607 PIXAC *pixac2)
1608{
1609l_int32 i, n1, n2, n, nb1, nb2;
1610BOX *box;
1611PIXC *pixc1, *pixc2;
1612PIXAC *pixacd;
1613
1614 PROCNAME("pixacompInterleave");
1615
1616 if (!pixac1)
1617 return (PIXAC *)ERROR_PTR("pixac1 not defined", procName, NULL);
1618 if (!pixac2)
1619 return (PIXAC *)ERROR_PTR("pixac2 not defined", procName, NULL);
1620 n1 = pixacompGetCount(pixac1);
1621 n2 = pixacompGetCount(pixac2);
1622 n = L_MIN(n1, n2);
1623 if (n == 0)
1624 return (PIXAC *)ERROR_PTR("at least one input pixac is empty",
1625 procName, NULL);
1626 if (n1 != n2)
1627 L_WARNING("counts differ: %d != %d\n", procName, n1, n2);
1628
1629 pixacd = pixacompCreate(2 * n);
1630 nb1 = pixacompGetBoxaCount(pixac1);
1631 nb2 = pixacompGetBoxaCount(pixac2);
1632 for (i = 0; i < n; i++) {
1633 pixc1 = pixacompGetPixcomp(pixac1, i, L_COPY);
1634 pixacompAddPixcomp(pixacd, pixc1, L_INSERT);
1635 if (i < nb1) {
1636 box = pixacompGetBox(pixac1, i, L_COPY);
1637 pixacompAddBox(pixacd, box, L_INSERT);
1638 }
1639 pixc2 = pixacompGetPixcomp(pixac2, i, L_COPY);
1640 pixacompAddPixcomp(pixacd, pixc2, L_INSERT);
1641 if (i < nb2) {
1642 box = pixacompGetBox(pixac2, i, L_COPY);
1643 pixacompAddBox(pixacd, box, L_INSERT);
1644 }
1645 }
1646
1647 return pixacd;
1648}
1649
1650
1651/*---------------------------------------------------------------------*
1652 * Pixacomp serialized I/O *
1653 *---------------------------------------------------------------------*/
1667PIXAC *
1668pixacompRead(const char *filename)
1669{
1670FILE *fp;
1671PIXAC *pixac;
1672
1673 PROCNAME("pixacompRead");
1674
1675 if (!filename)
1676 return (PIXAC *)ERROR_PTR("filename not defined", procName, NULL);
1677
1678 if ((fp = fopenReadStream(filename)) == NULL)
1679 return (PIXAC *)ERROR_PTR("stream not opened", procName, NULL);
1680 pixac = pixacompReadStream(fp);
1681 fclose(fp);
1682 if (!pixac)
1683 return (PIXAC *)ERROR_PTR("pixac not read", procName, NULL);
1684 return pixac;
1685}
1686
1687
1699PIXAC *
1701{
1702char buf[256];
1703l_uint8 *data;
1704l_int32 n, offset, i, w, h, d, ignore;
1705l_int32 comptype, cmapflag, version, xres, yres;
1706size_t size;
1707BOXA *boxa;
1708PIXC *pixc;
1709PIXAC *pixac;
1710
1711 PROCNAME("pixacompReadStream");
1712
1713 if (!fp)
1714 return (PIXAC *)ERROR_PTR("stream not defined", procName, NULL);
1715
1716 if (fscanf(fp, "\nPixacomp Version %d\n", &version) != 1)
1717 return (PIXAC *)ERROR_PTR("not a pixacomp file", procName, NULL);
1718 if (version != PIXACOMP_VERSION_NUMBER)
1719 return (PIXAC *)ERROR_PTR("invalid pixacomp version", procName, NULL);
1720 if (fscanf(fp, "Number of pixcomp = %d\n", &n) != 1)
1721 return (PIXAC *)ERROR_PTR("not a pixacomp file", procName, NULL);
1722 if (fscanf(fp, "Offset of index into array = %d", &offset) != 1)
1723 return (PIXAC *)ERROR_PTR("offset not read", procName, NULL);
1724 if (n < 0)
1725 return (PIXAC *)ERROR_PTR("num pixcomp ptrs < 0", procName, NULL);
1726 if (n > MaxPtrArraySize)
1727 return (PIXAC *)ERROR_PTR("too many pixcomp ptrs", procName, NULL);
1728 if (n == 0) L_INFO("the pixacomp is empty\n", procName);
1729
1730 if ((pixac = pixacompCreate(n)) == NULL)
1731 return (PIXAC *)ERROR_PTR("pixac not made", procName, NULL);
1732 if ((boxa = boxaReadStream(fp)) == NULL) {
1733 pixacompDestroy(&pixac);
1734 return (PIXAC *)ERROR_PTR("boxa not made", procName, NULL);
1735 }
1736 boxaDestroy(&pixac->boxa); /* empty */
1737 pixac->boxa = boxa;
1738 pixacompSetOffset(pixac, offset);
1739
1740 for (i = 0; i < n; i++) {
1741 if (fscanf(fp, "\nPixcomp[%d]: w = %d, h = %d, d = %d\n",
1742 &ignore, &w, &h, &d) != 4) {
1743 pixacompDestroy(&pixac);
1744 return (PIXAC *)ERROR_PTR("dimension reading", procName, NULL);
1745 }
1746 if (fscanf(fp, " comptype = %d, size = %zu, cmapflag = %d\n",
1747 &comptype, &size, &cmapflag) != 3) {
1748 pixacompDestroy(&pixac);
1749 return (PIXAC *)ERROR_PTR("comptype/size reading", procName, NULL);
1750 }
1751 if (size > MaxDataSize) {
1752 pixacompDestroy(&pixac);
1753 L_ERROR("data size = %zu is too big", procName, size);
1754 return NULL;
1755 }
1756
1757 /* Use fgets() and sscanf(); not fscanf(), for the last
1758 * bit of header data before the binary data. The reason is
1759 * that fscanf throws away white space, and if the binary data
1760 * happens to begin with ascii character(s) that are white
1761 * space, it will swallow them and all will be lost! */
1762 if (fgets(buf, sizeof(buf), fp) == NULL) {
1763 pixacompDestroy(&pixac);
1764 return (PIXAC *)ERROR_PTR("fgets read fail", procName, NULL);
1765 }
1766 if (sscanf(buf, " xres = %d, yres = %d\n", &xres, &yres) != 2) {
1767 pixacompDestroy(&pixac);
1768 return (PIXAC *)ERROR_PTR("read fail for res", procName, NULL);
1769 }
1770 if ((data = (l_uint8 *)LEPT_CALLOC(1, size)) == NULL) {
1771 pixacompDestroy(&pixac);
1772 return (PIXAC *)ERROR_PTR("calloc fail for data", procName, NULL);
1773 }
1774 if (fread(data, 1, size, fp) != size) {
1775 pixacompDestroy(&pixac);
1776 LEPT_FREE(data);
1777 return (PIXAC *)ERROR_PTR("error reading data", procName, NULL);
1778 }
1779 fgetc(fp); /* swallow the ending nl */
1780 pixc = (PIXC *)LEPT_CALLOC(1, sizeof(PIXC));
1781 pixc->w = w;
1782 pixc->h = h;
1783 pixc->d = d;
1784 pixc->xres = xres;
1785 pixc->yres = yres;
1786 pixc->comptype = comptype;
1787 pixc->cmapflag = cmapflag;
1788 pixc->data = data;
1789 pixc->size = size;
1790 pixacompAddPixcomp(pixac, pixc, L_INSERT);
1791 }
1792 return pixac;
1793}
1794
1795
1808PIXAC *
1809pixacompReadMem(const l_uint8 *data,
1810 size_t size)
1811{
1812FILE *fp;
1813PIXAC *pixac;
1814
1815 PROCNAME("pixacompReadMem");
1816
1817 if (!data)
1818 return (PIXAC *)ERROR_PTR("data not defined", procName, NULL);
1819 if ((fp = fopenReadFromMemory(data, size)) == NULL)
1820 return (PIXAC *)ERROR_PTR("stream not opened", procName, NULL);
1821
1822 pixac = pixacompReadStream(fp);
1823 fclose(fp);
1824 if (!pixac) L_ERROR("pixac not read\n", procName);
1825 return pixac;
1826}
1827
1828
1843l_ok
1844pixacompWrite(const char *filename,
1845 PIXAC *pixac)
1846{
1847l_int32 ret;
1848FILE *fp;
1849
1850 PROCNAME("pixacompWrite");
1851
1852 if (!filename)
1853 return ERROR_INT("filename not defined", procName, 1);
1854 if (!pixac)
1855 return ERROR_INT("pixacomp not defined", procName, 1);
1856
1857 if ((fp = fopenWriteStream(filename, "wb")) == NULL)
1858 return ERROR_INT("stream not opened", procName, 1);
1859 ret = pixacompWriteStream(fp, pixac);
1860 fclose(fp);
1861 if (ret)
1862 return ERROR_INT("pixacomp not written to stream", procName, 1);
1863 return 0;
1864}
1865
1866
1874l_ok
1876 PIXAC *pixac)
1877{
1878l_int32 n, i;
1879PIXC *pixc;
1880
1881 PROCNAME("pixacompWriteStream");
1882
1883 if (!fp)
1884 return ERROR_INT("stream not defined", procName, 1);
1885 if (!pixac)
1886 return ERROR_INT("pixac not defined", procName, 1);
1887
1888 n = pixacompGetCount(pixac);
1889 fprintf(fp, "\nPixacomp Version %d\n", PIXACOMP_VERSION_NUMBER);
1890 fprintf(fp, "Number of pixcomp = %d\n", n);
1891 fprintf(fp, "Offset of index into array = %d", pixac->offset);
1892 boxaWriteStream(fp, pixac->boxa);
1893 for (i = 0; i < n; i++) {
1894 if ((pixc = pixacompGetPixcomp(pixac, pixac->offset + i, L_NOCOPY))
1895 == NULL)
1896 return ERROR_INT("pixc not found", procName, 1);
1897 fprintf(fp, "\nPixcomp[%d]: w = %d, h = %d, d = %d\n",
1898 i, pixc->w, pixc->h, pixc->d);
1899 fprintf(fp, " comptype = %d, size = %zu, cmapflag = %d\n",
1900 pixc->comptype, pixc->size, pixc->cmapflag);
1901 fprintf(fp, " xres = %d, yres = %d\n", pixc->xres, pixc->yres);
1902 fwrite(pixc->data, 1, pixc->size, fp);
1903 fprintf(fp, "\n");
1904 }
1905 return 0;
1906}
1907
1908
1922l_ok
1923pixacompWriteMem(l_uint8 **pdata,
1924 size_t *psize,
1925 PIXAC *pixac)
1926{
1927l_int32 ret;
1928FILE *fp;
1929
1930 PROCNAME("pixacompWriteMem");
1931
1932 if (pdata) *pdata = NULL;
1933 if (psize) *psize = 0;
1934 if (!pdata)
1935 return ERROR_INT("&data not defined", procName, 1);
1936 if (!psize)
1937 return ERROR_INT("&size not defined", procName, 1);
1938 if (!pixac)
1939 return ERROR_INT("&pixac not defined", procName, 1);
1940
1941#if HAVE_FMEMOPEN
1942 if ((fp = open_memstream((char **)pdata, psize)) == NULL)
1943 return ERROR_INT("stream not opened", procName, 1);
1944 ret = pixacompWriteStream(fp, pixac);
1945 fputc('\0', fp);
1946 fclose(fp);
1947 *psize = *psize - 1;
1948#else
1949 L_INFO("work-around: writing to a temp file\n", procName);
1950 #ifdef _WIN32
1951 if ((fp = fopenWriteWinTempfile()) == NULL)
1952 return ERROR_INT("tmpfile stream not opened", procName, 1);
1953 #else
1954 if ((fp = tmpfile()) == NULL)
1955 return ERROR_INT("tmpfile stream not opened", procName, 1);
1956 #endif /* _WIN32 */
1957 ret = pixacompWriteStream(fp, pixac);
1958 rewind(fp);
1959 *pdata = l_binaryReadStream(fp, psize);
1960 fclose(fp);
1961#endif /* HAVE_FMEMOPEN */
1962 return ret;
1963}
1964
1965
1966/*--------------------------------------------------------------------*
1967 * Conversion to pdf *
1968 *--------------------------------------------------------------------*/
2001l_ok
2003 l_int32 res,
2004 l_float32 scalefactor,
2005 l_int32 type,
2006 l_int32 quality,
2007 const char *title,
2008 const char *fileout)
2009{
2010l_uint8 *data;
2011l_int32 ret;
2012size_t nbytes;
2013
2014 PROCNAME("pixacompConvertToPdf");
2015
2016 if (!pixac)
2017 return ERROR_INT("pixac not defined", procName, 1);
2018
2019 ret = pixacompConvertToPdfData(pixac, res, scalefactor, type, quality,
2020 title, &data, &nbytes);
2021 if (ret) {
2022 LEPT_FREE(data);
2023 return ERROR_INT("conversion to pdf failed", procName, 1);
2024 }
2025
2026 ret = l_binaryWrite(fileout, "w", data, nbytes);
2027 LEPT_FREE(data);
2028 if (ret)
2029 L_ERROR("pdf data not written to file\n", procName);
2030 return ret;
2031}
2032
2033
2054l_ok
2056 l_int32 res,
2057 l_float32 scalefactor,
2058 l_int32 type,
2059 l_int32 quality,
2060 const char *title,
2061 l_uint8 **pdata,
2062 size_t *pnbytes)
2063{
2064l_uint8 *imdata;
2065l_int32 i, n, ret, scaledres, pagetype;
2066size_t imbytes;
2067L_BYTEA *ba;
2068PIX *pixs, *pix;
2069L_PTRA *pa_data;
2070
2071 PROCNAME("pixacompConvertToPdfData");
2072
2073 if (!pdata)
2074 return ERROR_INT("&data not defined", procName, 1);
2075 *pdata = NULL;
2076 if (!pnbytes)
2077 return ERROR_INT("&nbytes not defined", procName, 1);
2078 *pnbytes = 0;
2079 if (!pixac)
2080 return ERROR_INT("pixac not defined", procName, 1);
2081 if (scalefactor <= 0.0) scalefactor = 1.0;
2082 if (type != L_DEFAULT_ENCODE && type != L_JPEG_ENCODE &&
2083 type != L_G4_ENCODE && type != L_FLATE_ENCODE &&
2084 type != L_JP2K_ENCODE) {
2085 L_WARNING("invalid compression type; using per-page default\n",
2086 procName);
2087 type = L_DEFAULT_ENCODE;
2088 }
2089
2090 /* Generate all the encoded pdf strings */
2091 n = pixacompGetCount(pixac);
2092 pa_data = ptraCreate(n);
2093 for (i = 0; i < n; i++) {
2094 if ((pixs =
2095 pixacompGetPix(pixac, pixacompGetOffset(pixac) + i)) == NULL) {
2096 L_ERROR("pix[%d] not retrieved\n", procName, i);
2097 continue;
2098 }
2099 if (pixGetWidth(pixs) == 1) { /* used sometimes as placeholders */
2100 L_INFO("placeholder image[%d] has w = 1\n", procName, i);
2101 pixDestroy(&pixs);
2102 continue;
2103 }
2104 if (scalefactor != 1.0)
2105 pix = pixScale(pixs, scalefactor, scalefactor);
2106 else
2107 pix = pixClone(pixs);
2108 pixDestroy(&pixs);
2109 scaledres = (l_int32)(res * scalefactor);
2110
2111 /* Select the encoding type */
2112 if (type != L_DEFAULT_ENCODE) {
2113 pagetype = type;
2114 } else if (selectDefaultPdfEncoding(pix, &pagetype) != 0) {
2115 L_ERROR("encoding type selection failed for pix[%d]\n",
2116 procName, i);
2117 pixDestroy(&pix);
2118 continue;
2119 }
2120
2121 ret = pixConvertToPdfData(pix, pagetype, quality, &imdata, &imbytes,
2122 0, 0, scaledres, title, NULL, 0);
2123 pixDestroy(&pix);
2124 if (ret) {
2125 L_ERROR("pdf encoding failed for pix[%d]\n", procName, i);
2126 continue;
2127 }
2128 ba = l_byteaInitFromMem(imdata, imbytes);
2129 LEPT_FREE(imdata);
2130 ptraAdd(pa_data, ba);
2131 }
2132 ptraGetActualCount(pa_data, &n);
2133 if (n == 0) {
2134 L_ERROR("no pdf files made\n", procName);
2135 ptraDestroy(&pa_data, FALSE, FALSE);
2136 return 1;
2137 }
2138
2139 /* Concatenate them */
2140 ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes);
2141
2142 ptraGetActualCount(pa_data, &n); /* recalculate in case it changes */
2143 for (i = 0; i < n; i++) {
2144 ba = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
2145 l_byteaDestroy(&ba);
2146 }
2147 ptraDestroy(&pa_data, FALSE, FALSE);
2148 return ret;
2149}
2150
2151
2170l_ok
2172 const char *title,
2173 l_uint8 **pdata,
2174 size_t *pnbytes)
2175{
2176l_uint8 *imdata;
2177l_int32 i, n, ret, comptype;
2178size_t imbytes;
2179L_BYTEA *ba;
2180PIXC *pixc;
2181L_PTRA *pa_data;
2182
2183 PROCNAME("pixacompFastConvertToPdfData");
2184
2185 if (!pdata)
2186 return ERROR_INT("&data not defined", procName, 1);
2187 *pdata = NULL;
2188 if (!pnbytes)
2189 return ERROR_INT("&nbytes not defined", procName, 1);
2190 *pnbytes = 0;
2191 if (!pixac)
2192 return ERROR_INT("pixac not defined", procName, 1);
2193
2194 /* Generate all the encoded pdf strings */
2195 n = pixacompGetCount(pixac);
2196 pa_data = ptraCreate(n);
2197 for (i = 0; i < n; i++) {
2198 if ((pixc = pixacompGetPixcomp(pixac, i, L_NOCOPY)) == NULL) {
2199 L_ERROR("pixc[%d] not retrieved\n", procName, i);
2200 continue;
2201 }
2202 pixcompGetParameters(pixc, NULL, NULL, &comptype, NULL);
2203 if (comptype != IFF_JFIF_JPEG) {
2204 L_ERROR("pixc[%d] not jpeg compressed\n", procName, i);
2205 continue;
2206 }
2207 ret = pixcompFastConvertToPdfData(pixc, title, &imdata, &imbytes);
2208 if (ret) {
2209 L_ERROR("pdf encoding failed for pixc[%d]\n", procName, i);
2210 continue;
2211 }
2212 ba = l_byteaInitFromMem(imdata, imbytes);
2213 LEPT_FREE(imdata);
2214 ptraAdd(pa_data, ba);
2215 }
2216 ptraGetActualCount(pa_data, &n);
2217 if (n == 0) {
2218 L_ERROR("no pdf files made\n", procName);
2219 ptraDestroy(&pa_data, FALSE, FALSE);
2220 return 1;
2221 }
2222
2223 /* Concatenate them */
2224 ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes);
2225
2226 /* Clean up */
2227 ptraGetActualCount(pa_data, &n); /* recalculate in case it changes */
2228 for (i = 0; i < n; i++) {
2229 ba = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
2230 l_byteaDestroy(&ba);
2231 }
2232 ptraDestroy(&pa_data, FALSE, FALSE);
2233 return ret;
2234}
2235
2236
2255static l_int32
2257 const char *title,
2258 l_uint8 **pdata,
2259 size_t *pnbytes)
2260{
2261l_uint8 *data;
2262L_COMP_DATA *cid;
2263
2264 PROCNAME("pixacompFastConvertToPdfData");
2265
2266 if (!pdata)
2267 return ERROR_INT("&data not defined", procName, 1);
2268 *pdata = NULL;
2269 if (!pnbytes)
2270 return ERROR_INT("&nbytes not defined", procName, 1);
2271 *pnbytes = 0;
2272 if (!pixc)
2273 return ERROR_INT("pixc not defined", procName, 1);
2274
2275 /* Make a copy of the data */
2276 data = l_binaryCopy(pixc->data, pixc->size);
2277 cid = l_generateJpegDataMem(data, pixc->size, 0);
2278
2279 /* Note: cid is destroyed, along with data, by this function */
2280 return cidConvertToPdfData(cid, title, pdata, pnbytes);
2281}
2282
2283
2284/*--------------------------------------------------------------------*
2285 * Output for debugging *
2286 *--------------------------------------------------------------------*/
2295l_ok
2297 PIXAC *pixac,
2298 const char *text)
2299{
2300l_int32 i, n, nboxes;
2301PIXC *pixc;
2302
2303 PROCNAME("pixacompWriteStreamInfo");
2304
2305 if (!fp)
2306 return ERROR_INT("fp not defined", procName, 1);
2307 if (!pixac)
2308 return ERROR_INT("pixac not defined", procName, 1);
2309
2310 if (text)
2311 fprintf(fp, "Pixacomp Info for %s:\n", text);
2312 else
2313 fprintf(fp, "Pixacomp Info:\n");
2314 n = pixacompGetCount(pixac);
2315 nboxes = pixacompGetBoxaCount(pixac);
2316 fprintf(fp, "Number of pixcomp: %d\n", n);
2317 fprintf(fp, "Size of pixcomp array alloc: %d\n", pixac->nalloc);
2318 fprintf(fp, "Offset of index into array: %d\n", pixac->offset);
2319 if (nboxes > 0)
2320 fprintf(fp, "Boxa has %d boxes\n", nboxes);
2321 else
2322 fprintf(fp, "Boxa is empty\n");
2323 for (i = 0; i < n; i++) {
2324 pixc = pixacompGetPixcomp(pixac, pixac->offset + i, L_NOCOPY);
2325 pixcompWriteStreamInfo(fp, pixc, NULL);
2326 }
2327 return 0;
2328}
2329
2330
2339l_ok
2341 PIXC *pixc,
2342 const char *text)
2343{
2344 PROCNAME("pixcompWriteStreamInfo");
2345
2346 if (!fp)
2347 return ERROR_INT("fp not defined", procName, 1);
2348 if (!pixc)
2349 return ERROR_INT("pixc not defined", procName, 1);
2350
2351 if (text)
2352 fprintf(fp, " Pixcomp Info for %s:", text);
2353 else
2354 fprintf(fp, " Pixcomp Info:");
2355 fprintf(fp, " width = %d, height = %d, depth = %d\n",
2356 pixc->w, pixc->h, pixc->d);
2357 fprintf(fp, " xres = %d, yres = %d, size in bytes = %zu\n",
2358 pixc->xres, pixc->yres, pixc->size);
2359 if (pixc->cmapflag)
2360 fprintf(fp, " has colormap\n");
2361 else
2362 fprintf(fp, " no colormap\n");
2363 if (pixc->comptype < NumImageFileFormatExtensions) {
2364 fprintf(fp, " comptype = %s (%d)\n",
2365 ImageFileFormatExtensions[pixc->comptype], pixc->comptype);
2366 } else {
2367 fprintf(fp, " Error!! Invalid comptype index: %d\n", pixc->comptype);
2368 }
2369 return 0;
2370}
2371
2372
2395PIX *
2397 l_int32 outdepth,
2398 l_int32 tilewidth,
2399 l_int32 ncols,
2400 l_int32 background,
2401 l_int32 spacing,
2402 l_int32 border)
2403{
2404PIX *pixd;
2405PIXA *pixa;
2406
2407 PROCNAME("pixacompDisplayTiledAndScaled");
2408
2409 if (!pixac)
2410 return (PIX *)ERROR_PTR("pixac not defined", procName, NULL);
2411
2412 if ((pixa = pixaCreateFromPixacomp(pixac, L_COPY)) == NULL)
2413 return (PIX *)ERROR_PTR("pixa not made", procName, NULL);
2414
2415 pixd = pixaDisplayTiledAndScaled(pixa, outdepth, tilewidth, ncols,
2416 background, spacing, border);
2417 pixaDestroy(&pixa);
2418 return pixd;
2419}
2420
2421
2429l_ok
2431 const char *subdir)
2432{
2433char buf[128];
2434l_int32 i, n;
2435PIXC *pixc;
2436
2437 PROCNAME("pixacompWriteFiles");
2438
2439 if (!pixac)
2440 return ERROR_INT("pixac not defined", procName, 1);
2441
2442 if (lept_mkdir(subdir) > 0)
2443 return ERROR_INT("invalid subdir", procName, 1);
2444
2445 n = pixacompGetCount(pixac);
2446 for (i = 0; i < n; i++) {
2447 pixc = pixacompGetPixcomp(pixac, i, L_NOCOPY);
2448 snprintf(buf, sizeof(buf), "/tmp/%s/%03d", subdir, i);
2449 pixcompWriteFile(buf, pixc);
2450 }
2451 return 0;
2452}
2453
2454extern const char *ImageFileFormatExtensions[];
2455
2469l_ok
2470pixcompWriteFile(const char *rootname,
2471 PIXC *pixc)
2472{
2473char buf[128];
2474
2475 PROCNAME("pixcompWriteFile");
2476
2477 if (!pixc)
2478 return ERROR_INT("pixc not defined", procName, 1);
2479
2480 snprintf(buf, sizeof(buf), "%s.%s", rootname,
2481 ImageFileFormatExtensions[pixc->comptype]);
2482 l_binaryWrite(buf, "w", pixc->data, pixc->size);
2483 return 0;
2484}
BOXA * boxaReadStream(FILE *fp)
boxaReadStream()
Definition: boxbasic.c:2161
BOX * boxCopy(BOX *box)
boxCopy()
Definition: boxbasic.c:235
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
boxaCopy()
Definition: boxbasic.c:537
void boxDestroy(BOX **pbox)
boxDestroy()
Definition: boxbasic.c:282
BOX * boxClone(BOX *box)
boxClone()
Definition: boxbasic.c:256
l_int32 boxaGetCount(BOXA *boxa)
boxaGetCount()
Definition: boxbasic.c:734
l_ok boxGetGeometry(BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
Definition: boxbasic.c:313
BOXA * boxaCreate(l_int32 n)
boxaCreate()
Definition: boxbasic.c:502
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
Definition: boxbasic.c:620
l_ok boxaExtendArray(BOXA *boxa)
boxaExtendArray()
Definition: boxbasic.c:671
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
Definition: boxbasic.c:583
l_ok boxaWriteStream(FILE *fp, BOXA *boxa)
boxaWriteStream()
Definition: boxbasic.c:2299
l_ok boxaJoin(BOXA *boxad, BOXA *boxas, l_int32 istart, l_int32 iend)
boxaJoin()
Definition: boxfunc1.c:2537
L_BYTEA * l_byteaInitFromMem(const l_uint8 *data, size_t size)
l_byteaInitFromMem()
Definition: bytearray.c:125
void l_byteaDestroy(L_BYTEA **pba)
l_byteaDestroy()
Definition: bytearray.c:250
@ L_DEFAULT_ENCODE
Definition: imageio.h:158
@ L_FLATE_ENCODE
Definition: imageio.h:161
@ L_G4_ENCODE
Definition: imageio.h:160
@ L_JP2K_ENCODE
Definition: imageio.h:162
@ L_JPEG_ENCODE
Definition: imageio.h:159
l_ok selectDefaultPdfEncoding(PIX *pix, l_int32 *ptype)
selectDefaultPdfEncoding()
Definition: pdfio1.c:477
L_COMP_DATA * l_generateJpegDataMem(l_uint8 *data, size_t nbytes, l_int32 ascii85flag)
l_generateJpegDataMem()
Definition: pdfio2.c:1002
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()
Definition: pdfio2.c:190
l_ok ptraConcatenatePdfToData(L_PTRA *pa_data, SARRAY *sa, l_uint8 **pdata, size_t *pnbytes)
ptraConcatenatePdfToData()
Definition: pdfio2.c:321
l_ok cidConvertToPdfData(L_COMP_DATA *cid, const char *title, l_uint8 **pdata, size_t *pnbytes)
cidConvertToPdfData()
Definition: pdfio2.c:1607
l_ok pixSetResolution(PIX *pix, l_int32 xres, l_int32 yres)
pixSetResolution()
Definition: pix1.c:1387
void pixDestroy(PIX **ppix)
pixDestroy()
Definition: pix1.c:621
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
Definition: pix1.c:1113
l_ok pixSetText(PIX *pix, const char *textstring)
pixSetText()
Definition: pix1.c:1536
l_ok pixGetResolution(const PIX *pix, l_int32 *pxres, l_int32 *pyres)
pixGetResolution()
Definition: pix1.c:1361
PIX * pixClone(PIX *pixs)
pixClone()
Definition: pix1.c:593
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
Definition: pix1.c:315
char * pixGetText(PIX *pix)
pixGetText()
Definition: pix1.c:1512
@ L_COPY
Definition: pix.h:712
@ L_CLONE
Definition: pix.h:713
@ L_COPY_CLONE
Definition: pix.h:714
@ L_NOCOPY
Definition: pix.h:710
@ L_INSERT
Definition: pix.h:711
#define PIXACOMP_VERSION_NUMBER
Definition: pix.h:650
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
Definition: pixabasic.c:506
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
Definition: pixabasic.c:412
PIXA * pixaCreate(l_int32 n)
pixaCreate()
Definition: pixabasic.c:167
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
Definition: pixabasic.c:650
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
Definition: pixabasic.c:691
BOXA * pixaGetBoxa(PIXA *pixa, l_int32 accesstype)
pixaGetBoxa()
Definition: pixabasic.c:760
PIX * pixaDisplayTiledAndScaled(PIXA *pixa, l_int32 outdepth, l_int32 tilewidth, l_int32 ncols, l_int32 background, l_int32 spacing, l_int32 border)
pixaDisplayTiledAndScaled()
Definition: pixafunc2.c:1045
l_ok pixacompJoin(PIXAC *pixacd, PIXAC *pixacs, l_int32 istart, l_int32 iend)
pixacompJoin()
Definition: pixcomp.c:1553
PIXAC * pixacompCreateFromFiles(const char *dirname, const char *substr, l_int32 comptype)
pixacompCreateFromFiles()
Definition: pixcomp.c:797
void pixacompDestroy(PIXAC **ppixac)
pixacompDestroy()
Definition: pixcomp.c:878
l_ok pixacompFastConvertToPdfData(PIXAC *pixac, const char *title, l_uint8 **pdata, size_t *pnbytes)
pixacompFastConvertToPdfData()
Definition: pixcomp.c:2171
l_ok pixacompWriteStream(FILE *fp, PIXAC *pixac)
pixacompWriteStream()
Definition: pixcomp.c:1875
l_ok pixacompWrite(const char *filename, PIXAC *pixac)
pixacompWrite()
Definition: pixcomp.c:1844
void pixcompDestroy(PIXC **ppixc)
pixcompDestroy()
Definition: pixcomp.c:361
l_ok pixacompWriteMem(l_uint8 **pdata, size_t *psize, PIXAC *pixac)
pixacompWriteMem()
Definition: pixcomp.c:1923
static const l_int32 InitialPtrArraySize
Definition: pixcomp.c:160
PIX * pixacompDisplayTiledAndScaled(PIXAC *pixac, l_int32 outdepth, l_int32 tilewidth, l_int32 ncols, l_int32 background, l_int32 spacing, l_int32 border)
pixacompDisplayTiledAndScaled()
Definition: pixcomp.c:2396
PIXC * pixcompCreateFromFile(const char *filename, l_int32 comptype)
pixcompCreateFromFile()
Definition: pixcomp.c:298
BOXA * pixacompGetBoxa(PIXAC *pixac, l_int32 accesstype)
pixacompGetBoxa()
Definition: pixcomp.c:1294
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()
Definition: pixcomp.c:2055
PIXAC * pixacompReadStream(FILE *fp)
pixacompReadStream()
Definition: pixcomp.c:1700
PIX * pixCreateFromPixcomp(PIXC *pixc)
pixCreateFromPixcomp()
Definition: pixcomp.c:556
PIXAC * pixacompCreateFromPixa(PIXA *pixa, l_int32 comptype, l_int32 accesstype)
pixacompCreateFromPixa()
Definition: pixcomp.c:738
l_int32 pixacompGetBoxaCount(PIXAC *pixac)
pixacompGetBoxaCount()
Definition: pixcomp.c:1318
PIXC * pixacompGetPixcomp(PIXAC *pixac, l_int32 index, l_int32 copyflag)
pixacompGetPixcomp()
Definition: pixcomp.c:1190
PIXAC * pixacompInterleave(PIXAC *pixac1, PIXAC *pixac2)
pixacompInterleave()
Definition: pixcomp.c:1606
l_ok pixcompGetParameters(PIXC *pixc, l_int32 *pxres, l_int32 *pyres, l_int32 *pcomptype, l_int32 *pcmapflag)
pixcompGetParameters()
Definition: pixcomp.c:468
l_ok pixcompWriteFile(const char *rootname, PIXC *pixc)
pixcompWriteFile()
Definition: pixcomp.c:2470
l_ok pixacompReplacePix(PIXAC *pixac, l_int32 index, PIX *pix, l_int32 comptype)
pixacompReplacePix()
Definition: pixcomp.c:1054
PIXAC * pixacompRead(const char *filename)
pixacompRead()
Definition: pixcomp.c:1668
PIXC * pixcompCreateFromPix(PIX *pix, l_int32 comptype)
pixcompCreateFromPix()
Definition: pixcomp.c:194
static l_int32 pixacompExtendArray(PIXAC *pixac)
pixacompExtendArray()
Definition: pixcomp.c:1012
l_ok pixcompGetDimensions(PIXC *pixc, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixcompGetDimensions()
Definition: pixcomp.c:444
l_ok pixacompConvertToPdf(PIXAC *pixac, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, const char *fileout)
pixacompConvertToPdf()
Definition: pixcomp.c:2002
l_ok pixacompSetOffset(PIXAC *pixac, l_int32 offset)
pixacompSetOffset()
Definition: pixcomp.c:1465
static l_int32 pixcompFastConvertToPdfData(PIXC *pixc, const char *title, l_uint8 **pdata, size_t *pnbytes)
pixcompFastConvertToPdfData()
Definition: pixcomp.c:2256
PIXAC * pixacompCreateWithInit(l_int32 n, l_int32 offset, PIX *pix, l_int32 comptype)
pixacompCreateWithInit()
Definition: pixcomp.c:674
l_ok pixacompWriteStreamInfo(FILE *fp, PIXAC *pixac, const char *text)
pixacompWriteStreamInfo()
Definition: pixcomp.c:2296
PIXA * pixaCreateFromPixacomp(PIXAC *pixac, l_int32 accesstype)
pixaCreateFromPixacomp()
Definition: pixcomp.c:1495
PIXC * pixcompCreateFromString(l_uint8 *data, size_t size, l_int32 copyflag)
pixcompCreateFromString()
Definition: pixcomp.c:250
l_ok pixacompGetBoxGeometry(PIXAC *pixac, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
pixacompGetBoxGeometry()
Definition: pixcomp.c:1400
l_int32 pixacompGetOffset(PIXAC *pixac)
pixacompGetOffset()
Definition: pixcomp.c:1440
l_int32 pixacompGetCount(PIXAC *pixac)
pixacompGetCount()
Definition: pixcomp.c:1162
l_ok pixacompAddPix(PIXAC *pixac, PIX *pix, l_int32 comptype)
pixacompAddPix()
Definition: pixcomp.c:923
l_ok pixacompAddBox(PIXAC *pixac, BOX *box, l_int32 copyflag)
pixacompAddBox()
Definition: pixcomp.c:1134
l_ok pixacompAddPixcomp(PIXAC *pixac, PIXC *pixc, l_int32 copyflag)
pixacompAddPixcomp()
Definition: pixcomp.c:965
l_ok pixcompDetermineFormat(l_int32 comptype, l_int32 d, l_int32 cmapflag, l_int32 *pformat)
pixcompDetermineFormat()
Definition: pixcomp.c:514
PIXAC * pixacompCreateFromSA(SARRAY *sa, l_int32 comptype)
pixacompCreateFromSA()
Definition: pixcomp.c:836
PIXAC * pixacompReadMem(const l_uint8 *data, size_t size)
pixacompReadMem()
Definition: pixcomp.c:1809
l_ok pixacompWriteFiles(PIXAC *pixac, const char *subdir)
pixacompWriteFiles()
Definition: pixcomp.c:2430
PIX * pixacompGetPix(PIXAC *pixac, l_int32 index)
pixacompGetPix()
Definition: pixcomp.c:1227
BOX * pixacompGetBox(PIXAC *pixac, l_int32 index, l_int32 accesstype)
pixacompGetBox()
Definition: pixcomp.c:1353
l_ok pixcompWriteStreamInfo(FILE *fp, PIXC *pixc, const char *text)
pixcompWriteStreamInfo()
Definition: pixcomp.c:2340
l_ok pixacompReplacePixcomp(PIXAC *pixac, l_int32 index, PIXC *pixc)
pixacompReplacePixcomp()
Definition: pixcomp.c:1099
l_ok pixacompGetPixDimensions(PIXAC *pixac, l_int32 index, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixacompGetPixDimensions()
Definition: pixcomp.c:1262
PIXC * pixcompCopy(PIXC *pixcs)
pixcompCopy()
Definition: pixcomp.c:395
PIXAC * pixacompCreate(l_int32 n)
pixacompCreate()
Definition: pixcomp.c:609
l_ok ptraGetActualCount(L_PTRA *pa, l_int32 *pcount)
ptraGetActualCount()
Definition: ptra.c:735
l_ok ptraAdd(L_PTRA *pa, void *item)
ptraAdd()
Definition: ptra.c:250
void * ptraRemove(L_PTRA *pa, l_int32 index, l_int32 flag)
ptraRemove()
Definition: ptra.c:442
void ptraDestroy(L_PTRA **ppa, l_int32 freeflag, l_int32 warnflag)
ptraDestroy()
Definition: ptra.c:194
L_PTRA * ptraCreate(l_int32 n)
ptraCreate()
Definition: ptra.c:144
@ L_NO_COMPACTION
Definition: ptra.h:79
PIX * pixRead(const char *filename)
pixRead()
Definition: readfile.c:193
l_ok findFileFormat(const char *filename, l_int32 *pformat)
findFileFormat()
Definition: readfile.c:584
PIX * pixReadMem(const l_uint8 *data, size_t size)
pixReadMem()
Definition: readfile.c:844
l_ok pixReadHeaderMem(const l_uint8 *data, size_t size, l_int32 *pformat, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *piscmap)
pixReadHeaderMem()
Definition: readfile.c:974
SARRAY * getSortedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
getSortedPathnamesInDirectory()
Definition: sarray1.c:1848
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
Definition: sarray1.c:703
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
Definition: sarray1.c:643
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
Definition: sarray1.c:362
PIX * pixScale(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScale()
Definition: scale1.c:250
Definition: pix.h:481
Definition: pix.h:492
l_int32 n
Definition: pix.h:493
struct Box ** box
Definition: pix.h:496
Definition: array.h:137
Definition: ptra.h:54
Definition: pix.h:629
l_int32 w
Definition: pix.h:630
size_t size
Definition: pix.h:642
l_uint8 * data
Definition: pix.h:641
l_int32 cmapflag
Definition: pix.h:640
l_int32 xres
Definition: pix.h:633
char * text
Definition: pix.h:639
l_int32 yres
Definition: pix.h:635
l_int32 d
Definition: pix.h:632
l_int32 h
Definition: pix.h:631
l_int32 comptype
Definition: pix.h:637
Definition: pix.h:139
Definition: pix.h:654
l_int32 offset
Definition: pix.h:657
l_int32 nalloc
Definition: pix.h:656
l_int32 n
Definition: pix.h:655
struct PixComp ** pixc
Definition: pix.h:658
struct Boxa * boxa
Definition: pix.h:659
Definition: pix.h:456
struct Boxa * boxa
Definition: pix.h:461
Definition: array.h:127
FILE * fopenWriteWinTempfile(void)
fopenWriteWinTempfile()
Definition: utils2.c:2055
l_uint8 * l_binaryCopy(const l_uint8 *datas, size_t size)
l_binaryCopy()
Definition: utils2.c:1675
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
Definition: utils2.c:1975
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()
Definition: utils2.c:1352
FILE * fopenReadFromMemory(const l_uint8 *data, size_t size)
fopenReadFromMemory()
Definition: utils2.c:2009
FILE * fopenReadStream(const char *filename)
fopenReadStream()
Definition: utils2.c:1932
l_uint8 * l_binaryReadStream(FILE *fp, size_t *pnbytes)
l_binaryReadStream()
Definition: utils2.c:1402
void * reallocNew(void **pindata, size_t oldsize, size_t newsize)
reallocNew()
Definition: utils2.c:1302
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
Definition: utils2.c:2218
l_ok l_binaryWrite(const char *filename, const char *operation, const void *data, size_t nbytes)
l_binaryWrite()
Definition: utils2.c:1569
char * stringNew(const char *src)
stringNew()
Definition: utils2.c:223