56static const char photoTag[] =
"PhotometricInterpretation";
68#define FLIP_VERTICALLY 0x01
76#define FLIP_HORIZONTALLY 0x02
86#define EMSG_BUF_SIZE 1024
100 {3.2410f, -1.5374f, -0.4986f},
101 {-0.9692f, 1.8760f, 0.0416f},
102 {0.0556f, -0.2040f, 1.0570f}},
146 if (orientation < 1 || orientation > 8)
160 uint16_t photometric;
166 "Sorry, requested compression method is not configured");
179 "Sorry, can not handle images with %" PRIu16
188 "Sorry, can not handle images with IEEE floating-point samples");
194 switch (colorchannels)
218 "Sorry, can not handle contiguous data with %s=%" PRIu16
220 "and %s=%" PRIu16
" and Bits/Sample=%" PRIu16
"",
221 photoTag, photometric,
"Samples/pixel",
240 if (colorchannels < 3)
243 "Sorry, can not handle RGB image with %s=%d",
244 "Color channels", colorchannels);
255 "Sorry, can not handle separated image with %s=%d",
263 "Sorry, can not handle separated image with %s=%" PRIu16,
273 "Sorry, LogL data must have %s=%d",
"Compression",
283 "Sorry, LogLuv data must have %s=%d or %d",
291 "Sorry, can not handle LogLuv images with %s=%" PRIu16,
298 "Sorry, can not handle image with %s=%" PRIu16
301 "colorchannels", colorchannels);
310 "Sorry, can not handle image with %s=%" PRIu16
311 ", %s=%d and %s=%" PRIu16,
313 "colorchannels", colorchannels,
"Bits/sample",
320 "Sorry, can not handle image with %s=%" PRIu16,
photoTag,
398 uint16_t *sampleinfo;
399 uint16_t extrasamples;
400 uint16_t planarconfig;
403 uint16_t *red_orig, *green_orig, *blue_orig;
437 "Sorry, can not handle images with %" PRIu16
446 if (extrasamples >= 1)
448 switch (sampleinfo[0])
458 img->
alpha = sampleinfo[0];
465#ifdef DEFAULT_EXTRASAMPLE_AS_ALPHA
482 switch (colorchannels)
506 "Missing required \"Colormap\" tag");
513 tif, (
tmsize_t)(
sizeof(uint16_t) * (
size_t)n_color));
515 tif, (
tmsize_t)(
sizeof(uint16_t) * (
size_t)n_color));
517 tif, (
tmsize_t)(
sizeof(uint16_t) * (
size_t)n_color));
521 "Out of memory for colormap copy");
537 "Sorry, can not handle contiguous data with %s=%" PRIu16
539 "and %s=%" PRIu16
" and Bits/Sample=%" PRIu16,
575 if (colorchannels < 3)
578 "Sorry, can not handle RGB image with %s=%d",
579 "Color channels", colorchannels);
591 "Sorry, can not handle separated image with %s=%" PRIu16,
599 "Sorry, can not handle separated image with %s=%" PRIu16,
609 "Sorry, LogL data must have %s=%d",
"Compression",
622 "Sorry, LogLuv data must have %s=%d or %d",
630 "Sorry, can not handle LogLuv images with %s=%" PRIu16,
631 "Planarconfiguration", planarconfig);
642 "Sorry, can not handle image with %s=%" PRIu16,
photoTag,
655 snprintf(emsg,
EMSG_BUF_SIZE,
"Sorry, can not handle image");
663 snprintf(emsg,
EMSG_BUF_SIZE,
"Sorry, can not handle image");
677 if (img->
get == NULL)
680 "No \"get\" routine setup");
687 "No \"put\" routine setupl; probably can not handle image format");
691 return (*img->
get)(img, raster, rwidth, rheight);
699 uint32_t *raster,
int orientation,
int stop)
724 uint32_t *raster,
int stop)
749 "TIFFRGBAImage ERROR: Requested orientation %d is not "
750 "within allowed range of image orientations 1 to 8. "
826 static const char warnMsg[] =
827 "TIFFRGBAImage cannot rotate but only flip. Therefore, image "
828 "pixel will be moved to %s corner of the raster matrix as origin "
829 "but the image pixel orientation will result in %s";
890 uint32_t rwidth, uint32_t rheight,
891 uint32_t *pwcpy, uint32_t *phcpy,
892 int *pflip, uint32_t **pp_raster_start,
893 int32_t *ptoskew, uint32_t *py,
894 bool isTiled, uint32_t tilewidth,
895 const char *funcName)
902 "Error in %s: row offset %d exceeds "
915 "Error in %s: column offset %d exceeds "
937 *pp_raster_start = raster;
941 *pp_raster_start = raster + ((size_t)rwidth - *pwcpy);
945 *pp_raster_start = raster + ((size_t)rheight - *phcpy) * rwidth +
946 ((size_t)rwidth - *pwcpy);
950 *pp_raster_start = raster + ((size_t)rheight - *phcpy) * rwidth;
962 const uint32_t cpywidth =
isTiled ? tilewidth : *pwcpy;
965 if ((int64_t)rwidth + cpywidth > INT_MAX)
968 "Width overflow in %s", funcName);
973 *ptoskew = -(int32_t)(rwidth + cpywidth);
980 if (cpywidth > ((int64_t)INT_MAX + rwidth) ||
981 rwidth > ((int64_t)INT_MAX + cpywidth))
984 "Width underflow in %s", funcName);
987 *ptoskew = (int32_t)(rwidth - cpywidth);
1016 if ((bitoffset % 8) != 0)
1019 "%s: column offset %d does not align to a byte boundary "
1020 "for bitspersample %u / samplesperpixel %u",
1068 uint32_t col, row, y, rowstoread;
1071 unsigned char *buf = NULL;
1072 int32_t fromskew, toskew;
1075 uint32_t this_tw, tocol;
1076 int32_t this_toskew, leftmost_toskew;
1077 int32_t leftmost_fromskew;
1078 uint32_t leftmost_tw;
1083 uint32_t *p_raster_start;
1091 if (tw == 0 || th == 0)
1098 &flip, &p_raster_start, &toskew, &y,
true,
1099 tw,
"gtTileContig"))
1115 leftmost_fromskew = (int32_t)((uint32_t)img->
col_offset % tw);
1116 leftmost_tw = (uint32_t)((int32_t)tw - leftmost_fromskew);
1117 int64_t skew_i64 = (int64_t)toskew + (int64_t)(int32_t)leftmost_fromskew;
1118 if (skew_i64 > INT_MAX || skew_i64 < INT_MIN)
1124 leftmost_toskew = (int32_t)skew_i64;
1126 (uint64_t)(uint32_t)leftmost_fromskew *
1132 int ycbcr_subsampled = 0;
1133 uint16_t ycbcr_ss_h = 1, ycbcr_ss_v = 1;
1134 uint32_t ycbcr_bpr = 0;
1135 uint32_t ycbcr_bsz = 0;
1140 if (ycbcr_ss_h == 0 || ycbcr_ss_v == 0)
1143 "Invalid YCbCr subsampling (%d, %d)", (
int)ycbcr_ss_h,
1147 if (ycbcr_ss_h > 1 || ycbcr_ss_v > 1)
1149 ycbcr_subsampled = 1;
1151 ycbcr_bsz = (uint32_t)ycbcr_ss_h * ycbcr_ss_v + 2;
1154 if (((uint32_t)img->
col_offset % ycbcr_ss_h) != 0)
1157 "gtTileContig: column offset %d does not align "
1158 "to the YCbCr subsampling block",
1165 for (row = 0; ret != 0 && row < hcpy; row += nrow)
1167 rowstoread = th - ((uint32_t)row + (uint32_t)img->
row_offset) % th;
1168 nrow = row + rowstoread > hcpy ? hcpy - row : rowstoread;
1169 fromskew = leftmost_fromskew;
1170 this_tw = leftmost_tw;
1171 this_toskew = leftmost_toskew;
1175 while (tocol < wcpy)
1190 const uint32_t trow =
1191 ((uint32_t)row + (uint32_t)img->
row_offset) % th;
1193 if (ycbcr_subsampled)
1195 pos64 = (uint64_t)(trow / ycbcr_ss_v) * ycbcr_bpr * ycbcr_bsz +
1196 (uint64_t)((uint32_t)fromskew / ycbcr_ss_h) * ycbcr_bsz;
1206 pos64 = (uint64_t)trow * (uint64_t)trowsize +
1211 if (pos64 >= (uint64_t)bufsize)
1214 "gtTileContig: tile offset out of range");
1219 if (tocol + this_tw > wcpy)
1224 fromskew = (int32_t)(tw - (wcpy - tocol));
1225 this_tw = (uint32_t)((int32_t)tw - fromskew);
1226 this_toskew = (int32_t)(toskew + (int32_t)(uint32_t)fromskew);
1229 (*put)(img, p_raster_start + roffset, tocol, y, this_tw, nrow,
1230 fromskew, this_toskew, buf + pos);
1239 this_toskew = toskew;
1251 for (line = 0; line < hcpy; line++)
1253 uint32_t *left = p_raster_start + (size_t)line * rwidth;
1256 uint32_t *right = left + wcpy - 1;
1258 while (left < right)
1260 uint32_t temp = *left;
1307 uint32_t col, row, y, rowstoread;
1310 unsigned char *buf = NULL;
1311 unsigned char *p0 = NULL;
1312 unsigned char *p1 = NULL;
1313 unsigned char *p2 = NULL;
1314 unsigned char *pa = NULL;
1317 int32_t fromskew, toskew;
1318 int alpha = img->
alpha;
1321 uint16_t colorchannels;
1322 uint32_t this_tw, tocol;
1323 int32_t this_toskew, leftmost_toskew;
1324 int32_t leftmost_fromskew;
1325 uint32_t leftmost_tw;
1329 uint32_t *p_raster_start;
1337 if (tw == 0 || th == 0)
1344 &flip, &p_raster_start, &toskew, &y,
true,
1345 tw,
"gtTileSeparate"))
1372 leftmost_fromskew = (int32_t)((uint32_t)img->
col_offset % tw);
1373 leftmost_tw = (uint32_t)((int32_t)tw - leftmost_fromskew);
1374 int64_t skew_i64 = (int64_t)toskew + (int64_t)(int32_t)leftmost_fromskew;
1375 if (skew_i64 > INT_MAX || skew_i64 < INT_MIN)
1381 leftmost_toskew = (int32_t)skew_i64;
1383 (uint64_t)(uint32_t)leftmost_fromskew *
1386 for (row = 0; ret != 0 && row < hcpy; row += nrow)
1388 rowstoread = th - ((uint32_t)row + (uint32_t)img->
row_offset) % th;
1389 nrow = row + rowstoread > hcpy ? hcpy - row : rowstoread;
1390 fromskew = leftmost_fromskew;
1391 this_tw = leftmost_tw;
1392 this_toskew = leftmost_toskew;
1396 while (tocol < wcpy)
1401 tif, (
void **)&buf, bufsize, col,
1402 (uint32_t)((int32_t)row + img->
row_offset), 0,
1410 if (colorchannels == 1)
1413 pa = (alpha ? (p0 + 3 * tilesize) : NULL);
1419 pa = (alpha ? (p2 + tilesize) : NULL);
1423 (uint32_t)((int32_t)row + img->
row_offset), 0,
1430 if (colorchannels > 1 &&
1432 (uint32_t)((int32_t)row + img->
row_offset), 0,
1439 if (colorchannels > 1 &&
1441 (uint32_t)((int32_t)row + img->
row_offset), 0,
1450 (uint32_t)((int32_t)row + img->
row_offset), 0,
1451 (uint16_t)colorchannels) == (
tmsize_t)(-1) &&
1463 const uint32_t trow =
1464 (uint32_t)((int32_t)row + img->
row_offset) % th;
1471 const uint64_t pos64 =
1472 (uint64_t)trow * (uint64_t)trowsize +
1474 if (pos64 >= (uint64_t)tilesize)
1477 "gtTileSeparate: tile offset out of range");
1482 if (tocol + this_tw > wcpy)
1487 fromskew = (int32_t)(tw - (wcpy - tocol));
1488 this_tw = (uint32_t)((int32_t)tw - fromskew);
1489 this_toskew = (int32_t)(toskew + (int32_t)(uint32_t)fromskew);
1492 (*put)(img, p_raster_start + roffset, tocol, y, this_tw, nrow,
1493 fromskew, this_toskew, p0 + pos, p1 + pos, p2 + pos,
1494 alpha ? pa + pos : NULL);
1503 this_toskew = toskew;
1514 for (line = 0; line < hcpy; line++)
1516 uint32_t *left = p_raster_start + (size_t)line * rwidth;
1519 uint32_t *right = left + wcpy - 1;
1521 while (left < right)
1523 uint32_t temp = *left;
1579 uint32_t row, y, nrow, nrowsub, rowstoread;
1581 unsigned char *buf = NULL;
1582 uint32_t rowsperstrip;
1583 uint16_t subsamplinghor, subsamplingver;
1587 int32_t fromskew, toskew;
1590 int ycbcr_subsampled = 0;
1591 uint32_t ycbcr_bpr = 0;
1592 uint32_t ycbcr_bsz = 0;
1597 uint32_t *p_raster_start;
1601 &flip, &p_raster_start, &toskew, &y,
false,
1602 0,
"gtStripContig"))
1615 if (subsamplinghor == 0 || subsamplingver == 0)
1621 (subsamplinghor > 1 || subsamplingver > 1))
1623 ycbcr_subsampled = 1;
1625 ycbcr_bsz = (uint32_t)subsamplinghor * subsamplingver + 2;
1628 if (((uint32_t)img->
col_offset % subsamplinghor) != 0)
1631 "gtStripContig: column offset %d does not align to "
1632 "the YCbCr subsampling block",
1641 if (rowsperstrip == 0)
1648 if (wcpy < img->width && (img->
width - wcpy) > (uint32_t)INT32_MAX)
1651 "Too large fromskew value (width=%" PRIu32
")",
1655 fromskew = (int32_t)(wcpy < img->width ? img->
width - wcpy : 0);
1657 for (row = 0; row < hcpy; row += nrow)
1663 rowstoread = rowsperstrip -
1664 (uint32_t)((int32_t)row + img->
row_offset) % rowsperstrip;
1667 nrow = row + rowstoread > hcpy ? hcpy - row : rowstoread;
1669 if ((nrowsub % subsamplingver) != 0)
1670 nrowsub += subsamplingver - nrowsub % subsamplingver;
1675 (uint32_t)((int32_t)row + img->
row_offset) % rowsperstrip + nrowsub;
1677 if (size_to_read <= 0)
1680 "Invalid strip read size in gtStripContig");
1686 (uint32_t)((int32_t)row + img->
row_offset), 0),
1687 (
void **)(&buf), maxstripsize,
1698 const uint32_t row_in_strip =
1699 (uint32_t)((int32_t)row + img->
row_offset) % rowsperstrip;
1701 if (ycbcr_subsampled)
1703 pos64 = (uint64_t)(row_in_strip / subsamplingver) * ycbcr_bpr *
1705 (uint64_t)((uint32_t)img->
col_offset / subsamplinghor) *
1710 pos64 = (uint64_t)row_in_strip * (uint64_t)scanline +
1715 if (pos64 >= (uint64_t)maxstripsize)
1718 "gtStripContig: strip offset out of range");
1725 (*put)(img, p_raster_start + roffset, 0, y, wcpy, nrow, fromskew,
1739 for (line = 0; line < hcpy; line++)
1741 uint32_t *left = p_raster_start + (size_t)line * rwidth;
1744 uint32_t *right = left + wcpy - 1;
1746 while (left < right)
1748 uint32_t temp = *left;
1793 uint32_t rwidth, uint32_t rheight)
1797 unsigned char *buf = NULL;
1798 unsigned char *p0 = NULL, *p1 = NULL, *p2 = NULL, *pa = NULL;
1799 uint32_t row, y, nrow, rowstoread;
1802 uint32_t rowsperstrip, offset_row;
1805 int32_t fromskew, toskew;
1806 int alpha = img->
alpha;
1808 uint16_t colorchannels;
1811 uint32_t *p_raster_start;
1816 &flip, &p_raster_start, &toskew, &y,
false,
1817 0,
"gtStripSeparate"))
1847 if (rowsperstrip == 0)
1854 if (wcpy < img->width && (img->
width - wcpy) > (uint32_t)INT32_MAX)
1857 "Too large fromskew value (width=%" PRIu32
")",
1861 fromskew = (int32_t)(wcpy < img->width ? img->
width - wcpy : 0);
1862 for (row = 0; row < hcpy; row += nrow)
1867 ((uint32_t)((int32_t)row + img->
row_offset) % rowsperstrip);
1868 nrow = row + rowstoread > hcpy ? hcpy - row : rowstoread;
1869 offset_row = (uint32_t)((int32_t)row + img->
row_offset);
1870 temp = (uint32_t)((int32_t)row + img->
row_offset) % rowsperstrip + nrow;
1874 "Integer overflow in gtStripSeparate");
1881 bufsize, temp * scanline) == (
tmsize_t)(-1) &&
1888 if (colorchannels == 1)
1891 pa = (alpha ? (p0 + 3 * stripsize) : NULL);
1895 p1 = p0 + stripsize;
1896 p2 = p1 + stripsize;
1897 pa = (alpha ? (p2 + stripsize) : NULL);
1901 p0, temp * scanline) == (
tmsize_t)(-1) &&
1907 if (colorchannels > 1 &&
1909 temp * scanline) == (
tmsize_t)(-1) &&
1915 if (colorchannels > 1 &&
1917 temp * scanline) == (
tmsize_t)(-1) &&
1927 temp * scanline) == (
tmsize_t)(-1) &&
1939 const uint64_t pos64 =
1940 (uint64_t)((uint32_t)((int32_t)row + img->
row_offset) %
1942 (uint64_t)scanline +
1944 if (pos64 >= (uint64_t)stripsize)
1947 "gtStripSeparate: strip offset out of range");
1953 (*put)(img, p_raster_start + roffset, 0, y, wcpy, nrow, fromskew,
1954 toskew, p0 + pos, p1 + pos, p2 + pos,
1955 (alpha ? (pa + pos) : NULL));
1964 for (line = 0; line < hcpy; line++)
1966 uint32_t *left = p_raster_start + (size_t)line * rwidth;
1969 uint32_t *right = left + wcpy - 1;
1971 while (left < right)
1973 uint32_t temp = *left;
2005#define REPEAT8(op) \
2017#define REPEAT4(op) \
2029#define REPEAT2(op) \
2042#define CASE8(x, op) \
2073#define CASE4(x, op) \
2107#define UNROLL8(w, op1, op2) \
2110 for (_x = w; _x >= 8; _x -= 8) \
2133#define UNROLL4(w, op1, op2) \
2136 for (_x = w; _x >= 4; _x -= 4) \
2159#define UNROLL2(w, op1, op2) \
2162 for (_x = w; _x >= 2; _x -= 2) \
2186#define SKEW(r, g, b, skew) \
2205#define SKEW4(r, g, b, a, skew) \
2220#define A1 (((uint32_t)0xffL) << 24)
2233#define PACK(r, g, b) \
2234 ((uint32_t)(r) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 16) | A1)
2248#define PACK4(r, g, b, a) \
2249 ((uint32_t)(r) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 16) | \
2250 ((uint32_t)(a) << 24))
2261#define DECLAREContigPutFunc(name) \
2262 static void name(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, \
2263 uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, \
2299 uint32_t **PALmap = img->PALmap;
2300 int samplesperpixel = img->samplesperpixel;
2308 for (x = w; x > 0; --x)
2310 *cp++ = PALmap[*pp][0];
2311 pp += samplesperpixel;
2314 pp += fromskewLocal;
2351 uint32_t **PALmap = img->PALmap;
2359 UNROLL2(w, bw = PALmap[*pp++], *cp++ = *bw++);
2398 uint32_t **PALmap = img->PALmap;
2406 UNROLL4(w, bw = PALmap[*pp++], *cp++ = *bw++);
2445 uint32_t **PALmap = img->PALmap;
2453 UNROLL8(w, bw = PALmap[*pp++], *cp++ = *bw++);
2492 int samplesperpixel = img->samplesperpixel;
2493 uint32_t **BWmap = img->BWmap;
2501 for (x = w; x > 0; --x)
2503 *cp++ = BWmap[*pp][0];
2504 pp += samplesperpixel;
2507 pp += fromskewLocal;
2545 int samplesperpixel = img->samplesperpixel;
2546 uint32_t **BWmap = img->BWmap;
2554 for (x = w; x > 0; --x)
2556 *cp++ = BWmap[*pp][0] & ((uint32_t)*(pp + 1) << 24 | ~A1);
2557 pp += samplesperpixel;
2560 pp += fromskewLocal;
2597 int samplesperpixel = img->samplesperpixel;
2598 uint32_t **BWmap = img->BWmap;
2606 uint16_t *wp = (uint16_t *)pp;
2608 for (x = w; x > 0; --x)
2612 *cp++ = BWmap[*wp >> 8][0];
2613 pp += 2 * samplesperpixel;
2614 wp += samplesperpixel;
2617 pp += fromskewLocal;
2654 uint32_t **BWmap = img->BWmap;
2662 UNROLL8(w, bw = BWmap[*pp++], *cp++ = *bw++);
2701 uint32_t **BWmap = img->BWmap;
2709 UNROLL4(w, bw = BWmap[*pp++], *cp++ = *bw++);
2748 uint32_t **BWmap = img->BWmap;
2756 UNROLL2(w, bw = BWmap[*pp++], *cp++ = *bw++);
2795 int samplesperpixel = img->samplesperpixel;
2804 pp += samplesperpixel);
2806 pp += fromskewLocal;
2845 int samplesperpixel = img->samplesperpixel;
2854 pp += samplesperpixel);
2856 pp += fromskewLocal;
2895 int samplesperpixel = img->samplesperpixel;
2901 uint32_t r, g, b, a;
2903 for (x = w; x > 0; --x)
2906 m = img->UaToAa + ((size_t)a << 8);
2910 *cp++ =
PACK4(r, g, b, a);
2911 pp += samplesperpixel;
2914 pp += fromskewLocal;
2951 int samplesperpixel = img->samplesperpixel;
2952 uint16_t *wp = (uint16_t *)pp;
2958 for (x = w; x > 0; --x)
2960 *cp++ =
PACK(img->Bitdepth16To8[wp[0]], img->Bitdepth16To8[wp[1]],
2961 img->Bitdepth16To8[wp[2]]);
2962 wp += samplesperpixel;
2965 wp += fromskewLocal;
3004 int samplesperpixel = img->samplesperpixel;
3005 uint16_t *wp = (uint16_t *)pp;
3011 for (x = w; x > 0; --x)
3013 *cp++ =
PACK4(img->Bitdepth16To8[wp[0]], img->Bitdepth16To8[wp[1]],
3014 img->Bitdepth16To8[wp[2]], img->Bitdepth16To8[wp[3]]);
3015 wp += samplesperpixel;
3018 wp += fromskewLocal;
3057 int samplesperpixel = img->samplesperpixel;
3058 uint16_t *wp = (uint16_t *)pp;
3064 uint32_t r, g, b, a;
3066 for (x = w; x > 0; --x)
3068 a = img->Bitdepth16To8[wp[3]];
3069 m = img->UaToAa + ((size_t)a << 8);
3070 r = m[img->Bitdepth16To8[wp[0]]];
3071 g = m[img->Bitdepth16To8[wp[1]]];
3072 b = m[img->Bitdepth16To8[wp[2]]];
3073 *cp++ =
PACK4(r, g, b, a);
3074 wp += samplesperpixel;
3077 wp += fromskewLocal;
3116 int samplesperpixel = img->samplesperpixel;
3117 uint16_t r, g, b, k;
3126 r = (uint16_t)((k * (uint16_t)(255 - pp[0])) / 255);
3127 g = (uint16_t)((k * (uint16_t)(255 - pp[1])) / 255);
3128 b = (uint16_t)((k * (uint16_t)(255 - pp[2])) / 255);
3129 *cp++ =
PACK(r, g, b); pp += samplesperpixel);
3131 pp += fromskewLocal;
3170 int samplesperpixel = img->samplesperpixel;
3172 unsigned int r, g, b, k;
3179 for (x = w; x > 0; --x)
3182 r = (k * (255U - pp[0])) / 255U;
3183 g = (k * (255U - pp[1])) / 255U;
3184 b = (k * (255U - pp[2])) / 255U;
3185 *cp++ =
PACK(Map[r], Map[g], Map[b]);
3186 pp += samplesperpixel;
3188 pp += fromskewLocal;
3202#define DECLARESepPutFunc(name) \
3203 static void name(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, \
3204 uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, \
3205 unsigned char *r, unsigned char *g, unsigned char *b, \
3253 SKEW(r, g, b, fromskew);
3302 SKEW4(r, g, b, a, fromskew);
3347 unsigned int rv, gv, bv, kv;
3348 for (x = w; x > 0; --x)
3351 rv = (kv * (255U - *r++)) / 255U;
3352 gv = (kv * (255U - *g++)) / 255U;
3353 bv = (kv * (255U - *b++)) / 255U;
3354 *cp++ =
PACK4(rv, gv, bv, 255);
3356 SKEW4(r, g, b, a, fromskew);
3404 uint32_t rv, gv, bv, av;
3406 for (x = w; x > 0; --x)
3409 m = img->UaToAa + ((size_t)av << 8);
3413 *cp++ =
PACK4(rv, gv, bv, av);
3415 SKEW4(r, g, b, a, fromskew);
3458 uint16_t *wr = (uint16_t *)r;
3459 uint16_t *wg = (uint16_t *)g;
3460 uint16_t *wb = (uint16_t *)b;
3466 for (x = 0; x < w; x++)
3467 *cp++ =
PACK(img->Bitdepth16To8[*wr++], img->Bitdepth16To8[*wg++],
3468 img->Bitdepth16To8[*wb++]);
3469 SKEW(wr, wg, wb, fromskew);
3512 uint16_t *wr = (uint16_t *)r;
3513 uint16_t *wg = (uint16_t *)g;
3514 uint16_t *wb = (uint16_t *)b;
3515 uint16_t *wa = (uint16_t *)a;
3520 for (x = 0; x < w; x++)
3521 *cp++ =
PACK4(img->Bitdepth16To8[*wr++], img->Bitdepth16To8[*wg++],
3522 img->Bitdepth16To8[*wb++], img->Bitdepth16To8[*wa++]);
3523 SKEW4(wr, wg, wb, wa, fromskew);
3567 uint16_t *wr = (uint16_t *)r;
3568 uint16_t *wg = (uint16_t *)g;
3569 uint16_t *wb = (uint16_t *)b;
3570 uint16_t *wa = (uint16_t *)a;
3575 uint32_t r2, g2, b2, a2;
3577 for (x = w; x > 0; --x)
3579 a2 = img->Bitdepth16To8[*wa++];
3580 m = img->UaToAa + ((size_t)a2 << 8);
3581 r2 = m[img->Bitdepth16To8[*wr++]];
3582 g2 = m[img->Bitdepth16To8[*wg++]];
3583 b2 = m[img->Bitdepth16To8[*wb++]];
3584 *cp++ =
PACK4(r2, g2, b2, a2);
3586 SKEW4(wr, wg, wb, wa, fromskew);
3630 for (x = w; x > 0; --x)
3633 (
signed char)pp[1], (
signed char)pp[2], &X, &Y, &Z);
3635 *cp++ =
PACK(r, g, b);
3639 pp += fromskewLocal;
3678 uint16_t *wp = (uint16_t *)pp;
3683 for (x = w; x > 0; --x)
3686 (int16_t)wp[2], &X, &Y, &Z);
3688 *cp++ =
PACK(r, g, b);
3692 wp += fromskewLocal;
3711#define YCbCrtoRGB(dst, Y) \
3714 TIFFYCbCrtoRGB(img->ycbcr, (Y), (int32_t)Cb, (int32_t)Cr, &r, &g, &b); \
3715 dst = PACK(r, g, b); \
3751 uint32_t *cp1 = cp + w + toskew;
3752 uint32_t *cp2 = cp1 + w + toskew;
3753 uint32_t *cp3 = cp2 + w + toskew;
3760 if ((h & 3) == 0 && (w & 3) == 0)
3762 for (; h >= 4; h -= 4)
3767 int32_t Cb = pp[16];
3768 int32_t Cr = pp[17];
3797 pp += fromskewLocal;
3806 int32_t Cb = pp[16];
3807 int32_t Cr = pp[17];
3884 pp += fromskewLocal;
3922 uint32_t *cp1 = cp + w + toskew;
3928 if ((w & 3) == 0 && (h & 1) == 0)
3930 for (; h >= 2; h -= 2)
3953 pp += fromskewLocal;
4018 pp += fromskewLocal;
4101 pp += fromskewLocal;
4143 cp2 = cp + w + toskew;
4149 uint32_t Cb = pp[4];
4150 uint32_t Cr = pp[5];
4162 uint32_t Cb = pp[4];
4163 uint32_t Cr = pp[5];
4172 pp += fromskewLocal;
4180 uint32_t Cb = pp[4];
4181 uint32_t Cr = pp[5];
4191 uint32_t Cb = pp[4];
4192 uint32_t Cr = pp[5];
4262 pp += fromskewLocal;
4304 cp2 = cp + w + toskew;
4310 uint32_t Cb = pp[2];
4311 uint32_t Cr = pp[3];
4320 pp += fromskewLocal;
4328 uint32_t Cb = pp[2];
4329 uint32_t Cr = pp[3];
4386 pp += fromskewLocal;
4434 uint32_t dr, dg, db;
4436 *cp++ =
PACK(dr, dg, db);
4438 SKEW(r, g, b, fromskew);
4456 return (f > (
float)(-0x7FFFFFFF + 128) && f < (
float)0x7FFFFFFF);
4478 static const char module[] = "initYCbCrConversion";
4480 float *luma, *refBlackWhite;
4482 if (img->
ycbcr == NULL)
4487 2 * 256 *
sizeof(
int) + 3 * 256 *
sizeof(int32_t));
4488 if (img->
ycbcr == NULL)
4491 "No space for YCbCr->RGB conversion state");
4502 if (isnan(luma[0]) || isnan(luma[1]) ||
TIFF_FLOAT_EQ(luma[1], 0.0f) ||
4506 "Invalid values for YCbCrCoefficients tag");
4518 "Invalid values for ReferenceBlackWhite tag");
4547 static const char module[] = "initCIELabConversion";
4566 "No space for CIE L*a*b*->RGB conversion state.");
4571 refWhite[1] = 100.0f;
4572 refWhite[0] = whitePoint[0] / whitePoint[1] * refWhite[1];
4574 (1.0f - whitePoint[0] - whitePoint[1]) / whitePoint[1] * refWhite[1];
4578 "Failed to initialize CIE L*a*b*->RGB conversion state.");
4614 int nsamples = 8 / bitspersample;
4623 (
tmsize_t)((size_t)256 *
sizeof(uint32_t *) +
4624 ((size_t)256 * (
size_t)nsamples *
sizeof(uint32_t))));
4625 if (img->
BWmap == NULL)
4628 "No space for B&W mapping table");
4631 p = (uint32_t *)(img->
BWmap + 256);
4632 for (i = 0; i < 256; i++)
4636 switch (bitspersample)
4640 *p++ = PACK(c, c, c);
4704 if (img->
Map == NULL)
4707 "No space for photometric conversion table");
4712 for (x = 0; x <= range; x++)
4717 for (x = 0; x <= range; x++)
4759 if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256)
4785#define CVT(x) ((uint16_t)((x) >> 8))
4815 int nsamples = 8 / bitspersample;
4824 (
tmsize_t)((size_t)256 *
sizeof(uint32_t *) +
4825 ((size_t)256 * (
size_t)nsamples *
sizeof(uint32_t))));
4829 "No space for Palette mapping table");
4832 p = (uint32_t *)(img->
PALmap + 256);
4833 for (i = 0; i < 256; i++)
4838 c = (TIFFRGBValue)x; \
4839 *p++ = PACK(r[c] & 0xff, g[c] & 0xff, b[c] & 0xff);
4840 switch (bitspersample)
4917 "Assuming 8-bit colormap");
5071 uint16_t SubsamplingHor;
5072 uint16_t SubsamplingVer;
5074 &SubsamplingHor, &SubsamplingVer);
5078 if (img->
width < SubsamplingHor ||
5079 img->
height < SubsamplingVer)
5082 "YCbCr subsampling (%u,%u) incompatible "
5083 "with image size %ux%u",
5084 SubsamplingHor, SubsamplingVer,
5088 switch ((SubsamplingHor << 4) | SubsamplingVer)
5128 return ((img->
get != NULL) && (img->
put.
contig != NULL));
5212 switch ((hs << 4) | vs)
5244 static const char module[] = "BuildMapUaToAa";
5247 assert(img->
UaToAa == NULL);
5255 for (na = 0; na < 256; na++)
5257 for (nv = 0; nv < 256; nv++)
5258 *m++ = (uint8_t)((nv * na + 127) / 255);
5277 static const char module[] = "BuildMapBitdepth16To8";
5288 for (n = 0; n < 65536; n++)
5289 *m++ = (uint8_t)((n + 128) / 257);
5313 uint32_t rowsperstrip, rows_to_read;
5318 "Can't use TIFFReadRGBAStrip() with tiled file.");
5324 if (rowsperstrip == 0)
5330 if ((row % rowsperstrip) != 0)
5334 "Row passed to TIFFReadRGBAStrip() must be first in a strip.");
5343 "Invalid row passed to TIFFReadRGBAStrip().");
5351 if (row + rowsperstrip > img.
height)
5352 rows_to_read = img.
height - row;
5354 rows_to_read = rowsperstrip;
5387 uint32_t tile_xsize, tile_ysize;
5388 uint32_t read_xsize, read_ysize;
5399 "Can't use TIFFReadRGBATile() with striped file.");
5405 if (tile_xsize == 0 || tile_ysize == 0)
5408 "tile_xsize or tile_ysize is zero");
5412 if ((col % tile_xsize) != 0 || (row % tile_ysize) != 0)
5415 "Row/col passed to TIFFReadRGBATile() must be top"
5416 "left corner of a tile.");
5433 "Invalid row/col passed to TIFFReadRGBATile().");
5445 if (row + tile_ysize > img.
height)
5446 read_ysize = img.
height - row;
5448 read_ysize = tile_ysize;
5450 if (col + tile_xsize > img.
width)
5451 read_xsize = img.
width - col;
5453 read_xsize = tile_xsize;
5474 if (read_xsize == tile_xsize && read_ysize == tile_ysize)
5477 for (i_row = 0; i_row < read_ysize; i_row++)
5479 memmove(raster + (
size_t)(tile_ysize - i_row - 1) * tile_xsize,
5480 raster + (
size_t)(read_ysize - i_row - 1) * read_xsize,
5481 read_xsize *
sizeof(uint32_t));
5483 raster + (
size_t)(tile_ysize - i_row - 1) * tile_xsize + read_xsize,
5485 (
tmsize_t)(
sizeof(uint32_t) * (
size_t)(tile_xsize - read_xsize)));
5488 for (i_row = read_ysize; i_row < tile_ysize; i_row++)
5490 _TIFFmemset(raster + (
size_t)(tile_ysize - i_row - 1) * tile_xsize, 0,
5491 (
tmsize_t)(
sizeof(uint32_t) * (
size_t)tile_xsize));
tmsize_t _TIFFMultiplySSize(TIFF *tif, tmsize_t first, tmsize_t second, const char *where)
Check and multiply two signed-size operands.
void TIFFCIELab16ToXYZ(TIFFCIELabToRGB *cielab, uint32_t l, int32_t a, int32_t b, float *X, float *Y, float *Z)
Convert 16-bit TIFF CIE L*a*b* samples to XYZ.
tmsize_t _TIFFReadEncodedStripAndAllocBuffer(TIFF *tif, uint32_t strip, void **buf, tmsize_t bufsizetoalloc, tmsize_t size_to_read)
Decode after deferred allocation of caller-owned output storage.
tmsize_t _TIFFReadTileAndAllocBuffer(TIFF *tif, void **buf, tmsize_t bufsizetoalloc, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
Decode after deferred allocation of caller-owned output storage.
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
Allocate uninitialised bytes under a handle's allocation policy.
#define FLIP_VERTICALLY
Select reversed raster row order.
static int gtTileContig(TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
Read contiguous tiles into a clipped RGBA raster.
static int checkColOffsetByteAligned(TIFFRGBAImage *img, const char *module, uint64_t bitoffset)
Reject a packed-sample offset between byte boundaries.
static void putRGBAAcontig8bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack RGBAAcontig8bittile samples into RGBA words.
static void put1bitcmaptile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack 1bitcmaptile samples into RGBA words.
#define EMSG_BUF_SIZE
Reserve 1024 bytes for RGBA rejection messages.
static void putcontig8bitYCbCr12tile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack contig8bitYCbCr12tile samples into RGBA words.
static int isInRefBlackWhiteRange(float f)
Check a reference endpoint against conversion integer bounds.
#define SKEW4(r, g, b, a, skew)
Advance four plane pointers by a source skew.
static void putRGBUAcontig16bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack RGBUAcontig16bittile samples into RGBA words.
static void put16bitbwtile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack 16bitbwtile samples into RGBA words.
static void putgreytile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack greytile samples into RGBA words.
static const TIFFDisplay display_sRGB
Describe the fixed display transform used for Lab output.
static int gtStripSeparate(TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
Read separate-plane strips into a clipped RGBA raster.
#define UNROLL8(w, op1, op2)
Traverse complete eight-pixel groups and their remainder.
static int gtStripContig(TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
Read contiguous strips into a clipped RGBA raster.
static int setupMap(TIFFRGBAImage *img)
Build sample scaling and grayscale unpacking maps.
#define GREY(x)
Append a grayscale-map entry to the expansion table.
static char const *const orientationStrings[]
Map checked orientation numbers to diagnostic labels.
static void put8bitcmaptile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack 8bitcmaptile samples into RGBA words.
static void put1bitbwtile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack 1bitbwtile samples into RGBA words.
static int setorientation(TIFFRGBAImage *img)
Choose horizontal and vertical raster flips.
#define YCbCrtoRGB(dst, Y)
Convert a local YCbCr group and pack an opaque output word.
static int buildMap(TIFFRGBAImage *img)
Build the lookup maps needed by a selected photometric case.
static void putcontig8bitYCbCr44tile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack contig8bitYCbCr44tile samples into RGBA words.
static void putRGBseparate16bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
Pack RGBseparate16bittile samples into RGBA words.
static int PickSeparateCase(TIFFRGBAImage *)
Select separate-plane get/put callbacks for the conversion.
static void putcontig8bitYCbCr21tile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack contig8bitYCbCr21tile samples into RGBA words.
static void putcontig8bitYCbCr42tile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack contig8bitYCbCr42tile samples into RGBA words.
#define NOP
Supply an empty loop operation.
static void putcontig8bitYCbCr22tile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack contig8bitYCbCr22tile samples into RGBA words.
static uint16_t checkedOrientation(uint16_t orientation)
Validate a TIFF orientation number.
static int PickContigCase(TIFFRGBAImage *)
Select contiguous get/put callbacks for the conversion.
#define PACK4(r, g, b, a)
Pack RGB and alpha bytes.
static void putRGBcontig8bitCMYKtile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack RGBcontig8bitCMYKtile samples into RGBA words.
static void put2bitcmaptile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack 2bitcmaptile samples into RGBA words.
#define UNROLL4(w, op1, op2)
Traverse complete four-pixel groups and their remainder.
static int gtTileSeparate(TIFFRGBAImage *, uint32_t *, uint32_t, uint32_t)
Read separate-plane tiles into a clipped RGBA raster.
static void putcontig8bitYCbCr11tile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack contig8bitYCbCr11tile samples into RGBA words.
static tileContigRoutine initCIELabConversion(TIFFRGBAImage *img)
Prepare Lab state and select an 8- or 16-bit packer.
static void putRGBcontig8bitCMYKMaptile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack RGBcontig8bitCMYKMaptile samples into RGBA words.
#define PACK(r, g, b)
Pack RGB bytes with opaque alpha.
#define DECLAREContigPutFunc(name)
Declare the concrete contiguous packer signature.
static void putcontig8bitCIELab8(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack contig8bitCIELab8 samples into RGBA words.
static int isCCITTCompression(TIFF *tif)
Recognise CCITT fax compression schemes.
static void putRGBcontig16bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack RGBcontig16bittile samples into RGBA words.
static void putCMYKseparate8bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
Pack CMYKseparate8bittile samples into RGBA words.
#define SKEW(r, g, b, skew)
Advance three plane pointers by a source skew.
static int calcCopyToRasterParameter(TIFFRGBAImage *img, uint32_t *raster, uint32_t rwidth, uint32_t rheight, uint32_t *pwcpy, uint32_t *phcpy, int *pflip, uint32_t **pp_raster_start, int32_t *ptoskew, uint32_t *py, bool isTiled, uint32_t tilewidth, const char *funcName)
Compute clipped raster placement and signed row steps.
static void putRGBAAseparate16bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
Pack RGBAAseparate16bittile samples into RGBA words.
static int makebwmap(TIFFRGBAImage *img)
Build byte-indexed packed grayscale expansion tables.
static int initYCbCrConversion(TIFFRGBAImage *img)
Allocate and initialise RGBA YCbCr contribution tables.
static void putRGBAAseparate8bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
Pack RGBAAseparate8bittile samples into RGBA words.
static void putagreytile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack agreytile samples into RGBA words.
static int BuildMapUaToAa(TIFFRGBAImage *img)
Build the unassociated-to-associated eight-bit channel map.
static void cvtcmap(TIFFRGBAImage *img)
Reduce all copied palette entries to their high byte.
static void putRGBUAseparate8bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
Pack RGBUAseparate8bittile samples into RGBA words.
#define UNROLL2(w, op1, op2)
Traverse complete two-pixel groups and their remainder.
static int checkcmap(TIFFRGBAImage *img)
Infer whether copied palette entries use eight or sixteen bits.
static void putcontig8bitYCbCr41tile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack contig8bitYCbCr41tile samples into RGBA words.
static void putRGBcontig8bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack RGBcontig8bittile samples into RGBA words.
#define FLIP_HORIZONTALLY
Select reversal within copied raster rows.
static void put4bitbwtile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack 4bitbwtile samples into RGBA words.
static int makecmap(TIFFRGBAImage *img)
Build byte-indexed packed palette expansion tables.
#define DECLARESepPutFunc(name)
Declare the concrete separate-plane packer signature.
#define CMAP(x)
Append a palette-map entry to the expansion table.
static void putcontig8bitCIELab16(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack contig8bitCIELab16 samples into RGBA words.
static void putseparate8bitYCbCr11tile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
Pack separate8bitYCbCr11tile samples into RGBA words.
#define CVT(x)
Reduce a palette entry to its high byte.
static void putRGBUAcontig8bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack RGBUAcontig8bittile samples into RGBA words.
static void putRGBAAcontig16bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack RGBAAcontig16bittile samples into RGBA words.
static int BuildMapBitdepth16To8(TIFFRGBAImage *img)
Build rounded sixteen-to-eight-bit sample reduction.
static void put4bitcmaptile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack 4bitcmaptile samples into RGBA words.
static void putRGBseparate8bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
Pack RGBseparate8bittile samples into RGBA words.
static void put2bitbwtile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Pack 2bitbwtile samples into RGBA words.
static void putRGBUAseparate16bittile(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
Pack RGBUAseparate16bittile samples into RGBA words.
static const char photoTag[]
Name the photometric tag in diagnostic messages.
#define isTiled(tif)
Test whether a handle uses tiled storage.
#define isUpSampled(tif)
Test whether the codec reports upsampled output.
#define TIFFroundup_32(x, y)
Round a 32-bit value up to a multiple using the guarded quotient.
#define TIFF_FLOAT_EQ(x, y)
Test whether a float difference is not greater than zero in magnitude.
#define TIFFmin(A, B)
Select the first operand if it is smaller, otherwise the second.
#define TIFFhowmany_32(x, y)
Compute a guarded 32-bit ceiling quotient.
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW void TIFFCIELabToXYZ(TIFFCIELabToRGB *cielab, uint32_t l, int32_t a, int32_t b, float *X, float *Y, float *Z)
Convert 8-bit TIFF CIE L*a*b* samples to XYZ.
void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *ycbcr, uint32_t Y, int32_t Cb, int32_t Cr, uint32_t *r, uint32_t *g, uint32_t *b)
Convert an 8-bit YCbCr sample triplet to clipped RGB.
int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB *ycbcr, float *luma, float *refBlackWhite)
Initialise caller-allocated 8-bit YCbCr conversion tables.
int TIFFCIELabToRGBInit(TIFFCIELabToRGB *cielab, const TIFFDisplay *display, float *refWhite)
Initialise caller-owned CIE Lab conversion tables and reference white.
void TIFFXYZToRGB(TIFFCIELabToRGB *cielab, float X, float Y, float Z, uint32_t *r, uint32_t *g, uint32_t *b)
Convert XYZ tristimulus values to display RGB channels.
unsigned char TIFFRGBValue
Represent an 8-bit RGB channel value.
void TIFFWarningExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a warning diagnostic to the configured handlers.
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
tmsize_t TIFFTileSize(TIFF *tif)
Compute the decoded-size estimate for the configured tile height.
tmsize_t TIFFStripSize(TIFF *tif)
Compute the decoded-size estimate for a nominal strip.
tmsize_t TIFFScanlineSize(TIFF *tif)
Compute the current scanline I/O byte estimate.
tmsize_t TIFFVStripSize(TIFF *tif, uint32_t nrows)
Compute the decoded-size estimate for a requested strip height.
tmsize_t TIFFTileRowSize(TIFF *tif)
Compute the packed byte count of one tile row.
uint32_t TIFFComputeStrip(TIFF *tif, uint32_t row, uint16_t sample)
Compute a strip index from a row and optional sample plane.
tmsize_t TIFFReadEncodedStrip(TIFF *tif, uint32_t strip, void *buf, tmsize_t size)
Read decoded samples from one strip.
tmsize_t TIFFReadTile(TIFF *tif, void *buf, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
Decode the tile containing image coordinates.
const char * TIFFFileName(TIFF *tif)
Return the handle's diagnostic filename.
int TIFFIsTiled(TIFF *tif)
Test whether the current image uses tiles.
void _TIFFmemset(void *p, int v, tmsize_t c)
Fill a byte range with one repeated byte.
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
void(* tileSeparateRoutine)(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
Convert a decoded separate-plane region through a caller-selectable packer.
void(* tileContigRoutine)(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, unsigned char *pp)
Convert a decoded contiguous region through a caller-selectable packer.
int TIFFReadRGBAImage(TIFF *tif, uint32_t rwidth, uint32_t rheight, uint32_t *raster, int stop)
Read the current image into a packed RGBA raster.
int TIFFReadRGBAStrip(TIFF *tif, uint32_t row, uint32_t *raster)
Read and convert one whole strip to packed RGBA.
int TIFFReadRGBATile(TIFF *tif, uint32_t col, uint32_t row, uint32_t *raster)
Read and convert one whole tile to packed RGBA.
int TIFFRGBAImageBegin(TIFFRGBAImage *img, TIFF *tif, int stop, char emsg[1024])
Initialise an RGBA reader and select conversion methods.
void TIFFRGBAImageEnd(TIFFRGBAImage *img)
Release RGBA conversion tables and copied colormaps.
int TIFFReadRGBAStripExt(TIFF *tif, uint32_t row, uint32_t *raster, int stop_on_error)
Read and convert one whole strip to packed RGBA.
int TIFFReadRGBATileExt(TIFF *tif, uint32_t col, uint32_t row, uint32_t *raster, int stop_on_error)
Read and convert one whole tile to packed RGBA.
int TIFFRGBAImageOK(TIFF *tif, char emsg[1024])
Check preliminary RGBA compatibility of the current directory.
int TIFFReadRGBAImageOriented(TIFF *tif, uint32_t rwidth, uint32_t rheight, uint32_t *raster, int orientation, int stop)
Read the current image into a packed RGBA raster.
int TIFFRGBAImageGet(TIFFRGBAImage *img, uint32_t *raster, uint32_t rwidth, uint32_t rheight)
Read and convert a selected image area through installed callbacks.
int TIFFSetField(TIFF *tif, uint32_t tag,...)
Set a tag value in the current in-memory directory.
int TIFFGetFieldDefaulted(TIFF *tif, uint32_t tag,...)
Query a present tag or a supported default.
int TIFFGetField(TIFF *tif, uint32_t tag,...)
Query a present tag in the current directory.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
#define TIFF_TMSIZE_T_MAX
Define the largest positive size representable by tmsize_t.
Hold CIE L*a*b*-to-RGB conversion parameters and tables.
Store the current directory values and image traversal state.
uint16_t td_compression
COMPRESSION_* codec identifier.
uint16_t td_extrasamples
Number of extra samples described by td_sampleinfo.
uint16_t td_bitspersample
Bits in each sample.
uint32_t td_colormap_count
Number of entries in each ColorMap plane that the directory uses, zero when none is installed.
uint16_t td_planarconfig
PLANARCONFIG_* sample-plane arrangement.
uint16_t td_sampleformat
SAMPLEFORMAT_* interpretation of samples.
uint16_t td_samplesperpixel
Samples per pixel, including extra samples.
Describe the matrix, luminance, and gamma of an RGB display.
Hold lookup-table pointers for 8-bit YCbCr-to-RGB conversion.
Hold the state and selected callbacks for an RGBA image reader.
uint32_t ** PALmap
Reader-owned palette expansion tables, or NULL.
int col_offset
Nonnegative starting source column, measured in pixels.
uint16_t req_orientation
Requested output raster orientation.
uint16_t * bluecmap
Reader-owned blue palette copy, or NULL.
uint16_t photometric
Source PhotometricInterpretation tag value.
TIFF * tif
Borrowed TIFF handle; must outlive this reader state.
tileContigRoutine contig
Put callback for contiguous source samples.
uint16_t * greencmap
Reader-owned green palette copy, or NULL.
uint16_t samplesperpixel
Source samples per pixel.
uint8_t * UaToAa
Reader-owned unassociated-to-associated alpha lookup table, or NULL.
union _TIFFRGBAImage::@3 put
Select the RGBA packer signature matching the image organisation.
TIFFCIELabToRGB * cielab
Reader-owned CIE L*a*b* conversion state, or NULL.
uint16_t bitspersample
Source bits per sample.
int alpha
ExtraSamples alpha interpretation, or zero when none is selected.
uint32_t height
Source image height in pixels.
uint16_t orientation
Source Orientation tag value.
uint16_t * redcmap
Reader-owned red palette copy, or NULL.
uint32_t width
Source image width in pixels.
void(* any)(TIFFRGBAImage *img)
Reserve a generic storage view of the selected packer.
uint8_t * Bitdepth16To8
Reader-owned 16-bit-to-8-bit sample lookup table, or NULL.
uint32_t ** BWmap
Reader-owned black/white expansion tables, or NULL.
TIFFRGBValue * Map
Reader-owned sample mapping table, or NULL.
int isContig
Nonzero for contiguous samples; zero for separate sample planes.
int row_offset
Nonnegative starting source row, measured in pixels.
TIFFYCbCrToRGB * ycbcr
Reader-owned YCbCr conversion block, or NULL.
int stoponerr
Nonzero to stop reading when an error is encountered.
int(* get)(TIFFRGBAImage *img, uint32_t *raster, uint32_t rwidth, uint32_t rheight)
Read and pack a raster through the selected RGBA state.
tileSeparateRoutine separate
Put callback for separate source planes.
Hold private state for one open TIFF library instance.
TIFFDirectory tif_dir
Inline representation of the current image directory.
int tif_decodestatus
Nonzero unless the selected scheme is a known but unconfigured codec; not a setup result.
Declare private library state, callbacks, and implementation helpers.