169#define SETJMP(jbuf) setjmp(jbuf)
184#define LONGJMP(jbuf, code) longjmp(jbuf, code)
192#define JMP_BUF jmp_buf
201#define OJPEG_BUFFER 2048
212#define JPEG_MARKER_SOF0 0xC0
220#define JPEG_MARKER_SOF1 0xC1
228#define JPEG_MARKER_SOF3 0xC3
237#define JPEG_MARKER_DHT 0xC4
245#define JPEG_MARKER_RST0 0XD0
253#define JPEG_MARKER_SOI 0xD8
260#define JPEG_MARKER_EOI 0xD9
268#define JPEG_MARKER_SOS 0xDA
277#define JPEG_MARKER_DQT 0xDB
285#define JPEG_MARKER_DRI 0xDD
293#define JPEG_MARKER_APP0 0xE0
301#define JPEG_MARKER_COM 0xFE
310#define FIELD_OJPEG_JPEGINTERCHANGEFORMAT (FIELD_CODEC + 0)
319#define FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH (FIELD_CODEC + 1)
327#define FIELD_OJPEG_JPEGQTABLES (FIELD_CODEC + 2)
335#define FIELD_OJPEG_JPEGDCTABLES (FIELD_CODEC + 3)
343#define FIELD_OJPEG_JPEGACTABLES (FIELD_CODEC + 4)
351#define FIELD_OJPEG_JPEGPROC (FIELD_CODEC + 5)
359#define FIELD_OJPEG_JPEGRESTARTINTERVAL (FIELD_CODEC + 6)
374 "JpegInterchangeFormatLength", NULL},
377 "JpegQTables", NULL},
380 "JpegDcTables", NULL},
383 "JpegAcTables", NULL},
391#ifndef LIBJPEG_ENCAP_EXTERNAL
520#ifndef LIBJPEG_ENCAP_EXTERNAL
573 uint64_t qtable_offset[3];
575 uint64_t dctable_offset[3];
577 uint64_t actable_offset[3];
683 uint32_t in_buffer_next_strile;
687 uint64_t in_buffer_file_pos;
691 uint64_t in_buffer_file_togo;
764#ifdef LIBJPEG_ENCAP_EXTERNAL
804 uint8_t require_image);
845 void *scanlines, uint32_t max_lines);
869 void *data, uint32_t max_lines);
923 uint8_t require_image);
964 void *scanlines, uint32_t max_lines);
988 void *data, uint32_t max_lines);
1022 static const char module[] = "TIFFInitOJPEG";
1034 "Merging Old JPEG codec-specific tags failed");
1042 TIFFErrorExtR(tif, module,
"No space for OJPEG state block");
1048 sp->subsampling_hor = 2;
1049 sp->subsampling_ver = 2;
1114 *va_arg(ap, uint64_t *) =
1125 *va_arg(ap,
const void **) = (
const void *)sp->
qtable_offset;
1136 *va_arg(ap, uint16_t *) = (uint16_t)sp->
jpeg_proc;
1171 static const char module[] = "OJPEGVSetField";
1181 sp->jpeg_interchange_format = (uint64_t)va_arg(ap, uint64_t);
1184 sp->jpeg_interchange_format_length = (uint64_t)va_arg(ap, uint64_t);
1187 sp->subsampling_tag = 1;
1188 sp->subsampling_hor = (uint8_t)va_arg(ap,
uint16_vap);
1189 sp->subsampling_ver = (uint8_t)va_arg(ap,
uint16_vap);
1194 ma = (uint32_t)va_arg(ap, uint32_t);
1200 "JpegQTables tag has incorrect count");
1203 sp->qtable_offset_count = (uint8_t)ma;
1204 mb = (uint64_t *)va_arg(ap, uint64_t *);
1205 for (n = 0; n < ma; n++)
1206 sp->qtable_offset[n] = mb[n];
1210 ma = (uint32_t)va_arg(ap, uint32_t);
1216 "JpegDcTables tag has incorrect count");
1219 sp->dctable_offset_count = (uint8_t)ma;
1220 mb = (uint64_t *)va_arg(ap, uint64_t *);
1221 for (n = 0; n < ma; n++)
1222 sp->dctable_offset[n] = mb[n];
1226 ma = (uint32_t)va_arg(ap, uint32_t);
1232 "JpegAcTables tag has incorrect count");
1235 sp->actable_offset_count = (uint8_t)ma;
1236 mb = (uint64_t *)va_arg(ap, uint64_t *);
1237 for (n = 0; n < ma; n++)
1238 sp->actable_offset[n] = mb[n];
1242 sp->jpeg_proc = (uint8_t)va_arg(ap,
uint16_vap);
1245 sp->restart_interval = (uint16_t)va_arg(ap,
uint16_vap);
1248 return (*sp->vsetparent)(tif, tag, ap);
1277 fprintf(fd,
" JpegInterchangeFormat: %" PRIu64
"\n",
1280 fprintf(fd,
" JpegInterchangeFormatLength: %" PRIu64
"\n",
1284 fprintf(fd,
" JpegQTables:");
1291 fprintf(fd,
" JpegDcTables:");
1298 fprintf(fd,
" JpegAcTables:");
1304 fprintf(fd,
" JpegProc: %" PRIu8
"\n", sp->
jpeg_proc);
1306 fprintf(fd,
" JpegRestartInterval: %" PRIu16
"\n",
1340 static const char module[] = "OJPEGSetupDecode";
1342 "Deprecated and troublesome old-style JPEG compression "
1343 "mode, please convert to new-style JPEG compression and "
1344 "notify vendor of writing software");
1504 static const char module[] = "OJPEGPreDecodeSkipScanlines";
1507 if (sp->skip_buffer == NULL)
1509 sp->skip_buffer = (uint8_t *)
_TIFFmallocExt(tif, sp->bytes_per_line);
1510 if (sp->skip_buffer == NULL)
1516 for (m = 0; m < sp->lines_per_strile; m++)
1519 &sp->skip_buffer, 1) == 0)
1548 static const char module[] = "OJPEGDecode";
1551 if (!sp->decoder_ok)
1553 memset(buf, 0, (
size_t)cc);
1555 "Cannot decode: decoder not correctly initialized");
1558 if (sp->libjpeg_session_active == 0)
1560 memset(buf, 0, (
size_t)cc);
1569 "Cannot decode: libjpeg_session_active == 0");
1572 if (sp->error_in_raw_data_decoding)
1574 memset(buf, 0, (
size_t)cc);
1577 if (sp->libjpeg_jpeg_query_style == 0)
1581 memset(buf, 0, (
size_t)cc);
1589 memset(buf, 0, (
size_t)cc);
1618 static const char module[] = "OJPEGDecodeRaw";
1629 if (cc % sp->bytes_per_line != 0)
1640 if (sp->subsampling_convert_state == 0)
1643 sp, &(sp->libjpeg_jpeg_decompress_struct),
1644 sp->subsampling_convert_ycbcrimage,
1645 (uint32_t)sp->subsampling_ver * 8) == 0)
1647 sp->error_in_raw_data_decoding = 1;
1651 oy = sp->subsampling_convert_ybuf +
1652 sp->subsampling_convert_state * sp->subsampling_ver *
1653 sp->subsampling_convert_ylinelen;
1654 ocb = sp->subsampling_convert_cbbuf +
1655 sp->subsampling_convert_state * sp->subsampling_convert_clinelen;
1656 ocr = sp->subsampling_convert_crbuf +
1657 sp->subsampling_convert_state * sp->subsampling_convert_clinelen;
1659 for (q = 0; q < sp->subsampling_convert_clinelenout; q++)
1662 for (sy = 0; sy < sp->subsampling_ver; sy++)
1664 for (sx = 0; sx < sp->subsampling_hor; sx++)
1666 r += sp->subsampling_convert_ylinelen - sp->subsampling_hor;
1668 oy += sp->subsampling_hor;
1672 sp->subsampling_convert_state++;
1673 if (sp->subsampling_convert_state == sp->subsampling_convert_clines)
1674 sp->subsampling_convert_state = 0;
1675 m += sp->bytes_per_line;
1676 n -= sp->bytes_per_line;
1703 static const char module[] = "OJPEGDecodeScanlines";
1707 if (cc % sp->bytes_per_line != 0)
1721 m += sp->bytes_per_line;
1722 n -= sp->bytes_per_line;
1776 static const char module[] = "OJPEGSetupEncode";
1779 "OJPEG encoding not supported; use new-style JPEG compression instead");
1795 static const char module[] = "OJPEGPreEncode";
1799 "OJPEG encoding not supported; use new-style JPEG compression instead");
1817 static const char module[] = "OJPEGEncode";
1823 "OJPEG encoding not supported; use new-style JPEG compression instead");
1838 static const char module[] = "OJPEGPostEncode";
1841 "OJPEG encoding not supported; use new-style JPEG compression instead");
1934 static const char module[] = "OJPEGSubsamplingCorrect";
1939 assert(sp->subsamplingcorrect_done == 0);
1944 if (sp->subsampling_tag != 0)
1946 "Subsampling tag not appropriate for this "
1947 "Photometric and/or SamplesPerPixel");
1948 sp->subsampling_hor = 1;
1949 sp->subsampling_ver = 1;
1950 sp->subsampling_force_desubsampling_inside_decompression = 0;
1954 sp->subsamplingcorrect_done = 1;
1955 mh = sp->subsampling_hor;
1956 mv = sp->subsampling_ver;
1957 sp->subsamplingcorrect = 1;
1959 if (sp->subsampling_force_desubsampling_inside_decompression != 0)
1961 sp->subsampling_hor = 1;
1962 sp->subsampling_ver = 1;
1964 sp->subsamplingcorrect = 0;
1965 if (((sp->subsampling_hor != mh) || (sp->subsampling_ver != mv)) &&
1966 (sp->subsampling_force_desubsampling_inside_decompression == 0))
1968 if (sp->subsampling_tag == 0)
1971 "Subsampling tag is not set, yet subsampling inside JPEG "
1972 "data [%" PRIu8
",%" PRIu8
1973 "] does not match default values [2,2]; assuming "
1974 "subsampling inside JPEG data is correct",
1975 sp->subsampling_hor, sp->subsampling_ver);
1979 "Subsampling inside JPEG data [%" PRIu8
",%" PRIu8
1980 "] does not match subsampling tag values [%" PRIu8
1982 "]; assuming subsampling inside JPEG data is correct",
1983 sp->subsampling_hor, sp->subsampling_ver, mh, mv);
1985 if (sp->subsampling_force_desubsampling_inside_decompression != 0)
1987 if (sp->subsampling_tag == 0)
1990 "Subsampling tag is not set, yet subsampling inside JPEG "
1991 "data does not match default values [2,2] (nor any other "
1992 "values allowed in TIFF); assuming subsampling inside JPEG "
1993 "data is correct and desubsampling inside JPEG "
1998 "Subsampling inside JPEG data does not match subsampling "
1999 "tag values [%" PRIu8
",%" PRIu8
2000 "] (nor any other values allowed in TIFF); assuming "
2001 "subsampling inside JPEG data is correct and desubsampling "
2002 "inside JPEG decompression",
2005 if (sp->subsampling_force_desubsampling_inside_decompression == 0)
2007 if (sp->subsampling_hor < sp->subsampling_ver)
2009 "Subsampling values [%" PRIu8
",%" PRIu8
2010 "] are not allowed in TIFF",
2011 sp->subsampling_hor, sp->subsampling_ver);
2014 sp->subsamplingcorrect_done = 1;
2039 static const char module[] = "OJPEGReadHeaderInfo";
2041 assert(sp->readheader_done == 0);
2048 sp->strile_length_total =
2049 ((sp->image_length + sp->strile_length - 1) / sp->strile_length) *
2054 sp->strile_width = sp->image_width;
2056 if (sp->strile_length == (uint32_t)-1)
2057 sp->strile_length = sp->image_length;
2058 sp->strile_length_total = sp->image_length;
2062 sp->samples_per_pixel = 1;
2063 sp->plane_sample_offset = 0;
2064 sp->samples_per_pixel_per_plane = sp->samples_per_pixel;
2065 sp->subsampling_hor = 1;
2066 sp->subsampling_ver = 1;
2073 "SamplesPerPixel %" PRIu8
2074 " not supported for this compression scheme",
2075 sp->samples_per_pixel);
2078 sp->samples_per_pixel = 3;
2079 sp->plane_sample_offset = 0;
2081 sp->samples_per_pixel_per_plane = 3;
2083 sp->samples_per_pixel_per_plane = 1;
2085 if (sp->strile_length < sp->image_length)
2087 if (((sp->subsampling_hor != 1) && (sp->subsampling_hor != 2) &&
2088 (sp->subsampling_hor != 4)) ||
2089 ((sp->subsampling_ver != 1) && (sp->subsampling_ver != 2) &&
2090 (sp->subsampling_ver != 4)))
2095 if (sp->strile_length % ((uint32_t)sp->subsampling_ver * 8) != 0)
2098 "Incompatible vertical subsampling and image "
2099 "strip/tile length");
2104 uint32_t mcu_width = (uint32_t)sp->subsampling_hor * 8;
2105 uint32_t mcu_height = (uint32_t)sp->subsampling_ver * 8;
2108 uint32_t mcu_rows = sp->strile_length / mcu_height;
2109 if (mcu_cols == 0 || mcu_rows == 0)
2111 sp->restart_interval = 0;
2115 uint32_t restart_interval =
2117 if (restart_interval == 0 || restart_interval > UINT16_MAX)
2120 "Integer overflow in restart interval");
2123 sp->restart_interval = (uint16_t)restart_interval;
2129 sp->sos_end[0].log = 1;
2130 sp->sos_end[0].in_buffer_source = sp->in_buffer_source;
2131 sp->sos_end[0].in_buffer_next_strile = sp->in_buffer_next_strile;
2132 sp->sos_end[0].in_buffer_file_pos =
2133 sp->in_buffer_file_pos - sp->in_buffer_togo;
2134 sp->sos_end[0].in_buffer_file_togo =
2135 sp->in_buffer_file_togo + sp->in_buffer_togo;
2136 sp->readheader_done = 1;
2233 static const char module[] = "OJPEGWriteHeaderInfo";
2238 if (sp->libjpeg_session_active != 0)
2241 sp->restart_index = 0;
2242 jpeg_std_error(&(sp->libjpeg_jpeg_error_mgr));
2243 sp->libjpeg_jpeg_error_mgr.output_message =
2246 sp->libjpeg_jpeg_decompress_struct.err = &(sp->libjpeg_jpeg_error_mgr);
2247 sp->libjpeg_jpeg_decompress_struct.client_data = (
void *)tif;
2249 sp, &(sp->libjpeg_jpeg_decompress_struct)) == 0)
2251 sp->libjpeg_session_active = 1;
2252 sp->libjpeg_jpeg_source_mgr.bytes_in_buffer = 0;
2253 sp->libjpeg_jpeg_source_mgr.init_source =
2255 sp->libjpeg_jpeg_source_mgr.fill_input_buffer =
2257 sp->libjpeg_jpeg_source_mgr.skip_input_data =
2259 sp->libjpeg_jpeg_source_mgr.resync_to_restart =
2261 sp->libjpeg_jpeg_source_mgr.term_source =
2263 sp->libjpeg_jpeg_decompress_struct.src = &(sp->libjpeg_jpeg_source_mgr);
2267 if ((sp->subsampling_force_desubsampling_inside_decompression == 0) &&
2268 (sp->samples_per_pixel_per_plane > 1))
2270 sp->libjpeg_jpeg_decompress_struct.raw_data_out = 1;
2271#if JPEG_LIB_VERSION >= 70
2272 sp->libjpeg_jpeg_decompress_struct.do_fancy_upsampling =
FALSE;
2274 sp->libjpeg_jpeg_query_style = 0;
2275 if (sp->subsampling_convert_log == 0)
2277 assert(sp->subsampling_convert_ycbcrbuf == 0);
2278 assert(sp->subsampling_convert_ycbcrimage == 0);
2280 if (sp->subsampling_hor == 0 || sp->subsampling_ver == 0)
2285 if (sp->strile_width >
2286 UINT32_MAX - ((uint32_t)sp->subsampling_hor * 8 - 1))
2288 sp->subsampling_convert_ylinelen =
2289 ((sp->strile_width + (uint32_t)sp->subsampling_hor * 8 - 1) /
2290 ((uint32_t)sp->subsampling_hor * 8) *
2291 ((uint32_t)sp->subsampling_hor * 8));
2292 sp->subsampling_convert_ylines = (uint32_t)sp->subsampling_ver * 8;
2293 sp->subsampling_convert_clinelen =
2294 sp->subsampling_convert_ylinelen / sp->subsampling_hor;
2295 sp->subsampling_convert_clines = 8;
2301 uint64_t ybuflen64 =
2302 (uint64_t)sp->subsampling_convert_ylinelen *
2303 sp->subsampling_convert_ylines;
2304 uint64_t cbuflen64 =
2305 (uint64_t)sp->subsampling_convert_clinelen *
2306 sp->subsampling_convert_clines;
2307 uint64_t ycbcrbuflen64 = ybuflen64 + 2 * cbuflen64;
2308 if (ybuflen64 > UINT32_MAX || cbuflen64 > UINT32_MAX ||
2309 ycbcrbuflen64 > UINT32_MAX)
2312 "Integer overflow in OJPEG buffer size");
2315 sp->subsampling_convert_ybuflen = (uint32_t)ybuflen64;
2316 sp->subsampling_convert_cbuflen = (uint32_t)cbuflen64;
2317 sp->subsampling_convert_ycbcrbuflen = (uint32_t)ycbcrbuflen64;
2331 tif, 1, sp->subsampling_convert_ycbcrbuflen);
2332 if (sp->subsampling_convert_ycbcrbuf == 0)
2337 sp->subsampling_convert_ybuf = sp->subsampling_convert_ycbcrbuf;
2338 sp->subsampling_convert_cbbuf =
2339 sp->subsampling_convert_ybuf + sp->subsampling_convert_ybuflen;
2340 sp->subsampling_convert_crbuf =
2341 sp->subsampling_convert_cbbuf + sp->subsampling_convert_cbuflen;
2342 sp->subsampling_convert_ycbcrimagelen =
2343 3 + sp->subsampling_convert_ylines +
2344 2 * sp->subsampling_convert_clines;
2346 tif, (
tmsize_t)((size_t)sp->subsampling_convert_ycbcrimagelen *
2347 sizeof(uint8_t *)));
2348 if (sp->subsampling_convert_ycbcrimage == 0)
2353 m = sp->subsampling_convert_ycbcrimage;
2354 *m++ = (uint8_t *)(sp->subsampling_convert_ycbcrimage + 3);
2355 *m++ = (uint8_t *)(sp->subsampling_convert_ycbcrimage + 3 +
2356 sp->subsampling_convert_ylines);
2357 *m++ = (uint8_t *)(sp->subsampling_convert_ycbcrimage + 3 +
2358 sp->subsampling_convert_ylines +
2359 sp->subsampling_convert_clines);
2360 for (n = 0; n < sp->subsampling_convert_ylines; n++)
2361 *m++ = sp->subsampling_convert_ybuf +
2362 n * sp->subsampling_convert_ylinelen;
2363 for (n = 0; n < sp->subsampling_convert_clines; n++)
2364 *m++ = sp->subsampling_convert_cbbuf +
2365 n * sp->subsampling_convert_clinelen;
2366 for (n = 0; n < sp->subsampling_convert_clines; n++)
2367 *m++ = sp->subsampling_convert_crbuf +
2368 n * sp->subsampling_convert_clinelen;
2369 sp->subsampling_convert_clinelenout =
2370 sp->strile_width / sp->subsampling_hor +
2371 ((sp->strile_width % sp->subsampling_hor) != 0 ? 1 : 0);
2372 sp->subsampling_convert_state = 0;
2373 sp->error_in_raw_data_decoding = 0;
2375 const uint64_t bpl =
2376 (uint64_t)sp->subsampling_convert_clinelenout *
2377 ((uint64_t)sp->subsampling_ver * sp->subsampling_hor + 2);
2378 if (bpl > UINT32_MAX)
2380 sp->bytes_per_line = (uint32_t)bpl;
2382 sp->lines_per_strile =
2383 sp->strile_length / sp->subsampling_ver +
2384 ((sp->strile_length % sp->subsampling_ver) != 0 ? 1 : 0);
2385 sp->subsampling_convert_log = 1;
2390 sp->libjpeg_jpeg_decompress_struct.jpeg_color_space = JCS_UNKNOWN;
2391 sp->libjpeg_jpeg_decompress_struct.out_color_space = JCS_UNKNOWN;
2392 sp->libjpeg_jpeg_query_style = 1;
2393 sp->bytes_per_line =
2395 sp->strile_width,
"OJPEGWriteHeaderInfo");
2396 if (sp->bytes_per_line == 0)
2398 sp->lines_per_strile = sp->strile_length;
2401 &(sp->libjpeg_jpeg_decompress_struct)) == 0)
2403 if (sp->libjpeg_jpeg_decompress_struct.image_width != sp->strile_width)
2406 "jpeg_start_decompress() returned image_width = %u, "
2407 "expected %" PRIu32,
2408 sp->libjpeg_jpeg_decompress_struct.image_width,
2412 if (sp->libjpeg_jpeg_decompress_struct.max_h_samp_factor !=
2413 sp->subsampling_hor ||
2414 sp->libjpeg_jpeg_decompress_struct.max_v_samp_factor !=
2415 sp->subsampling_ver)
2418 "jpeg_start_decompress() returned max_h_samp_factor = %d "
2419 "and max_v_samp_factor = %d, expected %" PRIu8
2421 sp->libjpeg_jpeg_decompress_struct.max_h_samp_factor,
2422 sp->libjpeg_jpeg_decompress_struct.max_v_samp_factor,
2423 sp->subsampling_hor, sp->subsampling_ver);
2427 sp->writeheader_done = 1;
2471 static const char module[] = "OJPEGReadHeaderInfoSec";
2476 if (sp->file_size == 0)
2478 if (sp->jpeg_interchange_format != 0)
2480 if (sp->jpeg_interchange_format >= sp->file_size)
2482 sp->jpeg_interchange_format = 0;
2483 sp->jpeg_interchange_format_length = 0;
2487 if ((sp->jpeg_interchange_format_length == 0) ||
2488 (sp->jpeg_interchange_format >
2489 UINT64_MAX - sp->jpeg_interchange_format_length) ||
2490 (sp->jpeg_interchange_format +
2491 sp->jpeg_interchange_format_length >
2493 sp->jpeg_interchange_format_length =
2494 sp->file_size - sp->jpeg_interchange_format;
2498 sp->in_buffer_next_strile = 0;
2500 sp->in_buffer_file_togo = 0;
2501 sp->in_buffer_togo = 0;
2542 if (sp->subsamplingcorrect == 0)
2566 if (sp->subsamplingcorrect != 0)
2570 if (sp->subsamplingcorrect != 0)
2572 assert(sp->plane_sample_offset == 0);
2578 "Unknown marker type %" PRIu8
" in JPEG data", m);
2582 if (sp->subsamplingcorrect)
2584 if (sp->sof_log == 0)
2589 for (o = 0; o < sp->samples_per_pixel; o++)
2590 sp->sof_c[o] = (uint8_t)o;
2592 (uint8_t)((sp->subsampling_hor << 4) | sp->subsampling_ver);
2593 for (o = 1; o < sp->samples_per_pixel; o++)
2595 sp->sof_x = sp->strile_width;
2596 sp->sof_y = sp->strile_length_total;
2602 for (o = 1; o < sp->samples_per_pixel; o++)
2625 static const char module[] = "OJPEGReadHeaderInfoSecStreamDri";
2632 TIFFErrorExtR(tif, module,
"Corrupt DRI marker in JPEG data");
2637 sp->restart_interval = m;
2661 static const char module[] = "OJPEGReadHeaderInfoSecStreamDqt";
2671 if (sp->subsamplingcorrect == 0)
2672 TIFFErrorExtR(tif, module,
"Corrupt DQT marker in JPEG data");
2675 if (sp->subsamplingcorrect != 0)
2679 m = (uint16_t)(m - 2);
2684 TIFFErrorExtR(tif, module,
"Corrupt DQT marker in JPEG data");
2687 na =
sizeof(uint32_t) + 69;
2694 *(uint32_t *)nb = na;
2695 nb[
sizeof(uint32_t)] = 255;
2697 nb[
sizeof(uint32_t) + 2] = 0;
2698 nb[
sizeof(uint32_t) + 3] = 67;
2704 o = nb[
sizeof(uint32_t) + 4] & 15;
2707 TIFFErrorExtR(tif, module,
"Corrupt DQT marker in JPEG data");
2711 if (sp->qtable[o] != 0)
2714 m = (uint16_t)(m - 65);
2742 static const char module[] = "OJPEGReadHeaderInfoSecStreamDht";
2752 if (sp->subsamplingcorrect == 0)
2753 TIFFErrorExtR(tif, module,
"Corrupt DHT marker in JPEG data");
2756 if (sp->subsamplingcorrect != 0)
2762 na = (uint32_t)(
sizeof(uint32_t) + 2 + m);
2769 *(uint32_t *)nb = na;
2770 nb[
sizeof(uint32_t)] = 255;
2772 nb[
sizeof(uint32_t) + 2] = (uint8_t)(m >> 8);
2773 nb[
sizeof(uint32_t) + 3] = (uint8_t)(m & 255);
2774 if (
OJPEGReadBlock(sp, (uint16_t)(m - 2), &nb[
sizeof(uint32_t) + 4]) ==
2780 o = nb[
sizeof(uint32_t) + 4];
2785 TIFFErrorExtR(tif, module,
"Corrupt DHT marker in JPEG data");
2789 if (sp->dctable[o] != 0)
2791 sp->dctable[o] = nb;
2795 if ((o & 240) != 16)
2797 TIFFErrorExtR(tif, module,
"Corrupt DHT marker in JPEG data");
2804 TIFFErrorExtR(tif, module,
"Corrupt DHT marker in JPEG data");
2808 if (sp->actable[o] != 0)
2810 sp->actable[o] = nb;
2837 static const char module[] = "OJPEGReadHeaderInfoSecStreamSof";
2844 if (sp->sof_log != 0)
2849 if (sp->subsamplingcorrect == 0)
2850 sp->sof_marker_id = marker_id;
2856 if (sp->subsamplingcorrect == 0)
2857 TIFFErrorExtR(tif, module,
"Corrupt SOF marker in JPEG data");
2860 m = (uint16_t)(m - 8);
2863 if (sp->subsamplingcorrect == 0)
2864 TIFFErrorExtR(tif, module,
"Corrupt SOF marker in JPEG data");
2868 if (sp->subsamplingcorrect == 0)
2870 if (n != sp->samples_per_pixel)
2874 "JPEG compressed data indicates unexpected number of samples");
2883 if (sp->subsamplingcorrect == 0)
2885 "JPEG compressed data indicates unexpected number of "
2890 if (sp->subsamplingcorrect)
2897 if (((uint32_t)p < sp->image_length) &&
2898 ((uint32_t)p < sp->strile_length_total))
2901 "JPEG compressed data indicates unexpected height");
2908 if (((uint32_t)p < sp->image_width) && ((uint32_t)p < sp->strile_width))
2911 "JPEG compressed data indicates unexpected width");
2914 if ((uint32_t)p > sp->strile_width)
2917 "JPEG compressed data image width exceeds expected "
2928 if (sp->subsamplingcorrect == 0)
2929 TIFFErrorExtR(tif, module,
"Corrupt SOF marker in JPEG data");
2935 for (q = 0; q < n; q++)
2940 if (sp->subsamplingcorrect == 0)
2945 if (sp->subsamplingcorrect != 0)
2949 sp->subsampling_hor = (o >> 4);
2950 sp->subsampling_ver = (o & 15);
2951 if (((sp->subsampling_hor != 1) && (sp->subsampling_hor != 2) &&
2952 (sp->subsampling_hor != 4)) ||
2953 ((sp->subsampling_ver != 1) && (sp->subsampling_ver != 2) &&
2954 (sp->subsampling_ver != 4)))
2955 sp->subsampling_force_desubsampling_inside_decompression =
2961 sp->subsampling_force_desubsampling_inside_decompression =
2968 if (sp->subsampling_force_desubsampling_inside_decompression == 0)
2972 if (o != ((sp->subsampling_hor << 4) | sp->subsampling_ver))
2975 "JPEG compressed data indicates "
2976 "unexpected subsampling values");
2985 "JPEG compressed data indicates "
2986 "unexpected subsampling values");
2995 if (sp->subsamplingcorrect == 0)
2998 if (sp->subsamplingcorrect == 0)
3022 static const char module[] = "OJPEGReadHeaderInfoSecStreamSos";
3027 assert(sp->subsamplingcorrect == 0);
3028 if (sp->sof_log == 0)
3030 TIFFErrorExtR(tif, module,
"Corrupt SOS marker in JPEG data");
3036 if (m != 6 + sp->samples_per_pixel_per_plane * 2)
3038 TIFFErrorExtR(tif, module,
"Corrupt SOS marker in JPEG data");
3044 if (n != sp->samples_per_pixel_per_plane)
3046 TIFFErrorExtR(tif, module,
"Corrupt SOS marker in JPEG data");
3050 for (o = 0; o < sp->samples_per_pixel_per_plane; o++)
3055 sp->sos_cs[sp->plane_sample_offset + o] = n;
3059 sp->sos_tda[sp->plane_sample_offset + o] = n;
3086 static const char module[] = "OJPEGReadHeaderInfoSecTablesQTable";
3093 if (sp->qtable_offset[0] == 0)
3098 sp->in_buffer_file_pos_log = 0;
3099 for (m = 0; m < sp->samples_per_pixel; m++)
3101 if ((sp->qtable_offset[m] != 0) &&
3102 ((m == 0) || (sp->qtable_offset[m] != sp->qtable_offset[m - 1])))
3104 for (n = 0; n < m - 1; n++)
3106 if (sp->qtable_offset[m] == sp->qtable_offset[n])
3108 TIFFErrorExtR(tif, module,
"Corrupt JpegQTables tag value");
3112 oa =
sizeof(uint32_t) + 69;
3119 *(uint32_t *)ob = oa;
3120 ob[
sizeof(uint32_t)] = 255;
3122 ob[
sizeof(uint32_t) + 2] = 0;
3123 ob[
sizeof(uint32_t) + 3] = 67;
3124 ob[
sizeof(uint32_t) + 4] = m;
3126 p = (uint32_t)
TIFFReadFile(tif, &ob[
sizeof(uint32_t) + 5], 64);
3132 if (sp->qtable[m] != 0)
3138 sp->sof_tq[m] = sp->sof_tq[m - 1];
3162 static const char module[] = "OJPEGReadHeaderInfoSecTablesDcTable";
3171 if (sp->dctable_offset[0] == 0)
3176 sp->in_buffer_file_pos_log = 0;
3177 for (m = 0; m < sp->samples_per_pixel; m++)
3179 if ((sp->dctable_offset[m] != 0) &&
3180 ((m == 0) || (sp->dctable_offset[m] != sp->dctable_offset[m - 1])))
3182 for (n = 0; n < m - 1; n++)
3184 if (sp->dctable_offset[m] == sp->dctable_offset[n])
3187 "Corrupt JpegDcTables tag value");
3196 for (n = 0; n < 16; n++)
3198 ra = (uint32_t)(
sizeof(uint32_t) + 21 + q);
3205 *(uint32_t *)rb = ra;
3206 rb[
sizeof(uint32_t)] = 255;
3208 rb[
sizeof(uint32_t) + 2] = (uint8_t)((19 + q) >> 8);
3209 rb[
sizeof(uint32_t) + 3] = ((19 + q) & 255);
3210 rb[
sizeof(uint32_t) + 4] = m;
3211 for (n = 0; n < 16; n++)
3212 rb[
sizeof(uint32_t) + 5 + n] = o[n];
3213 p = (uint32_t)
TIFFReadFile(tif, &(rb[
sizeof(uint32_t) + 21]), q);
3219 if (sp->dctable[m] != 0)
3221 sp->dctable[m] = rb;
3222 sp->sos_tda[m] = (uint8_t)(m << 4);
3225 sp->sos_tda[m] = sp->sos_tda[m - 1];
3249 static const char module[] = "OJPEGReadHeaderInfoSecTablesAcTable";
3258 if (sp->actable_offset[0] == 0)
3263 sp->in_buffer_file_pos_log = 0;
3264 for (m = 0; m < sp->samples_per_pixel; m++)
3266 if ((sp->actable_offset[m] != 0) &&
3267 ((m == 0) || (sp->actable_offset[m] != sp->actable_offset[m - 1])))
3269 for (n = 0; n < m - 1; n++)
3271 if (sp->actable_offset[m] == sp->actable_offset[n])
3274 "Corrupt JpegAcTables tag value");
3283 for (n = 0; n < 16; n++)
3285 ra = (uint32_t)(
sizeof(uint32_t) + 21 + q);
3292 *(uint32_t *)rb = ra;
3293 rb[
sizeof(uint32_t)] = 255;
3295 rb[
sizeof(uint32_t) + 2] = (uint8_t)((19 + q) >> 8);
3296 rb[
sizeof(uint32_t) + 3] = ((19 + q) & 255);
3297 rb[
sizeof(uint32_t) + 4] = (16 | m);
3298 for (n = 0; n < 16; n++)
3299 rb[
sizeof(uint32_t) + 5 + n] = o[n];
3300 p = (uint32_t)
TIFFReadFile(tif, &(rb[
sizeof(uint32_t) + 21]), q);
3306 if (sp->actable[m] != 0)
3308 sp->actable[m] = rb;
3309 sp->sos_tda[m] = (sp->sos_tda[m] | m);
3312 sp->sos_tda[m] = (sp->sos_tda[m] | (sp->sos_tda[m - 1] & 15));
3359 assert((uint64_t)n <= sp->in_buffer_file_togo);
3400 else if (bytecount == 0)
3519 *word = (uint16_t)(m << 8);
3548 mmem = (uint8_t *)mem;
3563 mlen = (uint16_t)(mlen - n);
3592 m = (uint16_t)(m - n);
3699 }
while (*len == 0);
3747 if (sp->
qtable[table_index] != 0)
3749 *mem = (
void *)(sp->
qtable[table_index] +
sizeof(uint32_t));
3750 *len = (uint32_t)(*((uint32_t *)sp->
qtable[table_index]) -
3777 if (sp->
dctable[table_index] != 0)
3779 *mem = (
void *)(sp->
dctable[table_index] +
sizeof(uint32_t));
3780 *len = (uint32_t)(*((uint32_t *)sp->
dctable[table_index]) -
3807 if (sp->
actable[table_index] != 0)
3809 *mem = (
void *)(sp->
actable[table_index] +
sizeof(uint32_t));
3810 *len = (uint32_t)(*((uint32_t *)sp->
actable[table_index]) -
4046#ifndef LIBJPEG_ENCAP_EXTERNAL
4054 jpeg_create_decompress(cinfo);
4060#ifndef LIBJPEG_ENCAP_EXTERNAL
4063 uint8_t require_image)
4069 jpeg_read_header(cinfo, require_image);
4075#ifndef LIBJPEG_ENCAP_EXTERNAL
4083 jpeg_start_decompress(cinfo);
4089#ifndef LIBJPEG_ENCAP_EXTERNAL
4092 void *scanlines, uint32_t max_lines)
4098 jpeg_read_scanlines(cinfo, (JSAMPARRAY)scanlines, max_lines);
4104#ifndef LIBJPEG_ENCAP_EXTERNAL
4107 void *data, uint32_t max_lines)
4113 jpeg_read_raw_data(cinfo, (JSAMPIMAGE)data, max_lines);
4119#ifndef LIBJPEG_ENCAP_EXTERNAL
4141 char buffer[JMSG_LENGTH_MAX];
4142 (*cinfo->err->format_message)(cinfo, buffer);
4159 char buffer[JMSG_LENGTH_MAX];
4160 (*cinfo->err->format_message)(cinfo, buffer);
4197 TIFF *tif = (
TIFF *)cinfo->client_data;
4203 TIFFErrorExtR(tif,
"LibJpeg",
"Premature end of JPEG data");
4226 TIFF *tif = (
TIFF *)cinfo->client_data;
4233#pragma warning(push)
4234#pragma warning(disable : 4702)
4253 TIFF *tif = (
TIFF *)cinfo->client_data;
uint32_t _TIFFMultiply32(TIFF *tif, uint32_t first, uint32_t second, const char *where)
Multiply two unsigned values with an overflow check.
void _TIFFSetDefaultCompressionState(TIFF *tif)
Install fallback codec callbacks and reset raw-access flags.
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32_t n)
Merge borrowed field definitions into the lookup table.
#define TIFFFieldSet(tif, field)
Test a directory presence bit.
#define TIFFSetFieldBit(tif, field)
Set a directory presence bit.
@ TIFF_SETGET_UINT64
Unsigned 64-bit scalar storage.
@ TIFF_SETGET_UINT16
Unsigned 16-bit scalar storage.
@ TIFF_SETGET_C32_UINT64
Unsigned 64-bit array with 32-bit explicit count.
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.
void * _TIFFcallocExt(TIFF *tif, tmsize_t nmemb, tmsize_t siz)
Allocate a zero-filled array under a handle's allocation policy.
static int OJPEGSetupDecode(TIFF *tif)
Warn that old-style JPEG compression is deprecated.
#define FIELD_OJPEG_JPEGACTABLES
TIFFField field bit for the codec-private JpegAcTables tag.
#define JPEG_MARKER_SOS
JPEG SOS (start of scan) marker code.
static int OJPEGPreDecode(TIFF *tif, uint16_t s)
Position a reconstructed JPEG session at the requested strile and plane.
static int OJPEGDecodeScanlines(TIFF *tif, uint8_t *buf, tmsize_t cc)
Decode complete ordinary sample rows.
static boolean OJPEGLibjpegJpegSourceMgrFillInputBuffer(tiff_ojpeg_decompress_struct *cinfo)
Supply the next reconstructed JPEG chunk to libjpeg.
struct jpeg_decompress_struct tiff_ojpeg_decompress_struct
Alias for the libjpeg decompressor context structure.
static void OJPEGWriteStreamAcTable(TIFF *tif, uint8_t table_index, void **mem, uint32_t *len)
Produce a AcTable reconstruction chunk.
static void OJPEGLibjpegJpegSourceMgrSkipInputData(tiff_ojpeg_decompress_struct *cinfo, long num_bytes)
Reject an unexpected dependency skip request.
static int OJPEGReadBytePeek(OJPEGState *sp, uint8_t *byte)
Peek at the next buffered byte.
#define LONGJMP(jbuf, code)
Jump back to the frame saved by SETJMP (plain longjmp); never returns.
OJPEGStateOutState
Next item to emit in the reconstructed JPEG stream.
static void OJPEGWriteStreamRst(TIFF *tif, void **mem, uint32_t *len)
Produce a Rst reconstruction chunk.
static int OJPEGSetupEncode(TIFF *tif)
Reject unsupported old-style JPEG encoding.
static void OJPEGWriteStreamSoi(TIFF *tif, void **mem, uint32_t *len)
Produce a Soi reconstruction chunk.
static void OJPEGPostDecode(TIFF *tif, uint8_t *buf, tmsize_t cc)
Advance the cached strile count and end a completed plane session.
static int OJPEGReadHeaderInfoSecTablesAcTable(TIFF *tif)
Build AC Huffman markers from TIFF table-offset tags.
static int OJPEGReadByte(OJPEGState *sp, uint8_t *byte)
Consume one buffered byte.
static int OJPEGFixupTags(TIFF *tif)
Accept the old-style JPEG directory without eager fixups.
static int OJPEGReadBufferFill(OJPEGState *sp)
Refill the old-style JPEG input window across interchange and strile extents.
static int OJPEGReadHeaderInfoSec(TIFF *tif)
Parse a bounded interchange/strile JPEG header or synthesize it from tags.
#define JPEG_MARKER_DQT
JPEG DQT (define quantization table) marker code.
static int OJPEGReadHeaderInfoSecStreamSof(TIFF *tif, uint8_t marker_id)
Validate a JPEG frame and cache its component selectors.
static int OJPEGReadHeaderInfoSecTablesQTable(TIFF *tif)
Build quantisation markers from TIFF table-offset tags.
static void OJPEGLibjpegJpegErrorMgrErrorExit(tiff_ojpeg_common_struct *cinfo)
Report a fatal dependency error and unwind the active wrapper.
static int OJPEGVGetField(TIFF *tif, uint32_t tag, va_list ap)
Retrieve old-style JPEG metadata or delegate to the parent getter.
#define JPEG_MARKER_APP0
JPEG APP0 marker code; APP0..APP15 are this value plus 0..15.
static void OJPEGWriteStreamQTable(TIFF *tif, uint8_t table_index, void **mem, uint32_t *len)
Produce a QTable reconstruction chunk.
#define JPEG_MARKER_SOF1
JPEG SOF1 (extended sequential DCT start-of-frame) marker code.
static void OJPEGLibjpegJpegSourceMgrInitSource(tiff_ojpeg_decompress_struct *cinfo)
Accept the dependency source initialization.
static void OJPEGReadByteAdvance(OJPEGState *sp)
Consume one already buffered byte.
struct jpeg_common_struct tiff_ojpeg_common_struct
Alias for the libjpeg common context structure.
static int OJPEGVSetField(TIFF *tif, uint32_t tag, va_list ap)
Cache old-style JPEG tag values or delegate to the parent setter.
struct jpeg_error_mgr tiff_ojpeg_error_mgr
Alias for the libjpeg error-manager structure.
static int jpeg_start_decompress_encap(OJPEGState *sp, tiff_ojpeg_decompress_struct *cinfo)
Trap dependency fatal errors while attempting to start decompression.
static int jpeg_create_decompress_encap(OJPEGState *sp, tiff_ojpeg_decompress_struct *cinfo)
Trap dependency fatal errors while attempting to create a decompressor.
static int OJPEGReadBlock(OJPEGState *sp, uint16_t len, void *mem)
Copy a positive byte block from the input stream.
static int OJPEGReadHeaderInfoSecStreamDri(TIFF *tif)
Parse and cache a JPEG restart interval.
static void OJPEGWriteStreamSos(TIFF *tif, void **mem, uint32_t *len)
Produce a Sos reconstruction chunk.
#define FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH
TIFFField field bit for the codec-private JpegInterchangeFormatLength tag.
static void OJPEGLibjpegJpegSourceMgrTermSource(tiff_ojpeg_decompress_struct *cinfo)
Accept the dependency source termination.
#define OJPEG_BUFFER
Capacity in bytes of the embedded input and synthetic marker buffers.
static void OJPEGSubsamplingCorrect(TIFF *tif)
Probe and reconcile old-style JPEG subsampling once.
#define JPEG_MARKER_SOI
JPEG SOI (start of image) marker code.
#define FIELD_OJPEG_JPEGPROC
TIFFField field bit for the codec-private JpegProc tag.
static void OJPEGWriteStreamSof(TIFF *tif, void **mem, uint32_t *len)
Produce a Sof reconstruction chunk.
static void OJPEGWriteStreamEoi(TIFF *tif, void **mem, uint32_t *len)
Produce a Eoi reconstruction chunk.
static int OJPEGEncode(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
Reject unsupported old-style JPEG encoding.
static int OJPEGReadWord(OJPEGState *sp, uint16_t *word)
Consume a big-endian sixteen-bit word.
static void OJPEGLibjpegSessionAbort(TIFF *tif)
Destroy the active old-style JPEG dependency session.
static int OJPEGPostEncode(TIFF *tif)
Reject unsupported old-style JPEG encoding.
static void OJPEGPrintDir(TIFF *tif, FILE *fd, long flags)
Print cached old-style JPEG fields before the optional parent printer.
static void jpeg_encap_unwind(TIFF *tif)
Jump to the active old-style JPEG dependency wrapper.
#define FIELD_OJPEG_JPEGQTABLES
TIFFField field bit for the codec-private JpegQTables tag.
static int jpeg_read_scanlines_encap(OJPEGState *sp, tiff_ojpeg_decompress_struct *cinfo, void *scanlines, uint32_t max_lines)
Trap dependency fatal errors while attempting to read scanlines.
static const TIFFField ojpegFields[]
Describe legacy JPEG tags merged into the handle.
static void OJPEGWriteStreamDcTable(TIFF *tif, uint8_t table_index, void **mem, uint32_t *len)
Produce a DcTable reconstruction chunk.
#define JMP_BUF
Type used to store the libjpeg error jump frame.
static void OJPEGLibjpegJpegErrorMgrOutputMessage(tiff_ojpeg_common_struct *cinfo)
Route a dependency message through the handle warning handler.
static int OJPEGReadHeaderInfoSecStreamDqt(TIFF *tif)
Capture eight-bit JPEG quantisation table markers.
static int OJPEGDecodeRaw(TIFF *tif, uint8_t *buf, tmsize_t cc)
Decode complete subsampled clump rows.
static int OJPEGWriteHeaderInfo(TIFF *tif)
Start libjpeg with a synthesized old-style JPEG input header.
static void OJPEGCleanup(TIFF *tif)
Release old-style JPEG state and restore parent methods.
#define JPEG_MARKER_RST0
JPEG RST0 (restart) marker code.
static int OJPEGReadSecondarySos(TIFF *tif, uint16_t s)
Locate and cache a later separate-plane scan header.
int TIFFInitOJPEG(TIFF *tif, int scheme)
Install the decode-only old-style JPEG codec.
static void OJPEGReadSkip(OJPEGState *sp, uint16_t len)
Skip up to a bounded input extent without fetching skipped bytes.
static boolean OJPEGLibjpegJpegSourceMgrResyncToRestart(tiff_ojpeg_decompress_struct *cinfo, int desired)
Reject an unexpected dependency restart resynchronization request.
#define JPEG_MARKER_DRI
JPEG DRI (define restart interval) marker code.
OJPEGStateInBufferSource
Source of the bytes currently read into the input buffer.
#define JPEG_MARKER_SOF0
JPEG SOF0 (baseline DCT start-of-frame) marker code.
static int OJPEGPreEncode(TIFF *tif, uint16_t s)
Reject unsupported old-style JPEG encoding.
static int OJPEGReadHeaderInfoSecStreamDht(TIFF *tif)
Capture a JPEG Huffman marker in its selected table slot.
#define SETJMP(jbuf)
Save the calling environment for a later LONGJMP (plain setjmp).
#define FIELD_OJPEG_JPEGDCTABLES
TIFFField field bit for the codec-private JpegDcTables tag.
static int jpeg_read_raw_data_encap(OJPEGState *sp, tiff_ojpeg_decompress_struct *cinfo, void *data, uint32_t max_lines)
Trap dependency fatal errors while attempting to read component planes.
#define JPEG_MARKER_DHT
JPEG DHT (define Huffman table) marker code.
static int OJPEGWriteStream(TIFF *tif, void **mem, uint32_t *len)
Produce the next borrowed chunk of reconstructed decoder input.
static int OJPEGReadHeaderInfoSecTablesDcTable(TIFF *tif)
Build DC Huffman markers from TIFF table-offset tags.
static void OJPEGWriteStreamDri(TIFF *tif, void **mem, uint32_t *len)
Produce a Dri reconstruction chunk.
#define FIELD_OJPEG_JPEGRESTARTINTERVAL
TIFFField field bit for the codec-private JpegRestartInterval tag.
static int OJPEGWriteStreamCompressed(TIFF *tif, void **mem, uint32_t *len)
Produce a Compressed reconstruction chunk.
static int OJPEGPreDecodeSkipScanlines(TIFF *tif)
Decode and discard one strile in scanlines mode.
static int OJPEGPreDecodeSkipRaw(TIFF *tif)
Decode and discard one strile in raw mode.
#define JPEG_MARKER_COM
JPEG COM (comment) marker code.
#define JPEG_MARKER_SOF3
JPEG SOF3 (lossless start-of-frame) marker code.
#define FIELD_OJPEG_JPEGINTERCHANGEFORMAT
TIFFField field bit for the codec-private JpegInterchangeFormat tag.
struct jpeg_source_mgr tiff_ojpeg_source_mgr
Alias for the libjpeg source-manager structure.
static int jpeg_read_header_encap(OJPEGState *sp, tiff_ojpeg_decompress_struct *cinfo, uint8_t require_image)
Trap dependency fatal errors while attempting to read a JPEG header.
static int OJPEGDecode(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
Decode complete output rows from the active old-style JPEG session.
#define JPEG_MARKER_EOI
JPEG EOI (end of image) marker code.
static int OJPEGReadHeaderInfo(TIFF *tif)
Validate geometry and cache the first old-style JPEG scan position.
static int OJPEGReadHeaderInfoSecStreamSos(TIFF *tif)
Validate and cache a JPEG scan component header.
@ ososDcTable3
Emit DC Huffman table slot 3 when present.
@ ososQTable3
Emit quantisation table slot 3 when present.
@ ososSoi
Emit the synthetic start-of-image marker.
@ ososQTable2
Emit quantisation table slot 2 when present.
@ ososDcTable2
Emit DC Huffman table slot 2 when present.
@ ososEoi
Emit the synthetic end-of-image marker.
@ ososCompressed
Borrow the next compressed input chunk.
@ ososQTable1
Emit quantisation table slot 1 when present.
@ ososAcTable2
Emit AC Huffman table slot 2 when present.
@ ososRst
Emit the next cyclic restart marker.
@ ososAcTable0
Emit AC Huffman table slot 0 when present.
@ ososSof
Emit the reconstructed frame header.
@ ososAcTable3
Emit AC Huffman table slot 3 when present.
@ ososDri
Emit the cached restart interval.
@ ososAcTable1
Emit AC Huffman table slot 1 when present.
@ ososQTable0
Emit quantisation table slot 0 when present.
@ ososDcTable1
Emit DC Huffman table slot 1 when present.
@ ososDcTable0
Emit DC Huffman table slot 0 when present.
@ ososSos
Emit the current scan header.
@ osibsStrile
Read bytes from the current strip or tile extent.
@ osibsNotSetYet
No input extent selected yet.
@ osibsEof
No further input extents remain.
@ osibsJpegInterchangeFormat
Read bytes from the interchange-format extent.
#define TIFFReadFile(tif, buf, size)
Invoke the handle's client read callback.
#define isTiled(tif)
Test whether a handle uses tiled storage.
#define TIFFhowmany_32_maxuint_compat(x, y)
Compute a 32-bit ceiling quotient without adding x and y first.
#define TRUE
Represent the legacy internal true value.
#define FALSE
Represent the legacy internal false value.
#define TIFFGetFileSize(tif)
Invoke the handle's client size callback.
#define TIFFSeekFile(tif, off, whence)
Invoke the handle's client seek callback.
#define TIFF_DIRTYDIRECT
Mark a current directory that needs writing.
#define TIFF_NOREADRAW
Suppress the normal raw-data read path.
#define TIFFArrayCount(a)
Compute the element count of an actual array.
#define TIFF_VARIABLE2
Mark a variable-length field with a 32-bit count convention.
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.
const TIFFField * TIFFFieldWithTag(TIFF *tif, uint32_t tag)
Find a registered field by tag number.
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.
int(* TIFFVGetMethod)(TIFF *tif, uint32_t tag, va_list ap)
Implement a handle's variadic tag getter.
int TIFFSetField(TIFF *tif, uint32_t tag,...)
Set a tag value in the current in-memory directory.
void(* TIFFPrintMethod)(TIFF *tif, FILE *fd, long flags)
Append extension-specific directory information to a stream.
int(* TIFFVSetMethod)(TIFF *tif, uint32_t tag, va_list ap)
Implement a handle's variadic tag setter.
int uint16_vap
Represent a uint16_t value after default variadic argument promotion.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
@ TIFF_SHORT
Unsigned 16-bit integer.
@ TIFF_LONG8
BigTIFF unsigned 64-bit integer.
Own old-style JPEG reconstruction tables buffers and dependency sessions.
uint8_t samples_per_pixel
Cached component count, at most three.
uint32_t subsampling_convert_ycbcrbuflen
Combined sample allocation byte capacity.
uint32_t sof_y
Cached frame height.
uint8_t writeheader_done
Nonzero after reconstructed decoder session setup.
uint8_t subsampling_hor
Cached horizontal Y sampling factor.
tiff_ojpeg_error_mgr libjpeg_jpeg_error_mgr
Embedded dependency diagnostic callbacks.
uint32_t subsampling_convert_clinelen
Allocated chroma-plane bytes per row.
uint8_t subsampling_convert_log
Nonzero after conversion geometry/storage setup.
TIFFPrintMethod printdir
Borrowed saved parent printer.
uint32_t in_buffer_next_strile
Next/snapshotted strile input index.
uint32_t subsampling_convert_ybuflen
Y-plane byte capacity.
uint64_t jpeg_interchange_format
Cached interchange stream offset.
uint32_t sof_x
Cached frame width.
uint8_t * subsampling_convert_cbbuf
Borrowed Cb view into the combined allocation.
uint8_t * in_buffer_cur
Borrowed cursor into in_buffer.
uint8_t ** subsampling_convert_ycbcrimage
Owned Ext dependency plane/row pointer allocation, borrowing sample storage.
uint8_t in_buffer[OJPEG_BUFFER]
Embedded client input window.
uint8_t * skip_buffer
Owned Ext discarded-scanline scratch allocation.
uint8_t in_buffer_file_pos_log
Nonzero when client position matches refill offset.
uint16_t in_buffer_togo
Unread bytes in the embedded input window.
uint8_t subsampling_ver
Cached vertical Y sampling factor.
uint16_t write_cursample
Current reconstructed separate-plane sample.
uint8_t samples_per_pixel_per_plane
Components in the current scan.
uint32_t subsampling_convert_ylines
Y rows per raw MCU group.
uint8_t * actable[4]
Owned Ext length-prefixed AC Huffman marker blobs.
uint8_t out_buffer[OJPEG_BUFFER]
Embedded synthetic marker storage, borrowed by source manager.
OJPEGStateOutState out_state
Next synthetic output state.
uint8_t dctable_offset_count
Number of stored DC Huffman offsets.
JMP_BUF exit_jmpbuf
Active synchronous dependency error frame.
uint8_t subsampling_tag
Nonzero when sampling was explicitly tagged.
int error_in_raw_data_decoding
Latched raw decode error until reset.
uint32_t strile_length_total
Height of reconstructed strile stream.
uint8_t readheader_done
Nonzero after initial header caching.
uint32_t lines_per_strile
Output ordinary rows or clump units per strile.
uint8_t * subsampling_convert_ycbcrbuf
Owned Ext combined Y/Cb/Cr sample allocation.
uint64_t file_size
Cached client file extent.
uint32_t subsampling_convert_state
Next chroma row in the current MCU group.
uint8_t libjpeg_jpeg_query_style
Zero for raw planes, one for scanlines.
uint8_t * dctable[4]
Owned Ext length-prefixed DC Huffman marker blobs.
uint64_t actable_offset[3]
Embedded AC Huffman offsets, borrowed by getters.
uint32_t image_length
Cached image height in rows.
uint8_t actable_offset_count
Number of stored AC Huffman offsets.
uint32_t subsampling_convert_clines
Chroma rows per raw MCU group.
uint64_t jpeg_interchange_format_length
Normalized interchange byte extent.
uint8_t subsamplingcorrect_done
Nonzero after the one-shot correction attempt.
uint32_t strile_length
Cached strile height.
uint8_t qtable_offset_count
Number of stored quantisation offsets.
uint32_t subsampling_convert_clinelenout
Output chroma samples per clump row.
uint8_t sos_cs[3]
Scan component selectors.
uint64_t qtable_offset[3]
Embedded quantisation offsets, borrowed by tag getters.
uint8_t log
Nonzero when this scan snapshot is valid.
uint32_t image_width
Cached image width in samples.
uint8_t sof_log
Nonzero when frame details are cached.
uint8_t libjpeg_session_active
Nonzero while dependency context needs destruction.
TIFFVGetMethod vgetparent
Borrowed saved parent getter.
uint8_t sof_marker_id
Cached SOF marker type.
uint32_t subsampling_convert_ylinelen
Allocated Y-plane bytes per padded row.
uint8_t sof_c[3]
Frame component identifiers.
TIFF * tif
Borrowed owning TIFF handle.
tiff_ojpeg_source_mgr libjpeg_jpeg_source_mgr
Embedded source manager borrowing reconstruction chunks.
uint8_t sof_hv[3]
Packed per-component sampling factors.
uint16_t restart_interval
Cached restart MCU interval.
uint8_t sos_tda[3]
Packed scan DC/AC table selectors.
uint64_t in_buffer_file_pos
Current/snapshotted next refill offset.
uint32_t in_buffer_strile_count
Total input strile count.
uint8_t plane_sample_offset
First component of the selected scan/plane.
uint8_t sof_tq[3]
Frame quantisation selectors.
uint32_t subsampling_convert_cbuflen
Each chroma-plane byte capacity.
uint8_t subsamplingcorrect
Nonzero during sampling-only header probing.
uint8_t * qtable[4]
Owned Ext length-prefixed quantisation marker blobs.
uint8_t jpeg_proc
Cached JPEG process tag.
uint8_t subsampling_force_desubsampling_inside_decompression
Nonzero requests ordinary dependency upsampling.
uint32_t write_curstrile
Current reconstructed strile counter.
uint32_t bytes_per_line
Output bytes per ordinary row or subsampling_ver-row clump unit.
OJPEGStateInBufferSource in_buffer_source
Current/snapshotted interchange or strile input source.
uint32_t subsampling_convert_ycbcrimagelen
Owned pointer-array entry count.
int decoder_ok
Latched nonzero by the first successful predecode; never cleared.
uint8_t * subsampling_convert_crbuf
Borrowed Cr view into the combined allocation.
uint64_t dctable_offset[3]
Embedded DC Huffman offsets, borrowed by getters.
struct OJPEGState::@2 sos_end[3]
Save the input position following one plane scan header.
uint64_t in_buffer_file_togo
Current/snapshotted remaining bounded extent.
uint32_t strile_width
Cached strile width.
tiff_ojpeg_decompress_struct libjpeg_jpeg_decompress_struct
Embedded context owning dependency session resources.
uint8_t restart_index
Next cyclic restart marker index.
TIFFVSetMethod vsetparent
Borrowed saved parent setter.
uint8_t * subsampling_convert_ybuf
Borrowed Y view into the combined allocation.
uint32_t td_rowsperstrip
Rows per strip; UINT32_MAX represents one whole-image strip.
uint32_t td_imagewidth
Image width in pixels.
uint16_t td_photometric
PHOTOMETRIC_* interpretation.
uint32_t td_tilewidth
Tile width in pixels.
uint32_t td_stripsperimage
Strips or tiles per sample plane, despite the historic name.
uint16_t td_planarconfig
PLANARCONFIG_* sample-plane arrangement.
uint16_t td_ycbcrsubsampling[2]
Horizontal and vertical YCbCr subsampling factors.
uint16_t td_samplesperpixel
Samples per pixel, including extra samples.
uint32_t td_nstrips
Total strile count across all planes; logical array length.
uint32_t td_imagelength
Image length in rows.
uint32_t td_curtile
Current tile index, or NOTILE.
uint32_t td_tilelength
Tile length in rows.
uint32_t td_curstrip
Current strip index, or NOSTRIP.
TIFFVGetMethod vgetfield
Variadic tag-query implementation for the handle.
TIFFVSetMethod vsetfield
Variadic tag-setting implementation for the handle.
TIFFPrintMethod printdir
Optional codec/extension directory-print callback.
Describe a field's file type and internal argument contract.
unsigned short field_bit
FIELD_* presence index; FIELD_CUSTOM shares storage through the custom list.
Hold private state for one open TIFF library instance.
TIFFCodeMethod tif_encodestrip
Codec callback encoding strip data.
TIFFCodeMethod tif_encodetile
Codec callback encoding tile data.
TIFFTagMethods tif_tagmethods
Inline table of directory field and print callbacks.
TIFFPreMethod tif_preencode
Codec callback preparing a row, strip, or tile encode.
TIFFBoolMethod tif_fixuptags
Codec callback for directory-dependent tag corrections.
TIFFPreMethod tif_predecode
Codec callback preparing a row, strip, or tile decode.
TIFFCodeMethod tif_decodestrip
Codec callback decoding strip data.
TIFFPostMethod tif_postdecode
Callback transforming decoded data, for example by byte swapping.
TIFFCodeMethod tif_decoderow
Codec callback decoding a scanline.
TIFFBoolMethod tif_setupencode
Codec setup callback run before preencode.
TIFFDirectory tif_dir
Inline representation of the current image directory.
TIFFBoolMethod tif_postencode
Codec callback completing buffered encoding.
TIFFCodeMethod tif_encoderow
Codec callback encoding a scanline.
TIFFVoidMethod tif_cleanup
Codec callback releasing codec-private state.
uint8_t * tif_data
Codec-private storage; allocation and cleanup follow the selected codec.
TIFFBoolMethod tif_setupdecode
Codec setup callback run before predecode.
uint32_t tif_flags
Bitmask combining the TIFF_* handle-state flags declared below.
TIFFCodeMethod tif_decodetile
Codec callback decoding tile data.
Declare private library state, callbacks, and implementation helpers.