119 #include <config_auto.h>
124 #include <sys/types.h>
131 #include "allheaders.h"
140 static const l_int32 DefaultResolution = 300;
141 static const l_int32 ManyPagesInTiffFile = 3000;
144 static const l_int32 MaxTiffWidth = 1 << 20;
145 static const l_int32 MaxTiffHeight = 1 << 20;
148 static 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);
164 static TIFF *
fopenTiff(FILE *fp,
const char *modestring);
165 static TIFF *
openTiff(
const char *filename,
const char *modestring);
172 l_uint8 **pdata,
size_t *pdatasize);
205 static struct tiff_transform tiff_partial_orientation_transforms[] = {
233 lept_read_proc(thandle_t cookie,
237 FILE* fp = (FILE *)cookie;
239 if (!buff || !cookie || !fp)
241 done = fread(buff, 1, size, fp);
246 lept_write_proc(thandle_t cookie,
250 FILE* fp = (FILE *)cookie;
252 if (!buff || !cookie || !fp)
254 done = fwrite(buff, 1, size, fp);
259 lept_seek_proc(thandle_t cookie,
263 FILE* fp = (FILE *)cookie;
264 #if defined(_MSC_VER)
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))
329 lept_close_proc(thandle_t cookie)
331 FILE* fp = (FILE *)cookie;
334 fseek(fp, 0, SEEK_SET);
339 lept_size_proc(thandle_t cookie)
341 FILE* fp = (FILE *)cookie;
342 #if defined(_MSC_VER)
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);
404 return (
PIX *)ERROR_PTR(
"image file not found", __func__, NULL);
436 return (
PIX *)ERROR_PTR(
"stream not defined", __func__, NULL);
439 return (
PIX *)ERROR_PTR(
"tif not opened", __func__, NULL);
441 if (TIFFSetDirectory(tif, n) == 0) {
500 l_uint8 *linebuf, *data, *rowptr;
501 l_uint16 spp, bps, photometry, tiffcomp, orientation, sample_fmt;
502 l_uint16 *redmap, *greenmap, *bluemap;
503 l_int32 d, wpl, bpl, comptype, i, j, k, ncolors, rval, gval, bval, aval;
504 l_int32 xres, yres, tiffbpl, packedbpl, half_size, twothirds_size;
505 l_uint32 w, h, tiffword, read_oriented;
506 l_uint32 *line, *ppixel, *tiffdata, *pixdata;
511 return (
PIX *)ERROR_PTR(
"tif not defined", __func__, NULL);
520 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_fmt);
521 if (sample_fmt != SAMPLEFORMAT_UINT) {
522 L_ERROR(
"sample format = %d is not uint\n", __func__, sample_fmt);
531 if (TIFFIsTiled(tif)) {
532 L_ERROR(
"tiled format is not supported\n", __func__);
543 TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &tiffcomp);
544 if (tiffcomp == COMPRESSION_OJPEG) {
545 L_ERROR(
"old style jpeg format is not supported\n", __func__);
550 #if defined(COMPRESSION_WEBP)
551 if (tiffcomp == COMPRESSION_WEBP) {
552 L_ERROR(
"webp in tiff not generally supported yet\n", __func__);
558 TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bps);
559 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &spp);
560 if (bps != 1 && bps != 2 && bps != 4 && bps != 8 && bps != 16) {
561 L_ERROR(
"invalid bps = %d\n", __func__, bps);
564 if (spp == 2 && bps != 8) {
565 L_ERROR(
"for 2 spp, only handle 8 bps; this is %d bps\n",
569 if ((spp == 3 || spp == 4) && bps < 8) {
570 L_ERROR(
"for 3 and 4 spp, only handle 8 and 16 bps; this is %d bps\n",
576 }
else if (spp == 2) {
578 }
else if (spp == 3 || spp == 4) {
581 L_ERROR(
"spp = %d; not in {1,2,3,4}\n", __func__, spp);
585 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
586 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
587 if (w > MaxTiffWidth) {
588 L_ERROR(
"width = %d pixels; too large\n", __func__, w);
591 if (h > MaxTiffHeight) {
592 L_ERROR(
"height = %d pixels; too large\n", __func__, h);
602 tiffbpl = TIFFScanlineSize(tif);
603 packedbpl = (bps * spp * w + 7) / 8;
604 half_size = (L_ABS(2 * tiffbpl - packedbpl) <= 8);
605 twothirds_size = (L_ABS(3 * tiffbpl - 2 * packedbpl) <= 8);
608 L_INFO(
"half_size: packedbpl = %d is approx. twice tiffbpl = %d\n",
609 __func__, packedbpl, tiffbpl);
611 L_INFO(
"twothirds_size: packedbpl = %d is approx. 1.5 tiffbpl = %d\n",
612 __func__, packedbpl, tiffbpl);
613 lept_stderr(
"tiffbpl = %d, packedbpl = %d, bps = %d, spp = %d, w = %d\n",
614 tiffbpl, packedbpl, bps, spp, w);
616 if (tiffbpl != packedbpl && !half_size && !twothirds_size) {
617 L_ERROR(
"invalid tiffbpl: tiffbpl = %d, packedbpl = %d, "
618 "bps = %d, spp = %d, w = %d\n",
619 __func__, tiffbpl, packedbpl, bps, spp, w);
626 return (
PIX *)ERROR_PTR(
"pix not made", __func__, NULL);
627 pixSetInputFormat(pix, IFF_TIFF);
629 wpl = pixGetWpl(pix);
632 linebuf = (l_uint8 *)LEPT_CALLOC(4 * wpl,
sizeof(l_uint8));
633 for (i = 0; i < h; i++) {
634 if (TIFFReadScanline(tif, linebuf, i, 0) < 0) {
637 L_ERROR(
"spp = 1, read fail at line %d\n", __func__, i);
640 memcpy(data, linebuf, tiffbpl);
648 }
else if (spp == 2 && bps == 8) {
649 L_INFO(
"gray+alpha is not supported; converting to RGBA\n", __func__);
651 linebuf = (l_uint8 *)LEPT_CALLOC(4 * wpl,
sizeof(l_uint8));
653 for (i = 0; i < h; i++) {
654 if (TIFFReadScanline(tif, linebuf, i, 0) < 0) {
657 L_ERROR(
"spp = 2, read fail at line %d\n", __func__, i);
661 ppixel = pixdata + i * wpl;
662 for (j = k = 0; j < w; j++) {
673 if ((tiffdata = (l_uint32 *)LEPT_CALLOC((
size_t)w * h,
674 sizeof(l_uint32))) == NULL) {
676 return (
PIX *)ERROR_PTR(
"calloc fail for tiffdata", __func__, NULL);
679 if (!TIFFReadRGBAImageOriented(tif, w, h, tiffdata,
680 ORIENTATION_TOPLEFT, 0)) {
683 return (
PIX *)ERROR_PTR(
"failed to read tiffdata", __func__, NULL);
688 if (spp == 4) pixSetSpp(pix, 4);
690 for (i = 0; i < h; i++, line += wpl) {
691 for (j = 0, ppixel = line; j < w; j++) {
693 tiffword = tiffdata[i * w + j];
694 rval = TIFFGetR(tiffword);
695 gval = TIFFGetG(tiffword);
696 bval = TIFFGetB(tiffword);
700 aval = TIFFGetA(tiffword);
710 pixSetXRes(pix, xres);
711 pixSetYRes(pix, yres);
716 pixSetInputFormat(pix, comptype);
718 if (TIFFGetField(tif, TIFFTAG_COLORMAP, &redmap, &greenmap, &bluemap)) {
725 return (
PIX *)ERROR_PTR(
"colormap size > 256", __func__, NULL);
729 return (
PIX *)ERROR_PTR(
"colormap not made", __func__, NULL);
732 for (i = 0; i < ncolors; i++)
737 return (
PIX *)ERROR_PTR(
"invalid colormap", __func__, NULL);
747 if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometry)) {
750 if (tiffcomp == COMPRESSION_CCITTFAX3 ||
751 tiffcomp == COMPRESSION_CCITTFAX4 ||
752 tiffcomp == COMPRESSION_CCITTRLE ||
753 tiffcomp == COMPRESSION_CCITTRLEW) {
754 photometry = PHOTOMETRIC_MINISWHITE;
756 photometry = PHOTOMETRIC_MINISBLACK;
759 if ((d == 1 && photometry == PHOTOMETRIC_MINISBLACK) ||
760 (d == 8 && photometry == PHOTOMETRIC_MINISWHITE))
764 if (TIFFGetField(tif, TIFFTAG_ORIENTATION, &orientation)) {
765 if (orientation >= 1 && orientation <= 8) {
767 &tiff_partial_orientation_transforms[orientation - 1] :
768 &tiff_orientation_transforms[orientation - 1];
769 if (transform->vflip)
pixFlipTB(pix, pix);
770 if (transform->hflip)
pixFlipLR(pix, pix);
771 if (transform->rotate) {
780 TIFFGetField(tif, TIFFTAG_IMAGEDESCRIPTION, &text);
817 NULL, NULL, NULL, NULL);
881 return ERROR_INT(
"filename not defined", __func__, 1);
883 return ERROR_INT(
"pix not defined", __func__, 1);
885 if ((tif =
openTiff(filename, modestr)) == NULL)
886 return ERROR_INT(
"tif not opened", __func__, 1);
958 return ERROR_INT(
"stream not defined", __func__, 1 );
960 return ERROR_INT(
"pix not defined", __func__, 1 );
961 if (strcmp(modestr,
"w") && strcmp(modestr,
"a")) {
962 L_ERROR(
"modestr = %s; not 'w' or 'a'\n", __func__, modestr);
966 if (pixGetDepth(pix) != 1 && comptype != IFF_TIFF &&
967 comptype != IFF_TIFF_LZW && comptype != IFF_TIFF_ZIP &&
968 comptype != IFF_TIFF_JPEG) {
969 L_WARNING(
"invalid compression type %d for bpp > 1; using TIFF_ZIP\n",
971 comptype = IFF_TIFF_ZIP;
974 if ((tif =
fopenTiff(fp, modestr)) == NULL)
975 return ERROR_INT(
"tif not opened", __func__, 1);
979 return ERROR_INT(
"tif write error", __func__, 1);
1031 l_uint8 *linebuf, *data;
1032 l_uint16 redmap[256], greenmap[256], bluemap[256];
1033 l_int32 w, h, d, spp, i, j, k, wpl, bpl, tiffbpl, ncolors, cmapsize;
1034 l_int32 *rmap, *gmap, *bmap;
1036 l_uint32 *line, *ppixel;
1042 return ERROR_INT(
"tif stream not defined", __func__, 1);
1044 return ERROR_INT(
"pix not defined", __func__, 1 );
1048 spp = pixGetSpp(pix);
1049 xres = pixGetXRes(pix);
1050 yres = pixGetYRes(pix);
1051 if (xres == 0) xres = DefaultResolution;
1052 if (yres == 0) yres = DefaultResolution;
1055 TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, (l_uint32)RESUNIT_INCH);
1056 TIFFSetField(tif, TIFFTAG_XRESOLUTION, (l_float64)xres);
1057 TIFFSetField(tif, TIFFTAG_YRESOLUTION, (l_float64)yres);
1059 TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (l_uint32)w);
1060 TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (l_uint32)h);
1061 TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
1064 TIFFSetField(tif, TIFFTAG_IMAGEDESCRIPTION, text);
1066 if (d == 1 && !pixGetColormap(pix)) {
1071 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
1072 }
else if ((d == 32 && spp == 3) || d == 24) {
1073 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1074 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)3);
1075 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE,
1076 (l_uint16)8, (l_uint16)8, (l_uint16)8);
1077 }
else if (d == 32 && spp == 4) {
1079 val[0] = EXTRASAMPLE_ASSOCALPHA;
1080 TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, (l_uint16)1, &val);
1081 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1082 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)4);
1083 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE,
1084 (l_uint16)8, (l_uint16)8, (l_uint16)8, (l_uint16)8);
1085 }
else if (d == 16) {
1086 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1087 }
else if ((cmap = pixGetColormap(pix)) == NULL) {
1088 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1091 L_ERROR(
"d = %d > 8 with colormap!; reducing to 8\n", __func__, d);
1096 ncolors = L_MIN(256, ncolors);
1098 cmapsize = L_MIN(256, cmapsize);
1099 if (ncolors > cmapsize) {
1100 L_WARNING(
"too many colors in cmap for tiff; truncating\n",
1104 for (i = 0; i < ncolors; i++) {
1105 redmap[i] = (rmap[i] << 8) | rmap[i];
1106 greenmap[i] = (gmap[i] << 8) | gmap[i];
1107 bluemap[i] = (bmap[i] << 8) | bmap[i];
1109 for (i = ncolors; i < cmapsize; i++)
1110 redmap[i] = greenmap[i] = bluemap[i] = 0;
1115 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_PALETTE);
1116 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)1);
1117 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, (l_uint16)d);
1118 TIFFSetField(tif, TIFFTAG_COLORMAP, redmap, greenmap, bluemap);
1122 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, (l_uint16)d);
1123 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (l_uint16)1);
1126 TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
1127 if (comptype == IFF_TIFF) {
1128 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
1129 }
else if (comptype == IFF_TIFF_G4) {
1130 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
1131 }
else if (comptype == IFF_TIFF_G3) {
1132 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX3);
1133 }
else if (comptype == IFF_TIFF_RLE) {
1134 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_CCITTRLE);
1135 }
else if (comptype == IFF_TIFF_PACKBITS) {
1136 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
1137 }
else if (comptype == IFF_TIFF_LZW) {
1138 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
1139 }
else if (comptype == IFF_TIFF_ZIP) {
1140 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_ADOBE_DEFLATE);
1141 }
else if (comptype == IFF_TIFF_JPEG) {
1142 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);
1144 L_WARNING(
"unknown tiff compression; using none\n", __func__);
1145 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
1152 tiffbpl = TIFFScanlineSize(tif);
1153 wpl = pixGetWpl(pix);
1156 lept_stderr(
"Big trouble: tiffbpl = %d, bpl = %d\n", tiffbpl, bpl);
1157 if ((linebuf = (l_uint8 *)LEPT_CALLOC(1, bpl)) == NULL)
1158 return ERROR_INT(
"calloc fail for linebuf", __func__, 1);
1161 TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, h);
1163 if (d != 24 && d != 32) {
1169 for (i = 0; i < h; i++, data += bpl) {
1170 memcpy(linebuf, data, tiffbpl);
1171 if (TIFFWriteScanline(tif, linebuf, i, 0) < 0)
1175 }
else if (d == 24) {
1176 for (i = 0; i < h; i++) {
1178 if (TIFFWriteScanline(tif, (l_uint8 *)line, i, 0) < 0)
1182 for (i = 0; i < h; i++) {
1184 for (j = 0, k = 0, ppixel = line; j < w; j++) {
1192 if (TIFFWriteScanline(tif, linebuf, i, 0) < 0)
1241 l_int32 i, n, ns, size, tagval, val;
1243 l_uint32 uval, uval2;
1246 return ERROR_INT(
"tif stream not defined", __func__, 1);
1247 if (!natags && !savals && !satypes)
1249 if (!natags || !savals || !satypes)
1250 return ERROR_INT(
"not all arrays defined", __func__, 1);
1253 return ERROR_INT(
"not all sa the same size", __func__, 1);
1259 return ERROR_INT(
"too many 4-arg tag calls", __func__, 1);
1260 for (i = 0; i < ns; i++) {
1265 if (strcmp(type,
"char*") && strcmp(type,
"l_uint8*"))
1266 L_WARNING(
"array type not char* or l_uint8*; ignore\n",
1268 TIFFSetField(tif, tagval, size, sval);
1275 for (i = ns; i < n; i++) {
1279 if (!strcmp(type,
"char*") || !strcmp(type,
"const char*")) {
1280 TIFFSetField(tif, tagval, sval);
1281 }
else if (!strcmp(type,
"l_uint16")) {
1282 if (sscanf(sval,
"%u", &uval) == 1) {
1283 TIFFSetField(tif, tagval, (l_uint16)uval);
1285 lept_stderr(
"val %s not of type %s\n", sval, type);
1286 return ERROR_INT(
"custom tag(s) not written", __func__, 1);
1288 }
else if (!strcmp(type,
"l_uint32")) {
1289 if (sscanf(sval,
"%u", &uval) == 1) {
1290 TIFFSetField(tif, tagval, uval);
1292 lept_stderr(
"val %s not of type %s\n", sval, type);
1293 return ERROR_INT(
"custom tag(s) not written", __func__, 1);
1295 }
else if (!strcmp(type,
"l_int32")) {
1296 if (sscanf(sval,
"%d", &val) == 1) {
1297 TIFFSetField(tif, tagval, val);
1299 lept_stderr(
"val %s not of type %s\n", sval, type);
1300 return ERROR_INT(
"custom tag(s) not written", __func__, 1);
1302 }
else if (!strcmp(type,
"l_float64")) {
1303 if (sscanf(sval,
"%lf", &dval) == 1) {
1304 TIFFSetField(tif, tagval, dval);
1306 lept_stderr(
"val %s not of type %s\n", sval, type);
1307 return ERROR_INT(
"custom tag(s) not written", __func__, 1);
1309 }
else if (!strcmp(type,
"l_uint16-l_uint16")) {
1310 if (sscanf(sval,
"%u-%u", &uval, &uval2) == 2) {
1311 TIFFSetField(tif, tagval, (l_uint16)uval, (l_uint16)uval2);
1313 lept_stderr(
"val %s not of type %s\n", sval, type);
1314 return ERROR_INT(
"custom tag(s) not written", __func__, 1);
1318 return ERROR_INT(
"unknown type; tag(s) not written", __func__, 1);
1369 return (
PIX *)ERROR_PTR(
"fname not defined", __func__, NULL);
1371 return (
PIX *)ERROR_PTR(
"&offset not defined", __func__, NULL);
1373 if ((tif =
openTiff(fname,
"r")) == NULL) {
1374 L_ERROR(
"tif open failed for %s\n", __func__, fname);
1380 retval = (offset == 0) ? TIFFSetDirectory(tif, 0)
1381 : TIFFSetSubDirectory(tif, offset);
1393 TIFFReadDirectory(tif);
1394 *poffset = TIFFCurrentDirOffset(tif);
1416 return (
PIXA *)ERROR_PTR(
"filename not defined", __func__, NULL);
1419 return (
PIXA *)ERROR_PTR(
"stream not opened", __func__, NULL);
1422 L_INFO(
" Tiff: %d pages\n", __func__, npages);
1424 return (
PIXA *)ERROR_PTR(
"file not tiff", __func__, NULL);
1428 return (
PIXA *)ERROR_PTR(
"tif not opened", __func__, NULL);
1432 for (i = 0; i < npages; i++) {
1436 L_WARNING(
"pix not read for page %d\n", __func__, i);
1440 if (TIFFReadDirectory(tif) == 0)
1468 const char *modestr;
1473 return ERROR_INT(
"fname not defined", __func__, 1);
1475 return ERROR_INT(
"pixa not defined", __func__, 1);
1478 for (i = 0; i < n; i++) {
1479 modestr = (i == 0) ?
"w" :
"a";
1481 if (pixGetDepth(pix1) == 1)
1519 const char *fileout)
1524 return ERROR_INT(
"dirin not defined", __func__, 1);
1526 return ERROR_INT(
"fileout not defined", __func__, 1);
1552 const char *fileout)
1556 l_int32 i, nfiles, firstfile, format;
1560 return ERROR_INT(
"sa not defined", __func__, 1);
1562 return ERROR_INT(
"fileout not defined", __func__, 1);
1566 for (i = 0; i < nfiles; i++) {
1567 op = (firstfile) ?
"w" :
"a";
1570 if (format == IFF_UNKNOWN) {
1571 L_INFO(
"format of %s not known\n", __func__, fname);
1575 if ((pix =
pixRead(fname)) == NULL) {
1576 L_WARNING(
"pix not made for file: %s\n", __func__, fname);
1579 if (pixGetDepth(pix) == 1)
1603 const char *tiffile)
1608 return ERROR_INT(
"tiffile not defined", __func__, 1);
1610 return ERROR_INT(
"stream out not defined", __func__, 1);
1612 if ((tif =
openTiff(tiffile,
"rb")) == NULL)
1613 return ERROR_INT(
"tif not open for read", __func__, 1);
1615 TIFFPrintDirectory(tif, fpout, 0);
1640 return ERROR_INT(
"stream not defined", __func__, 1);
1642 return ERROR_INT(
"&n not defined", __func__, 1);
1646 return ERROR_INT(
"tif not open for read", __func__, 1);
1648 for (i = 1; ; i++) {
1649 if (TIFFReadDirectory(tif) == 0)
1651 if (i == ManyPagesInTiffFile + 1) {
1652 L_WARNING(
"big file: more than %d pages\n", __func__,
1653 ManyPagesInTiffFile);
1685 if (!pxres || !pyres)
1686 return ERROR_INT(
"&xres and &yres not both defined", __func__, 1);
1687 *pxres = *pyres = 0;
1689 return ERROR_INT(
"stream not opened", __func__, 1);
1692 return ERROR_INT(
"tif not open for read", __func__, 1);
1718 l_int32 foundxres, foundyres;
1719 l_float32 fxres, fyres;
1722 return ERROR_INT(
"tif not opened", __func__, 1);
1723 if (!pxres || !pyres)
1724 return ERROR_INT(
"&xres and &yres not both defined", __func__, 1);
1725 *pxres = *pyres = 0;
1727 TIFFGetFieldDefaulted(tif, TIFFTAG_RESOLUTIONUNIT, &resunit);
1728 foundxres = TIFFGetField(tif, TIFFTAG_XRESOLUTION, &fxres);
1729 foundyres = TIFFGetField(tif, TIFFTAG_YRESOLUTION, &fyres);
1730 if (!foundxres && !foundyres)
return 1;
1731 if (isnan(fxres) || isnan(fyres))
return 1;
1732 if (!foundxres && foundyres)
1734 else if (foundxres && !foundyres)
1738 if (fxres < 0 || fxres > (1L << 29) || fyres < 0 || fyres > (1L << 29))
1739 return ERROR_INT(
"fxres and/or fyres values are invalid", __func__, 1);
1741 if (resunit == RESUNIT_CENTIMETER) {
1742 *pxres = (l_int32)(2.54 * fxres + 0.5);
1743 *pyres = (l_int32)(2.54 * fyres + 0.5);
1745 *pxres = (l_int32)(fxres + 0.5);
1746 *pyres = (l_int32)(fyres + 0.5);
1792 if (pbps) *pbps = 0;
1793 if (pspp) *pspp = 0;
1794 if (pres) *pres = 0;
1795 if (pcmap) *pcmap = 0;
1796 if (pformat) *pformat = 0;
1798 return ERROR_INT(
"filename not defined", __func__, 1);
1799 if (!pw && !ph && !pbps && !pspp && !pres && !pcmap && !pformat)
1800 return ERROR_INT(
"no results requested", __func__, 1);
1803 return ERROR_INT(
"image file not found", __func__, 1);
1804 ret =
freadHeaderTiff(fp, n, pw, ph, pbps, pspp, pres, pcmap, pformat);
1841 l_int32 i, ret, format;
1846 if (pbps) *pbps = 0;
1847 if (pspp) *pspp = 0;
1848 if (pres) *pres = 0;
1849 if (pcmap) *pcmap = 0;
1850 if (pformat) *pformat = 0;
1852 return ERROR_INT(
"stream not defined", __func__, 1);
1854 return ERROR_INT(
"image index must be >= 0", __func__, 1);
1855 if (!pw && !ph && !pbps && !pspp && !pres && !pcmap && !pformat)
1856 return ERROR_INT(
"no results requested", __func__, 1);
1859 if (!L_FORMAT_IS_TIFF(format))
1860 return ERROR_INT(
"file not tiff format", __func__, 1);
1863 return ERROR_INT(
"tif not open for read", __func__, 1);
1865 for (i = 0; i < n; i++) {
1866 if (TIFFReadDirectory(tif) == 0)
1867 return ERROR_INT(
"image n not found in file", __func__, 1);
1915 if (pbps) *pbps = 0;
1916 if (pspp) *pspp = 0;
1917 if (pres) *pres = 0;
1918 if (pcmap) *pcmap = 0;
1919 if (pformat) *pformat = 0;
1920 if (!pw && !ph && !pbps && !pspp && !pres && !pcmap && !pformat)
1921 return ERROR_INT(
"no results requested", __func__, 1);
1923 return ERROR_INT(
"cdata not defined", __func__, 1);
1926 data = (l_uint8 *)cdata;
1928 return ERROR_INT(
"tiff stream not opened", __func__, 1);
1930 for (i = 0; i < n; i++) {
1931 if (TIFFReadDirectory(tif) == 0) {
1933 return ERROR_INT(
"image n not found in file", __func__, 1);
1968 l_uint16 *rmap, *gmap, *bmap;
1973 return ERROR_INT(
"tif not opened", __func__, 1);
1975 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
1976 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
1977 TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bps);
1978 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &spp);
1980 return ERROR_INT(
"tif w and h not both > 0", __func__, 1);
1981 if (bps != 1 && bps != 2 && bps != 4 && bps != 8 && bps != 16)
1982 return ERROR_INT(
"bps not in set {1,2,4,8,16}", __func__, 1);
1983 if (spp != 1 && spp != 2 && spp != 3 && spp != 4)
1984 return ERROR_INT(
"spp not in set {1,2,3,4}", __func__, 1);
1987 if (pbps) *pbps = bps;
1988 if (pspp) *pspp = spp;
1991 *pres = (l_int32)xres;
1994 if (TIFFGetField(tif, TIFFTAG_COLORMAP, &rmap, &gmap, &bmap))
1998 TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &tiffcomp);
2032 return ERROR_INT(
"&comptype not defined", __func__, 1);
2033 *pcomptype = IFF_UNKNOWN;
2035 return ERROR_INT(
"stream not defined", __func__, 1);
2038 return ERROR_INT(
"tif not opened", __func__, 1);
2039 TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &tiffcomp);
2067 case COMPRESSION_CCITTFAX4:
2068 comptype = IFF_TIFF_G4;
2070 case COMPRESSION_CCITTFAX3:
2071 comptype = IFF_TIFF_G3;
2073 case COMPRESSION_CCITTRLE:
2074 comptype = IFF_TIFF_RLE;
2076 case COMPRESSION_PACKBITS:
2077 comptype = IFF_TIFF_PACKBITS;
2079 case COMPRESSION_LZW:
2080 comptype = IFF_TIFF_LZW;
2082 case COMPRESSION_ADOBE_DEFLATE:
2083 comptype = IFF_TIFF_ZIP;
2085 case COMPRESSION_JPEG:
2086 comptype = IFF_TIFF_JPEG;
2089 comptype = IFF_TIFF;
2116 l_int32 *pminisblack)
2118 l_uint8 *inarray, *data;
2119 l_uint16 minisblack, comptype;
2121 l_uint32 w, h, rowsperstrip;
2123 size_t fbytes, nbytes;
2128 return ERROR_INT(
"&data not defined", __func__, 1);
2130 return ERROR_INT(
"&nbytes not defined", __func__, 1);
2131 if (!pw && !ph && !pminisblack)
2132 return ERROR_INT(
"no output data requested", __func__, 1);
2137 return ERROR_INT(
"stream not opened to file", __func__, 1);
2141 return ERROR_INT(
"filein not tiff", __func__, 1);
2144 return ERROR_INT(
"inarray not made", __func__, 1);
2147 if ((tif =
openTiff(filein,
"rb")) == NULL) {
2149 return ERROR_INT(
"tif not open for read", __func__, 1);
2151 TIFFGetField(tif, TIFFTAG_COMPRESSION, &comptype);
2152 if (comptype != COMPRESSION_CCITTFAX4) {
2155 return ERROR_INT(
"filein is not g4 compressed", __func__, 1);
2158 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
2159 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
2160 TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
2161 if (h != rowsperstrip)
2162 L_WARNING(
"more than 1 strip\n", __func__);
2169 TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &minisblack);
2172 if (pw) *pw = (l_int32)w;
2173 if (ph) *ph = (l_int32)h;
2174 if (pminisblack) *pminisblack = (l_int32)minisblack;
2180 if (inarray[0] == 0x4d) {
2181 diroff = (inarray[4] << 24) | (inarray[5] << 16) |
2182 (inarray[6] << 8) | inarray[7];
2184 diroff = (inarray[7] << 24) | (inarray[6] << 16) |
2185 (inarray[5] << 8) | inarray[4];
2192 nbytes = diroff - 8;
2193 if (nbytes > MaxNumTiffBytes) {
2195 L_ERROR(
"requesting %zu bytes > %zu\n", __func__,
2196 nbytes, MaxNumTiffBytes);
2200 if ((data = (l_uint8 *)LEPT_CALLOC(nbytes,
sizeof(l_uint8))) == NULL) {
2202 return ERROR_INT(
"data not allocated", __func__, 1);
2205 memcpy(data, inarray + 8, nbytes);
2237 const char *modestring)
2240 return (TIFF *)ERROR_PTR(
"stream not opened", __func__, NULL);
2242 return (TIFF *)ERROR_PTR(
"modestring not defined", __func__, NULL);
2244 TIFFSetWarningHandler(NULL);
2245 TIFFSetErrorHandler(NULL);
2247 fseek(fp, 0, SEEK_SET);
2248 return TIFFClientOpen(
"TIFFstream", modestring, (thandle_t)fp,
2249 lept_read_proc, lept_write_proc, lept_seek_proc,
2250 lept_close_proc, lept_size_proc, NULL, NULL);
2271 const char *modestring)
2277 return (TIFF *)ERROR_PTR(
"filename not defined", __func__, NULL);
2279 return (TIFF *)ERROR_PTR(
"modestring not defined", __func__, NULL);
2281 TIFFSetWarningHandler(NULL);
2282 TIFFSetErrorHandler(NULL);
2285 tif = TIFFOpen(fname, modestring);
2340 static L_MEMSTREAM *memstreamCreateForRead(l_uint8 *indata,
size_t pinsize);
2341 static L_MEMSTREAM *memstreamCreateForWrite(l_uint8 **poutdata,
2343 static tsize_t tiffReadCallback(thandle_t handle, tdata_t data, tsize_t length);
2344 static tsize_t tiffWriteCallback(thandle_t handle, tdata_t data,
2346 static toff_t tiffSeekCallback(thandle_t handle, toff_t offset, l_int32 whence);
2347 static l_int32 tiffCloseCallback(thandle_t handle);
2348 static toff_t tiffSizeCallback(thandle_t handle);
2349 static l_int32 tiffMapCallback(thandle_t handle, tdata_t *data, toff_t *length);
2350 static void tiffUnmapCallback(thandle_t handle, tdata_t data, toff_t length);
2354 memstreamCreateForRead(l_uint8 *indata,
2360 mstream->buffer = indata;
2361 mstream->bufsize = insize;
2362 mstream->hw = insize;
2363 mstream->offset = 0;
2369 memstreamCreateForWrite(l_uint8 **poutdata,
2375 mstream->buffer = (l_uint8 *)LEPT_CALLOC(8 * 1024, 1);
2376 mstream->bufsize = 8 * 1024;
2377 mstream->poutdata = poutdata;
2378 mstream->poutsize = poutsize;
2379 mstream->hw = mstream->offset = 0;
2385 tiffReadCallback(thandle_t handle,
2393 amount = L_MIN((
size_t)length, mstream->hw - mstream->offset);
2396 if (mstream->offset + amount < amount ||
2397 mstream->offset + amount > mstream->hw) {
2398 lept_stderr(
"Bad file: amount too big: %zu\n", amount);
2402 memcpy(data, mstream->buffer + mstream->offset, amount);
2403 mstream->offset += amount;
2409 tiffWriteCallback(thandle_t handle,
2421 if (mstream->offset + length > mstream->bufsize) {
2422 newsize = 2 * (mstream->offset + length);
2423 mstream->buffer = (l_uint8 *)
reallocNew((
void **)&mstream->buffer,
2424 mstream->hw, newsize);
2425 mstream->bufsize = newsize;
2428 memcpy(mstream->buffer + mstream->offset, data, length);
2429 mstream->offset += length;
2430 mstream->hw = L_MAX(mstream->offset, mstream->hw);
2436 tiffSeekCallback(thandle_t handle,
2446 if((
size_t)offset != offset) {
2447 return (toff_t)ERROR_INT(
"too large offset value", __func__, 1);
2449 mstream->offset = offset;
2453 mstream->offset += offset;
2458 mstream->offset = mstream->hw - offset;
2461 return (toff_t)ERROR_INT(
"bad whence value", __func__,
2465 return mstream->offset;
2470 tiffCloseCallback(thandle_t handle)
2475 if (mstream->poutdata) {
2476 *mstream->poutdata = mstream->buffer;
2477 *mstream->poutsize = mstream->hw;
2485 tiffSizeCallback(thandle_t handle)
2495 tiffMapCallback(thandle_t handle,
2502 *data = mstream->buffer;
2503 *length = mstream->hw;
2509 tiffUnmapCallback(thandle_t handle,
2539 const char *operation,
2547 return (TIFF *)ERROR_PTR(
"filename not defined", __func__, NULL);
2549 return (TIFF *)ERROR_PTR(
"operation not defined", __func__, NULL);
2551 return (TIFF *)ERROR_PTR(
"&data not defined", __func__, NULL);
2553 return (TIFF *)ERROR_PTR(
"&datasize not defined", __func__, NULL);
2554 if (strcmp(operation,
"r") && strcmp(operation,
"w"))
2555 return (TIFF *)ERROR_PTR(
"op not 'r' or 'w'", __func__, NULL);
2557 if (!strcmp(operation,
"r"))
2558 mstream = memstreamCreateForRead(*pdata, *pdatasize);
2560 mstream = memstreamCreateForWrite(pdata, pdatasize);
2562 return (TIFF *)ERROR_PTR(
"mstream not made", __func__, NULL);
2564 TIFFSetWarningHandler(NULL);
2565 TIFFSetErrorHandler(NULL);
2567 tif = TIFFClientOpen(filename, operation, (thandle_t)mstream,
2568 tiffReadCallback, tiffWriteCallback,
2569 tiffSeekCallback, tiffCloseCallback,
2570 tiffSizeCallback, tiffMapCallback,
2609 return (
PIX *)ERROR_PTR(
"cdata not defined", __func__, NULL);
2611 data = (l_uint8 *)cdata;
2613 return (
PIX *)ERROR_PTR(
"tiff stream not opened", __func__, NULL);
2616 for (i = 0; ; i++) {
2622 pixSetInputFormat(pix, IFF_TIFF);
2625 if (TIFFReadDirectory(tif) == 0)
2627 if (i == ManyPagesInTiffFile + 1) {
2628 L_WARNING(
"big file: more than %d pages\n", __func__,
2629 ManyPagesInTiffFile);
2673 return (
PIX *)ERROR_PTR(
"cdata not defined", __func__, NULL);
2675 return (
PIX *)ERROR_PTR(
"&offset not defined", __func__, NULL);
2677 data = (l_uint8 *)cdata;
2679 return (
PIX *)ERROR_PTR(
"tiff stream not opened", __func__, NULL);
2683 retval = (offset == 0) ? TIFFSetDirectory(tif, 0)
2684 : TIFFSetSubDirectory(tif, offset);
2696 TIFFReadDirectory(tif);
2697 *poffset = TIFFCurrentDirOffset(tif);
2724 return (
PIXA *)ERROR_PTR(
"data not defined", __func__, NULL);
2731 }
while (offset != 0);
2758 const char *modestr;
2763 if (pdata) *pdata = NULL;
2765 return ERROR_INT(
"pdata not defined", __func__, 1);
2767 return ERROR_INT(
"pixa not defined", __func__, 1);
2771 return ERROR_INT(
"tmpfile stream not opened", __func__, 1);
2773 if ((fp = tmpfile()) == NULL)
2774 return ERROR_INT(
"tmpfile stream not opened", __func__, 1);
2778 for (i = 0; i < n; i++) {
2779 modestr = (i == 0) ?
"w" :
"a";
2781 if (pixGetDepth(pix1) == 1)
2817 NULL, NULL, NULL, NULL);
2855 return ERROR_INT(
"&data not defined", __func__, 1);
2857 return ERROR_INT(
"&size not defined", __func__, 1);
2859 return ERROR_INT(
"&pix not defined", __func__, 1);
2860 if (pixGetDepth(pix) != 1 && comptype != IFF_TIFF &&
2861 comptype != IFF_TIFF_LZW && comptype != IFF_TIFF_ZIP &&
2862 comptype != IFF_TIFF_JPEG) {
2863 L_WARNING(
"invalid compression type for bpp > 1\n", __func__);
2864 comptype = IFF_TIFF_ZIP;
2868 return ERROR_INT(
"tiff stream not opened", __func__, 1);
#define GET_DATA_BYTE(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
l_int32 pixcmapGetCount(const PIXCMAP *cmap)
pixcmapGetCount()
PIXCMAP * pixcmapCreate(l_int32 depth)
pixcmapCreate()
l_ok pixcmapToArrays(const PIXCMAP *cmap, l_int32 **prmap, l_int32 **pgmap, l_int32 **pbmap, l_int32 **pamap)
pixcmapToArrays()
l_ok pixcmapAddColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval)
pixcmapAddColor()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
l_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
char * pixGetText(PIX *pix)
pixGetText()
l_ok pixSetText(PIX *pix, const char *textstring)
pixSetText()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixEndianByteSwapNew(PIX *pixs)
pixEndianByteSwapNew()
l_ok pixEndianTwoByteSwap(PIX *pixs)
pixEndianTwoByteSwap()
l_ok pixSetPadBits(PIX *pix, l_int32 val)
pixSetPadBits()
l_ok composeRGBAPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_int32 aval, l_uint32 *ppixel)
composeRGBAPixel()
PIX * pixEndianTwoByteSwapNew(PIX *pixs)
pixEndianTwoByteSwapNew()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
l_ok pixEndianByteSwap(PIX *pixs)
pixEndianByteSwap()
PIX * pixInvert(PIX *pixd, PIX *pixs)
pixInvert()
@ REMOVE_CMAP_BASED_ON_SRC
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
l_ok findFileFormat(const char *filename, l_int32 *pformat)
findFileFormat()
l_ok findFileFormatStream(FILE *fp, l_int32 *pformat)
findFileFormatStream()
PIX * pixRead(const char *filename)
pixRead()
l_int32 fileFormatIsTiff(FILE *fp)
fileFormatIsTiff()
PIX * pixRotate90(PIX *pixs, l_int32 direction)
pixRotate90()
PIX * pixFlipLR(PIX *pixd, PIX *pixs)
pixFlipLR()
PIX * pixFlipTB(PIX *pixd, PIX *pixs)
pixFlipTB()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
SARRAY * getSortedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
getSortedPathnamesInDirectory()
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()
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()
PIX * pixReadMemFromMultipageTiff(const l_uint8 *cdata, size_t size, size_t *poffset)
pixReadMemFromMultipageTiff()
static l_int32 writeCustomTiffTags(TIFF *tif, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes)
writeCustomTiffTags()
l_ok getTiffResolution(FILE *fp, l_int32 *pxres, l_int32 *pyres)
getTiffResolution()
PIX * pixReadMemTiff(const l_uint8 *cdata, size_t size, l_int32 n)
pixReadMemTiff()
static PIX * pixReadFromTiffStream(TIFF *tif)
pixReadFromTiffStream()
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()
PIX * pixReadFromMultipageTiff(const char *fname, size_t *poffset)
pixReadFromMultipageTiff()
l_ok pixWriteTiffCustom(const char *filename, PIX *pix, l_int32 comptype, const char *modestr, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes)
pixWriteTiffCustom()
static l_int32 pixWriteToTiffStream(TIFF *tif, PIX *pix, l_int32 comptype, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes)
pixWriteToTiffStream()
PIX * pixReadStreamTiff(FILE *fp, l_int32 n)
pixReadStreamTiff()
l_ok pixWriteStreamTiff(FILE *fp, PIX *pix, l_int32 comptype)
pixWriteStreamTiff()
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()
PIX * pixReadTiff(const char *filename, l_int32 n)
pixReadTiff()
static l_int32 getTiffCompressedFormat(l_uint16 tiffcomp)
getTiffCompressedFormat()
l_ok tiffGetCount(FILE *fp, l_int32 *pn)
tiffGetCount()
PIXA * pixaReadMemMultipageTiff(const l_uint8 *data, size_t size)
pixaReadMemMultipageTiff()
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()
PIXA * pixaReadMultipageTiff(const char *filename)
pixaReadMultipageTiff()
l_ok extractG4DataFromFile(const char *filein, l_uint8 **pdata, size_t *pnbytes, l_int32 *pw, l_int32 *ph, l_int32 *pminisblack)
extractG4DataFromFile()
void lept_stderr(const char *fmt,...)
lept_stderr()
l_uint8 * l_binaryReadStream(FILE *fp, size_t *pnbytes)
l_binaryReadStream()
char * genPathname(const char *dir, const char *fname)
genPathname()
void * reallocNew(void **pindata, size_t oldsize, size_t newsize)
reallocNew()
FILE * fopenWriteWinTempfile(void)
fopenWriteWinTempfile()
FILE * fopenReadStream(const char *filename)
fopenReadStream()
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()