125 int scheme,
int is_encode);
145#if defined(EXPECTED_JPEG_LIB_VERSION) && !defined(LIBJPEG_12_PATH)
146#if EXPECTED_JPEG_LIB_VERSION != JPEG_LIB_VERSION
147#error EXPECTED_JPEG_LIB_VERSION != JPEG_LIB_VERSION
161#if defined(HAVE_JPEGTURBO_DUAL_MODE_8_12)
171#define JPEG_DUAL_MODE_8_12
176#undef BITS_IN_JSAMPLE
178#if defined(FROM_TIF_JPEG_12)
187#define BITS_IN_JSAMPLE 12
195#define TIFF_JSAMPLE J12SAMPLE
203#define TIFF_JSAMPARRAY J12SAMPARRAY
211#define TIFF_JSAMPIMAGE J12SAMPIMAGE
219#define TIFF_JSAMPROW J12SAMPROW
228#define BITS_IN_JSAMPLE 8
236#define TIFF_JSAMPLE JSAMPLE
244#define TIFF_JSAMPARRAY JSAMPARRAY
252#define TIFF_JSAMPIMAGE JSAMPIMAGE
260#define TIFF_JSAMPROW JSAMPROW
270#define TIFF_JSAMPLE JSAMPLE
278#define TIFF_JSAMPARRAY JSAMPARRAY
286#define TIFF_JSAMPIMAGE JSAMPIMAGE
294#define TIFF_JSAMPROW JSAMPROW
297#if defined(JPEG_LIB_MK1)
307#define JPEG_LIB_MK1_OR_12BIT 1
308#elif BITS_IN_JSAMPLE == 12
316#define JPEG_LIB_MK1_OR_12BIT 1
326#if defined(D_MAX_DATA_UNITS_IN_MCU)
336#define width_in_blocks width_in_data_units
355#define SETJMP(jbuf) setjmp(jbuf)
372#define LONGJMP(jbuf, code) longjmp(jbuf, code)
380#define JMP_BUF jmp_buf
422#pragma warning(disable : 4324)
440 struct jpeg_compress_struct c;
444 struct jpeg_decompress_struct d;
449 struct jpeg_common_struct comm;
463 struct jpeg_progress_mgr progress;
519#define JState(tif) ((JPEGState *)(tif)->tif_data)
536#define FIELD_JPEGTABLES (FIELD_CODEC + 0)
585 char buffer[JMSG_LENGTH_MAX];
587 (*cinfo->err->format_message)(cinfo, buffer);
612 char buffer[JMSG_LENGTH_MAX];
614 (*cinfo->err->format_message)(cinfo, buffer);
639 if (cinfo->is_decompressor)
641 const int scan_no = ((j_decompress_ptr)cinfo)->input_scan_number;
645 ((
JPEGState *)cinfo)->tif,
"TIFFjpeg_progress_monitor",
646 "Scan number %d exceeds maximum scans (%d). This limit "
647 "can be raised through the "
648 "LIBTIFF_JPEG_MAX_ALLOWED_SCAN_NUMBER "
649 "environment variable.",
687#define CALLJPEG(sp, fail, op) (SETJMP((sp)->exit_jmpbuf) ? (fail) : (op))
701#define CALLVJPEG(sp, op) CALLJPEG(sp, 0, ((op), 1))
723 sp->
cinfo.
c.err = jpeg_std_error(&sp->
err);
728 sp->
cinfo.
c.client_data = NULL;
753 sp->
cinfo.
d.err = jpeg_std_error(&sp->
err);
758 sp->
cinfo.
d.client_data = NULL;
824 boolean force_baseline)
827 jpeg_set_quality(&sp->
cinfo.
c, quality, force_baseline));
870 return CALLVJPEG(sp, jpeg_start_compress(&sp->
cinfo.
c, write_all_tables));
897#if defined(HAVE_JPEGTURBO_DUAL_MODE_8_12) && BITS_IN_JSAMPLE == 12
899 (
int)jpeg12_write_scanlines(&sp->
cinfo.
c, scanlines,
900 (JDIMENSION)num_lines));
903 (
int)jpeg_write_scanlines(&sp->
cinfo.
c, scanlines,
904 (JDIMENSION)num_lines));
932#if defined(HAVE_JPEGTURBO_DUAL_MODE_8_12) && BITS_IN_JSAMPLE == 12
935 (
int)jpeg12_write_raw_data(&sp->
cinfo.
c, data, (JDIMENSION)num_lines));
939 (
int)jpeg_write_raw_data(&sp->
cinfo.
c, data, (JDIMENSION)num_lines));
1002 return CALLJPEG(sp, -1, jpeg_read_header(&sp->
cinfo.
d, require_image));
1047 const char *sz_max_allowed_scan_number;
1052 sz_max_allowed_scan_number = getenv(
"LIBTIFF_JPEG_MAX_ALLOWED_SCAN_NUMBER");
1053 if (sz_max_allowed_scan_number)
1084#if defined(HAVE_JPEGTURBO_DUAL_MODE_8_12) && BITS_IN_JSAMPLE == 12
1086 (
int)jpeg12_read_scanlines(&sp->
cinfo.
d, scanlines,
1087 (JDIMENSION)max_lines));
1090 (
int)jpeg_read_scanlines(&sp->
cinfo.
d, scanlines,
1091 (JDIMENSION)max_lines));
1119#if defined(HAVE_JPEGTURBO_DUAL_MODE_8_12) && BITS_IN_JSAMPLE == 12
1122 (
int)jpeg12_read_raw_data(&sp->
cinfo.
d, data, (JDIMENSION)max_lines));
1126 (
int)jpeg_read_raw_data(&sp->
cinfo.
d, data, (JDIMENSION)max_lines));
1153 uint16_t h_sampling,
1154 uint16_t v_sampling,
1155 int data_precision,
const char *module)
1157 uint64_t clumps_per_line;
1158 uint64_t samples_per_clump;
1159 uint64_t samples_per_clumpline;
1160 uint64_t bits_per_clumpline;
1161 uint64_t bytes_per_clumpline;
1163 if (h_sampling == 0 || v_sampling == 0 || data_precision <= 0)
1165 TIFFErrorExtR(tif, module,
"Invalid JPEG sampling or precision");
1171 tif,
_TIFFMultiply64(tif, h_sampling, v_sampling, module), 2, module);
1172 samples_per_clumpline =
1175 (uint64_t)data_precision, module);
1209 const uint8_t *p = buf + (sample_index / 2) * 3;
1210 if ((sample_index & 1) != 0)
1212 return (
TIFF_JSAMPLE)((p[0] << 4) | ((p[1] & 0xf0) >> 4));
1235 uint16_t v = (uint16_t)sample & 0x0fff;
1236 uint8_t *p = buf + (sample_index / 2) * 3;
1237 if ((sample_index & 1) != 0)
1239 p[1] = (uint8_t)((p[1] & 0xf0) | ((v >> 8) & 0x0f));
1240 p[2] = (uint8_t)(v & 0xff);
1244 p[0] = (uint8_t)(v >> 4);
1245 p[1] = (uint8_t)((v & 0x0f) << 4);
1265 return CALLJPEG(sp, -1, (
int)jpeg_finish_decompress(&sp->
cinfo.
d));
1331 JDIMENSION samplesperrow,
1334 return CALLJPEG(sp, (JSAMPARRAY)NULL,
1336 &sp->
cinfo.
comm, pool_id, samplesperrow, numrows));
1393 if (sp->
dest.free_in_buffer >= 0)
1500 ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 100);
1501 sp->
dest.next_output_byte =
1503 sp->
dest.free_in_buffer = (size_t)1000;
1559 "No space for JPEGTables");
1611 static const JOCTET dummy_EOI[2] = {0xFF, JPEG_EOI};
1623 if (sp->
src.bytes_in_buffer > 0)
1637 WARNMS(cinfo, JWRN_JPEG_EOF);
1639 sp->
src.next_input_byte = dummy_EOI;
1640 sp->
src.bytes_in_buffer = 2;
1664 if ((
size_t)num_bytes > sp->
src.bytes_in_buffer)
1671 sp->
src.next_input_byte += (size_t)num_bytes;
1672 sp->
src.bytes_in_buffer -= (size_t)num_bytes;
1709 sp->
src.resync_to_restart = jpeg_resync_to_restart;
1711 sp->
src.bytes_in_buffer = 0;
1712 sp->
src.next_input_byte = NULL;
1789 jpeg_component_info *compptr;
1791 int samples_per_clump = 0;
1793 for (ci = 0, compptr = comp_info; ci < num_components; ci++, compptr++)
1795 samples_per_clump += compptr->h_samp_factor * compptr->v_samp_factor;
1797 sp, JPOOL_IMAGE, compptr->width_in_blocks * DCTSIZE,
1798 (JDIMENSION)(compptr->v_samp_factor * DCTSIZE));
1811#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
1820#define JPEG_MARKER_SOF0 0xC0
1828#define JPEG_MARKER_SOF1 0xC1
1836#define JPEG_MARKER_SOF2 0xC2
1844#define JPEG_MARKER_SOF9 0xC9
1852#define JPEG_MARKER_SOF10 0xCA
1860#define JPEG_MARKER_DHT 0xC4
1868#define JPEG_MARKER_SOI 0xD8
1876#define JPEG_MARKER_SOS 0xDA
1884#define JPEG_MARKER_DQT 0xDB
1892#define JPEG_MARKER_DRI 0xDD
1901#define JPEG_MARKER_APP0 0xE0
1909#define JPEG_MARKER_COM 0xFE
1948 uint16_t skiplength);
1969#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
1981#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
2019 static const char module[] = "JPEGFixupTagsSubsampling";
2037 "Unable to allocate memory for auto-correcting of "
2038 "subsampling values; auto-correcting skipped");
2049 "Unable to auto-correct subsampling values, likely corrupt JPEG "
2050 "compressed data in first strip/tile; auto-correcting skipped");
2073 static const char module[] = "JPEGFixupTagsSubsamplingSec";
2125 n = (uint16_t)(n - 2);
2164 "Subsampling values inside JPEG "
2166 "have no TIFF equivalent, "
2167 "auto-correction of TIFF "
2168 "subsampling values failed");
2173 if (((ph != 1) && (ph != 2) && (ph != 4)) ||
2174 ((pv != 1) && (pv != 2) && (pv != 4)))
2177 "Subsampling values inside JPEG "
2178 "compressed data have no TIFF "
2179 "equivalent, auto-correction of TIFF "
2180 "subsampling values failed");
2188 "Auto-corrected former TIFF subsampling values "
2189 "[%" PRIu16
",%" PRIu16
2190 "] to match subsampling values inside JPEG "
2191 "compressed data [%" PRIu8
",%" PRIu8
"]",
2242 assert(m < 0x80000000UL);
2281 *result = (uint16_t)((ma << 8) | mb);
2302 uint16_t skiplength)
2351#if defined(JPEG_DUAL_MODE_8_12) && !defined(FROM_TIF_JPEG_12)
2364 "Failed to initialize libjpeg decompressor");
2415#if defined(JPEG_DUAL_MODE_8_12) && !defined(FROM_TIF_JPEG_12)
2489 "JPEG horizontal or vertical sampling is zero");
2536 static const char module[] = "JPEGPreDecode";
2537 int downsampled_output;
2542 if (sp->
cinfo.
comm.is_decompressor == 0)
2571 "Improper JPEG strip/tile size, "
2572 "expected %" PRIu32
"x%" PRIu32
", got %ux%u",
2586 "JPEG strip size exceeds expected dimensions,"
2587 " expected %" PRIu32
"x%" PRIu32
", got %ux%u",
2601 "JPEG strip/tile size exceeds expected dimensions,"
2602 " expected %" PRIu32
"x%" PRIu32
", got %ux%u",
2607 if (sp->
cinfo.
d.num_components !=
2631 if (sp->
cinfo.
d.progressive_mode &&
2635 "The JPEG strip/tile is encoded with progressive mode, "
2636 "which is normally not legal for JPEG-in-TIFF.\n"
2637 "libtiff should be able to decode it, but it might "
2638 "cause compatibility issues with other readers");
2653 toff_t nRequiredMemory = 1024 * 1024;
2655 for (ci = 0; ci < sp->
cinfo.
d.num_components; ci++)
2657 const jpeg_component_info *compptr = &(sp->
cinfo.
d.comp_info[ci]);
2658 if (compptr->h_samp_factor > 0 && compptr->v_samp_factor > 0)
2661 (
toff_t)((JDIMENSION)(((int)compptr->width_in_blocks +
2662 compptr->h_samp_factor - 1) /
2663 compptr->h_samp_factor)) *
2664 (JDIMENSION)(((
int)compptr->height_in_blocks +
2665 compptr->v_samp_factor - 1) /
2666 compptr->v_samp_factor) *
2671 if (sp->
cinfo.
d.mem->max_memory_to_use > 0 &&
2672 nRequiredMemory > (
toff_t)(sp->
cinfo.
d.mem->max_memory_to_use) &&
2673 getenv(
"LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC") == NULL)
2677 "Reading this image would require libjpeg to allocate "
2678 "at least %" PRIu64
" bytes. "
2679 "This is disabled since above the %ld threshold. "
2680 "You may override this restriction by defining the "
2681 "LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC environment variable, "
2682 "or setting the JPEGMEM environment variable to a value "
2684 "or equal to '%" PRIu64
"M'",
2685 nRequiredMemory, sp->
cinfo.
d.mem->max_memory_to_use,
2686 (nRequiredMemory + 1000000u - 1u) / 1000000u);
2698 "Improper JPEG sampling factors %d,%d\n"
2699 "Apparently should be %" PRIu16
",%" PRIu16
".",
2700 sp->
cinfo.
d.comp_info[0].h_samp_factor,
2701 sp->
cinfo.
d.comp_info[0].v_samp_factor,
2706 for (ci = 1; ci < sp->
cinfo.
d.num_components; ci++)
2708 if (sp->
cinfo.
d.comp_info[ci].h_samp_factor != 1 ||
2709 sp->
cinfo.
d.comp_info[ci].v_samp_factor != 1)
2719 if (sp->
cinfo.
d.comp_info[0].h_samp_factor != 1 ||
2720 sp->
cinfo.
d.comp_info[0].v_samp_factor != 1)
2726 downsampled_output =
FALSE;
2732 sp->
cinfo.
d.jpeg_color_space = JCS_YCbCr;
2733 sp->
cinfo.
d.out_color_space = JCS_RGB;
2738 sp->
cinfo.
d.jpeg_color_space = JCS_UNKNOWN;
2739 sp->
cinfo.
d.out_color_space = JCS_UNKNOWN;
2742 downsampled_output =
TRUE;
2745 if (downsampled_output)
2749#if JPEG_LIB_VERSION >= 70
2768 if (downsampled_output)
2771 sp->
cinfo.
d.num_components))
2782#if !defined(JPEG_LIB_MK1_OR_12BIT)
2822 memset(buf, 0, (
size_t)cc);
2834 memset(buf, 0, (
size_t)cc);
2835 nrows = sp->
cinfo.
d.image_height;
2841 memset(buf, 0, (
size_t)cc);
2853 JSAMPROW bufptr = (JSAMPROW)buf;
2857 memset(buf, 0, (
size_t)cc);
2864 }
while (--nrows > 0);
2872 return sp->
cinfo.
d.output_scanline < sp->
cinfo.
d.output_height ||
2877#if defined(JPEG_LIB_MK1_OR_12BIT)
2924 if (sp->bytesperline == 0)
2926 memset(buf, 0, (
size_t)cc);
2930 nrows = cc / sp->bytesperline;
2931 if (cc % sp->bytesperline)
2934 if (nrows > (
tmsize_t)sp->cinfo.d.image_height)
2938 memset(buf, 0, (
size_t)cc);
2939 nrows = sp->cinfo.d.image_height;
2941 else if (sp->strile_width > sp->cinfo.d.image_width)
2945 memset(buf, 0, (
size_t)cc);
2957 if (sp->cinfo.d.data_precision == 12)
2961 (size_t)sp->cinfo.d.output_width *
2962 (
size_t)sp->cinfo.d.num_components));
2967 if (line_work_buf != NULL)
2977 memset(buf, 0, (
size_t)cc);
2982 if (sp->cinfo.d.data_precision == 12)
2985 (
tmsize_t)sp->cinfo.d.output_width *
2986 sp->cinfo.d.num_components;
2989 for (iPair = 0; iPair < value_count / 2; iPair++)
2991 unsigned char *out_ptr =
2992 ((
unsigned char *)buf) + iPair * 3;
2995 out_ptr[0] = (
unsigned char)((in_ptr[0] & 0xff0) >> 4);
2997 (
unsigned char)(((in_ptr[0] & 0xf) << 4) |
2998 ((in_ptr[1] & 0xf00) >> 8));
2999 out_ptr[2] = (
unsigned char)(((in_ptr[1] & 0xff) >> 0));
3001 if ((value_count & 1) != 0)
3003 line_work_buf[value_count - 1]);
3005 else if (sp->cinfo.d.data_precision == 8)
3008 (
tmsize_t)sp->cinfo.d.output_width *
3009 sp->cinfo.d.num_components;
3012 for (iValue = 0; iValue < value_count; iValue++)
3014 ((
unsigned char *)buf)[iValue] =
3015 (
unsigned char)(line_work_buf[iValue] & 0xff);
3021 buf += sp->bytesperline;
3022 cc -= sp->bytesperline;
3023 }
while (--nrows > 0);
3025 if (line_work_buf != NULL)
3034 return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height ||
3062 tif,
"TIFFReadScanline",
3063 "scanline oriented access is not supported for downsampled JPEG "
3064 "compressed images, consider enabling TIFFTAG_JPEGCOLORMODE as "
3065 "JPEGCOLORMODE_RGB.");
3111 nrows = sp->
cinfo.
d.image_height;
3124 memset(buf, 0, (
size_t)cc);
3126#if defined(JPEG_LIB_MK1_OR_12BIT)
3127 unsigned short *tmpbuf = NULL;
3135 JDIMENSION clumps_per_line = sp->
cinfo.
d.comp_info[1].downsampled_width;
3139 uint64_t samplesperclumpline64;
3147 samplesperclumpline64 =
3149 (uint64_t)samples_per_clump,
"JPEGDecodeRaw");
3150 samplesperclumpline =
3154 sp->
cinfo.
d.data_precision,
"JPEGDecodeRaw");
3155 if (samplesperclumpline == 0 || bytesperclumpline == 0)
3158#if defined(JPEG_LIB_MK1_OR_12BIT)
3160 tif, samplesperclumpline,
sizeof(
unsigned short),
"JPEGDecodeRaw");
3170 jpeg_component_info *compptr;
3171 int ci, clumpoffset;
3173 if (cc < bytesperclumpline)
3176 tif,
"JPEGDecodeRaw",
3177 "application buffer not large enough for all data.");
3184 int n = sp->
cinfo.
d.max_v_samp_factor * DCTSIZE;
3194 for (ci = 0, compptr = sp->
cinfo.
d.comp_info;
3195 ci < sp->
cinfo.
d.num_components; ci++, compptr++)
3197 int hsamp = compptr->h_samp_factor;
3198 int vsamp = compptr->v_samp_factor;
3201 for (ypos = 0; ypos < vsamp; ypos++)
3206#if defined(JPEG_LIB_MK1_OR_12BIT)
3209 uint8_t *outptr = buf + clumpoffset;
3212 (clumps_per_line - 1) +
3216 tif,
"JPEGDecodeRaw",
3217 "application buffer not large enough for all data, "
3218 "possible subsampling issue");
3226 for (nclump = clumps_per_line; nclump-- > 0;)
3229 outptr += samples_per_clump;
3237 for (nclump = clumps_per_line; nclump-- > 0;)
3239 for (xpos = 0; xpos < hsamp; xpos++)
3241 outptr += samples_per_clump;
3244 clumpoffset += hsamp;
3248#if defined(JPEG_LIB_MK1_OR_12BIT)
3250 if (sp->
cinfo.
d.data_precision == 8)
3253 tmsize_t len = samplesperclumpline;
3254 for (i = 0; i < len; i++)
3256 ((
unsigned char *)buf)[i] =
3257 (
unsigned char)(tmpbuf[i] & 0xff);
3263 for (iPair = 0; iPair < samplesperclumpline / 2; iPair++)
3265 unsigned char *out_ptr =
3266 ((
unsigned char *)buf) + iPair * 3;
3270 out_ptr[0] = (
unsigned char)((in_ptr[0] & 0xff0) >> 4);
3272 (
unsigned char)(((in_ptr[0] & 0xf) << 4) |
3273 ((in_ptr[1] & 0xf00) >> 8));
3274 out_ptr[2] = (
unsigned char)(((in_ptr[1] & 0xff) >> 0));
3276 if ((samplesperclumpline & 1) != 0)
3278 (uint8_t *)buf, samplesperclumpline - 1,
3287 buf += bytesperclumpline;
3288 cc -= bytesperclumpline;
3291 }
while (nrows > 0);
3293#if defined(JPEG_LIB_MK1_OR_12BIT)
3299 return sp->
cinfo.
d.output_scanline < sp->
cinfo.
d.output_height ||
3303#if defined(JPEG_LIB_MK1_OR_12BIT)
3329 if ((qtbl = sp->
cinfo.
c.quant_tbl_ptrs[tblno]) != NULL)
3330 qtbl->sent_table =
FALSE;
3349 if ((qtbl = sp->
cinfo.
c.quant_tbl_ptrs[tblno]) != NULL)
3350 qtbl->sent_table =
TRUE;
3370 if ((htbl = sp->
cinfo.
c.dc_huff_tbl_ptrs[tblno]) != NULL)
3371 htbl->sent_table =
FALSE;
3372 if ((htbl = sp->
cinfo.
c.ac_huff_tbl_ptrs[tblno]) != NULL)
3373 htbl->sent_table =
FALSE;
3393 if ((htbl = sp->
cinfo.
c.dc_huff_tbl_ptrs[tblno]) != NULL)
3394 htbl->sent_table =
TRUE;
3395 if ((htbl = sp->
cinfo.
c.ac_huff_tbl_ptrs[tblno]) != NULL)
3396 htbl->sent_table =
TRUE;
3446#if defined(JPEG_LIB_VERSION_MAJOR) && \
3447 (JPEG_LIB_VERSION_MAJOR > 9 || \
3448 (JPEG_LIB_VERSION_MAJOR == 9 && JPEG_LIB_VERSION_MINOR >= 4))
3470 if (cinfo->dc_huff_tbl_ptrs[0] == NULL)
3472 (void)jpeg_std_huff_table((j_common_ptr)cinfo,
TRUE, 0);
3474 if (cinfo->ac_huff_tbl_ptrs[0] == NULL)
3476 (void)jpeg_std_huff_table((j_common_ptr)cinfo,
FALSE, 0);
3478 if (cinfo->dc_huff_tbl_ptrs[1] == NULL)
3480 (void)jpeg_std_huff_table((j_common_ptr)cinfo,
TRUE, 1);
3482 if (cinfo->ac_huff_tbl_ptrs[1] == NULL)
3484 (void)jpeg_std_huff_table((j_common_ptr)cinfo,
FALSE, 1);
3512 static const char module[] = "JPEGSetupEncode";
3514#if defined(JPEG_DUAL_MODE_8_12) && !defined(FROM_TIF_JPEG_12)
3531 assert(!sp->
cinfo.
comm.is_decompressor);
3547 sp->
cinfo.
c.in_color_space = JCS_RGB;
3551 sp->
cinfo.
c.in_color_space = JCS_YCbCr;
3559 sp->
cinfo.
c.in_color_space = JCS_GRAYSCALE;
3562 sp->
cinfo.
c.in_color_space = JCS_RGB;
3565 sp->
cinfo.
c.in_color_space = JCS_CMYK;
3567 sp->
cinfo.
c.in_color_space = JCS_UNKNOWN;
3572 sp->
cinfo.
c.input_components = 1;
3573 sp->
cinfo.
c.in_color_space = JCS_UNKNOWN;
3581 if (sp->
cinfo.
c.num_scans != 0 &&
3588 "mozjpeg library likely detected. Disable emission of "
3589 "Huffman tables in JpegTables tag, and use optimize_coding "
3590 "to avoid potential issues");
3593 sp->
cinfo.
c.num_scans = 0;
3594 sp->
cinfo.
c.scan_info = NULL;
3605 "Invalig horizontal/vertical sampling value");
3611 "BitsPerSample %" PRIu16
" not allowed for JPEG",
3628 refbw[1] = (float)(top - 1);
3629 refbw[2] = (float)(top >> 1);
3630 refbw[3] = refbw[1];
3631 refbw[4] = refbw[2];
3632 refbw[5] = refbw[1];
3640 "PhotometricInterpretation %" PRIu16
3641 " not allowed for JPEG",
3666 "BitsPerSample %" PRIu16
" not allowed for JPEG",
3679 "JPEG tile height must be multiple of %" PRIu32,
3686 "JPEG tile width must be multiple of %" PRIu32,
3697 "RowsPerStrip must be multiple of %" PRIu32
3711#if defined(JPEG_LIB_VERSION_MAJOR) && \
3712 (JPEG_LIB_VERSION_MAJOR > 9 || \
3713 (JPEG_LIB_VERSION_MAJOR == 9 && JPEG_LIB_VERSION_MINOR >= 4))
3715 (sp->
cinfo.
c.dc_huff_tbl_ptrs[0] == NULL ||
3716 sp->
cinfo.
c.dc_huff_tbl_ptrs[1] == NULL ||
3717 sp->
cinfo.
c.ac_huff_tbl_ptrs[0] == NULL ||
3718 sp->
cinfo.
c.ac_huff_tbl_ptrs[1] == NULL))
3774 static const char module[] = "JPEGPreEncode";
3775 int downsampled_input;
3779 if (sp->
cinfo.
comm.is_decompressor == 1)
3784 assert(!sp->
cinfo.
comm.is_decompressor);
3793 "Strip/tile too large for JPEG. Maximum dimension is %d",
3794 (
int)JPEG_MAX_DIMENSION);
3799 downsampled_input =
FALSE;
3808 downsampled_input =
TRUE;
3830 sp->
cinfo.
c.comp_info[0].component_id = s;
3834 sp->
cinfo.
c.comp_info[0].quant_tbl_no = 1;
3835 sp->
cinfo.
c.comp_info[0].dc_tbl_no = 1;
3836 sp->
cinfo.
c.comp_info[0].ac_tbl_no = 1;
3875 if (sp->
cinfo.
c.data_precision == 8)
3880 if (downsampled_input)
3900 if (downsampled_input)
3903 sp->
cinfo.
c.num_components))
3943 short *line16 = NULL;
3944 int line16_count = 0;
3958 if (sp->
cinfo.
c.data_precision == 12)
3962 tif, (
tmsize_t)(
sizeof(short) * (
size_t)line16_count));
3974 if (sp->
cinfo.
c.data_precision == 12)
3977 int value_pairs = line16_count / 2;
3982 for (iPair = 0; iPair < value_pairs; iPair++)
3984 unsigned char *in_ptr = ((
unsigned char *)buf) + iPair * 3;
3988 ((in_ptr[1] & 0xf0) >> 4));
3992 if ((line16_count & 1) != 0)
3995 (
const uint8_t *)buf, line16_count - 1);
4009 if (sp->
cinfo.
c.data_precision == 12)
4048 JDIMENSION clumps_per_line, nclump;
4049 int clumpoffset, ci, xpos, ypos;
4050 jpeg_component_info *compptr;
4070 sp->
cinfo.
c.data_precision,
"JPEGEncodeRaw");
4071 if (bytesperclumpline == 0)
4074 nrows = (cc / bytesperclumpline) * sp->
v_sampling;
4075 if (cc % bytesperclumpline)
4079 clumps_per_line = sp->
cinfo.
c.comp_info[1].downsampled_width;
4088 for (ci = 0, compptr = sp->
cinfo.
c.comp_info;
4089 ci < sp->
cinfo.
c.num_components; ci++, compptr++)
4091 int hsamp = compptr->h_samp_factor;
4092 int vsamp = compptr->v_samp_factor;
4094 (int)(compptr->width_in_blocks * DCTSIZE -
4095 (JDIMENSION)clumps_per_line * (JDIMENSION)hsamp);
4096 for (ypos = 0; ypos < vsamp; ypos++)
4099 if (sp->
cinfo.
c.data_precision == 12)
4101 tmsize_t sample_index = clumpoffset;
4104 for (nclump = clumps_per_line; nclump-- > 0;)
4108 sample_index += samples_per_clump;
4113 for (nclump = clumps_per_line; nclump-- > 0;)
4115 for (xpos = 0; xpos < hsamp; xpos++)
4117 buf, sample_index + xpos);
4118 sample_index += samples_per_clump;
4124 const uint8_t *inptr8 = buf + clumpoffset;
4128 for (nclump = clumps_per_line; nclump-- > 0;)
4131 inptr8 += samples_per_clump;
4137 for (nclump = clumps_per_line; nclump-- > 0;)
4139 for (xpos = 0; xpos < hsamp; xpos++)
4141 inptr8 += samples_per_clump;
4146 for (xpos = 0; xpos < padding; xpos++)
4148 *outptr = outptr[-1];
4151 clumpoffset += hsamp;
4157 int n = sp->
cinfo.
c.max_v_samp_factor * DCTSIZE;
4166 buf += bytesperclumpline;
4203 jpeg_component_info *compptr;
4205 for (ci = 0, compptr = sp->
cinfo.
c.comp_info;
4206 ci < sp->
cinfo.
c.num_components; ci++, compptr++)
4208 int vsamp = compptr->v_samp_factor;
4211 for (ypos = sp->
scancount * vsamp; ypos < DCTSIZE * vsamp; ypos++)
4214 (
void *)sp->
ds_buffer[ci][ypos - 1], row_width);
4217 n = sp->
cinfo.
c.max_v_samp_factor * DCTSIZE;
4345 v32 = (uint32_t)va_arg(ap, uint32_t);
4352 va_arg(ap,
void *), v32);
4463 fprintf(fd,
" JPEG Tables: (%" PRIu32
" bytes)\n",
4496 if (s < td->td_imagelength)
4572 if (!decompress && sp->
cinfo.
comm.is_decompressor)
4574 else if (decompress && !sp->
cinfo.
comm.is_decompressor)
4594#ifndef TIFF_JPEG_MAX_MEMORY_TO_USE
4595#define TIFF_JPEG_MAX_MEMORY_TO_USE (10 * 1024 * 1024)
4601 if (sp->
cinfo.
c.mem->max_memory_to_use > 0)
4604 if (getenv(
"JPEGMEM") == NULL)
4611 if (sp->
cinfo.
c.mem->max_memory_to_use <
4613 sp->
cinfo.
c.mem->max_memory_to_use =
4737 "Merging JPEG codec-specific tags failed");
4774#define SIZE_OF_JPEGTABLES 2000
4793 "Failed to allocate memory for JPEG tables");
4796#undef SIZE_OF_JPEGTABLES
uint32_t _TIFFParseUInt32(const char *str, uint32_t default_value, uint32_t max_value)
Parse a decimal unsigned integer with a fallback value.
uint64_t _TIFFAdd64(TIFF *tif, uint64_t first, uint64_t second, const char *where)
Check and add two unsigned operands.
tmsize_t _TIFFCastUInt64ToSSize(TIFF *tif, uint64_t val, const char *module)
Convert an unsigned 64-bit value after checking the destination range.
uint64_t _TIFFMultiply64(TIFF *tif, uint64_t first, uint64_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 FIELD_PSEUDO
Share bit zero with FIELD_IGNORE for pseudo-tags.
#define TIFFClrFieldBit(tif, field)
Clear a directory presence bit.
#define TIFFSetFieldBit(tif, field)
Set a directory presence bit.
@ TIFF_SETGET_INT
Promoted int scalar representation.
@ TIFF_SETGET_C32_UINT8
Unsigned 8-bit array with 32-bit explicit count.
void(* TIFFTileMethod)(TIFF *tif, uint32_t *tw, uint32_t *th)
Adjust tile width and height for the current codec.
uint32_t(* TIFFStripMethod)(TIFF *tif, uint32_t request)
Recommend rows per strip for the current geometry and codec.
void _TIFFNoPostDecode(TIFF *tif, uint8_t *buf, tmsize_t cc)
Leave decoded bytes unchanged.
int TIFFFlushData1(TIFF *tif)
Append buffered encoded bytes without invoking postencode recursively.
int TIFFFillTile(TIFF *tif, uint32_t tile)
Load raw tile bytes and initialise codec decoding.
int TIFFFillStrip(TIFF *tif, uint32_t strip)
Load raw strip bytes and initialise codec decoding.
static void JPEGResetUpsampled(TIFF *tif)
Update upsampling flags and cached layout sizes after colour-mode changes.
#define JPEG_MARKER_SOS
Recognise the JPEG start of scan marker.
#define TIFF_JPEG_MAX_MEMORY_TO_USE
Preferred libjpeg compressor memory limit.
static int TIFFjpeg_create_decompress(JPEGState *sp)
Create a libjpeg decompressor and install TIFF error routing.
static int TIFFjpeg_start_decompress(JPEGState *sp)
Start the dependency decompressor and progress monitor.
static int JPEGPreEncode(TIFF *tif, uint16_t s)
Select per-strile JPEG sampling table emission and row encoding.
static int TIFFjpeg_read_header(JPEGState *sp, boolean require_image)
Parse a dependency JPEG header or tables-only stream.
static boolean std_fill_input_buffer(j_decompress_ptr cinfo)
Supply a synthetic JPEG end marker when cached input is exhausted.
static void std_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
Skip cached JPEG input or substitute synthetic end-of-image.
static void TIFFjpeg_tables_src(JPEGState *sp)
Install the JPEG source manager for tables-only input.
static int JPEGPreDecode(TIFF *tif, uint16_t s)
Validate one JPEG strile header and start its chosen decoder.
#define LONGJMP(jbuf, code)
Jump back to the frame saved by SETJMP (plain longjmp); never returns.
static int JPEGFixupTags(TIFF *tif)
Attempt JPEG-stream YCbCr subsampling correction before ordinary access.
static void std_init_source(j_decompress_ptr cinfo)
Attach libjpeg input to cached raw strile bytes.
static int TIFFjpeg_read_scanlines(JPEGState *sp, TIFF_JSAMPARRAY scanlines, int max_lines)
Decode dependency scanline rows.
struct jpeg_source_mgr tiff_jpeg_source_mgr
Name the embedded dependency jpeg source mgr type.
#define JPEG_MARKER_SOF10
Recognise the JPEG progressive arithmetic frame marker.
static int TIFFjpeg_set_colorspace(JPEGState *sp, J_COLOR_SPACE colorspace)
Select the dependency compression colour space.
static void unsuppress_huff_table(JPEGState *sp, int tblno)
Enable emission of an existing JPEG huff table.
static int JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData *data, uint8_t *result)
Read one byte through the bounded JPEG marker window.
#define TIFF_JSAMPIMAGE
Select the dependency component-plane sample type.
#define TIFF_JSAMPLE
Select the dependency scalar sample type.
static const TIFFField jpegFields[]
Define JPEG table and quality/colour/table-mode tag metadata.
static int JPEGEncodeRaw(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
Gather packed sampled clumps into dependency raw JPEG component rows.
#define JPEG_MARKER_DQT
Recognise the JPEG quantisation table marker.
static int JPEGVGetField(TIFF *tif, uint32_t tag, va_list ap)
Retrieve JPEG tables/options or delegate related tag queries.
#define JPEG_MARKER_APP0
Recognise the JPEG first application (APP0) marker.
static void JPEGDefaultTileSize(TIFF *tif, uint32_t *tw, uint32_t *th)
Round parent tile recommendations to JPEG MCU dimensions.
static void JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData *data, uint16_t skiplength)
Skip bounded marker bytes without immediately reading them.
#define JPEG_MARKER_SOF1
Recognise the JPEG extended sequential Huffman frame marker.
int TIFFJPEGIsFullStripRequired(TIFF *tif)
Probe whether cached JPEG input needs whole-strile decoding.
static void TIFF_std_huff_tables(j_compress_ptr cinfo)
Populate missing standard JPEG Huffman tables for relevant dependency versions.
struct jpeg_error_mgr tiff_jpeg_error_mgr
Name the embedded dependency jpeg error mgr type.
static int TIFFjpeg_has_multiple_scans(JPEGState *sp)
Query whether dependency input uses multiple scans.
static int DecodeRowError(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
Reject scanline access to raw downsampled JPEG clumps.
#define JPEG_MARKER_SOF9
Recognise the JPEG extended sequential arithmetic frame marker.
static int TIFFjpeg_finish_decompress(JPEGState *sp)
Finish dependency decompression after output rows.
static int JPEGEncode(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
Encode complete normal JPEG rows from caller bytes.
#define FIELD_JPEGTABLES
Reserve the codec field bit for JPEGTables.
#define JState(tif)
Borrow the handle-owned JPEG state.
#define TIFF_JSAMPARRAY
Select the dependency row-array sample type.
static void JPEGFixupTagsSubsampling(TIFF *tif)
Probe first-strile markers to recover JPEG sampling factors.
#define JPEG_MARKER_SOF2
Recognise the JPEG progressive Huffman frame marker.
#define JPEG_MARKER_SOI
Recognise the JPEG start of image marker.
int TIFFReInitJPEG_12(TIFF *tif, const JPEGOtherSettings *otherSettings, int scheme, int is_encode)
Replace JPEG state with the twelve-bit ABI and restore saved options.
static void TIFFjpeg_progress_monitor(j_common_ptr cinfo)
Abort JPEG decompression when its scan count reaches the configured limit.
static int TIFFjpeg_write_scanlines(JPEGState *sp, TIFF_JSAMPARRAY scanlines, int num_lines)
Encode dependency scanline rows.
static JSAMPARRAY TIFFjpeg_alloc_sarray(JPEGState *sp, int pool_id, JDIMENSION samplesperrow, JDIMENSION numrows)
Allocate sample-row storage in a dependency memory pool.
static int JPEGSetupEncode(TIFF *tif)
Initialise JPEG compression parameters tables and output manager.
static uint64_t JPEGGetMaxCompressionRatio(TIFF *tif)
Estimate JPEG expansion from precision and sampled layout.
static TIFF_JSAMPLE JPEGReadPacked12Sample(const uint8_t *buf, tmsize_t sample_index)
Read one sample from TIFF packed twelve-bit bytes.
static tmsize_t JPEGRawBytesPerClumpLine(TIFF *tif, uint32_t width, uint16_t h_sampling, uint16_t v_sampling, int data_precision, const char *module)
Calculate packed bytes for one horizontally sampled JPEG clump row.
static void tables_init_source(j_decompress_ptr cinfo)
Attach libjpeg input to codec-owned JPEG table bytes.
static int TIFFjpeg_set_quality(JPEGState *sp, int quality, boolean force_baseline)
Set dependency quantisation quality and baseline policy.
static int JPEGDecodeRaw(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
Decode a whole JPEG strile into packed sampled clump rows.
static int JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData *data)
Scan marker segments for TIFF-compatible component sampling.
static int TIFFjpeg_destroy(JPEGState *sp)
Destroy dependency resources while retaining outer JPEGState.
static int JPEGDecode(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
Decode whole JPEG output rows into caller bytes.
static int JPEGSetupDecode(TIFF *tif)
Initialise JPEG decompression tables sampling and source managers.
static int TIFFjpeg_create_compress(JPEGState *sp)
Create a libjpeg compressor and install TIFF error routing.
int TIFFInitJPEG(TIFF *tif, int scheme)
Allocate JPEG-in-TIFF codec state and install method chains.
static void JPEGPrintDir(TIFF *tif, FILE *fd, long flags)
Print JPEG table extent then invoke the saved directory printer.
#define JMP_BUF
Select jump-buffer storage for dependency failures.
static void tables_init_destination(j_compress_ptr cinfo)
Begin writing JPEG tables into the codec-owned table allocation.
static void std_term_source(j_decompress_ptr cinfo)
Complete JPEG source management without additional work.
static void std_term_destination(j_compress_ptr cinfo)
Commit dependency output cursor and pending bytes to the TIFF cache.
static void unsuppress_quant_table(JPEGState *sp, int tblno)
Enable emission of an existing JPEG quant table.
static int TIFFjpeg_abort(JPEGState *sp)
Abort the current dependency operation and release image-pool storage.
static void TIFFjpeg_output_message(j_common_ptr cinfo)
Route a dependency warning through the TIFF handle.
#define SIZE_OF_JPEGTABLES
Size of the zero-filled placeholder JPEGTables buffer.
static int JPEGVSetField(TIFF *tif, uint32_t tag, va_list ap)
Set JPEG tables or pseudo-options and chain related tag changes.
#define JPEG_MARKER_DRI
Recognise the JPEG restart interval marker.
static void JPEGCleanup(TIFF *tif)
Restore JPEG tag hooks and release dependency tables and outer state.
int TIFFJPEGIsFullStripRequired_12(TIFF *tif)
Probe cached twelve-bit JPEG input for whole-strile requirements.
#define JPEG_MARKER_SOF0
Recognise the JPEG baseline sequential Huffman frame marker.
#define TIFF_JSAMPROW
Select the dependency row-pointer sample type.
static int TIFFjpeg_finish_compress(JPEGState *sp)
Finish dependency compression through the attached destination.
static void TIFFjpeg_data_dest(JPEGState *sp, TIFF *tif)
Install raw-buffer JPEG output manager callbacks.
static int TIFFjpeg_write_tables(JPEGState *sp)
Emit a tables-only JPEG stream through the destination.
#define CALLVJPEG(sp, op)
Evaluate a void libjpeg call under CALLJPEG, yielding 1 on completion or 0 after a fatal libjpeg erro...
static void TIFFjpeg_error_exit(j_common_ptr cinfo)
Route a fatal JPEG error abort the operation and jump to its wrapper.
static boolean tables_empty_output_buffer(j_compress_ptr cinfo)
Grow the codec-owned JPEG table allocation by one thousand bytes.
static void std_init_destination(j_compress_ptr cinfo)
Attach libjpeg output to the handle raw buffer.
static void tables_term_destination(j_compress_ptr cinfo)
Replace JPEG table capacity with the emitted table-stream length.
static int alloc_downsampled_buffers(TIFF *tif, jpeg_component_info *comp_info, int num_components)
Allocate dependency-owned component rows for raw sampled JPEG transfer.
#define JPEG_MARKER_DHT
Recognise the JPEG Huffman table marker.
static void JPEGWritePacked12Sample(uint8_t *buf, tmsize_t sample_index, TIFF_JSAMPLE sample)
Write one sample to TIFF packed twelve-bit bytes.
static void TIFFInitJPEGCommon(TIFF *tif)
Install common JPEG callbacks defaults and handle backlink.
static boolean std_empty_output_buffer(j_compress_ptr cinfo)
Flush produced JPEG payload and reset the dependency output window.
static int TIFFjpeg_start_compress(JPEGState *sp, boolean write_all_tables)
Start the dependency compressor for a strile.
struct jpeg_destination_mgr tiff_jpeg_destination_mgr
Name the embedded dependency jpeg destination mgr type.
static int JPEGInitializeLibJPEG(TIFF *tif, int decompress)
Create or switch the embedded dependency compressor/decompressor.
static uint32_t JPEGDefaultStripSize(TIFF *tif, uint32_t s)
Round the parent strip recommendation to JPEG MCU height.
static int JPEGPostEncode(TIFF *tif)
Pad pending raw component rows and finish JPEG compression.
static int TIFFjpeg_read_raw_data(JPEGState *sp, TIFF_JSAMPIMAGE data, int max_lines)
Decode dependency downsampled component rows.
static int TIFFjpeg_set_defaults(JPEGState *sp)
Apply dependency default compression parameters.
#define JPEG_MARKER_COM
Recognise the JPEG comment marker.
static int TIFFjpeg_tables_dest(JPEGState *sp, TIFF *tif)
Replace table storage and install tables-only output callbacks.
static void TIFFjpeg_data_src(JPEGState *sp)
Install cached-strile JPEG source manager callbacks.
static int TIFFjpeg_suppress_tables(JPEGState *sp, boolean suppress)
Set dependency table-emission suppression.
static int JPEGComputeStrileWidthHeightBytesPerLine(TIFF *tif, uint16_t s)
Cache JPEG strile geometry and decoded row extent.
static void suppress_quant_table(JPEGState *sp, int tblno)
Suppress emission of an existing JPEG quant table.
static int TIFFjpeg_write_raw_data(JPEGState *sp, TIFF_JSAMPIMAGE data, int num_lines)
Encode dependency downsampled component rows.
static void suppress_huff_table(JPEGState *sp, int tblno)
Suppress emission of an existing JPEG huff table.
static int prepare_JPEGTables(TIFF *tif)
Generate selected JPEG quantisation and Huffman tables.
#define CALLJPEG(sp, fail, op)
Evaluate a libjpeg call, yielding a failure value if libjpeg raises a fatal error.
static int JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData *data, uint16_t *result)
Read a big-endian sixteen-bit marker value.
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
void _TIFFsetByteArrayExt(TIFF *tif, void **vpp, const void *vp, uint32_t n)
Replace an owned byte array with a copied array.
void * _TIFFreallocExt(TIFF *tif, void *p, tmsize_t s)
Resize a handle-aware block or release it for a nonpositive size.
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
Allocate uninitialised bytes under a handle's allocation policy.
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Allocate a checked array with an allocation-failure diagnostic.
#define TIFFReadFile(tif, buf, size)
Invoke the handle's client read callback.
#define isTiled(tif)
Test whether a handle uses tiled storage.
#define TIFFhowmany_64(x, y)
Compute a 64-bit ceiling quotient using an unchecked addition.
#define TIFF_UPSAMPLED
Mark codec output that has already been upsampled.
#define TIFFroundup_32(x, y)
Round a 32-bit value up to a multiple using the guarded quotient.
#define TRUE
Represent the legacy internal true value.
#define FALSE
Represent the legacy internal false value.
#define TIFFSeekFile(tif, off, whence)
Invoke the handle's client seek callback.
#define TIFF_DIRTYDIRECT
Mark a current directory that needs writing.
#define TIFFhowmany_32(x, y)
Compute a guarded 32-bit ceiling quotient.
#define TIFF_NOBITREV
Suppress automatic bit reversal.
#define TIFFhowmany8_64(x)
Compute the byte count needed to hold a 64-bit bit count.
#define TIFFArrayCount(a)
Compute the element count of an actual array.
#define TIFF_ATTRIBUTE(x)
Expand a compiler attribute in a public declaration when supported.
#define TIFF_ANY
Match any data type when searching for a field descriptor.
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.
tmsize_t TIFFTileSize(TIFF *tif)
Compute the decoded-size estimate for the configured tile height.
tmsize_t TIFFScanlineSize(TIFF *tif)
Compute the current scanline I/O byte estimate.
tmsize_t TIFFTileRowSize(TIFF *tif)
Compute the packed byte count of one tile row.
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 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.
uint64_t toff_t
Represent an unsigned file byte offset independently of off_t.
@ TIFF_UNDEFINED
Untyped 8-bit data.
Preserve ABI-independent JPEG options and saved parent hooks.
TIFFVSetMethod vsetparent
Borrowed parent setter restored during cleanup.
uint32_t jpegtables_length
Table byte extent, temporarily allocation capacity during generation.
TIFFStripMethod defsparent
Borrowed parent strip-size recommender.
TIFFPrintMethod printdir
Borrowed optional parent printer.
int has_warned_about_progressive_mode
Latch suppressing repeated progressive-mode warnings.
void * jpegtables
Owned Ext JPEG tables or placeholder; replaced by table building/tag assignment and freed on cleanup.
TIFFTileMethod deftparent
Borrowed parent tile-size recommender.
int jpegtablesmode
Cached quantisation/Huffman table emission mask.
int jpegquality
Cached dependency compression quality, default 75.
TIFFVGetMethod vgetparent
Borrowed parent getter restored during cleanup.
int max_allowed_scan_number
Progressive scan threshold set at decompression start.
int jpegcolormode
Cached raw/RGB colour-conversion policy.
int ycbcrsampling_fetched
Set when YCbCrSubsampling is assigned through the tag setter (even if the parent rejects it); suppres...
Own the leading libjpeg ABI context managers and TIFF transfer state.
TIFF * tif
Borrowed handle backlink, live for all callbacks.
JPEGOtherSettings otherSettings
Owned settings/table pointers and borrowed parent hooks retained across ABI reinitialisation.
union JPEGState::@1 cinfo
Overlay the leading compression decompression and common dependency contexts.
tiff_jpeg_destination_mgr dest
Embedded output manager borrowing raw or table storage.
int scancount
Count of accumulated downsampled row groups.
TIFF_JSAMPARRAY ds_buffer[MAX_COMPONENTS]
Borrowed dependency image-pool component-row arrays, invalidated by image-pool release.
struct jpeg_compress_struct c
Compression view of the leading dependency context union.
int encode_raw_error
Latched failure preventing unsafe raw-encoder retry.
struct jpeg_progress_mgr progress
Embedded dependency scan-progress monitor.
JMP_BUF exit_jmpbuf
Jump buffer valid only during a synchronous wrapper invocation.
tmsize_t bytesperline
Decoded line or raw clump-row byte extent for transfer.
struct jpeg_common_struct comm
Common dependency view; leading layout supports callback casts.
uint16_t photometric
Photometric copied at codec setup.
int cinfo_initialized
Whether dependency creation succeeded and destroy is required.
tiff_jpeg_error_mgr err
Embedded dependency error manager routing to TIFF diagnostics.
uint16_t h_sampling
Cached positive horizontal luminance sampling.
struct jpeg_decompress_struct d
Decompression view of the leading dependency context union.
uint32_t strile_width
Current tile/truncated-strip pixel width.
uint16_t v_sampling
Cached positive vertical luminance sampling.
tiff_jpeg_source_mgr src
Embedded input manager borrowing raw/table or static EOI bytes.
uint32_t strile_height
Current tile/truncated-strip row count.
int samplesperclump
Samples per raw sampled clump.
Store the current directory values and image traversal state.
tmsize_t td_tilesize
Cached decoded tile size in bytes; minus one when invalidated.
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.
tmsize_t td_scanlinesize
Cached decoded scanline size in bytes; zero when not computed.
uint16_t td_bitspersample
Bits in each sample.
uint32_t td_row
Current scanline index; UINT32_MAX before traversal starts.
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_imagelength
Image length in rows.
uint32_t td_tilelength
Tile length in rows.
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.
TIFFTileMethod tif_deftilesize
Codec callback computing or constraining default tile dimensions.
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.
tmsize_t tif_rawcc
Raw-buffer byte count interpreted according to read/write state.
TIFFPreMethod tif_predecode
Codec callback preparing a row, strip, or tile decode.
TIFFCodeMethod tif_decodestrip
Codec callback decoding strip data.
TIFFGetMaxCompressionRatioMethod tif_getmaxcompressionratio
Codec callback returning its maximum compression ratio.
TIFFPostMethod tif_postdecode
Callback transforming decoded data, for example by byte swapping.
uint64_t tif_diroff
Current directory byte offset, or zero for an unlinked in-memory IFD.
TIFFStripMethod tif_defstripsize
Codec callback computing or constraining a default strip size.
char * tif_name
Current filename pointer; may refer to inline or client-supplied storage.
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.
uint8_t * tif_rawcp
Borrowed current-position pointer into the raw buffer.
TIFFBoolMethod tif_setupdecode
Codec setup callback run before predecode.
uint8_t * tif_rawdata
Raw buffer; ownership/mapping follow TIFF_MYBUFFER and TIFF_BUFFERMMAP.
tmsize_t tif_rawdatasize
Raw-buffer capacity in bytes; kept in step with tif_rawdata, including zero whenever tif_rawdata is N...
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.