Leptonica  1.77.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 #include <string.h>
152 #include "allheaders.h"
153 
154 static const l_int32 INITIAL_PTR_ARRAYSIZE = 20; /* n'import quoi */
155 
156  /* These two globals are defined in writefile.c */
157 extern l_int32 NumImageFileFormatExtensions;
158 extern const char *ImageFileFormatExtensions[];
159 
160  /* Static functions */
161 static l_int32 pixacompExtendArray(PIXAC *pixac);
162 static l_int32 pixcompFastConvertToPdfData(PIXC *pixc, const char *title,
163  l_uint8 **pdata, size_t *pnbytes);
164 
165 
166 /*---------------------------------------------------------------------*
167  * Pixcomp creation and destruction *
168  *---------------------------------------------------------------------*/
184 PIXC *
186  l_int32 comptype)
187 {
188 size_t size;
189 char *text;
190 l_int32 ret, format;
191 l_uint8 *data;
192 PIXC *pixc;
193 
194  PROCNAME("pixcompCreateFromPix");
195 
196  if (!pix)
197  return (PIXC *)ERROR_PTR("pix not defined", procName, NULL);
198  if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
199  comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
200  return (PIXC *)ERROR_PTR("invalid comptype", procName, NULL);
201 
202  if ((pixc = (PIXC *)LEPT_CALLOC(1, sizeof(PIXC))) == NULL)
203  return (PIXC *)ERROR_PTR("pixc not made", procName, NULL);
204  pixGetDimensions(pix, &pixc->w, &pixc->h, &pixc->d);
205  pixGetResolution(pix, &pixc->xres, &pixc->yres);
206  if (pixGetColormap(pix))
207  pixc->cmapflag = 1;
208  if ((text = pixGetText(pix)) != NULL)
209  pixc->text = stringNew(text);
210 
211  pixcompDetermineFormat(comptype, pixc->d, pixc->cmapflag, &format);
212  pixc->comptype = format;
213  ret = pixWriteMem(&data, &size, pix, format);
214  if (ret) {
215  L_ERROR("write to memory failed\n", procName);
216  pixcompDestroy(&pixc);
217  return NULL;
218  }
219  pixc->data = data;
220  pixc->size = size;
221 
222  return pixc;
223 }
224 
225 
241 PIXC *
243  size_t size,
244  l_int32 copyflag)
245 {
246 l_int32 format, w, h, d, bps, spp, iscmap;
247 PIXC *pixc;
248 
249  PROCNAME("pixcompCreateFromString");
250 
251  if (!data)
252  return (PIXC *)ERROR_PTR("data not defined", procName, NULL);
253  if (copyflag != L_INSERT && copyflag != L_COPY)
254  return (PIXC *)ERROR_PTR("invalid copyflag", procName, NULL);
255 
256  if (pixReadHeaderMem(data, size, &format, &w, &h, &bps, &spp, &iscmap) == 1)
257  return (PIXC *)ERROR_PTR("header data not read", procName, NULL);
258  if ((pixc = (PIXC *)LEPT_CALLOC(1, sizeof(PIXC))) == NULL)
259  return (PIXC *)ERROR_PTR("pixc not made", procName, NULL);
260  d = (spp == 3) ? 32 : bps * spp;
261  pixc->w = w;
262  pixc->h = h;
263  pixc->d = d;
264  pixc->comptype = format;
265  pixc->cmapflag = iscmap;
266  if (copyflag == L_INSERT)
267  pixc->data = data;
268  else
269  pixc->data = l_binaryCopy(data, size);
270  pixc->size = size;
271  return pixc;
272 }
273 
274 
290 PIXC *
291 pixcompCreateFromFile(const char *filename,
292  l_int32 comptype)
293 {
294 l_int32 format;
295 size_t nbytes;
296 l_uint8 *data;
297 PIX *pix;
298 PIXC *pixc;
299 
300  PROCNAME("pixcompCreateFromFile");
301 
302  if (!filename)
303  return (PIXC *)ERROR_PTR("filename not defined", procName, NULL);
304  if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
305  comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
306  return (PIXC *)ERROR_PTR("invalid comptype", procName, NULL);
307 
308  findFileFormat(filename, &format);
309  if (format == IFF_UNKNOWN) {
310  L_ERROR("unreadable file: %s\n", procName, filename);
311  return NULL;
312  }
313 
314  /* Can we accept the encoded file directly? Remember that
315  * png is the "universal" compression type, so if requested
316  * it takes precedence. Otherwise, if the file is already
317  * compressed in g4 or jpeg, just accept the string. */
318  if ((format == IFF_TIFF_G4 && comptype != IFF_PNG) ||
319  (format == IFF_JFIF_JPEG && comptype != IFF_PNG))
320  comptype = format;
321  if (comptype != IFF_DEFAULT && comptype == format) {
322  data = l_binaryRead(filename, &nbytes);
323  if ((pixc = pixcompCreateFromString(data, nbytes, L_INSERT)) == NULL) {
324  LEPT_FREE(data);
325  return (PIXC *)ERROR_PTR("pixc not made (string)", procName, NULL);
326  }
327  return pixc;
328  }
329 
330  /* Need to recompress in the default format */
331  if ((pix = pixRead(filename)) == NULL)
332  return (PIXC *)ERROR_PTR("pix not read", procName, NULL);
333  if ((pixc = pixcompCreateFromPix(pix, comptype)) == NULL) {
334  pixDestroy(&pix);
335  return (PIXC *)ERROR_PTR("pixc not made", procName, NULL);
336  }
337  pixDestroy(&pix);
338  return pixc;
339 }
340 
341 
353 void
355 {
356 PIXC *pixc;
357 
358  PROCNAME("pixcompDestroy");
359 
360  if (!ppixc) {
361  L_WARNING("ptr address is null!\n", procName);
362  return;
363  }
364 
365  if ((pixc = *ppixc) == NULL)
366  return;
367 
368  LEPT_FREE(pixc->data);
369  if (pixc->text)
370  LEPT_FREE(pixc->text);
371  LEPT_FREE(pixc);
372  *ppixc = NULL;
373  return;
374 }
375 
376 
383 PIXC *
385 {
386 size_t size;
387 l_uint8 *datas, *datad;
388 PIXC *pixcd;
389 
390  PROCNAME("pixcompCopy");
391 
392  if (!pixcs)
393  return (PIXC *)ERROR_PTR("pixcs not defined", procName, NULL);
394 
395  if ((pixcd = (PIXC *)LEPT_CALLOC(1, sizeof(PIXC))) == NULL)
396  return (PIXC *)ERROR_PTR("pixcd not made", procName, NULL);
397  pixcd->w = pixcs->w;
398  pixcd->h = pixcs->h;
399  pixcd->d = pixcs->d;
400  pixcd->xres = pixcs->xres;
401  pixcd->yres = pixcs->yres;
402  pixcd->comptype = pixcs->comptype;
403  if (pixcs->text != NULL)
404  pixcd->text = stringNew(pixcs->text);
405  pixcd->cmapflag = pixcs->cmapflag;
406 
407  /* Copy image data */
408  size = pixcs->size;
409  datas = pixcs->data;
410  datad = (l_uint8 *)LEPT_CALLOC(size, sizeof(l_int8));
411  memcpy(datad, datas, size);
412  pixcd->data = datad;
413  pixcd->size = size;
414  return pixcd;
415 }
416 
417 
418 /*---------------------------------------------------------------------*
419  * Pixcomp accessors *
420  *---------------------------------------------------------------------*/
428 l_ok
430  l_int32 *pw,
431  l_int32 *ph,
432  l_int32 *pd)
433 {
434  PROCNAME("pixcompGetDimensions");
435 
436  if (!pixc)
437  return ERROR_INT("pixc not defined", procName, 1);
438  if (pw) *pw = pixc->w;
439  if (ph) *ph = pixc->h;
440  if (pd) *pd = pixc->d;
441  return 0;
442 }
443 
444 
452 l_ok
454  l_int32 *pxres,
455  l_int32 *pyres,
456  l_int32 *pcomptype,
457  l_int32 *pcmapflag)
458 {
459  PROCNAME("pixcompGetParameters");
460 
461  if (!pixc)
462  return ERROR_INT("pixc not defined", procName, 1);
463  if (pxres) *pxres = pixc->xres;
464  if (pyres) *pyres = pixc->yres;
465  if (pcomptype) *pcomptype = pixc->comptype;
466  if (pcmapflag) *pcmapflag = pixc->cmapflag;
467  return 0;
468 }
469 
470 
471 /*---------------------------------------------------------------------*
472  * Pixcomp compression selection *
473  *---------------------------------------------------------------------*/
494 l_ok
495 pixcompDetermineFormat(l_int32 comptype,
496  l_int32 d,
497  l_int32 cmapflag,
498  l_int32 *pformat)
499 {
500 
501  PROCNAME("pixcompDetermineFormat");
502 
503  if (!pformat)
504  return ERROR_INT("&format not defined", procName, 1);
505  *pformat = IFF_PNG; /* init value and default */
506  if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
507  comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
508  return ERROR_INT("invalid comptype", procName, 1);
509 
510  if (comptype == IFF_DEFAULT) {
511  if (d == 1)
512  *pformat = IFF_TIFF_G4;
513  else if (d == 16)
514  *pformat = IFF_PNG;
515  else if (d >= 8 && !cmapflag)
516  *pformat = IFF_JFIF_JPEG;
517  } else if (comptype == IFF_TIFF_G4 && d == 1) {
518  *pformat = IFF_TIFF_G4;
519  } else if (comptype == IFF_JFIF_JPEG && d >= 8 && !cmapflag) {
520  *pformat = IFF_JFIF_JPEG;
521  }
522 
523  return 0;
524 }
525 
526 
527 /*---------------------------------------------------------------------*
528  * Pixcomp conversion to Pix *
529  *---------------------------------------------------------------------*/
536 PIX *
538 {
539 l_int32 w, h, d, cmapinpix, format;
540 PIX *pix;
541 
542  PROCNAME("pixCreateFromPixcomp");
543 
544  if (!pixc)
545  return (PIX *)ERROR_PTR("pixc not defined", procName, NULL);
546 
547  if ((pix = pixReadMem(pixc->data, pixc->size)) == NULL)
548  return (PIX *)ERROR_PTR("pix not read", procName, NULL);
549  pixSetResolution(pix, pixc->xres, pixc->yres);
550  if (pixc->text)
551  pixSetText(pix, pixc->text);
552 
553  /* Check fields for consistency */
554  pixGetDimensions(pix, &w, &h, &d);
555  if (pixc->w != w) {
556  L_INFO("pix width %d != pixc width %d\n", procName, w, pixc->w);
557  L_ERROR("pix width %d != pixc width\n", procName, w);
558  }
559  if (pixc->h != h)
560  L_ERROR("pix height %d != pixc height\n", procName, h);
561  if (pixc->d != d) {
562  if (pixc->d == 16) /* we strip 16 --> 8 bpp by default */
563  L_WARNING("pix depth %d != pixc depth 16\n", procName, d);
564  else
565  L_ERROR("pix depth %d != pixc depth\n", procName, d);
566  }
567  cmapinpix = (pixGetColormap(pix) != NULL);
568  if ((cmapinpix && !pixc->cmapflag) || (!cmapinpix && pixc->cmapflag))
569  L_ERROR("pix cmap flag inconsistent\n", procName);
570  format = pixGetInputFormat(pix);
571  if (format != pixc->comptype) {
572  L_ERROR("pix comptype %d not equal to pixc comptype\n",
573  procName, format);
574  }
575 
576  return pix;
577 }
578 
579 
580 /*---------------------------------------------------------------------*
581  * Pixacomp creation and destruction *
582  *---------------------------------------------------------------------*/
589 PIXAC *
590 pixacompCreate(l_int32 n)
591 {
592 PIXAC *pixac;
593 
594  PROCNAME("pixacompCreate");
595 
596  if (n <= 0)
597  n = INITIAL_PTR_ARRAYSIZE;
598 
599  if ((pixac = (PIXAC *)LEPT_CALLOC(1, sizeof(PIXAC))) == NULL)
600  return (PIXAC *)ERROR_PTR("pixac not made", procName, NULL);
601  pixac->n = 0;
602  pixac->nalloc = n;
603  pixac->offset = 0;
604 
605  if ((pixac->pixc = (PIXC **)LEPT_CALLOC(n, sizeof(PIXC *))) == NULL) {
606  pixacompDestroy(&pixac);
607  return (PIXAC *)ERROR_PTR("pixc ptrs not made", procName, NULL);
608  }
609  if ((pixac->boxa = boxaCreate(n)) == NULL) {
610  pixacompDestroy(&pixac);
611  return (PIXAC *)ERROR_PTR("boxa not made", procName, NULL);
612  }
613 
614  return pixac;
615 }
616 
617 
656 PIXAC *
658  l_int32 offset,
659  PIX *pix,
660  l_int32 comptype)
661 {
662 l_int32 i;
663 PIX *pixt;
664 PIXC *pixc;
665 PIXAC *pixac;
666 
667  PROCNAME("pixacompCreateWithInit");
668 
669  if (n <= 0)
670  return (PIXAC *)ERROR_PTR("n must be > 0", procName, NULL);
671  if (pix) {
672  if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
673  comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
674  return (PIXAC *)ERROR_PTR("invalid comptype", procName, NULL);
675  } else {
676  comptype = IFF_TIFF_G4;
677  }
678  if (offset < 0) {
679  L_WARNING("offset < 0; setting to 0\n", procName);
680  offset = 0;
681  }
682 
683  if ((pixac = pixacompCreate(n)) == NULL)
684  return (PIXAC *)ERROR_PTR("pixac not made", procName, NULL);
685  pixacompSetOffset(pixac, offset);
686  if (pix)
687  pixt = pixClone(pix);
688  else
689  pixt = pixCreate(1, 1, 1);
690  for (i = 0; i < n; i++) {
691  pixc = pixcompCreateFromPix(pixt, comptype);
692  pixacompAddPixcomp(pixac, pixc, L_INSERT);
693  }
694  pixDestroy(&pixt);
695 
696  return pixac;
697 }
698 
699 
720 PIXAC *
722  l_int32 comptype,
723  l_int32 accesstype)
724 {
725 l_int32 i, n;
726 BOXA *boxa;
727 PIX *pix;
728 PIXAC *pixac;
729 
730  PROCNAME("pixacompCreateFromPixa");
731 
732  if (!pixa)
733  return (PIXAC *)ERROR_PTR("pixa not defined", procName, NULL);
734  if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
735  comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
736  return (PIXAC *)ERROR_PTR("invalid comptype", procName, NULL);
737  if (accesstype != L_COPY && accesstype != L_CLONE &&
738  accesstype != L_COPY_CLONE)
739  return (PIXAC *)ERROR_PTR("invalid accesstype", procName, NULL);
740 
741  n = pixaGetCount(pixa);
742  if ((pixac = pixacompCreate(n)) == NULL)
743  return (PIXAC *)ERROR_PTR("pixac not made", procName, NULL);
744  for (i = 0; i < n; i++) {
745  pix = pixaGetPix(pixa, i, L_CLONE);
746  pixacompAddPix(pixac, pix, comptype);
747  pixDestroy(&pix);
748  }
749  if ((boxa = pixaGetBoxa(pixa, accesstype)) != NULL) {
750  boxaDestroy(&pixac->boxa);
751  pixac->boxa = boxa;
752  }
753 
754  return pixac;
755 }
756 
757 
779 PIXAC *
780 pixacompCreateFromFiles(const char *dirname,
781  const char *substr,
782  l_int32 comptype)
783 {
784 PIXAC *pixac;
785 SARRAY *sa;
786 
787  PROCNAME("pixacompCreateFromFiles");
788 
789  if (!dirname)
790  return (PIXAC *)ERROR_PTR("dirname not defined", procName, NULL);
791  if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
792  comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
793  return (PIXAC *)ERROR_PTR("invalid comptype", procName, NULL);
794 
795  if ((sa = getSortedPathnamesInDirectory(dirname, substr, 0, 0)) == NULL)
796  return (PIXAC *)ERROR_PTR("sa not made", procName, NULL);
797  pixac = pixacompCreateFromSA(sa, comptype);
798  sarrayDestroy(&sa);
799  return pixac;
800 }
801 
802 
818 PIXAC *
820  l_int32 comptype)
821 {
822 char *str;
823 l_int32 i, n;
824 PIXC *pixc;
825 PIXAC *pixac;
826 
827  PROCNAME("pixacompCreateFromSA");
828 
829  if (!sa)
830  return (PIXAC *)ERROR_PTR("sarray not defined", procName, NULL);
831  if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
832  comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
833  return (PIXAC *)ERROR_PTR("invalid comptype", procName, NULL);
834 
835  n = sarrayGetCount(sa);
836  pixac = pixacompCreate(n);
837  for (i = 0; i < n; i++) {
838  str = sarrayGetString(sa, i, L_NOCOPY);
839  if ((pixc = pixcompCreateFromFile(str, comptype)) == NULL) {
840  L_ERROR("pixc not read from file: %s\n", procName, str);
841  continue;
842  }
843  pixacompAddPixcomp(pixac, pixc, L_INSERT);
844  }
845  return pixac;
846 }
847 
848 
860 void
862 {
863 l_int32 i;
864 PIXAC *pixac;
865 
866  PROCNAME("pixacompDestroy");
867 
868  if (ppixac == NULL) {
869  L_WARNING("ptr address is NULL!\n", procName);
870  return;
871  }
872 
873  if ((pixac = *ppixac) == NULL)
874  return;
875 
876  for (i = 0; i < pixac->n; i++)
877  pixcompDestroy(&pixac->pixc[i]);
878  LEPT_FREE(pixac->pixc);
879  boxaDestroy(&pixac->boxa);
880  LEPT_FREE(pixac);
881 
882  *ppixac = NULL;
883  return;
884 }
885 
886 
887 /*---------------------------------------------------------------------*
888  * Pixacomp addition *
889  *---------------------------------------------------------------------*/
907 l_ok
909  PIX *pix,
910  l_int32 comptype)
911 {
912 l_int32 cmapflag, format;
913 PIXC *pixc;
914 
915  PROCNAME("pixacompAddPix");
916 
917  if (!pixac)
918  return ERROR_INT("pixac not defined", procName, 1);
919  if (!pix)
920  return ERROR_INT("pix not defined", procName, 1);
921  if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
922  comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
923  return ERROR_INT("invalid format", procName, 1);
924 
925  cmapflag = pixGetColormap(pix) ? 1 : 0;
926  pixcompDetermineFormat(comptype, pixGetDepth(pix), cmapflag, &format);
927  if ((pixc = pixcompCreateFromPix(pix, format)) == NULL)
928  return ERROR_INT("pixc not made", procName, 1);
929  pixacompAddPixcomp(pixac, pixc, L_INSERT);
930  return 0;
931 }
932 
933 
949 l_ok
951  PIXC *pixc,
952  l_int32 copyflag)
953 {
954 l_int32 n;
955 
956  PROCNAME("pixacompAddPixcomp");
957 
958  if (!pixac)
959  return ERROR_INT("pixac not defined", procName, 1);
960  if (!pixc)
961  return ERROR_INT("pixc not defined", procName, 1);
962  if (copyflag != L_INSERT && copyflag != L_COPY)
963  return ERROR_INT("invalid copyflag", procName, 1);
964 
965  n = pixac->n;
966  if (n >= pixac->nalloc)
967  pixacompExtendArray(pixac);
968  if (copyflag == L_INSERT)
969  pixac->pixc[n] = pixc;
970  else /* L_COPY */
971  pixac->pixc[n] = pixcompCopy(pixc);
972  pixac->n++;
973 
974  return 0;
975 }
976 
977 
992 static l_int32
994 {
995  PROCNAME("pixacompExtendArray");
996 
997  if (!pixac)
998  return ERROR_INT("pixac not defined", procName, 1);
999 
1000  if ((pixac->pixc = (PIXC **)reallocNew((void **)&pixac->pixc,
1001  sizeof(PIXC *) * pixac->nalloc,
1002  2 * sizeof(PIXC *) * pixac->nalloc)) == NULL)
1003  return ERROR_INT("new ptr array not returned", procName, 1);
1004  pixac->nalloc = 2 * pixac->nalloc;
1005  boxaExtendArray(pixac->boxa);
1006  return 0;
1007 }
1008 
1009 
1027 l_ok
1029  l_int32 index,
1030  PIX *pix,
1031  l_int32 comptype)
1032 {
1033 l_int32 n, aindex;
1034 PIXC *pixc;
1035 
1036  PROCNAME("pixacompReplacePix");
1037 
1038  if (!pixac)
1039  return ERROR_INT("pixac not defined", procName, 1);
1040  n = pixacompGetCount(pixac);
1041  aindex = index - pixac->offset;
1042  if (aindex < 0 || aindex >= n)
1043  return ERROR_INT("array index out of bounds", procName, 1);
1044  if (!pix)
1045  return ERROR_INT("pix not defined", procName, 1);
1046  if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
1047  comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
1048  return ERROR_INT("invalid format", procName, 1);
1049 
1050  pixc = pixcompCreateFromPix(pix, comptype);
1051  pixacompReplacePixcomp(pixac, index, pixc);
1052  return 0;
1053 }
1054 
1055 
1072 l_ok
1074  l_int32 index,
1075  PIXC *pixc)
1076 {
1077 l_int32 n, aindex;
1078 PIXC *pixct;
1079 
1080  PROCNAME("pixacompReplacePixcomp");
1081 
1082  if (!pixac)
1083  return ERROR_INT("pixac not defined", procName, 1);
1084  n = pixacompGetCount(pixac);
1085  aindex = index - pixac->offset;
1086  if (aindex < 0 || aindex >= n)
1087  return ERROR_INT("array index out of bounds", procName, 1);
1088  if (!pixc)
1089  return ERROR_INT("pixc not defined", procName, 1);
1090 
1091  pixct = pixacompGetPixcomp(pixac, index, L_NOCOPY); /* use %index */
1092  pixcompDestroy(&pixct);
1093  pixac->pixc[aindex] = pixc; /* replace; use array index */
1094 
1095  return 0;
1096 }
1097 
1098 
1107 l_ok
1109  BOX *box,
1110  l_int32 copyflag)
1111 {
1112  PROCNAME("pixacompAddBox");
1113 
1114  if (!pixac)
1115  return ERROR_INT("pixac not defined", procName, 1);
1116  if (!box)
1117  return ERROR_INT("box not defined", procName, 1);
1118  if (copyflag != L_INSERT && copyflag != L_COPY)
1119  return ERROR_INT("invalid copyflag", procName, 1);
1120 
1121  boxaAddBox(pixac->boxa, box, copyflag);
1122  return 0;
1123 }
1124 
1125 
1126 /*---------------------------------------------------------------------*
1127  * Pixacomp accessors *
1128  *---------------------------------------------------------------------*/
1135 l_int32
1137 {
1138  PROCNAME("pixacompGetCount");
1139 
1140  if (!pixac)
1141  return ERROR_INT("pixac not defined", procName, 0);
1142 
1143  return pixac->n;
1144 }
1145 
1146 
1163 PIXC *
1165  l_int32 index,
1166  l_int32 copyflag)
1167 {
1168 l_int32 aindex;
1169 
1170  PROCNAME("pixacompGetPixcomp");
1171 
1172  if (!pixac)
1173  return (PIXC *)ERROR_PTR("pixac not defined", procName, NULL);
1174  if (copyflag != L_NOCOPY && copyflag != L_COPY)
1175  return (PIXC *)ERROR_PTR("invalid copyflag", procName, NULL);
1176  aindex = index - pixac->offset;
1177  if (aindex < 0 || aindex >= pixac->n)
1178  return (PIXC *)ERROR_PTR("array index not valid", procName, NULL);
1179 
1180  if (copyflag == L_NOCOPY)
1181  return pixac->pixc[aindex];
1182  else /* L_COPY */
1183  return pixcompCopy(pixac->pixc[aindex]);
1184 }
1185 
1186 
1200 PIX *
1202  l_int32 index)
1203 {
1204 l_int32 aindex;
1205 PIXC *pixc;
1206 
1207  PROCNAME("pixacompGetPix");
1208 
1209  if (!pixac)
1210  return (PIX *)ERROR_PTR("pixac not defined", procName, NULL);
1211  aindex = index - pixac->offset;
1212  if (aindex < 0 || aindex >= pixac->n)
1213  return (PIX *)ERROR_PTR("array index not valid", procName, NULL);
1214 
1215  pixc = pixacompGetPixcomp(pixac, index, L_NOCOPY);
1216  return pixCreateFromPixcomp(pixc);
1217 }
1218 
1219 
1235 l_ok
1237  l_int32 index,
1238  l_int32 *pw,
1239  l_int32 *ph,
1240  l_int32 *pd)
1241 {
1242 l_int32 aindex;
1243 PIXC *pixc;
1244 
1245  PROCNAME("pixacompGetPixDimensions");
1246 
1247  if (!pixac)
1248  return ERROR_INT("pixac not defined", procName, 1);
1249  aindex = index - pixac->offset;
1250  if (aindex < 0 || aindex >= pixac->n)
1251  return ERROR_INT("array index not valid", procName, 1);
1252 
1253  if ((pixc = pixac->pixc[aindex]) == NULL)
1254  return ERROR_INT("pixc not found!", procName, 1);
1255  pixcompGetDimensions(pixc, pw, ph, pd);
1256  return 0;
1257 }
1258 
1259 
1267 BOXA *
1269  l_int32 accesstype)
1270 {
1271  PROCNAME("pixacompGetBoxa");
1272 
1273  if (!pixac)
1274  return (BOXA *)ERROR_PTR("pixac not defined", procName, NULL);
1275  if (!pixac->boxa)
1276  return (BOXA *)ERROR_PTR("boxa not defined", procName, NULL);
1277  if (accesstype != L_COPY && accesstype != L_CLONE &&
1278  accesstype != L_COPY_CLONE)
1279  return (BOXA *)ERROR_PTR("invalid accesstype", procName, NULL);
1280 
1281  return boxaCopy(pixac->boxa, accesstype);
1282 }
1283 
1284 
1291 l_int32
1293 {
1294  PROCNAME("pixacompGetBoxaCount");
1295 
1296  if (!pixac)
1297  return ERROR_INT("pixac not defined", procName, 0);
1298 
1299  return boxaGetCount(pixac->boxa);
1300 }
1301 
1302 
1326 BOX *
1328  l_int32 index,
1329  l_int32 accesstype)
1330 {
1331 l_int32 aindex;
1332 BOX *box;
1333 
1334  PROCNAME("pixacompGetBox");
1335 
1336  if (!pixac)
1337  return (BOX *)ERROR_PTR("pixac not defined", procName, NULL);
1338  if (!pixac->boxa)
1339  return (BOX *)ERROR_PTR("boxa not defined", procName, NULL);
1340  aindex = index - pixac->offset;
1341  if (aindex < 0 || aindex >= pixac->boxa->n)
1342  return (BOX *)ERROR_PTR("array index not valid", procName, NULL);
1343  if (accesstype != L_COPY && accesstype != L_CLONE)
1344  return (BOX *)ERROR_PTR("invalid accesstype", procName, NULL);
1345 
1346  box = pixac->boxa->box[aindex];
1347  if (box) {
1348  if (accesstype == L_COPY)
1349  return boxCopy(box);
1350  else /* accesstype == L_CLONE */
1351  return boxClone(box);
1352  } else {
1353  return NULL;
1354  }
1355 }
1356 
1357 
1373 l_ok
1375  l_int32 index,
1376  l_int32 *px,
1377  l_int32 *py,
1378  l_int32 *pw,
1379  l_int32 *ph)
1380 {
1381 l_int32 aindex;
1382 BOX *box;
1383 
1384  PROCNAME("pixacompGetBoxGeometry");
1385 
1386  if (!pixac)
1387  return ERROR_INT("pixac not defined", procName, 1);
1388  aindex = index - pixac->offset;
1389  if (aindex < 0 || aindex >= pixac->n)
1390  return ERROR_INT("array index not valid", procName, 1);
1391 
1392  if ((box = pixacompGetBox(pixac, aindex, L_CLONE)) == NULL)
1393  return ERROR_INT("box not found!", procName, 1);
1394  boxGetGeometry(box, px, py, pw, ph);
1395  boxDestroy(&box);
1396  return 0;
1397 }
1398 
1399 
1413 l_int32
1415 {
1416  PROCNAME("pixacompGetOffset");
1417 
1418  if (!pixac)
1419  return ERROR_INT("pixac not defined", procName, 0);
1420  return pixac->offset;
1421 }
1422 
1423 
1438 l_ok
1440  l_int32 offset)
1441 {
1442  PROCNAME("pixacompSetOffset");
1443 
1444  if (!pixac)
1445  return ERROR_INT("pixac not defined", procName, 1);
1446  pixac->offset = L_MAX(0, offset);
1447  return 0;
1448 }
1449 
1450 
1451 /*---------------------------------------------------------------------*
1452  * Pixacomp conversion to Pixa *
1453  *---------------------------------------------------------------------*/
1468 PIXA *
1470  l_int32 accesstype)
1471 {
1472 l_int32 i, n, offset;
1473 PIX *pix;
1474 PIXA *pixa;
1475 
1476  PROCNAME("pixaCreateFromPixacomp");
1477 
1478  if (!pixac)
1479  return (PIXA *)ERROR_PTR("pixac not defined", procName, NULL);
1480  if (accesstype != L_COPY && accesstype != L_CLONE &&
1481  accesstype != L_COPY_CLONE)
1482  return (PIXA *)ERROR_PTR("invalid accesstype", procName, NULL);
1483 
1484  n = pixacompGetCount(pixac);
1485  offset = pixacompGetOffset(pixac);
1486  pixacompSetOffset(pixac, 0);
1487  if ((pixa = pixaCreate(n)) == NULL)
1488  return (PIXA *)ERROR_PTR("pixa not made", procName, NULL);
1489  for (i = 0; i < n; i++) {
1490  if ((pix = pixacompGetPix(pixac, i)) == NULL) {
1491  L_WARNING("pix %d not made\n", procName, i);
1492  continue;
1493  }
1494  pixaAddPix(pixa, pix, L_INSERT);
1495  }
1496  if (pixa->boxa) {
1497  boxaDestroy(&pixa->boxa);
1498  pixa->boxa = pixacompGetBoxa(pixac, accesstype);
1499  }
1500  pixacompSetOffset(pixac, offset);
1501 
1502  return pixa;
1503 }
1504 
1505 
1506 /*---------------------------------------------------------------------*
1507  * Combining pixacomp
1508  *---------------------------------------------------------------------*/
1526 l_ok
1528  PIXAC *pixacs,
1529  l_int32 istart,
1530  l_int32 iend)
1531 {
1532 l_int32 i, n, nb;
1533 BOXA *boxas, *boxad;
1534 PIXC *pixc;
1535 
1536  PROCNAME("pixacompJoin");
1537 
1538  if (!pixacd)
1539  return ERROR_INT("pixacd not defined", procName, 1);
1540  if (!pixacs || ((n = pixacompGetCount(pixacs)) == 0))
1541  return 0;
1542 
1543  if (istart < 0)
1544  istart = 0;
1545  if (iend < 0 || iend >= n)
1546  iend = n - 1;
1547  if (istart > iend)
1548  return ERROR_INT("istart > iend; nothing to add", procName, 1);
1549 
1550  for (i = istart; i <= iend; i++) {
1551  pixc = pixacompGetPixcomp(pixacs, i, L_NOCOPY);
1552  pixacompAddPixcomp(pixacd, pixc, L_COPY);
1553  }
1554 
1555  boxas = pixacompGetBoxa(pixacs, L_CLONE);
1556  boxad = pixacompGetBoxa(pixacd, L_CLONE);
1557  nb = pixacompGetBoxaCount(pixacs);
1558  iend = L_MIN(iend, nb - 1);
1559  boxaJoin(boxad, boxas, istart, iend);
1560  boxaDestroy(&boxas); /* just the clones */
1561  boxaDestroy(&boxad); /* ditto */
1562  return 0;
1563 }
1564 
1565 
1579 PIXAC *
1581  PIXAC *pixac2)
1582 {
1583 l_int32 i, n1, n2, n, nb1, nb2;
1584 BOX *box;
1585 PIXC *pixc1, *pixc2;
1586 PIXAC *pixacd;
1587 
1588  PROCNAME("pixacompInterleave");
1589 
1590  if (!pixac1)
1591  return (PIXAC *)ERROR_PTR("pixac1 not defined", procName, NULL);
1592  if (!pixac2)
1593  return (PIXAC *)ERROR_PTR("pixac2 not defined", procName, NULL);
1594  n1 = pixacompGetCount(pixac1);
1595  n2 = pixacompGetCount(pixac2);
1596  n = L_MIN(n1, n2);
1597  if (n == 0)
1598  return (PIXAC *)ERROR_PTR("at least one input pixac is empty",
1599  procName, NULL);
1600  if (n1 != n2)
1601  L_WARNING("counts differ: %d != %d\n", procName, n1, n2);
1602 
1603  pixacd = pixacompCreate(2 * n);
1604  nb1 = pixacompGetBoxaCount(pixac1);
1605  nb2 = pixacompGetBoxaCount(pixac2);
1606  for (i = 0; i < n; i++) {
1607  pixc1 = pixacompGetPixcomp(pixac1, i, L_COPY);
1608  pixacompAddPixcomp(pixacd, pixc1, L_INSERT);
1609  if (i < nb1) {
1610  box = pixacompGetBox(pixac1, i, L_COPY);
1611  pixacompAddBox(pixacd, box, L_INSERT);
1612  }
1613  pixc2 = pixacompGetPixcomp(pixac2, i, L_COPY);
1614  pixacompAddPixcomp(pixacd, pixc2, L_INSERT);
1615  if (i < nb2) {
1616  box = pixacompGetBox(pixac2, i, L_COPY);
1617  pixacompAddBox(pixacd, box, L_INSERT);
1618  }
1619  }
1620 
1621  return pixacd;
1622 }
1623 
1624 
1625 /*---------------------------------------------------------------------*
1626  * Pixacomp serialized I/O *
1627  *---------------------------------------------------------------------*/
1641 PIXAC *
1642 pixacompRead(const char *filename)
1643 {
1644 FILE *fp;
1645 PIXAC *pixac;
1646 
1647  PROCNAME("pixacompRead");
1648 
1649  if (!filename)
1650  return (PIXAC *)ERROR_PTR("filename not defined", procName, NULL);
1651 
1652  if ((fp = fopenReadStream(filename)) == NULL)
1653  return (PIXAC *)ERROR_PTR("stream not opened", procName, NULL);
1654  pixac = pixacompReadStream(fp);
1655  fclose(fp);
1656  if (!pixac)
1657  return (PIXAC *)ERROR_PTR("pixac not read", procName, NULL);
1658  return pixac;
1659 }
1660 
1661 
1668 PIXAC *
1670 {
1671 char buf[256];
1672 l_uint8 *data;
1673 l_int32 n, offset, i, w, h, d, ignore;
1674 l_int32 comptype, size, cmapflag, version, xres, yres;
1675 BOXA *boxa;
1676 PIXC *pixc;
1677 PIXAC *pixac;
1678 
1679  PROCNAME("pixacompReadStream");
1680 
1681  if (!fp)
1682  return (PIXAC *)ERROR_PTR("stream not defined", procName, NULL);
1683 
1684  if (fscanf(fp, "\nPixacomp Version %d\n", &version) != 1)
1685  return (PIXAC *)ERROR_PTR("not a pixacomp file", procName, NULL);
1686  if (version != PIXACOMP_VERSION_NUMBER)
1687  return (PIXAC *)ERROR_PTR("invalid pixacomp version", procName, NULL);
1688  if (fscanf(fp, "Number of pixcomp = %d\n", &n) != 1)
1689  return (PIXAC *)ERROR_PTR("not a pixacomp file", procName, NULL);
1690  if (fscanf(fp, "Offset of index into array = %d", &offset) != 1)
1691  return (PIXAC *)ERROR_PTR("offset not read", procName, NULL);
1692 
1693  if ((pixac = pixacompCreate(n)) == NULL)
1694  return (PIXAC *)ERROR_PTR("pixac not made", procName, NULL);
1695  if ((boxa = boxaReadStream(fp)) == NULL) {
1696  pixacompDestroy(&pixac);
1697  return (PIXAC *)ERROR_PTR("boxa not made", procName, NULL);
1698  }
1699  boxaDestroy(&pixac->boxa); /* empty */
1700  pixac->boxa = boxa;
1701  pixacompSetOffset(pixac, offset);
1702 
1703  for (i = 0; i < n; i++) {
1704  if (fscanf(fp, "\nPixcomp[%d]: w = %d, h = %d, d = %d\n",
1705  &ignore, &w, &h, &d) != 4) {
1706  pixacompDestroy(&pixac);
1707  return (PIXAC *)ERROR_PTR("size reading", procName, NULL);
1708  }
1709  if (fscanf(fp, " comptype = %d, size = %d, cmapflag = %d\n",
1710  &comptype, &size, &cmapflag) != 3) {
1711  pixacompDestroy(&pixac);
1712  return (PIXAC *)ERROR_PTR("comptype/size reading", procName, NULL);
1713  }
1714 
1715  /* Use fgets() and sscanf(); not fscanf(), for the last
1716  * bit of header data before the binary data. The reason is
1717  * that fscanf throws away white space, and if the binary data
1718  * happens to begin with ascii character(s) that are white
1719  * space, it will swallow them and all will be lost! */
1720  if (fgets(buf, sizeof(buf), fp) == NULL) {
1721  pixacompDestroy(&pixac);
1722  return (PIXAC *)ERROR_PTR("fgets read fail", procName, NULL);
1723  }
1724  if (sscanf(buf, " xres = %d, yres = %d\n", &xres, &yres) != 2) {
1725  pixacompDestroy(&pixac);
1726  return (PIXAC *)ERROR_PTR("read fail for res", procName, NULL);
1727  }
1728  if ((data = (l_uint8 *)LEPT_CALLOC(1, size)) == NULL) {
1729  pixacompDestroy(&pixac);
1730  return (PIXAC *)ERROR_PTR("calloc fail for data", procName, NULL);
1731  }
1732  if (fread(data, 1, size, fp) != size) {
1733  pixacompDestroy(&pixac);
1734  LEPT_FREE(data);
1735  return (PIXAC *)ERROR_PTR("error reading data", procName, NULL);
1736  }
1737  fgetc(fp); /* swallow the ending nl */
1738  pixc = (PIXC *)LEPT_CALLOC(1, sizeof(PIXC));
1739  pixc->w = w;
1740  pixc->h = h;
1741  pixc->d = d;
1742  pixc->xres = xres;
1743  pixc->yres = yres;
1744  pixc->comptype = comptype;
1745  pixc->cmapflag = cmapflag;
1746  pixc->data = data;
1747  pixc->size = size;
1748  pixacompAddPixcomp(pixac, pixc, L_INSERT);
1749  }
1750  return pixac;
1751 }
1752 
1753 
1766 PIXAC *
1767 pixacompReadMem(const l_uint8 *data,
1768  size_t size)
1769 {
1770 FILE *fp;
1771 PIXAC *pixac;
1772 
1773  PROCNAME("pixacompReadMem");
1774 
1775  if (!data)
1776  return (PIXAC *)ERROR_PTR("data not defined", procName, NULL);
1777  if ((fp = fopenReadFromMemory(data, size)) == NULL)
1778  return (PIXAC *)ERROR_PTR("stream not opened", procName, NULL);
1779 
1780  pixac = pixacompReadStream(fp);
1781  fclose(fp);
1782  if (!pixac) L_ERROR("pixac not read\n", procName);
1783  return pixac;
1784 }
1785 
1786 
1801 l_ok
1802 pixacompWrite(const char *filename,
1803  PIXAC *pixac)
1804 {
1805 l_int32 ret;
1806 FILE *fp;
1807 
1808  PROCNAME("pixacompWrite");
1809 
1810  if (!filename)
1811  return ERROR_INT("filename not defined", procName, 1);
1812  if (!pixac)
1813  return ERROR_INT("pixacomp not defined", procName, 1);
1814 
1815  if ((fp = fopenWriteStream(filename, "wb")) == NULL)
1816  return ERROR_INT("stream not opened", procName, 1);
1817  ret = pixacompWriteStream(fp, pixac);
1818  fclose(fp);
1819  if (ret)
1820  return ERROR_INT("pixacomp not written to stream", procName, 1);
1821  return 0;
1822 }
1823 
1824 
1832 l_ok
1834  PIXAC *pixac)
1835 {
1836 l_int32 n, i;
1837 PIXC *pixc;
1838 
1839  PROCNAME("pixacompWriteStream");
1840 
1841  if (!fp)
1842  return ERROR_INT("stream not defined", procName, 1);
1843  if (!pixac)
1844  return ERROR_INT("pixac not defined", procName, 1);
1845 
1846  n = pixacompGetCount(pixac);
1847  fprintf(fp, "\nPixacomp Version %d\n", PIXACOMP_VERSION_NUMBER);
1848  fprintf(fp, "Number of pixcomp = %d\n", n);
1849  fprintf(fp, "Offset of index into array = %d", pixac->offset);
1850  boxaWriteStream(fp, pixac->boxa);
1851  for (i = 0; i < n; i++) {
1852  if ((pixc = pixacompGetPixcomp(pixac, pixac->offset + i, L_NOCOPY))
1853  == NULL)
1854  return ERROR_INT("pixc not found", procName, 1);
1855  fprintf(fp, "\nPixcomp[%d]: w = %d, h = %d, d = %d\n",
1856  i, pixc->w, pixc->h, pixc->d);
1857  fprintf(fp, " comptype = %d, size = %lu, cmapflag = %d\n",
1858  pixc->comptype, (unsigned long)pixc->size, pixc->cmapflag);
1859  fprintf(fp, " xres = %d, yres = %d\n", pixc->xres, pixc->yres);
1860  fwrite(pixc->data, 1, pixc->size, fp);
1861  fprintf(fp, "\n");
1862  }
1863  return 0;
1864 }
1865 
1866 
1880 l_ok
1881 pixacompWriteMem(l_uint8 **pdata,
1882  size_t *psize,
1883  PIXAC *pixac)
1884 {
1885 l_int32 ret;
1886 FILE *fp;
1887 
1888  PROCNAME("pixacompWriteMem");
1889 
1890  if (pdata) *pdata = NULL;
1891  if (psize) *psize = 0;
1892  if (!pdata)
1893  return ERROR_INT("&data not defined", procName, 1);
1894  if (!psize)
1895  return ERROR_INT("&size not defined", procName, 1);
1896  if (!pixac)
1897  return ERROR_INT("&pixac not defined", procName, 1);
1898 
1899 #if HAVE_FMEMOPEN
1900  if ((fp = open_memstream((char **)pdata, psize)) == NULL)
1901  return ERROR_INT("stream not opened", procName, 1);
1902  ret = pixacompWriteStream(fp, pixac);
1903 #else
1904  L_INFO("work-around: writing to a temp file\n", procName);
1905  #ifdef _WIN32
1906  if ((fp = fopenWriteWinTempfile()) == NULL)
1907  return ERROR_INT("tmpfile stream not opened", procName, 1);
1908  #else
1909  if ((fp = tmpfile()) == NULL)
1910  return ERROR_INT("tmpfile stream not opened", procName, 1);
1911  #endif /* _WIN32 */
1912  ret = pixacompWriteStream(fp, pixac);
1913  rewind(fp);
1914  *pdata = l_binaryReadStream(fp, psize);
1915 #endif /* HAVE_FMEMOPEN */
1916  fclose(fp);
1917  return ret;
1918 }
1919 
1920 
1921 /*--------------------------------------------------------------------*
1922  * Conversion to pdf *
1923  *--------------------------------------------------------------------*/
1955 l_ok
1957  l_int32 res,
1958  l_float32 scalefactor,
1959  l_int32 type,
1960  l_int32 quality,
1961  const char *title,
1962  const char *fileout)
1963 {
1964 l_uint8 *data;
1965 l_int32 ret;
1966 size_t nbytes;
1967 
1968  PROCNAME("pixacompConvertToPdf");
1969 
1970  if (!pixac)
1971  return ERROR_INT("pixac not defined", procName, 1);
1972 
1973  ret = pixacompConvertToPdfData(pixac, res, scalefactor, type, quality,
1974  title, &data, &nbytes);
1975  if (ret) {
1976  LEPT_FREE(data);
1977  return ERROR_INT("conversion to pdf failed", procName, 1);
1978  }
1979 
1980  ret = l_binaryWrite(fileout, "w", data, nbytes);
1981  LEPT_FREE(data);
1982  if (ret)
1983  L_ERROR("pdf data not written to file\n", procName);
1984  return ret;
1985 }
1986 
1987 
2007 l_ok
2009  l_int32 res,
2010  l_float32 scalefactor,
2011  l_int32 type,
2012  l_int32 quality,
2013  const char *title,
2014  l_uint8 **pdata,
2015  size_t *pnbytes)
2016 {
2017 l_uint8 *imdata;
2018 l_int32 i, n, ret, scaledres, pagetype;
2019 size_t imbytes;
2020 L_BYTEA *ba;
2021 PIX *pixs, *pix;
2022 L_PTRA *pa_data;
2023 
2024  PROCNAME("pixacompConvertToPdfData");
2025 
2026  if (!pdata)
2027  return ERROR_INT("&data not defined", procName, 1);
2028  *pdata = NULL;
2029  if (!pnbytes)
2030  return ERROR_INT("&nbytes not defined", procName, 1);
2031  *pnbytes = 0;
2032  if (!pixac)
2033  return ERROR_INT("pixac not defined", procName, 1);
2034  if (scalefactor <= 0.0) scalefactor = 1.0;
2035  if (type < L_DEFAULT_ENCODE || type > L_FLATE_ENCODE) {
2036  L_WARNING("invalid compression type; using per-page default\n",
2037  procName);
2038  type = L_DEFAULT_ENCODE;
2039  }
2040 
2041  /* Generate all the encoded pdf strings */
2042  n = pixacompGetCount(pixac);
2043  pa_data = ptraCreate(n);
2044  for (i = 0; i < n; i++) {
2045  if ((pixs =
2046  pixacompGetPix(pixac, pixacompGetOffset(pixac) + i)) == NULL) {
2047  L_ERROR("pix[%d] not retrieved\n", procName, i);
2048  continue;
2049  }
2050  if (pixGetWidth(pixs) == 1) { /* used sometimes as placeholders */
2051  L_INFO("placeholder image[%d] has w = 1\n", procName, i);
2052  pixDestroy(&pixs);
2053  continue;
2054  }
2055  if (scalefactor != 1.0)
2056  pix = pixScale(pixs, scalefactor, scalefactor);
2057  else
2058  pix = pixClone(pixs);
2059  pixDestroy(&pixs);
2060  scaledres = (l_int32)(res * scalefactor);
2061  if (type != L_DEFAULT_ENCODE) {
2062  pagetype = type;
2063  } else if (selectDefaultPdfEncoding(pix, &pagetype) != 0) {
2064  L_ERROR("encoding type selection failed for pix[%d]\n",
2065  procName, i);
2066  pixDestroy(&pix);
2067  continue;
2068  }
2069  ret = pixConvertToPdfData(pix, pagetype, quality, &imdata, &imbytes,
2070  0, 0, scaledres, title, NULL, 0);
2071  pixDestroy(&pix);
2072  if (ret) {
2073  L_ERROR("pdf encoding failed for pix[%d]\n", procName, i);
2074  continue;
2075  }
2076  ba = l_byteaInitFromMem(imdata, imbytes);
2077  LEPT_FREE(imdata);
2078  ptraAdd(pa_data, ba);
2079  }
2080  ptraGetActualCount(pa_data, &n);
2081  if (n == 0) {
2082  L_ERROR("no pdf files made\n", procName);
2083  ptraDestroy(&pa_data, FALSE, FALSE);
2084  return 1;
2085  }
2086 
2087  /* Concatenate them */
2088  ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes);
2089 
2090  ptraGetActualCount(pa_data, &n); /* recalculate in case it changes */
2091  for (i = 0; i < n; i++) {
2092  ba = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
2093  l_byteaDestroy(&ba);
2094  }
2095  ptraDestroy(&pa_data, FALSE, FALSE);
2096  return ret;
2097 }
2098 
2099 
2118 l_ok
2120  const char *title,
2121  l_uint8 **pdata,
2122  size_t *pnbytes)
2123 {
2124 l_uint8 *imdata;
2125 l_int32 i, n, ret, comptype;
2126 size_t imbytes;
2127 L_BYTEA *ba;
2128 PIXC *pixc;
2129 L_PTRA *pa_data;
2130 
2131  PROCNAME("pixacompFastConvertToPdfData");
2132 
2133  if (!pdata)
2134  return ERROR_INT("&data not defined", procName, 1);
2135  *pdata = NULL;
2136  if (!pnbytes)
2137  return ERROR_INT("&nbytes not defined", procName, 1);
2138  *pnbytes = 0;
2139  if (!pixac)
2140  return ERROR_INT("pixac not defined", procName, 1);
2141 
2142  /* Generate all the encoded pdf strings */
2143  n = pixacompGetCount(pixac);
2144  pa_data = ptraCreate(n);
2145  for (i = 0; i < n; i++) {
2146  if ((pixc = pixacompGetPixcomp(pixac, i, L_NOCOPY)) == NULL) {
2147  L_ERROR("pixc[%d] not retrieved\n", procName, i);
2148  continue;
2149  }
2150  pixcompGetParameters(pixc, NULL, NULL, &comptype, NULL);
2151  if (comptype != IFF_JFIF_JPEG) {
2152  L_ERROR("pixc[%d] not jpeg compressed\n", procName, i);
2153  continue;
2154  }
2155  ret = pixcompFastConvertToPdfData(pixc, title, &imdata, &imbytes);
2156  if (ret) {
2157  L_ERROR("pdf encoding failed for pixc[%d]\n", procName, i);
2158  continue;
2159  }
2160  ba = l_byteaInitFromMem(imdata, imbytes);
2161  LEPT_FREE(imdata);
2162  ptraAdd(pa_data, ba);
2163  }
2164  ptraGetActualCount(pa_data, &n);
2165  if (n == 0) {
2166  L_ERROR("no pdf files made\n", procName);
2167  ptraDestroy(&pa_data, FALSE, FALSE);
2168  return 1;
2169  }
2170 
2171  /* Concatenate them */
2172  ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes);
2173 
2174  /* Clean up */
2175  ptraGetActualCount(pa_data, &n); /* recalculate in case it changes */
2176  for (i = 0; i < n; i++) {
2177  ba = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
2178  l_byteaDestroy(&ba);
2179  }
2180  ptraDestroy(&pa_data, FALSE, FALSE);
2181  return ret;
2182 }
2183 
2184 
2203 static l_int32
2205  const char *title,
2206  l_uint8 **pdata,
2207  size_t *pnbytes)
2208 {
2209 l_uint8 *data;
2210 L_COMP_DATA *cid;
2211 
2212  PROCNAME("pixacompFastConvertToPdfData");
2213 
2214  if (!pdata)
2215  return ERROR_INT("&data not defined", procName, 1);
2216  *pdata = NULL;
2217  if (!pnbytes)
2218  return ERROR_INT("&nbytes not defined", procName, 1);
2219  *pnbytes = 0;
2220  if (!pixc)
2221  return ERROR_INT("pixc not defined", procName, 1);
2222 
2223  /* Make a copy of the data */
2224  data = l_binaryCopy(pixc->data, pixc->size);
2225  cid = l_generateJpegDataMem(data, pixc->size, 0);
2226 
2227  /* Note: cid is destroyed, along with data, by this function */
2228  return cidConvertToPdfData(cid, title, pdata, pnbytes);
2229 }
2230 
2231 
2232 /*--------------------------------------------------------------------*
2233  * Output for debugging *
2234  *--------------------------------------------------------------------*/
2243 l_ok
2245  PIXAC *pixac,
2246  const char *text)
2247 {
2248 l_int32 i, n, nboxes;
2249 PIXC *pixc;
2250 
2251  PROCNAME("pixacompWriteStreamInfo");
2252 
2253  if (!fp)
2254  return ERROR_INT("fp not defined", procName, 1);
2255  if (!pixac)
2256  return ERROR_INT("pixac not defined", procName, 1);
2257 
2258  if (text)
2259  fprintf(fp, "Pixacomp Info for %s:\n", text);
2260  else
2261  fprintf(fp, "Pixacomp Info:\n");
2262  n = pixacompGetCount(pixac);
2263  nboxes = pixacompGetBoxaCount(pixac);
2264  fprintf(fp, "Number of pixcomp: %d\n", n);
2265  fprintf(fp, "Size of pixcomp array alloc: %d\n", pixac->nalloc);
2266  fprintf(fp, "Offset of index into array: %d\n", pixac->offset);
2267  if (nboxes > 0)
2268  fprintf(fp, "Boxa has %d boxes\n", nboxes);
2269  else
2270  fprintf(fp, "Boxa is empty\n");
2271  for (i = 0; i < n; i++) {
2272  pixc = pixacompGetPixcomp(pixac, pixac->offset + i, L_NOCOPY);
2273  pixcompWriteStreamInfo(fp, pixc, NULL);
2274  }
2275  return 0;
2276 }
2277 
2278 
2287 l_ok
2289  PIXC *pixc,
2290  const char *text)
2291 {
2292  PROCNAME("pixcompWriteStreamInfo");
2293 
2294  if (!fp)
2295  return ERROR_INT("fp not defined", procName, 1);
2296  if (!pixc)
2297  return ERROR_INT("pixc not defined", procName, 1);
2298 
2299  if (text)
2300  fprintf(fp, " Pixcomp Info for %s:", text);
2301  else
2302  fprintf(fp, " Pixcomp Info:");
2303  fprintf(fp, " width = %d, height = %d, depth = %d\n",
2304  pixc->w, pixc->h, pixc->d);
2305  fprintf(fp, " xres = %d, yres = %d, size in bytes = %lu\n",
2306  pixc->xres, pixc->yres, (unsigned long)pixc->size);
2307  if (pixc->cmapflag)
2308  fprintf(fp, " has colormap\n");
2309  else
2310  fprintf(fp, " no colormap\n");
2311  if (pixc->comptype < NumImageFileFormatExtensions) {
2312  fprintf(fp, " comptype = %s (%d)\n",
2313  ImageFileFormatExtensions[pixc->comptype], pixc->comptype);
2314  } else {
2315  fprintf(fp, " Error!! Invalid comptype index: %d\n", pixc->comptype);
2316  }
2317  return 0;
2318 }
2319 
2320 
2343 PIX *
2345  l_int32 outdepth,
2346  l_int32 tilewidth,
2347  l_int32 ncols,
2348  l_int32 background,
2349  l_int32 spacing,
2350  l_int32 border)
2351 {
2352 PIX *pixd;
2353 PIXA *pixa;
2354 
2355  PROCNAME("pixacompDisplayTiledAndScaled");
2356 
2357  if (!pixac)
2358  return (PIX *)ERROR_PTR("pixac not defined", procName, NULL);
2359 
2360  if ((pixa = pixaCreateFromPixacomp(pixac, L_COPY)) == NULL)
2361  return (PIX *)ERROR_PTR("pixa not made", procName, NULL);
2362 
2363  pixd = pixaDisplayTiledAndScaled(pixa, outdepth, tilewidth, ncols,
2364  background, spacing, border);
2365  pixaDestroy(&pixa);
2366  return pixd;
2367 }
2368 
2369 
2377 l_ok
2379  const char *subdir)
2380 {
2381 char buf[128];
2382 l_int32 i, n;
2383 PIXC *pixc;
2384 
2385  PROCNAME("pixacompWriteFiles");
2386 
2387  if (!pixac)
2388  return ERROR_INT("pixac not defined", procName, 1);
2389 
2390  if (lept_mkdir(subdir) > 0)
2391  return ERROR_INT("invalid subdir", procName, 1);
2392 
2393  n = pixacompGetCount(pixac);
2394  for (i = 0; i < n; i++) {
2395  pixc = pixacompGetPixcomp(pixac, i, L_NOCOPY);
2396  snprintf(buf, sizeof(buf), "/tmp/%s/%03d", subdir, i);
2397  pixcompWriteFile(buf, pixc);
2398  }
2399  return 0;
2400 }
2401 
2402 extern const char *ImageFileFormatExtensions[];
2403 
2417 l_ok
2418 pixcompWriteFile(const char *rootname,
2419  PIXC *pixc)
2420 {
2421 char buf[128];
2422 
2423  PROCNAME("pixcompWriteFile");
2424 
2425  if (!pixc)
2426  return ERROR_INT("pixc not defined", procName, 1);
2427 
2428  snprintf(buf, sizeof(buf), "%s.%s", rootname,
2429  ImageFileFormatExtensions[pixc->comptype]);
2430  l_binaryWrite(buf, "w", pixc->data, pixc->size);
2431  return 0;
2432 }
BOXA * boxaReadStream(FILE *fp)
boxaReadStream()
Definition: boxbasic.c:2108
PIXAC * pixacompCreateFromPixa(PIXA *pixa, l_int32 comptype, l_int32 accesstype)
pixacompCreateFromPixa()
Definition: pixcomp.c:721
PIX * pixacompGetPix(PIXAC *pixac, l_int32 index)
pixacompGetPix()
Definition: pixcomp.c:1201
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
Definition: utils2.c:1944
l_ok ptraConcatenatePdfToData(L_PTRA *pa_data, SARRAY *sa, l_uint8 **pdata, size_t *pnbytes)
ptraConcatenatePdfToData()
Definition: pdfio2.c:307
l_int32 n
Definition: pix.h:494
l_ok boxaJoin(BOXA *boxad, BOXA *boxas, l_int32 istart, l_int32 iend)
boxaJoin()
Definition: boxfunc1.c:2351
Definition: pix.h:717
l_ok pixacompAddPix(PIXAC *pixac, PIX *pix, l_int32 comptype)
pixacompAddPix()
Definition: pixcomp.c:908
l_ok ptraGetActualCount(L_PTRA *pa, l_int32 *pcount)
ptraGetActualCount()
Definition: ptra.c:727
l_int32 pixacompGetOffset(PIXAC *pixac)
pixacompGetOffset()
Definition: pixcomp.c:1414
struct Boxa * boxa
Definition: pix.h:460
PIXC * pixcompCreateFromPix(PIX *pix, l_int32 comptype)
pixcompCreateFromPix()
Definition: pixcomp.c:185
l_int32 pixacompGetBoxaCount(PIXAC *pixac)
pixacompGetBoxaCount()
Definition: pixcomp.c:1292
PIX * pixCreateFromPixcomp(PIXC *pixc)
pixCreateFromPixcomp()
Definition: pixcomp.c:537
PIXA * pixaCreate(l_int32 n)
pixaCreate()
Definition: pixabasic.c:163
PIXAC * pixacompRead(const char *filename)
pixacompRead()
Definition: pixcomp.c:1642
l_ok boxaExtendArray(BOXA *boxa)
boxaExtendArray()
Definition: boxbasic.c:665
Definition: pix.h:716
char * stringNew(const char *src)
stringNew()
Definition: utils2.c:215
PIXA * pixaCreateFromPixacomp(PIXAC *pixac, l_int32 accesstype)
pixaCreateFromPixacomp()
Definition: pixcomp.c:1469
l_ok boxaWriteStream(FILE *fp, BOXA *boxa)
boxaWriteStream()
Definition: boxbasic.c:2242
size_t nbytes
Definition: pixalloc.c:120
l_int32 comptype
Definition: pix.h:642
PIXAC * pixacompReadMem(const l_uint8 *data, size_t size)
pixacompReadMem()
Definition: pixcomp.c:1767
L_BYTEA * l_byteaInitFromMem(const l_uint8 *data, size_t size)
l_byteaInitFromMem()
Definition: bytearray.c:121
l_int32 n
Definition: pix.h:660
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
Definition: pix1.c:302
FILE * fopenReadFromMemory(const l_uint8 *data, size_t size)
fopenReadFromMemory()
Definition: utils2.c:1734
l_ok pixacompGetPixDimensions(PIXAC *pixac, l_int32 index, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixacompGetPixDimensions()
Definition: pixcomp.c:1236
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
boxaCopy()
Definition: boxbasic.c:534
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
Definition: boxbasic.c:580
l_ok pixacompFastConvertToPdfData(PIXAC *pixac, const char *title, l_uint8 **pdata, size_t *pnbytes)
pixacompFastConvertToPdfData()
Definition: pixcomp.c:2119
PIXAC * pixacompCreate(l_int32 n)
pixacompCreate()
Definition: pixcomp.c:590
l_ok pixacompReplacePixcomp(PIXAC *pixac, l_int32 index, PIXC *pixc)
pixacompReplacePixcomp()
Definition: pixcomp.c:1073
l_ok cidConvertToPdfData(L_COMP_DATA *cid, const char *title, l_uint8 **pdata, size_t *pnbytes)
cidConvertToPdfData()
Definition: pdfio2.c:1428
l_uint8 * l_binaryCopy(l_uint8 *datas, size_t size)
l_binaryCopy()
Definition: utils2.c:1533
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:1956
l_int32 w
Definition: pix.h:635
BOX * pixacompGetBox(PIXAC *pixac, l_int32 index, l_int32 accesstype)
pixacompGetBox()
Definition: pixcomp.c:1327
PIX * pixReadMem(const l_uint8 *data, size_t size)
pixReadMem()
Definition: readfile.c:839
l_ok pixacompJoin(PIXAC *pixacd, PIXAC *pixacs, l_int32 istart, l_int32 iend)
pixacompJoin()
Definition: pixcomp.c:1527
Definition: pix.h:492
void * reallocNew(void **pindata, l_int32 oldsize, l_int32 newsize)
reallocNew()
Definition: utils2.c:1161
l_ok pixacompWriteMem(l_uint8 **pdata, size_t *psize, PIXAC *pixac)
pixacompWriteMem()
Definition: pixcomp.c:1881
l_ok pixacompGetBoxGeometry(PIXAC *pixac, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
pixacompGetBoxGeometry()
Definition: pixcomp.c:1374
Definition: array.h:116
l_int32 d
Definition: pix.h:637
l_int32 h
Definition: pix.h:636
l_ok pixSetText(PIX *pix, const char *textstring)
pixSetText()
Definition: pix1.c:1483
l_ok pixGetResolution(const PIX *pix, l_int32 *pxres, l_int32 *pyres)
pixGetResolution()
Definition: pix1.c:1313
BOX * boxClone(BOX *box)
boxClone()
Definition: boxbasic.c:252
l_ok l_binaryWrite(const char *filename, const char *operation, const void *data, size_t nbytes)
l_binaryWrite()
Definition: utils2.c:1429
#define PIXACOMP_VERSION_NUMBER
Definition: pix.h:655
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()
Definition: utils2.c:1212
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
Definition: pixabasic.c:503
L_PTRA * ptraCreate(l_int32 n)
ptraCreate()
Definition: ptra.c:139
l_ok pixcompWriteStreamInfo(FILE *fp, PIXC *pixc, const char *text)
pixcompWriteStreamInfo()
Definition: pixcomp.c:2288
static l_int32 pixcompFastConvertToPdfData(PIXC *pixc, const char *title, l_uint8 **pdata, size_t *pnbytes)
pixcompFastConvertToPdfData()
Definition: pixcomp.c:2204
PIXAC * pixacompCreateWithInit(l_int32 n, l_int32 offset, PIX *pix, l_int32 comptype)
pixacompCreateWithInit()
Definition: pixcomp.c:657
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
Definition: boxbasic.c:618
l_ok pixcompGetDimensions(PIXC *pixc, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixcompGetDimensions()
Definition: pixcomp.c:429
PIXAC * pixacompInterleave(PIXAC *pixac1, PIXAC *pixac2)
pixacompInterleave()
Definition: pixcomp.c:1580
Definition: ptra.h:51
l_int32 nalloc
Definition: pix.h:661
FILE * fopenWriteWinTempfile()
fopenWriteWinTempfile()
Definition: utils2.c:1780
l_ok findFileFormat(const char *filename, l_int32 *pformat)
findFileFormat()
Definition: readfile.c:580
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
Definition: sarray1.c:681
l_int32 xres
Definition: pix.h:638
PIXAC * pixacompCreateFromFiles(const char *dirname, const char *substr, l_int32 comptype)
pixacompCreateFromFiles()
Definition: pixcomp.c:780
PIXAC * pixacompReadStream(FILE *fp)
pixacompReadStream()
Definition: pixcomp.c:1669
l_ok pixcompGetParameters(PIXC *pixc, l_int32 *pxres, l_int32 *pyres, l_int32 *pcomptype, l_int32 *pcmapflag)
pixcompGetParameters()
Definition: pixcomp.c:453
l_ok pixacompAddPixcomp(PIXAC *pixac, PIXC *pixc, l_int32 copyflag)
pixacompAddPixcomp()
Definition: pixcomp.c:950
PIX * pixClone(PIX *pixs)
pixClone()
Definition: pix1.c:515
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:1137
PIXC * pixacompGetPixcomp(PIXAC *pixac, l_int32 index, l_int32 copyflag)
pixacompGetPixcomp()
Definition: pixcomp.c:1164
Definition: pix.h:658
void pixacompDestroy(PIXAC **ppixac)
pixacompDestroy()
Definition: pixcomp.c:861
void pixDestroy(PIX **ppix)
pixDestroy()
Definition: pix1.c:543
static l_int32 pixacompExtendArray(PIXAC *pixac)
pixacompExtendArray()
Definition: pixcomp.c:993
l_ok pixacompReplacePix(PIXAC *pixac, l_int32 index, PIX *pix, l_int32 comptype)
pixacompReplacePix()
Definition: pixcomp.c:1028
struct Boxa * boxa
Definition: pix.h:664
l_ok selectDefaultPdfEncoding(PIX *pix, l_int32 *ptype)
selectDefaultPdfEncoding()
Definition: pdfio1.c:457
l_ok pixacompWriteStreamInfo(FILE *fp, PIXAC *pixac, const char *text)
pixacompWriteStreamInfo()
Definition: pixcomp.c:2244
SARRAY * getSortedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
getSortedPathnamesInDirectory()
Definition: sarray1.c:1717
Definition: pix.h:454
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
Definition: pix1.c:1065
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
Definition: utils2.c:1700
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:2008
PIXAC * pixacompCreateFromSA(SARRAY *sa, l_int32 comptype)
pixacompCreateFromSA()
Definition: pixcomp.c:819
Definition: pix.h:633
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:182
void ptraDestroy(L_PTRA **ppa, l_int32 freeflag, l_int32 warnflag)
ptraDestroy()
Definition: ptra.c:185
FILE * fopenReadStream(const char *filename)
fopenReadStream()
Definition: utils2.c:1657
l_ok pixacompWrite(const char *filename, PIXAC *pixac)
pixacompWrite()
Definition: pixcomp.c:1802
l_uint8 * l_binaryReadStream(FILE *fp, size_t *pnbytes)
l_binaryReadStream()
Definition: utils2.c:1262
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:2344
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
Definition: sarray1.c:621
l_ok ptraAdd(L_PTRA *pa, void *item)
ptraAdd()
Definition: ptra.c:242
PIX * pixRead(const char *filename)
pixRead()
Definition: readfile.c:190
char * pixGetText(PIX *pix)
pixGetText()
Definition: pix1.c:1459
l_int32 yres
Definition: pix.h:640
l_ok pixacompWriteFiles(PIXAC *pixac, const char *subdir)
pixacompWriteFiles()
Definition: pixcomp.c:2378
PIXC * pixcompCreateFromString(l_uint8 *data, size_t size, l_int32 copyflag)
pixcompCreateFromString()
Definition: pixcomp.c:242
char * text
Definition: pix.h:644
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
Definition: pixabasic.c:672
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:968
PIXC * pixcompCreateFromFile(const char *filename, l_int32 comptype)
pixcompCreateFromFile()
Definition: pixcomp.c:291
Definition: pix.h:718
void * ptraRemove(L_PTRA *pa, l_int32 index, l_int32 flag)
ptraRemove()
Definition: ptra.c:434
BOX * boxCopy(BOX *box)
boxCopy()
Definition: boxbasic.c:230
Definition: pix.h:134
PIXC * pixcompCopy(PIXC *pixcs)
pixcompCopy()
Definition: pixcomp.c:384
void pixcompDestroy(PIXC **ppixc)
pixcompDestroy()
Definition: pixcomp.c:354
Definition: pix.h:719
l_int32 cmapflag
Definition: pix.h:645
BOXA * boxaCreate(l_int32 n)
boxaCreate()
Definition: boxbasic.c:499
l_uint8 * data
Definition: pix.h:646
void boxDestroy(BOX **pbox)
boxDestroy()
Definition: boxbasic.c:278
l_int32 boxaGetCount(BOXA *boxa)
boxaGetCount()
Definition: boxbasic.c:718
l_int32 pixacompGetCount(PIXAC *pixac)
pixacompGetCount()
Definition: pixcomp.c:1136
l_ok pixSetResolution(PIX *pix, l_int32 xres, l_int32 yres)
pixSetResolution()
Definition: pix1.c:1339
void l_byteaDestroy(L_BYTEA **pba)
l_byteaDestroy()
Definition: bytearray.c:244
l_int32 offset
Definition: pix.h:662
struct PixComp ** pixc
Definition: pix.h:663
struct Box ** box
Definition: pix.h:497
L_COMP_DATA * l_generateJpegDataMem(l_uint8 *data, size_t nbytes, l_int32 ascii85flag)
l_generateJpegDataMem()
Definition: pdfio2.c:830
l_ok boxGetGeometry(BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
Definition: boxbasic.c:310
Definition: pix.h:480
PIX * pixScale(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScale()
Definition: scale1.c:244
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
Definition: pixabasic.c:408
l_ok pixacompWriteStream(FILE *fp, PIXAC *pixac)
pixacompWriteStream()
Definition: pixcomp.c:1833
l_ok pixcompDetermineFormat(l_int32 comptype, l_int32 d, l_int32 cmapflag, l_int32 *pformat)
pixcompDetermineFormat()
Definition: pixcomp.c:495
l_ok pixcompWriteFile(const char *rootname, PIXC *pixc)
pixcompWriteFile()
Definition: pixcomp.c:2418
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
Definition: pixabasic.c:631
BOXA * pixacompGetBoxa(PIXAC *pixac, l_int32 accesstype)
pixacompGetBoxa()
Definition: pixcomp.c:1268
size_t size
Definition: pix.h:647
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
Definition: sarray1.c:355
l_ok pixacompSetOffset(PIXAC *pixac, l_int32 offset)
pixacompSetOffset()
Definition: pixcomp.c:1439
Definition: array.h:126
l_ok pixacompAddBox(PIXAC *pixac, BOX *box, l_int32 copyflag)
pixacompAddBox()
Definition: pixcomp.c:1108
BOXA * pixaGetBoxa(PIXA *pixa, l_int32 accesstype)
pixaGetBoxa()
Definition: pixabasic.c:741