119#include <config_auto.h>
124#include <sys/types.h>
131#include "allheaders.h"
134#if HAVE_LIBTIFF && HAVE_LIBJPEG
140static const l_int32 DefaultResolution = 300;
141static const l_int32 ManyPagesInTiffFile = 3000;
144static const l_int32 MaxTiffWidth = 1 << 20;
145static const l_int32 MaxTiffHeight = 1 << 20;
148static const size_t MaxNumTiffBytes = (1 << 28) - 1;
155 l_int32 *pheight, l_int32 *pbps,
156 l_int32 *pspp, l_int32 *pres,
157 l_int32 *pcmap, l_int32 *pformat);
164static TIFF *
fopenTiff(FILE *fp,
const char *modestring);
165static TIFF *
openTiff(
const char *filename,
const char *modestring);
172 l_uint8 **pdata,
size_t *pdatasize);
205static struct tiff_transform tiff_partial_orientation_transforms[] = {
233lept_read_proc(thandle_t cookie,
237 FILE* fp = (FILE *)cookie;
239 if (!buff || !cookie || !fp)
241 done = fread(buff, 1, size, fp);
246lept_write_proc(thandle_t cookie,
250 FILE* fp = (FILE *)cookie;
252 if (!buff || !cookie || !fp)
254 done = fwrite(buff, 1, size, fp);
259lept_seek_proc(thandle_t cookie,
263 FILE* fp = (FILE *)cookie;
276 _fseeki64(fp, 0, SEEK_END);
280 pos = (__int64)(pos + offs);
281 _fseeki64(fp, pos, SEEK_SET);
282 if (pos == _ftelli64(fp))
284#elif defined(_LARGEFILE64_SOURCE)
296 fseeko(fp, 0, SEEK_END);
300 pos = (off64_t)(pos + offs);
301 fseeko(fp, pos, SEEK_SET);
302 if (pos == ftello(fp))
316 fseek(fp, 0, SEEK_END);
320 pos = (off_t)(pos + offs);
321 fseek(fp, pos, SEEK_SET);
322 if (pos == ftell(fp))
329lept_close_proc(thandle_t cookie)
331 FILE* fp = (FILE *)cookie;
334 fseek(fp, 0, SEEK_SET);
339lept_size_proc(thandle_t cookie)
341 FILE* fp = (FILE *)cookie;
348 _fseeki64(fp, 0, SEEK_END);
349 size = _ftelli64(fp);
350 _fseeki64(fp, pos, SEEK_SET);
351#elif defined(_LARGEFILE64_SOURCE)
357 fseeko(fp, 0, SEEK_END);
359 fseeko(fp, pos, SEEK_SET);
366 fseek(fp, 0, SEEK_END);
368 fseek(fp, pos, SEEK_SET);
401 return (
PIX *)ERROR_PTR(
"filename not defined", __func__, NULL);
403 if ((fp = fopenReadStream(filename)) == NULL)
404 return (
PIX *)ERROR_PTR_1(
"image file not found",
405 filename, __func__, NULL);
437 return (
PIX *)ERROR_PTR(
"stream not defined", __func__, NULL);
440 return (
PIX *)ERROR_PTR(
"tif not opened", __func__, NULL);
442 if (TIFFSetDirectory(tif, n) == 0) {
501l_uint8 *linebuf, *data, *rowptr;
502l_uint16 spp, bps, photometry, tiffcomp, orientation, sample_fmt;
503l_uint16 *redmap, *greenmap, *bluemap;
504l_int32 d, wpl, bpl, comptype, i, j, k, ncolors, rval, gval, bval, aval;
505l_int32 xres, yres, tiffbpl, packedbpl, half_size, twothirds_size;
506l_uint32 w, h, tiffword, read_oriented;
507l_uint32 *line, *ppixel, *tiffdata, *pixdata;
512 return (
PIX *)ERROR_PTR(
"tif not defined", __func__, NULL);
521 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_fmt);
522 if (sample_fmt != SAMPLEFORMAT_UINT) {
523 L_ERROR(
"sample format = %d is not uint\n", __func__, sample_fmt);
532 if (TIFFIsTiled(tif)) {
533 L_ERROR(
"tiled format is not supported\n", __func__);
544 TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &tiffcomp);
545 if (tiffcomp == COMPRESSION_OJPEG) {
546 L_ERROR(
"old style jpeg format is not supported\n", __func__);
551#if defined(COMPRESSION_WEBP)
552 if (tiffcomp == COMPRESSION_WEBP) {
553 L_ERROR(
"webp in tiff not generally supported yet\n", __func__);
559 TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bps);
560 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &spp);
561 if (bps != 1 && bps != 2 && bps != 4 && bps != 8 && bps != 16) {
562 L_ERROR(
"invalid bps = %d\n", __func__, bps);
565 if (spp == 2 && bps != 8) {
566 L_ERROR(
"for 2 spp, only handle 8 bps; this is %d bps\n",
570 if ((spp == 3 || spp == 4) && bps < 8) {
571 L_ERROR(
"for 3 and 4 spp, only handle 8 and 16 bps; this is %d bps\n",
577 }
else if (spp == 2) {
579 }
else if (spp == 3 || spp == 4) {
582 L_ERROR(
"spp = %d; not in {1,2,3,4}\n", __func__, spp);
586 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
587 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
588 if (w > MaxTiffWidth) {
589 L_ERROR(
"width = %d pixels; too large\n", __func__, w);
592 if (h > MaxTiffHeight) {
593 L_ERROR(
"height = %d pixels; too large\n", __func__, h);
603 tiffbpl = TIFFScanlineSize(tif);
604 packedbpl = (bps * spp * w + 7) / 8;
605 half_size = (L_ABS(2 * tiffbpl - packedbpl) <= 8);
606 twothirds_size = (L_ABS(3 * tiffbpl - 2 * packedbpl) <= 8);
609 L_INFO(
"half_size: packedbpl = %d is approx. twice tiffbpl = %d\n",
610 __func__, packedbpl, tiffbpl);
612 L_INFO(
"twothirds_size: packedbpl = %d is approx. 1.5 tiffbpl = %d\n",
613 __func__, packedbpl, tiffbpl);
614 lept_stderr(
"tiffbpl = %d, packedbpl = %d, bps = %d, spp = %d, w = %d\n",
615 tiffbpl, packedbpl, bps, spp, w);
617 if (tiffbpl != packedbpl && !half_size && !twothirds_size) {
618 L_ERROR(
"invalid tiffbpl: tiffbpl = %d, packedbpl = %d, "
619 "bps = %d, spp = %d, w = %d\n",
620 __func__, tiffbpl, packedbpl, bps, spp, w);
626 if ((pix = pixCreate(w, h, d)) == NULL)
627 return (
PIX *)ERROR_PTR(
"pix not made", __func__, NULL);
628 pixSetInputFormat(pix, IFF_TIFF);
629 data = (l_uint8 *)pixGetData(pix);
630 wpl = pixGetWpl(pix);
633 linebuf = (l_uint8 *)LEPT_CALLOC(4 * wpl,
sizeof(l_uint8));
634 for (i = 0; i < h; i++) {
635 if (TIFFReadScanline(tif, linebuf, i, 0) < 0) {
638 L_ERROR(
"spp = 1, read fail at line %d\n", __func__, i);
641 memcpy(data, linebuf, tiffbpl);
645 pixEndianByteSwap(pix);
647 pixEndianTwoByteSwap(pix);
649 }
else if (spp == 2 && bps == 8) {
650 L_INFO(
"gray+alpha is not supported; converting to RGBA\n", __func__);
652 linebuf = (l_uint8 *)LEPT_CALLOC(4 * wpl,
sizeof(l_uint8));
653 pixdata = pixGetData(pix);
654 for (i = 0; i < h; i++) {
655 if (TIFFReadScanline(tif, linebuf, i, 0) < 0) {
658 L_ERROR(
"spp = 2, read fail at line %d\n", __func__, i);
662 ppixel = pixdata + i * wpl;
663 for (j = k = 0; j < w; j++) {
674 if ((tiffdata = (l_uint32 *)LEPT_CALLOC((
size_t)w * h,
675 sizeof(l_uint32))) == NULL) {
677 return (
PIX *)ERROR_PTR(
"calloc fail for tiffdata", __func__, NULL);
680 if (!TIFFReadRGBAImageOriented(tif, w, h, tiffdata,
681 ORIENTATION_TOPLEFT, 0)) {
684 return (
PIX *)ERROR_PTR(
"failed to read tiffdata", __func__, NULL);
689 if (spp == 4) pixSetSpp(pix, 4);
690 line = pixGetData(pix);
691 for (i = 0; i < h; i++, line += wpl) {
692 for (j = 0, ppixel = line; j < w; j++) {
694 tiffword = tiffdata[i * w + j];
695 rval = TIFFGetR(tiffword);
696 gval = TIFFGetG(tiffword);
697 bval = TIFFGetB(tiffword);
699 composeRGBPixel(rval, gval, bval, ppixel);
701 aval = TIFFGetA(tiffword);
702 composeRGBAPixel(rval, gval, bval, aval, ppixel);
711 pixSetXRes(pix, xres);
712 pixSetYRes(pix, yres);
717 pixSetInputFormat(pix, comptype);
719 if (TIFFGetField(tif, TIFFTAG_COLORMAP, &redmap, &greenmap, &bluemap)) {
726 return (
PIX *)ERROR_PTR(
"colormap size > 256", __func__, NULL);
728 if ((cmap = pixcmapCreate(bps)) == NULL) {
730 return (
PIX *)ERROR_PTR(
"colormap not made", __func__, NULL);
733 for (i = 0; i < ncolors; i++)
734 pixcmapAddColor(cmap, redmap[i] >> 8, greenmap[i] >> 8,
736 if (pixSetColormap(pix, cmap)) {
738 return (
PIX *)ERROR_PTR(
"invalid colormap", __func__, NULL);
748 if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometry)) {
751 if (tiffcomp == COMPRESSION_CCITTFAX3 ||
752 tiffcomp == COMPRESSION_CCITTFAX4 ||
753 tiffcomp == COMPRESSION_CCITTRLE ||
754 tiffcomp == COMPRESSION_CCITTRLEW) {
755 photometry = PHOTOMETRIC_MINISWHITE;
757 photometry = PHOTOMETRIC_MINISBLACK;
760 if ((d == 1 && photometry == PHOTOMETRIC_MINISBLACK) ||
761 (d == 8 && photometry == PHOTOMETRIC_MINISWHITE))
765 if (TIFFGetField(tif, TIFFTAG_ORIENTATION, &orientation)) {
766 if (orientation >= 1 && orientation <= 8) {
768 &tiff_partial_orientation_transforms[orientation - 1] :
769 &tiff_orientation_transforms[orientation - 1];
770 if (transform->vflip) pixFlipTB(pix, pix);
771 if (transform->hflip) pixFlipLR(pix, pix);
772 if (transform->rotate) {
774 pix = pixRotate90(oldpix, transform->rotate);
781 TIFFGetField(tif, TIFFTAG_IMAGEDESCRIPTION, &text);
782 if (text) pixSetText(pix, text);
818 NULL, NULL, NULL, NULL);
882 return ERROR_INT(
"filename not defined", __func__, 1);
884 return ERROR_INT(
"pix not defined", __func__, 1);
886 if ((tif =
openTiff(filename, modestr)) == NULL)
887 return ERROR_INT(
"tif not opened", __func__, 1);
959 return ERROR_INT(
"stream not defined", __func__, 1 );
961 return ERROR_INT(
"pix not defined", __func__, 1 );
962 if (strcmp(modestr,
"w") && strcmp(modestr,
"a")) {
963 L_ERROR(
"modestr = %s; not 'w' or 'a'\n", __func__, modestr);
967 if (pixGetDepth(pix) != 1 && comptype != IFF_TIFF &&
968 comptype != IFF_TIFF_LZW && comptype != IFF_TIFF_ZIP &&
969 comptype != IFF_TIFF_JPEG) {
970 L_WARNING(
"invalid compression type %d for bpp > 1; using TIFF_ZIP\n",
972 comptype = IFF_TIFF_ZIP;
975 if ((tif =
fopenTiff(fp, modestr)) == NULL)
976 return ERROR_INT(
"tif not opened", __func__, 1);
980 return ERROR_INT(
"tif write error", __func__, 1);
1032l_uint8 *linebuf, *data;
1033l_uint16 redmap[256], greenmap[256], bluemap[256];
1034l_int32 w, h, d, spp, i, j, k, wpl, bpl, tiffbpl, ncolors, cmapsize;
1035l_int32 *rmap, *gmap, *bmap;
1037l_uint32 *line, *ppixel;
1043 return ERROR_INT(
"tif stream not defined", __func__, 1);
1045 return ERROR_INT(
"pix not defined", __func__, 1 );
1047 pixSetPadBits(pix, 0);
1048 pixGetDimensions(pix, &w, &h, &d);
1049 spp = pixGetSpp(pix);
1050 xres = pixGetXRes(pix);
1051 yres = pixGetYRes(pix);
1052 if (xres == 0) xres = DefaultResolution;
1053 if (yres == 0) yres = DefaultResolution;
1056 TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, (l_uint32)RESUNIT_INCH);
1057 TIFFSetField(tif, TIFFTAG_XRESOLUTION, (l_float64)xres);
1058 TIFFSetField(tif, TIFFTAG_YRESOLUTION, (l_float64)yres);
1060 TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (l_uint32)w);
1061 TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (l_uint32)h);
1062 TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
1064 if ((text = pixGetText(pix)) != NULL)
1065 TIFFSetField(tif, TIFFTAG_IMAGEDESCRIPTION, text);
1067 if (d == 1 && !pixGetColormap(pix)) {
1072 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
1073 }
else if ((d == 32 && spp == 3) || d == 24) {
1074 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1075 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)3);
1076 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE,
1077 (l_uint16)8, (l_uint16)8, (l_uint16)8);
1078 }
else if (d == 32 && spp == 4) {
1080 val[0] = EXTRASAMPLE_ASSOCALPHA;
1081 TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, (l_uint16)1, &val);
1082 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1083 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)4);
1084 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE,
1085 (l_uint16)8, (l_uint16)8, (l_uint16)8, (l_uint16)8);
1086 }
else if (d == 16) {
1087 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1088 }
else if ((cmap = pixGetColormap(pix)) == NULL) {
1089 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1092 L_ERROR(
"d = %d > 8 with colormap!; reducing to 8\n", __func__, d);
1095 pixcmapToArrays(cmap, &rmap, &gmap, &bmap, NULL);
1096 ncolors = pixcmapGetCount(cmap);
1097 ncolors = L_MIN(256, ncolors);
1099 cmapsize = L_MIN(256, cmapsize);
1100 if (ncolors > cmapsize) {
1101 L_WARNING(
"too many colors in cmap for tiff; truncating\n",
1105 for (i = 0; i < ncolors; i++) {
1106 redmap[i] = (rmap[i] << 8) | rmap[i];
1107 greenmap[i] = (gmap[i] << 8) | gmap[i];
1108 bluemap[i] = (bmap[i] << 8) | bmap[i];
1110 for (i = ncolors; i < cmapsize; i++)
1111 redmap[i] = greenmap[i] = bluemap[i] = 0;
1116 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_PALETTE);
1117 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)1);
1118 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, (l_uint16)d);
1119 TIFFSetField(tif, TIFFTAG_COLORMAP, redmap, greenmap, bluemap);
1123 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, (l_uint16)d);
1124 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)1);
1127 TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
1128 if (comptype == IFF_TIFF) {
1129 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
1130 }
else if (comptype == IFF_TIFF_G4) {
1131 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
1132 }
else if (comptype == IFF_TIFF_G3) {
1133 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX3);
1134 }
else if (comptype == IFF_TIFF_RLE) {
1135 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_CCITTRLE);
1136 }
else if (comptype == IFF_TIFF_PACKBITS) {
1137 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
1138 }
else if (comptype == IFF_TIFF_LZW) {
1139 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
1140 }
else if (comptype == IFF_TIFF_ZIP) {
1141 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_ADOBE_DEFLATE);
1142 }
else if (comptype == IFF_TIFF_JPEG) {
1143 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);
1145 L_WARNING(
"unknown tiff compression; using none\n", __func__);
1146 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
1153 tiffbpl = TIFFScanlineSize(tif);
1154 wpl = pixGetWpl(pix);
1157 lept_stderr(
"Big trouble: tiffbpl = %d, bpl = %d\n", tiffbpl, bpl);
1158 if ((linebuf = (l_uint8 *)LEPT_CALLOC(1, bpl)) == NULL)
1159 return ERROR_INT(
"calloc fail for linebuf", __func__, 1);
1162 TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, h);
1164 if (d != 24 && d != 32) {
1166 pixt = pixEndianTwoByteSwapNew(pix);
1168 pixt = pixEndianByteSwapNew(pix);
1169 data = (l_uint8 *)pixGetData(pixt);
1170 for (i = 0; i < h; i++, data += bpl) {
1171 memcpy(linebuf, data, tiffbpl);
1172 if (TIFFWriteScanline(tif, linebuf, i, 0) < 0)
1176 }
else if (d == 24) {
1177 for (i = 0; i < h; i++) {
1178 line = pixGetData(pix) + i * wpl;
1179 if (TIFFWriteScanline(tif, (l_uint8 *)line, i, 0) < 0)
1183 for (i = 0; i < h; i++) {
1184 line = pixGetData(pix) + i * wpl;
1185 for (j = 0, k = 0, ppixel = line; j < w; j++) {
1193 if (TIFFWriteScanline(tif, linebuf, i, 0) < 0)
1242l_int32 i, n, ns, size, tagval, val;
1244l_uint32 uval, uval2;
1247 return ERROR_INT(
"tif stream not defined", __func__, 1);
1248 if (!natags && !savals && !satypes)
1250 if (!natags || !savals || !satypes)
1251 return ERROR_INT(
"not all arrays defined", __func__, 1);
1252 n = numaGetCount(natags);
1253 if ((sarrayGetCount(savals) != n) || (sarrayGetCount(satypes) != n))
1254 return ERROR_INT(
"not all sa the same size", __func__, 1);
1258 ns = numaGetCount(nasizes);
1260 return ERROR_INT(
"too many 4-arg tag calls", __func__, 1);
1261 for (i = 0; i < ns; i++) {
1262 numaGetIValue(natags, i, &tagval);
1263 sval = sarrayGetString(savals, i,
L_NOCOPY);
1264 type = sarrayGetString(satypes, i,
L_NOCOPY);
1265 numaGetIValue(nasizes, i, &size);
1266 if (strcmp(type,
"char*") && strcmp(type,
"l_uint8*"))
1267 L_WARNING(
"array type not char* or l_uint8*; ignore\n",
1269 TIFFSetField(tif, tagval, size, sval);
1276 for (i = ns; i < n; i++) {
1277 numaGetIValue(natags, i, &tagval);
1278 sval = sarrayGetString(savals, i,
L_NOCOPY);
1279 type = sarrayGetString(satypes, i,
L_NOCOPY);
1280 if (!strcmp(type,
"char*") || !strcmp(type,
"const char*")) {
1281 TIFFSetField(tif, tagval, sval);
1282 }
else if (!strcmp(type,
"l_uint16")) {
1283 if (sscanf(sval,
"%u", &uval) == 1) {
1284 TIFFSetField(tif, tagval, (l_uint16)uval);
1286 lept_stderr(
"val %s not of type %s\n", sval, type);
1287 return ERROR_INT(
"custom tag(s) not written", __func__, 1);
1289 }
else if (!strcmp(type,
"l_uint32")) {
1290 if (sscanf(sval,
"%u", &uval) == 1) {
1291 TIFFSetField(tif, tagval, uval);
1293 lept_stderr(
"val %s not of type %s\n", sval, type);
1294 return ERROR_INT(
"custom tag(s) not written", __func__, 1);
1296 }
else if (!strcmp(type,
"l_int32")) {
1297 if (sscanf(sval,
"%d", &val) == 1) {
1298 TIFFSetField(tif, tagval, val);
1300 lept_stderr(
"val %s not of type %s\n", sval, type);
1301 return ERROR_INT(
"custom tag(s) not written", __func__, 1);
1303 }
else if (!strcmp(type,
"l_float64")) {
1304 if (sscanf(sval,
"%lf", &dval) == 1) {
1305 TIFFSetField(tif, tagval, dval);
1307 lept_stderr(
"val %s not of type %s\n", sval, type);
1308 return ERROR_INT(
"custom tag(s) not written", __func__, 1);
1310 }
else if (!strcmp(type,
"l_uint16-l_uint16")) {
1311 if (sscanf(sval,
"%u-%u", &uval, &uval2) == 2) {
1312 TIFFSetField(tif, tagval, (l_uint16)uval, (l_uint16)uval2);
1314 lept_stderr(
"val %s not of type %s\n", sval, type);
1315 return ERROR_INT(
"custom tag(s) not written", __func__, 1);
1318 lept_stderr(
"unknown type %s\n",type);
1319 return ERROR_INT(
"unknown type; tag(s) not written", __func__, 1);
1370 return (
PIX *)ERROR_PTR(
"fname not defined", __func__, NULL);
1372 return (
PIX *)ERROR_PTR(
"&offset not defined", __func__, NULL);
1374 if ((tif =
openTiff(fname,
"r")) == NULL) {
1375 L_ERROR(
"tif open failed for %s\n", __func__, fname);
1381 retval = (offset == 0) ? TIFFSetDirectory(tif, 0)
1382 : TIFFSetSubDirectory(tif, offset);
1394 TIFFReadDirectory(tif);
1395 *poffset = TIFFCurrentDirOffset(tif);
1417 return (
PIXA *)ERROR_PTR(
"filename not defined", __func__, NULL);
1419 if ((fp = fopenReadStream(filename)) == NULL)
1420 return (
PIXA *)ERROR_PTR_1(
"stream not opened",
1421 filename, __func__, NULL);
1422 if (fileFormatIsTiff(fp)) {
1424 L_INFO(
" Tiff: %d pages\n", __func__, npages);
1426 return (
PIXA *)ERROR_PTR_1(
"file is not tiff",
1427 filename, __func__, NULL);
1431 return (
PIXA *)ERROR_PTR_1(
"tif not opened",
1432 filename, __func__, NULL);
1434 pixa = pixaCreate(npages);
1436 for (i = 0; i < npages; i++) {
1440 L_WARNING(
"pix not read for page %d\n", __func__, i);
1444 if (TIFFReadDirectory(tif) == 0)
1477 return ERROR_INT(
"fname not defined", __func__, 1);
1479 return ERROR_INT(
"pixa not defined", __func__, 1);
1481 n = pixaGetCount(pixa);
1482 for (i = 0; i < n; i++) {
1483 modestr = (i == 0) ?
"w" :
"a";
1484 pix1 = pixaGetPix(pixa, i,
L_CLONE);
1485 if (pixGetDepth(pix1) == 1)
1523 const char *fileout)
1528 return ERROR_INT(
"dirin not defined", __func__, 1);
1530 return ERROR_INT(
"fileout not defined", __func__, 1);
1533 sa = getSortedPathnamesInDirectory(dirin, substr, 0, 0);
1556 const char *fileout)
1560l_int32 i, nfiles, firstfile, format;
1564 return ERROR_INT(
"sa not defined", __func__, 1);
1566 return ERROR_INT(
"fileout not defined", __func__, 1);
1568 nfiles = sarrayGetCount(sa);
1570 for (i = 0; i < nfiles; i++) {
1571 op = (firstfile) ?
"w" :
"a";
1572 fname = sarrayGetString(sa, i,
L_NOCOPY);
1573 findFileFormat(fname, &format);
1574 if (format == IFF_UNKNOWN) {
1575 L_INFO(
"format of %s not known\n", __func__, fname);
1579 if ((pix = pixRead(fname)) == NULL) {
1580 L_WARNING(
"pix not made for file: %s\n", __func__, fname);
1583 if (pixGetDepth(pix) == 1)
1607 const char *tiffile)
1612 return ERROR_INT(
"tiffile not defined", __func__, 1);
1614 return ERROR_INT(
"stream out not defined", __func__, 1);
1616 if ((tif =
openTiff(tiffile,
"rb")) == NULL)
1617 return ERROR_INT(
"tif not open for read", __func__, 1);
1619 TIFFPrintDirectory(tif, fpout, 0);
1644 return ERROR_INT(
"stream not defined", __func__, 1);
1646 return ERROR_INT(
"&n not defined", __func__, 1);
1650 return ERROR_INT(
"tif not open for read", __func__, 1);
1652 for (i = 1; ; i++) {
1653 if (TIFFReadDirectory(tif) == 0)
1655 if (i == ManyPagesInTiffFile + 1) {
1656 L_WARNING(
"big file: more than %d pages\n", __func__,
1657 ManyPagesInTiffFile);
1689 if (!pxres || !pyres)
1690 return ERROR_INT(
"&xres and &yres not both defined", __func__, 1);
1691 *pxres = *pyres = 0;
1693 return ERROR_INT(
"stream not opened", __func__, 1);
1696 return ERROR_INT(
"tif not open for read", __func__, 1);
1722l_int32 foundxres, foundyres;
1723l_float32 fxres, fyres;
1726 return ERROR_INT(
"tif not opened", __func__, 1);
1727 if (!pxres || !pyres)
1728 return ERROR_INT(
"&xres and &yres not both defined", __func__, 1);
1729 *pxres = *pyres = 0;
1731 TIFFGetFieldDefaulted(tif, TIFFTAG_RESOLUTIONUNIT, &resunit);
1732 foundxres = TIFFGetField(tif, TIFFTAG_XRESOLUTION, &fxres);
1733 foundyres = TIFFGetField(tif, TIFFTAG_YRESOLUTION, &fyres);
1734 if (!foundxres && !foundyres)
return 1;
1735 if (isnan(fxres) || isnan(fyres))
return 1;
1736 if (!foundxres && foundyres)
1738 else if (foundxres && !foundyres)
1742 if (fxres < 0 || fxres > (1L << 29) || fyres < 0 || fyres > (1L << 29))
1743 return ERROR_INT(
"fxres and/or fyres values are invalid", __func__, 1);
1745 if (resunit == RESUNIT_CENTIMETER) {
1746 *pxres = (l_int32)(2.54 * fxres + 0.5);
1747 *pyres = (l_int32)(2.54 * fyres + 0.5);
1749 *pxres = (l_int32)(fxres + 0.5);
1750 *pyres = (l_int32)(fyres + 0.5);
1796 if (pbps) *pbps = 0;
1797 if (pspp) *pspp = 0;
1798 if (pres) *pres = 0;
1799 if (pcmap) *pcmap = 0;
1800 if (pformat) *pformat = 0;
1802 return ERROR_INT(
"filename not defined", __func__, 1);
1803 if (!pw && !ph && !pbps && !pspp && !pres && !pcmap && !pformat)
1804 return ERROR_INT(
"no results requested", __func__, 1);
1806 if ((fp = fopenReadStream(filename)) == NULL)
1807 return ERROR_INT_1(
"image file not found", filename, __func__, 1);
1808 ret =
freadHeaderTiff(fp, n, pw, ph, pbps, pspp, pres, pcmap, pformat);
1845l_int32 i, ret, format;
1850 if (pbps) *pbps = 0;
1851 if (pspp) *pspp = 0;
1852 if (pres) *pres = 0;
1853 if (pcmap) *pcmap = 0;
1854 if (pformat) *pformat = 0;
1856 return ERROR_INT(
"stream not defined", __func__, 1);
1858 return ERROR_INT(
"image index must be >= 0", __func__, 1);
1859 if (!pw && !ph && !pbps && !pspp && !pres && !pcmap && !pformat)
1860 return ERROR_INT(
"no results requested", __func__, 1);
1862 findFileFormatStream(fp, &format);
1863 if (!L_FORMAT_IS_TIFF(format))
1864 return ERROR_INT(
"file not tiff format", __func__, 1);
1867 return ERROR_INT(
"tif not open for read", __func__, 1);
1869 for (i = 0; i < n; i++) {
1870 if (TIFFReadDirectory(tif) == 0)
1871 return ERROR_INT(
"image n not found in file", __func__, 1);
1919 if (pbps) *pbps = 0;
1920 if (pspp) *pspp = 0;
1921 if (pres) *pres = 0;
1922 if (pcmap) *pcmap = 0;
1923 if (pformat) *pformat = 0;
1924 if (!pw && !ph && !pbps && !pspp && !pres && !pcmap && !pformat)
1925 return ERROR_INT(
"no results requested", __func__, 1);
1927 return ERROR_INT(
"cdata not defined", __func__, 1);
1930 data = (l_uint8 *)cdata;
1932 return ERROR_INT(
"tiff stream not opened", __func__, 1);
1934 for (i = 0; i < n; i++) {
1935 if (TIFFReadDirectory(tif) == 0) {
1937 return ERROR_INT(
"image n not found in file", __func__, 1);
1972l_uint16 *rmap, *gmap, *bmap;
1977 return ERROR_INT(
"tif not opened", __func__, 1);
1979 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
1980 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
1981 TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bps);
1982 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &spp);
1984 return ERROR_INT(
"tif w and h not both > 0", __func__, 1);
1985 if (bps != 1 && bps != 2 && bps != 4 && bps != 8 && bps != 16)
1986 return ERROR_INT(
"bps not in set {1,2,4,8,16}", __func__, 1);
1987 if (spp != 1 && spp != 2 && spp != 3 && spp != 4)
1988 return ERROR_INT(
"spp not in set {1,2,3,4}", __func__, 1);
1991 if (pbps) *pbps = bps;
1992 if (pspp) *pspp = spp;
1995 *pres = (l_int32)xres;
1998 if (TIFFGetField(tif, TIFFTAG_COLORMAP, &rmap, &gmap, &bmap))
2002 TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &tiffcomp);
2036 return ERROR_INT(
"&comptype not defined", __func__, 1);
2037 *pcomptype = IFF_UNKNOWN;
2039 return ERROR_INT(
"stream not defined", __func__, 1);
2042 return ERROR_INT(
"tif not opened", __func__, 1);
2043 TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &tiffcomp);
2071 case COMPRESSION_CCITTFAX4:
2072 comptype = IFF_TIFF_G4;
2074 case COMPRESSION_CCITTFAX3:
2075 comptype = IFF_TIFF_G3;
2077 case COMPRESSION_CCITTRLE:
2078 comptype = IFF_TIFF_RLE;
2080 case COMPRESSION_PACKBITS:
2081 comptype = IFF_TIFF_PACKBITS;
2083 case COMPRESSION_LZW:
2084 comptype = IFF_TIFF_LZW;
2086 case COMPRESSION_ADOBE_DEFLATE:
2087 comptype = IFF_TIFF_ZIP;
2089 case COMPRESSION_JPEG:
2090 comptype = IFF_TIFF_JPEG;
2093 comptype = IFF_TIFF;
2120 l_int32 *pminisblack)
2122l_uint8 *inarray, *data;
2123l_uint16 minisblack, comptype;
2125l_uint32 w, h, rowsperstrip;
2127size_t fbytes, nbytes;
2132 return ERROR_INT(
"&data not defined", __func__, 1);
2134 return ERROR_INT(
"&nbytes not defined", __func__, 1);
2135 if (!pw && !ph && !pminisblack)
2136 return ERROR_INT(
"no output data requested", __func__, 1);
2140 if ((fpin = fopenReadStream(filein)) == NULL)
2141 return ERROR_INT_1(
"stream not opened to file", filein, __func__, 1);
2142 istiff = fileFormatIsTiff(fpin);
2145 return ERROR_INT_1(
"filein not tiff", filein, __func__, 1);
2147 if ((inarray = l_binaryRead(filein, &fbytes)) == NULL)
2148 return ERROR_INT_1(
"inarray not made", filein, __func__, 1);
2151 if ((tif =
openTiff(filein,
"rb")) == NULL) {
2153 return ERROR_INT_1(
"tif not open for read", filein, __func__, 1);
2155 TIFFGetField(tif, TIFFTAG_COMPRESSION, &comptype);
2156 if (comptype != COMPRESSION_CCITTFAX4) {
2159 return ERROR_INT_1(
"filein is not g4 compressed", filein, __func__, 1);
2162 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
2163 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
2164 TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
2165 if (h != rowsperstrip)
2166 L_WARNING(
"more than 1 strip\n", __func__);
2173 TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &minisblack);
2176 if (pw) *pw = (l_int32)w;
2177 if (ph) *ph = (l_int32)h;
2178 if (pminisblack) *pminisblack = (l_int32)minisblack;
2184 if (inarray[0] == 0x4d) {
2185 diroff = (inarray[4] << 24) | (inarray[5] << 16) |
2186 (inarray[6] << 8) | inarray[7];
2188 diroff = (inarray[7] << 24) | (inarray[6] << 16) |
2189 (inarray[5] << 8) | inarray[4];
2196 nbytes = diroff - 8;
2197 if (nbytes > MaxNumTiffBytes) {
2199 L_ERROR(
"requesting %zu bytes > %zu\n", __func__,
2200 nbytes, MaxNumTiffBytes);
2204 if ((data = (l_uint8 *)LEPT_CALLOC(nbytes,
sizeof(l_uint8))) == NULL) {
2206 return ERROR_INT(
"data not allocated", __func__, 1);
2209 memcpy(data, inarray + 8, nbytes);
2241 const char *modestring)
2244 return (TIFF *)ERROR_PTR(
"stream not opened", __func__, NULL);
2246 return (TIFF *)ERROR_PTR(
"modestring not defined", __func__, NULL);
2248 TIFFSetWarningHandler(NULL);
2249 TIFFSetErrorHandler(NULL);
2251 fseek(fp, 0, SEEK_SET);
2252 return TIFFClientOpen(
"TIFFstream", modestring, (thandle_t)fp,
2253 lept_read_proc, lept_write_proc, lept_seek_proc,
2254 lept_close_proc, lept_size_proc, NULL, NULL);
2275 const char *modestring)
2281 return (TIFF *)ERROR_PTR(
"filename not defined", __func__, NULL);
2283 return (TIFF *)ERROR_PTR(
"modestring not defined", __func__, NULL);
2285 TIFFSetWarningHandler(NULL);
2286 TIFFSetErrorHandler(NULL);
2288 fname = genPathname(filename, NULL);
2289 tif = TIFFOpen(fname, modestring);
2344static L_MEMSTREAM *memstreamCreateForRead(l_uint8 *indata,
size_t pinsize);
2345static L_MEMSTREAM *memstreamCreateForWrite(l_uint8 **poutdata,
2347static tsize_t tiffReadCallback(thandle_t handle, tdata_t data, tsize_t length);
2348static tsize_t tiffWriteCallback(thandle_t handle, tdata_t data,
2350static toff_t tiffSeekCallback(thandle_t handle, toff_t offset, l_int32 whence);
2351static l_int32 tiffCloseCallback(thandle_t handle);
2352static toff_t tiffSizeCallback(thandle_t handle);
2353static l_int32 tiffMapCallback(thandle_t handle, tdata_t *data, toff_t *length);
2354static void tiffUnmapCallback(thandle_t handle, tdata_t data, toff_t length);
2358memstreamCreateForRead(l_uint8 *indata,
2364 mstream->buffer = indata;
2365 mstream->bufsize = insize;
2366 mstream->hw = insize;
2367 mstream->offset = 0;
2373memstreamCreateForWrite(l_uint8 **poutdata,
2379 mstream->buffer = (l_uint8 *)LEPT_CALLOC(8 * 1024, 1);
2380 mstream->bufsize = 8 * 1024;
2381 mstream->poutdata = poutdata;
2382 mstream->poutsize = poutsize;
2383 mstream->hw = mstream->offset = 0;
2389tiffReadCallback(thandle_t handle,
2397 amount = L_MIN((
size_t)length, mstream->hw - mstream->offset);
2400 if (mstream->offset + amount < amount ||
2401 mstream->offset + amount > mstream->hw) {
2402 lept_stderr(
"Bad file: amount too big: %zu\n", amount);
2406 memcpy(data, mstream->buffer + mstream->offset, amount);
2407 mstream->offset += amount;
2413tiffWriteCallback(thandle_t handle,
2425 if (mstream->offset + length > mstream->bufsize) {
2426 newsize = 2 * (mstream->offset + length);
2427 mstream->buffer = (l_uint8 *)reallocNew((
void **)&mstream->buffer,
2428 mstream->hw, newsize);
2429 mstream->bufsize = newsize;
2432 memcpy(mstream->buffer + mstream->offset, data, length);
2433 mstream->offset += length;
2434 mstream->hw = L_MAX(mstream->offset, mstream->hw);
2440tiffSeekCallback(thandle_t handle,
2450 if((
size_t)offset != offset) {
2451 return (toff_t)ERROR_INT(
"too large offset value", __func__, 1);
2453 mstream->offset = offset;
2457 mstream->offset += offset;
2462 mstream->offset = mstream->hw - offset;
2465 return (toff_t)ERROR_INT(
"bad whence value", __func__,
2469 return mstream->offset;
2474tiffCloseCallback(thandle_t handle)
2479 if (mstream->poutdata) {
2480 *mstream->poutdata = mstream->buffer;
2481 *mstream->poutsize = mstream->hw;
2489tiffSizeCallback(thandle_t handle)
2499tiffMapCallback(thandle_t handle,
2506 *data = mstream->buffer;
2507 *length = mstream->hw;
2513tiffUnmapCallback(thandle_t handle,
2543 const char *operation,
2551 return (TIFF *)ERROR_PTR(
"filename not defined", __func__, NULL);
2553 return (TIFF *)ERROR_PTR(
"operation not defined", __func__, NULL);
2555 return (TIFF *)ERROR_PTR(
"&data not defined", __func__, NULL);
2557 return (TIFF *)ERROR_PTR(
"&datasize not defined", __func__, NULL);
2558 if (strcmp(operation,
"r") && strcmp(operation,
"w"))
2559 return (TIFF *)ERROR_PTR(
"op not 'r' or 'w'", __func__, NULL);
2561 if (!strcmp(operation,
"r"))
2562 mstream = memstreamCreateForRead(*pdata, *pdatasize);
2564 mstream = memstreamCreateForWrite(pdata, pdatasize);
2566 return (TIFF *)ERROR_PTR(
"mstream not made", __func__, NULL);
2568 TIFFSetWarningHandler(NULL);
2569 TIFFSetErrorHandler(NULL);
2571 tif = TIFFClientOpen(filename, operation, (thandle_t)mstream,
2572 tiffReadCallback, tiffWriteCallback,
2573 tiffSeekCallback, tiffCloseCallback,
2574 tiffSizeCallback, tiffMapCallback,
2613 return (
PIX *)ERROR_PTR(
"cdata not defined", __func__, NULL);
2615 data = (l_uint8 *)cdata;
2617 return (
PIX *)ERROR_PTR(
"tiff stream not opened", __func__, NULL);
2620 for (i = 0; ; i++) {
2626 pixSetInputFormat(pix, IFF_TIFF);
2629 if (TIFFReadDirectory(tif) == 0)
2631 if (i == ManyPagesInTiffFile + 1) {
2632 L_WARNING(
"big file: more than %d pages\n", __func__,
2633 ManyPagesInTiffFile);
2677 return (
PIX *)ERROR_PTR(
"cdata not defined", __func__, NULL);
2679 return (
PIX *)ERROR_PTR(
"&offset not defined", __func__, NULL);
2681 data = (l_uint8 *)cdata;
2683 return (
PIX *)ERROR_PTR(
"tiff stream not opened", __func__, NULL);
2687 retval = (offset == 0) ? TIFFSetDirectory(tif, 0)
2688 : TIFFSetSubDirectory(tif, offset);
2700 TIFFReadDirectory(tif);
2701 *poffset = TIFFCurrentDirOffset(tif);
2728 return (
PIXA *)ERROR_PTR(
"data not defined", __func__, NULL);
2731 pixa = pixaCreate(0);
2735 }
while (offset != 0);
2767 if (pdata) *pdata = NULL;
2769 return ERROR_INT(
"pdata not defined", __func__, 1);
2771 return ERROR_INT(
"pixa not defined", __func__, 1);
2774 if ((fp = fopenWriteWinTempfile()) == NULL)
2775 return ERROR_INT(
"tmpfile stream not opened", __func__, 1);
2777 if ((fp = tmpfile()) == NULL)
2778 return ERROR_INT(
"tmpfile stream not opened", __func__, 1);
2781 n = pixaGetCount(pixa);
2782 for (i = 0; i < n; i++) {
2783 modestr = (i == 0) ?
"w" :
"a";
2784 pix1 = pixaGetPix(pixa, i,
L_CLONE);
2785 if (pixGetDepth(pix1) == 1)
2793 *pdata = l_binaryReadStream(fp, psize);
2821 NULL, NULL, NULL, NULL);
2859 return ERROR_INT(
"&data not defined", __func__, 1);
2861 return ERROR_INT(
"&size not defined", __func__, 1);
2863 return ERROR_INT(
"&pix not defined", __func__, 1);
2864 if (pixGetDepth(pix) != 1 && comptype != IFF_TIFF &&
2865 comptype != IFF_TIFF_LZW && comptype != IFF_TIFF_ZIP &&
2866 comptype != IFF_TIFF_JPEG) {
2867 L_WARNING(
"invalid compression type for bpp > 1\n", __func__);
2868 comptype = IFF_TIFF_ZIP;
2872 return ERROR_INT(
"tiff stream not opened", __func__, 1);
#define GET_DATA_BYTE(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
@ REMOVE_CMAP_BASED_ON_SRC
Memory stream buffer used with TIFFClientOpen()
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()
static TIFF * fopenTiffMemstream(const char *filename, const char *operation, l_uint8 **pdata, size_t *pdatasize)
fopenTiffMemstream()
l_ok pixaWriteMemMultipageTiff(l_uint8 **pdata, size_t *psize, PIXA *pixa)
pixaWriteMemMultipageTiff()
l_ok fprintTiffInfo(FILE *fpout, const char *tiffile)
fprintTiffInfo()
PIX * pixReadTiff(const char *filename, l_int32 n)
pixReadTiff()
PIXA * pixaReadMultipageTiff(const char *filename)
pixaReadMultipageTiff()
l_ok pixWriteStreamTiffWA(FILE *fp, PIX *pix, l_int32 comptype, const char *modestr)
pixWriteStreamTiffWA()
static TIFF * openTiff(const char *filename, const char *modestring)
openTiff()
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()
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()
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 findTiffCompression(FILE *fp, l_int32 *pcomptype)
findTiffCompression()
static l_int32 writeCustomTiffTags(TIFF *tif, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes)
writeCustomTiffTags()
PIX * pixReadFromMultipageTiff(const char *fname, size_t *poffset)
pixReadFromMultipageTiff()
l_ok getTiffResolution(FILE *fp, l_int32 *pxres, l_int32 *pyres)
getTiffResolution()
PIX * pixReadStreamTiff(FILE *fp, l_int32 n)
pixReadStreamTiff()
static PIX * pixReadFromTiffStream(TIFF *tif)
pixReadFromTiffStream()
PIXA * pixaReadMemMultipageTiff(const l_uint8 *data, size_t size)
pixaReadMemMultipageTiff()
l_ok pixWriteTiff(const char *filename, PIX *pix, l_int32 comptype, const char *modestr)
pixWriteTiff()
l_ok writeMultipageTiff(const char *dirin, const char *substr, const char *fileout)
writeMultipageTiff()
l_ok pixWriteTiffCustom(const char *filename, PIX *pix, l_int32 comptype, const char *modestr, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes)
pixWriteTiffCustom()
PIX * pixReadMemFromMultipageTiff(const l_uint8 *cdata, size_t size, size_t *poffset)
pixReadMemFromMultipageTiff()
static l_int32 pixWriteToTiffStream(TIFF *tif, PIX *pix, l_int32 comptype, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes)
pixWriteToTiffStream()
l_ok pixWriteStreamTiff(FILE *fp, PIX *pix, l_int32 comptype)
pixWriteStreamTiff()
PIX * pixReadMemTiff(const l_uint8 *cdata, size_t size, l_int32 n)
pixReadMemTiff()
l_ok writeMultipageTiffSA(SARRAY *sa, const char *fileout)
writeMultipageTiffSA()
l_ok pixWriteMemTiff(l_uint8 **pdata, size_t *psize, PIX *pix, l_int32 comptype)
pixWriteMemTiff()
static TIFF * fopenTiff(FILE *fp, const char *modestring)
fopenTiff()
l_ok pixaWriteMultipageTiff(const char *fname, PIXA *pixa)
pixaWriteMultipageTiff()
static l_int32 getTiffCompressedFormat(l_uint16 tiffcomp)
getTiffCompressedFormat()
l_ok tiffGetCount(FILE *fp, l_int32 *pn)
tiffGetCount()
static l_int32 getTiffStreamResolution(TIFF *tif, l_int32 *pxres, l_int32 *pyres)
getTiffStreamResolution()
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 extractG4DataFromFile(const char *filein, l_uint8 **pdata, size_t *pnbytes, l_int32 *pw, l_int32 *ph, l_int32 *pminisblack)
extractG4DataFromFile()