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

Side by Side Diff: third_party/libtiff/tif_ojpeg.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_next.c ('k') | third_party/libtiff/tif_open.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_ojpeg.c,v 1.56 2012-05-24 03:15:18 fwarmerdam Exp $ */ 1 /* $Id: tif_ojpeg.c,v 1.60 2015-05-31 00:38:46 bfriesen Exp $ */
2 2
3 /* WARNING: The type of JPEG encapsulation defined by the TIFF Version 6.0 3 /* WARNING: The type of JPEG encapsulation defined by the TIFF Version 6.0
4 specification is now totally obsolete and deprecated for new applications and 4 specification is now totally obsolete and deprecated for new applications and
5 images. This file was was created solely in order to read unconverted images 5 images. This file was was created solely in order to read unconverted images
6 still present on some users' computer systems. It will never be extended 6 still present on some users' computer systems. It will never be extended
7 to write such files. Writing new-style JPEG compressed TIFFs is implemented 7 to write such files. Writing new-style JPEG compressed TIFFs is implemented
8 in tif_jpeg.c. 8 in tif_jpeg.c.
9 9
10 The code is carefully crafted to robustly read all gathered JPEG-in-TIFF 10 The code is carefully crafted to robustly read all gathered JPEG-in-TIFF
11 testfiles, and anticipate as much as possible all other... But still, it may 11 testfiles, and anticipate as much as possible all other... But still, it may
(...skipping 20 matching lines...) Expand all
32 library. 32 library.
33 33
34 IN NO EVENT SHALL JORIS VAN DAMME OR AWARE SYSTEMS BE LIABLE FOR 34 IN NO EVENT SHALL JORIS VAN DAMME OR AWARE SYSTEMS BE LIABLE FOR
35 ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 35 ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
36 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 36 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
37 WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 37 WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
38 LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 38 LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
39 OF THIS SOFTWARE. 39 OF THIS SOFTWARE.
40 40
41 Joris Van Damme and/or AWare Systems may be available for custom 41 Joris Van Damme and/or AWare Systems may be available for custom
42 developement. If you like what you see, and need anything similar or related, 42 development. If you like what you see, and need anything similar or related,
43 contact <info@awaresystems.be>. 43 contact <info@awaresystems.be>.
44 */ 44 */
45 45
46 /* What is what, and what is not? 46 /* What is what, and what is not?
47 47
48 This decoder starts with an input stream, that is essentially the JpegInterch angeFormat 48 This decoder starts with an input stream, that is essentially the JpegInterch angeFormat
49 stream, if any, followed by the strile data, if any. This stream is read in 49 stream, if any, followed by the strile data, if any. This stream is read in
50 OJPEGReadByte and related functions. 50 OJPEGReadByte and related functions.
51 51
52 It analyzes the start of this stream, until it encounters non-marker data, i. e. 52 It analyzes the start of this stream, until it encounters non-marker data, i. e.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 planarconfig is not separate (vast majority). We may one day use that to buil d 113 planarconfig is not separate (vast majority). We may one day use that to buil d
114 converters to JPEG, and/or to new-style JPEG compression inside TIFF. 114 converters to JPEG, and/or to new-style JPEG compression inside TIFF.
115 115
116 A dissadvantage is the lack of random access to the individual striles. This is the 116 A dissadvantage is the lack of random access to the individual striles. This is the
117 reason for much of the complicated restart-and-position stuff inside OJPEGPre Decode. 117 reason for much of the complicated restart-and-position stuff inside OJPEGPre Decode.
118 Applications would do well accessing all striles in order, as this will resul t in 118 Applications would do well accessing all striles in order, as this will resul t in
119 a single sequential scan of the input stream, and no restarting of LibJpeg de coding 119 a single sequential scan of the input stream, and no restarting of LibJpeg de coding
120 session. 120 session.
121 */ 121 */
122 122
123
124 #define WIN32_LEAN_AND_MEAN 123 #define WIN32_LEAN_AND_MEAN
125 #define VC_EXTRALEAN 124 #define VC_EXTRALEAN
126 125
127 #include "tiffiop.h" 126 #include "tiffiop.h"
128 #ifdef OJPEG_SUPPORT 127 #ifdef OJPEG_SUPPORT
129 128
130 /* Configuration defines here are: 129 /* Configuration defines here are:
131 * JPEG_ENCAP_EXTERNAL: The normal way to call libjpeg, uses longjump. In some e nvironments, 130 * JPEG_ENCAP_EXTERNAL: The normal way to call libjpeg, uses longjump. In some e nvironments,
132 * like eg LibTiffDelphi, this is not possible. For this reason, the actual calls to 131 * like eg LibTiffDelphi, this is not possible. For this reason, the actual calls to
133 * libjpeg, with longjump stuff, are encapsulated in dedicated functions. W hen 132 * libjpeg, with longjump stuff, are encapsulated in dedicated functions. W hen
134 * JPEG_ENCAP_EXTERNAL is defined, these encapsulating functions are declar ed external 133 * JPEG_ENCAP_EXTERNAL is defined, these encapsulating functions are declar ed external
135 * to this unit, and can be defined elsewhere to use stuff other then longj ump. 134 * to this unit, and can be defined elsewhere to use stuff other then longj ump.
136 * The default mode, without JPEG_ENCAP_EXTERNAL, implements the call encap sulators 135 * The default mode, without JPEG_ENCAP_EXTERNAL, implements the call encap sulators
137 * here, internally, with normal longjump. 136 * here, internally, with normal longjump.
138 * SETJMP, LONGJMP, JMP_BUF: On some machines/environments a longjump equivalent is 137 * SETJMP, LONGJMP, JMP_BUF: On some machines/environments a longjump equivalent is
139 * conviniently available, but still it may be worthwhile to use _setjmp or sigsetjmp 138 * conviniently available, but still it may be worthwhile to use _setjmp or sigsetjmp
140 * in place of plain setjmp. These macros will make it easier. It is useles s 139 * in place of plain setjmp. These macros will make it easier. It is useles s
141 * to fiddle with these if you define JPEG_ENCAP_EXTERNAL. 140 * to fiddle with these if you define JPEG_ENCAP_EXTERNAL.
142 * OJPEG_BUFFER: Define the size of the desired buffer here. Should be small eno ugh so as to guarantee 141 * OJPEG_BUFFER: Define the size of the desired buffer here. Should be small eno ugh so as to guarantee
143 * instant processing, optimal streaming and optimal use of processor cache , but also big 142 * instant processing, optimal streaming and optimal use of processor cache , but also big
144 * enough so as to not result in significant call overhead. It should be at least a few 143 * enough so as to not result in significant call overhead. It should be at least a few
145 * » bytes to accomodate some structures (this is verified in asserts), but i t would not be 144 * » bytes to accommodate some structures (this is verified in asserts), but it would not be
146 * sensible to make it this small anyway, and it should be at most 64K sinc e it is indexed 145 * sensible to make it this small anyway, and it should be at most 64K sinc e it is indexed
147 * with uint16. We recommend 2K. 146 * with uint16. We recommend 2K.
148 * EGYPTIANWALK: You could also define EGYPTIANWALK here, but it is not used any where and has 147 * EGYPTIANWALK: You could also define EGYPTIANWALK here, but it is not used any where and has
149 * absolutely no effect. That is why most people insist the EGYPTIANWALK is a bit silly. 148 * absolutely no effect. That is why most people insist the EGYPTIANWALK is a bit silly.
150 */ 149 */
151 150
152 /* define LIBJPEG_ENCAP_EXTERNAL */ 151 /* define LIBJPEG_ENCAP_EXTERNAL */
153 #define SETJMP(jbuf) setjmp(jbuf) 152 #define SETJMP(jbuf) setjmp(jbuf)
154 #define LONGJMP(jbuf,code) longjmp(jbuf,code) 153 #define LONGJMP(jbuf,code) longjmp(jbuf,code)
155 #define JMP_BUF jmp_buf 154 #define JMP_BUF jmp_buf
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 208
210 /* Define "boolean" as unsigned char, not int, per Windows custom. */ 209 /* Define "boolean" as unsigned char, not int, per Windows custom. */
211 #if defined(__WIN32__) && !defined(__MINGW32__) 210 #if defined(__WIN32__) && !defined(__MINGW32__)
212 # ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ 211 # ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
213 typedef unsigned char boolean; 212 typedef unsigned char boolean;
214 # endif 213 # endif
215 # define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ 214 # define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
216 #endif 215 #endif
217 216
218 #if defined(USE_SYSTEM_LIBJPEG) 217 #if defined(USE_SYSTEM_LIBJPEG)
218 #include <jerror.h>
219 #include <jpeglib.h> 219 #include <jpeglib.h>
220 #elif defined(USE_LIBJPEG_TURBO) 220 #elif defined(USE_LIBJPEG_TURBO)
221 #include "third_party/libjpeg_turbo/jerror.h"
221 #include "third_party/libjpeg_turbo/jpeglib.h" 222 #include "third_party/libjpeg_turbo/jpeglib.h"
222 #else 223 #else
224 #include "third_party/libjpeg/jerror.h"
223 #include "third_party/libjpeg/jpeglib.h" 225 #include "third_party/libjpeg/jpeglib.h"
224 #endif 226 #endif
225 227
228
226 typedef struct jpeg_error_mgr jpeg_error_mgr; 229 typedef struct jpeg_error_mgr jpeg_error_mgr;
227 typedef struct jpeg_common_struct jpeg_common_struct; 230 typedef struct jpeg_common_struct jpeg_common_struct;
228 typedef struct jpeg_decompress_struct jpeg_decompress_struct; 231 typedef struct jpeg_decompress_struct jpeg_decompress_struct;
229 typedef struct jpeg_source_mgr jpeg_source_mgr; 232 typedef struct jpeg_source_mgr jpeg_source_mgr;
230 233
231 typedef enum { 234 typedef enum {
232 osibsNotSetYet, 235 osibsNotSetYet,
233 osibsJpegInterchangeFormat, 236 osibsJpegInterchangeFormat,
234 osibsStrile, 237 osibsStrile,
235 osibsEof 238 osibsEof
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 /* 435 /*
433 * Merge codec-specific tag information. 436 * Merge codec-specific tag information.
434 */ 437 */
435 if (!_TIFFMergeFields(tif, ojpegFields, TIFFArrayCount(ojpegFields))) { 438 if (!_TIFFMergeFields(tif, ojpegFields, TIFFArrayCount(ojpegFields))) {
436 TIFFErrorExt(tif->tif_clientdata, module, 439 TIFFErrorExt(tif->tif_clientdata, module,
437 "Merging Old JPEG codec-specific tags failed"); 440 "Merging Old JPEG codec-specific tags failed");
438 return 0; 441 return 0;
439 } 442 }
440 443
441 /* state block */ 444 /* state block */
442 » sp = (OJPEGState*)_TIFFmalloc(sizeof(OJPEGState));» » // // ad d (OJPEGState*) cast 445 » sp=_TIFFmalloc(sizeof(OJPEGState));
443 » if (sp == NULL) 446 » if (sp==NULL)
444 { 447 {
445 TIFFErrorExt(tif->tif_clientdata,module,"No space for OJPEG stat e block"); 448 TIFFErrorExt(tif->tif_clientdata,module,"No space for OJPEG stat e block");
446 return(0); 449 return(0);
447 } 450 }
448 _TIFFmemset(sp,0,sizeof(OJPEGState)); 451 _TIFFmemset(sp,0,sizeof(OJPEGState));
449 sp->tif=tif; 452 sp->tif=tif;
450 sp->jpeg_proc=1; 453 sp->jpeg_proc=1;
451 sp->subsampling_hor=2; 454 sp->subsampling_hor=2;
452 sp->subsampling_ver=2; 455 sp->subsampling_ver=2;
453 TIFFSetField(tif,TIFFTAG_YCBCRSUBSAMPLING,2,2); 456 TIFFSetField(tif,TIFFTAG_YCBCRSUBSAMPLING,2,2);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 } 530 }
528 531
529 static int 532 static int
530 OJPEGVSetField(TIFF* tif, uint32 tag, va_list ap) 533 OJPEGVSetField(TIFF* tif, uint32 tag, va_list ap)
531 { 534 {
532 static const char module[]="OJPEGVSetField"; 535 static const char module[]="OJPEGVSetField";
533 OJPEGState* sp=(OJPEGState*)tif->tif_data; 536 OJPEGState* sp=(OJPEGState*)tif->tif_data;
534 uint32 ma; 537 uint32 ma;
535 uint64* mb; 538 uint64* mb;
536 uint32 n; 539 uint32 n;
540 const TIFFField* fip;
541
537 switch(tag) 542 switch(tag)
538 { 543 {
539 case TIFFTAG_JPEGIFOFFSET: 544 case TIFFTAG_JPEGIFOFFSET:
540 sp->jpeg_interchange_format=(uint64)va_arg(ap,uint64); 545 sp->jpeg_interchange_format=(uint64)va_arg(ap,uint64);
541 break; 546 break;
542 case TIFFTAG_JPEGIFBYTECOUNT: 547 case TIFFTAG_JPEGIFBYTECOUNT:
543 sp->jpeg_interchange_format_length=(uint64)va_arg(ap,uin t64); 548 sp->jpeg_interchange_format_length=(uint64)va_arg(ap,uin t64);
544 break; 549 break;
545 case TIFFTAG_YCBCRSUBSAMPLING: 550 case TIFFTAG_YCBCRSUBSAMPLING:
546 sp->subsampling_tag=1; 551 sp->subsampling_tag=1;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 break; 601 break;
597 case TIFFTAG_JPEGPROC: 602 case TIFFTAG_JPEGPROC:
598 sp->jpeg_proc=(uint8)va_arg(ap,uint16_vap); 603 sp->jpeg_proc=(uint8)va_arg(ap,uint16_vap);
599 break; 604 break;
600 case TIFFTAG_JPEGRESTARTINTERVAL: 605 case TIFFTAG_JPEGRESTARTINTERVAL:
601 sp->restart_interval=(uint16)va_arg(ap,uint16_vap); 606 sp->restart_interval=(uint16)va_arg(ap,uint16_vap);
602 break; 607 break;
603 default: 608 default:
604 return (*sp->vsetparent)(tif,tag,ap); 609 return (*sp->vsetparent)(tif,tag,ap);
605 } 610 }
606 » TIFFSetFieldBit(tif,TIFFFieldWithTag(tif,tag)->field_bit); 611 » fip = TIFFFieldWithTag(tif,tag);
612 » if( fip == NULL ) /* shouldn't happen */
613 » return(0);
614 » TIFFSetFieldBit(tif,fip->field_bit);
607 tif->tif_flags|=TIFF_DIRTYDIRECT; 615 tif->tif_flags|=TIFF_DIRTYDIRECT;
608 return(1); 616 return(1);
609 } 617 }
610 618
611 static void 619 static void
612 OJPEGPrintDir(TIFF* tif, FILE* fd, long flags) 620 OJPEGPrintDir(TIFF* tif, FILE* fd, long flags)
613 { 621 {
614 OJPEGState* sp=(OJPEGState*)tif->tif_data; 622 OJPEGState* sp=(OJPEGState*)tif->tif_data;
615 uint8 m; 623 uint8 m;
616 (void)flags; 624 (void)flags;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 } 768 }
761 769
762 static int 770 static int
763 OJPEGPreDecodeSkipScanlines(TIFF* tif) 771 OJPEGPreDecodeSkipScanlines(TIFF* tif)
764 { 772 {
765 static const char module[]="OJPEGPreDecodeSkipScanlines"; 773 static const char module[]="OJPEGPreDecodeSkipScanlines";
766 OJPEGState* sp=(OJPEGState*)tif->tif_data; 774 OJPEGState* sp=(OJPEGState*)tif->tif_data;
767 uint32 m; 775 uint32 m;
768 if (sp->skip_buffer==NULL) 776 if (sp->skip_buffer==NULL)
769 { 777 {
770 » » // add (uint8*) cast 778 » » sp->skip_buffer=_TIFFmalloc(sp->bytes_per_line);
771 » » sp->skip_buffer = (uint8*)_TIFFmalloc(sp->bytes_per_line); 779 » » if (sp->skip_buffer==NULL)
772 » » if (sp->skip_buffer == NULL)
773 { 780 {
774 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory") ; 781 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory") ;
775 return(0); 782 return(0);
776 } 783 }
777 } 784 }
778 for (m=0; m<sp->lines_per_strile; m++) 785 for (m=0; m<sp->lines_per_strile; m++)
779 { 786 {
780 if (jpeg_read_scanlines_encap(sp,&(sp->libjpeg_jpeg_decompress_s truct),&sp->skip_buffer,1)==0) 787 if (jpeg_read_scanlines_encap(sp,&(sp->libjpeg_jpeg_decompress_s truct),&sp->skip_buffer,1)==0)
781 return(0); 788 return(0);
782 } 789 }
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 { 1193 {
1187 assert(sp->subsampling_convert_ycbcrbuf==0); 1194 assert(sp->subsampling_convert_ycbcrbuf==0);
1188 assert(sp->subsampling_convert_ycbcrimage==0); 1195 assert(sp->subsampling_convert_ycbcrimage==0);
1189 sp->subsampling_convert_ylinelen=((sp->strile_width+sp-> subsampling_hor*8-1)/(sp->subsampling_hor*8)*sp->subsampling_hor*8); 1196 sp->subsampling_convert_ylinelen=((sp->strile_width+sp-> subsampling_hor*8-1)/(sp->subsampling_hor*8)*sp->subsampling_hor*8);
1190 sp->subsampling_convert_ylines=sp->subsampling_ver*8; 1197 sp->subsampling_convert_ylines=sp->subsampling_ver*8;
1191 sp->subsampling_convert_clinelen=sp->subsampling_convert _ylinelen/sp->subsampling_hor; 1198 sp->subsampling_convert_clinelen=sp->subsampling_convert _ylinelen/sp->subsampling_hor;
1192 sp->subsampling_convert_clines=8; 1199 sp->subsampling_convert_clines=8;
1193 sp->subsampling_convert_ybuflen=sp->subsampling_convert_ ylinelen*sp->subsampling_convert_ylines; 1200 sp->subsampling_convert_ybuflen=sp->subsampling_convert_ ylinelen*sp->subsampling_convert_ylines;
1194 sp->subsampling_convert_cbuflen=sp->subsampling_convert_ clinelen*sp->subsampling_convert_clines; 1201 sp->subsampling_convert_cbuflen=sp->subsampling_convert_ clinelen*sp->subsampling_convert_clines;
1195 sp->subsampling_convert_ycbcrbuflen=sp->subsampling_conv ert_ybuflen+2*sp->subsampling_convert_cbuflen; 1202 sp->subsampling_convert_ycbcrbuflen=sp->subsampling_conv ert_ybuflen+2*sp->subsampling_convert_cbuflen;
1196 » » » sp->subsampling_convert_ycbcrbuf = (uint8*)_TIFFmalloc(s p->subsampling_convert_ycbcrbuflen);» // add (uint8*) cast 1203 » » » sp->subsampling_convert_ycbcrbuf=_TIFFmalloc(sp->subsamp ling_convert_ycbcrbuflen);
1197 if (sp->subsampling_convert_ycbcrbuf==0) 1204 if (sp->subsampling_convert_ycbcrbuf==0)
1198 { 1205 {
1199 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1206 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
1200 return(0); 1207 return(0);
1201 } 1208 }
1202 sp->subsampling_convert_ybuf=sp->subsampling_convert_ycb crbuf; 1209 sp->subsampling_convert_ybuf=sp->subsampling_convert_ycb crbuf;
1203 sp->subsampling_convert_cbbuf=sp->subsampling_convert_yb uf+sp->subsampling_convert_ybuflen; 1210 sp->subsampling_convert_cbbuf=sp->subsampling_convert_yb uf+sp->subsampling_convert_ybuflen;
1204 sp->subsampling_convert_crbuf=sp->subsampling_convert_cb buf+sp->subsampling_convert_cbuflen; 1211 sp->subsampling_convert_crbuf=sp->subsampling_convert_cb buf+sp->subsampling_convert_cbuflen;
1205 sp->subsampling_convert_ycbcrimagelen=3+sp->subsampling_ convert_ylines+2*sp->subsampling_convert_clines; 1212 sp->subsampling_convert_ycbcrimagelen=3+sp->subsampling_ convert_ylines+2*sp->subsampling_convert_clines;
1206 » » » sp->subsampling_convert_ycbcrimage = (uint8**)_TIFFmallo c(sp->subsampling_convert_ycbcrimagelen * sizeof(uint8*));// add (uint8**) cast 1213 » » » sp->subsampling_convert_ycbcrimage=_TIFFmalloc(sp->subsa mpling_convert_ycbcrimagelen*sizeof(uint8*));
1207 if (sp->subsampling_convert_ycbcrimage==0) 1214 if (sp->subsampling_convert_ycbcrimage==0)
1208 { 1215 {
1209 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1216 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
1210 return(0); 1217 return(0);
1211 } 1218 }
1212 m=sp->subsampling_convert_ycbcrimage; 1219 m=sp->subsampling_convert_ycbcrimage;
1213 *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3); 1220 *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3);
1214 *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3+sp->s ubsampling_convert_ylines); 1221 *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3+sp->s ubsampling_convert_ylines);
1215 *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3+sp->s ubsampling_convert_ylines+sp->subsampling_convert_clines); 1222 *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3+sp->s ubsampling_convert_ylines+sp->subsampling_convert_clines);
1216 for (n=0; n<sp->subsampling_convert_ylines; n++) 1223 for (n=0; n<sp->subsampling_convert_ylines; n++)
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 else 1430 else
1424 { 1431 {
1425 m-=2; 1432 m-=2;
1426 do 1433 do
1427 { 1434 {
1428 if (m<65) 1435 if (m<65)
1429 { 1436 {
1430 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DQT marker in JPEG data"); 1437 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DQT marker in JPEG data");
1431 return(0); 1438 return(0);
1432 } 1439 }
1433 » » » na = sizeof(uint32) + 69; 1440 » » » na=sizeof(uint32)+69;
1434 » » » nb = (uint8*)_TIFFmalloc(na);» // add (uint8*) cast 1441 » » » nb=_TIFFmalloc(na);
1435 » » » if (nb == 0) 1442 » » » if (nb==0)
1436 { 1443 {
1437 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1444 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
1438 return(0); 1445 return(0);
1439 } 1446 }
1440 *(uint32*)nb=na; 1447 *(uint32*)nb=na;
1441 nb[sizeof(uint32)]=255; 1448 nb[sizeof(uint32)]=255;
1442 nb[sizeof(uint32)+1]=JPEG_MARKER_DQT; 1449 nb[sizeof(uint32)+1]=JPEG_MARKER_DQT;
1443 nb[sizeof(uint32)+2]=0; 1450 nb[sizeof(uint32)+2]=0;
1444 nb[sizeof(uint32)+3]=67; 1451 nb[sizeof(uint32)+3]=67;
1445 if (OJPEGReadBlock(sp,65,&nb[sizeof(uint32)+4])==0) { 1452 if (OJPEGReadBlock(sp,65,&nb[sizeof(uint32)+4])==0) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 if (sp->subsamplingcorrect==0) 1487 if (sp->subsamplingcorrect==0)
1481 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT mar ker in JPEG data"); 1488 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT mar ker in JPEG data");
1482 return(0); 1489 return(0);
1483 } 1490 }
1484 if (sp->subsamplingcorrect!=0) 1491 if (sp->subsamplingcorrect!=0)
1485 { 1492 {
1486 OJPEGReadSkip(sp,m-2); 1493 OJPEGReadSkip(sp,m-2);
1487 } 1494 }
1488 else 1495 else
1489 { 1496 {
1490 » » na = sizeof(uint32) + 2 + m; 1497 » » na=sizeof(uint32)+2+m;
1491 » » nb = (uint8*)_TIFFmalloc(na);» // add (uint8*) cast 1498 » » nb=_TIFFmalloc(na);
1492 » » if (nb == 0) 1499 » » if (nb==0)
1493 { 1500 {
1494 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory") ; 1501 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory") ;
1495 return(0); 1502 return(0);
1496 } 1503 }
1497 *(uint32*)nb=na; 1504 *(uint32*)nb=na;
1498 nb[sizeof(uint32)]=255; 1505 nb[sizeof(uint32)]=255;
1499 nb[sizeof(uint32)+1]=JPEG_MARKER_DHT; 1506 nb[sizeof(uint32)+1]=JPEG_MARKER_DHT;
1500 nb[sizeof(uint32)+2]=(m>>8); 1507 nb[sizeof(uint32)+2]=(m>>8);
1501 nb[sizeof(uint32)+3]=(m&255); 1508 nb[sizeof(uint32)+3]=(m&255);
1502 » » if (OJPEGReadBlock(sp,m-2,&nb[sizeof(uint32)+4])==0) 1509 » » if (OJPEGReadBlock(sp,m-2,&nb[sizeof(uint32)+4])==0) {
1510 _TIFFfree(nb);
1503 return(0); 1511 return(0);
1512 }
1504 o=nb[sizeof(uint32)+4]; 1513 o=nb[sizeof(uint32)+4];
1505 if ((o&240)==0) 1514 if ((o&240)==0)
1506 { 1515 {
1507 if (3<o) 1516 if (3<o)
1508 { 1517 {
1509 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); 1518 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data");
1519 _TIFFfree(nb);
1510 return(0); 1520 return(0);
1511 } 1521 }
1512 if (sp->dctable[o]!=0) 1522 if (sp->dctable[o]!=0)
1513 _TIFFfree(sp->dctable[o]); 1523 _TIFFfree(sp->dctable[o]);
1514 sp->dctable[o]=nb; 1524 sp->dctable[o]=nb;
1515 } 1525 }
1516 else 1526 else
1517 { 1527 {
1518 if ((o&240)!=16) 1528 if ((o&240)!=16)
1519 { 1529 {
1520 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); 1530 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data");
1531 _TIFFfree(nb);
1521 return(0); 1532 return(0);
1522 } 1533 }
1523 o&=15; 1534 o&=15;
1524 if (3<o) 1535 if (3<o)
1525 { 1536 {
1526 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); 1537 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data");
1538 _TIFFfree(nb);
1527 return(0); 1539 return(0);
1528 } 1540 }
1529 if (sp->actable[o]!=0) 1541 if (sp->actable[o]!=0)
1530 _TIFFfree(sp->actable[o]); 1542 _TIFFfree(sp->actable[o]);
1531 sp->actable[o]=nb; 1543 sp->actable[o]=nb;
1532 } 1544 }
1533 } 1545 }
1534 return(1); 1546 return(1);
1535 } 1547 }
1536 1548
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 { 1768 {
1757 for (n=0; n<m-1; n++) 1769 for (n=0; n<m-1; n++)
1758 { 1770 {
1759 if (sp->qtable_offset[m]==sp->qtable_offset[n]) 1771 if (sp->qtable_offset[m]==sp->qtable_offset[n])
1760 { 1772 {
1761 TIFFErrorExt(tif->tif_clientdata,module, "Corrupt JpegQTables tag value"); 1773 TIFFErrorExt(tif->tif_clientdata,module, "Corrupt JpegQTables tag value");
1762 return(0); 1774 return(0);
1763 } 1775 }
1764 } 1776 }
1765 oa=sizeof(uint32)+69; 1777 oa=sizeof(uint32)+69;
1766 » » » ob = (uint8*)_TIFFmalloc(oa);» // add (uint8*) cast 1778 » » » ob=_TIFFmalloc(oa);
1767 if (ob==0) 1779 if (ob==0)
1768 { 1780 {
1769 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1781 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
1770 return(0); 1782 return(0);
1771 } 1783 }
1772 *(uint32*)ob=oa; 1784 *(uint32*)ob=oa;
1773 ob[sizeof(uint32)]=255; 1785 ob[sizeof(uint32)]=255;
1774 ob[sizeof(uint32)+1]=JPEG_MARKER_DQT; 1786 ob[sizeof(uint32)+1]=JPEG_MARKER_DQT;
1775 ob[sizeof(uint32)+2]=0; 1787 ob[sizeof(uint32)+2]=0;
1776 ob[sizeof(uint32)+3]=67; 1788 ob[sizeof(uint32)+3]=67;
1777 ob[sizeof(uint32)+4]=m; 1789 ob[sizeof(uint32)+4]=m;
1778 TIFFSeekFile(tif,sp->qtable_offset[m],SEEK_SET); 1790 TIFFSeekFile(tif,sp->qtable_offset[m],SEEK_SET);
1779 » » » p=(uint32)TIFFReadFile(tif,&ob[sizeof(uint32)+5],64); 1791 » » » p=TIFFReadFile(tif,&ob[sizeof(uint32)+5],64);
1780 if (p!=64) 1792 if (p!=64)
1781 return(0); 1793 return(0);
1782 sp->qtable[m]=ob; 1794 sp->qtable[m]=ob;
1783 sp->sof_tq[m]=m; 1795 sp->sof_tq[m]=m;
1784 } 1796 }
1785 else 1797 else
1786 sp->sof_tq[m]=sp->sof_tq[m-1]; 1798 sp->sof_tq[m]=sp->sof_tq[m-1];
1787 } 1799 }
1788 return(1); 1800 return(1);
1789 } 1801 }
(...skipping 22 matching lines...) Expand all
1812 { 1824 {
1813 for (n=0; n<m-1; n++) 1825 for (n=0; n<m-1; n++)
1814 { 1826 {
1815 if (sp->dctable_offset[m]==sp->dctable_offset[n] ) 1827 if (sp->dctable_offset[m]==sp->dctable_offset[n] )
1816 { 1828 {
1817 TIFFErrorExt(tif->tif_clientdata,module, "Corrupt JpegDcTables tag value"); 1829 TIFFErrorExt(tif->tif_clientdata,module, "Corrupt JpegDcTables tag value");
1818 return(0); 1830 return(0);
1819 } 1831 }
1820 } 1832 }
1821 TIFFSeekFile(tif,sp->dctable_offset[m],SEEK_SET); 1833 TIFFSeekFile(tif,sp->dctable_offset[m],SEEK_SET);
1822 » » » p=(uint32)TIFFReadFile(tif,o,16); 1834 » » » p=TIFFReadFile(tif,o,16);
1823 if (p!=16) 1835 if (p!=16)
1824 return(0); 1836 return(0);
1825 q=0; 1837 q=0;
1826 for (n=0; n<16; n++) 1838 for (n=0; n<16; n++)
1827 q+=o[n]; 1839 q+=o[n];
1828 ra=sizeof(uint32)+21+q; 1840 ra=sizeof(uint32)+21+q;
1829 » » » rb = (uint8*)_TIFFmalloc(ra);» // add (uint8*) cast 1841 » » » rb=_TIFFmalloc(ra);
1830 if (rb==0) 1842 if (rb==0)
1831 { 1843 {
1832 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1844 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
1833 return(0); 1845 return(0);
1834 } 1846 }
1835 *(uint32*)rb=ra; 1847 *(uint32*)rb=ra;
1836 rb[sizeof(uint32)]=255; 1848 rb[sizeof(uint32)]=255;
1837 rb[sizeof(uint32)+1]=JPEG_MARKER_DHT; 1849 rb[sizeof(uint32)+1]=JPEG_MARKER_DHT;
1838 rb[sizeof(uint32)+2]=((19+q)>>8); 1850 rb[sizeof(uint32)+2]=((19+q)>>8);
1839 rb[sizeof(uint32)+3]=((19+q)&255); 1851 rb[sizeof(uint32)+3]=((19+q)&255);
1840 rb[sizeof(uint32)+4]=m; 1852 rb[sizeof(uint32)+4]=m;
1841 for (n=0; n<16; n++) 1853 for (n=0; n<16; n++)
1842 rb[sizeof(uint32)+5+n]=o[n]; 1854 rb[sizeof(uint32)+5+n]=o[n];
1843 » » » p=(uint32)TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); 1855 » » » p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q);
1844 if (p!=q) 1856 if (p!=q)
1845 return(0); 1857 return(0);
1846 sp->dctable[m]=rb; 1858 sp->dctable[m]=rb;
1847 sp->sos_tda[m]=(m<<4); 1859 sp->sos_tda[m]=(m<<4);
1848 } 1860 }
1849 else 1861 else
1850 sp->sos_tda[m]=sp->sos_tda[m-1]; 1862 sp->sos_tda[m]=sp->sos_tda[m-1];
1851 } 1863 }
1852 return(1); 1864 return(1);
1853 } 1865 }
(...skipping 22 matching lines...) Expand all
1876 { 1888 {
1877 for (n=0; n<m-1; n++) 1889 for (n=0; n<m-1; n++)
1878 { 1890 {
1879 if (sp->actable_offset[m]==sp->actable_offset[n] ) 1891 if (sp->actable_offset[m]==sp->actable_offset[n] )
1880 { 1892 {
1881 TIFFErrorExt(tif->tif_clientdata,module, "Corrupt JpegAcTables tag value"); 1893 TIFFErrorExt(tif->tif_clientdata,module, "Corrupt JpegAcTables tag value");
1882 return(0); 1894 return(0);
1883 } 1895 }
1884 } 1896 }
1885 TIFFSeekFile(tif,sp->actable_offset[m],SEEK_SET); 1897 TIFFSeekFile(tif,sp->actable_offset[m],SEEK_SET);
1886 » » » p=(uint32)TIFFReadFile(tif,o,16); 1898 » » » p=TIFFReadFile(tif,o,16);
1887 if (p!=16) 1899 if (p!=16)
1888 return(0); 1900 return(0);
1889 q=0; 1901 q=0;
1890 for (n=0; n<16; n++) 1902 for (n=0; n<16; n++)
1891 q+=o[n]; 1903 q+=o[n];
1892 ra=sizeof(uint32)+21+q; 1904 ra=sizeof(uint32)+21+q;
1893 » » » rb = (uint8*)_TIFFmalloc(ra);» // add (uint8*) cast 1905 » » » rb=_TIFFmalloc(ra);
1894 if (rb==0) 1906 if (rb==0)
1895 { 1907 {
1896 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1908 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
1897 return(0); 1909 return(0);
1898 } 1910 }
1899 *(uint32*)rb=ra; 1911 *(uint32*)rb=ra;
1900 rb[sizeof(uint32)]=255; 1912 rb[sizeof(uint32)]=255;
1901 rb[sizeof(uint32)+1]=JPEG_MARKER_DHT; 1913 rb[sizeof(uint32)+1]=JPEG_MARKER_DHT;
1902 rb[sizeof(uint32)+2]=((19+q)>>8); 1914 rb[sizeof(uint32)+2]=((19+q)>>8);
1903 rb[sizeof(uint32)+3]=((19+q)&255); 1915 rb[sizeof(uint32)+3]=((19+q)&255);
1904 rb[sizeof(uint32)+4]=(16|m); 1916 rb[sizeof(uint32)+4]=(16|m);
1905 for (n=0; n<16; n++) 1917 for (n=0; n<16; n++)
1906 rb[sizeof(uint32)+5+n]=o[n]; 1918 rb[sizeof(uint32)+5+n]=o[n];
1907 » » » p=(uint32)TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); 1919 » » » p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q);
1908 if (p!=q) 1920 if (p!=q)
1909 return(0); 1921 return(0);
1910 sp->actable[m]=rb; 1922 sp->actable[m]=rb;
1911 sp->sos_tda[m]=(sp->sos_tda[m]|m); 1923 sp->sos_tda[m]=(sp->sos_tda[m]|m);
1912 } 1924 }
1913 else 1925 else
1914 sp->sos_tda[m]=(sp->sos_tda[m]|(sp->sos_tda[m-1]&15)); 1926 sp->sos_tda[m]=(sp->sos_tda[m]|(sp->sos_tda[m-1]&15));
1915 } 1927 }
1916 return(1); 1928 return(1);
1917 } 1929 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 case osibsNotSetYet: 1967 case osibsNotSetYet:
1956 if (sp->jpeg_interchange_format!=0) 1968 if (sp->jpeg_interchange_format!=0)
1957 { 1969 {
1958 sp->in_buffer_file_pos=sp->jpeg_intercha nge_format; 1970 sp->in_buffer_file_pos=sp->jpeg_intercha nge_format;
1959 sp->in_buffer_file_togo=sp->jpeg_interch ange_format_length; 1971 sp->in_buffer_file_togo=sp->jpeg_interch ange_format_length;
1960 } 1972 }
1961 sp->in_buffer_source=osibsJpegInterchangeFormat; 1973 sp->in_buffer_source=osibsJpegInterchangeFormat;
1962 break; 1974 break;
1963 case osibsJpegInterchangeFormat: 1975 case osibsJpegInterchangeFormat:
1964 sp->in_buffer_source=osibsStrile; 1976 sp->in_buffer_source=osibsStrile;
1977 break;
1965 case osibsStrile: 1978 case osibsStrile:
1966 if (!_TIFFFillStriles( sp->tif ) 1979 if (!_TIFFFillStriles( sp->tif )
1967 || sp->tif->tif_dir.td_stripoffset == NULL 1980 || sp->tif->tif_dir.td_stripoffset == NULL
1968 || sp->tif->tif_dir.td_stripbytecount == NUL L) 1981 || sp->tif->tif_dir.td_stripbytecount == NUL L)
1969 return 0; 1982 return 0;
1970 1983
1971 if (sp->in_buffer_next_strile==sp->in_buffer_str ile_count) 1984 if (sp->in_buffer_next_strile==sp->in_buffer_str ile_count)
1972 sp->in_buffer_source=osibsEof; 1985 sp->in_buffer_source=osibsEof;
1973 else 1986 else
1974 { 1987 {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2052 } 2065 }
2053 2066
2054 static int 2067 static int
2055 OJPEGReadBlock(OJPEGState* sp, uint16 len, void* mem) 2068 OJPEGReadBlock(OJPEGState* sp, uint16 len, void* mem)
2056 { 2069 {
2057 uint16 mlen; 2070 uint16 mlen;
2058 uint8* mmem; 2071 uint8* mmem;
2059 uint16 n; 2072 uint16 n;
2060 assert(len>0); 2073 assert(len>0);
2061 mlen=len; 2074 mlen=len;
2062 » mmem = (uint8*)mem;» » // add (uint8*) cast 2075 » mmem=mem;
2063 do 2076 do
2064 { 2077 {
2065 if (sp->in_buffer_togo==0) 2078 if (sp->in_buffer_togo==0)
2066 { 2079 {
2067 if (OJPEGReadBufferFill(sp)==0) 2080 if (OJPEGReadBufferFill(sp)==0)
2068 return(0); 2081 return(0);
2069 assert(sp->in_buffer_togo>0); 2082 assert(sp->in_buffer_togo>0);
2070 } 2083 }
2071 n=mlen; 2084 n=mlen;
2072 if (n>sp->in_buffer_togo) 2085 if (n>sp->in_buffer_togo)
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
2454 { 2467 {
2455 TIFF* tif=(TIFF*)cinfo->client_data; 2468 TIFF* tif=(TIFF*)cinfo->client_data;
2456 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2469 OJPEGState* sp=(OJPEGState*)tif->tif_data;
2457 void* mem=0; 2470 void* mem=0;
2458 uint32 len=0U; 2471 uint32 len=0U;
2459 if (OJPEGWriteStream(tif,&mem,&len)==0) 2472 if (OJPEGWriteStream(tif,&mem,&len)==0)
2460 { 2473 {
2461 TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Premature end of JPE G data"); 2474 TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Premature end of JPE G data");
2462 jpeg_encap_unwind(tif); 2475 jpeg_encap_unwind(tif);
2463 } 2476 }
2464 » sp->libjpeg_jpeg_source_mgr.bytes_in_buffer = len; 2477 » sp->libjpeg_jpeg_source_mgr.bytes_in_buffer=len;
2465 » sp->libjpeg_jpeg_source_mgr.next_input_byte = (const JOCTET * )mem;» » // add (const JOCTET * ) cast 2478 » sp->libjpeg_jpeg_source_mgr.next_input_byte=mem;
2466 return(1); 2479 return(1);
2467 } 2480 }
2468 2481
2469 static void 2482 static void
2470 OJPEGLibjpegJpegSourceMgrSkipInputData(jpeg_decompress_struct* cinfo, long num_b ytes) 2483 OJPEGLibjpegJpegSourceMgrSkipInputData(jpeg_decompress_struct* cinfo, long num_b ytes)
2471 { 2484 {
2472 TIFF* tif=(TIFF*)cinfo->client_data; 2485 TIFF* tif=(TIFF*)cinfo->client_data;
2473 (void)num_bytes; 2486 (void)num_bytes;
2474 TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Unexpected error"); 2487 TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Unexpected error");
2475 jpeg_encap_unwind(tif); 2488 jpeg_encap_unwind(tif);
(...skipping 18 matching lines...) Expand all
2494 #endif 2507 #endif
2495 2508
2496 2509
2497 /* 2510 /*
2498 * Local Variables: 2511 * Local Variables:
2499 * mode: c 2512 * mode: c
2500 * c-basic-offset: 8 2513 * c-basic-offset: 8
2501 * fill-column: 78 2514 * fill-column: 78
2502 * End: 2515 * End:
2503 */ 2516 */
2504
OLDNEW
« no previous file with comments | « third_party/libtiff/tif_next.c ('k') | third_party/libtiff/tif_open.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698