108 #include <config_auto.h> 113 #include <sys/types.h> 120 #include "allheaders.h" 129 static const l_int32 DefaultResolution = 300;
130 static const l_int32 ManyPagesInTiffFile = 3000;
133 static const l_int32 MaxTiffWidth = 1 << 20;
134 static const l_int32 MaxTiffHeight = 1 << 20;
137 static const size_t MaxNumTiffBytes = (1 << 28) - 1;
144 l_int32 *pheight, l_int32 *pbps,
145 l_int32 *pspp, l_int32 *pres,
146 l_int32 *pcmap, l_int32 *pformat);
153 static TIFF *
fopenTiff(FILE *fp,
const char *modestring);
154 static TIFF *
openTiff(
const char *filename,
const char *modestring);
161 l_uint8 **pdata,
size_t *pdatasize);
194 static struct tiff_transform tiff_partial_orientation_transforms[] = {
222 lept_read_proc(thandle_t cookie,
226 FILE* fp = (FILE *)cookie;
228 if (!buff || !cookie || !fp)
230 done = fread(buff, 1, size, fp);
235 lept_write_proc(thandle_t cookie,
239 FILE* fp = (FILE *)cookie;
241 if (!buff || !cookie || !fp)
243 done = fwrite(buff, 1, size, fp);
248 lept_seek_proc(thandle_t cookie,
252 FILE* fp = (FILE *)cookie;
253 #if defined(_MSC_VER) 265 _fseeki64(fp, 0, SEEK_END);
269 pos = (__int64)(pos + offs);
270 _fseeki64(fp, pos, SEEK_SET);
271 if (pos == _ftelli64(fp))
273 #elif defined(_LARGEFILE64_SOURCE) 285 fseeko(fp, 0, SEEK_END);
289 pos = (off64_t)(pos + offs);
290 fseeko(fp, pos, SEEK_SET);
291 if (pos == ftello(fp))
305 fseek(fp, 0, SEEK_END);
309 pos = (off_t)(pos + offs);
310 fseek(fp, pos, SEEK_SET);
311 if (pos == ftell(fp))
318 lept_close_proc(thandle_t cookie)
320 FILE* fp = (FILE *)cookie;
323 fseek(fp, 0, SEEK_SET);
328 lept_size_proc(thandle_t cookie)
330 FILE* fp = (FILE *)cookie;
331 #if defined(_MSC_VER) 337 _fseeki64(fp, 0, SEEK_END);
338 size = _ftelli64(fp);
339 _fseeki64(fp, pos, SEEK_SET);
340 #elif defined(_LARGEFILE64_SOURCE) 346 fseeko(fp, 0, SEEK_END);
348 fseeko(fp, pos, SEEK_SET);
355 fseek(fp, 0, SEEK_END);
357 fseek(fp, pos, SEEK_SET);
389 PROCNAME(
"pixReadTiff");
392 return (
PIX *)ERROR_PTR(
"filename not defined", procName, NULL);
395 return (
PIX *)ERROR_PTR(
"image file not found", procName, NULL);
426 PROCNAME(
"pixReadStreamTiff");
429 return (
PIX *)ERROR_PTR(
"stream not defined", procName, NULL);
432 return (
PIX *)ERROR_PTR(
"tif not opened", procName, NULL);
434 if (TIFFSetDirectory(tif, n) == 0) {
488 l_uint8 *linebuf, *data, *rowptr;
489 l_uint16 spp, bps, photometry, tiffcomp, orientation, sample_fmt;
490 l_uint16 *redmap, *greenmap, *bluemap;
491 l_int32 d, wpl, bpl, comptype, i, j, k, ncolors, rval, gval, bval, aval;
492 l_int32 xres, yres, tiffbpl, packedbpl, half_size, twothirds_size;
493 l_uint32 w, h, tiffword, read_oriented;
494 l_uint32 *line, *ppixel, *tiffdata, *pixdata;
498 PROCNAME(
"pixReadFromTiffStream");
501 return (
PIX *)ERROR_PTR(
"tif not defined", procName, NULL);
510 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_fmt);
511 if (sample_fmt != SAMPLEFORMAT_UINT) {
512 L_ERROR(
"sample format = %d is not uint\n", procName, sample_fmt);
521 if (TIFFIsTiled(tif)) {
522 L_ERROR(
"tiled format is not supported\n", procName);
533 TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &tiffcomp);
534 if (tiffcomp == COMPRESSION_OJPEG) {
535 L_ERROR(
"old style jpeg format is not supported\n", procName);
540 #if defined(COMPRESSION_WEBP) 541 if (tiffcomp == COMPRESSION_WEBP) {
542 L_ERROR(
"webp in tiff not generally supported yet\n", procName);
548 TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bps);
549 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &spp);
550 if (bps != 1 && bps != 2 && bps != 4 && bps != 8 && bps != 16) {
551 L_ERROR(
"invalid bps = %d\n", procName, bps);
554 if (spp == 2 && bps != 8) {
555 L_WARNING(
"for 2 spp, only handle 8 bps\n", procName);
560 }
else if (spp == 2) {
562 }
else if (spp == 3 || spp == 4) {
565 L_ERROR(
"spp = %d; not in {1,2,3,4}\n", procName, spp);
569 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
570 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
571 if (w > MaxTiffWidth) {
572 L_ERROR(
"width = %d pixels; too large\n", procName, w);
575 if (h > MaxTiffHeight) {
576 L_ERROR(
"height = %d pixels; too large\n", procName, h);
586 tiffbpl = TIFFScanlineSize(tif);
587 packedbpl = (bps * spp * w + 7) / 8;
588 half_size = (L_ABS(2 * tiffbpl - packedbpl) <= 8);
589 twothirds_size = (L_ABS(3 * tiffbpl - 2 * packedbpl) <= 8);
592 L_INFO(
"half_size: packedbpl = %d is approx. twice tiffbpl = %d\n",
593 procName, packedbpl, tiffbpl);
595 L_INFO(
"twothirds_size: packedbpl = %d is approx. 1.5 tiffbpl = %d\n",
596 procName, packedbpl, tiffbpl);
597 lept_stderr(
"tiffbpl = %d, packedbpl = %d, bps = %d, spp = %d, w = %d\n",
598 tiffbpl, packedbpl, bps, spp, w);
600 if (tiffbpl != packedbpl && !half_size && !twothirds_size) {
601 L_ERROR(
"invalid tiffbpl: tiffbpl = %d, packedbpl = %d, " 602 "bps = %d, spp = %d, w = %d\n",
603 procName, tiffbpl, packedbpl, bps, spp, w);
610 return (
PIX *)ERROR_PTR(
"pix not made", procName, NULL);
611 pixSetInputFormat(pix, IFF_TIFF);
613 wpl = pixGetWpl(pix);
616 linebuf = (l_uint8 *)LEPT_CALLOC(4 * wpl,
sizeof(l_uint8));
617 for (i = 0; i < h; i++) {
618 if (TIFFReadScanline(tif, linebuf, i, 0) < 0) {
621 L_ERROR(
"spp = 1, read fail at line %d\n", procName, i);
624 memcpy(data, linebuf, tiffbpl);
632 }
else if (spp == 2 && bps == 8) {
633 L_INFO(
"gray+alpha is not supported; converting to RGBA\n", procName);
635 linebuf = (l_uint8 *)LEPT_CALLOC(4 * wpl,
sizeof(l_uint8));
637 for (i = 0; i < h; i++) {
638 if (TIFFReadScanline(tif, linebuf, i, 0) < 0) {
641 L_ERROR(
"spp = 2, read fail at line %d\n", procName, i);
645 ppixel = pixdata + i * wpl;
646 for (j = k = 0; j < w; j++) {
657 if ((tiffdata = (l_uint32 *)LEPT_CALLOC((
size_t)w * h,
658 sizeof(l_uint32))) == NULL) {
660 return (
PIX *)ERROR_PTR(
"calloc fail for tiffdata", procName, NULL);
663 if (!TIFFReadRGBAImageOriented(tif, w, h, tiffdata,
664 ORIENTATION_TOPLEFT, 0)) {
667 return (
PIX *)ERROR_PTR(
"failed to read tiffdata", procName, NULL);
672 if (spp == 4) pixSetSpp(pix, 4);
674 for (i = 0; i < h; i++, line += wpl) {
675 for (j = 0, ppixel = line; j < w; j++) {
677 tiffword = tiffdata[i * w + j];
678 rval = TIFFGetR(tiffword);
679 gval = TIFFGetG(tiffword);
680 bval = TIFFGetB(tiffword);
684 aval = TIFFGetA(tiffword);
694 pixSetXRes(pix, xres);
695 pixSetYRes(pix, yres);
700 pixSetInputFormat(pix, comptype);
702 if (TIFFGetField(tif, TIFFTAG_COLORMAP, &redmap, &greenmap, &bluemap)) {
709 return (
PIX *)ERROR_PTR(
"colormap size > 256", procName, NULL);
713 return (
PIX *)ERROR_PTR(
"colormap not made", procName, NULL);
716 for (i = 0; i < ncolors; i++)
721 return (
PIX *)ERROR_PTR(
"invalid colormap", procName, NULL);
731 if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometry)) {
734 if (tiffcomp == COMPRESSION_CCITTFAX3 ||
735 tiffcomp == COMPRESSION_CCITTFAX4 ||
736 tiffcomp == COMPRESSION_CCITTRLE ||
737 tiffcomp == COMPRESSION_CCITTRLEW) {
738 photometry = PHOTOMETRIC_MINISWHITE;
740 photometry = PHOTOMETRIC_MINISBLACK;
743 if ((d == 1 && photometry == PHOTOMETRIC_MINISBLACK) ||
744 (d == 8 && photometry == PHOTOMETRIC_MINISWHITE))
748 if (TIFFGetField(tif, TIFFTAG_ORIENTATION, &orientation)) {
749 if (orientation >= 1 && orientation <= 8) {
751 &tiff_partial_orientation_transforms[orientation - 1] :
752 &tiff_orientation_transforms[orientation - 1];
753 if (transform->vflip)
pixFlipTB(pix, pix);
754 if (transform->hflip)
pixFlipLR(pix, pix);
755 if (transform->rotate) {
764 TIFFGetField(tif, TIFFTAG_IMAGEDESCRIPTION, &text);
801 NULL, NULL, NULL, NULL);
864 PROCNAME(
"pixWriteTiffCustom");
867 return ERROR_INT(
"filename not defined", procName, 1);
869 return ERROR_INT(
"pix not defined", procName, 1);
871 if ((tif =
openTiff(filename, modestr)) == NULL)
872 return ERROR_INT(
"tif not opened", procName, 1);
943 PROCNAME(
"pixWriteStreamTiffWA");
946 return ERROR_INT(
"stream not defined", procName, 1 );
948 return ERROR_INT(
"pix not defined", procName, 1 );
949 if (strcmp(modestr,
"w") && strcmp(modestr,
"a")) {
950 L_ERROR(
"modestr = %s; not 'w' or 'a'\n", procName, modestr);
954 if (pixGetDepth(pix) != 1 && comptype != IFF_TIFF &&
955 comptype != IFF_TIFF_LZW && comptype != IFF_TIFF_ZIP &&
956 comptype != IFF_TIFF_JPEG) {
957 L_WARNING(
"invalid compression type %d for bpp > 1; using TIFF_ZIP\n",
959 comptype = IFF_TIFF_ZIP;
962 if ((tif =
fopenTiff(fp, modestr)) == NULL)
963 return ERROR_INT(
"tif not opened", procName, 1);
967 return ERROR_INT(
"tif write error", procName, 1);
1019 l_uint8 *linebuf, *data;
1020 l_uint16 redmap[256], greenmap[256], bluemap[256];
1021 l_int32 w, h, d, spp, i, j, k, wpl, bpl, tiffbpl, ncolors, cmapsize;
1022 l_int32 *rmap, *gmap, *bmap;
1024 l_uint32 *line, *ppixel;
1029 PROCNAME(
"pixWriteToTiffStream");
1032 return ERROR_INT(
"tif stream not defined", procName, 1);
1034 return ERROR_INT(
"pix not defined", procName, 1 );
1038 spp = pixGetSpp(pix);
1039 xres = pixGetXRes(pix);
1040 yres = pixGetYRes(pix);
1041 if (xres == 0) xres = DefaultResolution;
1042 if (yres == 0) yres = DefaultResolution;
1045 TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, (l_uint32)RESUNIT_INCH);
1046 TIFFSetField(tif, TIFFTAG_XRESOLUTION, (l_float64)xres);
1047 TIFFSetField(tif, TIFFTAG_YRESOLUTION, (l_float64)yres);
1049 TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (l_uint32)w);
1050 TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (l_uint32)h);
1051 TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
1054 TIFFSetField(tif, TIFFTAG_IMAGEDESCRIPTION, text);
1056 if (d == 1 && !pixGetColormap(pix)) {
1061 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
1062 }
else if ((d == 32 && spp == 3) || d == 24) {
1063 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1064 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)3);
1065 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE,
1066 (l_uint16)8, (l_uint16)8, (l_uint16)8);
1067 }
else if (d == 32 && spp == 4) {
1069 val[0] = EXTRASAMPLE_ASSOCALPHA;
1070 TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, (l_uint16)1, &val);
1071 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1072 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)4);
1073 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE,
1074 (l_uint16)8, (l_uint16)8, (l_uint16)8, (l_uint16)8);
1075 }
else if (d == 16) {
1076 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1077 }
else if ((cmap = pixGetColormap(pix)) == NULL) {
1078 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1081 L_ERROR(
"d = %d > 8 with colormap!; reducing to 8\n", procName, d);
1086 ncolors = L_MIN(256, ncolors);
1088 cmapsize = L_MIN(256, cmapsize);
1089 if (ncolors > cmapsize) {
1090 L_WARNING(
"too many colors in cmap for tiff; truncating\n",
1094 for (i = 0; i < ncolors; i++) {
1095 redmap[i] = (rmap[i] << 8) | rmap[i];
1096 greenmap[i] = (gmap[i] << 8) | gmap[i];
1097 bluemap[i] = (bmap[i] << 8) | bmap[i];
1099 for (i = ncolors; i < cmapsize; i++)
1100 redmap[i] = greenmap[i] = bluemap[i] = 0;
1105 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_PALETTE);
1106 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)1);
1107 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, (l_uint16)d);
1108 TIFFSetField(tif, TIFFTAG_COLORMAP, redmap, greenmap, bluemap);
1112 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, (l_uint16)d);
1113 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)1);
1116 TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
1117 if (comptype == IFF_TIFF) {
1118 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
1119 }
else if (comptype == IFF_TIFF_G4) {
1120 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
1121 }
else if (comptype == IFF_TIFF_G3) {
1122 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX3);
1123 }
else if (comptype == IFF_TIFF_RLE) {
1124 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_CCITTRLE);
1125 }
else if (comptype == IFF_TIFF_PACKBITS) {
1126 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
1127 }
else if (comptype == IFF_TIFF_LZW) {
1128 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
1129 }
else if (comptype == IFF_TIFF_ZIP) {
1130 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_ADOBE_DEFLATE);
1131 }
else if (comptype == IFF_TIFF_JPEG) {
1132 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);
1134 L_WARNING(
"unknown tiff compression; using none\n", procName);
1135 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
1142 tiffbpl = TIFFScanlineSize(tif);
1143 wpl = pixGetWpl(pix);
1146 lept_stderr(
"Big trouble: tiffbpl = %d, bpl = %d\n", tiffbpl, bpl);
1147 if ((linebuf = (l_uint8 *)LEPT_CALLOC(1, bpl)) == NULL)
1148 return ERROR_INT(
"calloc fail for linebuf", procName, 1);
1151 TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, h);
1153 if (d != 24 && d != 32) {
1159 for (i = 0; i < h; i++, data += bpl) {
1160 memcpy(linebuf, data, tiffbpl);
1161 if (TIFFWriteScanline(tif, linebuf, i, 0) < 0)
1165 }
else if (d == 24) {
1166 for (i = 0; i < h; i++) {
1168 if (TIFFWriteScanline(tif, (l_uint8 *)line, i, 0) < 0)
1172 for (i = 0; i < h; i++) {
1174 for (j = 0, k = 0, ppixel = line; j < w; j++) {
1182 if (TIFFWriteScanline(tif, linebuf, i, 0) < 0)
1231 l_int32 i, n, ns, size, tagval, val;
1233 l_uint32 uval, uval2;
1235 PROCNAME(
"writeCustomTiffTags");
1238 return ERROR_INT(
"tif stream not defined", procName, 1);
1239 if (!natags && !savals && !satypes)
1241 if (!natags || !savals || !satypes)
1242 return ERROR_INT(
"not all arrays defined", procName, 1);
1245 return ERROR_INT(
"not all sa the same size", procName, 1);
1251 return ERROR_INT(
"too many 4-arg tag calls", procName, 1);
1252 for (i = 0; i < ns; i++) {
1257 if (strcmp(type,
"char*") && strcmp(type,
"l_uint8*"))
1258 L_WARNING(
"array type not char* or l_uint8*; ignore\n",
1260 TIFFSetField(tif, tagval, size, sval);
1267 for (i = ns; i < n; i++) {
1271 if (!strcmp(type,
"char*") || !strcmp(type,
"const char*")) {
1272 TIFFSetField(tif, tagval, sval);
1273 }
else if (!strcmp(type,
"l_uint16")) {
1274 if (sscanf(sval,
"%u", &uval) == 1) {
1275 TIFFSetField(tif, tagval, (l_uint16)uval);
1277 lept_stderr(
"val %s not of type %s\n", sval, type);
1278 return ERROR_INT(
"custom tag(s) not written", procName, 1);
1280 }
else if (!strcmp(type,
"l_uint32")) {
1281 if (sscanf(sval,
"%u", &uval) == 1) {
1282 TIFFSetField(tif, tagval, uval);
1284 lept_stderr(
"val %s not of type %s\n", sval, type);
1285 return ERROR_INT(
"custom tag(s) not written", procName, 1);
1287 }
else if (!strcmp(type,
"l_int32")) {
1288 if (sscanf(sval,
"%d", &val) == 1) {
1289 TIFFSetField(tif, tagval, val);
1291 lept_stderr(
"val %s not of type %s\n", sval, type);
1292 return ERROR_INT(
"custom tag(s) not written", procName, 1);
1294 }
else if (!strcmp(type,
"l_float64")) {
1295 if (sscanf(sval,
"%lf", &dval) == 1) {
1296 TIFFSetField(tif, tagval, dval);
1298 lept_stderr(
"val %s not of type %s\n", sval, type);
1299 return ERROR_INT(
"custom tag(s) not written", procName, 1);
1301 }
else if (!strcmp(type,
"l_uint16-l_uint16")) {
1302 if (sscanf(sval,
"%u-%u", &uval, &uval2) == 2) {
1303 TIFFSetField(tif, tagval, (l_uint16)uval, (l_uint16)uval2);
1305 lept_stderr(
"val %s not of type %s\n", sval, type);
1306 return ERROR_INT(
"custom tag(s) not written", procName, 1);
1310 return ERROR_INT(
"unknown type; tag(s) not written", procName, 1);
1360 PROCNAME(
"pixReadFromMultipageTiff");
1363 return (
PIX *)ERROR_PTR(
"fname not defined", procName, NULL);
1365 return (
PIX *)ERROR_PTR(
"&offset not defined", procName, NULL);
1367 if ((tif =
openTiff(fname,
"r")) == NULL) {
1368 L_ERROR(
"tif open failed for %s\n", procName, fname);
1374 retval = (offset == 0) ? TIFFSetDirectory(tif, 0)
1375 : TIFFSetSubDirectory(tif, offset);
1387 TIFFReadDirectory(tif);
1388 *poffset = TIFFCurrentDirOffset(tif);
1409 PROCNAME(
"pixaReadMultipageTiff");
1412 return (
PIXA *)ERROR_PTR(
"filename not defined", procName, NULL);
1415 return (
PIXA *)ERROR_PTR(
"stream not opened", procName, NULL);
1418 L_INFO(
" Tiff: %d pages\n", procName, npages);
1420 return (
PIXA *)ERROR_PTR(
"file not tiff", procName, NULL);
1424 return (
PIXA *)ERROR_PTR(
"tif not opened", procName, NULL);
1428 for (i = 0; i < npages; i++) {
1432 L_WARNING(
"pix not read for page %d\n", procName, i);
1436 if (TIFFReadDirectory(tif) == 0)
1464 const char *modestr;
1468 PROCNAME(
"pixaWriteMultipageTiff");
1471 return ERROR_INT(
"fname not defined", procName, 1);
1473 return ERROR_INT(
"pixa not defined", procName, 1);
1476 for (i = 0; i < n; i++) {
1477 modestr = (i == 0) ?
"w" :
"a";
1479 if (pixGetDepth(pix1) == 1)
1517 const char *fileout)
1521 PROCNAME(
"writeMultipageTiff");
1524 return ERROR_INT(
"dirin not defined", procName, 1);
1526 return ERROR_INT(
"fileout not defined", procName, 1);
1552 const char *fileout)
1556 l_int32 i, nfiles, firstfile, format;
1559 PROCNAME(
"writeMultipageTiffSA");
1562 return ERROR_INT(
"sa not defined", procName, 1);
1564 return ERROR_INT(
"fileout not defined", procName, 1);
1568 for (i = 0; i < nfiles; i++) {
1569 op = (firstfile) ?
"w" :
"a";
1572 if (format == IFF_UNKNOWN) {
1573 L_INFO(
"format of %s not known\n", procName, fname);
1577 if ((pix =
pixRead(fname)) == NULL) {
1578 L_WARNING(
"pix not made for file: %s\n", procName, fname);
1581 if (pixGetDepth(pix) == 1)
1605 const char *tiffile)
1609 PROCNAME(
"fprintTiffInfo");
1612 return ERROR_INT(
"tiffile not defined", procName, 1);
1614 return ERROR_INT(
"stream out not defined", procName, 1);
1616 if ((tif =
openTiff(tiffile,
"rb")) == NULL)
1617 return ERROR_INT(
"tif not open for read", procName, 1);
1619 TIFFPrintDirectory(tif, fpout, 0);
1643 PROCNAME(
"tiffGetCount");
1646 return ERROR_INT(
"stream not defined", procName, 1);
1648 return ERROR_INT(
"&n not defined", procName, 1);
1652 return ERROR_INT(
"tif not open for read", procName, 1);
1654 for (i = 1; ; i++) {
1655 if (TIFFReadDirectory(tif) == 0)
1657 if (i == ManyPagesInTiffFile + 1) {
1658 L_WARNING(
"big file: more than %d pages\n", procName,
1659 ManyPagesInTiffFile);
1691 PROCNAME(
"getTiffResolution");
1693 if (!pxres || !pyres)
1694 return ERROR_INT(
"&xres and &yres not both defined", procName, 1);
1695 *pxres = *pyres = 0;
1697 return ERROR_INT(
"stream not opened", procName, 1);
1700 return ERROR_INT(
"tif not open for read", procName, 1);
1726 l_int32 foundxres, foundyres;
1727 l_float32 fxres, fyres;
1729 PROCNAME(
"getTiffStreamResolution");
1732 return ERROR_INT(
"tif not opened", procName, 1);
1733 if (!pxres || !pyres)
1734 return ERROR_INT(
"&xres and &yres not both defined", procName, 1);
1735 *pxres = *pyres = 0;
1737 TIFFGetFieldDefaulted(tif, TIFFTAG_RESOLUTIONUNIT, &resunit);
1738 foundxres = TIFFGetField(tif, TIFFTAG_XRESOLUTION, &fxres);
1739 foundyres = TIFFGetField(tif, TIFFTAG_YRESOLUTION, &fyres);
1740 if (!foundxres && !foundyres)
return 1;
1741 if (isnan(fxres) || isnan(fyres))
return 1;
1742 if (!foundxres && foundyres)
1744 else if (foundxres && !foundyres)
1748 if (fxres < 0 || fxres > (1L << 29) || fyres < 0 || fyres > (1L << 29))
1749 return ERROR_INT(
"fxres and/or fyres values are invalid", procName, 1);
1751 if (resunit == RESUNIT_CENTIMETER) {
1752 *pxres = (l_int32)(2.54 * fxres + 0.5);
1753 *pyres = (l_int32)(2.54 * fyres + 0.5);
1755 *pxres = (l_int32)fxres;
1756 *pyres = (l_int32)fyres;
1800 PROCNAME(
"readHeaderTiff");
1804 if (pbps) *pbps = 0;
1805 if (pspp) *pspp = 0;
1806 if (pres) *pres = 0;
1807 if (pcmap) *pcmap = 0;
1808 if (pformat) *pformat = 0;
1810 return ERROR_INT(
"filename not defined", procName, 1);
1811 if (!pw && !ph && !pbps && !pspp && !pres && !pcmap && !pformat)
1812 return ERROR_INT(
"no results requested", procName, 1);
1815 return ERROR_INT(
"image file not found", procName, 1);
1816 ret =
freadHeaderTiff(fp, n, pw, ph, pbps, pspp, pres, pcmap, pformat);
1853 l_int32 i, ret, format;
1856 PROCNAME(
"freadHeaderTiff");
1860 if (pbps) *pbps = 0;
1861 if (pspp) *pspp = 0;
1862 if (pres) *pres = 0;
1863 if (pcmap) *pcmap = 0;
1864 if (pformat) *pformat = 0;
1866 return ERROR_INT(
"stream not defined", procName, 1);
1868 return ERROR_INT(
"image index must be >= 0", procName, 1);
1869 if (!pw && !ph && !pbps && !pspp && !pres && !pcmap && !pformat)
1870 return ERROR_INT(
"no results requested", procName, 1);
1873 if (!L_FORMAT_IS_TIFF(format))
1874 return ERROR_INT(
"file not tiff format", procName, 1);
1877 return ERROR_INT(
"tif not open for read", procName, 1);
1879 for (i = 0; i < n; i++) {
1880 if (TIFFReadDirectory(tif) == 0)
1881 return ERROR_INT(
"image n not found in file", procName, 1);
1926 PROCNAME(
"readHeaderMemTiff");
1930 if (pbps) *pbps = 0;
1931 if (pspp) *pspp = 0;
1932 if (pres) *pres = 0;
1933 if (pcmap) *pcmap = 0;
1934 if (pformat) *pformat = 0;
1935 if (!pw && !ph && !pbps && !pspp && !pres && !pcmap && !pformat)
1936 return ERROR_INT(
"no results requested", procName, 1);
1938 return ERROR_INT(
"cdata not defined", procName, 1);
1941 data = (l_uint8 *)cdata;
1943 return ERROR_INT(
"tiff stream not opened", procName, 1);
1945 for (i = 0; i < n; i++) {
1946 if (TIFFReadDirectory(tif) == 0) {
1948 return ERROR_INT(
"image n not found in file", procName, 1);
1983 l_uint16 *rmap, *gmap, *bmap;
1987 PROCNAME(
"tiffReadHeaderTiff");
1990 return ERROR_INT(
"tif not opened", procName, 1);
1992 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
1993 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
1994 TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bps);
1995 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &spp);
1997 return ERROR_INT(
"tif w and h not both > 0", procName, 1);
1998 if (bps != 1 && bps != 2 && bps != 4 && bps != 8 && bps != 16)
1999 return ERROR_INT(
"bps not in set {1,2,4,8,16}", procName, 1);
2000 if (spp != 1 && spp != 2 && spp != 3 && spp != 4)
2001 return ERROR_INT(
"spp not in set {1,2,3,4}", procName, 1);
2004 if (pbps) *pbps = bps;
2005 if (pspp) *pspp = spp;
2009 *pres = (l_int32)xres;
2013 if (TIFFGetField(tif, TIFFTAG_COLORMAP, &rmap, &gmap, &bmap))
2017 TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &tiffcomp);
2050 PROCNAME(
"findTiffCompression");
2053 return ERROR_INT(
"&comptype not defined", procName, 1);
2054 *pcomptype = IFF_UNKNOWN;
2056 return ERROR_INT(
"stream not defined", procName, 1);
2059 return ERROR_INT(
"tif not opened", procName, 1);
2060 TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &tiffcomp);
2088 case COMPRESSION_CCITTFAX4:
2089 comptype = IFF_TIFF_G4;
2091 case COMPRESSION_CCITTFAX3:
2092 comptype = IFF_TIFF_G3;
2094 case COMPRESSION_CCITTRLE:
2095 comptype = IFF_TIFF_RLE;
2097 case COMPRESSION_PACKBITS:
2098 comptype = IFF_TIFF_PACKBITS;
2100 case COMPRESSION_LZW:
2101 comptype = IFF_TIFF_LZW;
2103 case COMPRESSION_ADOBE_DEFLATE:
2104 comptype = IFF_TIFF_ZIP;
2106 case COMPRESSION_JPEG:
2107 comptype = IFF_TIFF_JPEG;
2110 comptype = IFF_TIFF;
2137 l_int32 *pminisblack)
2139 l_uint8 *inarray, *data;
2140 l_uint16 minisblack, comptype;
2142 l_uint32 w, h, rowsperstrip;
2144 size_t fbytes, nbytes;
2148 PROCNAME(
"extractG4DataFromFile");
2151 return ERROR_INT(
"&data not defined", procName, 1);
2153 return ERROR_INT(
"&nbytes not defined", procName, 1);
2154 if (!pw && !ph && !pminisblack)
2155 return ERROR_INT(
"no output data requested", procName, 1);
2160 return ERROR_INT(
"stream not opened to file", procName, 1);
2164 return ERROR_INT(
"filein not tiff", procName, 1);
2167 return ERROR_INT(
"inarray not made", procName, 1);
2170 if ((tif =
openTiff(filein,
"rb")) == NULL) {
2172 return ERROR_INT(
"tif not open for read", procName, 1);
2174 TIFFGetField(tif, TIFFTAG_COMPRESSION, &comptype);
2175 if (comptype != COMPRESSION_CCITTFAX4) {
2178 return ERROR_INT(
"filein is not g4 compressed", procName, 1);
2181 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
2182 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
2183 TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
2184 if (h != rowsperstrip)
2185 L_WARNING(
"more than 1 strip\n", procName);
2186 TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &minisblack);
2189 if (pw) *pw = (l_int32)w;
2190 if (ph) *ph = (l_int32)h;
2191 if (pminisblack) *pminisblack = (l_int32)minisblack;
2197 if (inarray[0] == 0x4d) {
2198 diroff = (inarray[4] << 24) | (inarray[5] << 16) |
2199 (inarray[6] << 8) | inarray[7];
2201 diroff = (inarray[7] << 24) | (inarray[6] << 16) |
2202 (inarray[5] << 8) | inarray[4];
2209 nbytes = diroff - 8;
2210 if (nbytes > MaxNumTiffBytes) {
2212 L_ERROR(
"requesting %zu bytes > %zu\n", procName,
2213 nbytes, MaxNumTiffBytes);
2217 if ((data = (l_uint8 *)LEPT_CALLOC(nbytes,
sizeof(l_uint8))) == NULL) {
2219 return ERROR_INT(
"data not allocated", procName, 1);
2222 memcpy(data, inarray + 8, nbytes);
2254 const char *modestring)
2256 PROCNAME(
"fopenTiff");
2259 return (TIFF *)ERROR_PTR(
"stream not opened", procName, NULL);
2261 return (TIFF *)ERROR_PTR(
"modestring not defined", procName, NULL);
2263 TIFFSetWarningHandler(NULL);
2264 TIFFSetErrorHandler(NULL);
2266 fseek(fp, 0, SEEK_SET);
2267 return TIFFClientOpen(
"TIFFstream", modestring, (thandle_t)fp,
2268 lept_read_proc, lept_write_proc, lept_seek_proc,
2269 lept_close_proc, lept_size_proc, NULL, NULL);
2290 const char *modestring)
2295 PROCNAME(
"openTiff");
2298 return (TIFF *)ERROR_PTR(
"filename not defined", procName, NULL);
2300 return (TIFF *)ERROR_PTR(
"modestring not defined", procName, NULL);
2302 TIFFSetWarningHandler(NULL);
2303 TIFFSetErrorHandler(NULL);
2306 tif = TIFFOpen(fname, modestring);
2361 static L_MEMSTREAM *memstreamCreateForRead(l_uint8 *indata,
size_t pinsize);
2362 static L_MEMSTREAM *memstreamCreateForWrite(l_uint8 **poutdata,
2364 static tsize_t tiffReadCallback(thandle_t handle, tdata_t data, tsize_t length);
2365 static tsize_t tiffWriteCallback(thandle_t handle, tdata_t data,
2367 static toff_t tiffSeekCallback(thandle_t handle, toff_t offset, l_int32 whence);
2368 static l_int32 tiffCloseCallback(thandle_t handle);
2369 static toff_t tiffSizeCallback(thandle_t handle);
2370 static l_int32 tiffMapCallback(thandle_t handle, tdata_t *data, toff_t *length);
2371 static void tiffUnmapCallback(thandle_t handle, tdata_t data, toff_t length);
2375 memstreamCreateForRead(l_uint8 *indata,
2381 mstream->buffer = indata;
2382 mstream->bufsize = insize;
2383 mstream->hw = insize;
2384 mstream->offset = 0;
2390 memstreamCreateForWrite(l_uint8 **poutdata,
2396 mstream->buffer = (l_uint8 *)LEPT_CALLOC(8 * 1024, 1);
2397 mstream->bufsize = 8 * 1024;
2398 mstream->poutdata = poutdata;
2399 mstream->poutsize = poutsize;
2400 mstream->hw = mstream->offset = 0;
2406 tiffReadCallback(thandle_t handle,
2414 amount = L_MIN((
size_t)length, mstream->hw - mstream->offset);
2417 if (mstream->offset + amount < amount ||
2418 mstream->offset + amount > mstream->hw) {
2419 lept_stderr(
"Bad file: amount too big: %zu\n", amount);
2423 memcpy(data, mstream->buffer + mstream->offset, amount);
2424 mstream->offset += amount;
2430 tiffWriteCallback(thandle_t handle,
2442 if (mstream->offset + length > mstream->bufsize) {
2443 newsize = 2 * (mstream->offset + length);
2444 mstream->buffer = (l_uint8 *)
reallocNew((
void **)&mstream->buffer,
2445 mstream->hw, newsize);
2446 mstream->bufsize = newsize;
2449 memcpy(mstream->buffer + mstream->offset, data, length);
2450 mstream->offset += length;
2451 mstream->hw = L_MAX(mstream->offset, mstream->hw);
2457 tiffSeekCallback(thandle_t handle,
2463 PROCNAME(
"tiffSeekCallback");
2468 if((
size_t)offset != offset) {
2469 return (toff_t)ERROR_INT(
"too large offset value", procName, 1);
2471 mstream->offset = offset;
2475 mstream->offset += offset;
2480 mstream->offset = mstream->hw - offset;
2483 return (toff_t)ERROR_INT(
"bad whence value", procName,
2487 return mstream->offset;
2492 tiffCloseCallback(thandle_t handle)
2497 if (mstream->poutdata) {
2498 *mstream->poutdata = mstream->buffer;
2499 *mstream->poutsize = mstream->hw;
2507 tiffSizeCallback(thandle_t handle)
2517 tiffMapCallback(thandle_t handle,
2524 *data = mstream->buffer;
2525 *length = mstream->hw;
2531 tiffUnmapCallback(thandle_t handle,
2561 const char *operation,
2568 PROCNAME(
"fopenTiffMemstream");
2571 return (TIFF *)ERROR_PTR(
"filename not defined", procName, NULL);
2573 return (TIFF *)ERROR_PTR(
"operation not defined", procName, NULL);
2575 return (TIFF *)ERROR_PTR(
"&data not defined", procName, NULL);
2577 return (TIFF *)ERROR_PTR(
"&datasize not defined", procName, NULL);
2578 if (strcmp(operation,
"r") && strcmp(operation,
"w"))
2579 return (TIFF *)ERROR_PTR(
"op not 'r' or 'w'", procName, NULL);
2581 if (!strcmp(operation,
"r"))
2582 mstream = memstreamCreateForRead(*pdata, *pdatasize);
2584 mstream = memstreamCreateForWrite(pdata, pdatasize);
2586 TIFFSetWarningHandler(NULL);
2587 TIFFSetErrorHandler(NULL);
2589 tif = TIFFClientOpen(filename, operation, (thandle_t)mstream,
2590 tiffReadCallback, tiffWriteCallback,
2591 tiffSeekCallback, tiffCloseCallback,
2592 tiffSizeCallback, tiffMapCallback,
2630 PROCNAME(
"pixReadMemTiff");
2633 return (
PIX *)ERROR_PTR(
"cdata not defined", procName, NULL);
2635 data = (l_uint8 *)cdata;
2637 return (
PIX *)ERROR_PTR(
"tiff stream not opened", procName, NULL);
2640 for (i = 0; ; i++) {
2646 pixSetInputFormat(pix, IFF_TIFF);
2649 if (TIFFReadDirectory(tif) == 0)
2651 if (i == ManyPagesInTiffFile + 1) {
2652 L_WARNING(
"big file: more than %d pages\n", procName,
2653 ManyPagesInTiffFile);
2696 PROCNAME(
"pixReadMemFromMultipageTiff");
2699 return (
PIX *)ERROR_PTR(
"cdata not defined", procName, NULL);
2701 return (
PIX *)ERROR_PTR(
"&offset not defined", procName, NULL);
2703 data = (l_uint8 *)cdata;
2705 return (
PIX *)ERROR_PTR(
"tiff stream not opened", procName, NULL);
2709 retval = (offset == 0) ? TIFFSetDirectory(tif, 0)
2710 : TIFFSetSubDirectory(tif, offset);
2722 TIFFReadDirectory(tif);
2723 *poffset = TIFFCurrentDirOffset(tif);
2749 PROCNAME(
"pixaReadMemMultipageTiff");
2752 return (
PIXA *)ERROR_PTR(
"data not defined", procName, NULL);
2759 }
while (offset != 0);
2786 const char *modestr;
2791 PROCNAME(
"pixaWriteMemMultipageTiff");
2793 if (pdata) *pdata = NULL;
2795 return ERROR_INT(
"pdata not defined", procName, 1);
2797 return ERROR_INT(
"pixa not defined", procName, 1);
2801 return ERROR_INT(
"tmpfile stream not opened", procName, 1);
2803 if ((fp = tmpfile()) == NULL)
2804 return ERROR_INT(
"tmpfile stream not opened", procName, 1);
2808 for (i = 0; i < n; i++) {
2809 modestr = (i == 0) ?
"w" :
"a";
2811 if (pixGetDepth(pix1) == 1)
2847 NULL, NULL, NULL, NULL);
2884 PROCNAME(
"pixWriteMemTiffCustom");
2887 return ERROR_INT(
"&data not defined", procName, 1);
2889 return ERROR_INT(
"&size not defined", procName, 1);
2891 return ERROR_INT(
"&pix not defined", procName, 1);
2892 if (pixGetDepth(pix) != 1 && comptype != IFF_TIFF &&
2893 comptype != IFF_TIFF_LZW && comptype != IFF_TIFF_ZIP &&
2894 comptype != IFF_TIFF_JPEG) {
2895 L_WARNING(
"invalid compression type for bpp > 1\n", procName);
2896 comptype = IFF_TIFF_ZIP;
2900 return ERROR_INT(
"tiff stream not opened", procName, 1);
l_ok pixWriteTiff(const char *filename, PIX *pix, l_int32 comptype, const char *modestr)
pixWriteTiff()
PIX * pixFlipLR(PIX *pixd, PIX *pixs)
pixFlipLR()
l_ok readHeaderTiff(const char *filename, l_int32 n, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *pres, l_int32 *pcmap, l_int32 *pformat)
readHeaderTiff()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
PIX * pixReadStreamTiff(FILE *fp, l_int32 n)
pixReadStreamTiff()
static l_int32 getTiffStreamResolution(TIFF *tif, l_int32 *pxres, l_int32 *pyres)
getTiffStreamResolution()
l_ok pixWriteMemTiff(l_uint8 **pdata, size_t *psize, PIX *pix, l_int32 comptype)
pixWriteMemTiff()
l_ok fprintTiffInfo(FILE *fpout, const char *tiffile)
fprintTiffInfo()
PIXA * pixaReadMultipageTiff(const char *filename)
pixaReadMultipageTiff()
l_ok pixWriteStreamTiffWA(FILE *fp, PIX *pix, l_int32 comptype, const char *modestr)
pixWriteStreamTiffWA()
l_ok extractG4DataFromFile(const char *filein, l_uint8 **pdata, size_t *pnbytes, l_int32 *pw, l_int32 *ph, l_int32 *pminisblack)
extractG4DataFromFile()
static l_int32 tiffReadHeaderTiff(TIFF *tif, l_int32 *pwidth, l_int32 *pheight, l_int32 *pbps, l_int32 *pspp, l_int32 *pres, l_int32 *pcmap, l_int32 *pformat)
tiffReadHeaderTiff()
char * genPathname(const char *dir, const char *fname)
genPathname()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
l_ok pixaWriteMultipageTiff(const char *fname, PIXA *pixa)
pixaWriteMultipageTiff()
void lept_stderr(const char *fmt,...)
lept_stderr()
l_ok writeMultipageTiff(const char *dirin, const char *substr, const char *fileout)
writeMultipageTiff()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixInvert(PIX *pixd, PIX *pixs)
pixInvert()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
l_ok pixWriteStreamTiff(FILE *fp, PIX *pix, l_int32 comptype)
pixWriteStreamTiff()
l_ok readHeaderMemTiff(const l_uint8 *cdata, size_t size, l_int32 n, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *pres, l_int32 *pcmap, l_int32 *pformat)
readHeaderMemTiff()
Memory stream buffer used with TIFFClientOpen()
l_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
PIX * pixReadMemFromMultipageTiff(const l_uint8 *cdata, size_t size, size_t *poffset)
pixReadMemFromMultipageTiff()
l_ok pixSetText(PIX *pix, const char *textstring)
pixSetText()
static TIFF * fopenTiff(FILE *fp, const char *modestring)
fopenTiff()
PIXCMAP * pixcmapCreate(l_int32 depth)
pixcmapCreate()
l_ok freadHeaderTiff(FILE *fp, l_int32 n, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *pres, l_int32 *pcmap, l_int32 *pformat)
freadHeaderTiff()
l_ok findFileFormatStream(FILE *fp, l_int32 *pformat)
findFileFormatStream()
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()
PIX * pixEndianTwoByteSwapNew(PIX *pixs)
pixEndianTwoByteSwapNew()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
PIX * pixFlipTB(PIX *pixd, PIX *pixs)
pixFlipTB()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok getTiffResolution(FILE *fp, l_int32 *pxres, l_int32 *pyres)
getTiffResolution()
l_ok pixWriteTiffCustom(const char *filename, PIX *pix, l_int32 comptype, const char *modestr, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes)
pixWriteTiffCustom()
static TIFF * fopenTiffMemstream(const char *filename, const char *operation, l_uint8 **pdata, size_t *pdatasize)
fopenTiffMemstream()
l_ok pixEndianByteSwap(PIX *pixs)
pixEndianByteSwap()
l_ok composeRGBAPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_int32 aval, l_uint32 *ppixel)
composeRGBAPixel()
#define SET_DATA_BYTE(pdata, n, val)
l_ok pixSetPadBits(PIX *pix, l_int32 val)
pixSetPadBits()
static PIX * pixReadFromTiffStream(TIFF *tif)
pixReadFromTiffStream()
l_ok pixEndianTwoByteSwap(PIX *pixs)
pixEndianTwoByteSwap()
static l_int32 pixWriteToTiffStream(TIFF *tif, PIX *pix, l_int32 comptype, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes)
pixWriteToTiffStream()
static TIFF * openTiff(const char *filename, const char *modestring)
openTiff()
#define GET_DATA_BYTE(pdata, n)
l_ok findFileFormat(const char *filename, l_int32 *pformat)
findFileFormat()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
void * reallocNew(void **pindata, size_t oldsize, size_t newsize)
reallocNew()
void pixDestroy(PIX **ppix)
pixDestroy()
SARRAY * getSortedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
getSortedPathnamesInDirectory()
PIX * pixReadMemTiff(const l_uint8 *cdata, size_t size, l_int32 n)
pixReadMemTiff()
PIX * pixEndianByteSwapNew(PIX *pixs)
pixEndianByteSwapNew()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
FILE * fopenWriteWinTempfile(void)
fopenWriteWinTempfile()
l_int32 fileFormatIsTiff(FILE *fp)
fileFormatIsTiff()
FILE * fopenReadStream(const char *filename)
fopenReadStream()
l_uint8 * l_binaryReadStream(FILE *fp, size_t *pnbytes)
l_binaryReadStream()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
PIX * pixRead(const char *filename)
pixRead()
l_ok writeMultipageTiffSA(SARRAY *sa, const char *fileout)
writeMultipageTiffSA()
char * pixGetText(PIX *pix)
pixGetText()
l_ok findTiffCompression(FILE *fp, l_int32 *pcomptype)
findTiffCompression()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
static l_int32 getTiffCompressedFormat(l_uint16 tiffcomp)
getTiffCompressedFormat()
l_ok pixaWriteMemMultipageTiff(l_uint8 **pdata, size_t *psize, PIXA *pixa)
pixaWriteMemMultipageTiff()
PIX * pixReadTiff(const char *filename, l_int32 n)
pixReadTiff()
PIX * pixReadFromMultipageTiff(const char *fname, size_t *poffset)
pixReadFromMultipageTiff()
l_int32 pixcmapGetCount(const PIXCMAP *cmap)
pixcmapGetCount()
PIX * pixRotate90(PIX *pixs, l_int32 direction)
pixRotate90()
static l_int32 writeCustomTiffTags(TIFF *tif, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes)
writeCustomTiffTags()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
l_ok pixcmapAddColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval)
pixcmapAddColor()
l_ok tiffGetCount(FILE *fp, l_int32 *pn)
tiffGetCount()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
l_ok pixWriteMemTiffCustom(l_uint8 **pdata, size_t *psize, PIX *pix, l_int32 comptype, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes)
pixWriteMemTiffCustom()
l_ok pixcmapToArrays(const PIXCMAP *cmap, l_int32 **prmap, l_int32 **pgmap, l_int32 **pbmap, l_int32 **pamap)
pixcmapToArrays()
PIXA * pixaReadMemMultipageTiff(const l_uint8 *data, size_t size)
pixaReadMemMultipageTiff()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()