Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: third_party/libtiff/tif_jpeg.c

Issue 1563103002: XFA: Upgrade to libtiff 4.0.6. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: rename to libtiff Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libtiff/tif_getimage.c ('k') | third_party/libtiff/tif_luv.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* $Id: tif_jpeg.c,v 1.111 2012-07-06 18:48:04 bfriesen Exp $ */ 1 /* $Id: tif_jpeg.c,v 1.119 2015-08-15 20:13:07 bfriesen Exp $ */
2 2
3 /* 3 /*
4 * Copyright (c) 1994-1997 Sam Leffler 4 * Copyright (c) 1994-1997 Sam Leffler
5 * Copyright (c) 1994-1997 Silicon Graphics, Inc. 5 * Copyright (c) 1994-1997 Silicon Graphics, Inc.
6 * 6 *
7 * Permission to use, copy, modify, distribute, and sell this software and 7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided 8 * its documentation for any purpose is hereby granted without fee, provided
9 * that (i) the above copyright notices and this permission notice appear in 9 * that (i) the above copyright notices and this permission notice appear in
10 * all copies of the software and related documentation, and (ii) the names of 10 * all copies of the software and related documentation, and (ii) the names of
11 * Sam Leffler and Silicon Graphics may not be used in any advertising or 11 * Sam Leffler and Silicon Graphics may not be used in any advertising or
12 * publicity relating to the software without the specific, prior written 12 * publicity relating to the software without the specific, prior written
13 * permission of Sam Leffler and Silicon Graphics. 13 * permission of Sam Leffler and Silicon Graphics.
14 * 14 *
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18 * 18 *
19 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR 19 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 20 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 * OF THIS SOFTWARE. 24 * OF THIS SOFTWARE.
25 */ 25 */
26
26 #define WIN32_LEAN_AND_MEAN 27 #define WIN32_LEAN_AND_MEAN
27 #define VC_EXTRALEAN 28 #define VC_EXTRALEAN
28 29
29 #include "tiffiop.h" 30 #include "tiffiop.h"
30 #ifdef JPEG_SUPPORT 31 #ifdef JPEG_SUPPORT
31 32
32 /* 33 /*
33 * TIFF Library 34 * TIFF Library
34 * 35 *
35 * JPEG Compression support per TIFF Technical Note #2 36 * JPEG Compression support per TIFF Technical Note #2
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 way. That causes errors of the following type: 71 way. That causes errors of the following type:
71 72
72 "JPEGLib: JPEG parameter struct mismatch: library thinks size is 432, 73 "JPEGLib: JPEG parameter struct mismatch: library thinks size is 432,
73 caller expects 464" 74 caller expects 464"
74 75
75 For such users we wil fix the problem here. See install.doc file from 76 For such users we wil fix the problem here. See install.doc file from
76 the JPEG library distribution for details. 77 the JPEG library distribution for details.
77 */ 78 */
78 79
79 /* Define "boolean" as unsigned char, not int, per Windows custom. */ 80 /* Define "boolean" as unsigned char, not int, per Windows custom. */
80 #if defined(WIN32) && !defined(__MINGW32__) 81 #if defined(__WIN32__) && !defined(__MINGW32__)
81 # ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ 82 # ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
82 typedef unsigned char boolean; 83 typedef unsigned char boolean;
83 # endif 84 # endif
84 # define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ 85 # define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
85 #endif 86 #endif
86 87
87 #if defined(USE_SYSTEM_LIBJPEG) 88 #if defined(USE_SYSTEM_LIBJPEG)
88 #include <jerror.h> 89 #include <jerror.h>
89 #include <jpeglib.h> 90 #include <jpeglib.h>
90 #elif defined(USE_LIBJPEG_TURBO) 91 #elif defined(USE_LIBJPEG_TURBO)
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 #define CALLVJPEG(sp, op) CALLJPEG(sp, 0, ((op),1)) 253 #define CALLVJPEG(sp, op) CALLJPEG(sp, 0, ((op),1))
253 254
254 static int 255 static int
255 TIFFjpeg_create_compress(JPEGState* sp) 256 TIFFjpeg_create_compress(JPEGState* sp)
256 { 257 {
257 /* initialize JPEG error handling */ 258 /* initialize JPEG error handling */
258 sp->cinfo.c.err = jpeg_std_error(&sp->err); 259 sp->cinfo.c.err = jpeg_std_error(&sp->err);
259 sp->err.error_exit = TIFFjpeg_error_exit; 260 sp->err.error_exit = TIFFjpeg_error_exit;
260 sp->err.output_message = TIFFjpeg_output_message; 261 sp->err.output_message = TIFFjpeg_output_message;
261 262
263 /* set client_data to avoid UMR warning from tools like Purify */
264 sp->cinfo.c.client_data = NULL;
265
262 return CALLVJPEG(sp, jpeg_create_compress(&sp->cinfo.c)); 266 return CALLVJPEG(sp, jpeg_create_compress(&sp->cinfo.c));
263 } 267 }
264 268
265 static int 269 static int
266 TIFFjpeg_create_decompress(JPEGState* sp) 270 TIFFjpeg_create_decompress(JPEGState* sp)
267 { 271 {
268 /* initialize JPEG error handling */ 272 /* initialize JPEG error handling */
269 sp->cinfo.d.err = jpeg_std_error(&sp->err); 273 sp->cinfo.d.err = jpeg_std_error(&sp->err);
270 sp->err.error_exit = TIFFjpeg_error_exit; 274 sp->err.error_exit = TIFFjpeg_error_exit;
271 sp->err.output_message = TIFFjpeg_output_message; 275 sp->err.output_message = TIFFjpeg_output_message;
272 276
277 /* set client_data to avoid UMR warning from tools like Purify */
278 sp->cinfo.d.client_data = NULL;
279
273 return CALLVJPEG(sp, jpeg_create_decompress(&sp->cinfo.d)); 280 return CALLVJPEG(sp, jpeg_create_decompress(&sp->cinfo.d));
274 } 281 }
275 282
276 static int 283 static int
277 TIFFjpeg_set_defaults(JPEGState* sp) 284 TIFFjpeg_set_defaults(JPEGState* sp)
278 { 285 {
279 return CALLVJPEG(sp, jpeg_set_defaults(&sp->cinfo.c)); 286 return CALLVJPEG(sp, jpeg_set_defaults(&sp->cinfo.c));
280 } 287 }
281 288
282 static int 289 static int
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 665
659 666
660 /* 667 /*
661 * JPEG Decoding. 668 * JPEG Decoding.
662 */ 669 */
663 670
664 #ifdef CHECK_JPEG_YCBCR_SUBSAMPLING 671 #ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
665 672
666 #define JPEG_MARKER_SOF0 0xC0 673 #define JPEG_MARKER_SOF0 0xC0
667 #define JPEG_MARKER_SOF1 0xC1 674 #define JPEG_MARKER_SOF1 0xC1
668 #define JPEG_MARKER_SOF3 0xC3 675 #define JPEG_MARKER_SOF2 0xC2
676 #define JPEG_MARKER_SOF9 0xC9
677 #define JPEG_MARKER_SOF10 0xCA
669 #define JPEG_MARKER_DHT 0xC4 678 #define JPEG_MARKER_DHT 0xC4
670 #define JPEG_MARKER_SOI 0xD8 679 #define JPEG_MARKER_SOI 0xD8
671 #define JPEG_MARKER_SOS 0xDA 680 #define JPEG_MARKER_SOS 0xDA
672 #define JPEG_MARKER_DQT 0xDB 681 #define JPEG_MARKER_DQT 0xDB
673 #define JPEG_MARKER_DRI 0xDD 682 #define JPEG_MARKER_DRI 0xDD
674 #define JPEG_MARKER_APP0 0xE0 683 #define JPEG_MARKER_APP0 0xE0
675 #define JPEG_MARKER_COM 0xFE 684 #define JPEG_MARKER_COM 0xFE
676 struct JPEGFixupTagsSubsamplingData 685 struct JPEGFixupTagsSubsamplingData
677 { 686 {
678 TIFF* tif; 687 TIFF* tif;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 * 738 *
730 * Frank Warmerdam, July 2002 739 * Frank Warmerdam, July 2002
731 * Joris Van Damme, May 2007 740 * Joris Van Damme, May 2007
732 */ 741 */
733 static const char module[] = "JPEGFixupTagsSubsampling"; 742 static const char module[] = "JPEGFixupTagsSubsampling";
734 struct JPEGFixupTagsSubsamplingData m; 743 struct JPEGFixupTagsSubsamplingData m;
735 744
736 _TIFFFillStriles( tif ); 745 _TIFFFillStriles( tif );
737 746
738 if( tif->tif_dir.td_stripbytecount == NULL 747 if( tif->tif_dir.td_stripbytecount == NULL
748 || tif->tif_dir.td_stripoffset == NULL
739 || tif->tif_dir.td_stripbytecount[0] == 0 ) 749 || tif->tif_dir.td_stripbytecount[0] == 0 )
740 { 750 {
741 /* Do not even try to check if the first strip/tile does not 751 /* Do not even try to check if the first strip/tile does not
742 yet exist, as occurs when GDAL has created a new NULL file 752 yet exist, as occurs when GDAL has created a new NULL file
743 for instance. */ 753 for instance. */
744 return; 754 return;
745 } 755 }
746 756
747 m.tif=tif; 757 m.tif=tif;
748 m.buffersize=2048; 758 m.buffersize=2048;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 uint16 n; 826 uint16 n;
817 if (!JPEGFixupTagsSubsamplingReadWord(da ta,&n)) 827 if (!JPEGFixupTagsSubsamplingReadWord(da ta,&n))
818 return(0); 828 return(0);
819 if (n<2) 829 if (n<2)
820 return(0); 830 return(0);
821 n-=2; 831 n-=2;
822 if (n>0) 832 if (n>0)
823 JPEGFixupTagsSubsamplingSkip(dat a,n); 833 JPEGFixupTagsSubsamplingSkip(dat a,n);
824 } 834 }
825 break; 835 break;
826 » » » case JPEG_MARKER_SOF0: 836 » » » case JPEG_MARKER_SOF0: /* Baseline sequential Huffman */
827 » » » case JPEG_MARKER_SOF1: 837 » » » case JPEG_MARKER_SOF1: /* Extended sequential Huffman */
838 » » » case JPEG_MARKER_SOF2: /* Progressive Huffman: normally not allowed by TechNote, but that doesn't hurt supporting it */
839 » » » case JPEG_MARKER_SOF9: /* Extended sequential arithmetic */
840 » » » case JPEG_MARKER_SOF10: /* Progressive arithmetic: norma lly not allowed by TechNote, but that doesn't hurt supporting it */
828 /* this marker contains the subsampling factors we're scanning for */ 841 /* this marker contains the subsampling factors we're scanning for */
829 { 842 {
830 uint16 n; 843 uint16 n;
831 uint16 o; 844 uint16 o;
832 uint8 p; 845 uint8 p;
833 uint8 ph,pv; 846 uint8 ph,pv;
834 if (!JPEGFixupTagsSubsamplingReadWord(da ta,&n)) 847 if (!JPEGFixupTagsSubsamplingReadWord(da ta,&n))
835 return(0); 848 return(0);
836 if (n!=8+data->tif->tif_dir.td_samplespe rpixel*3) 849 if (n!=8+data->tif->tif_dir.td_samplespe rpixel*3)
837 return(0); 850 return(0);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 1005
993 /* Set up for reading normal data */ 1006 /* Set up for reading normal data */
994 TIFFjpeg_data_src(sp, tif); 1007 TIFFjpeg_data_src(sp, tif);
995 tif->tif_postdecode = _TIFFNoPostDecode; /* override byte swapping */ 1008 tif->tif_postdecode = _TIFFNoPostDecode; /* override byte swapping */
996 return (1); 1009 return (1);
997 } 1010 }
998 1011
999 /* 1012 /*
1000 * Set up for decoding a strip or tile. 1013 * Set up for decoding a strip or tile.
1001 */ 1014 */
1002 static int 1015 /*ARGSUSED*/ static int
1003 JPEGPreDecode(TIFF* tif, uint16 s) 1016 JPEGPreDecode(TIFF* tif, uint16 s)
1004 { 1017 {
1005 JPEGState *sp = JState(tif); 1018 JPEGState *sp = JState(tif);
1006 TIFFDirectory *td = &tif->tif_dir; 1019 TIFFDirectory *td = &tif->tif_dir;
1007 static const char module[] = "JPEGPreDecode"; 1020 static const char module[] = "JPEGPreDecode";
1008 uint32 segment_width, segment_height; 1021 uint32 segment_width, segment_height;
1009 int downsampled_output; 1022 int downsampled_output;
1010 int ci; 1023 int ci;
1011 1024
1012 assert(sp != NULL); 1025 assert(sp != NULL);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 return (0); 1181 return (0);
1169 sp->scancount = DCTSIZE; /* mark buffer empty */ 1182 sp->scancount = DCTSIZE; /* mark buffer empty */
1170 } 1183 }
1171 return (1); 1184 return (1);
1172 } 1185 }
1173 1186
1174 /* 1187 /*
1175 * Decode a chunk of pixels. 1188 * Decode a chunk of pixels.
1176 * "Standard" case: returned data is not downsampled. 1189 * "Standard" case: returned data is not downsampled.
1177 */ 1190 */
1178 /*ARGSUSED*/ static int 1191 #if !JPEG_LIB_MK1_OR_12BIT
1192 static int
1179 JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) 1193 JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
1180 { 1194 {
1181 JPEGState *sp = JState(tif); 1195 JPEGState *sp = JState(tif);
1182 tmsize_t nrows; 1196 tmsize_t nrows;
1183 (void) s; 1197 (void) s;
1184 1198
1185 /* 1199 /*
1186 ** Update available information, buffer may have been refilled 1200 ** Update available information, buffer may have been refilled
1187 ** between decode requests 1201 ** between decode requests
1188 */ 1202 */
1189 sp->src.next_input_byte = (const JOCTET*) tif->tif_rawcp; 1203 sp->src.next_input_byte = (const JOCTET*) tif->tif_rawcp;
1190 sp->src.bytes_in_buffer = (size_t) tif->tif_rawcc; 1204 sp->src.bytes_in_buffer = (size_t) tif->tif_rawcc;
1191 1205
1192 if( sp->bytesperline == 0 ) 1206 if( sp->bytesperline == 0 )
1193 return 0; 1207 return 0;
1194 1208
1195 nrows = cc / sp->bytesperline; 1209 nrows = cc / sp->bytesperline;
1196 if (cc % sp->bytesperline) 1210 if (cc % sp->bytesperline)
1197 » » TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional s canline not read"); 1211 » » TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
1212 "fractional scanline not read");
1198 1213
1199 if( nrows > (tmsize_t) sp->cinfo.d.image_height ) 1214 if( nrows > (tmsize_t) sp->cinfo.d.image_height )
1200 nrows = sp->cinfo.d.image_height; 1215 nrows = sp->cinfo.d.image_height;
1201 1216
1202 /* data is expected to be read in multiples of a scanline */ 1217 /* data is expected to be read in multiples of a scanline */
1203 if (nrows) 1218 if (nrows)
1204 » { 1219 {
1205 » » JSAMPROW line_work_buf = NULL; 1220 do
1221 {
1222 /*
1223 * In the libjpeg6b-9a 8bit case. We read directly into
1224 * the TIFF buffer.
1225 */
1226 JSAMPROW bufptr = (JSAMPROW)buf;
1206 1227
1207 » » /* 1228 if (TIFFjpeg_read_scanlines(sp, &bufptr, 1) != 1)
1208 » » * For 6B, only use temporary buffer for 12 bit imagery. 1229 return (0);
1209 » » * For Mk1 always use it.
1210 » » */
1211 #if !defined(JPEG_LIB_MK1)
1212 » » if( sp->cinfo.d.data_precision == 12 )
1213 #endif
1214 » » {
1215 » » » line_work_buf = (JSAMPROW)
1216 » » » _TIFFmalloc(sizeof(short) * sp->cinfo.d.output_width
1217 » » » * sp->cinfo.d.num_components );
1218 » » }
1219 1230
1220 » » do { 1231 ++tif->tif_row;
1221 » » » if( line_work_buf != NULL ) 1232 buf += sp->bytesperline;
1222 » » » { 1233 cc -= sp->bytesperline;
1223 » » » » /* 1234 } while (--nrows > 0);
1224 » » » » * In the MK1 case, we aways read into a 16bit b uffer, and then 1235 }
1225 » » » » * pack down to 12bit or 8bit. In 6B case we on ly read into 16
1226 » » » » * bit buffer for 12bit data, which we need to r epack.
1227 » » » » */
1228 » » » » if (TIFFjpeg_read_scanlines(sp, &line_work_buf, 1) != 1)
1229 » » » » » return (0);
1230
1231 » » » » if( sp->cinfo.d.data_precision == 12 )
1232 » » » » {
1233 » » » » » int value_pairs = (sp->cinfo.d.output_wi dth
1234 » » » » » * sp->cinfo.d.num_components) / 2;
1235 » » » » » int iPair;
1236
1237 » » » » » for( iPair = 0; iPair < value_pairs; iPa ir++ )
1238 » » » » » {
1239 » » » » » » unsigned char *out_ptr =
1240 » » » » » » ((unsigned char *) buf) + iP air * 3;
1241 » » » » » » JSAMPLE *in_ptr = line_work_buf + iPair * 2;
1242
1243 » » » » » » out_ptr[0] = (in_ptr[0] & 0xff0) >> 4;
1244 » » » » » » out_ptr[1] = ((in_ptr[0] & 0xf) << 4)
1245 » » » » » » | ((in_ptr[1] & 0xf00) >> 8) ;
1246 » » » » » » out_ptr[2] = ((in_ptr[1] & 0xff) >> 0);
1247 » » » » » }
1248 » » » » }
1249 » » » » else if( sp->cinfo.d.data_precision == 8 )
1250 » » » » {
1251 » » » » » int value_count = (sp->cinfo.d.output_wi dth
1252 » » » » » * sp->cinfo.d.num_components);
1253 » » » » » int iValue;
1254
1255 » » » » » for( iValue = 0; iValue < value_count; i Value++ )
1256 » » » » » {
1257 » » » » » » ((unsigned char *) buf)[iValue] =
1258 » » » » » » line_work_buf[iValue] & 0xff ;
1259 » » » » » }
1260 » » » » }
1261 » » » }
1262 » » » else
1263 » » » {
1264 » » » » /*
1265 » » » » * In the libjpeg6b 8bit case. We read directly into the
1266 » » » » * TIFF buffer.
1267 » » » » */
1268 » » » » JSAMPROW bufptr = (JSAMPROW)buf;
1269
1270 » » » » if (TIFFjpeg_read_scanlines(sp, &bufptr, 1) != 1 )
1271 » » » » » return (0);
1272 » » » }
1273
1274 » » » ++tif->tif_row;
1275 » » » buf += sp->bytesperline;
1276 » » » cc -= sp->bytesperline;
1277 » » } while (--nrows > 0);
1278
1279 » » if( line_work_buf != NULL )
1280 » » » _TIFFfree( line_work_buf );
1281 » }
1282 1236
1283 /* Update information on consumed data */ 1237 /* Update information on consumed data */
1284 tif->tif_rawcp = (uint8*) sp->src.next_input_byte; 1238 tif->tif_rawcp = (uint8*) sp->src.next_input_byte;
1239 tif->tif_rawcc = sp->src.bytes_in_buffer;
1240
1241 /* Close down the decompressor if we've finished the strip or tile. */
1242 return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height
1243 || TIFFjpeg_finish_decompress(sp);
1244 }
1245 #endif /* !JPEG_LIB_MK1_OR_12BIT */
1246
1247 #if JPEG_LIB_MK1_OR_12BIT
1248 /*ARGSUSED*/ static int
1249 JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
1250 {
1251 JPEGState *sp = JState(tif);
1252 tmsize_t nrows;
1253 (void) s;
1254
1255 /*
1256 ** Update available information, buffer may have been refilled
1257 ** between decode requests
1258 */
1259 sp->src.next_input_byte = (const JOCTET*) tif->tif_rawcp;
1260 sp->src.bytes_in_buffer = (size_t) tif->tif_rawcc;
1261
1262 if( sp->bytesperline == 0 )
1263 return 0;
1264
1265 nrows = cc / sp->bytesperline;
1266 if (cc % sp->bytesperline)
1267 TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
1268 "fractional scanline not read");
1269
1270 if( nrows > (tmsize_t) sp->cinfo.d.image_height )
1271 nrows = sp->cinfo.d.image_height;
1272
1273 /* data is expected to be read in multiples of a scanline */
1274 if (nrows)
1275 {
1276 JSAMPROW line_work_buf = NULL;
1277
1278 /*
1279 * For 6B, only use temporary buffer for 12 bit imagery.
1280 * For Mk1 always use it.
1281 */
1282 if( sp->cinfo.d.data_precision == 12 )
1283 {
1284 line_work_buf = (JSAMPROW)
1285 _TIFFmalloc(sizeof(short) * sp->cinfo.d.output_w idth
1286 * sp->cinfo.d.num_components );
1287 }
1288
1289 do
1290 {
1291 if( line_work_buf != NULL )
1292 {
1293 /*
1294 * In the MK1 case, we aways read into a 16bit
1295 * buffer, and then pack down to 12bit or 8bit.
1296 * In 6B case we only read into 16 bit buffer
1297 * for 12bit data, which we need to repack.
1298 */
1299 if (TIFFjpeg_read_scanlines(sp, &line_work_buf, 1 ) != 1)
1300 return (0);
1301
1302 if( sp->cinfo.d.data_precision == 12 )
1303 {
1304 int value_pairs = (sp->cinfo.d.output_wid th
1305 * sp->cinfo.d.num_comp onents) / 2;
1306 int iPair;
1307
1308 for( iPair = 0; iPair < value_pairs; iPai r++ )
1309 {
1310 unsigned char *out_ptr =
1311 ((unsigned char *) buf) + iPair * 3;
1312 JSAMPLE *in_ptr = line_work_buf + iPair * 2;
1313
1314 out_ptr[0] = (in_ptr[0] & 0xff0) >> 4;
1315 out_ptr[1] = ((in_ptr[0] & 0xf) < < 4)
1316 | ((in_ptr[1] & 0xf00) >> 8);
1317 out_ptr[2] = ((in_ptr[1] & 0xff) >> 0);
1318 }
1319 }
1320 else if( sp->cinfo.d.data_precision == 8 )
1321 {
1322 int value_count = (sp->cinfo.d.output_wid th
1323 * sp->cinfo.d.num_comp onents);
1324 int iValue;
1325
1326 for( iValue = 0; iValue < value_count; iV alue++ )
1327 {
1328 ((unsigned char *) buf)[iValue] =
1329 line_work_buf[iValue] & 0 xff;
1330 }
1331 }
1332 }
1333
1334 ++tif->tif_row;
1335 buf += sp->bytesperline;
1336 cc -= sp->bytesperline;
1337 } while (--nrows > 0);
1338
1339 if( line_work_buf != NULL )
1340 _TIFFfree( line_work_buf );
1341 }
1342
1343 /* Update information on consumed data */
1344 tif->tif_rawcp = (uint8*) sp->src.next_input_byte;
1285 tif->tif_rawcc = sp->src.bytes_in_buffer; 1345 tif->tif_rawcc = sp->src.bytes_in_buffer;
1286 1346
1287 /* Close down the decompressor if we've finished the strip or tile. */ 1347 /* Close down the decompressor if we've finished the strip or tile. */
1288 return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height 1348 return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height
1289 » || TIFFjpeg_finish_decompress(sp); 1349 || TIFFjpeg_finish_decompress(sp);
1290 } 1350 }
1351 #endif /* JPEG_LIB_MK1_OR_12BIT */
1291 1352
1292 /*ARGSUSED*/ static int 1353 /*ARGSUSED*/ static int
1293 DecodeRowError(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) 1354 DecodeRowError(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
1294 1355
1295 { 1356 {
1296 (void) buf; 1357 (void) buf;
1297 (void) cc; 1358 (void) cc;
1298 (void) s; 1359 (void) s;
1299 1360
1300 TIFFErrorExt(tif->tif_clientdata, "TIFFReadScanline", 1361 TIFFErrorExt(tif->tif_clientdata, "TIFFReadScanline",
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 static void 1512 static void
1452 unsuppress_quant_table (JPEGState* sp, int tblno) 1513 unsuppress_quant_table (JPEGState* sp, int tblno)
1453 { 1514 {
1454 JQUANT_TBL* qtbl; 1515 JQUANT_TBL* qtbl;
1455 1516
1456 if ((qtbl = sp->cinfo.c.quant_tbl_ptrs[tblno]) != NULL) 1517 if ((qtbl = sp->cinfo.c.quant_tbl_ptrs[tblno]) != NULL)
1457 qtbl->sent_table = FALSE; 1518 qtbl->sent_table = FALSE;
1458 } 1519 }
1459 1520
1460 static void 1521 static void
1522 suppress_quant_table (JPEGState* sp, int tblno)
1523 {
1524 JQUANT_TBL* qtbl;
1525
1526 if ((qtbl = sp->cinfo.c.quant_tbl_ptrs[tblno]) != NULL)
1527 qtbl->sent_table = TRUE;
1528 }
1529
1530 static void
1461 unsuppress_huff_table (JPEGState* sp, int tblno) 1531 unsuppress_huff_table (JPEGState* sp, int tblno)
1462 { 1532 {
1463 JHUFF_TBL* htbl; 1533 JHUFF_TBL* htbl;
1464 1534
1465 if ((htbl = sp->cinfo.c.dc_huff_tbl_ptrs[tblno]) != NULL) 1535 if ((htbl = sp->cinfo.c.dc_huff_tbl_ptrs[tblno]) != NULL)
1466 htbl->sent_table = FALSE; 1536 htbl->sent_table = FALSE;
1467 if ((htbl = sp->cinfo.c.ac_huff_tbl_ptrs[tblno]) != NULL) 1537 if ((htbl = sp->cinfo.c.ac_huff_tbl_ptrs[tblno]) != NULL)
1468 htbl->sent_table = FALSE; 1538 htbl->sent_table = FALSE;
1469 } 1539 }
1470 1540
1541 static void
1542 suppress_huff_table (JPEGState* sp, int tblno)
1543 {
1544 JHUFF_TBL* htbl;
1545
1546 if ((htbl = sp->cinfo.c.dc_huff_tbl_ptrs[tblno]) != NULL)
1547 htbl->sent_table = TRUE;
1548 if ((htbl = sp->cinfo.c.ac_huff_tbl_ptrs[tblno]) != NULL)
1549 htbl->sent_table = TRUE;
1550 }
1551
1471 static int 1552 static int
1472 prepare_JPEGTables(TIFF* tif) 1553 prepare_JPEGTables(TIFF* tif)
1473 { 1554 {
1474 JPEGState* sp = JState(tif); 1555 JPEGState* sp = JState(tif);
1475 1556
1476 /* Initialize quant tables for current quality setting */ 1557 /* Initialize quant tables for current quality setting */
1477 if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE)) 1558 if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
1478 return (0); 1559 return (0);
1479 /* Mark only the tables we want for output */ 1560 /* Mark only the tables we want for output */
1480 /* NB: chrominance tables are currently used only with YCbCr */ 1561 /* NB: chrominance tables are currently used only with YCbCr */
(...skipping 29 matching lines...) Expand all
1510 #if defined(JPEG_DUAL_MODE_8_12) && !defined(TIFFInitJPEG) 1591 #if defined(JPEG_DUAL_MODE_8_12) && !defined(TIFFInitJPEG)
1511 if( tif->tif_dir.td_bitspersample == 12 ) 1592 if( tif->tif_dir.td_bitspersample == 12 )
1512 return TIFFReInitJPEG_12( tif, COMPRESSION_JPEG, 1 ); 1593 return TIFFReInitJPEG_12( tif, COMPRESSION_JPEG, 1 );
1513 #endif 1594 #endif
1514 1595
1515 JPEGInitializeLibJPEG( tif, FALSE ); 1596 JPEGInitializeLibJPEG( tif, FALSE );
1516 1597
1517 assert(sp != NULL); 1598 assert(sp != NULL);
1518 assert(!sp->cinfo.comm.is_decompressor); 1599 assert(!sp->cinfo.comm.is_decompressor);
1519 1600
1601 sp->photometric = td->td_photometric;
1602
1520 /* 1603 /*
1521 * Initialize all JPEG parameters to default values. 1604 * Initialize all JPEG parameters to default values.
1522 * Note that jpeg_set_defaults needs legal values for 1605 * Note that jpeg_set_defaults needs legal values for
1523 * in_color_space and input_components. 1606 * in_color_space and input_components.
1524 */ 1607 */
1525 » sp->cinfo.c.in_color_space = JCS_UNKNOWN; 1608 » if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
1526 » sp->cinfo.c.input_components = 1; 1609 » » sp->cinfo.c.input_components = td->td_samplesperpixel;
1610 » » if (sp->photometric == PHOTOMETRIC_YCBCR) {
1611 » » » if (sp->jpegcolormode == JPEGCOLORMODE_RGB) {
1612 » » » » sp->cinfo.c.in_color_space = JCS_RGB;
1613 » » » } else {
1614 » » » » sp->cinfo.c.in_color_space = JCS_YCbCr;
1615 » » » }
1616 » » } else {
1617 » » » if ((td->td_photometric == PHOTOMETRIC_MINISWHITE || td- >td_photometric == PHOTOMETRIC_MINISBLACK) && td->td_samplesperpixel == 1)
1618 » » » » sp->cinfo.c.in_color_space = JCS_GRAYSCALE;
1619 » » » else if (td->td_photometric == PHOTOMETRIC_RGB && td->td _samplesperpixel == 3)
1620 » » » » sp->cinfo.c.in_color_space = JCS_RGB;
1621 » » » else if (td->td_photometric == PHOTOMETRIC_SEPARATED && td->td_samplesperpixel == 4)
1622 » » » » sp->cinfo.c.in_color_space = JCS_CMYK;
1623 » » » else
1624 » » » » sp->cinfo.c.in_color_space = JCS_UNKNOWN;
1625 » » }
1626 » } else {
1627 » » sp->cinfo.c.input_components = 1;
1628 » » sp->cinfo.c.in_color_space = JCS_UNKNOWN;
1629 » }
1527 if (!TIFFjpeg_set_defaults(sp)) 1630 if (!TIFFjpeg_set_defaults(sp))
1528 return (0); 1631 return (0);
1529 /* Set per-file parameters */ 1632 /* Set per-file parameters */
1530 sp->photometric = td->td_photometric;
1531 switch (sp->photometric) { 1633 switch (sp->photometric) {
1532 case PHOTOMETRIC_YCBCR: 1634 case PHOTOMETRIC_YCBCR:
1533 sp->h_sampling = td->td_ycbcrsubsampling[0]; 1635 sp->h_sampling = td->td_ycbcrsubsampling[0];
1534 sp->v_sampling = td->td_ycbcrsubsampling[1]; 1636 sp->v_sampling = td->td_ycbcrsubsampling[1];
1535 /* 1637 /*
1536 * A ReferenceBlackWhite field *must* be present since the 1638 * A ReferenceBlackWhite field *must* be present since the
1537 * default value is inappropriate for YCbCr. Fill in the 1639 * default value is inappropriate for YCbCr. Fill in the
1538 * proper value if application didn't set it. 1640 * proper value if application didn't set it.
1539 */ 1641 */
1540 { 1642 {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 if (segment_width > 65535 || segment_height > 65535) { 1782 if (segment_width > 65535 || segment_height > 65535) {
1681 TIFFErrorExt(tif->tif_clientdata, module, "Strip/tile too large for JPEG"); 1783 TIFFErrorExt(tif->tif_clientdata, module, "Strip/tile too large for JPEG");
1682 return (0); 1784 return (0);
1683 } 1785 }
1684 sp->cinfo.c.image_width = segment_width; 1786 sp->cinfo.c.image_width = segment_width;
1685 sp->cinfo.c.image_height = segment_height; 1787 sp->cinfo.c.image_height = segment_height;
1686 downsampled_input = FALSE; 1788 downsampled_input = FALSE;
1687 if (td->td_planarconfig == PLANARCONFIG_CONTIG) { 1789 if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
1688 sp->cinfo.c.input_components = td->td_samplesperpixel; 1790 sp->cinfo.c.input_components = td->td_samplesperpixel;
1689 if (sp->photometric == PHOTOMETRIC_YCBCR) { 1791 if (sp->photometric == PHOTOMETRIC_YCBCR) {
1690 » » » if (sp->jpegcolormode == JPEGCOLORMODE_RGB) { 1792 » » » if (sp->jpegcolormode != JPEGCOLORMODE_RGB) {
1691 » » » » sp->cinfo.c.in_color_space = JCS_RGB;
1692 » » » } else {
1693 » » » » sp->cinfo.c.in_color_space = JCS_YCbCr;
1694 if (sp->h_sampling != 1 || sp->v_sampling != 1) 1793 if (sp->h_sampling != 1 || sp->v_sampling != 1)
1695 downsampled_input = TRUE; 1794 downsampled_input = TRUE;
1696 } 1795 }
1697 if (!TIFFjpeg_set_colorspace(sp, JCS_YCbCr)) 1796 if (!TIFFjpeg_set_colorspace(sp, JCS_YCbCr))
1698 return (0); 1797 return (0);
1699 /* 1798 /*
1700 * Set Y sampling factors; 1799 * Set Y sampling factors;
1701 * we assume jpeg_set_colorspace() set the rest to 1 1800 * we assume jpeg_set_colorspace() set the rest to 1
1702 */ 1801 */
1703 sp->cinfo.c.comp_info[0].h_samp_factor = sp->h_sampling; 1802 sp->cinfo.c.comp_info[0].h_samp_factor = sp->h_sampling;
1704 sp->cinfo.c.comp_info[0].v_samp_factor = sp->v_sampling; 1803 sp->cinfo.c.comp_info[0].v_samp_factor = sp->v_sampling;
1705 } else { 1804 } else {
1706 if ((td->td_photometric == PHOTOMETRIC_MINISWHITE || td- >td_photometric == PHOTOMETRIC_MINISBLACK) && td->td_samplesperpixel == 1)
1707 sp->cinfo.c.in_color_space = JCS_GRAYSCALE;
1708 else if (td->td_photometric == PHOTOMETRIC_RGB && td->td _samplesperpixel == 3)
1709 sp->cinfo.c.in_color_space = JCS_RGB;
1710 else if (td->td_photometric == PHOTOMETRIC_SEPARATED && td->td_samplesperpixel == 4)
1711 sp->cinfo.c.in_color_space = JCS_CMYK;
1712 else
1713 sp->cinfo.c.in_color_space = JCS_UNKNOWN;
1714 if (!TIFFjpeg_set_colorspace(sp, sp->cinfo.c.in_color_sp ace)) 1805 if (!TIFFjpeg_set_colorspace(sp, sp->cinfo.c.in_color_sp ace))
1715 return (0); 1806 return (0);
1716 /* jpeg_set_colorspace set all sampling factors to 1 */ 1807 /* jpeg_set_colorspace set all sampling factors to 1 */
1717 } 1808 }
1718 } else { 1809 } else {
1719 sp->cinfo.c.input_components = 1;
1720 sp->cinfo.c.in_color_space = JCS_UNKNOWN;
1721 if (!TIFFjpeg_set_colorspace(sp, JCS_UNKNOWN)) 1810 if (!TIFFjpeg_set_colorspace(sp, JCS_UNKNOWN))
1722 return (0); 1811 return (0);
1723 sp->cinfo.c.comp_info[0].component_id = s; 1812 sp->cinfo.c.comp_info[0].component_id = s;
1724 /* jpeg_set_colorspace() set sampling factors to 1 */ 1813 /* jpeg_set_colorspace() set sampling factors to 1 */
1725 if (sp->photometric == PHOTOMETRIC_YCBCR && s > 0) { 1814 if (sp->photometric == PHOTOMETRIC_YCBCR && s > 0) {
1726 sp->cinfo.c.comp_info[0].quant_tbl_no = 1; 1815 sp->cinfo.c.comp_info[0].quant_tbl_no = 1;
1727 sp->cinfo.c.comp_info[0].dc_tbl_no = 1; 1816 sp->cinfo.c.comp_info[0].dc_tbl_no = 1;
1728 sp->cinfo.c.comp_info[0].ac_tbl_no = 1; 1817 sp->cinfo.c.comp_info[0].ac_tbl_no = 1;
1729 } 1818 }
1730 } 1819 }
1731 /* ensure libjpeg won't write any extraneous markers */ 1820 /* ensure libjpeg won't write any extraneous markers */
1732 sp->cinfo.c.write_JFIF_header = FALSE; 1821 sp->cinfo.c.write_JFIF_header = FALSE;
1733 sp->cinfo.c.write_Adobe_marker = FALSE; 1822 sp->cinfo.c.write_Adobe_marker = FALSE;
1734 /* set up table handling correctly */ 1823 /* set up table handling correctly */
1735 if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE)) 1824 » /* calling TIFFjpeg_set_quality() causes quantization tables to be flagg ed */
1825 » /* as being to be emitted, which we don't want in the JPEGTABLESMODE_QUA NT */
1826 » /* mode, so we must manually suppress them. However TIFFjpeg_set_quality () */
1827 » /* should really be called when dealing with files with directories with */
1828 » /* mixed qualities. see http://trac.osgeo.org/gdal/ticket/3539 */
1829 » if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
1736 return (0); 1830 return (0);
1737 » if (! (sp->jpegtablesmode & JPEGTABLESMODE_QUANT)) { 1831 » if (sp->jpegtablesmode & JPEGTABLESMODE_QUANT) {
1832 » » suppress_quant_table(sp, 0);
1833 » » suppress_quant_table(sp, 1);
1834 » }
1835 » else {
1738 unsuppress_quant_table(sp, 0); 1836 unsuppress_quant_table(sp, 0);
1739 unsuppress_quant_table(sp, 1); 1837 unsuppress_quant_table(sp, 1);
1740 } 1838 }
1741 if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF) 1839 if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF)
1840 {
1841 /* Explicit suppression is only needed if we did not go through the */
1842 /* prepare_JPEGTables() code path, which may be the case if upda ting */
1843 /* an existing file */
1844 suppress_huff_table(sp, 0);
1845 suppress_huff_table(sp, 1);
1742 sp->cinfo.c.optimize_coding = FALSE; 1846 sp->cinfo.c.optimize_coding = FALSE;
1847 }
1743 else 1848 else
1744 sp->cinfo.c.optimize_coding = TRUE; 1849 sp->cinfo.c.optimize_coding = TRUE;
1745 if (downsampled_input) { 1850 if (downsampled_input) {
1746 /* Need to use raw-data interface to libjpeg */ 1851 /* Need to use raw-data interface to libjpeg */
1747 sp->cinfo.c.raw_data_in = TRUE; 1852 sp->cinfo.c.raw_data_in = TRUE;
1748 tif->tif_encoderow = JPEGEncodeRaw; 1853 tif->tif_encoderow = JPEGEncodeRaw;
1749 tif->tif_encodestrip = JPEGEncodeRaw; 1854 tif->tif_encodestrip = JPEGEncodeRaw;
1750 tif->tif_encodetile = JPEGEncodeRaw; 1855 tif->tif_encodetile = JPEGEncodeRaw;
1751 } else { 1856 } else {
1752 /* Use normal interface to libjpeg */ 1857 /* Use normal interface to libjpeg */
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 if (cc % sp->bytesperline) 1894 if (cc % sp->bytesperline)
1790 TIFFWarningExt(tif->tif_clientdata, tif->tif_name, 1895 TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
1791 "fractional scanline discarded"); 1896 "fractional scanline discarded");
1792 1897
1793 /* The last strip will be limited to image size */ 1898 /* The last strip will be limited to image size */
1794 if( !isTiled(tif) && tif->tif_row+nrows > tif->tif_dir.td_imagelength ) 1899 if( !isTiled(tif) && tif->tif_row+nrows > tif->tif_dir.td_imagelength )
1795 nrows = tif->tif_dir.td_imagelength - tif->tif_row; 1900 nrows = tif->tif_dir.td_imagelength - tif->tif_row;
1796 1901
1797 if( sp->cinfo.c.data_precision == 12 ) 1902 if( sp->cinfo.c.data_precision == 12 )
1798 { 1903 {
1799 line16_count = (int)((sp->bytesperline * 2) / 3); 1904 line16_count = (sp->bytesperline * 2) / 3;
1800 line16 = (short *) _TIFFmalloc(sizeof(short) * line16_count); 1905 line16 = (short *) _TIFFmalloc(sizeof(short) * line16_count);
1801 » // FIXME: undiagnosed malloc failure 1906 if (!line16)
1907 {
1908 TIFFErrorExt(tif->tif_clientdata,
1909 » » » "JPEGEncode",
1910 "Failed to allocate memory");
1911
1912 return 0;
1913 }
1802 } 1914 }
1803 1915
1804 while (nrows-- > 0) { 1916 while (nrows-- > 0) {
1805 1917
1806 if( sp->cinfo.c.data_precision == 12 ) 1918 if( sp->cinfo.c.data_precision == 12 )
1807 { 1919 {
1808 1920
1809 int value_pairs = line16_count / 2; 1921 int value_pairs = line16_count / 2;
1810 int iPair; 1922 int iPair;
1811 1923
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 static void 2078 static void
1967 JPEGCleanup(TIFF* tif) 2079 JPEGCleanup(TIFF* tif)
1968 { 2080 {
1969 JPEGState *sp = JState(tif); 2081 JPEGState *sp = JState(tif);
1970 2082
1971 assert(sp != 0); 2083 assert(sp != 0);
1972 2084
1973 tif->tif_tagmethods.vgetfield = sp->vgetparent; 2085 tif->tif_tagmethods.vgetfield = sp->vgetparent;
1974 tif->tif_tagmethods.vsetfield = sp->vsetparent; 2086 tif->tif_tagmethods.vsetfield = sp->vsetparent;
1975 tif->tif_tagmethods.printdir = sp->printdir; 2087 tif->tif_tagmethods.printdir = sp->printdir;
1976 2088 if( sp->cinfo_initialized )
1977 » if( sp != NULL ) { 2089 TIFFjpeg_destroy(sp);» /* release libjpeg resources */
1978 » » if( sp->cinfo_initialized ) 2090 if (sp->jpegtables)» » /* tag value */
1979 » » TIFFjpeg_destroy(sp);» /* release libjpeg resources */ 2091 _TIFFfree(sp->jpegtables);
1980 » » if (sp->jpegtables)» » /* tag value */
1981 » » » _TIFFfree(sp->jpegtables);
1982 » }
1983 _TIFFfree(tif->tif_data); /* release local state */ 2092 _TIFFfree(tif->tif_data); /* release local state */
1984 tif->tif_data = NULL; 2093 tif->tif_data = NULL;
1985 2094
1986 _TIFFSetDefaultCompressionState(tif); 2095 _TIFFSetDefaultCompressionState(tif);
1987 } 2096 }
1988 2097
1989 static void 2098 static void
1990 JPEGResetUpsampled( TIFF* tif ) 2099 JPEGResetUpsampled( TIFF* tif )
1991 { 2100 {
1992 JPEGState* sp = JState(tif); 2101 JPEGState* sp = JState(tif);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
2284 /* 2393 /*
2285 The following line assumes incorrectly that all JPEG-in-TIFF files will have 2394 The following line assumes incorrectly that all JPEG-in-TIFF files will have
2286 a JPEGTABLES tag generated and causes null-filled JPEGTABLES tags to be written 2395 a JPEGTABLES tag generated and causes null-filled JPEGTABLES tags to be written
2287 when the JPEG data is placed with TIFFWriteRawStrip. The field bit should be 2396 when the JPEG data is placed with TIFFWriteRawStrip. The field bit should be
2288 set, anyway, later when actual JPEGTABLES header is generated, so removing it 2397 set, anyway, later when actual JPEGTABLES header is generated, so removing it
2289 here hopefully is harmless. 2398 here hopefully is harmless.
2290 TIFFSetFieldBit(tif, FIELD_JPEGTABLES); 2399 TIFFSetFieldBit(tif, FIELD_JPEGTABLES);
2291 */ 2400 */
2292 sp->jpegtables_length = SIZE_OF_JPEGTABLES; 2401 sp->jpegtables_length = SIZE_OF_JPEGTABLES;
2293 sp->jpegtables = (void *) _TIFFmalloc(sp->jpegtables_length); 2402 sp->jpegtables = (void *) _TIFFmalloc(sp->jpegtables_length);
2294 » // FIXME: NULL-deref after malloc failure 2403 if (sp->jpegtables)
2295 » _TIFFmemset(sp->jpegtables, 0, SIZE_OF_JPEGTABLES); 2404 {
2405 _TIFFmemset(sp->jpegtables, 0, SIZE_OF_JPEGTABLES);
2406 }
2407 else
2408 {
2409 TIFFErrorExt(tif->tif_clientdata,
2410 » » » "TIFFInitJPEG",
2411 "Failed to allocate memory for JPEG tables");
2412 return 0;
2413 }
2296 #undef SIZE_OF_JPEGTABLES 2414 #undef SIZE_OF_JPEGTABLES
2297 } 2415 }
2298 2416
2299 return 1; 2417 return 1;
2300 } 2418 }
2301 #endif /* JPEG_SUPPORT */ 2419 #endif /* JPEG_SUPPORT */
2302 2420
2303 /* vim: set ts=8 sts=8 sw=8 noet: */ 2421 /* vim: set ts=8 sts=8 sw=8 noet: */
2304 2422
2305 /* 2423 /*
2306 * Local Variables: 2424 * Local Variables:
2307 * mode: c 2425 * mode: c
2308 * c-basic-offset: 8 2426 * c-basic-offset: 8
2309 * fill-column: 78 2427 * fill-column: 78
2310 * End: 2428 * End:
2311 */ 2429 */
2312
OLDNEW
« no previous file with comments | « third_party/libtiff/tif_getimage.c ('k') | third_party/libtiff/tif_luv.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698