25#define WIN32_LEAN_AND_MEAN
65 int ycbcrsampling_fetched;
66 int max_allowed_scan_number;
67 int has_warned_about_progressive_mode;
72int TIFFReInitJPEG_12(
TIFF *tif,
const JPEGOtherSettings *otherSettings,
73 int scheme,
int is_encode);
74int TIFFJPEGIsFullStripRequired_12(
TIFF *tif);
80#if defined(EXPECTED_JPEG_LIB_VERSION) && !defined(LIBJPEG_12_PATH)
81#if EXPECTED_JPEG_LIB_VERSION != JPEG_LIB_VERSION
82#error EXPECTED_JPEG_LIB_VERSION != JPEG_LIB_VERSION
96#if defined(HAVE_JPEGTURBO_DUAL_MODE_8_12)
97#define JPEG_DUAL_MODE_8_12
102#undef BITS_IN_JSAMPLE
104#if defined(FROM_TIF_JPEG_12)
105#define BITS_IN_JSAMPLE 12
106#define TIFF_JSAMPLE J12SAMPLE
107#define TIFF_JSAMPARRAY J12SAMPARRAY
108#define TIFF_JSAMPIMAGE J12SAMPIMAGE
109#define TIFF_JSAMPROW J12SAMPROW
111#define BITS_IN_JSAMPLE 8
112#define TIFF_JSAMPLE JSAMPLE
113#define TIFF_JSAMPARRAY JSAMPARRAY
114#define TIFF_JSAMPIMAGE JSAMPIMAGE
115#define TIFF_JSAMPROW JSAMPROW
118#define TIFF_JSAMPLE JSAMPLE
119#define TIFF_JSAMPARRAY JSAMPARRAY
120#define TIFF_JSAMPIMAGE JSAMPIMAGE
121#define TIFF_JSAMPROW JSAMPROW
124#if defined(JPEG_LIB_MK1)
125#define JPEG_LIB_MK1_OR_12BIT 1
126#elif BITS_IN_JSAMPLE == 12
127#define JPEG_LIB_MK1_OR_12BIT 1
137#if defined(D_MAX_DATA_UNITS_IN_MCU)
138#define width_in_blocks width_in_data_units
145#define SETJMP(jbuf) setjmp(jbuf)
146#define LONGJMP(jbuf, code) longjmp(jbuf, code)
147#define JMP_BUF jmp_buf
149#ifndef TIFF_jpeg_destination_mgr_defined
150#define TIFF_jpeg_destination_mgr_defined
154#ifndef TIFF_jpeg_source_mgr_defined
155#define TIFF_jpeg_source_mgr_defined
159#ifndef TIFF_jpeg_error_mgr_defined
160#define TIFF_jpeg_error_mgr_defined
185 int cinfo_initialized;
208 JPEGOtherSettings otherSettings;
210 int encode_raw_error;
213#define JState(tif) ((JPEGState *)(tif)->tif_data)
219static int JPEGInitializeLibJPEG(
TIFF *tif,
int decode);
222#define FIELD_JPEGTABLES (FIELD_CODEC + 0)
250 JPEGState *
sp = (JPEGState *)cinfo;
253 (*cinfo->err->format_message)(cinfo,
buffer);
257 LONGJMP(
sp->exit_jmpbuf, 1);
269 (*cinfo->err->format_message)(cinfo,
buffer);
278static void TIFFjpeg_progress_monitor(
j_common_ptr cinfo)
280 JPEGState *
sp = (JPEGState *)cinfo;
281 if (cinfo->is_decompressor)
284 if (scan_no >=
sp->otherSettings.max_allowed_scan_number)
287 ((JPEGState *)cinfo)->tif,
"TIFFjpeg_progress_monitor",
288 "Scan number %d exceeds maximum scans (%d). This limit "
289 "can be raised through the "
290 "LIBTIFF_JPEG_MAX_ALLOWED_SCAN_NUMBER "
291 "environment variable.",
292 scan_no,
sp->otherSettings.max_allowed_scan_number);
295 LONGJMP(
sp->exit_jmpbuf, 1);
306#define CALLJPEG(sp, fail, op) (SETJMP((sp)->exit_jmpbuf) ? (fail) : (op))
307#define CALLVJPEG(sp, op) CALLJPEG(sp, 0, ((op), 1))
309static int TIFFjpeg_create_compress(JPEGState *
sp)
313 sp->err.error_exit = TIFFjpeg_error_exit;
314 sp->err.output_message = TIFFjpeg_output_message;
317 sp->cinfo.c.client_data =
NULL;
322static int TIFFjpeg_create_decompress(JPEGState *
sp)
326 sp->err.error_exit = TIFFjpeg_error_exit;
327 sp->err.output_message = TIFFjpeg_output_message;
330 sp->cinfo.d.client_data =
NULL;
335static int TIFFjpeg_set_defaults(JPEGState *
sp)
345static int TIFFjpeg_set_quality(JPEGState *
sp,
int quality,
352static int TIFFjpeg_suppress_tables(JPEGState *
sp,
boolean suppress)
362static int TIFFjpeg_write_scanlines(JPEGState *
sp, TIFF_JSAMPARRAY
scanlines,
365#if defined(HAVE_JPEGTURBO_DUAL_MODE_8_12) && BITS_IN_JSAMPLE == 12
366 return CALLJPEG(
sp, -1,
367 (
int)jpeg12_write_scanlines(&
sp->cinfo.c,
scanlines,
370 return CALLJPEG(
sp, -1,
376static int TIFFjpeg_write_raw_data(JPEGState *
sp, TIFF_JSAMPIMAGE
data,
379#if defined(HAVE_JPEGTURBO_DUAL_MODE_8_12) && BITS_IN_JSAMPLE == 12
390static int TIFFjpeg_finish_compress(JPEGState *
sp)
395static int TIFFjpeg_write_tables(JPEGState *
sp)
405static int TIFFjpeg_has_multiple_scans(JPEGState *
sp)
410static int TIFFjpeg_start_decompress(JPEGState *
sp)
412 const char *sz_max_allowed_scan_number;
414 sp->cinfo.d.progress = &
sp->progress;
415 sp->progress.progress_monitor = TIFFjpeg_progress_monitor;
416 sp->otherSettings.max_allowed_scan_number = 100;
417 sz_max_allowed_scan_number =
getenv(
"LIBTIFF_JPEG_MAX_ALLOWED_SCAN_NUMBER");
418 if (sz_max_allowed_scan_number)
419 sp->otherSettings.max_allowed_scan_number =
420 atoi(sz_max_allowed_scan_number);
422 return CALLVJPEG(
sp, jpeg_start_decompress(&
sp->cinfo.d));
425static int TIFFjpeg_read_scanlines(JPEGState *
sp, TIFF_JSAMPARRAY
scanlines,
428#if defined(HAVE_JPEGTURBO_DUAL_MODE_8_12) && BITS_IN_JSAMPLE == 12
429 return CALLJPEG(
sp, -1,
430 (
int)jpeg12_read_scanlines(&
sp->cinfo.d,
scanlines,
433 return CALLJPEG(
sp, -1,
439static int TIFFjpeg_read_raw_data(JPEGState *
sp, TIFF_JSAMPIMAGE
data,
442#if defined(HAVE_JPEGTURBO_DUAL_MODE_8_12) && BITS_IN_JSAMPLE == 12
453static int TIFFjpeg_finish_decompress(JPEGState *
sp)
458static int TIFFjpeg_abort(JPEGState *
sp)
463static int TIFFjpeg_destroy(JPEGState *
sp)
468static JSAMPARRAY TIFFjpeg_alloc_sarray(JPEGState *
sp,
int pool_id,
473 (*
sp->cinfo.comm.mem->alloc_sarray)(
474 &
sp->cinfo.comm, pool_id, samplesperrow, numrows));
485 JPEGState *
sp = (JPEGState *)cinfo;
494 JPEGState *
sp = (JPEGState *)cinfo;
507 if (
sp->dest.free_in_buffer >= 0)
523 JPEGState *
sp = (JPEGState *)cinfo;
531static void TIFFjpeg_data_dest(JPEGState *
sp,
TIFF *tif)
534 sp->cinfo.c.dest = &
sp->dest;
535 sp->dest.init_destination = std_init_destination;
536 sp->dest.empty_output_buffer = std_empty_output_buffer;
537 sp->dest.term_destination = std_term_destination;
546 JPEGState *
sp = (JPEGState *)cinfo;
550 sp->dest.next_output_byte = (
JOCTET *)
sp->otherSettings.jpegtables;
551 sp->dest.free_in_buffer = (
size_t)
sp->otherSettings.jpegtables_length;
556 JPEGState *
sp = (JPEGState *)cinfo;
562 (
tmsize_t)(
sp->otherSettings.jpegtables_length + 1000));
564 ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 100);
565 sp->dest.next_output_byte =
566 (
JOCTET *)newbuf +
sp->otherSettings.jpegtables_length;
567 sp->dest.free_in_buffer = (
size_t)1000;
568 sp->otherSettings.jpegtables = newbuf;
569 sp->otherSettings.jpegtables_length += 1000;
575 JPEGState *
sp = (JPEGState *)cinfo;
578 sp->otherSettings.jpegtables_length -= (
uint32_t)
sp->dest.free_in_buffer;
581static int TIFFjpeg_tables_dest(JPEGState *
sp,
TIFF *tif)
588 if (
sp->otherSettings.jpegtables)
590 sp->otherSettings.jpegtables_length = 1000;
592 tif, (
tmsize_t)
sp->otherSettings.jpegtables_length);
593 if (
sp->otherSettings.jpegtables ==
NULL)
595 sp->otherSettings.jpegtables_length = 0;
597 "No space for JPEGTables");
600 sp->cinfo.c.dest = &
sp->dest;
601 sp->dest.init_destination = tables_init_destination;
602 sp->dest.empty_output_buffer = tables_empty_output_buffer;
603 sp->dest.term_destination = tables_term_destination;
614 JPEGState *
sp = (JPEGState *)cinfo;
623 JPEGState *
sp = (JPEGState *)cinfo;
636 if (
sp->src.bytes_in_buffer > 0)
650 WARNMS(cinfo, JWRN_JPEG_EOF);
652 sp->src.next_input_byte = dummy_EOI;
653 sp->src.bytes_in_buffer = 2;
659 JPEGState *
sp = (JPEGState *)cinfo;
663 if ((
size_t)num_bytes >
sp->src.bytes_in_buffer)
666 (
void)std_fill_input_buffer(cinfo);
670 sp->src.next_input_byte += (
size_t)num_bytes;
671 sp->src.bytes_in_buffer -= (
size_t)num_bytes;
682static void TIFFjpeg_data_src(JPEGState *
sp)
684 sp->cinfo.d.src = &
sp->src;
685 sp->src.init_source = std_init_source;
686 sp->src.fill_input_buffer = std_fill_input_buffer;
687 sp->src.skip_input_data = std_skip_input_data;
689 sp->src.term_source = std_term_source;
690 sp->src.bytes_in_buffer = 0;
691 sp->src.next_input_byte =
NULL;
701 JPEGState *
sp = (JPEGState *)cinfo;
703 sp->src.next_input_byte = (
const JOCTET *)
sp->otherSettings.jpegtables;
704 sp->src.bytes_in_buffer = (
size_t)
sp->otherSettings.jpegtables_length;
707static void TIFFjpeg_tables_src(JPEGState *
sp)
709 TIFFjpeg_data_src(
sp);
710 sp->src.init_source = tables_init_source;
723 JPEGState *
sp = JState(tif);
727 int samples_per_clump = 0;
729 for (ci = 0,
compptr = comp_info; ci < num_components; ci++,
compptr++)
732 buf = (TIFF_JSAMPARRAY)TIFFjpeg_alloc_sarray(
737 sp->ds_buffer[ci] =
buf;
739 sp->samplesperclump = samples_per_clump;
747#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
749#define JPEG_MARKER_SOF0 0xC0
750#define JPEG_MARKER_SOF1 0xC1
751#define JPEG_MARKER_SOF2 0xC2
752#define JPEG_MARKER_SOF9 0xC9
753#define JPEG_MARKER_SOF10 0xCA
754#define JPEG_MARKER_DHT 0xC4
755#define JPEG_MARKER_SOI 0xD8
756#define JPEG_MARKER_SOS 0xDA
757#define JPEG_MARKER_DQT 0xDB
758#define JPEG_MARKER_DRI 0xDD
759#define JPEG_MARKER_APP0 0xE0
760#define JPEG_MARKER_COM 0xFE
761struct JPEGFixupTagsSubsamplingData
772static void JPEGFixupTagsSubsampling(
TIFF *tif);
774JPEGFixupTagsSubsamplingSec(
struct JPEGFixupTagsSubsamplingData *
data);
776JPEGFixupTagsSubsamplingReadByte(
struct JPEGFixupTagsSubsamplingData *
data,
779JPEGFixupTagsSubsamplingReadWord(
struct JPEGFixupTagsSubsamplingData *
data,
782JPEGFixupTagsSubsamplingSkip(
struct JPEGFixupTagsSubsamplingData *
data,
787static int JPEGFixupTags(
TIFF *tif)
789#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
790 JPEGState *
sp = JState(tif);
794 !
sp->otherSettings.ycbcrsampling_fetched)
795 JPEGFixupTagsSubsampling(tif);
801#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
803static void JPEGFixupTagsSubsampling(
TIFF *tif)
825 static const char module[] =
"JPEGFixupTagsSubsampling";
826 struct JPEGFixupTagsSubsamplingData
m;
840 if (
m.buffer ==
NULL)
843 "Unable to allocate memory for auto-correcting of "
844 "subsampling values; auto-correcting skipped");
847 m.buffercurrentbyte =
NULL;
848 m.bufferbytesleft = 0;
849 m.fileoffset = fileoffset;
850 m.filepositioned = 0;
852 if (!JPEGFixupTagsSubsamplingSec(&
m))
855 "Unable to auto-correct subsampling values, likely corrupt JPEG "
856 "compressed data in first strip/tile; auto-correcting skipped");
861JPEGFixupTagsSubsamplingSec(
struct JPEGFixupTagsSubsamplingData *
data)
863 static const char module[] =
"JPEGFixupTagsSubsamplingSec";
869 if (!JPEGFixupTagsSubsamplingReadByte(
data, &
m))
876 if (!JPEGFixupTagsSubsamplingReadByte(
data, &
m))
883 case JPEG_MARKER_SOI:
886 case JPEG_MARKER_COM:
887 case JPEG_MARKER_APP0:
888 case JPEG_MARKER_APP0 + 1:
889 case JPEG_MARKER_APP0 + 2:
890 case JPEG_MARKER_APP0 + 3:
891 case JPEG_MARKER_APP0 + 4:
892 case JPEG_MARKER_APP0 + 5:
893 case JPEG_MARKER_APP0 + 6:
894 case JPEG_MARKER_APP0 + 7:
895 case JPEG_MARKER_APP0 + 8:
896 case JPEG_MARKER_APP0 + 9:
897 case JPEG_MARKER_APP0 + 10:
898 case JPEG_MARKER_APP0 + 11:
899 case JPEG_MARKER_APP0 + 12:
900 case JPEG_MARKER_APP0 + 13:
901 case JPEG_MARKER_APP0 + 14:
902 case JPEG_MARKER_APP0 + 15:
903 case JPEG_MARKER_DQT:
904 case JPEG_MARKER_SOS:
905 case JPEG_MARKER_DHT:
906 case JPEG_MARKER_DRI:
911 if (!JPEGFixupTagsSubsamplingReadWord(
data, &
n))
917 JPEGFixupTagsSubsamplingSkip(
data,
n);
920 case JPEG_MARKER_SOF0:
921 case JPEG_MARKER_SOF1:
922 case JPEG_MARKER_SOF2:
925 case JPEG_MARKER_SOF9:
926 case JPEG_MARKER_SOF10:
936 if (!JPEGFixupTagsSubsamplingReadWord(
data, &
n))
938 if (
n != 8 +
data->tif->tif_dir.td_samplesperpixel * 3)
940 JPEGFixupTagsSubsamplingSkip(
data, 7);
941 if (!JPEGFixupTagsSubsamplingReadByte(
data, &
p))
945 JPEGFixupTagsSubsamplingSkip(
data, 1);
946 for (o = 1; o <
data->tif->tif_dir.td_samplesperpixel; o++)
948 JPEGFixupTagsSubsamplingSkip(
data, 1);
949 if (!JPEGFixupTagsSubsamplingReadByte(
data, &
p))
954 "Subsampling values inside JPEG "
956 "have no TIFF equivalent, "
957 "auto-correction of TIFF "
958 "subsampling values failed");
961 JPEGFixupTagsSubsamplingSkip(
data, 1);
963 if (((ph != 1) && (ph != 2) && (ph != 4)) ||
964 ((pv != 1) && (pv != 2) && (pv != 4)))
967 "Subsampling values inside JPEG "
968 "compressed data have no TIFF "
969 "equivalent, auto-correction of TIFF "
970 "subsampling values failed");
973 if ((ph !=
data->tif->tif_dir.td_ycbcrsubsampling[0]) ||
974 (pv !=
data->tif->tif_dir.td_ycbcrsubsampling[1]))
978 "Auto-corrected former TIFF subsampling values "
980 "] to match subsampling values inside JPEG "
982 data->tif->tif_dir.td_ycbcrsubsampling[0],
983 data->tif->tif_dir.td_ycbcrsubsampling[1], ph, pv);
984 data->tif->tif_dir.td_ycbcrsubsampling[0] = ph;
985 data->tif->tif_dir.td_ycbcrsubsampling[1] = pv;
996JPEGFixupTagsSubsamplingReadByte(
struct JPEGFixupTagsSubsamplingData *
data,
999 if (
data->bufferbytesleft == 0)
1002 if (
data->filebytesleft == 0)
1004 if (!
data->filepositioned)
1011 data->filepositioned = 1;
1013 m =
data->buffersize;
1019 data->buffercurrentbyte =
data->buffer;
1020 data->bufferbytesleft =
m;
1021 data->fileoffset +=
m;
1022 data->filebytesleft -=
m;
1025 data->buffercurrentbyte++;
1026 data->bufferbytesleft--;
1031JPEGFixupTagsSubsamplingReadWord(
struct JPEGFixupTagsSubsamplingData *
data,
1036 if (!JPEGFixupTagsSubsamplingReadByte(
data, &ma))
1038 if (!JPEGFixupTagsSubsamplingReadByte(
data, &mb))
1040 *
result = (ma << 8) | mb;
1045JPEGFixupTagsSubsamplingSkip(
struct JPEGFixupTagsSubsamplingData *
data,
1048 if ((
uint32_t)skiplength <= data->bufferbytesleft)
1050 data->buffercurrentbyte += skiplength;
1051 data->bufferbytesleft -= skiplength;
1057 if (m <= data->filebytesleft)
1059 data->bufferbytesleft = 0;
1060 data->fileoffset +=
m;
1061 data->filebytesleft -=
m;
1062 data->filepositioned = 0;
1066 data->bufferbytesleft = 0;
1067 data->filebytesleft = 0;
1074static int JPEGSetupDecode(
TIFF *tif)
1076 JPEGState *
sp = JState(tif);
1079#if defined(JPEG_DUAL_MODE_8_12) && !defined(FROM_TIF_JPEG_12)
1084 JPEGOtherSettings savedOtherSettings =
sp->otherSettings;
1089 JPEGInitializeLibJPEG(tif,
TRUE);
1092 assert(
sp->cinfo.comm.is_decompressor);
1097 TIFFjpeg_tables_src(
sp);
1100 TIFFErrorExtR(tif,
"JPEGSetupDecode",
"Bogus JPEGTables field");
1107 switch (
sp->photometric)
1121 TIFFjpeg_data_src(
sp);
1138#if defined(JPEG_DUAL_MODE_8_12) && !defined(FROM_TIF_JPEG_12)
1140 return TIFFJPEGIsFullStripRequired_12(tif);
1146 TIFFjpeg_create_decompress(&
state);
1148 TIFFjpeg_data_src(&
state);
1152 TIFFjpeg_destroy(&
state);
1155 ret = TIFFjpeg_has_multiple_scans(&
state);
1157 TIFFjpeg_destroy(&
state);
1167 JPEGState *
sp = JState(tif);
1169 static const char module[] =
"JPEGPreDecode";
1170 uint32_t segment_width, segment_height;
1171 int downsampled_output;
1176 if (
sp->cinfo.comm.is_decompressor == 0)
1181 assert(
sp->cinfo.comm.is_decompressor);
1186 if (!TIFFjpeg_abort(
sp))
1221 if (
sp->h_sampling == 0 ||
sp->v_sampling == 0)
1224 "JPEG horizontal or vertical sampling is zero");
1230 if (
sp->cinfo.d.image_width < segment_width ||
1231 sp->cinfo.d.image_height < segment_height)
1234 "Improper JPEG strip/tile size, "
1236 segment_width, segment_height,
sp->cinfo.d.image_width,
1237 sp->cinfo.d.image_height);
1239 if (
sp->cinfo.d.image_width == segment_width &&
1240 sp->cinfo.d.image_height > segment_height &&
1248 "JPEG strip size exceeds expected dimensions,"
1250 segment_width, segment_height,
sp->cinfo.d.image_width,
1251 sp->cinfo.d.image_height);
1253 else if (
sp->cinfo.d.image_width > segment_width ||
1254 sp->cinfo.d.image_height > segment_height)
1263 "JPEG strip/tile size exceeds expected dimensions,"
1265 segment_width, segment_height,
sp->cinfo.d.image_width,
1266 sp->cinfo.d.image_height);
1269 if (
sp->cinfo.d.num_components !=
1292 if (
sp->cinfo.d.progressive_mode &&
1293 !
sp->otherSettings.has_warned_about_progressive_mode)
1296 "The JPEG strip/tile is encoded with progressive mode, "
1297 "which is normally not legal for JPEG-in-TIFF.\n"
1298 "libtiff should be able to decode it, but it might "
1299 "cause compatibility issues with other readers");
1300 sp->otherSettings.has_warned_about_progressive_mode =
TRUE;
1306 if (TIFFjpeg_has_multiple_scans(
sp))
1314 toff_t nRequiredMemory = 1024 * 1024;
1316 for (ci = 0; ci <
sp->cinfo.d.num_components; ci++)
1331 if (
sp->cinfo.d.mem->max_memory_to_use > 0 &&
1332 nRequiredMemory > (
toff_t)(
sp->cinfo.d.mem->max_memory_to_use) &&
1333 getenv(
"LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC") ==
NULL)
1337 "Reading this image would require libjpeg to allocate "
1338 "at least %" PRIu64 " bytes. "
1339 "This is disabled since above the %ld threshold. "
1340 "You may override this restriction by defining the "
1341 "LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC environment variable, "
1342 "or setting the JPEGMEM environment variable to a value "
1344 "or equal to '%" PRIu64 "M'",
1345 nRequiredMemory,
sp->cinfo.d.mem->max_memory_to_use,
1346 (nRequiredMemory + 1000000u - 1u) / 1000000u);
1354 if (
sp->cinfo.d.comp_info[0].h_samp_factor !=
sp->h_sampling ||
1355 sp->cinfo.d.comp_info[0].v_samp_factor !=
sp->v_sampling)
1358 "Improper JPEG sampling factors %d,%d\n"
1360 sp->cinfo.d.comp_info[0].h_samp_factor,
1361 sp->cinfo.d.comp_info[0].v_samp_factor,
1362 sp->h_sampling,
sp->v_sampling);
1366 for (ci = 1; ci <
sp->cinfo.d.num_components; ci++)
1368 if (
sp->cinfo.d.comp_info[ci].h_samp_factor != 1 ||
1369 sp->cinfo.d.comp_info[ci].v_samp_factor != 1)
1379 if (
sp->cinfo.d.comp_info[0].h_samp_factor != 1 ||
1380 sp->cinfo.d.comp_info[0].v_samp_factor != 1)
1386 downsampled_output =
FALSE;
1401 (
sp->h_sampling != 1 ||
sp->v_sampling != 1))
1402 downsampled_output =
TRUE;
1405 if (downsampled_output)
1408 sp->cinfo.d.raw_data_out =
TRUE;
1409#if JPEG_LIB_VERSION >= 70
1410 sp->cinfo.d.do_fancy_upsampling =
FALSE;
1419 sp->cinfo.d.raw_data_out =
FALSE;
1425 if (!TIFFjpeg_start_decompress(
sp))
1428 if (downsampled_output)
1430 if (!alloc_downsampled_buffers(tif,
sp->cinfo.d.comp_info,
1431 sp->cinfo.d.num_components))
1442#if !JPEG_LIB_MK1_OR_12BIT
1445 JPEGState *
sp = JState(tif);
1456 if (
sp->bytesperline == 0)
1462 nrows =
cc /
sp->bytesperline;
1463 if (
cc %
sp->bytesperline)
1466 if (nrows > (
tmsize_t)
sp->cinfo.d.image_height)
1467 nrows =
sp->cinfo.d.image_height;
1480 if (TIFFjpeg_read_scanlines(
sp, &
bufptr, 1) != 1)
1487 buf +=
sp->bytesperline;
1488 cc -=
sp->bytesperline;
1489 }
while (--nrows > 0);
1497 return sp->cinfo.d.output_scanline <
sp->cinfo.d.output_height ||
1498 TIFFjpeg_finish_decompress(
sp);
1502#if JPEG_LIB_MK1_OR_12BIT
1506 JPEGState *
sp = JState(tif);
1517 if (
sp->bytesperline == 0)
1523 nrows =
cc /
sp->bytesperline;
1524 if (
cc %
sp->bytesperline)
1527 if (nrows > (
tmsize_t)
sp->cinfo.d.image_height)
1528 nrows =
sp->cinfo.d.image_height;
1533 TIFF_JSAMPROW line_work_buf =
NULL;
1539 if (
sp->cinfo.d.data_precision == 12)
1542 tif,
sizeof(
short) *
sp->cinfo.d.output_width *
1543 sp->cinfo.d.num_components);
1548 if (line_work_buf !=
NULL)
1556 if (TIFFjpeg_read_scanlines(
sp, &line_work_buf, 1) != 1)
1562 if (
sp->cinfo.d.data_precision == 12)
1564 int value_pairs = (
sp->cinfo.d.output_width *
1565 sp->cinfo.d.num_components) /
1569 for (iPair = 0; iPair < value_pairs; iPair++)
1571 unsigned char *out_ptr =
1572 ((
unsigned char *)
buf) + iPair * 3;
1573 TIFF_JSAMPLE *in_ptr = line_work_buf + iPair * 2;
1575 out_ptr[0] = (
unsigned char)((in_ptr[0] & 0xff0) >> 4);
1577 (
unsigned char)(((in_ptr[0] & 0xf) << 4) |
1578 ((in_ptr[1] & 0xf00) >> 8));
1579 out_ptr[2] = (
unsigned char)(((in_ptr[1] & 0xff) >> 0));
1582 else if (
sp->cinfo.d.data_precision == 8)
1585 (
sp->cinfo.d.output_width *
sp->cinfo.d.num_components);
1588 for (iValue = 0; iValue < value_count; iValue++)
1590 ((
unsigned char *)
buf)[iValue] =
1591 line_work_buf[iValue] & 0xff;
1597 buf +=
sp->bytesperline;
1598 cc -=
sp->bytesperline;
1599 }
while (--nrows > 0);
1601 if (line_work_buf !=
NULL)
1610 return sp->cinfo.d.output_scanline <
sp->cinfo.d.output_height ||
1611 TIFFjpeg_finish_decompress(
sp);
1624 tif,
"TIFFReadScanline",
1625 "scanline oriented access is not supported for downsampled JPEG "
1626 "compressed images, consider enabling TIFFTAG_JPEGCOLORMODE as "
1627 "JPEGCOLORMODE_RGB.");
1638 JPEGState *
sp = JState(tif);
1643 nrows =
sp->cinfo.d.image_height;
1650#
if defined(JPEG_LIB_MK1_OR_12BIT)
1651 unsigned short *tmpbuf =
NULL;
1659 JDIMENSION clumps_per_line =
sp->cinfo.d.comp_info[1].downsampled_width;
1660 int samples_per_clump =
sp->samplesperclump;
1662#if defined(JPEG_LIB_MK1_OR_12BIT)
1664 sp->cinfo.d.output_width *
1665 sp->cinfo.d.num_components);
1676 int ci, clumpoffset;
1678 if (cc < sp->bytesperline)
1681 tif,
"JPEGDecodeRaw",
1682 "application buffer not large enough for all data.");
1689 int n =
sp->cinfo.d.max_v_samp_factor *
DCTSIZE;
1690 if (TIFFjpeg_read_raw_data(
sp,
sp->ds_buffer,
n) !=
n)
1699 for (ci = 0,
compptr =
sp->cinfo.d.comp_info;
1706 for (ypos = 0; ypos < vsamp; ypos++)
1708 TIFF_JSAMPLE *inptr =
1709 sp->ds_buffer[ci][
sp->scancount * vsamp + ypos];
1711#if defined(JPEG_LIB_MK1_OR_12BIT)
1712 TIFF_JSAMPLE *outptr = (TIFF_JSAMPLE *)tmpbuf + clumpoffset;
1714 TIFF_JSAMPLE *outptr = (TIFF_JSAMPLE *)
buf + clumpoffset;
1717 (clumps_per_line - 1) +
1721 tif,
"JPEGDecodeRaw",
1722 "application buffer not large enough for all data, "
1723 "possible subsampling issue");
1731 for (nclump = clumps_per_line; nclump-- > 0;)
1733 outptr[0] = *inptr++;
1734 outptr += samples_per_clump;
1742 for (nclump = clumps_per_line; nclump-- > 0;)
1744 for (xpos = 0; xpos < hsamp; xpos++)
1745 outptr[xpos] = *inptr++;
1746 outptr += samples_per_clump;
1749 clumpoffset += hsamp;
1753#if defined(JPEG_LIB_MK1_OR_12BIT)
1755 if (
sp->cinfo.d.data_precision == 8)
1759 sp->cinfo.d.output_width *
sp->cinfo.d.num_components;
1760 for (
i = 0;
i <
len;
i++)
1762 ((
unsigned char *)
buf)[
i] = tmpbuf[
i] & 0xff;
1767 int value_pairs = (
sp->cinfo.d.output_width *
1768 sp->cinfo.d.num_components) /
1771 for (iPair = 0; iPair < value_pairs; iPair++)
1773 unsigned char *out_ptr =
1774 ((
unsigned char *)
buf) + iPair * 3;
1775 TIFF_JSAMPLE *in_ptr =
1776 (TIFF_JSAMPLE *)(tmpbuf + iPair * 2);
1777 out_ptr[0] = (
unsigned char)((in_ptr[0] & 0xff0) >> 4);
1779 (
unsigned char)(((in_ptr[0] & 0xf) << 4) |
1780 ((in_ptr[1] & 0xf00) >> 8));
1781 out_ptr[2] = (
unsigned char)(((in_ptr[1] & 0xff) >> 0));
1790 buf +=
sp->bytesperline;
1791 cc -=
sp->bytesperline;
1793 nrows -=
sp->v_sampling;
1794 }
while (nrows > 0);
1796#if defined(JPEG_LIB_MK1_OR_12BIT)
1802 return sp->cinfo.d.output_scanline <
sp->cinfo.d.output_height ||
1803 TIFFjpeg_finish_decompress(
sp);
1806#if defined(JPEG_LIB_MK1_OR_12BIT)
1816static void unsuppress_quant_table(JPEGState *
sp,
int tblno)
1820 if ((qtbl =
sp->cinfo.c.quant_tbl_ptrs[
tblno]) !=
NULL)
1824static void suppress_quant_table(JPEGState *
sp,
int tblno)
1828 if ((qtbl =
sp->cinfo.c.quant_tbl_ptrs[
tblno]) !=
NULL)
1832static void unsuppress_huff_table(JPEGState *
sp,
int tblno)
1836 if ((htbl =
sp->cinfo.c.dc_huff_tbl_ptrs[
tblno]) !=
NULL)
1838 if ((htbl =
sp->cinfo.c.ac_huff_tbl_ptrs[
tblno]) !=
NULL)
1842static void suppress_huff_table(JPEGState *
sp,
int tblno)
1846 if ((htbl =
sp->cinfo.c.dc_huff_tbl_ptrs[
tblno]) !=
NULL)
1848 if ((htbl =
sp->cinfo.c.ac_huff_tbl_ptrs[
tblno]) !=
NULL)
1852static int prepare_JPEGTables(
TIFF *tif)
1854 JPEGState *
sp = JState(tif);
1857 if (!TIFFjpeg_set_quality(
sp,
sp->otherSettings.jpegquality,
FALSE))
1861 if (!TIFFjpeg_suppress_tables(
sp,
TRUE))
1865 unsuppress_quant_table(
sp, 0);
1867 unsuppress_quant_table(
sp, 1);
1871 unsuppress_huff_table(
sp, 0);
1873 unsuppress_huff_table(
sp, 1);
1876 if (!TIFFjpeg_tables_dest(
sp, tif))
1879 if (!TIFFjpeg_write_tables(
sp))
1885#if defined(JPEG_LIB_VERSION_MAJOR) && \
1886 (JPEG_LIB_VERSION_MAJOR > 9 || \
1887 (JPEG_LIB_VERSION_MAJOR == 9 && JPEG_LIB_VERSION_MINOR >= 4))
1913static int JPEGSetupEncode(
TIFF *tif)
1915 JPEGState *
sp = JState(tif);
1917 static const char module[] =
"JPEGSetupEncode";
1919#if defined(JPEG_DUAL_MODE_8_12) && !defined(FROM_TIF_JPEG_12)
1924 JPEGOtherSettings savedOtherSettings =
sp->otherSettings;
1929 JPEGInitializeLibJPEG(tif,
FALSE);
1932 assert(!
sp->cinfo.comm.is_decompressor);
1973 sp->cinfo.c.input_components = 1;
1976 if (!TIFFjpeg_set_defaults(
sp))
1982 if (
sp->cinfo.c.num_scans != 0 &&
1989 "mozjpeg library likely detected. Disable emission of "
1990 "Huffman tables in JpegTables tag, and use optimize_coding "
1991 "to avoid potential issues");
1992 sp->otherSettings.jpegtablesmode &= ~JPEGTABLESMODE_HUFF;
1994 sp->cinfo.c.num_scans = 0;
1995 sp->cinfo.c.scan_info =
NULL;
1998 switch (
sp->photometric)
2003 if (
sp->h_sampling == 0 ||
sp->v_sampling == 0)
2006 "Invalig horizontal/vertical sampling value");
2012 "BitsPerSample %" PRIu16 " not allowed for JPEG",
2031 refbw[3] = refbw[1];
2032 refbw[4] = refbw[2];
2033 refbw[5] = refbw[1];
2041 "PhotometricInterpretation %" PRIu16
2042 " not allowed for JPEG",
2067 "BitsPerSample %" PRIu16 " not allowed for JPEG",
2080 "JPEG tile height must be multiple of %" PRIu32,
2087 "JPEG tile width must be multiple of %" PRIu32,
2098 "RowsPerStrip must be multiple of %" PRIu32
2106 if (
sp->otherSettings.jpegtablesmode &
2109 if (
sp->otherSettings.jpegtables ==
NULL ||
2110 memcmp(
sp->otherSettings.jpegtables,
"\0\0\0\0\0\0\0\0\0", 8) == 0)
2112#if defined(JPEG_LIB_VERSION_MAJOR) && \
2113 (JPEG_LIB_VERSION_MAJOR > 9 || \
2114 (JPEG_LIB_VERSION_MAJOR == 9 && JPEG_LIB_VERSION_MINOR >= 4))
2116 (
sp->cinfo.c.dc_huff_tbl_ptrs[0] ==
NULL ||
2117 sp->cinfo.c.dc_huff_tbl_ptrs[1] ==
NULL ||
2118 sp->cinfo.c.ac_huff_tbl_ptrs[0] ==
NULL ||
2119 sp->cinfo.c.ac_huff_tbl_ptrs[1] ==
NULL))
2123 TIFF_std_huff_tables(&
sp->cinfo.c);
2127 if (!prepare_JPEGTables(tif))
2143 TIFFjpeg_data_dest(
sp, tif);
2153 JPEGState *
sp = JState(tif);
2155 static const char module[] =
"JPEGPreEncode";
2156 uint32_t segment_width, segment_height;
2157 int downsampled_input;
2161 if (
sp->cinfo.comm.is_decompressor == 1)
2166 assert(!
sp->cinfo.comm.is_decompressor);
2189 if (
sp->h_sampling == 0 ||
sp->v_sampling == 0)
2192 "JPEG horizontal or vertical sampling is zero");
2202 "Strip/tile too large for JPEG. Maximum dimension is %d",
2206 sp->cinfo.c.image_width = segment_width;
2207 sp->cinfo.c.image_height = segment_height;
2208 downsampled_input =
FALSE;
2216 if (
sp->h_sampling != 1 ||
sp->v_sampling != 1)
2217 downsampled_input =
TRUE;
2225 sp->cinfo.c.comp_info[0].h_samp_factor =
sp->h_sampling;
2226 sp->cinfo.c.comp_info[0].v_samp_factor =
sp->v_sampling;
2230 if (!TIFFjpeg_set_colorspace(
sp,
sp->cinfo.c.in_color_space))
2239 sp->cinfo.c.comp_info[0].component_id =
s;
2243 sp->cinfo.c.comp_info[0].quant_tbl_no = 1;
2244 sp->cinfo.c.comp_info[0].dc_tbl_no = 1;
2245 sp->cinfo.c.comp_info[0].ac_tbl_no = 1;
2249 sp->cinfo.c.write_JFIF_header =
FALSE;
2250 sp->cinfo.c.write_Adobe_marker =
FALSE;
2260 if (!TIFFjpeg_set_quality(
sp,
sp->otherSettings.jpegquality,
FALSE))
2264 suppress_quant_table(
sp, 0);
2265 suppress_quant_table(
sp, 1);
2269 unsuppress_quant_table(
sp, 0);
2270 unsuppress_quant_table(
sp, 1);
2277 suppress_huff_table(
sp, 0);
2278 suppress_huff_table(
sp, 1);
2279 sp->cinfo.c.optimize_coding =
FALSE;
2282 sp->cinfo.c.optimize_coding =
TRUE;
2283 if (downsampled_input)
2286 sp->cinfo.c.raw_data_in =
TRUE;
2294 sp->cinfo.c.raw_data_in =
FALSE;
2300 if (!TIFFjpeg_start_compress(
sp,
FALSE))
2303 if (downsampled_input)
2305 if (!alloc_downsampled_buffers(tif,
sp->cinfo.c.comp_info,
2306 sp->cinfo.c.num_components))
2321 JPEGState *
sp = JState(tif);
2324 short *line16 =
NULL;
2325 int line16_count = 0;
2330 nrows =
cc /
sp->bytesperline;
2331 if (
cc %
sp->bytesperline)
2338 if (
sp->cinfo.c.data_precision == 12)
2340 line16_count = (
int)((
sp->bytesperline * 2) / 3);
2341 line16 = (
short *)
_TIFFmallocExt(tif,
sizeof(
short) * line16_count);
2344 TIFFErrorExtR(tif,
"JPEGEncode",
"Failed to allocate memory");
2353 if (
sp->cinfo.c.data_precision == 12)
2356 int value_pairs = line16_count / 2;
2359 bufptr[0] = (TIFF_JSAMPROW)line16;
2361 for (iPair = 0; iPair < value_pairs; iPair++)
2363 unsigned char *in_ptr = ((
unsigned char *)
buf) + iPair * 3;
2364 TIFF_JSAMPLE *out_ptr = (TIFF_JSAMPLE *)(line16 + iPair * 2);
2366 out_ptr[0] = (in_ptr[0] << 4) | ((in_ptr[1] & 0xf0) >> 4);
2367 out_ptr[1] = ((in_ptr[1] & 0x0f) << 8) | in_ptr[2];
2374 if (TIFFjpeg_write_scanlines(
sp,
bufptr, 1) != 1)
2378 buf +=
sp->bytesperline;
2381 if (
sp->cinfo.c.data_precision == 12)
2395 JPEGState *
sp = JState(tif);
2396 TIFF_JSAMPLE *inptr;
2397 TIFF_JSAMPLE *outptr;
2400 int clumpoffset, ci, xpos, ypos;
2402 int samples_per_clump =
sp->samplesperclump;
2408 if (
sp->encode_raw_error)
2420 ((((
tmsize_t)
sp->cinfo.c.image_width +
sp->h_sampling - 1) /
2423 sp->cinfo.c.data_precision +
2427 nrows = (
cc / bytesperclumpline) *
sp->v_sampling;
2428 if (
cc % bytesperclumpline)
2432 clumps_per_line =
sp->cinfo.c.comp_info[1].downsampled_width;
2441 for (ci = 0,
compptr =
sp->cinfo.c.comp_info;
2447 clumps_per_line * hsamp);
2448 for (ypos = 0; ypos < vsamp; ypos++)
2450 inptr = ((TIFF_JSAMPLE *)
buf) + clumpoffset;
2451 outptr =
sp->ds_buffer[ci][
sp->scancount * vsamp + ypos];
2455 for (nclump = clumps_per_line; nclump-- > 0;)
2457 *outptr++ = inptr[0];
2458 inptr += samples_per_clump;
2464 for (nclump = clumps_per_line; nclump-- > 0;)
2466 for (xpos = 0; xpos < hsamp; xpos++)
2467 *outptr++ = inptr[xpos];
2468 inptr += samples_per_clump;
2472 for (xpos = 0; xpos <
padding; xpos++)
2474 *outptr = outptr[-1];
2477 clumpoffset += hsamp;
2483 int n =
sp->cinfo.c.max_v_samp_factor *
DCTSIZE;
2484 if (TIFFjpeg_write_raw_data(
sp,
sp->ds_buffer,
n) !=
n)
2486 sp->encode_raw_error =
TRUE;
2492 buf += bytesperclumpline;
2493 nrows -=
sp->v_sampling;
2501static int JPEGPostEncode(
TIFF *tif)
2503 JPEGState *
sp = JState(tif);
2505 if (
sp->scancount > 0)
2514 for (ci = 0,
compptr =
sp->cinfo.c.comp_info;
2520 for (ypos =
sp->scancount * vsamp; ypos <
DCTSIZE * vsamp; ypos++)
2523 (
void *)
sp->ds_buffer[ci][ypos - 1], row_width);
2527 if (TIFFjpeg_write_raw_data(
sp,
sp->ds_buffer,
n) !=
n)
2531 return (TIFFjpeg_finish_compress(JState(tif)));
2534static void JPEGCleanup(
TIFF *tif)
2536 JPEGState *
sp = JState(tif);
2543 if (
sp->cinfo_initialized)
2544 TIFFjpeg_destroy(
sp);
2545 if (
sp->otherSettings.jpegtables)
2553static void JPEGResetUpsampled(
TIFF *tif)
2555 JPEGState *
sp = JState(tif);
2593 JPEGState *
sp = JState(tif);
2610 sp->otherSettings.jpegtables_length = v32;
2618 JPEGResetUpsampled(tif);
2622 int ret_value = (*
sp->otherSettings.vsetparent)(tif,
tag,
ap);
2623 JPEGResetUpsampled(tif);
2631 sp->otherSettings.ycbcrsampling_fetched = 1;
2633 return (*
sp->otherSettings.vsetparent)(tif,
tag,
ap);
2635 return (*
sp->otherSettings.vsetparent)(tif,
tag,
ap);
2653 JPEGState *
sp = JState(tif);
2661 *
va_arg(
ap,
const void **) =
sp->otherSettings.jpegtables;
2664 *
va_arg(
ap,
int *) =
sp->otherSettings.jpegquality;
2667 *
va_arg(
ap,
int *) =
sp->otherSettings.jpegcolormode;
2670 *
va_arg(
ap,
int *) =
sp->otherSettings.jpegtablesmode;
2673 return (*
sp->otherSettings.vgetparent)(tif,
tag,
ap);
2680 JPEGState *
sp = JState(tif);
2689 sp->otherSettings.jpegtables_length);
2690 if (
sp->otherSettings.printdir)
2691 (*
sp->otherSettings.printdir)(tif,
fd,
flags);
2697 JPEGState *
sp = JState(tif);
2700 s = (*
sp->otherSettings.defsparent)(tif,
s);
2701 if (s < td->td_imagelength)
2708 JPEGState *
sp = JState(tif);
2711 (*
sp->otherSettings.deftparent)(tif, tw, th);
2738static int JPEGInitializeLibJPEG(
TIFF *tif,
int decompress)
2740 JPEGState *
sp = JState(tif);
2742 if (
sp->cinfo_initialized)
2744 if (!decompress &&
sp->cinfo.comm.is_decompressor)
2745 TIFFjpeg_destroy(
sp);
2746 else if (decompress && !
sp->cinfo.comm.is_decompressor)
2747 TIFFjpeg_destroy(
sp);
2751 sp->cinfo_initialized = 0;
2759 if (!TIFFjpeg_create_decompress(
sp))
2764 if (!TIFFjpeg_create_compress(
sp))
2766#ifndef TIFF_JPEG_MAX_MEMORY_TO_USE
2767#define TIFF_JPEG_MAX_MEMORY_TO_USE (10 * 1024 * 1024)
2773 if (
sp->cinfo.c.mem->max_memory_to_use > 0)
2783 if (
sp->cinfo.c.mem->max_memory_to_use <
2784 TIFF_JPEG_MAX_MEMORY_TO_USE)
2785 sp->cinfo.c.mem->max_memory_to_use =
2786 TIFF_JPEG_MAX_MEMORY_TO_USE;
2791 sp->cinfo_initialized =
TRUE;
2797static void TIFFInitJPEGCommon(
TIFF *tif)
2805 sp->otherSettings.jpegtables =
NULL;
2806 sp->otherSettings.jpegtables_length = 0;
2807 sp->otherSettings.jpegquality = 75;
2809 sp->otherSettings.jpegtablesmode =
2811 sp->otherSettings.ycbcrsampling_fetched = 0;
2837 sp->cinfo_initialized =
FALSE;
2853 "Merging JPEG codec-specific tags failed");
2864 TIFFErrorExtR(tif,
"TIFFInitJPEG",
"No space for JPEG state block");
2880 TIFFInitJPEGCommon(tif);
2890#define SIZE_OF_JPEGTABLES 2000
2899 sp->otherSettings.jpegtables_length = SIZE_OF_JPEGTABLES;
2900 sp->otherSettings.jpegtables =
2902 if (
sp->otherSettings.jpegtables)
2904 _TIFFmemset(
sp->otherSettings.jpegtables, 0, SIZE_OF_JPEGTABLES);
2909 "Failed to allocate memory for JPEG tables");
2912#undef SIZE_OF_JPEGTABLES
static BYTE decode(char c)
char boolean force_baseline
char *CDECL getenv(const char *name)
int WINAPIV fprintf(FILE *file, const char *format,...)
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
_ACRTIMP int __cdecl atoi(const char *)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLdouble GLdouble GLdouble GLdouble top
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
jpeg_finish_compress(j_compress_ptr cinfo)
jpeg_write_tables(j_compress_ptr cinfo)
jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress)
jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data, JDIMENSION num_lines)
jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)
jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
jpeg_abort(j_common_ptr cinfo)
jpeg_destroy(j_common_ptr cinfo)
jpeg_std_huff_table(j_common_ptr cinfo, boolean isDC, int tblno)
jpeg_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
jpeg_set_quality(j_compress_ptr cinfo, int quality, boolean force_baseline)
jpeg_set_defaults(j_compress_ptr cinfo)
jpeg_has_multiple_scans(j_decompress_ptr cinfo)
jpeg_finish_decompress(j_decompress_ptr cinfo)
jpeg_read_header(j_decompress_ptr cinfo, boolean require_image)
jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data, JDIMENSION max_lines)
jpeg_component_info * compptr
jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired)
jpeg_std_error(struct jpeg_error_mgr *err)
#define ERREXIT1(cinfo, code, p1)
#define WARNMS(cinfo, code)
#define JPEG_MAX_DIMENSION
struct jpeg_decompress_struct * j_decompress_ptr
#define JPEG_HEADER_TABLES_ONLY
#define jpeg_create_decompress(cinfo)
#define jpeg_create_compress(cinfo)
JSAMPARRAY JDIMENSION num_lines
JSAMPARRAY JDIMENSION max_lines
static const DWORD padding[]
static float(__cdecl *square_half_float)(float x
uint16_t td_bitspersample
uint16_t td_ycbcrsubsampling[2]
uint16_t td_samplesperpixel
JDIMENSION width_in_blocks
JDIMENSION height_in_blocks
JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]
JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]
TIFFTileMethod tif_deftilesize
TIFFCodeMethod tif_encodestrip
TIFFCodeMethod tif_encodetile
TIFFTagMethods tif_tagmethods
tmsize_t tif_scanlinesize
TIFFPreMethod tif_preencode
TIFFBoolMethod tif_fixuptags
TIFFPreMethod tif_predecode
TIFFCodeMethod tif_decodestrip
TIFFPostMethod tif_postdecode
TIFFStripMethod tif_defstripsize
TIFFCodeMethod tif_decoderow
TIFFBoolMethod tif_setupencode
TIFFBoolMethod tif_postencode
TIFFCodeMethod tif_encoderow
TIFFVoidMethod tif_cleanup
TIFFBoolMethod tif_setupdecode
TIFFCodeMethod tif_decodetile
void _TIFFSetDefaultCompressionState(TIFF *tif)
int TIFFSetField(TIFF *tif, uint32_t tag,...)
void _TIFFsetByteArrayExt(TIFF *tif, void **vpp, const void *vp, uint32_t n)
int TIFFGetField(TIFF *tif, uint32_t tag,...)
#define TIFFFieldSet(tif, field)
#define TIFFClrFieldBit(tif, field)
#define TIFFSetFieldBit(tif, field)
const TIFFField * TIFFFieldWithTag(TIFF *tif, uint32_t tag)
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32_t n)
uint64_t TIFFGetStrileOffset(TIFF *tif, uint32_t strile)
uint64_t TIFFGetStrileByteCount(TIFF *tif, uint32_t strile)
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
void _TIFFfreeExt(TIFF *tif, void *p)
void * _TIFFreallocExt(TIFF *tif, void *p, tmsize_t s)
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
void _TIFFNoPostDecode(TIFF *tif, uint8_t *buf, tmsize_t cc)
int TIFFFillTile(TIFF *tif, uint32_t tile)
int TIFFFillStrip(TIFF *tif, uint32_t strip)
tmsize_t TIFFScanlineSize(TIFF *tif)
tmsize_t TIFFTileSize(TIFF *tif)
tmsize_t TIFFTileRowSize(TIFF *tif)
void _TIFFmemset(void *p, int v, tmsize_t c)
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
void TIFFWarningExtR(TIFF *tif, const char *module, const char *fmt,...)
int TIFFFlushData1(TIFF *tif)
#define PLANARCONFIG_SEPARATE
#define JPEGTABLESMODE_HUFF
#define JPEGCOLORMODE_RAW
#define TIFFTAG_PHOTOMETRIC
#define PHOTOMETRIC_PALETTE
#define TIFFTAG_JPEGTABLESMODE
#define PHOTOMETRIC_SEPARATED
#define JPEGTABLESMODE_QUANT
#define PHOTOMETRIC_YCBCR
#define PHOTOMETRIC_MINISWHITE
#define TIFFTAG_JPEGQUALITY
#define TIFFTAG_YCBCRSUBSAMPLING
#define TIFFTAG_REFERENCEBLACKWHITE
#define PHOTOMETRIC_MINISBLACK
#define TIFFTAG_JPEGCOLORMODE
#define JPEGCOLORMODE_RGB
#define TIFFTAG_JPEGTABLES
#define PLANARCONFIG_CONTIG
void(* TIFFPrintMethod)(TIFF *, FILE *, long)
int(* TIFFVSetMethod)(TIFF *, uint32_t, va_list)
int(* TIFFVGetMethod)(TIFF *, uint32_t, va_list)
#define TIFFReadFile(tif, buf, size)
uint32_t(* TIFFStripMethod)(TIFF *, uint32_t)
void(* TIFFTileMethod)(TIFF *, uint32_t *, uint32_t *)
#define TIFFroundup_32(x, y)
int TIFFJPEGIsFullStripRequired(TIFF *)
#define TIFFSeekFile(tif, off, whence)
#define TIFFhowmany_32(x, y)
#define TIFFArrayCount(a)
static unsigned int bufptr
void int int ULONGLONG int va_list * ap