Changeset 846 for trunk/src/3rdparty/libtiff
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 24 deleted
- 117 edited
- 13 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/3rdparty/libtiff/ChangeLog
r2 r846 1 2009-11-04 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 2 3 * libtiff 3.9.2 released. 4 5 2009-11-03 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 6 7 * tools/tiffcrop.c: Updated tiffcrop from Richard Nolde. This 8 version has undergone substantial testing with arbitrary sample 9 bit depths. Also eliminates GCC compilation warnings. 10 11 2009-11-02 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 12 13 * port/libport.h: Added header file for porting prototypes and 14 extern declarations. 15 16 2009-10-31 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 17 18 * libtiff/tif_dirwrite.c (TIFFWriteAnyArray): Add missing break 19 statement so writing an array of TIFF_DOUBLE works. 20 21 2009-10-29 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 22 23 * libtiff/tif_dirread.c: Eliminate GCC "dereferencing type-punned 24 pointer" warnings. 25 26 2009-10-28 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 27 28 * html/tools.html: Add manual page links, and a summary 29 description of tiffcrop. 30 31 2009-10-07 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 32 33 * configure.ac: x86_64 should use the same fill order as i386. 34 35 2009-09-24 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 36 37 * tools/tiffcrop.c, man/tiffcrop.1: New tiffcrop from Richard 38 Nolde. Major updates to add significant functionality for reading 39 and writing tile based images with bit depths not a multiple of 8 40 which cannot be handled by tiffcp. 41 42 2009-09-03 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 43 44 * libtiff/tif_ojpeg.c (OJPEGWriteHeaderInfo): IJG JPEG 7 needs 45 do_fancy_upsampling=FALSE in order to read raw data. Resolves 46 "Bug 2090 - OJPEG crash with libjpeg v7". 47 http://bugzilla.maptools.org/show_bug.cgi?id=2090 48 49 2009-08-30 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 50 51 * contrib/iptcutil/iptcutil.c, 52 libtiff/tif_getimage.c,libtiff/tif_jpeg.c,libtiff/tif_ojpeg.c,tools/tiffcrop.c,tools/tiffgt.c: 53 Applied patch from Oden Eriksson to allow building with GCC using 54 the "-Wformat -Werror=format-security" flags. 55 56 2009-08-28 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 57 58 * libtiff 3.9.1 released. 59 60 2009-08-28 Frank Warmerdam <warmerdam@pobox.com> 61 62 * libtiff/tif_dirwrite.c: Back out changes from 2007-11-22 that 63 resulted in the final strip not being written in some circumstances. 64 http://bugzilla.maptools.org/show_bug.cgi?id=2088 65 66 2009-08-27 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 67 68 * libtiff/tif_write.c (TIFFAppendToStrip): Remove cast which 69 caused libtiff to output a wrong last strip with byte-count and 70 strip-offset of zero. This cast was added on the day of the 3.9.0 71 release. 72 73 * libtiff/tif_config.vc.h: tiffiop.h needs the TIFF_INT64_T and 74 TIFF_UINT64_T defines in order to compile. Copy existing 75 definitions from tiffconf.vc.h. 76 77 2009-08-21 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 78 79 * test/Makefile.am (AUTOMAKE_OPTIONS): Colorized tests was not 80 actually activated since it needed to be enabled in this 81 Makefile.am. Also activated parallel-tests mode since it offers 82 useful features such as per-test .log files and a summary test 83 report .log file. 84 85 2009-08-20 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 86 87 * libtiff 3.9.0 released. 88 89 * libtiff/tif_print.c (TIFFPrintDirectory): Applied patch for "tag 90 error may cause segfault in tif_print.c." 91 http://bugzilla.maptools.org/show_bug.cgi?id=1896 92 93 * tools/{rgb2ycbcr.c, tiff2rgba.c}: Applied patch for 94 CVE-2009-2347 libtiff: integer overflows in various inter-color 95 space conversion tools. 96 http://bugzilla.maptools.org/show_bug.cgi?id=2079 97 98 * configure.ac: Updated autotools. Autoconf 2.64, Automake 1.11, 99 libtool 2.2.6. Enabled support for silent build rules 100 (--enable-silent-rules or 'make V=0') and colorized tests. 101 102 2009-06-30 Frank Warmerdam <warmerdam@pobox.com> 103 104 * libtiff/tif_luv.c: correct return codes from encoderow to be 105 1 on success instead of zero. 106 http://bugzilla.maptools.org/show_bug.cgi?id=2069 107 108 2009-06-22 Frank Warmerdam <warmerdam@pobox.com> 109 110 * libtiff/tif_lzw.c: Fix buffer underflow bug. 111 http://bugzilla.maptools.org/show_bug.cgi?id=2065 112 113 2009-06-03 Frank Warmerdam <warmerdam@pobox.com> 114 115 * libtiff/tif_write.c: do not override the planar configuration to be 116 contig for one sample files if planar configuration is already set. 117 http://bugzilla.maptools.org/show_bug.cgi?id=2057 118 119 2009-02-12 Frank Warmerdam <warmerdam@pobox.com> 120 121 * libtiff/tif_luv.c: Fix handling of tiled logluv images. 122 http://bugzilla.maptools.org/show_bug.cgi?id=2005 123 124 2009-01-23 Frank Warmerdam <warmerdam@pobox.com> 125 126 * libtiff/tif_predict.c: Add support for 32bit integer horz. predictors. 127 http://bugzilla.maptools.org/show_bug.cgi?id=1911 128 129 2009-01-20 Frank Warmerdam <warmerdam@pobox.com> 130 131 * tools/tiffsplit.c: fix sampleformat to be shortv instead of longv. 132 133 2009-01-12 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 134 135 * tools/tiff2ps.c: Remove spurious message printed to stderr. 136 137 2009-01-11 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 138 139 * tools/tiff2ps.c: Incorporated significant functionality update 140 from Richard Nolde. In particular, support for rotating the image 141 by 90, 180, 270, and 'auto' has been added. 142 143 * tools/tiffcrop.c: Incorporated significant functionality update 144 from Richard Nolde. 145 146 2009-01-06 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 147 148 * libtiff/tiffiop.h: Add private type declarations for int64, and 149 uint64 so that bundled utilities (like tiffcrop) can use it when 150 necessary. 151 152 2009-01-01 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 153 154 * configure.ac: Updated to test for 64-bit types. This version of 155 the library does not require a 64-bit type, but tiffcrop needs it. 156 157 2008-12-31 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 158 159 * Update to use current FSF autotools versions. 160 * libtiff/tiffio.h: GCC will now validate format specifications 161 for TIFFError(), TIFFErrorExt(), TIFFWarning(), and 162 TIFFWarningExt() in order to reveal bugs. Cleaned up resulting 163 warnings throughout for 32 bit build only. 164 165 2008-12-31 Frank Warmerdam <warmerdam@pobox.com> 166 167 * tools/tiffcrop.c, man/tiffcrop.1: A major update from Richard 168 Nolde. 169 170 2008-12-21 Frank Warmerdam <warmerdam@pobox.com> 171 172 * libtiff/tif_jpeg.c: Avoid errors if the application writes a full 173 strip for the last partial strip in a jpeg compressed file. 174 http://bugzilla.maptools.org/show_bug.cgi?id=1981 175 176 2008-12-21 Frank Warmerdam <warmerdam@pobox.com> 177 178 * libtiff/tif_getimage.c, tiffio.h: More ABI corrections. 179 Removed SubsamplingHor/Ver from TIFFRGBAImage structure. 180 http://bugzilla.maptools.org/show_bug.cgi?id=1980 181 182 2008-12-18 Frank Warmerdam <warmerdam@pobox.com> 183 184 * libtiff/tif_getimage.c,tiffio.h: removed all use of UaToAa and 185 Bitmap16to8 arrays in TIFFRGBAImage structure to restore ABI 186 compatability. These were just an attempt to speed up processing 187 with precalculated tables. 188 http://bugzilla.maptools.org/show_bug.cgi?id=1979 189 190 * libtiff/tif_codec.c: Avoid printing c->name if it does not exist. 191 192 2008-10-21 Andrey Kiselev <dron@ak4719.spb.edu> 193 194 * libtiff/tif_jbig.c: Support the JBIG-KIT 2.0 (compatibility with 195 the older versions retained). 196 197 2008-09-05 Andrey Kiselev <dron@ak4719.spb.edu> 198 199 * tools/tiffsplit.c: Use dynamically allocated array instead of static 200 when constructing output file names. 201 202 2008-09-03 Andrey Kiselev <dron@ak4719.spb.edu> 203 204 * tools/tiffsplit.c: Get rid of unsafe strcpy()/strcat() calls when 205 doing the filename/path construction. 206 207 * tools/tiff2pdf.c: More appropriate format string in 208 t2p_write_pdf_string(); avoid signed/unsigned mismatch. 209 210 * libtiff/tif_lzw.c: Properly zero out the codetable. As per bug 211 212 http://bugzilla.maptools.org/show_bug.cgi?id=1929 213 214 * libtiff/tif_lzw.c: Properly zero out the string table. Fixes 215 CVE-2008-2327 security issue. 216 217 2008-05-24 Frank Warmerdam <warmerdam@pobox.com> 218 219 * tif_codec.c: Avoid NULL pointer dereferencing for exotic 220 compression codec codes. 221 222 * tif_dirread.c: zero tif->tif_dir after freeing the directory 223 in TIFFReadCustomDirectory(). I don't exactly remember why this 224 was important. 225 226 * tif_dirwrite.c: Fix potential memory leak writing large double 227 tags. 228 229 * tif_dirread.c: Fix unchecked malloc result. 230 231 2008-01-30 Andrey Kiselev <dron@ak4719.spb.edu> 232 233 * tif_fax3.c: Make find0span() and find1span() non-inline to 234 make MSVC 6.0 compiler happy. 235 236 2007-11-26 Frank Warmerdam <warmerdam@pobox.com> 237 238 * tif_fax3.c: fix leak of FAXCS state (per bug 1603). 239 240 2007-11-23 Andrey Kiselev <dron@ak4719.spb.edu> 241 242 * configure.com, libtiff/tif_vms.c: Better OpenVMS support. Patches 243 from Alexey Chupahin. 244 245 2007-11-22 Frank Warmerdam <warmerdam@pobox.com> 246 247 * tif_write.c: Rip out the fancy logic in TIFFAppendToStrip() for 248 establishing if an existing tile can be rewritten to the same location 249 by comparing the current size to all the other blocks in the same 250 directory. This is dangerous in many situations and can easily 251 corrupt a file. (observed in esoteric GDAL situation that's hard to 252 document). This change involves leaving the stripbytecount[] values 253 unaltered till TIFFAppendToStrip(). Now we only write a block back 254 to the same location it used to be at if the new data is the same 255 size or smaller - otherwise we move it to the end of file. 256 257 * tif_dirwrite.c: Try to avoid writing out a full readbuffer of tile 258 data when writing the directory just because we have BEENWRITING at 259 some point in the past. This was causing odd junk to be written out 260 in a tile of data when a single tile had an interleaving of reading 261 and writing with reading last. (highlighted by gdal 262 autotest/gcore/tif_write.py test 7. 263 264 * tif_predict.c: use working buffer in PredictorEncodeTile to avoid 265 modifying callers buffer. 266 http://trac.osgeo.org/gdal/ticket/1965 267 268 * tif_predict.c/h, tif_lzw.c, tif_zip.c: Improvements so that 269 predictor based encoding and decoding works in read-write update 270 mode properly. 271 http://trac.osgeo.org/gdal/ticket/1948 272 273 2007-10-05 Frank Warmerdam <warmerdam@pobox.com> 274 275 * tools/tiff2pdf.c: Fixed setting of alpha value per report on list. 276 277 2007-09-13 Frank Warmerdam <warmerdam@pobox.com> 278 279 * tif_dirinfo.c: _TIFFMergeFields() now only merges in field 280 definitions that are missing. Existing definitions are silently 281 ignored. (Bug #1585) 282 283 2007-07-18 Andrey Kiselev <dron@ak4719.spb.edu> 284 285 * libtiff/{Makefile.am, Makefile.v}: Do not distribute tiffconf.h, 286 remove tif_config.h/tiffconf.h during cleaning. As per bug 287 288 http://bugzilla.remotesensing.org/show_bug.cgi?id=1573 289 290 2007-07-13 Andrey Kiselev <dron@ak4719.spb.edu> 291 292 * libtiff 3.9.0beta released. 293 294 2007-07-12 Andrey Kiselev <dron@ak4719.spb.edu> 295 296 * tools/tiff2pdf.c: Added missed extern optind as per bug 297 298 http://bugzilla.remotesensing.org/show_bug.cgi?id=1567 299 300 2007-07-03 Andrey Kiselev <dron@ak4719.spb.edu> 301 302 * tools/tiff2ps.c: Added support 16-bit images as per bug 303 304 http://bugzilla.remotesensing.org/show_bug.cgi?id=1566 305 306 Patch from William Bader. 307 308 * tools/tiff2pdf.c: Fix for TIFFTAG_JPEGTABLES tag fetching and 309 significant upgrade of the whole utility as per bug 310 311 http://bugzilla.remotesensing.org/show_bug.cgi?id=1560 312 313 Now we don't need tiffiop.h in tiff2pdf anymore and will open output 314 PDF file using TIFFClientOpen() machinery as it is implemented 315 by Leon Bottou. 316 317 2007-06-29 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 318 319 * libtiff/tif_dirinfo.c (_TIFFFindFieldInfo): Don't attempt to 320 bsearch() on a NULL fieldinfo list. 321 (_TIFFFindFieldInfoByName): Don't attempt to 322 lfind() on a NULL fieldinfo list. 323 324 2007-05-01 Andrey Kiselev <dron@ak4719.spb.edu> 325 326 * libtiff/tif_dirwrite.c: Fixed problem introduced with a fix for a 327 byte swapping issue 328 329 http://bugzilla.remotesensing.org/show_bug.cgi?id=1363 330 331 As per bug 332 333 http://bugzilla.remotesensing.org/show_bug.cgi?id=1550 334 335 2007-04-27 Andrey Kiselev <dron@ak4719.spb.edu> 336 337 * tools/tiff2pdf.c: Check the tmpfile() return status as per bug 338 339 http://bugzilla.remotesensing.org/show_bug.cgi?id=154 340 341 2007-04-07 Andrey Kiselev <dron@ak4719.spb.edu> 342 343 * libtiff/{tif_dir.h, tif_dirread.c, tif_dirinfo.c, tif_jpeg.c, 344 tif_fax3.c, tif_jbig.c, tif_luv.c, tif_ojpeg.c, tif_pixarlog.c, 345 tif_predict.c, tif_zip.c}: Finally fix bug 346 347 http://bugzilla.remotesensing.org/show_bug.cgi?id=1274 348 349 by introducing _TIFFMergeFieldInfo() returning integer error status 350 instead of void in case of problems with field merging (e.g., if the 351 field with such a tag already registered). TIFFMergeFieldInfo() in 352 public API remains void. Use _TIFFMergeFieldInfo() everywhere and 353 check returned value. 354 355 2007-04-07 Frank Warmerdam <warmerdam@pobox.com> 356 357 * contrib/addtiffo/tif_overview.c: Fix problems with odd sized output 358 blocks in TIFF_DownSample_Subsampled() (bug 1542). 359 360 2007-04-06 Frank Warmerdam <warmerdam@pobox.com> 361 362 * libtiff/tif_jpeg.c: Changed JPEGInitializeLibJPEG() so that it 363 will convert from decompressor to compressor or compress to decompress 364 if required by the force arguments. This works around a problem in 365 where the JPEGFixupTestSubsampling() may cause a decompressor to 366 be setup on a directory when later a compressor is required with the 367 force flag set. Occurs with the addtiffo program for instance. 368 369 2007-04-06 Andrey Kiselev <dron@ak4719.spb.edu> 370 371 * libtiff/tif_dirwrite.c: Fixed swapping of byte arrays stored 372 in-place in tag offsets as per bug 373 374 http://bugzilla.remotesensing.org/show_bug.cgi?id=1363 375 376 * tools/tiffcrop.c, man/tiffcrop.1: Significant update in 377 functionality from Richard Nolde. As per bug 378 379 http://bugzilla.remotesensing.org/show_bug.cgi?id=1525 380 381 2007-03-28 Frank Warmerdam <warmerdam@pobox.com> 382 383 * libtiff/tif_fax3.c: "inline static" -> "static inline" for IRIC CC. 384 385 2007-03-07 Joris Van Damme <joris.at.lebbeke@skynet.be> 386 387 * libtiff/tif_getimage.c: workaround for 'Fractional scanline' error reading 388 OJPEG images with rowsperstrip that is not a multiple of vertical subsampling 389 factor. This bug is mentioned in: 390 http://bugzilla.remotesensing.org/show_bug.cgi?id=1390 391 http://www.asmail.be/msg0054766825.html 392 393 2007-03-07 Joris Van Damme <joris.at.lebbeke@skynet.be> 394 395 * libtiff/tif_win32.c: made inclusion of windows.h unconditional 396 397 * libtiff/tif_win32.c: replaced preprocessor indication for consiously 398 unused arguments by standard C indication for the same 399 400 2007-02-27 Andrey Kiselev <dron@ak4719.spb.edu> 401 402 * libtiff/tif_dirread.c: Use uint32 type instead of tsize_t in byte 403 counters in TIFFFetchData(). Should finally fix the issue 404 405 http://bugzilla.remotesensing.org/show_bug.cgi?id=890 406 407 2007-02-24 Andrey Kiselev <dron@ak4719.spb.edu> 408 409 * tools/tiffset.c: Properly handle tags with TIFF_VARIABLE writecount. 410 As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1350 411 412 * libtiff/tif_dirread.c: Added special function to handle 413 SubjectDistance EXIF tag as per bug 414 415 http://bugzilla.remotesensing.org/show_bug.cgi?id=1362 416 417 * tools/tiff2pdf.c: Do not assume inches when the resolution units 418 do not specified. As per bug 419 420 http://bugzilla.remotesensing.org/show_bug.cgi?id=1366 421 422 * tools/{tiffcp.c, tiffcrop.c}: Do not change RowsPerStrip value if 423 it was set as infinite. As per bug 424 425 http://bugzilla.remotesensing.org/show_bug.cgi?id=1368 426 427 * tools/tiffcrop.c, man/tiffcrop.1: New tiffcrop utility contributed 428 by Richard Nolde. As per bug 429 430 http://bugzilla.remotesensing.org/show_bug.cgi?id=1383 431 432 2007-02-22 Andrey Kiselev <dron@ak4719.spb.edu> 433 434 * libtiff/tif_dir.c: Workaround for incorrect TIFFs with 435 ExtraSamples == 999 produced by Corel Draw. As per bug 436 437 http://bugzilla.remotesensing.org/show_bug.cgi?id=1490 438 439 * libtiff/{tif_dirread.c, tif_read.c}: Type of the byte counters 440 changed from tsize_t to uint32 to be able to work with data arrays 441 larger than 2GB. Fixes bug 442 443 http://bugzilla.remotesensing.org/show_bug.cgi?id=890 444 445 Idea submitted by Matt Hancher. 446 447 2007-01-31 Andrey Kiselev <dron@ak4719.spb.edu> 448 449 * tools/tif2rgba.c: This utility does not work properly on big-endian 450 architectures. It was fixed including the bug 451 452 http://bugzilla.remotesensing.org/show_bug.cgi?id=1149 453 454 2007-01-15 Mateusz Loskot <mateusz@loskot.net> 455 456 * Submitted libtiff port for Windows CE platform 457 * libtiff/tif_config.wince.h: Added configuration header for WinCE. 458 * libtiff/tiffconf.wince.h: Ported old configuration header for WinCE. 459 * libtiff/tif_wince.c: Added WinCE-specific implementation of some 460 functons from tif_win32.c. 461 * libtiff/tif_win32.c: Disabled some functions already reimplemented in tif_wince.c. 462 * libtiff/tiffiop.h, port/lfind.c: Added conditional include of some 463 standard header files for Windows CE build. 464 * tools/tiffinfoce.c: Ported tiffinfo utility for Windows CE. 465 466 2006-11-19 Frank Warmerdam <warmerdam@pobox.com> 467 468 * libtiff/tif_write.c: TIFFAppendToStrip() - clear sorted flag if 469 we move a strip. 470 http://bugzilla.remotesensing.org/show_bug.cgi?id=1359 471 472 2006-10-13 Andrey Kiselev <dron@ak4719.spb.edu> 473 474 * libtiff/tif_dir.c: More fixes for vulnerabilities, reported 475 in Gentoo bug (): 476 477 http://bugs.gentoo.org/show_bug.cgi?id=142383 478 479 * libtiff/contrib/dbs/xtiff/xtiff.c: Make xtiff utility compilable. 480 Though it is still far from the state of being working and useful. 481 482 2006-10-12 Andrey Kiselev <dron@ak4719.spb.edu> 483 484 * libtiff/tif_fax3.c: Save the state of printdir codec dependent 485 method. 486 487 * libtiff/tif_jpeg.c: Save the state of printdir codec dependent method 488 as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1273 489 490 * libtiff/tif_win32.c: Fixed problem with offset value manipulation 491 as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1322 492 493 * libtiff/{tif_read.c, tif_jpeg.c, tif_dir.c}: More fixes for 494 vulnerabilities, reported in Gentoo bug (): 495 496 http://bugs.gentoo.org/show_bug.cgi?id=142383 497 498 2006-09-28 Andrey Kiselev <dron@ak4719.spb.edu> 499 500 * libtiff/{tif_fax3.c, tif_next.c, tif_pixarlog.c}: Fixed multiple 501 vulnerabilities, as per Gentoo bug (): 502 503 http://bugs.gentoo.org/show_bug.cgi?id=142383 504 505 2006-09-27 Frank Warmerdam <warmerdam@pobox.com> 506 507 * libtiff/tif_lzw.c, libtiff/tif_zip.c: Fixed problems with mixing 508 encoding and decoding on the same read-write TIFF handle. The LZW 509 code can now maintain encode and decode state at the same time. The 510 ZIP code will switch back and forth as needed. 511 http://bugzilla.remotesensing.org/show_bug.cgi?id=757 512 513 2006-09-20 Frank Warmerdam <warmerdam@pobox.com> 514 515 * libtiff: Rename config.h.vc and tif_config.h.vc to config.vc.h and 516 tif_config.vc.h for easier identification by folks using an IDE. 517 518 2006-07-25 Frank Warmerdam <warmerdam@pobox.com> 519 520 * tif_msdos.c: Avoid handle leak for failed opens. c/o Thierry Pierron 521 522 2006-07-19 Frank Warmerdam <warmerdam@pobox.com> 523 524 * tif_dirwrite.c: take care not to flush out buffer of strip/tile 525 data in _TIFFWriteDirectory if TIFF_BEENWRITING not set. Relates 526 to bug report by Peng Gao with black strip at bottom of images. 527 528 2006-07-12 Frank Warmerdam <warmerdam@pobox.com> 529 530 * tif_dirwrite.c: make sure to use uint32 for wordcount in 531 TIFFWriteNormanTag if writecount is VARIABLE2 for ASCII fields. 532 It already seems to have been done for other field types. Needed 533 for "tiffset" on files with geotiff ascii text. 534 535 2006-07-04 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 536 537 * {configure.ac, libtiff/tif_config.h.vc, libtiff/tif_jbig.c} 538 (JBIGDecode): jbg_newlen is not available in older JBIG-KIT and 539 its use does not appear to be required, so use it only when it is 540 available. 541 542 2006-06-24 Andrey Kiselev <dron@ak4719.spb.edu> 543 544 * libtiff/tif_dirinfo.c: Added missed EXIF tag ColorSpace (40961). 545 546 * libtiff/tif_dirread.c: Move IFD fetching code in the separate 547 function TIFFFetchDirectory() avoiding code duplication in 548 TIFFReadDirectory() and TIFFReadCustomDirectory(). 549 550 2006-06-19 Frank Warmerdam <warmerdam@pobox.com> 551 552 * tools/tiff2pdf.c: Fix handling of -q values. 553 http://bugzilla.remotesensing.org/show_bug.cgi?id=587 554 555 2006-06-17 Frank Warmerdam <warmerdam@pobox.com> 556 557 * tif_readdir.c: Added case in EstimateStripByteCounts() for tiled 558 files. Modified TIFFReadDirectory() to not invoke 559 EstimateStripByteCounts() for case where entry 0 and 1 are unequal 560 but one of them is zero. 561 http://bugzilla.remotesensing.org/show_bug.cgi?id=1204 562 563 2006-06-08 Andrey Kiselev <dron@ak4719.spb.edu> 564 565 * libtiff/{tif_open.c, tif_dirread.c, tiffiop.h}: Move IFD looping 566 checking code in the separate function TIFFCheckDirOffset(). 567 568 * libtiff/tif_aux.c: Added _TIFFCheckRealloc() function. 569 570 * tools/tiffcmp.c: Fixed floating point comparison logic as per bug 571 572 http://bugzilla.remotesensing.org/show_bug.cgi?id=1191 573 574 * libtiff/tif_fax3.c: Fixed problems in fax decoder as per bug 575 576 http://bugzilla.remotesensing.org/show_bug.cgi?id=1194 577 578 * tools/tiff2pdf.c: Fixed buffer overflow condition in 579 t2p_write_pdf_string() as per bug 580 581 http://bugzilla.remotesensing.org/show_bug.cgi?id=1196 582 583 2006-06-07 Andrey Kiselev <dron@ak4719.spb.edu> 584 585 * {configure, configure.ac, libtiff/tif_jbig.c, tools/tiffcp.c}: Added 586 support for JBIG compression scheme (34661 code) contributed by Lee 587 Howard. As per bug 588 589 http://bugzilla.remotesensing.org/show_bug.cgi?id=896 590 591 * configure, configure.ac: OJPEG support enabled by default. 592 593 * contrib/ojpeg/: Removed. New OJPEG support does not need this patch. 594 595 2006-06-03 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> 596 597 * libtiff/{tif_dirinfo.c, tif_print.c} : Fix crash in 598 TIFFPrintDirectory(). Joris Van Damme authored the fix. 599 600 2006-04-21 Andrey Kiselev <dron@ak4719.spb.edu> 601 602 * tools/tiff2pdf.c: Unified line ending characters (always use '\n') 603 as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1163 604 605 * README.vms, Makefile.am, configure.com, libtiff/{Makefile.am, 606 tif_config.h-vms, tif_stream.cxx, tif_vms.c, tiffconf.h-vms}: 607 Added support for OpenVMS by Alexey Chupahin, elvis_75@mail.ru. 608 609 2006-04-20 Andrey Kiselev <dron@ak4719.spb.edu> 610 611 * tools/{fax2ps.c, fax2tiff.c, ppm2tiff.c, ras2tiff.c, tiff2pdf.c}: 612 Properly set the binary mode for stdin stream as per bug 613 http://bugzilla.remotesensing.org/show_bug.cgi?id=1141 614 615 * man/{bmp2tiff.1, fax2ps.1, fax2tiff.1, gif2tiff.1, ras2tiff.1, 616 raw2tiff.1, rgb2ycbcr.1, sgi2tiff.1, tiff2bw.1, tiff2pdf.1, tiff2ps.1, 617 tiff2rgba.1, tiffcmp.1, tiffcp.1, tiffdither.1, tiffdump.1, tiffgt.1, 618 tiffset.1}: Improvements in page formatting as per bug 619 http://bugzilla.remotesensing.org/show_bug.cgi?id=1140 620 621 * html/tools.html, html/man/Makefile.am, tools/tiff2pdf.c: Fixed 622 typos as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1139 623 624 2006-04-18 Frank Warmerdam <warmerdam@pobox.com> 625 626 * nmake.opt: use /EHsc for VS2005 compatibility. Also define 627 _CRT_SECURE_NO_DEPRECATE to avoid noise on VS2005. 628 629 2006-04-12 Joris Van Damme <joris.at.lebbeke@skynet.be> 630 631 * libtiff/tif_getimage.c: Added support for planarconfig separate 632 non-subsampled YCbCr (i.e. separate YCbCr with subsampling [1,1]) 633 634 2006-04-11 Joris Van Damme <joris.at.lebbeke@skynet.be> 635 636 * libtiff/tif_getimage.c: Revision of all RGB(A) put routines 637 - Conversion of unassociated alpha to associated alpha now done with 638 more performant LUT, and calculation more correct 639 - Conversion of 16bit data to 8bit data now done with 640 more performant LUT, and calculation more correct 641 - Bugfix of handling of 16bit RGB with unassociated alpha 642 643 2006-04-11 Joris Van Damme <joris.at.lebbeke@skynet.be> 644 645 * libtiff/tif_getimage.c: 646 - When there is no alpha, gtTileSeparate and gtStripSeparate allocated 647 buffer for alpha strile and filled it, only to never read it back. 648 Removed allocation and fill. 649 - Minor rename of vars in gtTileSeparate and gtStripSeparate 650 anticipating planned functionality extension 651 652 2006-04-08 Joris Van Damme <joris.at.lebbeke@skynet.be> 653 654 * libtiff/tif_getimage.c: renamed pickTileContigCase to PickContigCase 655 and pickTileSeparateCase to PickSeparateCase as both work on strips as 656 well 657 658 * libtiff/tif_getimage.c: moved img->get selection from 659 TIFFRGBAImageBegin into PickContigCase and PickSeparateCase to create 660 logical hook for planned functionality extension 661 662 2006-04-08 Joris Van Damme <joris.at.lebbeke@skynet.be> 663 664 * libtiff/tif_ojpeg.c: resolved memory leak that was a consequence 665 of inappropriate use of jpeg_abort instead of jpeg_destroy 666 667 2006-04-07 Joris Van Damme <joris.at.lebbeke@skynet.be> 668 669 * libtiff/tif_getimage.c: replaced usage of TIFFScanlineSize in 670 gtStripContig with TIFFNewScanlineSize so as to fix buggy behaviour 671 on subsampled images - this ought to get sorted when we feel brave 672 enough to replace TIFFScanlineSize alltogether 673 674 * libtiff/tif_ojpeg.c: fixed bug in OJPEGReadSkip 675 676 2006-04-04 Joris Van Damme <joris.at.lebbeke@skynet.be> 677 678 * libtiff/tiffio.h: added new type tstrile_t 679 680 * libtiff/tif_dir.h: changed types of td_stripsperimage and td_nstrips 681 to new tstrile_t, types of td_stripoffset and td_stripbytecount to 682 toff_t* 683 684 * libtiff/tif_ojpeg.c: totally new implementation 685 686 * libtiff/tif_dirread.c: added several hacks to suit new support of 687 OJPEG 688 689 * libtiff/tif_getimage.c: removed TIFFTAG_JPEGCOLORMODE handling 690 of OJPEG images in favor of tif_getimage.c native handling of 691 YCbCr and desubsampling 692 693 2006-03-29 Frank Warmerdam <warmerdam@pobox.com> 694 695 * libtiff/tif_jpeg.c: JPEGVSetField() so that altering the photometric 696 interpretation causes the "upsampled" flag to be recomputed. Fixes 697 peculiar bug where photometric flag had to be set before jpegcolormode 698 flag. 699 700 2006-03-25 Joris Van Damme <joris.at.lebbeke@skynet.be> 701 702 * libtiff/tif_jpeg.c: strip size related bugfix in encode raw 703 704 * libtiff/tif_strip.c: temporarilly added two new versions of 705 TIFFScanlineSize 706 - TIFFNewScanlineSize: proposed new version, after all related 707 issues and side-effects are sorted out 708 - TIFFOldScanlineSize: old version, from prior to 2006-03-21 change 709 This needs further sorting out. 710 711 2006-03-25 Joris Van Damme <joris.at.lebbeke@skynet.be> 712 713 * contrib/addtiffo/tif_ovrcache.c: bugfix to correctly pass size 714 of last truncated strip data to TIFFWriteEncodedStrip 715 716 2006-03-25 Joris Van Damme <joris.at.lebbeke@skynet.be> 717 718 * libtiff/{tif_jpeg.c, tif_strip.c}: bugfix of tif_jpeg decode raw 719 720 2006-03-25 Joris Van Damme <joris.at.lebbeke@skynet.be> 721 722 * libtiff/tif_getimage.c: bugfix/rewrite of putcontig8bitYCbCr22tile 723 724 * libtiff/tif_getimage.c: added putcontig8bitYCbCr12tile 725 726 * libtiff/tif_read.c: added support for new TIFF_NOREADRAW flag to 727 prepare the path for new tif_ojpeg.c 728 1 729 2006-03-23 Andrey Kiselev <dron@ak4719.spb.edu> 2 730 -
trunk/src/3rdparty/libtiff/HOWTO-RELEASE
r2 r846 1 1 HOWTO-RELEASE: 2 2 3 Notes on releasing. You will need appropriate autoconf, automake and libtool 4 utilities to release a package. 3 Notes on releasing. 4 5 0. Make sure that you have current FSF releases of autoconf, automake, 6 and libtool packages installed under a common installation prefix 7 and that these tools are in your executable search path prior to 8 any other installed versions. Versions delivered with Linux may be 9 altered so it is best to install official FSF releases. GNU 'm4' 10 1.4.6 or later is needed in order to avoid bugs in m4. These 11 packages may be downloaded from the following ftp locations: 12 13 autoconf - ftp://ftp.gnu.org/pub/gnu/autoconf 14 automake - ftp://ftp.gnu.org/pub/gnu/automake 15 libtool - ftp://ftp.gnu.org/pub/gnu/libtool 16 17 Release builds should only be done on a system with a functioning 18 and correctly set system clock and on a filesystem which accurately 19 records file update times. Use of GNU make is recommended. 5 20 6 21 1. Commit any unsaved changes. 7 22 8 2. "make clean" 9 10 3. Create html/vX.X.html. Take ChangeLog entries and html-ify in there. 23 2. Create html/vX.X.html. Take ChangeLog entries and html-ify in there. 11 24 Easist thing to do is take html/vX.(X-1).html and use it as a template. 12 25 Add that file to the list of EXTRA_DIST files in the html/Makefile.am. 13 26 14 3. 5.Update html/index.html to refer to this new page as the current release.27 3. Update html/index.html to refer to this new page as the current release. 15 28 16 4. Increment version in configure.ac. Put 'alpha' or 'beta' after17 the version, if applicable.29 4. Increment the release version in configure.ac. Put 'alpha' or 30 'beta' after the version, if applicable. For example: 18 31 19 eg. 20 3.5.7 21 or 22 3.5.8beta 32 3.9.1 33 or 34 3.9.1beta 23 35 24 36 Version should be updated in two places: in the second argument of the 25 37 AC_INIT macro and in LIBTIFF_xxx_VERSION variables. 26 38 27 5. autoconf39 5. Add an entry to Changelog similar to: 28 40 29 6. sh configure 41 * libtiff 3.9.1 released. 30 42 31 7. make release -- this will update "RELEASE-DATE" and "VERSION" in the top 32 level dir, and libtiff/tiffvers.h. 43 6. In the source tree do 33 44 34 8. Please verify that the version info in RELEASE-DATE, VERSION and 35 libtiff/tiffvers.h is right. 45 ./autogen.sh 36 46 37 9. make; make distcheck (to test). 47 This step may be skipped if you have already been using a 48 maintainer build with current autoconf, automake, and libtool 49 packages. It is only needed when updating tool versions. 38 50 39 10. make distclean 51 7. It is recommended (but not required) to build outside of the source 52 tree so that the source tree is kept in a pristine state. This 53 also allows sharing the source directory on several networked 54 systems. For example: 40 55 41 11. cvs commit 56 mkdir libtiff-build 57 cd libtiff-build 58 /path/to/libtiff/configure --enable-maintainer-mode 42 59 43 12. cvs tag Release-v3-5-7 (or the appropriate name for the release) 60 otherwise do 44 61 45 13. configure; make dist 62 ./configure --enable-maintainer-mode 63 64 8. In the build tree do 65 66 make release 67 68 This will update "RELEASE-DATE", "VERSION", and libtiff/tiffvers.h 69 in the source tree. 70 71 9. In the source tree, verify that the version info in RELEASE-DATE, 72 VERSION and libtiff/tiffvers.h is right. 73 74 10. In the build tree do 75 76 make 77 make distcheck 78 79 If 'make distcheck' fails, then correct any issues until it 80 succeeds. 81 46 82 Two files with names tiff-version.tar.gz and tiff-version.zip will 47 be created in the top level packagedirectory.83 be created in the top level build directory. 48 84 49 14. Copy to ftp.remotesensing.org ftp site. 50 scp tiff-*.tar.gz ftp.remotesensing.org:/var/ftp/libtiff/ 51 scp tiff-*.zip ftp.remotesensing.org:/var/ftp/libtiff/ 85 11. In the source tree do 52 86 53 15. Announce to list, tiff@lists.maptools.org 87 'cvs commit'. 54 88 55 16. Update libtiff page on freshmeat with new version announcement. 89 12. In the source tree do 90 91 cvs tag Release-v3-9-1 92 93 (or the appropriate name for the release) 94 95 13. Copy release packages from the build tree to the 96 ftp.remotesensing.org ftp site. 97 98 scp tiff-*.tar.gz tiff-*.zip \ 99 frankw@upload.osgeo.org:/osgeo/download/libtiff 100 101 14. Announce to list, tiff@lists.maptools.org 102 103 15. Update libtiff page on freshmeat with new version announcement. 56 104 57 105 -
trunk/src/3rdparty/libtiff/RELEASE-DATE
r2 r846 1 200 603231 20091104 -
trunk/src/3rdparty/libtiff/SConstruct
r2 r846 1 # $Id: SConstruct,v 1. 2 2006/03/23 14:54:00dron Exp $1 # $Id: SConstruct,v 1.4 2007/02/24 15:03:47 dron Exp $ 2 2 3 3 # Tag Image File Format (TIFF) Software … … 77 77 # Now proceed to system feature checks 78 78 target_cpu, target_vendor, target_kernel, target_os = \ 79 os.popen("./config .guess").readlines()[0].split("-")79 os.popen("./config/config.guess").readlines()[0].split("-") 80 80 81 81 def Define(context, key, have): … … 133 133 conf.CheckCHeader('assert.h') 134 134 conf.CheckCHeader('fcntl.h') 135 conf.CheckCHeader('io.h') 135 136 conf.CheckCHeader('limits.h') 136 137 conf.CheckCHeader('malloc.h') … … 146 147 conf.CheckFunc('mmap') 147 148 conf.CheckFunc('pow') 149 conf.CheckFunc('setmode') 148 150 conf.CheckFunc('sqrt') 149 151 conf.CheckFunc('strchr') -
trunk/src/3rdparty/libtiff/VERSION
r2 r846 1 3. 8.21 3.9.2 -
trunk/src/3rdparty/libtiff/html/bugs.html
r2 r846 15 15 16 16 <P> 17 Thanks to <A HREF=http://www.remotesensing.org/>remotesensing.org</a>, libtiff now uses bugzilla to track bugs. 17 Thanks to <A HREF=http://www.maptools.org/>MapTools.org</a>, libtiff now uses 18 bugzilla to track bugs. All bugs filed in the older bugzilla at 19 bugzilla.remotesensing.org (pre April 2008) have unfortunately been lost. 18 20 <P> 19 21 If you think you've discovered a bug, please first check to see if it is 20 22 already known by looking at the list of already reported bugs. You can do so 21 23 by visiting the buglist at 22 <A HREF=http://bugzilla. remotesensing.org/buglist.cgi?product=libtiff>http://bugzilla.remotesensing.org/buglist.cgi?product=libtiff</A>. Also verify that24 <A HREF=http://bugzilla.maptools.org/buglist.cgi?product=libtiff>http://bugzilla.maptools.org/buglist.cgi?product=libtiff</A>. Also verify that 23 25 the problem is still reproducable with the current development software 24 26 from CVS. 25 <p> 26 If you'd like to enter a new bug, you can do so at <A HREF=http://bugzilla.remotesensing.org/enter_bug.cgi?product=libtiff>http://bugzilla.remotesensing.org/enter_bug.cgi?product=libtiff</A>. 27 <P> 28 If you'd like to enter a new bug, you can do so at 29 <A HREF=http://bugzilla.maptools.org/enter_bug.cgi?product=libtiff>http://bugzilla.maptools.org/enter_bug.cgi?product=libtiff</A>. 30 <P> 31 If you'd like to inform us about some kind of security issue that should not 32 be disclosed for a period of time, then you can contact maintainers directly. 33 Send a copies of your report to the following people: Frank Warmerdam 34 <a href="mailto:warmerdam@pobox.com"><warmerdam@pobox.com></a>, 35 Andrey Kiselev 36 <a href="mailto:dron@ak4719.spb.edu"><dron@ak4719.spb.edu></a>. 27 37 <P> 28 38 … … 49 59 <HR> 50 60 51 Last updated: $Date: 200 5/07/26 14:43:24$61 Last updated: $Date: 2008/09/03 08:04:26 $ 52 62 </BODY> 53 63 </HTML> -
trunk/src/3rdparty/libtiff/html/document.html
r2 r846 15 15 A copy of the 6.0 specification is available from Adobe at 16 16 <A HREF="http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf">http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf</A>, or from the libtiff 17 ftp site at <a href="ftp://ftp.remotesensing.org/pub/libtiff/ TIFF6.pdf">18 ftp://ftp.remotesensing.org/pub/libtiff/ TIFF6.pdf</A>.<p>17 ftp site at <a href="ftp://ftp.remotesensing.org/pub/libtiff/doc/TIFF6.pdf"> 18 ftp://ftp.remotesensing.org/pub/libtiff/doc/TIFF6.pdf</A>.<p> 19 19 20 20 <P> … … 39 39 http://www.awaresystems.be/imaging/tiff/faq.html</A> 40 40 41 <P>42 There is a preliminary <a href="bigtiffdesign.html">BigTIFF Design</a> for43 a TIFF variation supporting files larger than 4GB.44 45 41 <HR> 46 42 47 43 <ADDRESS> 48 Last updated: $Date: 200 4/12/02 14:51:19$44 Last updated: $Date: 2009-08-20 22:31:00 $ 49 45 </ADDRESS> 50 46 -
trunk/src/3rdparty/libtiff/html/index.html
r2 r846 25 25 <tr> 26 26 <th>Latest Stable Release</th> 27 <td><a href="v3.8.2.html">v3.8.2</a></td> 28 </tr> 29 <tr> 30 <th>Latest Development Release</th> 31 <td><a href="v3.8.2.html">v3.8.2</a></td> 27 <td><a href="v3.9.2.html">v3.9.2</a></td> 32 28 </tr> 33 29 <tr> … … 54 50 <th>Anonymous CVS</th> 55 51 <td><tt>export CVSROOT=:pserver:cvsanon@cvs.maptools.org:/cvs/maptools/cvsroot<br> 56 cvs login # use empty password"<br> 57 cvs checkout libtiff<br></tt></td> 52 cvs login</tt><br> 53 (use empty password)<br> 54 <tt>cvs checkout -r branch-3-9 libtiff<br></tt> 55 to get stable libtiff branch, or<br> 56 <tt>cvs checkout libtiff</tt><br> 57 to get bleeding edge development version of libtiff from CVS HEAD.</td> 58 58 </tr> 59 59 </table> … … 66 66 </p> 67 67 <p> 68 Included in this software distribution is a library, libtiff, for 69 reading and writing TIFF, a small collection of tools for doing simple 70 manipulations of TIFF images on UNIX systems, 71 and documentation on the library and 72 tools. A small assortment of TIFF-related software for UNIX 73 that has been contributed by others is also included. 68 Included in this software distribution is a library, libtiff, for reading 69 and writing TIFF, a small collection of tools for doing simple 70 manipulations of TIFF images, and documentation on the 71 library and tools. Libtiff is a portable software, it was built and 72 tested on various systems: UNIX flavors (Linux, BSD, Solaris, MacOS X), 73 Windows, OpenVMS. It should be possible to port libtiff and additional 74 tools on other OSes. 74 75 </p> 75 76 <p> … … 81 82 </p> 82 83 <p> 83 The software was or ginally authored and maintained by Sam Leffler.84 The software was originally authored and maintained by Sam Leffler. 84 85 While he keeps a fatherly eye on the mailing list, he is no longer 85 86 responsible for day to day maintenance. … … 95 96 versions >= 3.5.1 are 96 97 <a href="http://pobox.com/~warmerdam">Frank Warmerdam</a>, 97 <a href="mailto:dron@ak4719.spb.edu">Andrey Kiselev</a> and Mike Welles. 98 <a href="mailto:dron@ak4719.spb.edu">Andrey Kiselev</a>, Bob Friesenhahn, 99 Joris Van Damme and Lee Howard. 98 100 </p> 99 101 <p> … … 116 118 <hr> 117 119 <p> 118 Last updated $Date: 200 6/03/23 14:54:01$.120 Last updated $Date: 2009-08-28 16:24:13 $. 119 121 </p> 120 122 </body> -
trunk/src/3rdparty/libtiff/html/man/TIFFClose.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:08 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:15 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFDataWidth.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:08 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:15 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFError.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:08 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:15 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFFlush.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:08 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:15 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFGetField.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:08 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:15 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFOpen.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:08 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:15 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFPrintDirectory.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:09 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:15 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFRGBAImage.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:10 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:16 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFReadDirectory.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:09 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:16 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFReadEncodedStrip.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:09 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:16 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFReadEncodedTile.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:09 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:16 2007 --> 3 3 <html> 4 4 <head> … … 42 42 <!-- INDENTATION --> 43 43 <p><b>int TIFFReadEncodedTile(TIFF *</b><i>tif</i><b>, 44 u_long</b> <i>tile</i><b>, u_char *</b><i>buf</i><b>,45 u_long</b> <i>size</i><b>)</b></p>44 ttile_t</b> <i>tile</i><b>, tdata_t</b> <i>buf</i><b>, 45 tsize_t</b> <i>size</i><b>)</b></p> 46 46 </td> 47 47 </table> -
trunk/src/3rdparty/libtiff/html/man/TIFFReadRGBAImage.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:09 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:16 2007 --> 3 3 <html> 4 4 <head> … … 48 48 <!-- INDENTATION --> 49 49 <p><b>int TIFFReadRGBAImage(TIFF *</b><i>tif</i><b>, 50 u _long</b> <i>width</i><b>, u_long</b> <i>height</i><b>,51 u _long*</b><i>raster</i><b>, int</b>50 uint32</b> <i>width</i><b>, uint32</b> <i>height</i><b>, 51 uint32 *</b><i>raster</i><b>, int</b> 52 52 <i>stopOnError</i><b>)<br> 53 53 int TIFFReadRGBAImageOriented(TIFF *</b><i>tif</i><b>, 54 u _long</b> <i>width</i><b>, u_long</b> <i>height</i><b>,55 u _long*</b><i>raster</i><b>, int</b> <i>orientation</i><b>,54 uint32</b> <i>width</i><b>, uint32</b> <i>height</i><b>, 55 uint32 *</b><i>raster</i><b>, int</b> <i>orientation</i><b>, 56 56 int</b> <i>stopOnError</i><b>)</b></p> 57 57 </td> -
trunk/src/3rdparty/libtiff/html/man/TIFFReadRGBAStrip.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:10 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:16 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFReadRGBATile.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:10 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:16 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFReadRawStrip.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:09 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:16 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFReadRawTile.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:09 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:16 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFReadScanline.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:10 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:16 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFReadTile.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:10 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:16 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFSetDirectory.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:10 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:17 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFSetField.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:10 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:17 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFWarning.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:11 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:17 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFWriteDirectory.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:11 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:17 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFWriteEncodedStrip.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:11 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:17 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFWriteEncodedTile.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:11 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:17 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFWriteRawStrip.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:11 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:17 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFWriteRawTile.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:11 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:18 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFWriteScanline.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:11 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:18 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFWriteTile.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:11 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:18 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFbuffer.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:08 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:14 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFcodec.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:08 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:15 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFcolor.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:08 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:15 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFmemory.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:08 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:15 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFquery.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:09 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:15 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFsize.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:10 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:17 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFstrip.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:10 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:17 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFswab.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:10 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:17 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/TIFFtile.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:11 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:17 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/fax2ps.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:11 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:18 2007 --> 3 3 <html> 4 4 <head> … … 29 29 <td width="91%"> 30 30 <p>fax2ps − convert a <small>TIFF</small> facsimile to 31 compressed ™</p>31 compressed PostScript™</p> 32 32 </td> 33 33 </table> … … 40 40 <td width="8%"></td> 41 41 <td width="91%"> 42 <p><b>fax2ps</b> [ <i>options</i> ] [ <i>file </i>...]</p>42 <p><b>fax2ps</b> [ <i>options</i> ] [ <i>file ...</i> ]</p> 43 43 </td> 44 44 </table> … … 52 52 <td width="91%"> 53 53 <p><i>fax2ps</i> reads one or more <small>TIFF</small> 54 facsimile image files and prints a compressed form of on the 55 standard output that is suitable for printing.</p> 54 facsimile image files and prints a compressed form of 55 PostScript on the standard output that is suitable for 56 printing.</p> 56 57 <!-- INDENTATION --> 57 58 <p>By default, each page is scaled to reflect the image … … 65 66 <b>−W</b> and <b>−H</b> options.</p> 66 67 <!-- INDENTATION --> 67 <p>By default <i>fax2ps</i> generates for all pages in the 68 file. The <b>−p</b> option can be used to select one 69 or more pages from a multi-page document.</p> 70 <!-- INDENTATION --> 71 <p><i>fax2ps</i> generates a compressed form of that is 72 optimized for sending pages of text to a printer attached to 73 a host through a low-speed link (such as a serial line). 74 Each output page is filled with white and then only the 75 black areas are drawn. The specification of the black 76 drawing operations is optimized by using a special font that 77 encodes the move-draw operations required to fill the black 78 regions on the page. This compression scheme typically 79 results in a substantially reduced description, relative to 80 the straightforward imaging of the page with a <i>image</i> 81 operator. This algorithm can, however, be ineffective for 82 continuous-tone and white-on-black images. For these images, 83 it sometimes is more efficient to send the raster bitmap 84 image directly; see <i>tiff2ps</i>(1).</p> 68 <p>By default <i>fax2ps</i> generates PostScript for all 69 pages in the file. The <b>−p</b> option can be used to 70 select one or more pages from a multi-page document.</p> 71 <!-- INDENTATION --> 72 <p><i>fax2ps</i> generates a compressed form of PostScript 73 that is optimized for sending pages of text to a PostScript 74 printer attached to a host through a low-speed link (such as 75 a serial line). Each output page is filled with white and 76 then only the black areas are drawn. The PostScript 77 specification of the black drawing operations is optimized 78 by using a special font that encodes the move-draw 79 operations required to fill the black regions on the page. 80 This compression scheme typically results in a substantially 81 reduced PostScript description, relative to the 82 straightforward imaging of the page with a PostScript 83 <i>image</i> operator. This algorithm can, however, be 84 ineffective for continuous-tone and white-on-black images. 85 For these images, it sometimes is more efficient to send the 86 raster bitmap image directly; see <b>tiff2ps</b>(1).</p> 85 87 </td> 86 88 </table> … … 89 91 <!-- TABS --> 90 92 <table width="100%" border=0 rules="none" frame="void" 91 cols=" 5" cellspacing="0" cellpadding="0">92 <tr valign="top" align="left"> 93 <td width="1 0%"></td>93 cols="4" cellspacing="0" cellpadding="0"> 94 <tr valign="top" align="left"> 95 <td width="11%"></td> 94 96 <td width="11%"> 95 97 96 98 <p><b>−p</b> <i>number</i></p> 97 99 </td> 98 <td width="1%"></td>99 100 <td width="76%"> 100 101 … … 145 146 <!-- TABS --> 146 147 <table width="100%" border=0 rules="none" frame="void" 147 cols=" 5" cellspacing="0" cellpadding="0">148 cols="4" cellspacing="0" cellpadding="0"> 148 149 <tr valign="top" align="left"> 149 150 <td width="10%"></td> 150 <td width="1 1%">151 <td width="12%"> 151 152 152 153 <p><b>−S</b></p> 153 154 </td> 154 <td width="1%"></td>155 155 <td width="76%"> 156 156 … … 164 164 <tr valign="top" align="left"> 165 165 <td width="10%"></td> 166 <td width="1 1%">166 <td width="12%"> 167 167 168 168 <p><b>−W</b> <i>width</i></p> 169 169 </td> 170 <td width="1%"></td>171 170 <td width="76%"> 172 171 … … 178 177 <tr valign="top" align="left"> 179 178 <td width="10%"></td> 180 <td width="1 1%">179 <td width="12%"> 181 180 182 181 <p><b>−H</b> <i>height</i></p> 183 182 </td> 184 <td width="1%"></td>185 183 <td width="76%"> 186 184 … … 207 205 errors by resynchronizing decoding at the end of the current 208 206 scanline. This can result in long horizontal black lines in 209 the resultant image.</p>207 the resultant PostScript image.</p> 210 208 </td> 211 209 </table> … … 218 216 <td width="8%"></td> 219 217 <td width="91%"> 220 <p>If the destination printer supports Level II then it is221 always faster to just send the encoded bitmap generated by 222 the <b>tiff2ps</b>(1) program.</p>218 <p>If the destination printer supports PostScript Level II 219 then it is always faster to just send the encoded bitmap 220 generated by the <b>tiff2ps</b>(1) program.</p> 223 221 </td> 224 222 </table> … … 232 230 <td width="91%"> 233 231 <p><i>fax2ps</i> should probably figure out when it is doing 234 a poor job of compressing the output and just generate to235 image the bitmap raster instead.</p>232 a poor job of compressing the output and just generate 233 PostScript to image the bitmap raster instead.</p> 236 234 </td> 237 235 </table> -
trunk/src/3rdparty/libtiff/html/man/fax2tiff.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:12 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:18 2007 --> 3 3 <html> 4 4 <head> … … 486 486 rows/strip that no more than 8 kilobytes of data appear in a 487 487 strip (with except of G3/G4 compression schemes). If you 488 specify special value <b> -1</b> it will results in infinite489 number of the rows per strip. The entire image will be the 490 one strip in that case. This is default in case of G3/G4 491 output compression schemes.</p>488 specify special value <b>−1</b> it will results in 489 infinite number of the rows per strip. The entire image will 490 be the one strip in that case. This is default in case of 491 G3/G4 output compression schemes.</p> 492 492 </td> 493 493 <td width="0%"> -
trunk/src/3rdparty/libtiff/html/man/gif2tiff.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:12 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:18 2007 --> 3 3 <html> 4 4 <head> … … 74 74 75 75 <p>Specify a compression scheme to use when writing image 76 data: <b>−c none</b> for no compression, <b> -c77 packbits</b> for the PackBits compression algorithm, <b>-c78 zip</b> for the Deflate compression algorithm, and 79 <b>−c lzw</b> for Lempel-Ziv & Welch (the76 data: <b>−c none</b> for no compression, <b>−c 77 packbits</b> for the PackBits compression algorithm, 78 <b>−c zip</b> for the Deflate compression algorithm, 79 and <b>−c lzw</b> for Lempel-Ziv & Welch (the 80 80 default).</p> 81 81 </td> -
trunk/src/3rdparty/libtiff/html/man/index.html
r2 r846 1 1 <HTML><HEAD><TITLE>Libtiff HTML manpage index</TITLE></HEAD><BODY BGCOLOR=white><ul><H2>Man Pages</h2><p> 2 <li><A HREF=libtiff.3tiff.html>libtiff.3tiff.html</a>3 2 <li><A HREF=TIFFbuffer.3tiff.html>TIFFbuffer.3tiff.html</a> 4 3 <li><A HREF=TIFFClose.3tiff.html>TIFFClose.3tiff.html</a> … … 54 53 <li><A HREF=tiffcmp.1.html>tiffcmp.1.html</a> 55 54 <li><A HREF=tiffcp.1.html>tiffcp.1.html</a> 55 <li><A HREF=tiffcrop.1.html>tiffcrop.1.html</a> 56 56 <li><A HREF=tiffdither.1.html>tiffdither.1.html</a> 57 57 <li><A HREF=tiffdump.1.html>tiffdump.1.html</a> -
trunk/src/3rdparty/libtiff/html/man/libtiff.3tiff.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:07 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:14 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/pal2rgb.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:12 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:18 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/ppm2tiff.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:12 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:18 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/ras2tiff.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:12 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:18 2007 --> 3 3 <html> 4 4 <head> … … 82 82 83 83 <p>Specify a compression scheme to use when writing image 84 data: <b>−c none</b> for no compression, <b> -c85 packbits</b> for the PackBits compression algorithm, <b>-c86 jpeg</b> for the baseline JPEG compression algorithm, <b>-c 87 zip</b> for the Deflate compression algorithm, and 88 <b>−c lzw</b> for Lempel-Ziv & Welch (the 89 default).</p>84 data: <b>−c none</b> for no compression, <b>−c 85 packbits</b> for the PackBits compression algorithm, 86 <b>−c jpeg</b> for the baseline JPEG compression 87 algorithm, <b>−c zip</b> for the Deflate compression 88 algorithm, and <b>−c lzw</b> for Lempel-Ziv & 89 Welch (the default).</p> 90 90 </td> 91 91 <td width="0%"> -
trunk/src/3rdparty/libtiff/html/man/raw2tiff.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:12 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:18 2007 --> 3 3 <html> 4 4 <head> … … 54 54 image is created with data samples packed 55 55 (<i>PlanarConfiguration</i>=1), compressed with the PackBits 56 algorithm (<i>Compression</i>= <i>32773),</i> and with each57 strip no more than 8 kilobytes. These characteristics can 58 o verridden, or explicitly specified with the options59 describedbelow.</p>56 algorithm (<i>Compression</i>=32773), and with each strip no 57 more than 8 kilobytes. These characteristics can overridden, 58 or explicitly specified with the options described 59 below.</p> 60 60 </td> 61 61 </table> … … 68 68 <td width="8%"></td> 69 69 <td width="91%"> 70 <p><b>−H <number></b></p></td>70 <p><b>−H</b> <i>number</i></p></td> 71 71 </table> 72 72 <!-- INDENTATION --> … … 87 87 <td width="8%"></td> 88 88 <td width="91%"> 89 <p><b>−w <number></b></p></td>89 <p><b>−w</b> <i>number</i></p></td> 90 90 </table> 91 91 <!-- INDENTATION --> … … 106 106 <td width="8%"></td> 107 107 <td width="91%"> 108 <p><b>−l <number></b></p></td>109 </table> 110 <!-- INDENTATION --> 111 <table width="100%" border=0 rules="none" frame="void" 112 cols="2" cellspacing="0" cellpadding="0"> 113 <tr valign="top" align="left"> 114 <td width="19%"></td> 115 <td width="80%"> 116 <p>length of input image in lines (can be guessed, see108 <p><b>−l</b> <i>number</i></p></td> 109 </table> 110 <!-- INDENTATION --> 111 <table width="100%" border=0 rules="none" frame="void" 112 cols="2" cellspacing="0" cellpadding="0"> 113 <tr valign="top" align="left"> 114 <td width="19%"></td> 115 <td width="80%"> 116 <p>length of input image in lines (can be guessed, see 117 117 <b><small>GUESSING THE IMAGE GEOMETRY</small></b> 118 118 below).</p> … … 125 125 <td width="8%"></td> 126 126 <td width="91%"> 127 <p><b>−b <number></b></p></td>127 <p><b>−b</b> <i>number</i></p></td> 128 128 </table> 129 129 <!-- INDENTATION --> … … 142 142 <td width="8%"></td> 143 143 <td width="91%"> 144 <p><b>−d data_type</b></p></td>145 </table> 146 <!-- INDENTATION --> 147 <table width="100%" border=0 rules="none" frame="void" 148 cols="2" cellspacing="0" cellpadding="0"> 149 <tr valign="top" align="left"> 150 <td width="19%"></td> 151 <td width="80%"> 152 <p>type of samples in input image, where < b>data_type</b>144 <p><b>−d</b> <i>data_type</i></p></td> 145 </table> 146 <!-- INDENTATION --> 147 <table width="100%" border=0 rules="none" frame="void" 148 cols="2" cellspacing="0" cellpadding="0"> 149 <tr valign="top" align="left"> 150 <td width="19%"></td> 151 <td width="80%"> 152 <p>type of samples in input image, where <i>data_type</i> 153 153 may be:</p></td> 154 154 </table> 155 155 <!-- TABS --> 156 156 <table width="100%" border=0 rules="none" frame="void" 157 cols="5" cellspacing="0" cellpadding="0"> 158 <tr valign="top" align="left"> 159 <td width="19%"></td> 160 <td width="6%"> 161 162 <p><i>byte</i></p> 163 </td> 164 <td width="6%"> 165 </td> 166 <td width="6%"> 157 cols="3" cellspacing="0" cellpadding="0"> 158 <tr valign="top" align="left"> 159 <td width="19%"></td> 160 <td width="10%"> 161 162 <p><b>byte</b></p> 163 </td> 164 <td width="70%"> 167 165 168 166 <p>8-bit unsigned integer (default),</p> 169 167 </td> 170 <td width="61%"> 171 </td> 172 <tr valign="top" align="left"> 173 <td width="19%"></td> 174 <td width="6%"> 175 176 <p><i>short</i></p> 177 </td> 178 <td width="6%"></td> 179 <td width="6%"> 168 <tr valign="top" align="left"> 169 <td width="19%"></td> 170 <td width="10%"> 171 172 <p><b>short</b></p> 173 </td> 174 <td width="70%"> 180 175 181 176 <p>16-bit unsigned integer,</p> 182 177 </td> 183 <td width="61%"> 184 </td> 185 <tr valign="top" align="left"> 186 <td width="19%"></td> 187 <td width="6%"> 188 189 <p><i>long</i></p> 190 </td> 191 <td width="6%"> 192 </td> 193 <td width="6%"> 178 <tr valign="top" align="left"> 179 <td width="19%"></td> 180 <td width="10%"> 181 182 <p><b>long</b></p> 183 </td> 184 <td width="70%"> 194 185 195 186 <p>32-bit unsigned integer,</p> 196 187 </td> 197 <td width="61%"> 198 </td> 199 <tr valign="top" align="left"> 200 <td width="19%"></td> 201 <td width="6%"> 202 203 <p><i>sbyte</i></p> 204 </td> 205 <td width="6%"></td> 206 <td width="6%"> 188 <tr valign="top" align="left"> 189 <td width="19%"></td> 190 <td width="10%"> 191 192 <p><b>sbyte</b></p> 193 </td> 194 <td width="70%"> 207 195 208 196 <p>8-bit signed integer,</p> 209 197 </td> 210 <td width="61%"> 211 </td> 212 <tr valign="top" align="left"> 213 <td width="19%"></td> 214 <td width="6%"> 215 216 <p><i>sshort</i></p> 217 </td> 218 <td width="6%"></td> 219 <td width="6%"> 198 <tr valign="top" align="left"> 199 <td width="19%"></td> 200 <td width="10%"> 201 202 <p><b>sshort</b></p> 203 </td> 204 <td width="70%"> 220 205 221 206 <p>16-bit signed integer,</p> 222 207 </td> 223 <td width="61%"> 224 </td> 225 <tr valign="top" align="left"> 226 <td width="19%"></td> 227 <td width="6%"> 228 229 <p><i>slong</i></p> 230 </td> 231 <td width="6%"></td> 232 <td width="6%"> 208 <tr valign="top" align="left"> 209 <td width="19%"></td> 210 <td width="10%"> 211 212 <p><b>slong</b></p> 213 </td> 214 <td width="70%"> 233 215 234 216 <p>32-bit signed integer,</p> 235 217 </td> 236 <td width="61%"> 237 </td> 238 <tr valign="top" align="left"> 239 <td width="19%"></td> 240 <td width="6%"> 241 242 <p><i>float</i></p> 243 </td> 244 <td width="6%"></td> 245 <td width="6%"> 218 <tr valign="top" align="left"> 219 <td width="19%"></td> 220 <td width="10%"> 221 222 <p><b>float</b></p> 223 </td> 224 <td width="70%"> 246 225 247 226 <p>32-bit IEEE floating point,</p> 248 227 </td> 249 <td width="61%"> 250 </td> 251 <tr valign="top" align="left"> 252 <td width="19%"></td> 253 <td width="6%"> 254 255 <p><i>double</i></p> 256 </td> 257 <td width="6%"></td> 258 <td width="6%"> 259 260 <p>64-bit IEEE floating point,</p> 261 </td> 262 <td width="61%"> 263 </td> 264 </table> 265 <!-- INDENTATION --> 266 <table width="100%" border=0 rules="none" frame="void" 267 cols="2" cellspacing="0" cellpadding="0"> 268 <tr valign="top" align="left"> 269 <td width="8%"></td> 270 <td width="91%"> 271 <p><b>−i config</b></p></td> 228 <tr valign="top" align="left"> 229 <td width="19%"></td> 230 <td width="10%"> 231 232 <p><b>double</b></p> 233 </td> 234 <td width="70%"> 235 236 <p>64-bit IEEE floating point.</p> 237 </td> 238 </table> 239 <!-- INDENTATION --> 240 <table width="100%" border=0 rules="none" frame="void" 241 cols="2" cellspacing="0" cellpadding="0"> 242 <tr valign="top" align="left"> 243 <td width="8%"></td> 244 <td width="91%"> 245 <p><b>−i</b> <i>config</i></p></td> 272 246 </table> 273 247 <!-- INDENTATION --> … … 278 252 <td width="80%"> 279 253 <p>type of samples interleaving in input image, where 280 < b>config</b> may be:</p></td>254 <i>config</i> may be:</p></td> 281 255 </table> 282 256 <!-- TABS --> 283 257 <table width="100%" border=0 rules="none" frame="void" 284 cols="5" cellspacing="0" cellpadding="0"> 285 <tr valign="top" align="left"> 286 <td width="19%"></td> 287 <td width="6%"> 288 289 <p><i>pixel</i></p> 290 </td> 291 <td width="6%"></td> 292 <td width="6%"> 258 cols="3" cellspacing="0" cellpadding="0"> 259 <tr valign="top" align="left"> 260 <td width="19%"></td> 261 <td width="8%"> 262 263 <p><b>pixel</b></p> 264 </td> 265 <td width="71%"> 293 266 294 267 <p>pixel interleaved data (default),</p> 295 268 </td> 296 <td width="61%"> 297 </td> 298 <tr valign="top" align="left"> 299 <td width="19%"></td> 300 <td width="6%"> 301 302 <p><i>band</i></p> 303 </td> 304 <td width="6%"> 305 </td> 306 <td width="6%"> 269 <tr valign="top" align="left"> 270 <td width="19%"></td> 271 <td width="8%"> 272 273 <p><b>band</b></p> 274 </td> 275 <td width="71%"> 307 276 308 277 <p>band interleaved data.</p> 309 278 </td> 310 <td width="61%"> 311 </td> 312 </table> 313 <!-- INDENTATION --> 314 <table width="100%" border=0 rules="none" frame="void" 315 cols="2" cellspacing="0" cellpadding="0"> 316 <tr valign="top" align="left"> 317 <td width="8%"></td> 318 <td width="91%"> 319 <p><b>−p photo</b></p></td> 279 </table> 280 <!-- INDENTATION --> 281 <table width="100%" border=0 rules="none" frame="void" 282 cols="2" cellspacing="0" cellpadding="0"> 283 <tr valign="top" align="left"> 284 <td width="8%"></td> 285 <td width="91%"> 286 <p><b>−p</b> <i>photo</i></p></td> 320 287 </table> 321 288 <!-- INDENTATION --> … … 326 293 <td width="80%"> 327 294 <p>photometric interpretation (color space) of the input 328 image, where <b>photo</b> may be:<i><br> 329 miniswhite</i> white color represented with 0 value,<i><br> 330 minisblack</i> black color represented with 0 value 331 (default),</p></td> 295 image, where <i>photo</i> may be:</p></td> 332 296 </table> 333 297 <!-- TABS --> 334 298 <table width="100%" border=0 rules="none" frame="void" 335 cols="6" cellspacing="0" cellpadding="0"> 336 <tr valign="top" align="left"> 337 <td width="19%"></td> 338 <td width="6%"> 339 340 <p><i>rgb</i></p> 341 </td> 342 <td width="6%"> 343 </td> 344 <td width="6%"> 299 cols="3" cellspacing="0" cellpadding="0"> 300 <tr valign="top" align="left"> 301 <td width="19%"></td> 302 <td width="15%"> 303 304 <p><b>miniswhite</b></p> 305 </td> 306 <td width="65%"> 307 308 <p>white color represented with 0 value,</p> 309 </td> 310 <tr valign="top" align="left"> 311 <td width="19%"></td> 312 <td width="15%"> 313 314 <p><b>minisblack</b></p> 315 </td> 316 <td width="65%"> 317 318 <p>black color represented with 0 value (default),</p> 319 </td> 320 <tr valign="top" align="left"> 321 <td width="19%"></td> 322 <td width="15%"> 323 324 <p><b>rgb</b></p> 325 </td> 326 <td width="65%"> 345 327 346 328 <p>image has RGB color model,</p> 347 329 </td> 348 <td width="6%"></td> 349 <td width="55%"> 350 </td> 351 <tr valign="top" align="left"> 352 <td width="19%"></td> 353 <td width="6%"> 354 355 <p><i>cmyk</i></p> 356 </td> 357 <td width="6%"> 358 </td> 359 <td width="6%"> 330 <tr valign="top" align="left"> 331 <td width="19%"></td> 332 <td width="15%"> 333 334 <p><b>cmyk</b></p> 335 </td> 336 <td width="65%"> 360 337 361 338 <p>image has CMYK (separated) color model,</p> 362 339 </td> 363 <td width="6%"></td> 364 <td width="55%"> 365 </td> 366 <tr valign="top" align="left"> 367 <td width="19%"></td> 368 <td width="6%"> 369 370 <p><i>ycbcr</i></p> 371 </td> 372 <td width="6%"></td> 373 <td width="6%"> 374 </td> 375 <td width="6%"> 340 <tr valign="top" align="left"> 341 <td width="19%"></td> 342 <td width="15%"> 343 344 <p><b>ycbcr</b></p> 345 </td> 346 <td width="65%"> 376 347 377 348 <p>image has YCbCr color model,</p> 378 349 </td> 379 <td width="55%"> 380 </td> 381 <tr valign="top" align="left"> 382 <td width="19%"></td> 383 <td width="6%"> 384 385 <p><i>cielab</i></p> 386 </td> 387 <td width="6%"></td> 388 <td width="6%"> 350 <tr valign="top" align="left"> 351 <td width="19%"></td> 352 <td width="15%"> 353 354 <p><b>cielab</b></p> 355 </td> 356 <td width="65%"> 389 357 390 358 <p>image has CIE L*a*b color model,</p> 391 359 </td> 392 <td width="6%"></td> 393 <td width="55%"> 394 </td> 395 <tr valign="top" align="left"> 396 <td width="19%"></td> 397 <td width="6%"> 398 399 <p><i>icclab</i></p> 400 </td> 401 <td width="6%"></td> 402 <td width="6%"> 360 <tr valign="top" align="left"> 361 <td width="19%"></td> 362 <td width="15%"> 363 364 <p><b>icclab</b></p> 365 </td> 366 <td width="65%"> 403 367 404 368 <p>image has ICC L*a*b color model,</p> 405 369 </td> 406 <td width="6%"></td> 407 <td width="55%"> 408 </td> 409 <tr valign="top" align="left"> 410 <td width="19%"></td> 411 <td width="6%"> 412 413 <p><i>itulab</i></p> 414 </td> 415 <td width="6%"></td> 416 <td width="6%"> 417 418 <p>image has ITU L*a*b color model,</p> 419 </td> 420 <td width="6%"></td> 421 <td width="55%"> 370 <tr valign="top" align="left"> 371 <td width="19%"></td> 372 <td width="15%"> 373 374 <p><b>itulab</b></p> 375 </td> 376 <td width="65%"> 377 378 <p>image has ITU L*a*b color model.</p> 422 379 </td> 423 380 </table> … … 474 431 475 432 <p>Specify a compression scheme to use when writing image 476 data: <b>−c none</b> for no compression, <b> -c433 data: <b>−c none</b> for no compression, <b>−c 477 434 packbits</b> for the PackBits compression algorithm (the 478 default), <b> -c jpeg</b> for the baseline JPEG compression479 algorithm, <b>-c zip</b> for the Deflate compression 480 algorithm, and <b>−c lzw</b> for Lempel-Ziv & 481 Welch.</p>435 default), <b>−c jpeg</b> for the baseline JPEG 436 compression algorithm, <b>−c zip</b> for the Deflate 437 compression algorithm, and <b>−c lzw</b> for 438 Lempel-Ziv & Welch.</p> 482 439 </td> 483 440 <td width="0%"> … … 490 447 <td width="8%"></td> 491 448 <td width="91%"> 492 <p><b>−r <number></b></p></td>449 <p><b>−r</b> <i>number</i></p></td> 493 450 </table> 494 451 <!-- INDENTATION --> -
trunk/src/3rdparty/libtiff/html/man/rgb2ycbcr.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:12 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:19 2007 --> 3 3 <html> 4 4 <head> … … 83 83 84 84 <p>Specify a compression scheme to use when writing image 85 data: <b>−c none</b> for no compression, <b> -c85 data: <b>−c none</b> for no compression, <b>−c 86 86 packbits</b> for the PackBits compression algorithm (the 87 default), <b>-c jpeg</b> for the JPEG compression algorithm, 88 <b>-c zip</b> for the deflate compression algorithm, and 89 <b>−c lzw</b> for Lempel-Ziv & Welch.</p> 87 default), <b>−c jpeg</b> for the JPEG compression 88 algorithm, <b>−c zip</b> for the deflate compression 89 algorithm, and <b>−c lzw</b> for Lempel-Ziv & 90 Welch.</p> 90 91 </td> 91 92 <td width="0%"> -
trunk/src/3rdparty/libtiff/html/man/sgi2tiff.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:12 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:19 2007 --> 3 3 <html> 4 4 <head> … … 75 75 76 76 <p>Specify a compression scheme to use when writing image 77 data: <b>−c none</b> for no compression, <b> -c78 packbits</b> for the PackBits compression algorithm), <b>-c79 jpeg</b> for the baseline JPEG compression algorithm, <b>-c 80 zip</b> for the Deflate compression algorithm, and 81 <b>−c lzw</b> for Lempel-Ziv & Welch (the 82 default).</p>77 data: <b>−c none</b> for no compression, <b>−c 78 packbits</b> for the PackBits compression algorithm), 79 <b>−c jpeg</b> for the baseline JPEG compression 80 algorithm, <b>−c zip</b> for the Deflate compression 81 algorithm, and <b>−c lzw</b> for Lempel-Ziv & 82 Welch (the default).</p> 83 83 </td> 84 84 <td width="0%"> -
trunk/src/3rdparty/libtiff/html/man/thumbnail.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:12 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:19 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/tiff2bw.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:12 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:19 2007 --> 3 3 <html> 4 4 <head> … … 37 37 <td width="8%"></td> 38 38 <td width="91%"> 39 <p><b>tiff2bw</b> [ options] <i>input.tif39 <p><b>tiff2bw</b> [ <i>options</i> ] <i>input.tif 40 40 output.tif</i></p> 41 41 </td> … … 74 74 75 75 <p>Specify a compression scheme to use when writing image 76 data: <b>−c none</b> for no compression, <b>-c 77 packbits</b> for the PackBits compression algorithm, <b>-c 78 zip</b> for the Deflate compression algorithm, <b>-c g3</b> 79 for the CCITT Group 3 compression algorithm, <b>-c g4</b> 80 for the CCITT Group 4 compression algorithm, and <b>−c 81 lzw</b> for Lempel-Ziv & Welch (the default).</p> 76 data: <b>−c none</b> for no compression, <b>−c 77 packbits</b> for the PackBits compression algorithm, 78 <b>−c zip</b> for the Deflate compression algorithm, 79 <b>−c g3</b> for the CCITT Group 3 compression 80 algorithm, <b>−c g4</b> for the CCITT Group 4 81 compression algorithm, and <b>−c lzw</b> for 82 Lempel-Ziv & Welch (the default).</p> 82 83 </td> 83 84 <td width="0%"> -
trunk/src/3rdparty/libtiff/html/man/tiff2pdf.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:12 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:19 2007 --> 3 3 <html> 4 4 <head> … … 27 27 <td width="10%"></td> 28 28 <td width="89%"> 29 <p>tiff2pdf - convert a TIFF image to a PDF document</p> 29 <p>tiff2pdf − convert a TIFF image to a PDF 30 document</p> 30 31 </td> 31 32 </table> … … 38 39 <td width="10%"></td> 39 40 <td width="89%"> 40 <p><b>tiff2pdf [</b> <i>options</i> <b>]</b> 41 <i>input.tiff</i></p> 41 <p><b>tiff2pdf</b> [ <i>options</i> ] <i>input.tiff</i></p> 42 42 </td> 43 43 </table> … … 50 50 <td width="10%"></td> 51 51 <td width="89%"> 52 <p>< b>tiff2pdf</b> opens a TIFF image and writes a PDF52 <p><i>tiff2pdf</i> opens a TIFF image and writes a PDF 53 53 document to standard output.</p> 54 54 <!-- INDENTATION --> … … 68 68 <!-- INDENTATION --> 69 69 <p>The standard output is standard output. Set the output 70 file name with the <b>-o</b><i>output.pdf</i> option.</p> 70 file name with the <b>−o</b> <i>output.pdf</i> 71 option.</p> 71 72 <!-- INDENTATION --> 72 73 <p>All black and white files are compressed into a single … … 110 111 <!-- INDENTATION --> 111 112 <p>Various items of the output document information can be 112 set with the <b>−e, −c, −a, −t, 113 −s,</b> and <b>−k</b> options. Setting the 114 argument of the option to "" for these tags causes 115 the relevant document information field to be not written. 116 Some of the document information values otherwise get their 117 information from the input TIFF image, the software, author, 118 document name, and image description.</p> 113 set with the <b>−e</b>, <b>−c</b>, 114 <b>−a</b>, <b>−t</b>, <b>−s</b>, and 115 <b>−k</b> options. Setting the argument of the option 116 to "" for these tags causes the relevant document 117 information field to be not written. Some of the document 118 information values otherwise get their information from the 119 input TIFF image, the software, author, document name, and 120 image description.</p> 119 121 <!-- INDENTATION --> 120 122 <p>The Portable Document Format (PDF) specification is … … 130 132 <td width="10%"></td> 131 133 <td width="89%"> 132 <p><b>−o</b> <i>output-file</i></p></td>133 </table> 134 <!-- INDENTATION --> 135 <table width="100%" border=0 rules="none" frame="void" 136 cols="2" cellspacing="0" cellpadding="0"> 137 <tr valign="top" align="left"> 138 <td width="21%"></td> 139 <td width="77%"> 140 <p>Set the output to go to file <i>output-file</i></p>134 <p><b>−o</b> <i>output-file</i></p></td> 135 </table> 136 <!-- INDENTATION --> 137 <table width="100%" border=0 rules="none" frame="void" 138 cols="2" cellspacing="0" cellpadding="0"> 139 <tr valign="top" align="left"> 140 <td width="21%"></td> 141 <td width="77%"> 142 <p>Set the output to go to file. <i>output-file</i></p> 141 143 </td> 142 144 </table> … … 153 155 <td width="77%"> 154 156 155 <p>Compress with JPEG (requires libjpeg configured with156 libtiff).</p>157 <p>Compress with JPEG (requires <i>libjpeg</i> configured 158 with <i>libtiff</i>).</p> 157 159 </td> 158 160 <tr valign="top" align="left"> … … 165 167 <td width="77%"> 166 168 167 <p>Compress with Zip/Deflate (requires zlib configured with168 libtiff).</p>169 </td> 170 </table> 171 <!-- INDENTATION --> 172 <table width="100%" border=0 rules="none" frame="void" 173 cols="2" cellspacing="0" cellpadding="0"> 174 <tr valign="top" align="left"> 175 <td width="10%"></td> 176 <td width="89%"> 177 <p><b>−q</b> <i>quality</i></p></td>169 <p>Compress with Zip/Deflate (requires <i>zlib</i> 170 configured with <i>libtiff</i>).</p> 171 </td> 172 </table> 173 <!-- INDENTATION --> 174 <table width="100%" border=0 rules="none" frame="void" 175 cols="2" cellspacing="0" cellpadding="0"> 176 <tr valign="top" align="left"> 177 <td width="10%"></td> 178 <td width="89%"> 179 <p><b>−q</b> <i>quality</i></p></td> 178 180 </table> 179 181 <!-- INDENTATION --> … … 210 212 <td width="77%"> 211 213 212 <p>Set PDF "Interpolate" user preference.</p> 214 <p>Set PDF ‘‘Interpolate’’ user 215 preference.</p> 213 216 </td> 214 217 <tr valign="top" align="left"> … … 241 244 <td width="10%"></td> 242 245 <td width="89%"> 243 <p><b>−p</b> <i>paper-size</i></p></td>244 </table> 245 <!-- INDENTATION --> 246 <table width="100%" border=0 rules="none" frame="void" 247 cols="2" cellspacing="0" cellpadding="0"> 248 <tr valign="top" align="left"> 249 <td width="21%"></td> 250 <td width="77%"> 251 <p>Set paper size, e g "letter", "legal",252 "A4".</p>253 </td> 254 </table> 255 <!-- INDENTATION --> 256 <table width="100%" border=0 rules="none" frame="void" 257 cols="2" cellspacing="0" cellpadding="0"> 258 <tr valign="top" align="left"> 259 <td width="10%"></td> 260 <td width="89%"> 261 <p><b>−u</b> <i>[i|m]</i></p></td>262 </table> 263 <!-- INDENTATION --> 264 <table width="100%" border=0 rules="none" frame="void" 265 cols="2" cellspacing="0" cellpadding="0"> 266 <tr valign="top" align="left"> 267 <td width="21%"></td> 268 <td width="77%"> 269 <p>Set distance unit, < i>i</i> for inch, <i>m</i> for246 <p><b>−p</b> <i>paper-size</i></p></td> 247 </table> 248 <!-- INDENTATION --> 249 <table width="100%" border=0 rules="none" frame="void" 250 cols="2" cellspacing="0" cellpadding="0"> 251 <tr valign="top" align="left"> 252 <td width="21%"></td> 253 <td width="77%"> 254 <p>Set paper size, e.g., <b>letter</b>, <b>legal</b>, 255 <b>A4</b>.</p> 256 </td> 257 </table> 258 <!-- INDENTATION --> 259 <table width="100%" border=0 rules="none" frame="void" 260 cols="2" cellspacing="0" cellpadding="0"> 261 <tr valign="top" align="left"> 262 <td width="10%"></td> 263 <td width="89%"> 264 <p><b>−u</b> [<b>i</b>|<b>m</b>]</p></td> 265 </table> 266 <!-- INDENTATION --> 267 <table width="100%" border=0 rules="none" frame="void" 268 cols="2" cellspacing="0" cellpadding="0"> 269 <tr valign="top" align="left"> 270 <td width="21%"></td> 271 <td width="77%"> 272 <p>Set distance unit, <b>i</b> for inch, <b>m</b> for 270 273 centimeter.</p> 271 274 </td> … … 277 280 <td width="10%"></td> 278 281 <td width="89%"> 279 <p><b>−w</b> <i>width</i></p></td>282 <p><b>−w</b> <i>width</i></p></td> 280 283 </table> 281 284 <!-- INDENTATION --> … … 294 297 <td width="10%"></td> 295 298 <td width="89%"> 296 <p><b>−l</b> <i>length</i></p></td>299 <p><b>−l</b> <i>length</i></p></td> 297 300 </table> 298 301 <!-- INDENTATION --> … … 305 308 </td> 306 309 </table> 310 <!-- INDENTATION --> 311 <table width="100%" border=0 rules="none" frame="void" 312 cols="2" cellspacing="0" cellpadding="0"> 313 <tr valign="top" align="left"> 314 <td width="10%"></td> 315 <td width="89%"> 316 <p><b>−x</b> <i>xres</i></p></td> 317 </table> 318 <!-- INDENTATION --> 319 <table width="100%" border=0 rules="none" frame="void" 320 cols="2" cellspacing="0" cellpadding="0"> 321 <tr valign="top" align="left"> 322 <td width="21%"></td> 323 <td width="77%"> 324 <p>Set x/width resolution default.</p> 325 </td> 326 </table> 327 <!-- INDENTATION --> 328 <table width="100%" border=0 rules="none" frame="void" 329 cols="2" cellspacing="0" cellpadding="0"> 330 <tr valign="top" align="left"> 331 <td width="10%"></td> 332 <td width="89%"> 333 <p><b>−y</b> <i>yres</i></p></td> 334 </table> 335 <!-- INDENTATION --> 336 <table width="100%" border=0 rules="none" frame="void" 337 cols="2" cellspacing="0" cellpadding="0"> 338 <tr valign="top" align="left"> 339 <td width="21%"></td> 340 <td width="77%"> 341 <p>Set y/length resolution default.</p> 342 </td> 343 </table> 344 <!-- INDENTATION --> 345 <table width="100%" border=0 rules="none" frame="void" 346 cols="2" cellspacing="0" cellpadding="0"> 347 <tr valign="top" align="left"> 348 <td width="10%"></td> 349 <td width="89%"> 350 <p><b>−r</b> [<b>d</b>|<b>o</b>]</p></td> 351 </table> 352 <!-- INDENTATION --> 353 <table width="100%" border=0 rules="none" frame="void" 354 cols="2" cellspacing="0" cellpadding="0"> 355 <tr valign="top" align="left"> 356 <td width="21%"></td> 357 <td width="77%"> 358 <p>Set <b>d</b> for resolution default for images without 359 resolution, <b>o</b> for resolution override for all 360 images.</p> 361 </td> 362 </table> 307 363 <!-- TABS --> 308 364 <table width="100%" border=0 rules="none" frame="void" … … 310 366 <tr valign="top" align="left"> 311 367 <td width="11%"></td> 312 <td width=" 8%">313 314 <p><b>− x</b><i>xres</i></p>368 <td width="2%"> 369 370 <p><b>−f</b></p> 315 371 </td> 316 372 <td width="13%"></td> 317 <td width="47%"> 318 319 <p>Set x/width resolution default.</p> 320 </td> 321 <td width="19%"> 322 </td> 323 <tr valign="top" align="left"> 324 <td width="11%"></td> 325 <td width="8%"> 326 327 <p><b>−y</b><i>yres</i></p> 328 </td> 329 <td width="13%"></td> 330 <td width="47%"> 331 332 <p>Set y/length resolution default.</p> 333 </td> 334 <td width="19%"> 335 </td> 336 </table> 337 <!-- INDENTATION --> 338 <table width="100%" border=0 rules="none" frame="void" 339 cols="2" cellspacing="0" cellpadding="0"> 340 <tr valign="top" align="left"> 341 <td width="10%"></td> 342 <td width="89%"> 343 <p><b>−r</b><i>[d|o]</i></p></td> 344 </table> 345 <!-- INDENTATION --> 346 <table width="100%" border=0 rules="none" frame="void" 347 cols="2" cellspacing="0" cellpadding="0"> 348 <tr valign="top" align="left"> 349 <td width="21%"></td> 350 <td width="77%"> 351 <p>Set <i>d</i> for resolution default for images without 352 resolution, <i>o for resolution override for all 353 images.</i></p> 354 </td> 355 </table> 356 <!-- TABS --> 357 <table width="100%" border=0 rules="none" frame="void" 358 cols="5" cellspacing="0" cellpadding="0"> 359 <tr valign="top" align="left"> 360 <td width="11%"></td> 361 <td width="2%"> 362 363 <p><b>−f</b></p> 364 </td> 365 <td width="13%"></td> 366 <td width="54%"> 367 368 <p>Set PDF "Fit Window" user preference.</p> 369 </td> 370 <td width="17%"> 371 </td> 372 </table> 373 <!-- INDENTATION --> 374 <table width="100%" border=0 rules="none" frame="void" 375 cols="2" cellspacing="0" cellpadding="0"> 376 <tr valign="top" align="left"> 377 <td width="10%"></td> 378 <td width="89%"> 379 <p><b>−e</b><i>YYYYMMDDHHMMSS</i></p></td> 373 <td width="57%"> 374 375 <p>Set PDF ‘‘Fit Window’’ user 376 preference.</p> 377 </td> 378 <td width="14%"> 379 </td> 380 </table> 381 <!-- INDENTATION --> 382 <table width="100%" border=0 rules="none" frame="void" 383 cols="2" cellspacing="0" cellpadding="0"> 384 <tr valign="top" align="left"> 385 <td width="10%"></td> 386 <td width="89%"> 387 <p><b>−e</b> <i>YYYYMMDDHHMMSS</i></p></td> 380 388 </table> 381 389 <!-- INDENTATION --> … … 395 403 <td width="10%"></td> 396 404 <td width="89%"> 397 <p><b>−c</b> <i>creator</i></p></td>405 <p><b>−c</b> <i>creator</i></p></td> 398 406 </table> 399 407 <!-- INDENTATION --> … … 413 421 <td width="10%"></td> 414 422 <td width="89%"> 415 <p><b>−a</b> <i>author</i></p></td>423 <p><b>−a</b> <i>author</i></p></td> 416 424 </table> 417 425 <!-- INDENTATION --> … … 422 430 <td width="77%"> 423 431 <p>Set document information author, overrides image artist 424 default </p>425 </td> 426 </table> 427 <!-- INDENTATION --> 428 <table width="100%" border=0 rules="none" frame="void" 429 cols="2" cellspacing="0" cellpadding="0"> 430 <tr valign="top" align="left"> 431 <td width="10%"></td> 432 <td width="89%"> 433 <p><b>−t</b> <i>title</i></p></td>432 default.</p> 433 </td> 434 </table> 435 <!-- INDENTATION --> 436 <table width="100%" border=0 rules="none" frame="void" 437 cols="2" cellspacing="0" cellpadding="0"> 438 <tr valign="top" align="left"> 439 <td width="10%"></td> 440 <td width="89%"> 441 <p><b>−t</b> <i>title</i></p></td> 434 442 </table> 435 443 <!-- INDENTATION --> … … 440 448 <td width="77%"> 441 449 <p>Set document information title, overrides image document 442 name default </p>443 </td> 444 </table> 445 <!-- INDENTATION --> 446 <table width="100%" border=0 rules="none" frame="void" 447 cols="2" cellspacing="0" cellpadding="0"> 448 <tr valign="top" align="left"> 449 <td width="10%"></td> 450 <td width="89%"> 451 <p><b>−s</b> <i>subject</i></p></td>450 name default.</p> 451 </td> 452 </table> 453 <!-- INDENTATION --> 454 <table width="100%" border=0 rules="none" frame="void" 455 cols="2" cellspacing="0" cellpadding="0"> 456 <tr valign="top" align="left"> 457 <td width="10%"></td> 458 <td width="89%"> 459 <p><b>−s</b> <i>subject</i></p></td> 452 460 </table> 453 461 <!-- INDENTATION --> … … 458 466 <td width="77%"> 459 467 <p>Set document information subject, overrides image image 460 description default </p>461 </td> 462 </table> 463 <!-- INDENTATION --> 464 <table width="100%" border=0 rules="none" frame="void" 465 cols="2" cellspacing="0" cellpadding="0"> 466 <tr valign="top" align="left"> 467 <td width="10%"></td> 468 <td width="89%"> 469 <p><b>−k</b> <i>keywords</i></p></td>468 description default.</p> 469 </td> 470 </table> 471 <!-- INDENTATION --> 472 <table width="100%" border=0 rules="none" frame="void" 473 cols="2" cellspacing="0" cellpadding="0"> 474 <tr valign="top" align="left"> 475 <td width="10%"></td> 476 <td width="89%"> 477 <p><b>−k</b> <i>keywords</i></p></td> 470 478 </table> 471 479 <!-- INDENTATION --> … … 494 502 <td width="14%"> 495 503 </td> 496 <tr valign="top" align="left"> 497 <td width="11%"></td> 498 <td width="2%"> 499 </td> 500 <td width="13%"></td> 501 <td width="57%"> 504 </table> 502 505 <a name="EXAMPLES"></a> 503 506 <h2>EXAMPLES</h2> … … 517 520 <td width="20%"></td> 518 521 <td width="79%"> 519 <p>tiff2pdf -o output.pdf input.tiff</p></td> 520 </table> 521 <!-- INDENTATION --> 522 <pre>tiff2pdf −o output.pdf input.tiff 523 </pre> 524 </td> 525 </table> 526 <!-- INDENTATION --> 527 522 528 <table width="100%" border=0 rules="none" frame="void" 523 529 cols="2" cellspacing="0" cellpadding="0"> … … 526 532 <td width="89%"> 527 533 <p>The following example would generate PDF output from 528 input.tiff and write it to standard output.</p> 529 </td> 534 input.tiff and write it to standard output.</p></td> 530 535 </table> 531 536 <!-- INDENTATION --> … … 535 540 <td width="20%"></td> 536 541 <td width="79%"> 537 <p>tiff2pdf input.tiff</p></td> 538 </table> 539 <!-- INDENTATION --> 542 <pre>tiff2pdf input.tiff 543 </pre> 544 </td> 545 </table> 546 <!-- INDENTATION --> 547 540 548 <table width="100%" border=0 rules="none" frame="void" 541 549 cols="2" cellspacing="0" cellpadding="0"> … … 546 554 from input.tiff, putting the image pages on a letter sized 547 555 page, compressing the output with JPEG, with JPEG quality 548 75, setting the title to "Document", and setting549 the "Fit Window" option.</p> 550 </td>556 75, setting the title to 557 ‘‘Document’’, and setting the 558 ‘‘Fit Window’’ option.</p></td> 551 559 </table> 552 560 <!-- INDENTATION --> … … 556 564 <td width="20%"></td> 557 565 <td width="79%"> 558 <p>tiff2pdf -p letter -j -q 75 -t "Document" -f -o 559 output.pdf input.tiff</p></td> 566 <pre>tiff2pdf −p letter −j −q 75 −t "Document" −f −o output.pdf input.tiff 567 </pre> 568 </td> 560 569 </table> 561 570 <a name="BUGS"></a> 562 571 <h2>BUGS</h2> 563 572 <!-- INDENTATION --> 573 564 574 <table width="100%" border=0 rules="none" frame="void" 565 575 cols="2" cellspacing="0" cellpadding="0"> … … 588 598 <td width="10%"></td> 589 599 <td width="89%"> 590 <p><b>libtiff</b>(3) <b>, tiffcp</b>(1)<b>,591 tiff2ps</b>(1)</p>600 <p><b>libtiff</b>(3), <b>tiffcp</b>(1), 601 <b>tiff2ps</b>(1)</p> 592 602 <!-- INDENTATION --> 593 603 <p>Libtiff library home page: -
trunk/src/3rdparty/libtiff/html/man/tiff2ps.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:13 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:19 2007 --> 3 3 <html> 4 4 <head> … … 16 16 <a href="#EXAMPLES">EXAMPLES</a><br> 17 17 <a href="#BUGS">BUGS</a><br> 18 <a href="#BUGS">BUGS</a><br>19 18 <a href="#SEE ALSO">SEE ALSO</a><br> 20 19 … … 29 28 <td width="91%"> 30 29 <p>tiff2ps − convert a <small>TIFF</small> image to 31 ™</p>30 PostScript™</p> 32 31 </td> 33 32 </table> … … 53 52 <td width="91%"> 54 53 <p><i>tiff2ps</i> reads <small>TIFF</small> images and 55 writes or Encapsulated (EPS) on the standard output. By 56 default, <i>tiff2ps</i> writes Encapsulated for the first 57 image in the specified <small>TIFF</small> image file.</p> 58 <!-- INDENTATION --> 59 <p>By default, <i>tiff2ps</i> will generate that fills a 60 printed area specified by the <small>TIFF</small> tags in 61 the input file. If the file does not contain 54 writes PostScript or Encapsulated PostScript (EPS) on the 55 standard output. By default, <i>tiff2ps</i> writes 56 Encapsulated PostScript for the first image in the specified 57 <small>TIFF</small> image file.</p> 58 <!-- INDENTATION --> 59 <p>By default, <i>tiff2ps</i> will generate PostScript that 60 fills a printed area specified by the <small>TIFF</small> 61 tags in the input file. If the file does not contain 62 62 <i>XResolution</i> or <i>YResolution</i> tags, then the 63 63 printed area is set according to the image dimensions. The … … 66 66 overriding any relevant <small>TIFF</small> tags.</p> 67 67 <!-- INDENTATION --> 68 <p>The generated for <small>RGB,</small> palette, and 69 <small>CMYK</small> images uses the <i>colorimage</i> 70 operator. The generated for greyscale and bilevel images 71 uses the <i>image</i> operator. When the <i>colorimage</i> 72 operator is used, code to emulate this operator on older 73 printers is also generated. Note that this emulation code 74 can be very slow.</p> 68 <p>The PostScript generated for <small>RGB,</small> palette, 69 and <small>CMYK</small> images uses the <i>colorimage</i> 70 operator. The PostScript generated for greyscale and bilevel 71 images uses the <i>image</i> operator. When the 72 <i>colorimage</i> operator is used, PostScript code to 73 emulate this operator on older PostScript printers is also 74 generated. Note that this emulation code can be very 75 slow.</p> 75 76 <!-- INDENTATION --> 76 77 <p>Color images with associated alpha data are composited … … 92 93 <td width="80%"> 93 94 94 <p>Generate Level 1 (the default).</p>95 <p>Generate PostScript Level 1 (the default).</p> 95 96 </td> 96 97 <td width="0%"> … … 105 106 <td width="80%"> 106 107 107 <p>Generate Level 2.</p>108 <p>Generate PostScript Level 2.</p> 108 109 </td> 109 110 <td width="0%"> … … 118 119 <td width="80%"> 119 120 120 <p>Generate Level 3. It basically allows one to use the 121 /flateDecode filter for ZIP compressed TIFF images.</p> 121 <p>Generate PostScript Level 3. It basically allows one to 122 use the /flateDecode filter for ZIP compressed TIFF 123 images.</p> 122 124 </td> 123 125 <td width="0%"> … … 161 163 162 164 <p>Center the image in the output. This option only shows 163 an effect if both the -w and the -h option are given.</p> 165 an effect if both the <b>−w</b> and the 166 <b>−h</b> option are given.</p> 164 167 </td> 165 168 <td width="0%"> … … 175 178 176 179 <p>Set the initial <small>TIFF</small> directory to the 177 specified directory number. (NB: directories are numbered180 specified directory number. (NB: Directories are numbered 178 181 starting at zero.) This option is useful for selecting 179 182 individual pages in a multi-page (e.g. facsimile) file.</p> … … 190 193 <td width="80%"> 191 194 192 <p>Force the generation of Encapsulated (implies -z).</p> 195 <p>Force the generation of Encapsulated PostScript (implies 196 <b>−z</b>).</p> 193 197 </td> 194 198 <td width="0%"> … … 277 281 <td width="80%"> 278 282 279 <p>Where possible render using the < b>imagemask</b>280 operator instead of the image operator. When this option is 281 specified <i>tiff2ps</i> will use <b>imagemask</b> for 282 rendering 1 bit deep images. If this option is not specified 283 o r if the image depth is greater than 1 then the image284 operator is used.</p>283 <p>Where possible render using the <i>imagemask</i> 284 PostScript operator instead of the <i>image</i> operator. 285 When this option is specified <i>tiff2ps</i> will use 286 <i>imagemask</i> for rendering 1 bit deep images. If this 287 option is not specified or if the image depth is greater 288 than 1 then the <i>image</i> operator is used.</p> 285 289 </td> 286 290 <td width="0%"> … … 298 302 <small>IFD</small> at the specified file offset. This option 299 303 is useful for selecting thumbnail images and the like which 300 are hidden using the SubIFDtag.</p>304 are hidden using the <i>SubIFD</i> tag.</p> 301 305 </td> 302 306 <td width="0%"> … … 311 315 <td width="80%"> 312 316 313 <p>Force the generation of (non-Encapsulated) .</p> 317 <p>Force the generation of (non-Encapsulated) 318 PostScript.</p> 314 319 </td> 315 320 <td width="0%"> … … 393 398 <td width="80%"> 394 399 395 <p>When generating Level 2, data is scaled so that it does396 not image into the <i>deadzone</i> on a page (the outer 397 margin that the printing device is unable to mark). This 398 option suppresses this behavior. When Level 1 is generated, 399 data is imaged to the entire printed page and this option 400 has no affect.</p>400 <p>When generating PostScript Level 2, data is scaled so 401 that it does not image into the <i>deadzone</i> on a page 402 (the outer margin that the printing device is unable to 403 mark). This option suppresses this behavior. When PostScript 404 Level 1 is generated, data is imaged to the entire printed 405 page and this option has no affect.</p> 401 406 </td> 402 407 <td width="0%"> … … 411 416 <td width="8%"></td> 412 417 <td width="91%"> 413 <p>The following generates Level 2 for all pages of a414 facsimile:</p></td>418 <p>The following generates PostScript Level 2 for all pages 419 of a facsimile:</p></td> 415 420 </table> 416 421 <!-- INDENTATION --> … … 420 425 <td width="17%"></td> 421 426 <td width="82%"> 422 <pre>tiff2ps -a2 fax.tif | lpr427 <pre>tiff2ps −a2 fax.tif | lpr 423 428 </pre> 424 429 </td> … … 435 440 generated with the above command.</p> 436 441 <!-- INDENTATION --> 437 <p>To generate Encapsulated for a the image at directory 2438 of an image use:</p></td>442 <p>To generate Encapsulated PostScript for a the image at 443 directory 2 of an image use:</p></td> 439 444 </table> 440 445 <!-- INDENTATION --> … … 444 449 <td width="17%"></td> 445 450 <td width="82%"> 446 <pre>tiff2ps -d 1 foo.tif451 <pre>tiff2ps −d 1 foo.tif 447 452 </pre> 448 453 </td> … … 455 460 <td width="8%"></td> 456 461 <td width="91%"> 457 <p>( notice that directories are numbered starting at462 <p>(Notice that directories are numbered starting at 458 463 zero.)</p> 459 464 <!-- INDENTATION --> … … 467 472 <td width="17%"></td> 468 473 <td width="82%"> 469 <pre>tiff2ps -h11 -w8.5 -H14 -L.5 foo.tif > foo.ps474 <pre>tiff2ps −h11 −w8.5 −H14 −L.5 foo.tif > foo.ps 470 475 </pre> 471 476 </td> … … 496 501 <td width="8%"></td> 497 502 <td width="91%"> 498 <p>Because does not support the notion of a colormap, 8-bit 499 palette images produce 24-bit images. This conversion 500 results in output that is six times bigger than the original 501 image and which takes a long time to send to a printer over 502 a serial line. Matters are even worse for 4-, 2-, and 1-bit 503 palette images.</p> 504 </td> 505 </table> 506 <a name="BUGS"></a> 507 <h2>BUGS</h2> 508 <!-- INDENTATION --> 509 <table width="100%" border=0 rules="none" frame="void" 510 cols="2" cellspacing="0" cellpadding="0"> 511 <tr valign="top" align="left"> 512 <td width="8%"></td> 513 <td width="91%"> 514 <p>Does not handle tiled images when generating PS Level I 515 output.</p> 503 <p>Because PostScript does not support the notion of a 504 colormap, 8-bit palette images produce 24-bit PostScript 505 images. This conversion results in output that is six times 506 bigger than the original image and which takes a long time 507 to send to a printer over a serial line. Matters are even 508 worse for 4-, 2-, and 1-bit palette images.</p> 509 <!-- INDENTATION --> 510 <p>Does not handle tiled images when generating PostScript 511 Level I output.</p> 516 512 </td> 517 513 </table> -
trunk/src/3rdparty/libtiff/html/man/tiff2rgba.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:13 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:19 2007 --> 3 3 <html> 4 4 <head> … … 37 37 <td width="8%"></td> 38 38 <td width="91%"> 39 <p><b>tiff2rgba</b> [ options] <i>input.tif39 <p><b>tiff2rgba</b> [ <i>options</i> ] <i>input.tif 40 40 output.tif</i></p> 41 41 </td> … … 64 64 <!-- INDENTATION --> 65 65 <p>The generated images are stripped images with four 66 samples per pixel (red, green, blue and alpha) or if the -n67 flag is used, three samples per pixel (red, green, and 68 blue). The resulting images are always planar configuration 69 con tiguous. For this reason, this program is a useful70 u tility for transform exotic TIFF files into a form66 samples per pixel (red, green, blue and alpha) or if the 67 <b>−n</b> flag is used, three samples per pixel (red, 68 green, and blue). The resulting images are always planar 69 configuration contiguous. For this reason, this program is a 70 useful utility for transform exotic TIFF files into a form 71 71 ingestible by almost any TIFF supporting software.</p> 72 72 </td> … … 88 88 <p>Specify a compression scheme to use when writing image 89 89 data: <b>−c none</b> for no compression (the default), 90 <b>-c packbits</b> for the PackBits compression algorithm, 91 <b>-c zip</b> for the Deflate compression algorithm, <b>-c 92 jpeg</b> for the JPEG compression algorithm, and <b>−c 93 lzw</b> for Lempel-Ziv & Welch.</p> 90 <b>−c packbits</b> for the PackBits compression 91 algorithm, <b>−c zip</b> for the Deflate compression 92 algorithm, <b>−c jpeg</b> for the JPEG compression 93 algorithm, and <b>−c lzw</b> for Lempel-Ziv & 94 Welch.</p> 94 95 </td> 95 96 <td width="0%"> … … 136 137 137 138 <p>Drop the alpha component from the output file, producing 138 a pure RGB file. Currently this does not work if the -b flag139 is also in effect.</p>139 a pure RGB file. Currently this does not work if the 140 <b>−b</b> flag is also in effect.</p> 140 141 </td> 141 142 <td width="0%"> -
trunk/src/3rdparty/libtiff/html/man/tiffcmp.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:13 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:19 2007 --> 3 3 <html> 4 4 <head> … … 89 89 <td width="8%"></td> 90 90 <td width="91%"> 91 <p><b>−z number</b></p></td>91 <p><b>−z</b> <i>number</i></p></td> 92 92 </table> 93 93 <!-- INDENTATION --> … … 130 130 <!-- INDENTATION --> 131 131 <p>The image data of tiled files is not compared, since the 132 TIFFReadScanline() function is used. Aerror will be132 <i>TIFFReadScanline()</i> function is used. An error will be 133 133 reported for tiled files.</p> 134 134 <!-- INDENTATION --> -
trunk/src/3rdparty/libtiff/html/man/tiffcp.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:13 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:19 2007 --> 3 3 <html> 4 4 <head> … … 75 75 <td width="8%"></td> 76 76 <td width="91%"> 77 <p><b>−b image</b></p></td>77 <p><b>−b</b> <i>image</i></p></td> 78 78 </table> 79 79 <!-- INDENTATION --> … … 202 202 <td width="3%"> 203 203 204 <p><b>−i</b></p> 205 </td> 206 <td width="5%"></td> 207 <td width="80%"> 208 209 <p>Ignore non-fatal read errors and continue processing of 210 the input file.</p> 211 </td> 212 <td width="0%"> 213 </td> 214 <tr valign="top" align="left"> 215 <td width="10%"></td> 216 <td width="3%"> 217 204 218 <p><b>−l</b></p> 205 219 </td> … … 275 289 <b>0</b> is specified), <i>tiffcp</i> attempts to set the 276 290 rows/strip that no more than 8 kilobytes of data appear in a 277 strip. If you specify special value <b> -1</b> it will291 strip. If you specify special value <b>−1</b> it will 278 292 results in infinite number of the rows per strip. The entire 279 293 image will be the one strip in that case.</p> … … 335 349 <td width="8%"></td> 336 350 <td width="91%"> 337 <p><b>−,= {character}</b></p></td>351 <p><b>−,=</b><i>character</i></p></td> 338 352 </table> 339 353 <!-- INDENTATION --> … … 343 357 <td width="19%"></td> 344 358 <td width="80%"> 345 <p>substitute {character} for ’,’ in parsing346 image directory indices in files. This is necessary if 347 filenames contain commas. Note that ’,=’with359 <p>substitute <i>character</i> for ‘,’ in 360 parsing image directory indices in files. This is necessary 361 if filenames contain commas. Note that <b>−,=</b> with 348 362 whitespace immediately following will disable the special 349 meaning of the & rsquo;,’ entirely. See examples.</p>363 meaning of the ‘,’ entirely. See examples.</p> 350 364 </td> 351 365 </table> … … 367 381 <td width="17%"></td> 368 382 <td width="82%"> 369 <pre>tiffcp -c lzw a.tif b.tif result.tif383 <pre>tiffcp −c lzw a.tif b.tif result.tif 370 384 </pre> 371 385 </td> … … 388 402 <td width="17%"></td> 389 403 <td width="82%"> 390 <pre>tiffcp -c g4 -r 10000 g3.tif g4.tif404 <pre>tiffcp −c g4 −r 10000 g3.tif g4.tif 391 405 </pre> 392 406 </td> … … 404 418 <p>To extract a selected set of images from a multi-image 405 419 TIFF file, the file name may be immediately followed by a 406 & rsquo;,’ separated list of image directory indices.420 ‘,’ separated list of image directory indices. 407 421 The first image is always in directory 0. Thus, to copy the 408 1st and 3rd images of image file "album.tif" to 409 "result.tif":</p></td> 422 1st and 3rd images of image file 423 ‘‘album.tif’’ to 424 ‘‘result.tif’’:</p></td> 410 425 </table> 411 426 <!-- INDENTATION --> … … 426 441 <td width="8%"></td> 427 442 <td width="91%"> 428 <p>Given file "CCD.tif" whose first image is a 429 noise bias followed by images which include that bias, 430 subtract the noise from all those images following it (while 431 decompressing) with the command:</p></td> 432 </table> 433 <!-- INDENTATION --> 434 <table width="100%" border=0 rules="none" frame="void" 435 cols="2" cellspacing="0" cellpadding="0"> 436 <tr valign="top" align="left"> 437 <td width="17%"></td> 438 <td width="82%"> 439 <pre>tiffcp -c none -b CCD.tif CCD.tif,1, result.tif 443 <p>A trailing comma denotes remaining images in sequence. 444 The following command will copy all image with except the 445 first one:</p></td> 446 </table> 447 <!-- INDENTATION --> 448 <table width="100%" border=0 rules="none" frame="void" 449 cols="2" cellspacing="0" cellpadding="0"> 450 <tr valign="top" align="left"> 451 <td width="17%"></td> 452 <td width="82%"> 453 <pre>tiffcp album.tif,1, result.tif 440 454 </pre> 441 455 </td> … … 448 462 <td width="8%"></td> 449 463 <td width="91%"> 450 <p>If the file above were named "CCD,X.tif", the 451 "-,=" option would be required to correctly parse 452 this filename with image numbers, as follows:</p></td> 453 </table> 454 <!-- INDENTATION --> 455 <table width="100%" border=0 rules="none" frame="void" 456 cols="2" cellspacing="0" cellpadding="0"> 457 <tr valign="top" align="left"> 458 <td width="17%"></td> 459 <td width="82%"> 460 <pre>tiffcp -c none -,=% -b CCD,X.tif CCD,X%1%.tif result.tif 464 <p>Given file ‘‘CCD.tif’’ whose 465 first image is a noise bias followed by images which include 466 that bias, subtract the noise from all those images 467 following it (while decompressing) with the 468 command:</p></td> 469 </table> 470 <!-- INDENTATION --> 471 <table width="100%" border=0 rules="none" frame="void" 472 cols="2" cellspacing="0" cellpadding="0"> 473 <tr valign="top" align="left"> 474 <td width="17%"></td> 475 <td width="82%"> 476 <pre>tiffcp −c none −b CCD.tif CCD.tif,1, result.tif 477 </pre> 478 </td> 479 </table> 480 <!-- INDENTATION --> 481 482 <table width="100%" border=0 rules="none" frame="void" 483 cols="2" cellspacing="0" cellpadding="0"> 484 <tr valign="top" align="left"> 485 <td width="8%"></td> 486 <td width="91%"> 487 <p>If the file above were named 488 ‘‘CCD,X.tif’’, the <b>−,=</b> 489 option would be required to correctly parse this filename 490 with image numbers, as follows:</p></td> 491 </table> 492 <!-- INDENTATION --> 493 <table width="100%" border=0 rules="none" frame="void" 494 cols="2" cellspacing="0" cellpadding="0"> 495 <tr valign="top" align="left"> 496 <td width="17%"></td> 497 <td width="82%"> 498 <pre>tiffcp −c none −,=% −b CCD,X.tif CCD,X%1%.tif result.tif 461 499 462 500 </pre> -
trunk/src/3rdparty/libtiff/html/man/tiffdither.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:13 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:19 2007 --> 3 3 <html> 4 4 <head> … … 129 129 with the same fill order as the original. Specifying 130 130 <b>−f lsb2msb</b> will force data to be written with 131 the FillOrder tag set to <small>LSB2MSB ,</small> while 132 <b>−f msb2lsb</b> will force data to be written with 133 the FillOrder tag set to <small>MSB2LSB .</small></p> 131 the <i>FillOrder</i> tag set to <small>LSB2MSB ,</small> 132 while <b>−f msb2lsb</b> will force data to be written 133 with the <i>Fill- Order</i> tag set to <small>MSB2LSB 134 .</small></p> 134 135 </td> 135 136 <td width="0%"> -
trunk/src/3rdparty/libtiff/html/man/tiffdump.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:13 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:20 2007 --> 3 3 <html> 4 4 <head> … … 94 94 <td width="8%"></td> 95 95 <td width="91%"> 96 <p><b>−m items</b></p></td>96 <p><b>−m</b> <i>items</i></p></td> 97 97 </table> 98 98 <!-- INDENTATION --> … … 112 112 <td width="8%"></td> 113 113 <td width="91%"> 114 <p><b>−o offset</b></p></td>114 <p><b>−o</b> <i>offset</i></p></td> 115 115 </table> 116 116 <!-- INDENTATION --> -
trunk/src/3rdparty/libtiff/html/man/tiffgt.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:13 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:20 2007 --> 3 3 <html> 4 4 <head> … … 70 70 <td width="34%"> 71 71 72 <p> BitsPerSample</p>72 <p><i>BitsPerSample</i></p> 73 73 </td> 74 74 <td width="50%"> … … 80 80 <td width="34%"> 81 81 82 <p> SamplesPerPixel</p>82 <p><i>SamplesPerPixel</i></p> 83 83 </td> 84 84 <td width="50%"> … … 90 90 <td width="34%"> 91 91 92 <p> PhotometricInterpretation</p>92 <p><i>PhotometricInterpretation</i></p> 93 93 </td> 94 94 <td width="50%"> … … 101 101 <td width="34%"> 102 102 103 <p> PlanarConfiguration</p>103 <p><i>PlanarConfiguration</i></p> 104 104 </td> 105 105 <td width="50%"> … … 111 111 <td width="34%"> 112 112 113 <p> Orientation</p>113 <p><i>Orientation</i></p> 114 114 </td> 115 115 <td width="50%"> … … 451 451 <p>Override the value of the 452 452 <i>PhotometricInterpretation</i> tag; the parameter may be 453 one of: < i>miniswhite</i>, <i>minisblack</i>, <i>rgb</i>,454 < i>palette</i>, <i>mask</i>, <i>separated</i>, <i>ycbcr</i>,455 and < i>cielab</i>.</p>453 one of: <b>miniswhite</b>, <b>minisblack</b>, <b>rgb</b>, 454 <b>palette</b>, <b>mask</b>, <b>separated</b>, <b>ycbcr</b>, 455 and <b>cielab</b>.</p> 456 456 </td> 457 457 <td width="0%"> -
trunk/src/3rdparty/libtiff/html/man/tiffinfo.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:13 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:20 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/tiffmedian.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:13 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:20 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/tiffset.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:13 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:20 2007 --> 3 3 <html> 4 4 <head> … … 38 38 <td width="8%"></td> 39 39 <td width="91%"> 40 <p><b>tiffset</b> [ options] <i>filename.tif</i></p>40 <p><b>tiffset</b> [ <i>options</i> ] <i>filename.tif</i></p> 41 41 </td> 42 42 </table> … … 61 61 <td width="8%"></td> 62 62 <td width="91%"> 63 <p><b>−s tagnumber [count] value ...</b></p></td> 63 <p><b>−s</b> <i>tagnumber</i> [ <i>count</i> ] 64 <i>value ...</i></p></td> 64 65 </table> 65 66 <!-- INDENTATION --> … … 79 80 <td width="8%"></td> 80 81 <td width="91%"> 81 <p><b>−sf tagnumber filename</b></p></td>82 <p><b>−sf</b> <i>tagnumber filename</i></p></td> 82 83 </table> 83 84 <!-- INDENTATION --> … … 108 109 <td width="17%"></td> 109 110 <td width="82%"> 110 <pre>tiffset -sf 270 descrip a.tif111 <pre>tiffset −sf 270 descrip a.tif 111 112 </pre> 112 113 </td> … … 120 121 <td width="91%"> 121 122 <p>The following example sets the artist tag (315) of a.tif 122 to the string "Anonymous":</p></td> 123 to the string 124 ‘‘Anonymous’’:</p></td> 123 125 </table> 124 126 <!-- INDENTATION --> … … 128 130 <td width="17%"></td> 129 131 <td width="82%"> 130 <pre>tiffset -s 305 Anonymous a.tif132 <pre>tiffset −s 305 Anonymous a.tif 131 133 </pre> 132 134 </td> … … 148 150 <td width="17%"></td> 149 151 <td width="82%"> 150 <pre>tiffset -s 296 2 a.tif151 tiffset -s 282 300.0 a.tif152 tiffset -s 283 300.0 a.tif152 <pre>tiffset −s 296 2 a.tif 153 tiffset −s 282 300.0 a.tif 154 tiffset −s 283 300.0 a.tif 153 155 </pre> 154 156 </td> -
trunk/src/3rdparty/libtiff/html/man/tiffsplit.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:13 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:20 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/man/tiffsv.1.html
r2 r846 1 1 <!-- Creator : groff version 1.18.1 --> 2 <!-- CreationDate: Mon Mar 13 18:03:14 2006-->2 <!-- CreationDate: Fri Jul 13 17:43:20 2007 --> 3 3 <html> 4 4 <head> -
trunk/src/3rdparty/libtiff/html/misc.html
r2 r846 26 26 Silicon Graphics.<p> 27 27 28 The LZW algorithm is derived from the compress program (the proper 29 attribution is included in the source code). The Group 3 fax stuff 30 originated as code from Jef Poskanzer, but has since been rewritten 31 several times. The latest version uses an algorithm from Frank 32 Cringle -- consult <TT>libtiff/mkg3states.c</TT> and 33 <TT>libtiff/tif_fax3.h</TT> for further information. 34 The JPEG support was written by Tom Lane and is dependent on the 35 excellent work of Tom Lane and the Independent JPEG Group (IJG) 36 who distribute their work under friendly licensing similar to this 37 software. 38 Many other people have by now helped with bug fixes and code; a 39 few of the more persistent contributors have been: 28 The LZW algorithm is derived from the compress program (the proper attribution 29 is included in the source code). The Group 3 fax stuff originated as code 30 from Jef Poskanzer, but has since been rewritten several times. The latest 31 version uses an algorithm from Frank Cringle -- consult 32 <TT>libtiff/mkg3states.c</TT> and <TT>libtiff/tif_fax3.h</TT> for further 33 information. The JPEG support was written by Tom Lane and is dependent on the 34 excellent work of Tom Lane and the Independent JPEG Group (IJG) who distribute 35 their work under friendly licensing similar to this software. Joris Van Damme 36 implemented the robust Old JPEG decoder (as included in libtiff since version 37 3.9.0, there was another Old JPEG module in older releases, which was 38 incomplete and unsuitable for many existing images of that format). JBIG 39 module was written by Lee Howard and depends on JBIG library from the Markus 40 Kuhn. Many other people have by now helped with bug fixes and code; a few of 41 the more persistent contributors have been: 40 42 41 43 <PRE> … … 74 76 Lee Howard 75 77 Joris Van Damme 78 Tavis Ormandy 79 Richard Nolde 76 80 </PRE> 77 81 … … 108 112 109 113 110 Last updated: $Date: 200 5/10/23 19:43:29$114 Last updated: $Date: 2007/02/24 15:47:04 $ 111 115 </BODY> 112 116 </HTML> -
trunk/src/3rdparty/libtiff/html/tools.html
r2 r846 12 12 <p>This software distribution comes with a small collection of 13 13 programs for converting non-TIFF format images to TIFF and for 14 manipulating and inter ogating the contents of TIFF images. Several14 manipulating and interrogating the contents of TIFF images. Several 15 15 of these tools are useful in their own right. Many of them however 16 16 are more intended to serve as programming examples for using the … … 22 22 <tr> 23 23 <td valign="top" width="10%"> 24 <tt> tiffgt </tt></td>24 <tt><a href="man/tiffgt.1.html">tiffgt</a> </tt></td> 25 25 <td>Display the contents of one or more TIFF images using OpenGL. 26 26 The software makes extensive use of the <tt>TIFFRGBAImage</tt> … … 28 28 </tr> 29 29 <tr> 30 <td valign="top" width="10%"><tt> tiffsv</tt></td>30 <td valign="top" width="10%"><tt><a href="man/tiffsv.1.html">tiffsv</a></tt></td> 31 31 <td>A program to save all or part of a screen dump on a Silicon 32 32 Graphics system. As for <tt>tiffgt</tt> this code, while written to … … 38 38 <table border cellpadding="3"> 39 39 <tr> 40 <td valign="top" width="10%"><tt> bmp2tiff</tt></td>40 <td valign="top" width="10%"><tt><a href="man/bmp2tiff.1.html">bmp2tiff</a></tt></td> 41 41 <td>Convert BMP images to TIFF</td> 42 42 </tr> 43 43 <tr> 44 <td valign="top" width="10%"><tt> fax2ps</tt></td>44 <td valign="top" width="10%"><tt><a href="man/fax2ps.1.html">fax2ps</a></tt></td> 45 45 <td>Convert a Group 3- or Group 4- compressed TIFF to PostScript 46 46 that is significantly more compressed than is generated by … … 48 48 </tr> 49 49 <tr> 50 <td valign="top" width="10%"><tt> fax2tiff</tt></td>50 <td valign="top" width="10%"><tt><a href="man/fax2tiff.1.html">fax2tiff</a></tt></td> 51 51 <td>Convert raw Group 3 or Group 4 facsimile data to TIFF</td> 52 52 </tr> 53 53 <tr> 54 <td valign="top" width="10%"><tt> gif2tiff</tt></td>55 <td>A quick hack that converts GIF 87a format images to TIFF</td>54 <td valign="top" width="10%"><tt><a href="man/gif2tiff.1.html">gif2tiff</a></tt></td> 55 <td>A quick hack that converts GIF 87a (old) format images to TIFF</td> 56 56 </tr> 57 57 <tr> 58 <td valign="top" width="10%"><tt> pal2rgb</tt></td>58 <td valign="top" width="10%"><tt><a href="man/pal2rgb.1.html">pal2rgb</a></tt></td> 59 59 <td>Convert a Palette-style image to a full color RGB image by 60 60 applying the colormap</td> 61 61 </tr> 62 62 <tr> 63 <td valign="top" width="10%"><tt> ppm2tiff</tt></td>64 <td>A quick hack that converts PPM format images to TIFF</td>63 <td valign="top" width="10%"><tt><a href="man/ppm2tiff.1.html">ppm2tiff</a></tt></td> 64 <td>A quick hack that converts 8-bit PPM format images to TIFF</td> 65 65 </tr> 66 66 <tr> 67 <td valign="top" width="10%"><tt> ras2tiff</tt></td>67 <td valign="top" width="10%"><tt><a href="man/ras2tiff.1.html">ras2tiff</a></tt></td> 68 68 <td>A quick hack that converts Sun rasterfile format images to TIFF 69 69 -- it's less than complete</td> 70 70 </tr> 71 71 <tr> 72 <td valign="top" width="10%"><tt> raw2tiff</tt></td>72 <td valign="top" width="10%"><tt><a href="man/raw2tiff.1.html">raw2tiff</a></tt></td> 73 73 <td>Create a TIFF file from raw data</td> 74 74 </tr> 75 75 <tr> 76 <td valign="top" width="10%"><tt> rgb2ycbcr</tt></td>76 <td valign="top" width="10%"><tt><a href="man/rgb2ycbcr.1.html">rgb2ycbcr</a></tt></td> 77 77 <td>Convert an RGB, grayscale, or bilevel TIFF image to a YCbCr 78 78 TIFF image; it's mainly provided for testing</td> 79 79 </tr> 80 80 <tr> 81 <td valign="top" width="10%"><tt> sgi2tiff</tt></td>81 <td valign="top" width="10%"><tt><a href="man/sgi2tiff.1.html">sgi2tiff</a></tt></td> 82 82 <td>A program to convert SGI image files to TIFF. This program is 83 83 only useful on SGI machines as it uses <tt>-limage</tt>.</td> 84 84 </tr> 85 85 <tr> 86 <td valign="top" width="10%"><tt> thumbnail</tt></td>86 <td valign="top" width="10%"><tt><a href="man/thumbnail.1.html">thumbnail</a></tt></tt></td> 87 87 <td>Copy a bilevel TIFF to one that includes 8-bit greyscale 88 88 "thumbnail images" for each page; it is provided as an example of … … 91 91 </tr> 92 92 <tr> 93 <td valign="top" width="10%"><tt> tiff2bw</tt></td>93 <td valign="top" width="10%"><tt><a href="man/tiff2bw.1.html">tiff2bw</a></tt></td> 94 94 <td>A simple program to convert a color image to grayscale</td> 95 95 </tr> 96 96 <tr> 97 <td valign="top" width="10%"><tt> tiff2pdf</tt></td>97 <td valign="top" width="10%"><tt><a href="man/tiff2pdf.1.html">tiff2pdf</a></tt></td> 98 98 <td>Convert TIFF images to PDF</td> 99 99 </tr> 100 100 <tr> 101 <td valign="top" width="10%"><tt> tiff2ps</tt></td>101 <td valign="top" width="10%"><tt><a href="man/tiff2ps.1.html">tiff2ps</a></tt></td> 102 102 <td>Convert TIFF images to PostScript</td> 103 103 </tr> 104 104 <tr> 105 <td valign="top" width="10%"><tt> tiff2rgba</tt></td>105 <td valign="top" width="10%"><tt><a href="man/tiff2rgba.1.html">tiff2rgba</a></tt></td> 106 106 <td>Convert a TIFF image to RGBA color space</td> 107 107 </tr> 108 108 <tr> 109 <td valign="top" width="10%"><tt> tiffcmp</tt></td>109 <td valign="top" width="10%"><tt><a href="man/tiffcmp.1.html">tiffcmp</a></tt></td> 110 110 <td>Compare the contents of two TIFF files (it does not check all 111 111 the directory information, but does check all the data)</td> 112 112 </tr> 113 113 <tr> 114 <td valign="top" width="10%"><tt> tiffcp</tt></td>114 <td valign="top" width="10%"><tt><a href="man/tiffcp.1.html">tiffcp</a></tt></td> 115 115 <td>Copy, concatenate, and convert TIFF images (e.g. switching from 116 116 Compression=5 to Compression=1)</td> 117 117 </tr> 118 118 <tr> 119 <td valign="top" width="10%"><tt>tiffdither</tt></td> 119 <td valign="top" width="10%"><tt><a href="man/tiffcrop.1.html">tiffcrop</a></tt></td> 120 <td>Provides selection of images from within one or more multi-image 121 TIFF files, with orthogonal rotation, mirroring, cropping, and 122 extraction of multiple sections and exporting to one or more files. 123 It extends the functionality of tiffcp to support additional bit 124 depths in strips and tiles and enhances the selection capabilities of 125 tiffsplit. Bilevel images can be inverted and images may be split into 126 segments to fit on multiple /pages/ (standard paper sizes), plus other 127 functions described in the tiffcrop man page</td> 128 </tr> 129 <tr> 130 <td valign="top" width="10%"><tt><a href="man/tiffdither.1.html">tiffdither</a></tt></td> 120 131 <td>Dither a b&w image into a bilevel image (suitable for use 121 132 in creating fax files)</td> 122 133 </tr> 123 134 <tr> 124 <td valign="top" width="10%"><tt> tiffdump</tt></td>135 <td valign="top" width="10%"><tt><a href="man/tiffdump.1.html">tiffdump</a></tt></td> 125 136 <td>Display the verbatim contents of the TIFF directory in a file 126 137 (it's very useful for debugging bogus files that you may get from … … 128 139 </tr> 129 140 <tr> 130 <td valign="top" width="10%"><tt> tiffinfo</tt></td>141 <td valign="top" width="10%"><tt><a href="man/tiffinfo.1.html">tiffinfo</a></tt></td> 131 142 <td>Display information about one or more TIFF files.</td> 132 143 </tr> 133 144 <tr> 134 <td valign="top" width="10%"><tt> tiffmedian</tt></td>145 <td valign="top" width="10%"><tt><a href="man/tiffmedian.1.html">tiffmedian</a></tt></td> 135 146 <td>A version of Paul Heckbert's median cut program that reads an 136 RGB TIFF image, and creates a TIFF palette file as a result; it's 137 useful for converting full-color RGB images to 8-bit color for your 138 friends that have cheapo 8-bit framebuffers.</td> 147 RGB TIFF image, and creates a TIFF palette file as a result</td> 139 148 </tr> 140 149 <tr> 141 <td valign="top" width="10%"><tt> tiffset</tt></td>150 <td valign="top" width="10%"><tt><a href="man/tiffset.1.html">tiffset</a></tt></td> 142 151 <td>Set a field in a TIFF header</td> 143 152 </tr> 144 153 <tr> 145 <td valign="top" width="10%"><tt> tiffsplit</tt></td>154 <td valign="top" width="10%"><tt><a href="man/tiffsplit.1.html">tiffsplit</a></tt></td> 146 155 <td>Create one or more single-image files from a (possibly) 147 156 multi-image file</td> … … 151 160 programs.</p> 152 161 <hr> 153 Last updated: $Date: 200 6/01/03 02:16:07$162 Last updated: $Date: 2009-10-28 22:13:58 $ 154 163 </body> 155 164 </html> -
trunk/src/3rdparty/libtiff/libtiff/SConstruct
r2 r846 1 # $Id: SConstruct,v 1. 2 2006/03/23 14:54:02dron Exp $1 # $Id: SConstruct,v 1.4 2007/02/24 15:03:50 dron Exp $ 2 2 3 3 # Tag Image File Format (TIFF) Software … … 47 47 'tif_flush.c', \ 48 48 'tif_getimage.c', \ 49 'tif_jbig.c', \ 49 50 'tif_jpeg.c', \ 50 51 'tif_luv.c', \ … … 70 71 StaticLibrary('tiff', SRCS) 71 72 SharedLibrary('tiff', SRCS) 73 -
trunk/src/3rdparty/libtiff/libtiff/mkg3states.c
r2 r846 1 /* "$Id: mkg3states.c,v 1. 9 2004/10/10 11:46:16dron Exp $ */1 /* "$Id: mkg3states.c,v 1.10 2007/02/22 11:27:17 dron Exp $ */ 2 2 3 3 /* … … 41 41 42 42 #include "tif_fax3.h" 43 44 #ifndef HAVE_GETOPT 45 extern int getopt(int, char**, char*); 46 #endif 43 47 44 48 #define streq(a,b) (strcmp(a,b) == 0) -
trunk/src/3rdparty/libtiff/libtiff/tif_aux.c
r2 r846 1 /* $Id: tif_aux.c,v 1. 19 2006/02/07 10:41:30dron Exp $ */1 /* $Id: tif_aux.c,v 1.20 2006/06/08 14:24:13 dron Exp $ */ 2 2 3 3 /* … … 35 35 36 36 tdata_t 37 _TIFFCheckMalloc(TIFF* tif, size_t nmemb, size_t elem_size, const char* what) 37 _TIFFCheckRealloc(TIFF* tif, tdata_t buffer, 38 size_t nmemb, size_t elem_size, const char* what) 38 39 { 39 40 tdata_t cp = NULL; … … 44 45 */ 45 46 if (nmemb && elem_size && bytes / elem_size == nmemb) 46 cp = _TIFF malloc(bytes);47 cp = _TIFFrealloc(buffer, bytes); 47 48 48 49 if (cp == NULL) 49 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "No space %s", what); 50 51 return (cp); 50 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 51 "No space %s", what); 52 53 return cp; 54 } 55 56 tdata_t 57 _TIFFCheckMalloc(TIFF* tif, size_t nmemb, size_t elem_size, const char* what) 58 { 59 return _TIFFCheckRealloc(tif, NULL, nmemb, elem_size, what); 52 60 } 53 61 -
trunk/src/3rdparty/libtiff/libtiff/tif_close.c
r2 r846 1 /* $Id: tif_close.c,v 1. 9 2005/11/23 22:20:56 dronExp $ */1 /* $Id: tif_close.c,v 1.10 2006/03/25 03:09:24 joris Exp $ */ 2 2 3 3 /* … … 55 55 56 56 if (tif->tif_dirlist) 57 58 57 _TIFFfree(tif->tif_dirlist); 58 59 59 /* Clean up client info links */ 60 60 while( tif->tif_clientinfo ) 61 61 { 62 62 TIFFClientInfoLink *link = tif->tif_clientinfo; 63 63 64 65 66 64 tif->tif_clientinfo = link->next; 65 _TIFFfree( link->name ); 66 _TIFFfree( link ); 67 67 } 68 68 69 69 if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER)) 70 70 _TIFFfree(tif->tif_rawdata); 71 71 if (isMapped(tif)) 72 72 TIFFUnmapFileContents(tif, tif->tif_base, tif->tif_size); 73 73 74 74 /* Clean up custom fields */ 75 if (tif->tif_nfields > 0) 75 if (tif->tif_nfields > 0) 76 76 { 77 77 size_t i; 78 78 79 79 for (i = 0; i < tif->tif_nfields; i++) -
trunk/src/3rdparty/libtiff/libtiff/tif_codec.c
r2 r846 1 /* $Id: tif_codec.c,v 1.10 2005/12/21 12:23:13 jorisExp $ */1 /* $Id: tif_codec.c,v 1.10.2.1 2008-12-18 19:50:41 fwarmerdam Exp $ */ 2 2 3 3 /* … … 103 103 { 104 104 const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression); 105 105 char compression_code[20]; 106 107 sprintf( compression_code, "%d", tif->tif_dir.td_compression ); 106 108 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 107 "%s compression support is not configured", c->name); 109 "%s compression support is not configured", 110 c ? c->name : compression_code ); 108 111 return (0); 109 112 } -
trunk/src/3rdparty/libtiff/libtiff/tif_compress.c
r2 r846 1 /* $Id: tif_compress.c,v 1.1 1 2005/12/21 12:23:13 jorisExp $ */1 /* $Id: tif_compress.c,v 1.13 2007/02/24 15:03:50 dron Exp $ */ 2 2 3 3 /* … … 38 38 39 39 if (c) { 40 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%s %s encoding is not implemented", 41 c->name, method); 40 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 41 "%s %s encoding is not implemented", 42 c->name, method); 42 43 } else { 43 44 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 44 45 tif->tif_dir.td_compression, method);45 "Compression scheme %u %s encoding is not implemented", 46 tif->tif_dir.td_compression, method); 46 47 } 47 48 return (-1); … … 75 76 76 77 if (c) 77 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%s %s decoding is not implemented", 78 c->name, method); 78 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 79 "%s %s decoding is not implemented", 80 c->name, method); 79 81 else 80 82 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 81 "Compression scheme %u %s decoding is not implemented",82 tif->tif_dir.td_compression, method);83 "Compression scheme %u %s decoding is not implemented", 84 tif->tif_dir.td_compression, method); 83 85 return (-1); 84 86 } … … 110 112 (void) off; 111 113 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 112 "Compression algorithm does not support random access");114 "Compression algorithm does not support random access"); 113 115 return (0); 114 116 } … … 145 147 tif->tif_defstripsize = _TIFFDefaultStripSize; 146 148 tif->tif_deftilesize = _TIFFDefaultTileSize; 147 tif->tif_flags &= ~ TIFF_NOBITREV;149 tif->tif_flags &= ~(TIFF_NOBITREV|TIFF_NOREADRAW); 148 150 } 149 151 -
trunk/src/3rdparty/libtiff/libtiff/tif_config.h
r561 r846 1 1 /* 2 Configuration defines by Trolltech.2 Configuration defines for Qt. 3 3 */ 4 4 … … 7 7 # include <qfunctions_wince.h> 8 8 #endif 9 10 /* Define if building universal (internal helper macro) */ 11 /* #undef AC_APPLE_UNIVERSAL_BUILD */ 9 12 10 13 /* Support CCITT Group 3 & 4 algorithms */ … … 48 51 49 52 /* Define to 1 if the system has the type `int16'. */ 50 /* #undef HAVE_INT16 */51 53 #ifdef Q_OS_AIX 52 54 #define HAVE_INT16 1 … … 54 56 55 57 /* Define to 1 if the system has the type `int32'. */ 56 /* #undef HAVE_INT32 */57 58 #ifdef Q_OS_AIX 58 59 #define HAVE_INT32 1 … … 60 61 61 62 /* Define to 1 if the system has the type `int8'. */ 62 /* #undef HAVE_INT8 */63 63 #ifdef Q_OS_AIX 64 64 #define HAVE_INT8 1 … … 68 68 /* #undef HAVE_INTTYPES_H */ 69 69 70 /* Define to 1 if you have the <io.h> header file. */ 71 /* #undef HAVE_IO_H */ 72 70 73 /* Define to 1 if you have the `isascii' function. */ 71 74 /* #undef HAVE_ISASCII */ 75 76 /* Define to 1 if you have the `jbg_newlen' function. */ 77 /* #undef HAVE_JBG_NEWLEN */ 72 78 73 79 /* Define to 1 if you have the `lfind' function. */ … … 109 115 #endif 110 116 117 /* Define to 1 if you have the `setmode' function. */ 118 /* #undef HAVE_SETMODE */ 119 111 120 /* Define to 1 if you have the `sqrt' function. */ 112 121 /* #undef HAVE_SQRT */ … … 156 165 /* Define to 1 if you have the <windows.h> header file. */ 157 166 /* #undef HAVE_WINDOWS_H */ 158 #ifdef Q_OS_WIN159 #define TIF_PLATFORM_CONSOLE160 #endif161 167 162 168 /* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian … … 171 177 #define HOST_FILLORDER FILLORDER_LSB2MSB 172 178 179 /* Support ISO JBIG compression (requires JBIG-KIT library) */ 180 /* #undef JBIG_SUPPORT */ 181 173 182 /* Support JPEG compression (requires IJG JPEG library) */ 174 183 /* #undef JPEG_SUPPORT */ … … 193 202 /* #undef NO_MINUS_C_MINUS_O */ 194 203 195 /* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation 196 fails with unpatched IJG JPEG library) */ 204 /* Support Old JPEG compresson (read-only) */ 197 205 /* #undef OJPEG_SUPPORT */ 198 206 … … 212 220 /* #undef PACKAGE_TARNAME */ 213 221 222 /* Define to the home page for this package. */ 223 /* #undef PACKAGE_URL */ 224 214 225 /* Define to the version of this package. */ 215 /* #undef PACKAGE_VERSION */ 226 #define PACKAGE_VERSION "3.9.2" 216 227 217 228 /* Support Macintosh PackBits algorithm */ … … 225 236 /* #undef PTHREAD_CREATE_JOINABLE */ 226 237 227 /* The size of a`int', as computed by sizeof. */238 /* The size of `int', as computed by sizeof. */ 228 239 #define SIZEOF_INT 4 229 240 230 /* The size of a`long', as computed by sizeof. */241 /* The size of `long', as computed by sizeof. */ 231 242 #if (QT_POINTER_SIZE == 8) && !defined(Q_OS_WIN64) 232 243 #define SIZEOF_LONG 8 … … 235 246 #endif 236 247 248 /* The size of `signed long', as computed by sizeof. */ 249 /* #undef SIZEOF_SIGNED_LONG */ 250 251 /* The size of `signed long long', as computed by sizeof. */ 252 /* #undef SIZEOF_SIGNED_LONG_LONG */ 253 254 /* The size of `unsigned long', as computed by sizeof. */ 255 /* #undef SIZEOF_UNSIGNED_LONG */ 256 257 /* The size of `unsigned long long', as computed by sizeof. */ 258 /* #undef SIZEOF_UNSIGNED_LONG_LONG */ 259 237 260 /* Define to 1 if you have the ANSI C header files. */ 238 261 /* #undef STDC_HEADERS */ … … 251 274 #define THUNDER_SUPPORT 1 252 275 276 /* Signed 64-bit type formatter */ 277 /* #undef TIFF_INT64_FORMAT */ 278 279 /* Signed 64-bit type */ 280 #define TIFF_INT64_T qint64 281 282 /* Unsigned 64-bit type formatter */ 283 /* #undef TIFF_UINT64_FORMAT */ 284 285 /* Unsigned 64-bit type */ 286 #define TIFF_UINT64_T quint64 287 253 288 /* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ 254 289 /* #undef TIME_WITH_SYS_TIME */ … … 260 295 /* #undef VERSION */ 261 296 262 /* Define to 1 if your processor stores words with the most significant byte263 first (like Motorola and SPARC, unlike Intel and VAX). */297 /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 298 significant byte first (like Motorola and SPARC, unlike Intel). */ 264 299 #if (Q_BYTE_ORDER == Q_BIG_ENDIAN) 265 300 #define WORDS_BIGENDIAN 1 266 #else267 /* #undef WORDS_BIGENDIAN */268 301 #endif 269 302 … … 292 325 #endif 293 326 294 /* Define to `long ' if <sys/types.h> does not define. */327 /* Define to `long int' if <sys/types.h> does not define. */ 295 328 /* #undef off_t */ 296 329 297 /* Define to `unsigned ' if <sys/types.h> does not define. */330 /* Define to `unsigned int' if <sys/types.h> does not define. */ 298 331 /* #undef size_t */ 332 333 #ifdef Q_OS_WIN 334 #define TIF_PLATFORM_CONSOLE 335 #endif -
trunk/src/3rdparty/libtiff/libtiff/tif_config.h.in
r2 r846 1 1 /* libtiff/tif_config.h.in. Generated from configure.ac by autoheader. */ 2 3 /* Define if building universal (internal helper macro) */ 4 #undef AC_APPLE_UNIVERSAL_BUILD 2 5 3 6 /* Support CCITT Group 3 & 4 algorithms */ … … 50 53 #undef HAVE_INTTYPES_H 51 54 55 /* Define to 1 if you have the <io.h> header file. */ 56 #undef HAVE_IO_H 57 52 58 /* Define to 1 if you have the `isascii' function. */ 53 59 #undef HAVE_ISASCII 54 60 61 /* Define to 1 if you have the `jbg_newlen' function. */ 62 #undef HAVE_JBG_NEWLEN 63 55 64 /* Define to 1 if you have the `lfind' function. */ 56 65 #undef HAVE_LFIND … … 88 97 /* Define to 1 if you have the <search.h> header file. */ 89 98 #undef HAVE_SEARCH_H 99 100 /* Define to 1 if you have the `setmode' function. */ 101 #undef HAVE_SETMODE 90 102 91 103 /* Define to 1 if you have the `sqrt' function. */ … … 144 156 #undef HOST_FILLORDER 145 157 158 /* Support ISO JBIG compression (requires JBIG-KIT library) */ 159 #undef JBIG_SUPPORT 160 146 161 /* Support JPEG compression (requires IJG JPEG library) */ 147 162 #undef JPEG_SUPPORT … … 166 181 #undef NO_MINUS_C_MINUS_O 167 182 168 /* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation 169 fails with unpatched IJG JPEG library) */ 183 /* Support Old JPEG compresson (read-only) */ 170 184 #undef OJPEG_SUPPORT 171 185 … … 184 198 /* Define to the one symbol short name of this package. */ 185 199 #undef PACKAGE_TARNAME 200 201 /* Define to the home page for this package. */ 202 #undef PACKAGE_URL 186 203 187 204 /* Define to the version of this package. */ … … 198 215 #undef PTHREAD_CREATE_JOINABLE 199 216 200 /* The size of a`int', as computed by sizeof. */217 /* The size of `int', as computed by sizeof. */ 201 218 #undef SIZEOF_INT 202 219 203 /* The size of a`long', as computed by sizeof. */220 /* The size of `long', as computed by sizeof. */ 204 221 #undef SIZEOF_LONG 222 223 /* The size of `signed long', as computed by sizeof. */ 224 #undef SIZEOF_SIGNED_LONG 225 226 /* The size of `signed long long', as computed by sizeof. */ 227 #undef SIZEOF_SIGNED_LONG_LONG 228 229 /* The size of `unsigned long', as computed by sizeof. */ 230 #undef SIZEOF_UNSIGNED_LONG 231 232 /* The size of `unsigned long long', as computed by sizeof. */ 233 #undef SIZEOF_UNSIGNED_LONG_LONG 205 234 206 235 /* Define to 1 if you have the ANSI C header files. */ … … 220 249 #undef THUNDER_SUPPORT 221 250 251 /* Signed 64-bit type formatter */ 252 #undef TIFF_INT64_FORMAT 253 254 /* Signed 64-bit type */ 255 #undef TIFF_INT64_T 256 257 /* Unsigned 64-bit type formatter */ 258 #undef TIFF_UINT64_FORMAT 259 260 /* Unsigned 64-bit type */ 261 #undef TIFF_UINT64_T 262 222 263 /* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ 223 264 #undef TIME_WITH_SYS_TIME … … 229 270 #undef VERSION 230 271 231 /* Define to 1 if your processor stores words with the most significant byte 232 first (like Motorola and SPARC, unlike Intel and VAX). */ 233 #undef WORDS_BIGENDIAN 272 /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 273 significant byte first (like Motorola and SPARC, unlike Intel). */ 274 #if defined AC_APPLE_UNIVERSAL_BUILD 275 # if defined __BIG_ENDIAN__ 276 # define WORDS_BIGENDIAN 1 277 # endif 278 #else 279 # ifndef WORDS_BIGENDIAN 280 # undef WORDS_BIGENDIAN 281 # endif 282 #endif 234 283 235 284 /* Define to 1 if the X Window System is missing or not being used. */ … … 254 303 #endif 255 304 256 /* Define to `long ' if <sys/types.h> does not define. */305 /* Define to `long int' if <sys/types.h> does not define. */ 257 306 #undef off_t 258 307 259 /* Define to `unsigned ' if <sys/types.h> does not define. */308 /* Define to `unsigned int' if <sys/types.h> does not define. */ 260 309 #undef size_t -
trunk/src/3rdparty/libtiff/libtiff/tif_dir.c
r2 r846 1 /* $Id: tif_dir.c,v 1.7 2 2006/03/15 12:49:35 dron Exp $ */1 /* $Id: tif_dir.c,v 1.75.2.2 2009-01-01 00:10:43 bfriesen Exp $ */ 2 2 3 3 /* … … 75 75 setExtraSamples(TIFFDirectory* td, va_list ap, uint32* v) 76 76 { 77 /* XXX: Unassociated alpha data == 999 is a known Corel Draw bug, see below */ 78 #define EXTRASAMPLE_COREL_UNASSALPHA 999 79 77 80 uint16* va; 78 81 uint32 i; … … 80 83 *v = va_arg(ap, uint32); 81 84 if ((uint16) *v > td->td_samplesperpixel) 82 return (0);85 return 0; 83 86 va = va_arg(ap, uint16*); 84 87 if (*v > 0 && va == NULL) /* typically missing param */ 85 return (0); 86 for (i = 0; i < *v; i++) 87 if (va[i] > EXTRASAMPLE_UNASSALPHA) 88 return (0); 88 return 0; 89 for (i = 0; i < *v; i++) { 90 if (va[i] > EXTRASAMPLE_UNASSALPHA) { 91 /* 92 * XXX: Corel Draw is known to produce incorrect 93 * ExtraSamples tags which must be patched here if we 94 * want to be able to open some of the damaged TIFF 95 * files: 96 */ 97 if (va[i] == EXTRASAMPLE_COREL_UNASSALPHA) 98 va[i] = EXTRASAMPLE_UNASSALPHA; 99 else 100 return 0; 101 } 102 } 89 103 td->td_extrasamples = (uint16) *v; 90 104 _TIFFsetShortArray(&td->td_sampleinfo, va, td->td_extrasamples); 91 return (1); 105 return 1; 106 107 #undef EXTRASAMPLE_COREL_UNASSALPHA 92 108 } 93 109 … … 122 138 { 123 139 static const char module[] = "_TIFFVSetField"; 124 140 125 141 TIFFDirectory* td = &tif->tif_dir; 126 142 int status = 1; … … 193 209 td->td_fillorder = (uint16) v; 194 210 break; 195 break;196 211 case TIFFTAG_ORIENTATION: 197 212 v = va_arg(ap, uint32); 198 if (v < ORIENTATION_TOPLEFT || ORIENTATION_LEFTBOT < v) { 199 TIFFWarningExt(tif->tif_clientdata, tif->tif_name, 200 "Bad value %lu for \"%s\" tag ignored", 201 v, _TIFFFieldWithTag(tif, tag)->field_name); 202 } else 213 if (v < ORIENTATION_TOPLEFT || ORIENTATION_LEFTBOT < v) 214 goto badvalue; 215 else 203 216 td->td_orientation = (uint16) v; 204 217 break; … … 346 359 (long) td->td_nsubifd); 347 360 } else { 348 TIFFErrorExt(tif->tif_clientdata, module, "%s: Sorry, cannot nest SubIFDs", 349 tif->tif_name); 361 TIFFErrorExt(tif->tif_clientdata, module, 362 "%s: Sorry, cannot nest SubIFDs", 363 tif->tif_name); 350 364 status = 0; 351 365 } … … 375 389 break; 376 390 default: { 377 const TIFFFieldInfo* fip = _TIFFFindFieldInfo(tif, tag, TIFF_ANY);378 391 TIFFTagValue *tv; 379 392 int tv_size, iCustom; 393 const TIFFFieldInfo* fip = _TIFFFindFieldInfo(tif, tag, TIFF_ANY); 380 394 381 395 /* … … 390 404 if(fip == NULL || fip->field_bit != FIELD_CUSTOM) { 391 405 TIFFErrorExt(tif->tif_clientdata, module, 392 "%s: Invalid %stag \"%s\" (not supported by codec)",393 tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",394 _TIFFFieldWithTag(tif, tag)->field_name);406 "%s: Invalid %stag \"%s\" (not supported by codec)", 407 tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "", 408 fip ? fip->field_name : "Unknown"); 395 409 status = 0; 396 410 break; … … 401 415 */ 402 416 tv = NULL; 403 for(iCustom = 0; iCustom < td->td_customValueCount; iCustom++) { 404 if(td->td_customValues[iCustom].info == fip) { 405 tv = td->td_customValues + iCustom; 406 if(tv->value != NULL) 407 { 408 _TIFFfree(tv->value); 409 tv->value = NULL; 410 } 411 break; 412 } 417 for (iCustom = 0; iCustom < td->td_customValueCount; iCustom++) { 418 if (td->td_customValues[iCustom].info->field_tag == tag) { 419 tv = td->td_customValues + iCustom; 420 if (tv->value != NULL) { 421 _TIFFfree(tv->value); 422 tv->value = NULL; 423 } 424 break; 425 } 413 426 } 414 427 … … 433 446 td->td_customValues = new_customValues; 434 447 435 tv = td->td_customValues + (td->td_customValueCount -1);448 tv = td->td_customValues + (td->td_customValueCount - 1); 436 449 tv->info = fip; 437 450 tv->value = NULL; … … 469 482 _TIFFsetString((char **)&tv->value, va_arg(ap, char *)); 470 483 else { 471 tv->value = _TIFFmalloc(tv_size * tv->count); 484 tv->value = _TIFFCheckMalloc(tif, tv_size, tv->count, 485 "Tag Value"); 472 486 if (!tv->value) { 473 487 status = 0; … … 572 586 return (status); 573 587 badvalue: 574 TIFFErrorExt(tif->tif_clientdata, module, "%s: Bad value %d for \"%s\"", 575 tif->tif_name, v, _TIFFFieldWithTag(tif, tag)->field_name); 588 TIFFErrorExt(tif->tif_clientdata, module, 589 "%s: Bad value %d for \"%s\" tag", 590 tif->tif_name, v, 591 _TIFFFieldWithTag(tif, tag)->field_name); 576 592 va_end(ap); 577 593 return (0); 578 594 badvalue32: 579 TIFFErrorExt(tif->tif_clientdata, module, "%s: Bad value %ld for \"%s\"", 580 tif->tif_name, v32, _TIFFFieldWithTag(tif, tag)->field_name); 595 TIFFErrorExt(tif->tif_clientdata, module, 596 "%s: Bad value %u for \"%s\" tag", 597 tif->tif_name, v32, 598 _TIFFFieldWithTag(tif, tag)->field_name); 581 599 va_end(ap); 582 600 return (0); … … 807 825 808 826 /* 809 * This can happen if multiple images are open with 810 * different codecs which have private tags. The 811 * global tag information table may then have tags 812 * that are valid for one file but not the other. 813 * If the client tries to get a tag that is not valid 814 * for the image's codec then we'll arrive here. 827 * This can happen if multiple images are open with different 828 * codecs which have private tags. The global tag information 829 * table may then have tags that are valid for one file but not 830 * the other. If the client tries to get a tag that is not valid 831 * for the image's codec then we'll arrive here. 815 832 */ 816 833 if( fip == NULL || fip->field_bit != FIELD_CUSTOM ) 817 834 { 818 TIFFErrorExt(tif->tif_clientdata, "_TIFFVGetField", 819 "%s: Invalid %stag \"%s\" (not supported by codec)", 820 tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "", 821 _TIFFFieldWithTag(tif, tag)->field_name); 822 ret_val = 0; 823 break; 835 TIFFErrorExt(tif->tif_clientdata, "_TIFFVGetField", 836 "%s: Invalid %stag \"%s\" " 837 "(not supported by codec)", 838 tif->tif_name, 839 isPseudoTag(tag) ? "pseudo-" : "", 840 fip ? fip->field_name : "Unknown"); 841 ret_val = 0; 842 break; 824 843 } 825 844 … … 1033 1052 size_t tiffFieldInfoCount; 1034 1053 const TIFFFieldInfo *tiffFieldInfo = 1035 1054 _TIFFGetFieldInfo(&tiffFieldInfoCount); 1036 1055 _TIFFSetupFieldInfo(tif, tiffFieldInfo, tiffFieldInfoCount); 1037 1056 … … 1054 1073 td->td_ycbcrpositioning = YCBCRPOSITION_CENTERED; 1055 1074 tif->tif_postdecode = _TIFFNoPostDecode; 1056 1075 tif->tif_foundfield = NULL; 1057 1076 tif->tif_tagmethods.vsetfield = _TIFFVSetField; 1058 1077 tif->tif_tagmethods.vgetfield = _TIFFVGetField; … … 1075 1094 tif->tif_flags &= ~TIFF_DIRTYDIRECT; 1076 1095 1077 1078 1079 1080 1081 1082 1096 /* 1097 * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=19 1098 * we clear the ISTILED flag when setting up a new directory. 1099 * Should we also be clearing stuff like INSUBIFD? 1100 */ 1101 tif->tif_flags &= ~TIFF_ISTILED; 1083 1102 1084 1103 return (1); … … 1088 1107 TIFFAdvanceDirectory(TIFF* tif, uint32* nextdir, toff_t* off) 1089 1108 { 1090 1091 1092 1093 1094 1095 1096 1109 static const char module[] = "TIFFAdvanceDirectory"; 1110 uint16 dircount; 1111 if (isMapped(tif)) 1112 { 1113 toff_t poff=*nextdir; 1114 if (poff+sizeof(uint16) > tif->tif_size) 1115 { 1097 1116 TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory count", 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1117 tif->tif_name); 1118 return (0); 1119 } 1120 _TIFFmemcpy(&dircount, tif->tif_base+poff, sizeof (uint16)); 1121 if (tif->tif_flags & TIFF_SWAB) 1122 TIFFSwabShort(&dircount); 1123 poff+=sizeof (uint16)+dircount*sizeof (TIFFDirEntry); 1124 if (off != NULL) 1125 *off = poff; 1126 if (((toff_t) (poff+sizeof (uint32))) > tif->tif_size) 1127 { 1109 1128 TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory link", 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1129 tif->tif_name); 1130 return (0); 1131 } 1132 _TIFFmemcpy(nextdir, tif->tif_base+poff, sizeof (uint32)); 1133 if (tif->tif_flags & TIFF_SWAB) 1134 TIFFSwabLong(nextdir); 1135 return (1); 1136 } 1137 else 1138 { 1139 if (!SeekOK(tif, *nextdir) || 1140 !ReadOK(tif, &dircount, sizeof (uint16))) { 1122 1141 TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory count", 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1142 tif->tif_name); 1143 return (0); 1144 } 1145 if (tif->tif_flags & TIFF_SWAB) 1146 TIFFSwabShort(&dircount); 1147 if (off != NULL) 1148 *off = TIFFSeekFile(tif, 1149 dircount*sizeof (TIFFDirEntry), SEEK_CUR); 1150 else 1151 (void) TIFFSeekFile(tif, 1152 dircount*sizeof (TIFFDirEntry), SEEK_CUR); 1153 if (!ReadOK(tif, nextdir, sizeof (uint32))) { 1135 1154 TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory link", 1136 1137 1138 1139 1140 1141 1142 1155 tif->tif_name); 1156 return (0); 1157 } 1158 if (tif->tif_flags & TIFF_SWAB) 1159 TIFFSwabLong(nextdir); 1160 return (1); 1161 } 1143 1162 } 1144 1163 -
trunk/src/3rdparty/libtiff/libtiff/tif_dir.h
r2 r846 1 /* $Id: tif_dir.h,v 1. 28 2005/12/26 14:31:25dron Exp $ */1 /* $Id: tif_dir.h,v 1.30.2.1 2007/04/07 14:58:30 dron Exp $ */ 2 2 3 3 /* … … 39 39 unsigned long td_fieldsset[FIELD_SETLONGS]; 40 40 41 uint32 td_imagewidth, td_imagelength, td_imagedepth; 42 uint32 td_tilewidth, td_tilelength, td_tiledepth; 43 uint32 td_subfiletype; 44 uint16 td_bitspersample; 45 uint16 td_sampleformat; 46 uint16 td_compression; 47 uint16 td_photometric; 48 uint16 td_threshholding; 49 uint16 td_fillorder; 50 uint16 td_orientation; 51 uint16 td_samplesperpixel; 52 uint32 td_rowsperstrip; 53 uint16 td_minsamplevalue, td_maxsamplevalue; 54 double td_sminsamplevalue, td_smaxsamplevalue; 55 float td_xresolution, td_yresolution; 56 uint16 td_resolutionunit; 57 uint16 td_planarconfig; 58 float td_xposition, td_yposition; 59 uint16 td_pagenumber[2]; 60 uint16* td_colormap[3]; 61 uint16 td_halftonehints[2]; 62 uint16 td_extrasamples; 63 uint16* td_sampleinfo; 64 tstrip_t td_stripsperimage; 65 tstrip_t td_nstrips; /* size of offset & bytecount arrays */ 66 uint32* td_stripoffset; 67 uint32* td_stripbytecount; 68 int td_stripbytecountsorted; /* is the bytecount array sorted ascending? */ 69 uint16 td_nsubifd; 70 uint32* td_subifd; 41 uint32 td_imagewidth, td_imagelength, td_imagedepth; 42 uint32 td_tilewidth, td_tilelength, td_tiledepth; 43 uint32 td_subfiletype; 44 uint16 td_bitspersample; 45 uint16 td_sampleformat; 46 uint16 td_compression; 47 uint16 td_photometric; 48 uint16 td_threshholding; 49 uint16 td_fillorder; 50 uint16 td_orientation; 51 uint16 td_samplesperpixel; 52 uint32 td_rowsperstrip; 53 uint16 td_minsamplevalue, td_maxsamplevalue; 54 double td_sminsamplevalue, td_smaxsamplevalue; 55 float td_xresolution, td_yresolution; 56 uint16 td_resolutionunit; 57 uint16 td_planarconfig; 58 float td_xposition, td_yposition; 59 uint16 td_pagenumber[2]; 60 uint16* td_colormap[3]; 61 uint16 td_halftonehints[2]; 62 uint16 td_extrasamples; 63 uint16* td_sampleinfo; 64 /* even though the name is misleading, td_stripsperimage is the number 65 * of striles (=strips or tiles) per plane, and td_nstrips the total 66 * number of striles */ 67 tstrile_t td_stripsperimage; 68 tstrile_t td_nstrips; /* size of offset & bytecount arrays */ 69 toff_t* td_stripoffset; 70 toff_t* td_stripbytecount; /* FIXME: it should be tsize_t array */ 71 int td_stripbytecountsorted; /* is the bytecount array sorted ascending? */ 72 uint16 td_nsubifd; 73 uint32* td_subifd; 71 74 /* YCbCr parameters */ 72 uint16 73 uint16 75 uint16 td_ycbcrsubsampling[2]; 76 uint16 td_ycbcrpositioning; 74 77 /* Colorimetry parameters */ 75 uint16* 78 uint16* td_transferfunction[3]; 76 79 /* CMYK parameters */ 77 int 78 char* 80 int td_inknameslen; 81 char* td_inknames; 79 82 80 83 int td_customValueCount; … … 178 181 extern const TIFFFieldInfo *_TIFFGetExifFieldInfo(size_t *); 179 182 extern void _TIFFSetupFieldInfo(TIFF*, const TIFFFieldInfo[], size_t); 183 extern int _TIFFMergeFieldInfo(TIFF*, const TIFFFieldInfo[], int); 180 184 extern void _TIFFPrintFieldInfo(TIFF*, FILE*); 181 185 extern TIFFDataType _TIFFSampleToTagType(TIFF*); … … 186 190 TIFFDataType dt ); 187 191 188 #define _TIFFMergeFieldInfo TIFFMergeFieldInfo189 192 #define _TIFFFindFieldInfo TIFFFindFieldInfo 190 193 #define _TIFFFindFieldInfoByName TIFFFindFieldInfoByName -
trunk/src/3rdparty/libtiff/libtiff/tif_dirinfo.c
r2 r846 1 /* $Id: tif_dirinfo.c,v 1.6 2 2006/02/07 10:45:38 dron Exp $ */1 /* $Id: tif_dirinfo.c,v 1.65.2.7 2009-09-17 18:00:28 bfriesen Exp $ */ 2 2 3 3 /* … … 32 32 #include "tiffiop.h" 33 33 #include <stdlib.h> 34 #include <string.h> 34 35 35 36 /* … … 450 451 { EXIFTAG_FLASHPIXVERSION, 4, 4, TIFF_UNDEFINED, FIELD_CUSTOM, 451 452 1, 0, "FlashpixVersion" }, 453 { EXIFTAG_COLORSPACE, 1, 1, TIFF_SHORT, FIELD_CUSTOM, 454 1, 0, "ColorSpace" }, 452 455 { EXIFTAG_PIXELXDIMENSION, 1, 1, TIFF_LONG, FIELD_CUSTOM, 453 456 1, 0, "PixelXDimension" }, … … 543 546 tif->tif_nfields = 0; 544 547 } 545 _TIFFMergeFieldInfo(tif, info, n); 548 if (!_TIFFMergeFieldInfo(tif, info, n)) 549 { 550 TIFFErrorExt(tif->tif_clientdata, "_TIFFSetupFieldInfo", 551 "Setting up field info failed"); 552 } 546 553 } 547 554 … … 553 560 /* NB: be careful of return values for 16-bit platforms */ 554 561 if (ta->field_tag != tb->field_tag) 555 return ( ta->field_tag < tb->field_tag ? -1 : 1);562 return (int)ta->field_tag - (int)tb->field_tag; 556 563 else 557 return ((int)tb->field_type - (int)ta->field_type); 564 return (ta->field_type == TIFF_ANY) ? 565 0 : ((int)tb->field_type - (int)ta->field_type); 558 566 } 559 567 … … 563 571 const TIFFFieldInfo* ta = *(const TIFFFieldInfo**) a; 564 572 const TIFFFieldInfo* tb = *(const TIFFFieldInfo**) b; 565 566 return strcmp(ta->field_name, tb->field_name); 573 int ret = strcmp(ta->field_name, tb->field_name); 574 575 if (ret) 576 return ret; 577 else 578 return (ta->field_type == TIFF_ANY) ? 579 0 : ((int)tb->field_type - (int)ta->field_type); 567 580 } 568 581 569 582 void 583 TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], int n) 584 { 585 if (_TIFFMergeFieldInfo(tif, info, n) < 0) 586 { 587 TIFFErrorExt(tif->tif_clientdata, "TIFFMergeFieldInfo", 588 "Merging block of %d fields failed", n); 589 } 590 } 591 592 int 570 593 _TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], int n) 571 594 { 595 static const char module[] = "_TIFFMergeFieldInfo"; 596 static const char reason[] = "for field info array"; 572 597 TIFFFieldInfo** tp; 573 598 int i; … … 577 602 if (tif->tif_nfields > 0) { 578 603 tif->tif_fieldinfo = (TIFFFieldInfo**) 579 _TIFFrealloc(tif->tif_fieldinfo, 580 (tif->tif_nfields+n) * sizeof (TIFFFieldInfo*)); 604 _TIFFCheckRealloc(tif, tif->tif_fieldinfo, 605 (tif->tif_nfields + n), 606 sizeof (TIFFFieldInfo*), reason); 581 607 } else { 582 608 tif->tif_fieldinfo = (TIFFFieldInfo**) 583 _TIFFmalloc(n * sizeof (TIFFFieldInfo*)); 584 } 585 assert(tif->tif_fieldinfo != NULL); 609 _TIFFCheckMalloc(tif, n, sizeof (TIFFFieldInfo*), 610 reason); 611 } 612 if (!tif->tif_fieldinfo) { 613 TIFFErrorExt(tif->tif_clientdata, module, 614 "Failed to allocate field info array"); 615 return 0; 616 } 586 617 tp = tif->tif_fieldinfo + tif->tif_nfields; 587 618 for (i = 0; i < n; i++) 588 *tp++ = (TIFFFieldInfo*) (info + i); /* XXX */ 619 { 620 const TIFFFieldInfo *fip = 621 _TIFFFindFieldInfo(tif, info[i].field_tag, info[i].field_type); 622 623 /* only add definitions that aren't already present */ 624 if (!fip) { 625 *tp++ = (TIFFFieldInfo*) (info + i); 626 tif->tif_nfields++; 627 } 628 } 589 629 590 630 /* Sort the field info by tag number */ 591 qsort(tif->tif_fieldinfo, tif->tif_nfields += n,631 qsort(tif->tif_fieldinfo, tif->tif_nfields, 592 632 sizeof (TIFFFieldInfo*), tagCompare); 633 634 return n; 593 635 } 594 636 … … 705 747 _TIFFFindFieldInfo(TIFF* tif, ttag_t tag, TIFFDataType dt) 706 748 { 707 int i, n; 749 TIFFFieldInfo key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0}; 750 TIFFFieldInfo* pkey = &key; 751 const TIFFFieldInfo **ret; 708 752 709 753 if (tif->tif_foundfield && tif->tif_foundfield->field_tag == tag && 710 754 (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type)) 711 return (tif->tif_foundfield); 755 return tif->tif_foundfield; 756 757 /* If we are invoked with no field information, then just return. */ 758 if ( !tif->tif_fieldinfo ) { 759 return NULL; 760 } 761 712 762 /* NB: use sorted search (e.g. binary search) */ 713 if(dt != TIFF_ANY) { 714 TIFFFieldInfo key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0}; 715 TIFFFieldInfo* pkey = &key; 716 const TIFFFieldInfo **ret; 717 718 key.field_tag = tag; 719 key.field_type = dt; 720 721 ret = (const TIFFFieldInfo **) bsearch(&pkey, 722 tif->tif_fieldinfo, 723 tif->tif_nfields, 724 sizeof(TIFFFieldInfo *), 725 tagCompare); 726 return (ret) ? (*ret) : NULL; 727 } else for (i = 0, n = tif->tif_nfields; i < n; i++) { 728 const TIFFFieldInfo* fip = tif->tif_fieldinfo[i]; 729 if (fip->field_tag == tag && 730 (dt == TIFF_ANY || fip->field_type == dt)) 731 return (tif->tif_foundfield = fip); 732 } 733 return ((const TIFFFieldInfo *)0); 763 key.field_tag = tag; 764 key.field_type = dt; 765 766 ret = (const TIFFFieldInfo **) bsearch(&pkey, 767 tif->tif_fieldinfo, 768 tif->tif_nfields, 769 sizeof(TIFFFieldInfo *), 770 tagCompare); 771 return tif->tif_foundfield = (ret ? *ret : NULL); 734 772 } 735 773 … … 737 775 _TIFFFindFieldInfoByName(TIFF* tif, const char *field_name, TIFFDataType dt) 738 776 { 739 int i, n; 777 TIFFFieldInfo key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0}; 778 TIFFFieldInfo* pkey = &key; 779 const TIFFFieldInfo **ret; 740 780 741 781 if (tif->tif_foundfield … … 743 783 && (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type)) 744 784 return (tif->tif_foundfield); 785 786 /* If we are invoked with no field information, then just return. */ 787 if ( !tif->tif_fieldinfo ) { 788 return NULL; 789 } 790 745 791 /* NB: use sorted search (e.g. binary search) */ 746 if(dt != TIFF_ANY) { 747 TIFFFieldInfo key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0}; 748 TIFFFieldInfo* pkey = &key; 749 const TIFFFieldInfo **ret; 750 751 key.field_name = (char *)field_name; 752 key.field_type = dt; 753 754 ret = (const TIFFFieldInfo **) lfind(&pkey, 755 tif->tif_fieldinfo, 756 &tif->tif_nfields, 757 sizeof(TIFFFieldInfo *), 758 tagNameCompare); 759 return (ret) ? (*ret) : NULL; 760 } else 761 for (i = 0, n = tif->tif_nfields; i < n; i++) { 762 const TIFFFieldInfo* fip = tif->tif_fieldinfo[i]; 763 if (streq(fip->field_name, field_name) && 764 (dt == TIFF_ANY || fip->field_type == dt)) 765 return (tif->tif_foundfield = fip); 766 } 767 return ((const TIFFFieldInfo *)0); 792 key.field_name = (char *)field_name; 793 key.field_type = dt; 794 795 ret = (const TIFFFieldInfo **) lfind(&pkey, 796 tif->tif_fieldinfo, 797 &tif->tif_nfields, 798 sizeof(TIFFFieldInfo *), 799 tagNameCompare); 800 return tif->tif_foundfield = (ret ? *ret : NULL); 768 801 } 769 802 … … 774 807 if (!fip) { 775 808 TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithTag", 776 "Internal error, unknown tag 0x%x",777 809 "Internal error, unknown tag 0x%x", 810 (unsigned int) tag); 778 811 assert(fip != NULL); 779 812 /*NOTREACHED*/ … … 789 822 if (!fip) { 790 823 TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithName", 791 "Internal error, unknown tag %s", field_name);824 "Internal error, unknown tag %s", field_name); 792 825 assert(fip != NULL); 793 826 /*NOTREACHED*/ … … 806 839 { 807 840 fld = _TIFFCreateAnonFieldInfo( tif, tag, dt ); 808 _TIFFMergeFieldInfo( tif, fld, 1 ); 841 if (!_TIFFMergeFieldInfo(tif, fld, 1)) 842 return NULL; 809 843 } 810 844 … … 824 858 825 859 fld->field_tag = tag; 826 fld->field_readcount = TIFF_VARIABLE ;827 fld->field_writecount = TIFF_VARIABLE ;860 fld->field_readcount = TIFF_VARIABLE2; 861 fld->field_writecount = TIFF_VARIABLE2; 828 862 fld->field_type = field_type; 829 863 fld->field_bit = FIELD_CUSTOM; … … 836 870 } 837 871 838 /* note that this name is a special sign to TIFFClose() and 872 /* 873 * note that this name is a special sign to TIFFClose() and 839 874 * _TIFFSetupFieldInfo() to free the field 840 875 */ -
trunk/src/3rdparty/libtiff/libtiff/tif_dirread.c
r2 r846 1 /* $Id: tif_dirread.c,v 1. 82 2006/03/16 12:24:53 dron Exp $ */1 /* $Id: tif_dirread.c,v 1.92.2.6 2009-10-29 20:04:32 bfriesen Exp $ */ 2 2 3 3 /* … … 42 42 #endif 43 43 44 static TIFFDirEntry* TIFFReadDirectoryFind(TIFFDirEntry* dir, 45 uint16 dircount, uint16 tagid); 44 46 static int EstimateStripByteCounts(TIFF*, TIFFDirEntry*, uint16); 45 47 static void MissingRequired(TIFF*, const char*); 48 static int TIFFCheckDirOffset(TIFF*, toff_t); 46 49 static int CheckDirCount(TIFF*, TIFFDirEntry*, uint32); 50 static uint16 TIFFFetchDirectory(TIFF*, toff_t, TIFFDirEntry**, toff_t *); 47 51 static tsize_t TIFFFetchData(TIFF*, TIFFDirEntry*, char*); 48 52 static tsize_t TIFFFetchString(TIFF*, TIFFDirEntry*, char*); … … 55 59 static int TIFFFetchStripThing(TIFF*, TIFFDirEntry*, long, uint32**); 56 60 static int TIFFFetchRefBlackWhite(TIFF*, TIFFDirEntry*); 61 static int TIFFFetchSubjectDistance(TIFF*, TIFFDirEntry*); 57 62 static float TIFFFetchFloat(TIFF*, TIFFDirEntry*); 58 63 static int TIFFFetchFloatArray(TIFF*, TIFFDirEntry*, float*); … … 63 68 64 69 /* 65 * Read the next TIFF directory from a file 66 * and convert it to the internal format. 67 * We read directories sequentially. 70 * Read the next TIFF directory from a file and convert it to the internal 71 * format. We read directories sequentially. 68 72 */ 69 73 int … … 80 84 size_t fix; 81 85 uint16 dircount; 82 toff_t nextdiroff; 83 int diroutoforderwarning = 0; 84 toff_t* new_dirlist; 86 int diroutoforderwarning = 0, compressionknown = 0; 85 87 86 88 tif->tif_diroff = tif->tif_nextdiroff; 87 if (tif->tif_diroff == 0) /* no more directories */ 88 return (0); 89 90 /* 91 * XXX: Trick to prevent IFD looping. The one can create TIFF file 92 * with looped directory pointers. We will maintain a list of already 93 * seen directories and check every IFD offset against this list. 94 */ 95 for (n = 0; n < tif->tif_dirnumber; n++) { 96 if (tif->tif_dirlist[n] == tif->tif_diroff) 97 return (0); 98 } 99 tif->tif_dirnumber++; 100 new_dirlist = (toff_t *)_TIFFrealloc(tif->tif_dirlist, 101 tif->tif_dirnumber * sizeof(toff_t)); 102 if (!new_dirlist) { 103 TIFFErrorExt(tif->tif_clientdata, module, 104 "%s: Failed to allocate space for IFD list", 105 tif->tif_name); 106 return (0); 107 } 108 tif->tif_dirlist = new_dirlist; 109 tif->tif_dirlist[tif->tif_dirnumber - 1] = tif->tif_diroff; 110 89 /* 90 * Check whether we have the last offset or bad offset (IFD looping). 91 */ 92 if (!TIFFCheckDirOffset(tif, tif->tif_nextdiroff)) 93 return 0; 111 94 /* 112 95 * Cleanup any previous compression state. … … 114 97 (*tif->tif_cleanup)(tif); 115 98 tif->tif_curdir++; 116 nextdiroff = 0; 117 if (!isMapped(tif)) { 118 if (!SeekOK(tif, tif->tif_diroff)) { 119 TIFFErrorExt(tif->tif_clientdata, module, 120 "%s: Seek error accessing TIFF directory", 121 tif->tif_name); 122 return (0); 123 } 124 if (!ReadOK(tif, &dircount, sizeof (uint16))) { 125 TIFFErrorExt(tif->tif_clientdata, module, 126 "%s: Can not read TIFF directory count", 127 tif->tif_name); 128 return (0); 129 } 130 if (tif->tif_flags & TIFF_SWAB) 131 TIFFSwabShort(&dircount); 132 dir = (TIFFDirEntry *)_TIFFCheckMalloc(tif, dircount, 133 sizeof (TIFFDirEntry), 134 "to read TIFF directory"); 135 if (dir == NULL) 136 return (0); 137 if (!ReadOK(tif, dir, dircount*sizeof (TIFFDirEntry))) { 138 TIFFErrorExt(tif->tif_clientdata, module, 139 "%.100s: Can not read TIFF directory", 140 tif->tif_name); 141 goto bad; 142 } 143 /* 144 * Read offset to next directory for sequential scans. 145 */ 146 (void) ReadOK(tif, &nextdiroff, sizeof (uint32)); 147 } else { 148 toff_t off = tif->tif_diroff; 149 150 if (off + sizeof (uint16) > tif->tif_size) { 151 TIFFErrorExt(tif->tif_clientdata, module, 152 "%s: Can not read TIFF directory count", 153 tif->tif_name); 154 return (0); 155 } else 156 _TIFFmemcpy(&dircount, tif->tif_base + off, sizeof (uint16)); 157 off += sizeof (uint16); 158 if (tif->tif_flags & TIFF_SWAB) 159 TIFFSwabShort(&dircount); 160 dir = (TIFFDirEntry *)_TIFFCheckMalloc(tif, dircount, 161 sizeof (TIFFDirEntry), 162 "to read TIFF directory"); 163 if (dir == NULL) 164 return (0); 165 if (off + dircount*sizeof (TIFFDirEntry) > tif->tif_size) { 166 TIFFErrorExt(tif->tif_clientdata, module, 167 "%s: Can not read TIFF directory", 168 tif->tif_name); 169 goto bad; 170 } else { 171 _TIFFmemcpy(dir, tif->tif_base + off, 172 dircount*sizeof (TIFFDirEntry)); 173 } 174 off += dircount* sizeof (TIFFDirEntry); 175 if (off + sizeof (uint32) <= tif->tif_size) 176 _TIFFmemcpy(&nextdiroff, tif->tif_base+off, sizeof (uint32)); 177 } 178 if (tif->tif_flags & TIFF_SWAB) 179 TIFFSwabLong(&nextdiroff); 180 tif->tif_nextdiroff = nextdiroff; 99 dircount = TIFFFetchDirectory(tif, tif->tif_nextdiroff, 100 &dir, &tif->tif_nextdiroff); 101 if (!dircount) { 102 TIFFErrorExt(tif->tif_clientdata, module, 103 "%s: Failed to read directory at offset %u", 104 tif->tif_name, tif->tif_nextdiroff); 105 return 0; 106 } 181 107 182 108 tif->tif_flags &= ~TIFF_BEENWRITING; /* reset before new dir */ … … 217 143 * It sure would have been nice if Aldus had really thought 218 144 * this stuff through carefully. 219 */ 145 */ 220 146 for (dp = dir, n = dircount; n > 0; n--, dp++) { 221 147 if (tif->tif_flags & TIFF_SWAB) { … … 237 163 if (fix >= tif->tif_nfields || dp->tdir_tag == IGNORE) 238 164 continue; 239 165 240 166 /* 241 167 * Silicon Beach (at least) writes unordered … … 247 173 TIFFWarningExt(tif->tif_clientdata, module, 248 174 "%s: invalid TIFF directory; tags are not sorted in ascending order", 249 175 tif->tif_name); 250 176 diroutoforderwarning = 1; 251 177 } … … 253 179 } 254 180 while (fix < tif->tif_nfields && 255 181 tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag) 256 182 fix++; 257 183 if (fix >= tif->tif_nfields || … … 263 189 tif->tif_name, 264 190 dp->tdir_tag, 265 dp->tdir_tag, 266 dp->tdir_type); 267 268 TIFFMergeFieldInfo(tif, 269 _TIFFCreateAnonFieldInfo(tif, 191 dp->tdir_tag); 192 193 if (!_TIFFMergeFieldInfo(tif, 194 _TIFFCreateAnonFieldInfo(tif, 270 195 dp->tdir_tag, 271 196 (TIFFDataType) dp->tdir_type), 272 1 ); 273 fix = 0; 274 while (fix < tif->tif_nfields && 275 tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag) 276 fix++; 197 1)) 198 { 199 TIFFWarningExt(tif->tif_clientdata, 200 module, 201 "Registering anonymous field with tag %d (0x%x) failed", 202 dp->tdir_tag, 203 dp->tdir_tag); 204 goto ignore; 205 } 206 fix = 0; 207 while (fix < tif->tif_nfields && 208 tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag) 209 fix++; 277 210 } 278 211 /* … … 289 222 fip = tif->tif_fieldinfo[fix]; 290 223 while (dp->tdir_type != (unsigned short) fip->field_type 291 224 && fix < tif->tif_nfields) { 292 225 if (fip->field_type == TIFF_ANY) /* wildcard */ 293 226 break; 294 227 fip = tif->tif_fieldinfo[++fix]; 295 228 if (fix >= tif->tif_nfields || 296 229 fip->field_tag != dp->tdir_tag) { … … 327 260 if (!TIFFSetField(tif, dp->tdir_tag, (uint16)v)) 328 261 goto bad; 262 else 263 compressionknown = 1; 329 264 break; 330 265 /* XXX: workaround for broken TIFFs */ … … 363 298 364 299 /* 300 * XXX: OJPEG hack. 301 * If a) compression is OJPEG, b) planarconfig tag says it's separate, 302 * c) strip offsets/bytecounts tag are both present and 303 * d) both contain exactly one value, then we consistently find 304 * that the buggy implementation of the buggy compression scheme 305 * matches contig planarconfig best. So we 'fix-up' the tag here 306 */ 307 if ((td->td_compression==COMPRESSION_OJPEG) && 308 (td->td_planarconfig==PLANARCONFIG_SEPARATE)) { 309 dp = TIFFReadDirectoryFind(dir,dircount,TIFFTAG_STRIPOFFSETS); 310 if ((dp!=0) && (dp->tdir_count==1)) { 311 dp = TIFFReadDirectoryFind(dir, dircount, 312 TIFFTAG_STRIPBYTECOUNTS); 313 if ((dp!=0) && (dp->tdir_count==1)) { 314 td->td_planarconfig=PLANARCONFIG_CONTIG; 315 TIFFWarningExt(tif->tif_clientdata, 316 "TIFFReadDirectory", 317 "Planarconfig tag value assumed incorrect, " 318 "assuming data is contig instead of chunky"); 319 } 320 } 321 } 322 323 /* 365 324 * Allocate directory structure and setup defaults. 366 325 */ … … 370 329 } 371 330 /* 372 331 * Setup appropriate structures (by strip or by tile) 373 332 */ 374 333 if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) { … … 392 351 td->td_stripsperimage /= td->td_samplesperpixel; 393 352 if (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) { 394 MissingRequired(tif, 353 if ((td->td_compression==COMPRESSION_OJPEG) && 354 (isTiled(tif)==0) && 355 (td->td_nstrips==1)) { 356 /* 357 * XXX: OJPEG hack. 358 * If a) compression is OJPEG, b) it's not a tiled TIFF, 359 * and c) the number of strips is 1, 360 * then we tolerate the absence of stripoffsets tag, 361 * because, presumably, all required data is in the 362 * JpegInterchangeFormat stream. 363 */ 364 TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); 365 } else { 366 MissingRequired(tif, 395 367 isTiled(tif) ? "TileOffsets" : "StripOffsets"); 396 goto bad; 368 goto bad; 369 } 397 370 } 398 371 … … 415 388 * accept the tag if one value is supplied. 416 389 * 417 418 419 420 421 390 * The MinSampleValue, MaxSampleValue, BitsPerSample 391 * DataType and SampleFormat tags are supposed to be 392 * written as one value/sample, but some vendors 393 * incorrectly write one value only -- so we accept 394 * that as well (yech). Other vendors write correct 422 395 * value for NumberOfSamples, but incorrect one for 423 396 * BitsPerSample and friends, and we will read this … … 530 503 } 531 504 /* 505 * OJPEG hack: 506 * - If a) compression is OJPEG, and b) photometric tag is missing, 507 * then we consistently find that photometric should be YCbCr 508 * - If a) compression is OJPEG, and b) photometric tag says it's RGB, 509 * then we consistently find that the buggy implementation of the 510 * buggy compression scheme matches photometric YCbCr instead. 511 * - If a) compression is OJPEG, and b) bitspersample tag is missing, 512 * then we consistently find bitspersample should be 8. 513 * - If a) compression is OJPEG, b) samplesperpixel tag is missing, 514 * and c) photometric is RGB or YCbCr, then we consistently find 515 * samplesperpixel should be 3 516 * - If a) compression is OJPEG, b) samplesperpixel tag is missing, 517 * and c) photometric is MINISWHITE or MINISBLACK, then we consistently 518 * find samplesperpixel should be 3 519 */ 520 if (td->td_compression==COMPRESSION_OJPEG) 521 { 522 if (!TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) 523 { 524 TIFFWarningExt(tif->tif_clientdata, "TIFFReadDirectory", 525 "Photometric tag is missing, assuming data is YCbCr"); 526 if (!TIFFSetField(tif,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_YCBCR)) 527 goto bad; 528 } 529 else if (td->td_photometric==PHOTOMETRIC_RGB) 530 { 531 td->td_photometric=PHOTOMETRIC_YCBCR; 532 TIFFWarningExt(tif->tif_clientdata, "TIFFReadDirectory", 533 "Photometric tag value assumed incorrect, " 534 "assuming data is YCbCr instead of RGB"); 535 } 536 if (!TIFFFieldSet(tif,FIELD_BITSPERSAMPLE)) 537 { 538 TIFFWarningExt(tif->tif_clientdata,"TIFFReadDirectory", 539 "BitsPerSample tag is missing, assuming 8 bits per sample"); 540 if (!TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE,8)) 541 goto bad; 542 } 543 if (!TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL)) 544 { 545 if ((td->td_photometric==PHOTOMETRIC_RGB) 546 || (td->td_photometric==PHOTOMETRIC_YCBCR)) 547 { 548 TIFFWarningExt(tif->tif_clientdata, 549 "TIFFReadDirectory", 550 "SamplesPerPixel tag is missing, " 551 "assuming correct SamplesPerPixel value is 3"); 552 if (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,3)) 553 goto bad; 554 } 555 else if ((td->td_photometric==PHOTOMETRIC_MINISWHITE) 556 || (td->td_photometric==PHOTOMETRIC_MINISBLACK)) 557 { 558 TIFFWarningExt(tif->tif_clientdata, 559 "TIFFReadDirectory", 560 "SamplesPerPixel tag is missing, " 561 "assuming correct SamplesPerPixel value is 1"); 562 if (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,1)) 563 goto bad; 564 } 565 } 566 } 567 /* 532 568 * Verify Palette image has a Colormap. 533 569 */ … … 538 574 } 539 575 /* 540 * Attempt to deal with a missing StripByteCounts tag. 541 */ 542 if (!TIFFFieldSet(tif, FIELD_STRIPBYTECOUNTS)) { 576 * OJPEG hack: 577 * We do no further messing with strip/tile offsets/bytecounts in OJPEG 578 * TIFFs 579 */ 580 if (td->td_compression!=COMPRESSION_OJPEG) 581 { 543 582 /* 544 * Some manufacturers violate the spec by not giving 545 * the size of the strips. In this case, assume there 546 * is one uncompressed strip of data. 583 * Attempt to deal with a missing StripByteCounts tag. 547 584 */ 548 if ((td->td_planarconfig == PLANARCONFIG_CONTIG && 549 td->td_nstrips > 1) || 550 (td->td_planarconfig == PLANARCONFIG_SEPARATE && 551 td->td_nstrips != td->td_samplesperpixel)) { 552 MissingRequired(tif, "StripByteCounts"); 553 goto bad; 554 } 555 TIFFWarningExt(tif->tif_clientdata, module, 556 "%s: TIFF directory is missing required " 557 "\"%s\" field, calculating from imagelength", 558 tif->tif_name, 559 _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name); 560 if (EstimateStripByteCounts(tif, dir, dircount) < 0) 561 goto bad; 562 /* 563 * Assume we have wrong StripByteCount value (in case of single strip) in 564 * following cases: 565 * - it is equal to zero along with StripOffset; 566 * - it is larger than file itself (in case of uncompressed image); 567 * - it is smaller than the size of the bytes per row multiplied on the 568 * number of rows. The last case should not be checked in the case of 569 * writing new image, because we may do not know the exact strip size 570 * until the whole image will be written and directory dumped out. 571 */ 572 #define BYTECOUNTLOOKSBAD \ 573 ( (td->td_stripbytecount[0] == 0 && td->td_stripoffset[0] != 0) || \ 574 (td->td_compression == COMPRESSION_NONE && \ 575 td->td_stripbytecount[0] > TIFFGetFileSize(tif) - td->td_stripoffset[0]) || \ 576 (tif->tif_mode == O_RDONLY && \ 577 td->td_compression == COMPRESSION_NONE && \ 578 td->td_stripbytecount[0] < TIFFScanlineSize(tif) * td->td_imagelength) ) 579 580 } else if (td->td_nstrips == 1 581 && td->td_stripoffset[0] != 0 582 && BYTECOUNTLOOKSBAD) { 585 if (!TIFFFieldSet(tif, FIELD_STRIPBYTECOUNTS)) { 586 /* 587 * Some manufacturers violate the spec by not giving 588 * the size of the strips. In this case, assume there 589 * is one uncompressed strip of data. 590 */ 591 if ((td->td_planarconfig == PLANARCONFIG_CONTIG && 592 td->td_nstrips > 1) || 593 (td->td_planarconfig == PLANARCONFIG_SEPARATE && 594 td->td_nstrips != td->td_samplesperpixel)) { 595 MissingRequired(tif, "StripByteCounts"); 596 goto bad; 597 } 598 TIFFWarningExt(tif->tif_clientdata, module, 599 "%s: TIFF directory is missing required " 600 "\"%s\" field, calculating from imagelength", 601 tif->tif_name, 602 _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name); 603 if (EstimateStripByteCounts(tif, dir, dircount) < 0) 604 goto bad; 583 605 /* 584 * XXX: Plexus (and others) sometimes give a value of zero for 585 * a tag when they don't know what the correct value is! Try 586 * and handle the simple case of estimating the size of a one 587 * strip image. 606 * Assume we have wrong StripByteCount value (in case 607 * of single strip) in following cases: 608 * - it is equal to zero along with StripOffset; 609 * - it is larger than file itself (in case of uncompressed 610 * image); 611 * - it is smaller than the size of the bytes per row 612 * multiplied on the number of rows. The last case should 613 * not be checked in the case of writing new image, 614 * because we may do not know the exact strip size 615 * until the whole image will be written and directory 616 * dumped out. 588 617 */ 589 TIFFWarningExt(tif->tif_clientdata, module, 618 #define BYTECOUNTLOOKSBAD \ 619 ( (td->td_stripbytecount[0] == 0 && td->td_stripoffset[0] != 0) || \ 620 (td->td_compression == COMPRESSION_NONE && \ 621 td->td_stripbytecount[0] > TIFFGetFileSize(tif) - td->td_stripoffset[0]) || \ 622 (tif->tif_mode == O_RDONLY && \ 623 td->td_compression == COMPRESSION_NONE && \ 624 td->td_stripbytecount[0] < TIFFScanlineSize(tif) * td->td_imagelength) ) 625 626 } else if (td->td_nstrips == 1 627 && td->td_stripoffset[0] != 0 628 && BYTECOUNTLOOKSBAD) { 629 /* 630 * XXX: Plexus (and others) sometimes give a value of 631 * zero for a tag when they don't know what the 632 * correct value is! Try and handle the simple case 633 * of estimating the size of a one strip image. 634 */ 635 TIFFWarningExt(tif->tif_clientdata, module, 590 636 "%s: Bogus \"%s\" field, ignoring and calculating from imagelength", 591 tif->tif_name, 592 _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name); 593 if(EstimateStripByteCounts(tif, dir, dircount) < 0) 594 goto bad; 595 } else if (td->td_planarconfig == PLANARCONFIG_CONTIG 596 && td->td_nstrips > 2 597 && td->td_compression == COMPRESSION_NONE 598 && td->td_stripbytecount[0] != td->td_stripbytecount[1]) { 599 /* 600 * XXX: Some vendors fill StripByteCount array with absolutely 601 * wrong values (it can be equal to StripOffset array, for 602 * example). Catch this case here. 603 */ 604 TIFFWarningExt(tif->tif_clientdata, module, 637 tif->tif_name, 638 _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name); 639 if(EstimateStripByteCounts(tif, dir, dircount) < 0) 640 goto bad; 641 } else if (td->td_planarconfig == PLANARCONFIG_CONTIG 642 && td->td_nstrips > 2 643 && td->td_compression == COMPRESSION_NONE 644 && td->td_stripbytecount[0] != td->td_stripbytecount[1] 645 && td->td_stripbytecount[0] != 0 646 && td->td_stripbytecount[1] != 0 ) { 647 /* 648 * XXX: Some vendors fill StripByteCount array with 649 * absolutely wrong values (it can be equal to 650 * StripOffset array, for example). Catch this case 651 * here. 652 */ 653 TIFFWarningExt(tif->tif_clientdata, module, 605 654 "%s: Wrong \"%s\" field, ignoring and calculating from imagelength", 606 tif->tif_name, 607 _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name); 608 if (EstimateStripByteCounts(tif, dir, dircount) < 0) 609 goto bad; 655 tif->tif_name, 656 _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name); 657 if (EstimateStripByteCounts(tif, dir, dircount) < 0) 658 goto bad; 659 } 610 660 } 611 661 if (dir) { … … 639 689 if (!TIFFFieldSet(tif, FIELD_COMPRESSION)) 640 690 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE); 641 642 691 /* 692 * Some manufacturers make life difficult by writing 643 693 * large amounts of uncompressed data as a single strip. 644 694 * This is contrary to the recommendations of the spec. 645 695 * The following makes an attempt at breaking such images 646 696 * into strips closer to the recommended 8k bytes. A 647 697 * side effect, however, is that the RowsPerStrip tag 648 698 * value may be changed. 649 699 */ 650 700 if (td->td_nstrips == 1 && td->td_compression == COMPRESSION_NONE && 651 701 (tif->tif_flags & (TIFF_STRIPCHOP|TIFF_ISTILED)) == TIFF_STRIPCHOP) … … 663 713 tif->tif_scanlinesize = TIFFScanlineSize(tif); 664 714 if (!tif->tif_scanlinesize) { 665 TIFFErrorExt(tif->tif_clientdata, module, "%s: cannot handle zero scanline size", 666 tif->tif_name); 715 TIFFErrorExt(tif->tif_clientdata, module, 716 "%s: cannot handle zero scanline size", 717 tif->tif_name); 667 718 return (0); 668 719 } … … 671 722 tif->tif_tilesize = TIFFTileSize(tif); 672 723 if (!tif->tif_tilesize) { 673 TIFFErrorExt(tif->tif_clientdata, module, "%s: cannot handle zero tile size", 674 tif->tif_name); 724 TIFFErrorExt(tif->tif_clientdata, module, 725 "%s: cannot handle zero tile size", 726 tif->tif_name); 675 727 return (0); 676 728 } 677 729 } else { 678 730 if (!TIFFStripSize(tif)) { 679 TIFFErrorExt(tif->tif_clientdata, module, "%s: cannot handle zero strip size", 680 tif->tif_name); 731 TIFFErrorExt(tif->tif_clientdata, module, 732 "%s: cannot handle zero strip size", 733 tif->tif_name); 681 734 return (0); 682 735 } … … 689 742 } 690 743 691 /* 744 static TIFFDirEntry* 745 TIFFReadDirectoryFind(TIFFDirEntry* dir, uint16 dircount, uint16 tagid) 746 { 747 TIFFDirEntry* m; 748 uint16 n; 749 for (m=dir, n=0; n<dircount; m++, n++) 750 { 751 if (m->tdir_tag==tagid) 752 return(m); 753 } 754 return(0); 755 } 756 757 /* 692 758 * Read custom directory from the arbitarry offset. 693 759 * The code is very similar to TIFFReadDirectory(). … … 707 773 _TIFFSetupFieldInfo(tif, info, n); 708 774 709 tif->tif_diroff = diroff; 710 711 if (!isMapped(tif)) { 712 if (!SeekOK(tif, diroff)) { 713 TIFFErrorExt(tif->tif_clientdata, module, 714 "%s: Seek error accessing TIFF directory", 715 tif->tif_name); 716 return (0); 717 } 718 if (!ReadOK(tif, &dircount, sizeof (uint16))) { 719 TIFFErrorExt(tif->tif_clientdata, module, 720 "%s: Can not read TIFF directory count", 721 tif->tif_name); 722 return (0); 723 } 724 if (tif->tif_flags & TIFF_SWAB) 725 TIFFSwabShort(&dircount); 726 dir = (TIFFDirEntry *)_TIFFCheckMalloc(tif, dircount, 727 sizeof (TIFFDirEntry), 728 "to read TIFF custom directory"); 729 if (dir == NULL) 730 return (0); 731 if (!ReadOK(tif, dir, dircount * sizeof (TIFFDirEntry))) { 732 TIFFErrorExt(tif->tif_clientdata, module, 733 "%.100s: Can not read TIFF directory", 734 tif->tif_name); 735 goto bad; 736 } 737 } else { 738 toff_t off = diroff; 739 740 if (off + sizeof (uint16) > tif->tif_size) { 741 TIFFErrorExt(tif->tif_clientdata, module, 742 "%s: Can not read TIFF directory count", 743 tif->tif_name); 744 return (0); 745 } else 746 _TIFFmemcpy(&dircount, tif->tif_base + off, sizeof (uint16)); 747 off += sizeof (uint16); 748 if (tif->tif_flags & TIFF_SWAB) 749 TIFFSwabShort(&dircount); 750 dir = (TIFFDirEntry *)_TIFFCheckMalloc(tif, dircount, 751 sizeof (TIFFDirEntry), 752 "to read TIFF custom directory"); 753 if (dir == NULL) 754 return (0); 755 if (off + dircount * sizeof (TIFFDirEntry) > tif->tif_size) { 756 TIFFErrorExt(tif->tif_clientdata, module, 757 "%s: Can not read TIFF directory", 758 tif->tif_name); 759 goto bad; 760 } else { 761 _TIFFmemcpy(dir, tif->tif_base + off, 762 dircount * sizeof (TIFFDirEntry)); 763 } 775 dircount = TIFFFetchDirectory(tif, diroff, &dir, NULL); 776 if (!dircount) { 777 TIFFErrorExt(tif->tif_clientdata, module, 778 "%s: Failed to read custom directory at offset %u", 779 tif->tif_name, diroff); 780 return 0; 764 781 } 765 782 766 783 TIFFFreeDirectory(tif); 784 _TIFFmemset(&tif->tif_dir, 0, sizeof(TIFFDirectory)); 767 785 768 786 fix = 0; … … 785 803 TIFFWarningExt(tif->tif_clientdata, module, 786 804 "%s: unknown field with tag %d (0x%x) encountered", 787 tif->tif_name, dp->tdir_tag, dp->tdir_tag, 788 dp->tdir_type); 789 790 TIFFMergeFieldInfo(tif, 791 _TIFFCreateAnonFieldInfo(tif, 792 dp->tdir_tag, 793 (TIFFDataType)dp->tdir_type), 794 1); 805 tif->tif_name, dp->tdir_tag, dp->tdir_tag); 806 if (!_TIFFMergeFieldInfo(tif, 807 _TIFFCreateAnonFieldInfo(tif, 808 dp->tdir_tag, 809 (TIFFDataType) dp->tdir_type), 810 1)) 811 { 812 TIFFWarningExt(tif->tif_clientdata, module, 813 "Registering anonymous field with tag %d (0x%x) failed", 814 dp->tdir_tag, dp->tdir_tag); 815 goto ignore; 816 } 795 817 796 818 fix = 0; … … 837 859 } 838 860 839 (void) TIFFFetchNormalTag(tif, dp); 861 /* 862 * EXIF tags which need to be specifically processed. 863 */ 864 switch (dp->tdir_tag) { 865 case EXIFTAG_SUBJECTDISTANCE: 866 (void) TIFFFetchSubjectDistance(tif, dp); 867 break; 868 default: 869 (void) TIFFFetchNormalTag(tif, dp); 870 break; 871 } 840 872 } 841 873 … … 843 875 _TIFFfree(dir); 844 876 return 1; 845 846 bad:847 if (dir)848 _TIFFfree(dir);849 return 0;850 877 } 851 878 … … 869 896 static const char module[] = "EstimateStripByteCounts"; 870 897 871 registerTIFFDirEntry *dp;872 registerTIFFDirectory *td = &tif->tif_dir;873 uint 16 i;898 TIFFDirEntry *dp; 899 TIFFDirectory *td = &tif->tif_dir; 900 uint32 strip; 874 901 875 902 if (td->td_stripbytecount) … … 878 905 _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint32), 879 906 "for \"StripByteCounts\" array"); 907 if( td->td_stripbytecount == NULL ) 908 return -1; 909 880 910 if (td->td_compression != COMPRESSION_NONE) { 881 911 uint32 space = (uint32)(sizeof (TIFFHeader) … … 903 933 if (td->td_planarconfig == PLANARCONFIG_SEPARATE) 904 934 space /= td->td_samplesperpixel; 905 for ( i = 0; i < td->td_nstrips; i++)906 td->td_stripbytecount[ i] = space;935 for (strip = 0; strip < td->td_nstrips; strip++) 936 td->td_stripbytecount[strip] = space; 907 937 /* 908 938 * This gross hack handles the case were the offset to … … 912 942 * of data in the strip and trim this number back accordingly. 913 943 */ 914 i--; 915 if (((toff_t)(td->td_stripoffset[i]+td->td_stripbytecount[i])) 916 > filesize) 917 td->td_stripbytecount[i] = 918 filesize - td->td_stripoffset[i]; 944 strip--; 945 if (((toff_t)(td->td_stripoffset[strip]+ 946 td->td_stripbytecount[strip])) > filesize) 947 td->td_stripbytecount[strip] = 948 filesize - td->td_stripoffset[strip]; 949 } else if (isTiled(tif)) { 950 uint32 bytespertile = TIFFTileSize(tif); 951 952 for (strip = 0; strip < td->td_nstrips; strip++) 953 td->td_stripbytecount[strip] = bytespertile; 919 954 } else { 920 955 uint32 rowbytes = TIFFScanlineSize(tif); 921 956 uint32 rowsperstrip = td->td_imagelength/td->td_stripsperimage; 922 for ( i = 0; i < td->td_nstrips; i++)923 td->td_stripbytecount[ i] = rowbytes*rowsperstrip;957 for (strip = 0; strip < td->td_nstrips; strip++) 958 td->td_stripbytecount[strip] = rowbytes * rowsperstrip; 924 959 } 925 960 TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS); … … 940 975 941 976 /* 942 * Check the count field of a directory 943 * entry against a known value. The caller 944 * is expected to skip/ignore the tag if 945 * there is a mismatch. 977 * Check the directory offset against the list of already seen directory 978 * offsets. This is a trick to prevent IFD looping. The one can create TIFF 979 * file with looped directory pointers. We will maintain a list of already 980 * seen directories and check every IFD offset against that list. 981 */ 982 static int 983 TIFFCheckDirOffset(TIFF* tif, toff_t diroff) 984 { 985 uint16 n; 986 987 if (diroff == 0) /* no more directories */ 988 return 0; 989 990 for (n = 0; n < tif->tif_dirnumber && tif->tif_dirlist; n++) { 991 if (tif->tif_dirlist[n] == diroff) 992 return 0; 993 } 994 995 tif->tif_dirnumber++; 996 997 if (tif->tif_dirnumber > tif->tif_dirlistsize) { 998 toff_t* new_dirlist; 999 1000 /* 1001 * XXX: Reduce memory allocation granularity of the dirlist 1002 * array. 1003 */ 1004 new_dirlist = (toff_t *)_TIFFCheckRealloc(tif, 1005 tif->tif_dirlist, 1006 tif->tif_dirnumber, 1007 2 * sizeof(toff_t), 1008 "for IFD list"); 1009 if (!new_dirlist) 1010 return 0; 1011 tif->tif_dirlistsize = 2 * tif->tif_dirnumber; 1012 tif->tif_dirlist = new_dirlist; 1013 } 1014 1015 tif->tif_dirlist[tif->tif_dirnumber - 1] = diroff; 1016 1017 return 1; 1018 } 1019 1020 /* 1021 * Check the count field of a directory entry against a known value. The 1022 * caller is expected to skip/ignore the tag if there is a mismatch. 946 1023 */ 947 1024 static int … … 950 1027 if (count > dir->tdir_count) { 951 1028 TIFFWarningExt(tif->tif_clientdata, tif->tif_name, 952 "incorrect count for field \"%s\" (% lu, expecting %lu); tag ignored",1029 "incorrect count for field \"%s\" (%u, expecting %u); tag ignored", 953 1030 _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name, 954 1031 dir->tdir_count, count); … … 956 1033 } else if (count < dir->tdir_count) { 957 1034 TIFFWarningExt(tif->tif_clientdata, tif->tif_name, 958 "incorrect count for field \"%s\" (% lu, expecting %lu); tag trimmed",1035 "incorrect count for field \"%s\" (%u, expecting %u); tag trimmed", 959 1036 _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name, 960 1037 dir->tdir_count, count); … … 965 1042 966 1043 /* 1044 * Read IFD structure from the specified offset. If the pointer to 1045 * nextdiroff variable has been specified, read it too. Function returns a 1046 * number of fields in the directory or 0 if failed. 1047 */ 1048 static uint16 1049 TIFFFetchDirectory(TIFF* tif, toff_t diroff, TIFFDirEntry **pdir, 1050 toff_t *nextdiroff) 1051 { 1052 static const char module[] = "TIFFFetchDirectory"; 1053 1054 TIFFDirEntry *dir; 1055 uint16 dircount; 1056 1057 assert(pdir); 1058 1059 tif->tif_diroff = diroff; 1060 if (nextdiroff) 1061 *nextdiroff = 0; 1062 if (!isMapped(tif)) { 1063 if (!SeekOK(tif, tif->tif_diroff)) { 1064 TIFFErrorExt(tif->tif_clientdata, module, 1065 "%s: Seek error accessing TIFF directory", 1066 tif->tif_name); 1067 return 0; 1068 } 1069 if (!ReadOK(tif, &dircount, sizeof (uint16))) { 1070 TIFFErrorExt(tif->tif_clientdata, module, 1071 "%s: Can not read TIFF directory count", 1072 tif->tif_name); 1073 return 0; 1074 } 1075 if (tif->tif_flags & TIFF_SWAB) 1076 TIFFSwabShort(&dircount); 1077 dir = (TIFFDirEntry *)_TIFFCheckMalloc(tif, dircount, 1078 sizeof (TIFFDirEntry), 1079 "to read TIFF directory"); 1080 if (dir == NULL) 1081 return 0; 1082 if (!ReadOK(tif, dir, dircount*sizeof (TIFFDirEntry))) { 1083 TIFFErrorExt(tif->tif_clientdata, module, 1084 "%.100s: Can not read TIFF directory", 1085 tif->tif_name); 1086 _TIFFfree(dir); 1087 return 0; 1088 } 1089 /* 1090 * Read offset to next directory for sequential scans if 1091 * needed. 1092 */ 1093 if (nextdiroff) 1094 (void) ReadOK(tif, nextdiroff, sizeof(uint32)); 1095 } else { 1096 toff_t off = tif->tif_diroff; 1097 1098 /* 1099 * Check for integer overflow when validating the dir_off, 1100 * otherwise a very high offset may cause an OOB read and 1101 * crash the client. Make two comparisons instead of 1102 * 1103 * off + sizeof(uint16) > tif->tif_size 1104 * 1105 * to avoid overflow. 1106 */ 1107 if (tif->tif_size < sizeof (uint16) || 1108 off > tif->tif_size - sizeof(uint16)) { 1109 TIFFErrorExt(tif->tif_clientdata, module, 1110 "%s: Can not read TIFF directory count", 1111 tif->tif_name); 1112 return 0; 1113 } else { 1114 _TIFFmemcpy(&dircount, tif->tif_base + off, 1115 sizeof(uint16)); 1116 } 1117 off += sizeof (uint16); 1118 if (tif->tif_flags & TIFF_SWAB) 1119 TIFFSwabShort(&dircount); 1120 dir = (TIFFDirEntry *)_TIFFCheckMalloc(tif, dircount, 1121 sizeof(TIFFDirEntry), 1122 "to read TIFF directory"); 1123 if (dir == NULL) 1124 return 0; 1125 if (off + dircount * sizeof (TIFFDirEntry) > tif->tif_size) { 1126 TIFFErrorExt(tif->tif_clientdata, module, 1127 "%s: Can not read TIFF directory", 1128 tif->tif_name); 1129 _TIFFfree(dir); 1130 return 0; 1131 } else { 1132 _TIFFmemcpy(dir, tif->tif_base + off, 1133 dircount * sizeof(TIFFDirEntry)); 1134 } 1135 if (nextdiroff) { 1136 off += dircount * sizeof (TIFFDirEntry); 1137 if (off + sizeof (uint32) <= tif->tif_size) { 1138 _TIFFmemcpy(nextdiroff, tif->tif_base + off, 1139 sizeof (uint32)); 1140 } 1141 } 1142 } 1143 if (nextdiroff && tif->tif_flags & TIFF_SWAB) 1144 TIFFSwabLong(nextdiroff); 1145 *pdir = dir; 1146 return dircount; 1147 } 1148 1149 /* 967 1150 * Fetch a contiguous directory item. 968 1151 */ … … 970 1153 TIFFFetchData(TIFF* tif, TIFFDirEntry* dir, char* cp) 971 1154 { 972 int w = TIFFDataWidth((TIFFDataType) dir->tdir_type); 973 tsize_t cc = dir->tdir_count * w; 1155 uint32 w = TIFFDataWidth((TIFFDataType) dir->tdir_type); 1156 /* 1157 * FIXME: butecount should have tsize_t type, but for now libtiff 1158 * defines tsize_t as a signed 32-bit integer and we are losing 1159 * ability to read arrays larger than 2^31 bytes. So we are using 1160 * uint32 instead of tsize_t here. 1161 */ 1162 uint32 cc = dir->tdir_count * w; 974 1163 975 1164 /* Check for overflow. */ 976 if (!dir->tdir_count || !w || cc / w != (tsize_t)dir->tdir_count)1165 if (!dir->tdir_count || !w || cc / w != dir->tdir_count) 977 1166 goto bad; 978 1167 … … 984 1173 } else { 985 1174 /* Check for overflow. */ 986 if ( (tsize_t)dir->tdir_offset + cc < (tsize_t)dir->tdir_offset987 || (tsize_t)dir->tdir_offset + cc < cc988 || (tsize_t)dir->tdir_offset + cc > (tsize_t)tif->tif_size)1175 if (dir->tdir_offset + cc < dir->tdir_offset 1176 || dir->tdir_offset + cc < cc 1177 || dir->tdir_offset + cc > tif->tif_size) 989 1178 goto bad; 990 1179 _TIFFmemcpy(cp, tif->tif_base + dir->tdir_offset, cc); … … 1042 1231 if (denom == 0) { 1043 1232 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 1044 "%s: Rational with zero denominator (num = % lu)",1233 "%s: Rational with zero denominator (num = %u)", 1045 1234 _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name, num); 1046 1235 return (0); … … 1055 1244 1056 1245 /* 1057 * Fetch a rational item from the file 1058 * at offset off and return the value 1059 * as a floating point number. 1246 * Fetch a rational item from the file at offset off and return the value as a 1247 * floating point number. 1060 1248 */ 1061 1249 static float … … 1070 1258 1071 1259 /* 1072 * Fetch a single floating point value 1073 * from the offset field and return it 1074 * as a native float. 1260 * Fetch a single floating point value from the offset field and return it as 1261 * a native float. 1075 1262 */ 1076 1263 static float … … 1160 1347 TIFFFetchShortPair(TIFF* tif, TIFFDirEntry* dir) 1161 1348 { 1349 /* 1350 * Prevent overflowing the v stack arrays below by performing a sanity 1351 * check on tdir_count, this should never be greater than two. 1352 */ 1353 if (dir->tdir_count > 2) { 1354 TIFFWarningExt(tif->tif_clientdata, tif->tif_name, 1355 "unexpected count for field \"%s\", %u, expected 2; ignored", 1356 _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name, 1357 dir->tdir_count); 1358 return 0; 1359 } 1360 1162 1361 switch (dir->tdir_type) { 1163 1362 case TIFF_BYTE: … … 1228 1427 1229 1428 if (dir->tdir_count == 1) { 1230 v[0] = *(float*) &dir->tdir_offset; 1429 union 1430 { 1431 float f; 1432 uint32 i; 1433 } float_union; 1434 1435 float_union.i=dir->tdir_offset; 1436 v[0]=float_union.f; 1231 1437 TIFFCvtIEEEFloatToNative(tif, dir->tdir_count, v); 1232 1438 return (1); … … 1252 1458 1253 1459 /* 1254 * Fetch an array of ANY values. The actual values are 1255 * returned as doubles which should be able hold all the 1256 * types. Yes, there really should be an tany_t to avoid 1257 * this potential non-portability ... Note in particular 1258 * that we assume that the double return value vector is 1259 * large enough to read in any fundamental type. We use 1260 * that vector as a buffer to read in the base type vector 1261 * and then convert it in place to double (from end 1262 * to front of course). 1460 * Fetch an array of ANY values. The actual values are returned as doubles 1461 * which should be able hold all the types. Yes, there really should be an 1462 * tany_t to avoid this potential non-portability ... Note in particular that 1463 * we assume that the double return value vector is large enough to read in 1464 * any fundamental type. We use that vector as a buffer to read in the base 1465 * type vector and then convert it in place to double (from end to front of 1466 * course). 1263 1467 */ 1264 1468 static int … … 1511 1715 for (i = 1; i < check_count; i++) 1512 1716 if (v[i] != v[0]) { 1513 1514 1515 1516 1717 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 1718 "Cannot handle different per-sample values for field \"%s\"", 1719 _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name); 1720 goto bad; 1517 1721 } 1518 1722 *pl = v[0]; … … 1552 1756 for (i = 1; i < check_count; i++) 1553 1757 if (v[i] != v[0]) { 1554 1555 1556 1557 1758 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 1759 "Cannot handle different per-sample values for field \"%s\"", 1760 _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name); 1761 goto bad; 1558 1762 } 1559 1763 *pl = v[0]; … … 1592 1796 for (i = 1; i < check_count; i++) 1593 1797 if (v[i] != v[0]) { 1594 1595 1596 1597 1798 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 1799 "Cannot handle different per-sample values for field \"%s\"", 1800 _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name); 1801 goto bad; 1598 1802 } 1599 1803 *pl = v[0]; … … 1707 1911 1708 1912 /* 1709 * Replace a single strip (tile) of uncompressed data by 1710 * multiple strips (tiles), each approximately 8Kbytes. 1711 * This is useful for dealing with large images or 1712 * for dealing with machines with a limited amount 1713 * memory. 1913 * Fetch and set the SubjectDistance EXIF tag. 1914 */ 1915 static int 1916 TIFFFetchSubjectDistance(TIFF* tif, TIFFDirEntry* dir) 1917 { 1918 uint32 l[2]; 1919 float v; 1920 int ok = 0; 1921 1922 if (TIFFFetchData(tif, dir, (char *)l) 1923 && cvtRational(tif, dir, l[0], l[1], &v)) { 1924 /* 1925 * XXX: Numerator 0xFFFFFFFF means that we have infinite 1926 * distance. Indicate that with a negative floating point 1927 * SubjectDistance value. 1928 */ 1929 ok = TIFFSetField(tif, dir->tdir_tag, 1930 (l[0] != 0xFFFFFFFF) ? v : -v); 1931 } 1932 1933 return ok; 1934 } 1935 1936 /* 1937 * Replace a single strip (tile) of uncompressed data by multiple strips 1938 * (tiles), each approximately STRIP_SIZE_DEFAULT bytes. This is useful for 1939 * dealing with large images or for dealing with machines with a limited 1940 * amount memory. 1714 1941 */ 1715 1942 static void … … 1753 1980 if (newcounts == NULL || newoffsets == NULL) { 1754 1981 /* 1755 * Unable to allocate new strip information, give 1756 * up and usethe original one strip information.1982 * Unable to allocate new strip information, give up and use 1983 * the original one strip information. 1757 1984 */ 1758 1985 if (newcounts != NULL) … … 1767 1994 */ 1768 1995 for (strip = 0; strip < nstrips; strip++) { 1769 if ( stripbytes > (tsize_t)bytecount)1996 if ((uint32)stripbytes > bytecount) 1770 1997 stripbytes = bytecount; 1771 1998 newcounts[strip] = stripbytes; -
trunk/src/3rdparty/libtiff/libtiff/tif_dirwrite.c
r2 r846 1 /* $Id: tif_dirwrite.c,v 1.3 4 2006/02/23 16:07:45 dron Exp $ */1 /* $Id: tif_dirwrite.c,v 1.37.2.6 2009-10-31 21:51:08 bfriesen Exp $ */ 2 2 3 3 /* … … 101 101 if (done) 102 102 { 103 if (tif->tif_flags & TIFF_POSTENCODE) { 104 tif->tif_flags &= ~TIFF_POSTENCODE; 105 if (!(*tif->tif_postencode)(tif)) { 106 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 103 if (tif->tif_flags & TIFF_POSTENCODE) { 104 tif->tif_flags &= ~TIFF_POSTENCODE; 105 if (!(*tif->tif_postencode)(tif)) { 106 TIFFErrorExt(tif->tif_clientdata, 107 tif->tif_name, 107 108 "Error post-encoding before directory write"); 108 return (0); 109 } 110 } 111 (*tif->tif_close)(tif); /* shutdown encoder */ 112 /* 113 * Flush any data that might have been written 114 * by the compression close+cleanup routines. 115 */ 116 if (tif->tif_rawcc > 0 && !TIFFFlushData1(tif)) { 109 return (0); 110 } 111 } 112 (*tif->tif_close)(tif); /* shutdown encoder */ 113 /* 114 * Flush any data that might have been written 115 * by the compression close+cleanup routines. 116 */ 117 if (tif->tif_rawcc > 0 118 && (tif->tif_flags & TIFF_BEENWRITING) != 0 119 && !TIFFFlushData1(tif)) { 117 120 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 118 "Error flushing data before directory write");119 120 121 122 123 124 125 126 127 121 "Error flushing data before directory write"); 122 return (0); 123 } 124 if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) { 125 _TIFFfree(tif->tif_rawdata); 126 tif->tif_rawdata = NULL; 127 tif->tif_rawcc = 0; 128 tif->tif_rawdatasize = 0; 129 } 130 tif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP); 128 131 } 129 132 … … 138 141 if (TIFFFieldSet(tif, b) && b != FIELD_CUSTOM) 139 142 nfields += (b < FIELD_SUBFILETYPE ? 2 : 1); 140 143 nfields += td->td_customValueCount; 141 144 dirsize = nfields * sizeof (TIFFDirEntry); 142 145 data = (char*) _TIFFmalloc(dirsize); 143 146 if (data == NULL) { 144 147 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 145 "Cannot write directory, out of space");148 "Cannot write directory, out of space"); 146 149 return (0); 147 150 } … … 177 180 const TIFFFieldInfo* fip = tif->tif_fieldinfo[fi]; 178 181 179 180 ** For custom fields, we test to see if the custom field181 ** is set or not. For normal fields, we just use the182 ** FieldSet test. 183 184 185 186 187 188 189 190 191 192 193 182 /* 183 * For custom fields, we test to see if the custom field 184 * is set or not. For normal fields, we just use the 185 * FieldSet test. 186 */ 187 if( fip->field_bit == FIELD_CUSTOM ) 188 { 189 int ci, is_set = FALSE; 190 191 for( ci = 0; ci < td->td_customValueCount; ci++ ) 192 is_set |= (td->td_customValues[ci].info == fip); 193 194 if( !is_set ) 195 continue; 196 } 194 197 else if (!FieldSet(fields, fip->field_bit)) 195 continue; 196 197 198 /* 199 ** Handle other fields. 200 */ 198 continue; 199 200 /* 201 * Handle other fields. 202 */ 201 203 switch (fip->field_bit) 202 204 { 203 205 case FIELD_STRIPOFFSETS: 204 206 /* … … 235 237 dir->tdir_type = (uint16) TIFF_LONG; 236 238 dir->tdir_count = (uint32) td->td_nstrips; 237 if (!TIFFWriteLongArray(tif, dir, 238 td->td_stripbytecount)) 239 if (!TIFFWriteLongArray(tif, dir, td->td_stripbytecount)) 239 240 goto bad; 240 241 break; … … 347 348 dir++; 348 349 349 350 350 if( fip->field_bit != FIELD_CUSTOM ) 351 ResetFieldBit(fields, fip->field_bit); 351 352 } 352 353 … … 377 378 (void) TIFFSeekFile(tif, tif->tif_diroff, SEEK_SET); 378 379 if (!WriteOK(tif, &dircount, sizeof (dircount))) { 379 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "Error writing directory count"); 380 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 381 "Error writing directory count"); 380 382 goto bad; 381 383 } 382 384 if (!WriteOK(tif, data, dirsize)) { 383 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "Error writing directory contents"); 385 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 386 "Error writing directory contents"); 384 387 goto bad; 385 388 } 386 if (!WriteOK(tif, &diroff, sizeof (diroff))) { 387 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "Error writing directory link"); 389 if (!WriteOK(tif, &diroff, sizeof (uint32))) { 390 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 391 "Error writing directory link"); 388 392 goto bad; 389 393 } … … 429 433 (void) TIFFSetWriteOffset(tif, TIFFSeekFile(tif, 0, SEEK_END)); 430 434 return rc; 435 } 436 437 static int 438 _TIFFWriteCustomDirectory(TIFF* tif, toff_t *pdiroff) 439 { 440 uint16 dircount; 441 uint32 nfields; 442 tsize_t dirsize; 443 char* data; 444 TIFFDirEntry* dir; 445 TIFFDirectory* td; 446 unsigned long b, fields[FIELD_SETLONGS]; 447 int fi, nfi; 448 449 if (tif->tif_mode == O_RDONLY) 450 return (1); 451 452 td = &tif->tif_dir; 453 /* 454 * Size the directory so that we can calculate 455 * offsets for the data items that aren't kept 456 * in-place in each field. 457 */ 458 nfields = 0; 459 for (b = 0; b <= FIELD_LAST; b++) 460 if (TIFFFieldSet(tif, b) && b != FIELD_CUSTOM) 461 nfields += (b < FIELD_SUBFILETYPE ? 2 : 1); 462 nfields += td->td_customValueCount; 463 dirsize = nfields * sizeof (TIFFDirEntry); 464 data = (char*) _TIFFmalloc(dirsize); 465 if (data == NULL) { 466 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 467 "Cannot write directory, out of space"); 468 return (0); 469 } 470 /* 471 * Put the directory at the end of the file. 472 */ 473 tif->tif_diroff = (TIFFSeekFile(tif, (toff_t) 0, SEEK_END)+1) &~ 1; 474 tif->tif_dataoff = (toff_t)( 475 tif->tif_diroff + sizeof (uint16) + dirsize + sizeof (toff_t)); 476 if (tif->tif_dataoff & 1) 477 tif->tif_dataoff++; 478 (void) TIFFSeekFile(tif, tif->tif_dataoff, SEEK_SET); 479 dir = (TIFFDirEntry*) data; 480 /* 481 * Setup external form of directory 482 * entries and write data items. 483 */ 484 _TIFFmemcpy(fields, td->td_fieldsset, sizeof (fields)); 485 486 for (fi = 0, nfi = tif->tif_nfields; nfi > 0; nfi--, fi++) { 487 const TIFFFieldInfo* fip = tif->tif_fieldinfo[fi]; 488 489 /* 490 * For custom fields, we test to see if the custom field 491 * is set or not. For normal fields, we just use the 492 * FieldSet test. 493 */ 494 if( fip->field_bit == FIELD_CUSTOM ) 495 { 496 int ci, is_set = FALSE; 497 498 for( ci = 0; ci < td->td_customValueCount; ci++ ) 499 is_set |= (td->td_customValues[ci].info == fip); 500 501 if( !is_set ) 502 continue; 503 } 504 else if (!FieldSet(fields, fip->field_bit)) 505 continue; 506 507 if( fip->field_bit != FIELD_CUSTOM ) 508 ResetFieldBit(fields, fip->field_bit); 509 } 510 511 /* 512 * Write directory. 513 */ 514 dircount = (uint16) nfields; 515 *pdiroff = (uint32) tif->tif_nextdiroff; 516 if (tif->tif_flags & TIFF_SWAB) { 517 /* 518 * The file's byte order is opposite to the 519 * native machine architecture. We overwrite 520 * the directory information with impunity 521 * because it'll be released below after we 522 * write it to the file. Note that all the 523 * other tag construction routines assume that 524 * we do this byte-swapping; i.e. they only 525 * byte-swap indirect data. 526 */ 527 for (dir = (TIFFDirEntry*) data; dircount; dir++, dircount--) { 528 TIFFSwabArrayOfShort(&dir->tdir_tag, 2); 529 TIFFSwabArrayOfLong(&dir->tdir_count, 2); 530 } 531 dircount = (uint16) nfields; 532 TIFFSwabShort(&dircount); 533 TIFFSwabLong(pdiroff); 534 } 535 (void) TIFFSeekFile(tif, tif->tif_diroff, SEEK_SET); 536 if (!WriteOK(tif, &dircount, sizeof (dircount))) { 537 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 538 "Error writing directory count"); 539 goto bad; 540 } 541 if (!WriteOK(tif, data, dirsize)) { 542 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 543 "Error writing directory contents"); 544 goto bad; 545 } 546 if (!WriteOK(tif, pdiroff, sizeof (uint32))) { 547 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 548 "Error writing directory link"); 549 goto bad; 550 } 551 _TIFFfree(data); 552 return (1); 553 bad: 554 _TIFFfree(data); 555 return (0); 556 } 557 558 int 559 TIFFWriteCustomDirectory(TIFF* tif, toff_t *pdiroff) 560 { 561 return _TIFFWriteCustomDirectory(tif, pdiroff); 431 562 } 432 563 … … 582 713 char* cp; 583 714 if (fip->field_passcount) 584 TIFFGetField(tif, fip->field_tag, &wc, &cp); 715 { 716 if( wc == (uint16) TIFF_VARIABLE2 ) 717 TIFFGetField(tif, fip->field_tag, &wc2, &cp); 718 else 719 TIFFGetField(tif, fip->field_tag, &wc, &cp); 720 } 585 721 else 586 722 TIFFGetField(tif, fip->field_tag, &cp); … … 787 923 TIFFWriteByteArray(TIFF* tif, TIFFDirEntry* dir, char* cp) 788 924 { 789 if (dir->tdir_count > 4) { 790 if (!TIFFWriteData(tif, dir, cp)) 791 return (0); 925 if (dir->tdir_count <= 4) { 926 if (tif->tif_header.tiff_magic == TIFF_BIGENDIAN) { 927 dir->tdir_offset = (uint32)cp[0] << 24; 928 if (dir->tdir_count >= 2) 929 dir->tdir_offset |= (uint32)cp[1] << 16; 930 if (dir->tdir_count >= 3) 931 dir->tdir_offset |= (uint32)cp[2] << 8; 932 if (dir->tdir_count == 4) 933 dir->tdir_offset |= cp[3]; 934 } else { 935 dir->tdir_offset = cp[0]; 936 if (dir->tdir_count >= 2) 937 dir->tdir_offset |= (uint32) cp[1] << 8; 938 if (dir->tdir_count >= 3) 939 dir->tdir_offset |= (uint32) cp[2] << 16; 940 if (dir->tdir_count == 4) 941 dir->tdir_offset |= (uint32) cp[3] << 24; 942 } 943 return 1; 792 944 } else 793 _TIFFmemcpy(&dir->tdir_offset, cp, dir->tdir_count); 794 return (1); 945 return TIFFWriteData(tif, dir, cp); 795 946 } 796 947 … … 804 955 if (dir->tdir_count <= 2) { 805 956 if (tif->tif_header.tiff_magic == TIFF_BIGENDIAN) { 806 dir->tdir_offset = (uint32) ((long) v[0] << 16);957 dir->tdir_offset = (uint32) v[0] << 16; 807 958 if (dir->tdir_count == 2) 808 959 dir->tdir_offset |= v[1] & 0xffff; … … 810 961 dir->tdir_offset = v[0] & 0xffff; 811 962 if (dir->tdir_count == 2) 812 dir->tdir_offset |= ( long) v[1] << 16;963 dir->tdir_offset |= (uint32) v[1] << 16; 813 964 } 814 965 return (1); … … 855 1006 if (fv < 0) { 856 1007 if (dir->tdir_type == TIFF_RATIONAL) { 857 TIFFWarningExt(tif->tif_clientdata, tif->tif_name, 1008 TIFFWarningExt(tif->tif_clientdata, 1009 tif->tif_name, 858 1010 "\"%s\": Information lost writing value (%g) as (unsigned) RATIONAL", 859 1011 _TIFFFieldWithTag(tif,dir->tdir_tag)->field_name, 860 fv);1012 fv); 861 1013 fv = 0; 862 1014 } else … … 915 1067 if (w == NULL) { 916 1068 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 917 "No space to write array");1069 "No space to write array"); 918 1070 return (0); 919 1071 } … … 989 1141 break; 990 1142 case TIFF_DOUBLE: 991 return (TIFFWriteDoubleArray(tif, dir, v)); 1143 { 1144 if( !TIFFWriteDoubleArray(tif, dir, v)) 1145 goto out; 1146 } 1147 break; 992 1148 default: 993 1149 /* TIFF_NOTYPE */ … … 1074 1230 return (1); 1075 1231 } 1076 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "Error writing data for field \"%s\"", 1077 _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name); 1232 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 1233 "Error writing data for field \"%s\"", 1234 _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name); 1078 1235 return (0); 1079 1236 } … … 1111 1268 sizeof (tif->tif_diroff))) 1112 1269 { 1113 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "Error updating TIFF header"); 1270 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 1271 "Error updating TIFF header"); 1114 1272 return (0); 1115 1273 } … … 1125 1283 if (!SeekOK(tif, nextdir) || 1126 1284 !ReadOK(tif, &dircount, sizeof (dircount))) { 1127 TIFFErrorExt(tif->tif_clientdata, module, "Error fetching directory count"); 1285 TIFFErrorExt(tif->tif_clientdata, module, 1286 "Error fetching directory count"); 1128 1287 return (0); 1129 1288 } … … 1133 1292 dircount * sizeof (TIFFDirEntry), SEEK_CUR); 1134 1293 if (!ReadOK(tif, &nextdir, sizeof (nextdir))) { 1135 TIFFErrorExt(tif->tif_clientdata, module, "Error fetching directory link"); 1294 TIFFErrorExt(tif->tif_clientdata, module, 1295 "Error fetching directory link"); 1136 1296 return (0); 1137 1297 } … … 1143 1303 tif->tif_diroff = 0; 1144 1304 if (!WriteOK(tif, &(tif->tif_diroff), sizeof (nextdir))) { 1145 TIFFErrorExt(tif->tif_clientdata, module, "Error writing directory link"); 1305 TIFFErrorExt(tif->tif_clientdata, module, 1306 "Error writing directory link"); 1146 1307 return (0); 1147 1308 } … … 1157 1318 1158 1319 /* 1159 * Link the current directory into the 1160 * directory chain for the file. 1320 * Link the current directory into the directory chain for the file. 1161 1321 */ 1162 1322 static int … … 1179 1339 if (!WriteOK(tif, &diroff, sizeof (diroff))) { 1180 1340 TIFFErrorExt(tif->tif_clientdata, module, 1181 "%s: Error writing SubIFD directory link",1182 tif->tif_name);1341 "%s: Error writing SubIFD directory link", 1342 tif->tif_name); 1183 1343 return (0); 1184 1344 } … … 1204 1364 SEEK_SET); 1205 1365 if (!WriteOK(tif, &diroff, sizeof (diroff))) { 1206 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "Error writing TIFF header"); 1366 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 1367 "Error writing TIFF header"); 1207 1368 return (0); 1208 1369 } … … 1218 1379 if (!SeekOK(tif, nextdir) || 1219 1380 !ReadOK(tif, &dircount, sizeof (dircount))) { 1220 TIFFErrorExt(tif->tif_clientdata, module, "Error fetching directory count"); 1381 TIFFErrorExt(tif->tif_clientdata, module, 1382 "Error fetching directory count"); 1221 1383 return (0); 1222 1384 } … … 1226 1388 dircount * sizeof (TIFFDirEntry), SEEK_CUR); 1227 1389 if (!ReadOK(tif, &nextdir, sizeof (nextdir))) { 1228 TIFFErrorExt(tif->tif_clientdata, module, "Error fetching directory link"); 1390 TIFFErrorExt(tif->tif_clientdata, module, 1391 "Error fetching directory link"); 1229 1392 return (0); 1230 1393 } … … 1235 1398 (void) TIFFSeekFile(tif, off - (toff_t)sizeof(nextdir), SEEK_SET); 1236 1399 if (!WriteOK(tif, &diroff, sizeof (diroff))) { 1237 TIFFErrorExt(tif->tif_clientdata, module, "Error writing directory link"); 1400 TIFFErrorExt(tif->tif_clientdata, module, 1401 "Error writing directory link"); 1238 1402 return (0); 1239 1403 } -
trunk/src/3rdparty/libtiff/libtiff/tif_dumpmode.c
r2 r846 1 /* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dumpmode.c,v 1. 4 2005/12/21 12:23:13 jorisExp $ */1 /* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dumpmode.c,v 1.5.2.1 2009-01-01 00:10:43 bfriesen Exp $ */ 2 2 3 3 /* … … 46 46 n = tif->tif_rawdatasize - tif->tif_rawcc; 47 47 48 48 assert( n > 0 ); 49 49 50 50 /* … … 72 72 { 73 73 (void) s; 74 /* fprintf(stderr,"DumpModeDecode: scanline %ld, expected %ld bytes, got %ld bytes\n", */ 75 /* (long) tif->tif_row, (long) tif->tif_rawcc, (long) cc); */ 74 76 if (tif->tif_rawcc < cc) { 75 77 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, -
trunk/src/3rdparty/libtiff/libtiff/tif_fax3.c
r2 r846 1 /* $Id: tif_fax3.c,v 1.4 0 2006/03/16 12:38:24 dron Exp $ */1 /* $Id: tif_fax3.c,v 1.43.2.5 2009-01-01 00:10:43 bfriesen Exp $ */ 2 2 3 3 /* … … 64 64 TIFFVGetMethod vgetparent; /* super-class method */ 65 65 TIFFVSetMethod vsetparent; /* super-class method */ 66 TIFFPrintMethod printdir; /* super-class method */ 66 67 } Fax3BaseState; 67 68 #define Fax3State(tif) ((Fax3BaseState*) (tif)->tif_data) … … 86 87 int k; /* #rows left that can be 2d encoded */ 87 88 int maxk; /* max #rows that can be 2d encoded */ 89 90 int line; 88 91 } Fax3CodecState; 89 92 #define DecoderState(tif) ((Fax3CodecState*) Fax3State(tif)) … … 168 171 sp->refruns[1] = 0; 169 172 } 173 sp->line = 0; 170 174 return (1); 171 175 } … … 180 184 Fax3Unexpected(const char* module, TIFF* tif, uint32 line, uint32 a0) 181 185 { 182 TIFFErrorExt(tif->tif_clientdata, module, "%s: Bad code word at line % lu of %s %lu (x %lu)",183 tif->tif_name, (unsigned long)line, isTiled(tif) ? "tile" : "strip",184 (unsigned long)(isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),185 (unsigned long)a0);186 } 187 #define unexpected(table, a0) Fax3Unexpected(module, tif, line, a0)186 TIFFErrorExt(tif->tif_clientdata, module, "%s: Bad code word at line %u of %s %u (x %u)", 187 tif->tif_name, line, isTiled(tif) ? "tile" : "strip", 188 (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), 189 a0); 190 } 191 #define unexpected(table, a0) Fax3Unexpected(module, tif, sp->line, a0) 188 192 189 193 static void … … 191 195 { 192 196 TIFFErrorExt(tif->tif_clientdata, module, 193 "%s: Uncompressed data (not supported) at line %lu of %s %lu (x %lu)",194 tif->tif_name, (unsigned long)line, isTiled(tif) ? "tile" : "strip",195 (unsigned long)(isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),196 (unsigned long)a0);197 } 198 #define extension(a0) Fax3Extension(module, tif, line, a0)197 "%s: Uncompressed data (not supported) at line %u of %s %u (x %u)", 198 tif->tif_name, line, isTiled(tif) ? "tile" : "strip", 199 (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), 200 a0); 201 } 202 #define extension(a0) Fax3Extension(module, tif, sp->line, a0) 199 203 200 204 static void 201 205 Fax3BadLength(const char* module, TIFF* tif, uint32 line, uint32 a0, uint32 lastx) 202 206 { 203 TIFFWarningExt(tif->tif_clientdata, module, "%s: %s at line % lu of %s %lu (got %lu, expected %lu)",204 tif->tif_name,205 a0 < lastx ? "Premature EOL" : "Line length mismatch",206 (unsigned long)line, isTiled(tif) ? "tile" : "strip",207 (unsigned long)(isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),208 (unsigned long)a0, lastx);209 } 210 #define badlength(a0,lastx) Fax3BadLength(module, tif, line, a0, lastx)207 TIFFWarningExt(tif->tif_clientdata, module, "%s: %s at line %u of %s %u (got %u, expected %u)", 208 tif->tif_name, 209 a0 < lastx ? "Premature EOL" : "Line length mismatch", 210 line, isTiled(tif) ? "tile" : "strip", 211 (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), 212 a0, lastx); 213 } 214 #define badlength(a0,lastx) Fax3BadLength(module, tif, sp->line, a0, lastx) 211 215 212 216 static void 213 217 Fax3PrematureEOF(const char* module, TIFF* tif, uint32 line, uint32 a0) 214 218 { 215 TIFFWarningExt(tif->tif_clientdata, module, "%s: Premature EOF at line % lu of %s %lu (x %lu)",219 TIFFWarningExt(tif->tif_clientdata, module, "%s: Premature EOF at line %u of %s %u (x %u)", 216 220 tif->tif_name, 217 (unsigned long)line, isTiled(tif) ? "tile" : "strip",218 (unsigned long)(isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip),219 (unsigned long)a0);220 } 221 #define prematureEOF(a0) Fax3PrematureEOF(module, tif, line, a0)221 line, isTiled(tif) ? "tile" : "strip", 222 (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), 223 a0); 224 } 225 #define prematureEOF(a0) Fax3PrematureEOF(module, tif, sp->line, a0) 222 226 223 227 #define Nop … … 230 234 { 231 235 DECLARE_STATE(tif, sp, "Fax3Decode1D"); 232 int line = 0;233 236 234 237 (void) s; … … 249 252 buf += sp->b.rowbytes; 250 253 occ -= sp->b.rowbytes; 251 254 sp->line++; 252 255 continue; 253 256 EOF1D: /* premature EOF */ … … 270 273 { 271 274 DECLARE_STATE_2D(tif, sp, "Fax3Decode2D"); 272 int line = 0;273 275 int is1D; /* current line is 1d/2d-encoded */ 274 276 … … 303 305 buf += sp->b.rowbytes; 304 306 occ -= sp->b.rowbytes; 305 307 sp->line++; 306 308 continue; 307 309 EOF2D: /* premature EOF */ … … 493 495 494 496 nruns = needsRefLine ? 2*TIFFroundup(rowpixels,32) : rowpixels; 495 496 dsp->runs = (uint32*) _TIFFCheckMalloc(tif, 2*nruns +3, sizeof (uint32),497 nruns += 3; 498 dsp->runs = (uint32*) _TIFFCheckMalloc(tif, 2*nruns, sizeof (uint32), 497 499 "for Group 3/4 run arrays"); 498 500 if (dsp->runs == NULL) … … 500 502 dsp->curruns = dsp->runs; 501 503 if (needsRefLine) 502 dsp->refruns = dsp->runs + (nruns>>1);504 dsp->refruns = dsp->runs + nruns; 503 505 else 504 506 dsp->refruns = NULL; … … 719 721 } else 720 722 sp->k = sp->maxk = 0; 723 sp->line = 0; 721 724 return (1); 722 725 } … … 774 777 * along with the start+end bit indices. 775 778 */ 776 inlinestatic int32779 static int32 777 780 find0span(unsigned char* bp, int32 bs, int32 be) 778 781 { … … 833 836 } 834 837 835 inlinestatic int32838 static int32 836 839 find1span(unsigned char* bp, int32 bs, int32 be) 837 840 { … … 1075 1078 tif->tif_tagmethods.vgetfield = sp->b.vgetparent; 1076 1079 tif->tif_tagmethods.vsetfield = sp->b.vsetparent; 1080 tif->tif_tagmethods.printdir = sp->b.printdir; 1077 1081 1078 1082 if (sp->runs) … … 1083 1087 if (Fax3State(tif)->subaddress) 1084 1088 _TIFFfree(Fax3State(tif)->subaddress); 1089 if (Fax3State(tif)->faxdcs) 1090 _TIFFfree(Fax3State(tif)->faxdcs); 1091 1085 1092 _TIFFfree(tif->tif_data); 1086 1093 tif->tif_data = NULL; … … 1137 1144 { 1138 1145 Fax3BaseState* sp = Fax3State(tif); 1146 const TIFFFieldInfo* fip; 1139 1147 1140 1148 assert(sp != 0); … … 1144 1152 case TIFFTAG_FAXMODE: 1145 1153 sp->mode = va_arg(ap, int); 1146 return (1); /* NB: pseudo tag */1154 return 1; /* NB: pseudo tag */ 1147 1155 case TIFFTAG_FAXFILLFUNC: 1148 1156 DecoderState(tif)->fill = va_arg(ap, TIFFFaxFillFunc); 1149 return (1); /* NB: pseudo tag */1157 return 1; /* NB: pseudo tag */ 1150 1158 case TIFFTAG_GROUP3OPTIONS: 1151 1159 /* XXX: avoid reading options if compression mismatches. */ … … 1182 1190 return (*sp->vsetparent)(tif, tag, ap); 1183 1191 } 1184 TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif, tag)->field_bit); 1192 1193 if ((fip = _TIFFFieldWithTag(tif, tag))) 1194 TIFFSetFieldBit(tif, fip->field_bit); 1195 else 1196 return 0; 1197 1185 1198 tif->tif_flags |= TIFF_DIRTYDIRECT; 1186 return (1);1199 return 1; 1187 1200 } 1188 1201 … … 1191 1204 { 1192 1205 Fax3BaseState* sp = Fax3State(tif); 1206 1207 assert(sp != 0); 1193 1208 1194 1209 switch (tag) { … … 1234 1249 { 1235 1250 Fax3BaseState* sp = Fax3State(tif); 1251 1252 assert(sp != 0); 1236 1253 1237 1254 (void) flags; … … 1296 1313 1297 1314 /* 1315 * Merge codec-specific tag information. 1316 */ 1317 if (!_TIFFMergeFieldInfo(tif, faxFieldInfo, N(faxFieldInfo))) { 1318 TIFFErrorExt(tif->tif_clientdata, "InitCCITTFax3", 1319 "Merging common CCITT Fax codec-specific tags failed"); 1320 return 0; 1321 } 1322 1323 /* 1298 1324 * Allocate state block so tag methods have storage to record values. 1299 1325 */ … … 1311 1337 1312 1338 /* 1313 * Merge codec-specific tag information and 1314 * override parent get/set field methods. 1339 * Override parent get/set field methods. 1315 1340 */ 1316 _TIFFMergeFieldInfo(tif, faxFieldInfo, N(faxFieldInfo));1317 1341 sp->vgetparent = tif->tif_tagmethods.vgetfield; 1318 1342 tif->tif_tagmethods.vgetfield = Fax3VGetField; /* hook for codec tags */ 1319 1343 sp->vsetparent = tif->tif_tagmethods.vsetfield; 1320 1344 tif->tif_tagmethods.vsetfield = Fax3VSetField; /* hook for codec tags */ 1345 sp->printdir = tif->tif_tagmethods.printdir; 1321 1346 tif->tif_tagmethods.printdir = Fax3PrintDir; /* hook for codec tags */ 1322 1347 sp->groupoptions = 0; … … 1356 1381 (void) scheme; 1357 1382 if (InitCCITTFax3(tif)) { 1358 _TIFFMergeFieldInfo(tif, fax3FieldInfo, N(fax3FieldInfo)); 1383 /* 1384 * Merge codec-specific tag information. 1385 */ 1386 if (!_TIFFMergeFieldInfo(tif, fax3FieldInfo, N(fax3FieldInfo))) { 1387 TIFFErrorExt(tif->tif_clientdata, "TIFFInitCCITTFax3", 1388 "Merging CCITT Fax 3 codec-specific tags failed"); 1389 return 0; 1390 } 1359 1391 1360 1392 /* … … 1363 1395 return TIFFSetField(tif, TIFFTAG_FAXMODE, FAXMODE_CLASSF); 1364 1396 } else 1365 return (0);1397 return 01; 1366 1398 } 1367 1399 … … 1379 1411 { 1380 1412 DECLARE_STATE_2D(tif, sp, "Fax4Decode"); 1381 int line = 0;1382 1413 1383 1414 (void) s; … … 1402 1433 buf += sp->b.rowbytes; 1403 1434 occ -= sp->b.rowbytes; 1404 1435 sp->line++; 1405 1436 continue; 1406 1437 EOFG4: … … 1458 1489 (void) scheme; 1459 1490 if (InitCCITTFax3(tif)) { /* reuse G3 support */ 1460 _TIFFMergeFieldInfo(tif, fax4FieldInfo, N(fax4FieldInfo)); 1491 /* 1492 * Merge codec-specific tag information. 1493 */ 1494 if (!_TIFFMergeFieldInfo(tif, fax4FieldInfo, N(fax4FieldInfo))) { 1495 TIFFErrorExt(tif->tif_clientdata, "TIFFInitCCITTFax4", 1496 "Merging CCITT Fax 4 codec-specific tags failed"); 1497 return 0; 1498 } 1461 1499 1462 1500 tif->tif_decoderow = Fax4Decode; … … 1488 1526 DECLARE_STATE(tif, sp, "Fax3DecodeRLE"); 1489 1527 int mode = sp->b.mode; 1490 int line = 0;1491 1528 1492 1529 (void) s; … … 1518 1555 buf += sp->b.rowbytes; 1519 1556 occ -= sp->b.rowbytes; 1520 1557 sp->line++; 1521 1558 continue; 1522 1559 EOFRLE: /* premature EOF */ -
trunk/src/3rdparty/libtiff/libtiff/tif_getimage.c
r2 r846 1 /* $Id: tif_getimage.c,v 1. 49 2005/12/24 15:36:16 dron Exp $ */1 /* $Id: tif_getimage.c,v 1.63.2.3 2009-08-30 16:21:46 bfriesen Exp $ */ 2 2 3 3 /* … … 33 33 #include <stdio.h> 34 34 35 static int gtTileContig(TIFFRGBAImage*, uint32*, uint32, uint32); 36 static int gtTileSeparate(TIFFRGBAImage*, uint32*, uint32, uint32); 37 static int gtStripContig(TIFFRGBAImage*, uint32*, uint32, uint32); 38 static int gtStripSeparate(TIFFRGBAImage*, uint32*, uint32, uint32); 39 static int pickTileContigCase(TIFFRGBAImage*); 40 static int pickTileSeparateCase(TIFFRGBAImage*); 41 42 static const char photoTag[] = "PhotometricInterpretation"; 35 static int gtTileContig(TIFFRGBAImage*, uint32*, uint32, uint32); 36 static int gtTileSeparate(TIFFRGBAImage*, uint32*, uint32, uint32); 37 static int gtStripContig(TIFFRGBAImage*, uint32*, uint32, uint32); 38 static int gtStripSeparate(TIFFRGBAImage*, uint32*, uint32, uint32); 39 static int PickContigCase(TIFFRGBAImage*); 40 static int PickSeparateCase(TIFFRGBAImage*); 41 static const char photoTag[] = "PhotometricInterpretation"; 43 42 44 43 /* … … 73 72 TIFFRGBAImageOK(TIFF* tif, char emsg[1024]) 74 73 { 75 TIFFDirectory* td = &tif->tif_dir; 76 uint16 photometric; 77 int colorchannels; 78 79 if (!tif->tif_decodestatus) { 80 sprintf(emsg, "Sorry, requested compression method is not configured"); 81 return (0); 82 } 83 switch (td->td_bitspersample) { 84 case 1: case 2: case 4: 85 case 8: case 16: 86 break; 87 default: 88 sprintf(emsg, "Sorry, can not handle images with %d-bit samples", 89 td->td_bitspersample); 90 return (0); 91 } 92 colorchannels = td->td_samplesperpixel - td->td_extrasamples; 93 if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric)) { 94 switch (colorchannels) { 95 case 1: 96 photometric = PHOTOMETRIC_MINISBLACK; 97 break; 98 case 3: 99 photometric = PHOTOMETRIC_RGB; 100 break; 101 default: 102 sprintf(emsg, "Missing needed %s tag", photoTag); 103 return (0); 104 } 105 } 106 switch (photometric) { 107 case PHOTOMETRIC_MINISWHITE: 108 case PHOTOMETRIC_MINISBLACK: 109 case PHOTOMETRIC_PALETTE: 110 if (td->td_planarconfig == PLANARCONFIG_CONTIG 111 && td->td_samplesperpixel != 1 112 && td->td_bitspersample < 8 ) { 113 sprintf(emsg, 114 "Sorry, can not handle contiguous data with %s=%d, " 115 "and %s=%d and Bits/Sample=%d", 116 photoTag, photometric, 117 "Samples/pixel", td->td_samplesperpixel, 118 td->td_bitspersample); 119 return (0); 120 } 121 /* 122 ** We should likely validate that any extra samples are either 123 ** to be ignored, or are alpha, and if alpha we should try to use 124 ** them. But for now we won't bother with this. 125 */ 126 break; 127 case PHOTOMETRIC_YCBCR: 128 if (td->td_planarconfig != PLANARCONFIG_CONTIG) { 129 sprintf(emsg, "Sorry, can not handle YCbCr images with %s=%d", 130 "Planarconfiguration", td->td_planarconfig); 131 return (0); 132 } 133 break; 134 case PHOTOMETRIC_RGB: 135 if (colorchannels < 3) { 136 sprintf(emsg, "Sorry, can not handle RGB image with %s=%d", 137 "Color channels", colorchannels); 138 return (0); 139 } 140 break; 141 case PHOTOMETRIC_SEPARATED: 142 { 143 uint16 inkset; 144 TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset); 145 if (inkset != INKSET_CMYK) { 146 sprintf(emsg, 147 "Sorry, can not handle separated image with %s=%d", 148 "InkSet", inkset); 149 return 0; 150 } 151 if (td->td_samplesperpixel < 4) { 152 sprintf(emsg, 153 "Sorry, can not handle separated image with %s=%d", 154 "Samples/pixel", td->td_samplesperpixel); 155 return 0; 156 } 157 break; 158 } 159 case PHOTOMETRIC_LOGL: 160 if (td->td_compression != COMPRESSION_SGILOG) { 161 sprintf(emsg, "Sorry, LogL data must have %s=%d", 162 "Compression", COMPRESSION_SGILOG); 163 return (0); 164 } 165 break; 166 case PHOTOMETRIC_LOGLUV: 167 if (td->td_compression != COMPRESSION_SGILOG && 168 td->td_compression != COMPRESSION_SGILOG24) { 169 sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d", 170 "Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24); 171 return (0); 172 } 173 if (td->td_planarconfig != PLANARCONFIG_CONTIG) { 174 sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d", 175 "Planarconfiguration", td->td_planarconfig); 176 return (0); 177 } 178 break; 179 case PHOTOMETRIC_CIELAB: 180 break; 181 default: 182 sprintf(emsg, "Sorry, can not handle image with %s=%d", 183 photoTag, photometric); 184 return (0); 185 } 186 return (1); 74 TIFFDirectory* td = &tif->tif_dir; 75 uint16 photometric; 76 int colorchannels; 77 78 if (!tif->tif_decodestatus) { 79 sprintf(emsg, "Sorry, requested compression method is not configured"); 80 return (0); 81 } 82 switch (td->td_bitspersample) { 83 case 1: 84 case 2: 85 case 4: 86 case 8: 87 case 16: 88 break; 89 default: 90 sprintf(emsg, "Sorry, can not handle images with %d-bit samples", 91 td->td_bitspersample); 92 return (0); 93 } 94 colorchannels = td->td_samplesperpixel - td->td_extrasamples; 95 if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric)) { 96 switch (colorchannels) { 97 case 1: 98 photometric = PHOTOMETRIC_MINISBLACK; 99 break; 100 case 3: 101 photometric = PHOTOMETRIC_RGB; 102 break; 103 default: 104 sprintf(emsg, "Missing needed %s tag", photoTag); 105 return (0); 106 } 107 } 108 switch (photometric) { 109 case PHOTOMETRIC_MINISWHITE: 110 case PHOTOMETRIC_MINISBLACK: 111 case PHOTOMETRIC_PALETTE: 112 if (td->td_planarconfig == PLANARCONFIG_CONTIG 113 && td->td_samplesperpixel != 1 114 && td->td_bitspersample < 8 ) { 115 sprintf(emsg, 116 "Sorry, can not handle contiguous data with %s=%d, " 117 "and %s=%d and Bits/Sample=%d", 118 photoTag, photometric, 119 "Samples/pixel", td->td_samplesperpixel, 120 td->td_bitspersample); 121 return (0); 122 } 123 /* 124 * We should likely validate that any extra samples are either 125 * to be ignored, or are alpha, and if alpha we should try to use 126 * them. But for now we won't bother with this. 127 */ 128 break; 129 case PHOTOMETRIC_YCBCR: 130 /* 131 * TODO: if at all meaningful and useful, make more complete 132 * support check here, or better still, refactor to let supporting 133 * code decide whether there is support and what meaningfull 134 * error to return 135 */ 136 break; 137 case PHOTOMETRIC_RGB: 138 if (colorchannels < 3) { 139 sprintf(emsg, "Sorry, can not handle RGB image with %s=%d", 140 "Color channels", colorchannels); 141 return (0); 142 } 143 break; 144 case PHOTOMETRIC_SEPARATED: 145 { 146 uint16 inkset; 147 TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset); 148 if (inkset != INKSET_CMYK) { 149 sprintf(emsg, 150 "Sorry, can not handle separated image with %s=%d", 151 "InkSet", inkset); 152 return 0; 153 } 154 if (td->td_samplesperpixel < 4) { 155 sprintf(emsg, 156 "Sorry, can not handle separated image with %s=%d", 157 "Samples/pixel", td->td_samplesperpixel); 158 return 0; 159 } 160 break; 161 } 162 case PHOTOMETRIC_LOGL: 163 if (td->td_compression != COMPRESSION_SGILOG) { 164 sprintf(emsg, "Sorry, LogL data must have %s=%d", 165 "Compression", COMPRESSION_SGILOG); 166 return (0); 167 } 168 break; 169 case PHOTOMETRIC_LOGLUV: 170 if (td->td_compression != COMPRESSION_SGILOG && 171 td->td_compression != COMPRESSION_SGILOG24) { 172 sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d", 173 "Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24); 174 return (0); 175 } 176 if (td->td_planarconfig != PLANARCONFIG_CONTIG) { 177 sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d", 178 "Planarconfiguration", td->td_planarconfig); 179 return (0); 180 } 181 break; 182 case PHOTOMETRIC_CIELAB: 183 break; 184 default: 185 sprintf(emsg, "Sorry, can not handle image with %s=%d", 186 photoTag, photometric); 187 return (0); 188 } 189 return (1); 187 190 } 188 191 … … 200 203 if (img->cielab) 201 204 _TIFFfree(img->cielab), img->cielab = NULL; 202 203 205 if( img->redcmap ) { 204 206 _TIFFfree( img->redcmap ); … … 222 224 TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) 223 225 { 224 uint16* sampleinfo; 225 uint16 extrasamples; 226 uint16 planarconfig; 227 uint16 compress; 228 int colorchannels; 229 uint16 *red_orig, *green_orig, *blue_orig; 230 int n_color; 231 232 /* Initialize to normal values */ 233 img->row_offset = 0; 234 img->col_offset = 0; 235 img->redcmap = NULL; 236 img->greencmap = NULL; 237 img->bluecmap = NULL; 238 img->req_orientation = ORIENTATION_BOTLEFT; /* It is the default */ 239 240 img->tif = tif; 241 img->stoponerr = stop; 242 TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample); 243 switch (img->bitspersample) { 244 case 1: case 2: case 4: 245 case 8: case 16: 246 break; 247 default: 248 sprintf(emsg, "Sorry, can not handle images with %d-bit samples", 249 img->bitspersample); 250 return (0); 251 } 252 img->alpha = 0; 253 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &img->samplesperpixel); 254 TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, 255 &extrasamples, &sampleinfo); 256 if (extrasamples >= 1) 257 { 258 switch (sampleinfo[0]) { 259 case EXTRASAMPLE_UNSPECIFIED: /* Workaround for some images without */ 260 if (img->samplesperpixel > 3) /* correct info about alpha channel */ 261 img->alpha = EXTRASAMPLE_ASSOCALPHA; 262 break; 263 case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */ 264 case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */ 265 img->alpha = sampleinfo[0]; 266 break; 267 } 268 } 226 uint16* sampleinfo; 227 uint16 extrasamples; 228 uint16 planarconfig; 229 uint16 compress; 230 int colorchannels; 231 uint16 *red_orig, *green_orig, *blue_orig; 232 int n_color; 233 234 /* Initialize to normal values */ 235 img->row_offset = 0; 236 img->col_offset = 0; 237 img->redcmap = NULL; 238 img->greencmap = NULL; 239 img->bluecmap = NULL; 240 img->req_orientation = ORIENTATION_BOTLEFT; /* It is the default */ 241 242 img->tif = tif; 243 img->stoponerr = stop; 244 TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample); 245 switch (img->bitspersample) { 246 case 1: 247 case 2: 248 case 4: 249 case 8: 250 case 16: 251 break; 252 default: 253 sprintf(emsg, "Sorry, can not handle images with %d-bit samples", 254 img->bitspersample); 255 return (0); 256 } 257 img->alpha = 0; 258 TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &img->samplesperpixel); 259 TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, 260 &extrasamples, &sampleinfo); 261 if (extrasamples >= 1) 262 { 263 switch (sampleinfo[0]) { 264 case EXTRASAMPLE_UNSPECIFIED: /* Workaround for some images without */ 265 if (img->samplesperpixel > 3) /* correct info about alpha channel */ 266 img->alpha = EXTRASAMPLE_ASSOCALPHA; 267 break; 268 case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */ 269 case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */ 270 img->alpha = sampleinfo[0]; 271 break; 272 } 273 } 269 274 270 275 #ifdef DEFAULT_EXTRASAMPLE_AS_ALPHA 271 272 273 274 if( extrasamples == 0 275 && img->samplesperpixel == 4 276 277 278 279 280 276 if( !TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) 277 img->photometric = PHOTOMETRIC_MINISWHITE; 278 279 if( extrasamples == 0 280 && img->samplesperpixel == 4 281 && img->photometric == PHOTOMETRIC_RGB ) 282 { 283 img->alpha = EXTRASAMPLE_ASSOCALPHA; 284 extrasamples = 1; 285 } 281 286 #endif 282 287 283 colorchannels = img->samplesperpixel - extrasamples; 284 TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compress); 285 TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig); 286 if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) { 287 switch (colorchannels) { 288 case 1: 289 if (isCCITTCompression(tif)) 290 img->photometric = PHOTOMETRIC_MINISWHITE; 291 else 292 img->photometric = PHOTOMETRIC_MINISBLACK; 293 break; 294 case 3: 295 img->photometric = PHOTOMETRIC_RGB; 296 break; 297 default: 298 sprintf(emsg, "Missing needed %s tag", photoTag); 299 return (0); 300 } 301 } 302 switch (img->photometric) { 303 case PHOTOMETRIC_PALETTE: 304 if (!TIFFGetField(tif, TIFFTAG_COLORMAP, 305 &red_orig, &green_orig, &blue_orig)) { 306 sprintf(emsg, "Missing required \"Colormap\" tag"); 307 return (0); 308 } 309 310 /* copy the colormaps so we can modify them */ 311 n_color = (1L << img->bitspersample); 312 img->redcmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); 313 img->greencmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); 314 img->bluecmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); 315 if( !img->redcmap || !img->greencmap || !img->bluecmap ) { 316 sprintf(emsg, "Out of memory for colormap copy"); 317 return (0); 318 } 319 320 _TIFFmemcpy( img->redcmap, red_orig, n_color * 2 ); 321 _TIFFmemcpy( img->greencmap, green_orig, n_color * 2 ); 322 _TIFFmemcpy( img->bluecmap, blue_orig, n_color * 2 ); 323 324 /* fall thru... */ 325 case PHOTOMETRIC_MINISWHITE: 326 case PHOTOMETRIC_MINISBLACK: 327 if (planarconfig == PLANARCONFIG_CONTIG 328 && img->samplesperpixel != 1 329 && img->bitspersample < 8 ) { 330 sprintf(emsg, 331 "Sorry, can not handle contiguous data with %s=%d, " 332 "and %s=%d and Bits/Sample=%d", 333 photoTag, img->photometric, 334 "Samples/pixel", img->samplesperpixel, 335 img->bitspersample); 336 return (0); 337 } 338 break; 339 case PHOTOMETRIC_YCBCR: 340 if (planarconfig != PLANARCONFIG_CONTIG) { 341 sprintf(emsg, "Sorry, can not handle YCbCr images with %s=%d", 342 "Planarconfiguration", planarconfig); 343 return (0); 344 } 345 /* It would probably be nice to have a reality check here. */ 346 if (planarconfig == PLANARCONFIG_CONTIG) 347 /* can rely on libjpeg to convert to RGB */ 348 /* XXX should restore current state on exit */ 349 switch (compress) { 350 case COMPRESSION_OJPEG: 351 case COMPRESSION_JPEG: 352 TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB); 353 img->photometric = PHOTOMETRIC_RGB; 354 break; 355 356 default: 357 /* do nothing */; 358 break; 359 } 360 break; 361 case PHOTOMETRIC_RGB: 362 if (colorchannels < 3) { 363 sprintf(emsg, "Sorry, can not handle RGB image with %s=%d", 364 "Color channels", colorchannels); 365 return (0); 366 } 367 break; 368 case PHOTOMETRIC_SEPARATED: { 369 uint16 inkset; 370 TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset); 371 if (inkset != INKSET_CMYK) { 372 sprintf(emsg, "Sorry, can not handle separated image with %s=%d", 373 "InkSet", inkset); 374 return (0); 375 } 376 if (img->samplesperpixel < 4) { 377 sprintf(emsg, "Sorry, can not handle separated image with %s=%d", 378 "Samples/pixel", img->samplesperpixel); 379 return (0); 380 } 381 break; 382 } 383 case PHOTOMETRIC_LOGL: 384 if (compress != COMPRESSION_SGILOG) { 385 sprintf(emsg, "Sorry, LogL data must have %s=%d", 386 "Compression", COMPRESSION_SGILOG); 387 return (0); 388 } 389 TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT); 390 img->photometric = PHOTOMETRIC_MINISBLACK; /* little white lie */ 391 img->bitspersample = 8; 392 break; 393 case PHOTOMETRIC_LOGLUV: 394 if (compress != COMPRESSION_SGILOG && compress != COMPRESSION_SGILOG24) { 395 sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d", 396 "Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24); 397 return (0); 398 } 399 if (planarconfig != PLANARCONFIG_CONTIG) { 400 sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d", 401 "Planarconfiguration", planarconfig); 402 return (0); 403 } 404 TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT); 405 img->photometric = PHOTOMETRIC_RGB; /* little white lie */ 406 img->bitspersample = 8; 407 break; 408 case PHOTOMETRIC_CIELAB: 409 break; 410 default: 411 sprintf(emsg, "Sorry, can not handle image with %s=%d", 412 photoTag, img->photometric); 413 return (0); 414 } 415 img->Map = NULL; 416 img->BWmap = NULL; 417 img->PALmap = NULL; 418 img->ycbcr = NULL; 419 img->cielab = NULL; 420 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width); 421 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height); 422 TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation); 423 img->isContig = 424 !(planarconfig == PLANARCONFIG_SEPARATE && colorchannels > 1); 425 if (img->isContig) { 426 img->get = TIFFIsTiled(tif) ? gtTileContig : gtStripContig; 427 if (!pickTileContigCase(img)) { 428 sprintf(emsg, "Sorry, can not handle image"); 429 return 0; 430 } 431 } else { 432 img->get = TIFFIsTiled(tif) ? gtTileSeparate : gtStripSeparate; 433 if (!pickTileSeparateCase(img)) { 434 sprintf(emsg, "Sorry, can not handle image"); 435 return 0; 436 } 437 } 438 return 1; 288 colorchannels = img->samplesperpixel - extrasamples; 289 TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compress); 290 TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig); 291 if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) { 292 switch (colorchannels) { 293 case 1: 294 if (isCCITTCompression(tif)) 295 img->photometric = PHOTOMETRIC_MINISWHITE; 296 else 297 img->photometric = PHOTOMETRIC_MINISBLACK; 298 break; 299 case 3: 300 img->photometric = PHOTOMETRIC_RGB; 301 break; 302 default: 303 sprintf(emsg, "Missing needed %s tag", photoTag); 304 return (0); 305 } 306 } 307 switch (img->photometric) { 308 case PHOTOMETRIC_PALETTE: 309 if (!TIFFGetField(tif, TIFFTAG_COLORMAP, 310 &red_orig, &green_orig, &blue_orig)) { 311 sprintf(emsg, "Missing required \"Colormap\" tag"); 312 return (0); 313 } 314 315 /* copy the colormaps so we can modify them */ 316 n_color = (1L << img->bitspersample); 317 img->redcmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); 318 img->greencmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); 319 img->bluecmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); 320 if( !img->redcmap || !img->greencmap || !img->bluecmap ) { 321 sprintf(emsg, "Out of memory for colormap copy"); 322 return (0); 323 } 324 325 _TIFFmemcpy( img->redcmap, red_orig, n_color * 2 ); 326 _TIFFmemcpy( img->greencmap, green_orig, n_color * 2 ); 327 _TIFFmemcpy( img->bluecmap, blue_orig, n_color * 2 ); 328 329 /* fall thru... */ 330 case PHOTOMETRIC_MINISWHITE: 331 case PHOTOMETRIC_MINISBLACK: 332 if (planarconfig == PLANARCONFIG_CONTIG 333 && img->samplesperpixel != 1 334 && img->bitspersample < 8 ) { 335 sprintf(emsg, 336 "Sorry, can not handle contiguous data with %s=%d, " 337 "and %s=%d and Bits/Sample=%d", 338 photoTag, img->photometric, 339 "Samples/pixel", img->samplesperpixel, 340 img->bitspersample); 341 return (0); 342 } 343 break; 344 case PHOTOMETRIC_YCBCR: 345 /* It would probably be nice to have a reality check here. */ 346 if (planarconfig == PLANARCONFIG_CONTIG) 347 /* can rely on libjpeg to convert to RGB */ 348 /* XXX should restore current state on exit */ 349 switch (compress) { 350 case COMPRESSION_JPEG: 351 /* 352 * TODO: when complete tests verify complete desubsampling 353 * and YCbCr handling, remove use of TIFFTAG_JPEGCOLORMODE in 354 * favor of tif_getimage.c native handling 355 */ 356 TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB); 357 img->photometric = PHOTOMETRIC_RGB; 358 break; 359 default: 360 /* do nothing */; 361 break; 362 } 363 /* 364 * TODO: if at all meaningful and useful, make more complete 365 * support check here, or better still, refactor to let supporting 366 * code decide whether there is support and what meaningfull 367 * error to return 368 */ 369 break; 370 case PHOTOMETRIC_RGB: 371 if (colorchannels < 3) { 372 sprintf(emsg, "Sorry, can not handle RGB image with %s=%d", 373 "Color channels", colorchannels); 374 return (0); 375 } 376 break; 377 case PHOTOMETRIC_SEPARATED: 378 { 379 uint16 inkset; 380 TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset); 381 if (inkset != INKSET_CMYK) { 382 sprintf(emsg, "Sorry, can not handle separated image with %s=%d", 383 "InkSet", inkset); 384 return (0); 385 } 386 if (img->samplesperpixel < 4) { 387 sprintf(emsg, "Sorry, can not handle separated image with %s=%d", 388 "Samples/pixel", img->samplesperpixel); 389 return (0); 390 } 391 } 392 break; 393 case PHOTOMETRIC_LOGL: 394 if (compress != COMPRESSION_SGILOG) { 395 sprintf(emsg, "Sorry, LogL data must have %s=%d", 396 "Compression", COMPRESSION_SGILOG); 397 return (0); 398 } 399 TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT); 400 img->photometric = PHOTOMETRIC_MINISBLACK; /* little white lie */ 401 img->bitspersample = 8; 402 break; 403 case PHOTOMETRIC_LOGLUV: 404 if (compress != COMPRESSION_SGILOG && compress != COMPRESSION_SGILOG24) { 405 sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d", 406 "Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24); 407 return (0); 408 } 409 if (planarconfig != PLANARCONFIG_CONTIG) { 410 sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d", 411 "Planarconfiguration", planarconfig); 412 return (0); 413 } 414 TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT); 415 img->photometric = PHOTOMETRIC_RGB; /* little white lie */ 416 img->bitspersample = 8; 417 break; 418 case PHOTOMETRIC_CIELAB: 419 break; 420 default: 421 sprintf(emsg, "Sorry, can not handle image with %s=%d", 422 photoTag, img->photometric); 423 return (0); 424 } 425 img->Map = NULL; 426 img->BWmap = NULL; 427 img->PALmap = NULL; 428 img->ycbcr = NULL; 429 img->cielab = NULL; 430 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width); 431 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height); 432 TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation); 433 img->isContig = 434 !(planarconfig == PLANARCONFIG_SEPARATE && colorchannels > 1); 435 if (img->isContig) { 436 if (!PickContigCase(img)) { 437 sprintf(emsg, "Sorry, can not handle image"); 438 return 0; 439 } 440 } else { 441 if (!PickSeparateCase(img)) { 442 sprintf(emsg, "Sorry, can not handle image"); 443 return 0; 444 } 445 } 446 return 1; 439 447 } 440 448 … … 474 482 TIFFRGBAImageEnd(&img); 475 483 } else { 476 TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), emsg);484 TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg); 477 485 ok = 0; 478 486 } … … 655 663 gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) 656 664 { 657 658 659 660 661 662 663 unsigned char* r;664 unsigned char* g;665 unsigned char* b;666 unsigned char*a;667 668 669 670 671 672 673 674 buf = (unsigned char*) _TIFFmalloc(4*tilesize);675 665 TIFF* tif = img->tif; 666 tileSeparateRoutine put = img->put.separate; 667 uint32 col, row, y, rowstoread; 668 uint32 pos; 669 uint32 tw, th; 670 unsigned char* buf; 671 unsigned char* p0; 672 unsigned char* p1; 673 unsigned char* p2; 674 unsigned char* pa; 675 tsize_t tilesize; 676 int32 fromskew, toskew; 677 int alpha = img->alpha; 678 uint32 nrow; 679 int ret = 1, flip; 680 681 tilesize = TIFFTileSize(tif); 682 buf = (unsigned char*) _TIFFmalloc((alpha?4:3)*tilesize); 683 if (buf == 0) { 676 684 TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer"); 677 685 return (0); 678 } 679 _TIFFmemset(buf, 0, 4*tilesize); 680 r = buf; 681 g = r + tilesize; 682 b = g + tilesize; 683 a = b + tilesize; 684 if (!alpha) 685 _TIFFmemset(a, 0xff, tilesize); 686 TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw); 687 TIFFGetField(tif, TIFFTAG_TILELENGTH, &th); 688 689 flip = setorientation(img); 690 if (flip & FLIP_VERTICALLY) { 691 y = h - 1; 692 toskew = -(int32)(tw + w); 693 } 694 else { 695 y = 0; 696 toskew = -(int32)(tw - w); 697 } 698 699 for (row = 0; row < h; row += nrow) 700 { 701 rowstoread = th - (row + img->row_offset) % th; 702 nrow = (row + rowstoread > h ? h - row : rowstoread); 703 for (col = 0; col < w; col += tw) 704 { 705 if (TIFFReadTile(tif, r, col+img->col_offset, 706 row+img->row_offset,0,0) < 0 && img->stoponerr) 707 { 708 ret = 0; 709 break; 710 } 711 if (TIFFReadTile(tif, g, col+img->col_offset, 712 row+img->row_offset,0,1) < 0 && img->stoponerr) 713 { 714 ret = 0; 715 break; 716 } 717 if (TIFFReadTile(tif, b, col+img->col_offset, 718 row+img->row_offset,0,2) < 0 && img->stoponerr) 719 { 720 ret = 0; 721 break; 722 } 723 if (alpha && TIFFReadTile(tif,a,col+img->col_offset, 724 row+img->row_offset,0,3) < 0 && img->stoponerr) 725 { 726 ret = 0; 727 break; 728 } 729 730 pos = ((row+img->row_offset) % th) * TIFFTileRowSize(tif); 731 732 if (col + tw > w) 733 { 734 /* 735 * Tile is clipped horizontally. Calculate 736 * visible portion and skewing factors. 737 */ 738 uint32 npix = w - col; 739 fromskew = tw - npix; 740 (*put)(img, raster+y*w+col, col, y, 741 npix, nrow, fromskew, toskew + fromskew, 742 r + pos, g + pos, b + pos, a + pos); 743 } else { 744 (*put)(img, raster+y*w+col, col, y, 745 tw, nrow, 0, toskew, r + pos, g + pos, b + pos, a + pos); 746 } 747 } 748 749 y += (flip & FLIP_VERTICALLY ?-(int32) nrow : (int32) nrow); 750 } 751 752 if (flip & FLIP_HORIZONTALLY) { 753 uint32 line; 754 755 for (line = 0; line < h; line++) { 756 uint32 *left = raster + (line * w); 757 uint32 *right = left + w - 1; 758 759 while ( left < right ) { 760 uint32 temp = *left; 761 *left = *right; 762 *right = temp; 763 left++, right--; 764 } 765 } 766 } 767 768 _TIFFfree(buf); 769 return (ret); 686 } 687 _TIFFmemset(buf, 0, (alpha?4:3)*tilesize); 688 p0 = buf; 689 p1 = p0 + tilesize; 690 p2 = p1 + tilesize; 691 pa = (alpha?(p2+tilesize):NULL); 692 TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw); 693 TIFFGetField(tif, TIFFTAG_TILELENGTH, &th); 694 695 flip = setorientation(img); 696 if (flip & FLIP_VERTICALLY) { 697 y = h - 1; 698 toskew = -(int32)(tw + w); 699 } 700 else { 701 y = 0; 702 toskew = -(int32)(tw - w); 703 } 704 705 for (row = 0; row < h; row += nrow) 706 { 707 rowstoread = th - (row + img->row_offset) % th; 708 nrow = (row + rowstoread > h ? h - row : rowstoread); 709 for (col = 0; col < w; col += tw) 710 { 711 if (TIFFReadTile(tif, p0, col+img->col_offset, 712 row+img->row_offset,0,0) < 0 && img->stoponerr) 713 { 714 ret = 0; 715 break; 716 } 717 if (TIFFReadTile(tif, p1, col+img->col_offset, 718 row+img->row_offset,0,1) < 0 && img->stoponerr) 719 { 720 ret = 0; 721 break; 722 } 723 if (TIFFReadTile(tif, p2, col+img->col_offset, 724 row+img->row_offset,0,2) < 0 && img->stoponerr) 725 { 726 ret = 0; 727 break; 728 } 729 if (alpha) 730 { 731 if (TIFFReadTile(tif,pa,col+img->col_offset, 732 row+img->row_offset,0,3) < 0 && img->stoponerr) 733 { 734 ret = 0; 735 break; 736 } 737 } 738 739 pos = ((row+img->row_offset) % th) * TIFFTileRowSize(tif); 740 741 if (col + tw > w) 742 { 743 /* 744 * Tile is clipped horizontally. Calculate 745 * visible portion and skewing factors. 746 */ 747 uint32 npix = w - col; 748 fromskew = tw - npix; 749 (*put)(img, raster+y*w+col, col, y, 750 npix, nrow, fromskew, toskew + fromskew, 751 p0 + pos, p1 + pos, p2 + pos, (alpha?(pa+pos):NULL)); 752 } else { 753 (*put)(img, raster+y*w+col, col, y, 754 tw, nrow, 0, toskew, p0 + pos, p1 + pos, p2 + pos, (alpha?(pa+pos):NULL)); 755 } 756 } 757 758 y += (flip & FLIP_VERTICALLY ?-(int32) nrow : (int32) nrow); 759 } 760 761 if (flip & FLIP_HORIZONTALLY) { 762 uint32 line; 763 764 for (line = 0; line < h; line++) { 765 uint32 *left = raster + (line * w); 766 uint32 *right = left + w - 1; 767 768 while ( left < right ) { 769 uint32 temp = *left; 770 *left = *right; 771 *right = temp; 772 left++, right--; 773 } 774 } 775 } 776 777 _TIFFfree(buf); 778 return (ret); 770 779 } 771 780 … … 779 788 gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) 780 789 { 781 TIFF* tif = img->tif; 782 tileContigRoutine put = img->put.contig; 783 uint32 row, y, nrow, rowstoread; 784 uint32 pos; 785 unsigned char* buf; 786 uint32 rowsperstrip; 787 uint32 imagewidth = img->width; 788 tsize_t scanline; 789 int32 fromskew, toskew; 790 int ret = 1, flip; 791 792 buf = (unsigned char*) _TIFFmalloc(TIFFStripSize(tif)); 793 if (buf == 0) { 790 TIFF* tif = img->tif; 791 tileContigRoutine put = img->put.contig; 792 uint32 row, y, nrow, nrowsub, rowstoread; 793 uint32 pos; 794 unsigned char* buf; 795 uint32 rowsperstrip; 796 uint16 subsamplinghor,subsamplingver; 797 uint32 imagewidth = img->width; 798 tsize_t scanline; 799 int32 fromskew, toskew; 800 int ret = 1, flip; 801 802 buf = (unsigned char*) _TIFFmalloc(TIFFStripSize(tif)); 803 if (buf == 0) { 794 804 TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for strip buffer"); 795 805 return (0); 796 } 797 _TIFFmemset(buf, 0, TIFFStripSize(tif)); 798 799 flip = setorientation(img); 800 if (flip & FLIP_VERTICALLY) { 801 y = h - 1; 802 toskew = -(int32)(w + w); 803 } else { 804 y = 0; 805 toskew = -(int32)(w - w); 806 } 807 808 TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); 809 scanline = TIFFScanlineSize(tif); 810 fromskew = (w < imagewidth ? imagewidth - w : 0); 811 for (row = 0; row < h; row += nrow) 812 { 813 rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip; 814 nrow = (row + rowstoread > h ? h - row : rowstoread); 815 if (TIFFReadEncodedStrip(tif, 816 TIFFComputeStrip(tif,row+img->row_offset, 0), 817 buf, 818 ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 819 && img->stoponerr) 820 { 821 ret = 0; 822 break; 823 } 824 825 pos = ((row + img->row_offset) % rowsperstrip) * scanline; 826 (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, buf + pos); 827 y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); 828 } 829 830 if (flip & FLIP_HORIZONTALLY) { 831 uint32 line; 832 833 for (line = 0; line < h; line++) { 834 uint32 *left = raster + (line * w); 835 uint32 *right = left + w - 1; 836 837 while ( left < right ) { 838 uint32 temp = *left; 839 *left = *right; 840 *right = temp; 841 left++, right--; 842 } 843 } 844 } 845 846 _TIFFfree(buf); 847 return (ret); 806 } 807 _TIFFmemset(buf, 0, TIFFStripSize(tif)); 808 809 flip = setorientation(img); 810 if (flip & FLIP_VERTICALLY) { 811 y = h - 1; 812 toskew = -(int32)(w + w); 813 } else { 814 y = 0; 815 toskew = -(int32)(w - w); 816 } 817 818 TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); 819 TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING, &subsamplinghor, &subsamplingver); 820 scanline = TIFFNewScanlineSize(tif); 821 fromskew = (w < imagewidth ? imagewidth - w : 0); 822 for (row = 0; row < h; row += nrow) 823 { 824 rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip; 825 nrow = (row + rowstoread > h ? h - row : rowstoread); 826 nrowsub = nrow; 827 if ((nrowsub%subsamplingver)!=0) 828 nrowsub+=subsamplingver-nrowsub%subsamplingver; 829 if (TIFFReadEncodedStrip(tif, 830 TIFFComputeStrip(tif,row+img->row_offset, 0), 831 buf, 832 ((row + img->row_offset)%rowsperstrip + nrowsub) * scanline) < 0 833 && img->stoponerr) 834 { 835 ret = 0; 836 break; 837 } 838 839 pos = ((row + img->row_offset) % rowsperstrip) * scanline; 840 (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, buf + pos); 841 y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); 842 } 843 844 if (flip & FLIP_HORIZONTALLY) { 845 uint32 line; 846 847 for (line = 0; line < h; line++) { 848 uint32 *left = raster + (line * w); 849 uint32 *right = left + w - 1; 850 851 while ( left < right ) { 852 uint32 temp = *left; 853 *left = *right; 854 *right = temp; 855 left++, right--; 856 } 857 } 858 } 859 860 _TIFFfree(buf); 861 return (ret); 848 862 } 849 863 … … 857 871 gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) 858 872 { 859 860 861 862 unsigned char *r, *g, *b, *a;863 864 865 866 867 868 869 870 871 intret = 1, flip;872 873 874 r = buf = (unsigned char *)_TIFFmalloc(4*stripsize);875 873 TIFF* tif = img->tif; 874 tileSeparateRoutine put = img->put.separate; 875 unsigned char *buf; 876 unsigned char *p0, *p1, *p2, *pa; 877 uint32 row, y, nrow, rowstoread; 878 uint32 pos; 879 tsize_t scanline; 880 uint32 rowsperstrip, offset_row; 881 uint32 imagewidth = img->width; 882 tsize_t stripsize; 883 int32 fromskew, toskew; 884 int alpha = img->alpha; 885 int ret = 1, flip; 886 887 stripsize = TIFFStripSize(tif); 888 p0 = buf = (unsigned char *)_TIFFmalloc((alpha?4:3)*stripsize); 889 if (buf == 0) { 876 890 TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer"); 877 891 return (0); 878 879 _TIFFmemset(buf, 0, 4*stripsize);880 g = r+ stripsize;881 b = g+ stripsize;882 a = b + stripsize;883 if (!alpha) 884 _TIFFmemset(a, 0xff, stripsize);885 886 flip = setorientation(img);887 if (flip & FLIP_VERTICALLY) { 888 y = h - 1;889 toskew = -(int32)(w + w);890 } 891 else { 892 y = 0;893 toskew = -(int32)(w - w); 894 } 895 896 TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);897 scanline = TIFFScanlineSize(tif); 898 fromskew = (w < imagewidth ? imagewidth - w : 0); 899 for (row = 0; row < h; row += nrow) 900 { 901 rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip; 902 nrow = (row + rowstoread > h ? h - row : rowstoread); 903 offset_row = row + img->row_offset; 904 if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0), 905 r, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 906 && img->stoponerr) 907 { 908 ret = 0; 909 break; 910 } 911 if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 1), 912 g, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 913 && img->stoponerr) 914 { 915 ret = 0; 916 break; 917 } 918 if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 2), 919 b, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 920 && img->stoponerr) 921 { 922 ret = 0; 923 break; 924 } 925 if (alpha && 926 (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 3), 927 a, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 928 && img->stoponerr)) 929 { 930 ret = 0;931 break; 932 933 934 935 (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, r + pos, g + pos, 936 b + pos, a + pos);937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 892 } 893 _TIFFmemset(buf, 0, (alpha?4:3)*stripsize); 894 p1 = p0 + stripsize; 895 p2 = p1 + stripsize; 896 pa = (alpha?(p2+stripsize):NULL); 897 898 flip = setorientation(img); 899 if (flip & FLIP_VERTICALLY) { 900 y = h - 1; 901 toskew = -(int32)(w + w); 902 } 903 else { 904 y = 0; 905 toskew = -(int32)(w - w); 906 } 907 908 TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); 909 scanline = TIFFScanlineSize(tif); 910 fromskew = (w < imagewidth ? imagewidth - w : 0); 911 for (row = 0; row < h; row += nrow) 912 { 913 rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip; 914 nrow = (row + rowstoread > h ? h - row : rowstoread); 915 offset_row = row + img->row_offset; 916 if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0), 917 p0, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 918 && img->stoponerr) 919 { 920 ret = 0; 921 break; 922 } 923 if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 1), 924 p1, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 925 && img->stoponerr) 926 { 927 ret = 0; 928 break; 929 } 930 if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 2), 931 p2, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 932 && img->stoponerr) 933 { 934 ret = 0; 935 break; 936 } 937 if (alpha) 938 { 939 if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 3), 940 pa, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 941 && img->stoponerr) 942 { 943 ret = 0; 944 break; 945 } 946 } 947 948 pos = ((row + img->row_offset) % rowsperstrip) * scanline; 949 (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, p0 + pos, p1 + pos, 950 p2 + pos, (alpha?(pa+pos):NULL)); 951 y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); 952 } 953 954 if (flip & FLIP_HORIZONTALLY) { 955 uint32 line; 956 957 for (line = 0; line < h; line++) { 958 uint32 *left = raster + (line * w); 959 uint32 *right = left + w - 1; 960 961 while ( left < right ) { 962 uint32 temp = *left; 963 *left = *right; 964 *right = temp; 965 left++, right--; 966 } 967 } 968 } 969 970 _TIFFfree(buf); 971 return (ret); 958 972 } 959 973 … … 964 978 * 965 979 * The routines have been created according to the most 966 * important cases and optimized. pickTileContigCase and967 * pickTileSeparateCase analyze the parameters and select968 * the appropriate " put" routine to use.980 * important cases and optimized. PickContigCase and 981 * PickSeparateCase analyze the parameters and select 982 * the appropriate "get" and "put" routine to use. 969 983 */ 970 984 #define REPEAT8(op) REPEAT4(op); REPEAT4(op) … … 1224 1238 1225 1239 /* 1226 * 8-bit packed samples, w/ Map => RGB1227 */1228 DECLAREContigPutFunc(putRGBcontig8bitMaptile)1229 {1230 TIFFRGBValue* Map = img->Map;1231 int samplesperpixel = img->samplesperpixel;1232 1233 (void) y;1234 fromskew *= samplesperpixel;1235 while (h-- > 0) {1236 for (x = w; x-- > 0;) {1237 *cp++ = PACK(Map[pp[0]], Map[pp[1]], Map[pp[2]]);1238 pp += samplesperpixel;1239 }1240 pp += fromskew;1241 cp += toskew;1242 }1243 }1244 1245 /*1246 1240 * 8-bit packed samples => RGBA w/ associated alpha 1247 1241 * (known to have Map == NULL) … … 1268 1262 DECLAREContigPutFunc(putRGBUAcontig8bittile) 1269 1263 { 1270 int samplesperpixel = img->samplesperpixel; 1271 1272 (void) y; 1273 fromskew *= samplesperpixel; 1274 while (h-- > 0) { 1275 uint32 r, g, b, a; 1276 for (x = w; x-- > 0;) { 1277 a = pp[3]; 1278 r = (pp[0] * a) / 255; 1279 g = (pp[1] * a) / 255; 1280 b = (pp[2] * a) / 255; 1281 *cp++ = PACK4(r,g,b,a); 1282 pp += samplesperpixel; 1283 } 1284 cp += toskew; 1285 pp += fromskew; 1286 } 1264 int samplesperpixel = img->samplesperpixel; 1265 (void) y; 1266 fromskew *= samplesperpixel; 1267 while (h-- > 0) { 1268 uint32 r, g, b, a; 1269 for (x = w; x-- > 0;) { 1270 a = pp[3]; 1271 r = (a*pp[0] + 127) / 255; 1272 g = (a*pp[1] + 127) / 255; 1273 b = (a*pp[2] + 127) / 255; 1274 *cp++ = PACK4(r,g,b,a); 1275 pp += samplesperpixel; 1276 } 1277 cp += toskew; 1278 pp += fromskew; 1279 } 1287 1280 } 1288 1281 … … 1292 1285 DECLAREContigPutFunc(putRGBcontig16bittile) 1293 1286 { 1294 int samplesperpixel = img->samplesperpixel; 1295 uint16 *wp = (uint16 *)pp; 1296 1297 (void) y; 1298 fromskew *= samplesperpixel; 1299 while (h-- > 0) { 1300 for (x = w; x-- > 0;) { 1301 *cp++ = PACKW(wp[0], wp[1], wp[2]); 1302 wp += samplesperpixel; 1303 } 1304 cp += toskew; 1305 wp += fromskew; 1306 } 1287 int samplesperpixel = img->samplesperpixel; 1288 uint16 *wp = (uint16 *)pp; 1289 (void) y; 1290 fromskew *= samplesperpixel; 1291 while (h-- > 0) { 1292 for (x = w; x-- > 0;) { 1293 *cp++ = PACKW(wp[0],wp[1],wp[2]); 1294 wp += samplesperpixel; 1295 } 1296 cp += toskew; 1297 wp += fromskew; 1298 } 1307 1299 } 1308 1300 … … 1313 1305 DECLAREContigPutFunc(putRGBAAcontig16bittile) 1314 1306 { 1315 int samplesperpixel = img->samplesperpixel; 1316 uint16 *wp = (uint16 *)pp; 1317 1318 (void) y; 1319 fromskew *= samplesperpixel; 1320 while (h-- > 0) { 1321 for (x = w; x-- > 0;) { 1322 *cp++ = PACKW4(wp[0], wp[1], wp[2], wp[3]); 1323 wp += samplesperpixel; 1324 } 1325 cp += toskew; 1326 wp += fromskew; 1327 } 1307 int samplesperpixel = img->samplesperpixel; 1308 uint16 *wp = (uint16 *)pp; 1309 (void) y; 1310 fromskew *= samplesperpixel; 1311 while (h-- > 0) { 1312 for (x = w; x-- > 0;) { 1313 *cp++ = PACKW4(wp[0],wp[1],wp[2],wp[3]); 1314 wp += samplesperpixel; 1315 } 1316 cp += toskew; 1317 wp += fromskew; 1318 } 1328 1319 } 1329 1320 … … 1334 1325 DECLAREContigPutFunc(putRGBUAcontig16bittile) 1335 1326 { 1336 int samplesperpixel = img->samplesperpixel; 1337 uint16 *wp = (uint16 *)pp; 1338 1339 (void) y; 1340 fromskew *= samplesperpixel; 1341 while (h-- > 0) { 1342 uint32 r,g,b,a; 1343 /* 1344 * We shift alpha down four bits just in case unsigned 1345 * arithmetic doesn't handle the full range. 1346 * We still have plenty of accuracy, since the output is 8 bits. 1347 * So we have (r * 0xffff) * (a * 0xfff)) = r*a * (0xffff*0xfff) 1348 * Since we want r*a * 0xff for eight bit output, 1349 * we divide by (0xffff * 0xfff) / 0xff == 0x10eff. 1350 */ 1351 for (x = w; x-- > 0;) { 1352 a = wp[3] >> 4; 1353 r = (wp[0] * a) / 0x10eff; 1354 g = (wp[1] * a) / 0x10eff; 1355 b = (wp[2] * a) / 0x10eff; 1356 *cp++ = PACK4(r,g,b,a); 1357 wp += samplesperpixel; 1358 } 1359 cp += toskew; 1360 wp += fromskew; 1361 } 1327 int samplesperpixel = img->samplesperpixel; 1328 uint16 *wp = (uint16 *)pp; 1329 (void) y; 1330 fromskew *= samplesperpixel; 1331 while (h-- > 0) { 1332 uint32 r,g,b,a; 1333 for (x = w; x-- > 0;) { 1334 a = W2B(wp[3]); 1335 r = (a*W2B(wp[0]) + 127) / 255; 1336 g = (a*W2B(wp[1]) + 127) / 255; 1337 b = (a*W2B(wp[2]) + 127) / 255; 1338 *cp++ = PACK4(r,g,b,a); 1339 wp += samplesperpixel; 1340 } 1341 cp += toskew; 1342 wp += fromskew; 1343 } 1362 1344 } 1363 1345 … … 1438 1420 1439 1421 /* 1440 * 8-bit unpacked samples => RGB1441 */1442 DECLARESepPutFunc(putRGBseparate8bitMaptile)1443 {1444 TIFFRGBValue* Map = img->Map;1445 1446 (void) y; (void) a;1447 while (h-- > 0) {1448 for (x = w; x > 0; x--)1449 *cp++ = PACK(Map[*r++], Map[*g++], Map[*b++]);1450 SKEW(r, g, b, fromskew);1451 cp += toskew;1452 }1453 }1454 1455 /*1456 1422 * 8-bit unpacked samples => RGBA w/ associated alpha 1457 1423 */ 1458 1424 DECLARESepPutFunc(putRGBAAseparate8bittile) 1459 1425 { 1460 1461 1462 UNROLL8(w, NOP, *cp++ = PACK4(*r++, *g++, *b++, *a++));1463 SKEW4(r, g, b, a, fromskew);1464 cp += toskew;1465 1426 (void) img; (void) x; (void) y; 1427 while (h-- > 0) { 1428 UNROLL8(w, NOP, *cp++ = PACK4(*r++, *g++, *b++, *a++)); 1429 SKEW4(r, g, b, a, fromskew); 1430 cp += toskew; 1431 } 1466 1432 } 1467 1433 … … 1471 1437 DECLARESepPutFunc(putRGBUAseparate8bittile) 1472 1438 { 1473 1474 1475 uint32 rv, gv, bv, av;1476 for (x = w; x-- > 0;) {1477 1478 rv = (*r++ * av) / 255;1479 gv = (*g++ * av) / 255;1480 bv = (*b++ * av) / 255;1481 1482 }1483 SKEW4(r, g, b, a, fromskew);1484 cp += toskew;1485 1439 (void) img; (void) y; 1440 while (h-- > 0) { 1441 uint32 rv, gv, bv, av; 1442 for (x = w; x-- > 0;) { 1443 av = *a++; 1444 rv = (av* *r++ + 127) / 255; 1445 gv = (av* *g++ + 127) / 255; 1446 bv = (av* *b++ + 127) / 255; 1447 *cp++ = PACK4(rv,gv,bv,av); 1448 } 1449 SKEW4(r, g, b, a, fromskew); 1450 cp += toskew; 1451 } 1486 1452 } 1487 1453 … … 1491 1457 DECLARESepPutFunc(putRGBseparate16bittile) 1492 1458 { 1493 uint16 *wr = (uint16*) r; 1494 uint16 *wg = (uint16*) g; 1495 uint16 *wb = (uint16*) b; 1496 1497 (void) img; (void) y; (void) a; 1498 while (h-- > 0) { 1499 for (x = 0; x < w; x++) 1500 *cp++ = PACKW(*wr++, *wg++, *wb++); 1501 SKEW(wr, wg, wb, fromskew); 1502 cp += toskew; 1503 } 1459 uint16 *wr = (uint16*) r; 1460 uint16 *wg = (uint16*) g; 1461 uint16 *wb = (uint16*) b; 1462 (void) img; (void) y; (void) a; 1463 while (h-- > 0) { 1464 for (x = 0; x < w; x++) 1465 *cp++ = PACKW(*wr++,*wg++,*wb++); 1466 SKEW(wr, wg, wb, fromskew); 1467 cp += toskew; 1468 } 1504 1469 } 1505 1470 … … 1509 1474 DECLARESepPutFunc(putRGBAAseparate16bittile) 1510 1475 { 1511 uint16 *wr = (uint16*) r; 1512 uint16 *wg = (uint16*) g; 1513 uint16 *wb = (uint16*) b; 1514 uint16 *wa = (uint16*) a; 1515 1516 (void) img; (void) y; 1517 while (h-- > 0) { 1518 for (x = 0; x < w; x++) 1519 *cp++ = PACKW4(*wr++, *wg++, *wb++, *wa++); 1520 SKEW4(wr, wg, wb, wa, fromskew); 1521 cp += toskew; 1522 } 1476 uint16 *wr = (uint16*) r; 1477 uint16 *wg = (uint16*) g; 1478 uint16 *wb = (uint16*) b; 1479 uint16 *wa = (uint16*) a; 1480 (void) img; (void) y; 1481 while (h-- > 0) { 1482 for (x = 0; x < w; x++) 1483 *cp++ = PACKW4(*wr++,*wg++,*wb++,*wa++); 1484 SKEW4(wr, wg, wb, wa, fromskew); 1485 cp += toskew; 1486 } 1523 1487 } 1524 1488 … … 1528 1492 DECLARESepPutFunc(putRGBUAseparate16bittile) 1529 1493 { 1530 uint16 *wr = (uint16*) r; 1531 uint16 *wg = (uint16*) g; 1532 uint16 *wb = (uint16*) b; 1533 uint16 *wa = (uint16*) a; 1534 1535 (void) img; (void) y; 1536 while (h-- > 0) { 1537 uint32 r,g,b,a; 1538 /* 1539 * We shift alpha down four bits just in case unsigned 1540 * arithmetic doesn't handle the full range. 1541 * We still have plenty of accuracy, since the output is 8 bits. 1542 * So we have (r * 0xffff) * (a * 0xfff)) = r*a * (0xffff*0xfff) 1543 * Since we want r*a * 0xff for eight bit output, 1544 * we divide by (0xffff * 0xfff) / 0xff == 0x10eff. 1545 */ 1546 for (x = w; x-- > 0;) { 1547 a = *wa++ >> 4; 1548 r = (*wr++ * a) / 0x10eff; 1549 g = (*wg++ * a) / 0x10eff; 1550 b = (*wb++ * a) / 0x10eff; 1551 *cp++ = PACK4(r,g,b,a); 1552 } 1553 SKEW4(wr, wg, wb, wa, fromskew); 1554 cp += toskew; 1555 } 1494 uint16 *wr = (uint16*) r; 1495 uint16 *wg = (uint16*) g; 1496 uint16 *wb = (uint16*) b; 1497 uint16 *wa = (uint16*) a; 1498 (void) img; (void) y; 1499 while (h-- > 0) { 1500 uint32 r,g,b,a; 1501 for (x = w; x-- > 0;) { 1502 a = W2B(*wa++); 1503 r = (a*W2B(*wr++) + 127) / 255; 1504 g = (a*W2B(*wg++) + 127) / 255; 1505 b = (a*W2B(*wb++) + 127) / 255; 1506 *cp++ = PACK4(r,g,b,a); 1507 } 1508 SKEW4(wr, wg, wb, wa, fromskew); 1509 cp += toskew; 1510 } 1556 1511 } 1557 1512 … … 1891 1846 DECLAREContigPutFunc(putcontig8bitYCbCr22tile) 1892 1847 { 1893 uint32* cp1 = cp+w+toskew; 1894 int32 incr = 2*toskew+w; 1895 1896 (void) y; 1897 fromskew = (fromskew * 6) / 2; 1898 if ((h & 1) == 0 && (w & 1) == 0) { 1899 for (; h >= 2; h -= 2) { 1900 x = w>>1; 1901 do { 1902 int32 Cb = pp[4]; 1903 int32 Cr = pp[5]; 1904 1905 YCbCrtoRGB(cp [0], pp[0]); 1906 YCbCrtoRGB(cp [1], pp[1]); 1907 YCbCrtoRGB(cp1[0], pp[2]); 1908 YCbCrtoRGB(cp1[1], pp[3]); 1909 1910 cp += 2, cp1 += 2; 1911 pp += 6; 1912 } while (--x); 1913 cp += incr, cp1 += incr; 1914 pp += fromskew; 1915 } 1916 } else { 1917 while (h > 0) { 1918 for (x = w; x > 0;) { 1919 int32 Cb = pp[4]; 1920 int32 Cr = pp[5]; 1921 switch (x) { 1922 default: 1923 switch (h) { 1924 default: YCbCrtoRGB(cp1[1], pp[ 3]); /* FALLTHROUGH */ 1925 case 1: YCbCrtoRGB(cp [1], pp[ 1]); /* FALLTHROUGH */ 1926 } /* FALLTHROUGH */ 1927 case 1: 1928 switch (h) { 1929 default: YCbCrtoRGB(cp1[0], pp[ 2]); /* FALLTHROUGH */ 1930 case 1: YCbCrtoRGB(cp [0], pp[ 0]); /* FALLTHROUGH */ 1931 } /* FALLTHROUGH */ 1932 } 1933 if (x < 2) { 1934 cp += x; cp1 += x; 1935 x = 0; 1936 } 1937 else { 1938 cp += 2; cp1 += 2; 1939 x -= 2; 1940 } 1941 pp += 6; 1942 } 1943 if (h <= 2) 1944 break; 1945 h -= 2; 1946 cp += incr, cp1 += incr; 1947 pp += fromskew; 1948 } 1949 } 1848 uint32* cp2; 1849 (void) y; 1850 fromskew = (fromskew / 2) * 6; 1851 cp2 = cp+w+toskew; 1852 while (h>=2) { 1853 x = w; 1854 while (x>=2) { 1855 uint32 Cb = pp[4]; 1856 uint32 Cr = pp[5]; 1857 YCbCrtoRGB(cp[0], pp[0]); 1858 YCbCrtoRGB(cp[1], pp[1]); 1859 YCbCrtoRGB(cp2[0], pp[2]); 1860 YCbCrtoRGB(cp2[1], pp[3]); 1861 cp += 2; 1862 cp2 += 2; 1863 pp += 6; 1864 x -= 2; 1865 } 1866 if (x==1) { 1867 uint32 Cb = pp[4]; 1868 uint32 Cr = pp[5]; 1869 YCbCrtoRGB(cp[0], pp[0]); 1870 YCbCrtoRGB(cp2[0], pp[2]); 1871 cp ++ ; 1872 cp2 ++ ; 1873 pp += 6; 1874 } 1875 cp += toskew*2+w; 1876 cp2 += toskew*2+w; 1877 pp += fromskew; 1878 h-=2; 1879 } 1880 if (h==1) { 1881 x = w; 1882 while (x>=2) { 1883 uint32 Cb = pp[4]; 1884 uint32 Cr = pp[5]; 1885 YCbCrtoRGB(cp[0], pp[0]); 1886 YCbCrtoRGB(cp[1], pp[1]); 1887 cp += 2; 1888 cp2 += 2; 1889 pp += 6; 1890 x -= 2; 1891 } 1892 if (x==1) { 1893 uint32 Cb = pp[4]; 1894 uint32 Cr = pp[5]; 1895 YCbCrtoRGB(cp[0], pp[0]); 1896 } 1897 } 1950 1898 } 1951 1899 … … 1955 1903 DECLAREContigPutFunc(putcontig8bitYCbCr21tile) 1956 1904 { 1957 (void) y; 1958 fromskew = (fromskew * 4) / 2; 1959 do { 1960 x = w>>1; 1905 (void) y; 1906 fromskew = (fromskew * 4) / 2; 1961 1907 do { 1962 int32 Cb = pp[2]; 1963 int32 Cr = pp[3]; 1964 1965 YCbCrtoRGB(cp[0], pp[0]); 1966 YCbCrtoRGB(cp[1], pp[1]); 1967 1968 cp += 2; 1969 pp += 4; 1970 } while (--x); 1971 1972 if( (w&1) != 0 ) 1973 { 1974 int32 Cb = pp[2]; 1975 int32 Cr = pp[3]; 1976 1977 YCbCrtoRGB(cp [0], pp[0]); 1978 1979 cp += 1; 1980 pp += 4; 1981 } 1982 1983 cp += toskew; 1984 pp += fromskew; 1985 } while (--h); 1908 x = w>>1; 1909 do { 1910 int32 Cb = pp[2]; 1911 int32 Cr = pp[3]; 1912 1913 YCbCrtoRGB(cp[0], pp[0]); 1914 YCbCrtoRGB(cp[1], pp[1]); 1915 1916 cp += 2; 1917 pp += 4; 1918 } while (--x); 1919 1920 if( (w&1) != 0 ) 1921 { 1922 int32 Cb = pp[2]; 1923 int32 Cr = pp[3]; 1924 1925 YCbCrtoRGB(cp[0], pp[0]); 1926 1927 cp += 1; 1928 pp += 4; 1929 } 1930 1931 cp += toskew; 1932 pp += fromskew; 1933 } while (--h); 1934 } 1935 1936 /* 1937 * 8-bit packed YCbCr samples w/ 1,2 subsampling => RGB 1938 */ 1939 DECLAREContigPutFunc(putcontig8bitYCbCr12tile) 1940 { 1941 uint32* cp2; 1942 (void) y; 1943 fromskew = (fromskew / 2) * 4; 1944 cp2 = cp+w+toskew; 1945 while (h>=2) { 1946 x = w; 1947 do { 1948 uint32 Cb = pp[2]; 1949 uint32 Cr = pp[3]; 1950 YCbCrtoRGB(cp[0], pp[0]); 1951 YCbCrtoRGB(cp2[0], pp[1]); 1952 cp ++; 1953 cp2 ++; 1954 pp += 4; 1955 } while (--x); 1956 cp += toskew*2+w; 1957 cp2 += toskew*2+w; 1958 pp += fromskew; 1959 h-=2; 1960 } 1961 if (h==1) { 1962 x = w; 1963 do { 1964 uint32 Cb = pp[2]; 1965 uint32 Cr = pp[3]; 1966 YCbCrtoRGB(cp[0], pp[0]); 1967 cp ++; 1968 pp += 4; 1969 } while (--x); 1970 } 1986 1971 } 1987 1972 … … 1991 1976 DECLAREContigPutFunc(putcontig8bitYCbCr11tile) 1992 1977 { 1993 (void) y; 1994 fromskew *= 3; 1995 do { 1996 x = w; /* was x = w>>1; patched 2000/09/25 warmerda@home.com */ 1978 (void) y; 1979 fromskew *= 3; 1997 1980 do { 1998 int32 Cb = pp[1]; 1999 int32 Cr = pp[2]; 2000 2001 YCbCrtoRGB(*cp++, pp[0]); 2002 2003 pp += 3; 2004 } while (--x); 2005 cp += toskew; 2006 pp += fromskew; 2007 } while (--h); 2008 } 2009 #undef YCbCrtoRGB 2010 2011 static tileContigRoutine 1981 x = w; /* was x = w>>1; patched 2000/09/25 warmerda@home.com */ 1982 do { 1983 int32 Cb = pp[1]; 1984 int32 Cr = pp[2]; 1985 1986 YCbCrtoRGB(*cp++, pp[0]); 1987 1988 pp += 3; 1989 } while (--x); 1990 cp += toskew; 1991 pp += fromskew; 1992 } while (--h); 1993 } 1994 1995 /* 1996 * 8-bit packed YCbCr samples w/ no subsampling => RGB 1997 */ 1998 DECLARESepPutFunc(putseparate8bitYCbCr11tile) 1999 { 2000 (void) y; 2001 (void) a; 2002 /* TODO: naming of input vars is still off, change obfuscating declaration inside define, or resolve obfuscation */ 2003 while (h-- > 0) { 2004 x = w; 2005 do { 2006 uint32 dr, dg, db; 2007 TIFFYCbCrtoRGB(img->ycbcr,*r++,*g++,*b++,&dr,&dg,&db); 2008 *cp++ = PACK(dr,dg,db); 2009 } while (--x); 2010 SKEW(r, g, b, fromskew); 2011 cp += toskew; 2012 } 2013 } 2014 #undef YCbCrtoRGB 2015 2016 static int 2012 2017 initYCbCrConversion(TIFFRGBAImage* img) 2013 2018 { 2014 static char module[] = "init CIELabConversion";2019 static char module[] = "initYCbCrConversion"; 2015 2020 2016 2021 float *luma, *refBlackWhite; 2017 uint16 hs, vs;2018 2022 2019 2023 if (img->ycbcr == NULL) { 2020 2024 img->ycbcr = (TIFFYCbCrToRGB*) _TIFFmalloc( 2021 2025 TIFFroundup(sizeof (TIFFYCbCrToRGB), sizeof (long)) 2022 2026 + 4*256*sizeof (TIFFRGBValue) 2023 2027 + 2*256*sizeof (int) 2024 2028 + 3*256*sizeof (int32) 2025 );2026 2029 ); 2030 if (img->ycbcr == NULL) { 2027 2031 TIFFErrorExt(img->tif->tif_clientdata, module, 2028 2029 return (NULL);2030 2032 "No space for YCbCr->RGB conversion state"); 2033 return (0); 2034 } 2031 2035 } 2032 2036 2033 2037 TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRCOEFFICIENTS, &luma); 2034 2038 TIFFGetFieldDefaulted(img->tif, TIFFTAG_REFERENCEBLACKWHITE, 2035 2039 &refBlackWhite); 2036 2040 if (TIFFYCbCrToRGBInit(img->ycbcr, luma, refBlackWhite) < 0) 2037 return NULL; 2038 2039 /* 2040 * The 6.0 spec says that subsampling must be 2041 * one of 1, 2, or 4, and that vertical subsampling 2042 * must always be <= horizontal subsampling; so 2043 * there are only a few possibilities and we just 2044 * enumerate the cases. 2045 */ 2046 TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &hs, &vs); 2047 switch ((hs<<4)|vs) { 2048 case 0x44: return (putcontig8bitYCbCr44tile); 2049 case 0x42: return (putcontig8bitYCbCr42tile); 2050 case 0x41: return (putcontig8bitYCbCr41tile); 2051 case 0x22: return (putcontig8bitYCbCr22tile); 2052 case 0x21: return (putcontig8bitYCbCr21tile); 2053 case 0x11: return (putcontig8bitYCbCr11tile); 2054 } 2055 2056 return (NULL); 2041 return(0); 2042 return (1); 2057 2043 } 2058 2044 … … 2328 2314 */ 2329 2315 static int 2330 pickTileContigCase(TIFFRGBAImage* img) 2331 { 2332 tileContigRoutine put = 0; 2333 2334 if (buildMap(img)) { 2316 PickContigCase(TIFFRGBAImage* img) 2317 { 2318 img->get = TIFFIsTiled(img->tif) ? gtTileContig : gtStripContig; 2319 img->put.contig = NULL; 2335 2320 switch (img->photometric) { 2336 case PHOTOMETRIC_RGB: 2337 switch (img->bitspersample) { 2338 case 8: 2339 if (!img->Map) { 2340 if (img->alpha == EXTRASAMPLE_ASSOCALPHA) 2341 put = putRGBAAcontig8bittile; 2342 else if (img->alpha == EXTRASAMPLE_UNASSALPHA) 2343 put = putRGBUAcontig8bittile; 2344 else 2345 put = putRGBcontig8bittile; 2346 } else 2347 put = putRGBcontig8bitMaptile; 2348 break; 2349 case 16: 2350 put = putRGBcontig16bittile; 2351 if (!img->Map) { 2352 if (img->alpha == EXTRASAMPLE_ASSOCALPHA) 2353 put = putRGBAAcontig16bittile; 2354 else if (img->alpha == EXTRASAMPLE_UNASSALPHA) 2355 put = putRGBUAcontig16bittile; 2356 } 2357 break; 2358 } 2359 break; 2360 case PHOTOMETRIC_SEPARATED: 2361 if (img->bitspersample == 8) { 2362 if (!img->Map) 2363 put = putRGBcontig8bitCMYKtile; 2364 else 2365 put = putRGBcontig8bitCMYKMaptile; 2366 } 2367 break; 2368 case PHOTOMETRIC_PALETTE: 2369 switch (img->bitspersample) { 2370 case 8: put = put8bitcmaptile; break; 2371 case 4: put = put4bitcmaptile; break; 2372 case 2: put = put2bitcmaptile; break; 2373 case 1: put = put1bitcmaptile; break; 2374 } 2375 break; 2376 case PHOTOMETRIC_MINISWHITE: 2377 case PHOTOMETRIC_MINISBLACK: 2378 switch (img->bitspersample) { 2379 case 16: put = put16bitbwtile; break; 2380 case 8: put = putgreytile; break; 2381 case 4: put = put4bitbwtile; break; 2382 case 2: put = put2bitbwtile; break; 2383 case 1: put = put1bitbwtile; break; 2384 } 2385 break; 2386 case PHOTOMETRIC_YCBCR: 2387 if (img->bitspersample == 8) 2388 put = initYCbCrConversion(img); 2389 break; 2390 case PHOTOMETRIC_CIELAB: 2391 if (img->bitspersample == 8) 2392 put = initCIELabConversion(img); 2393 break; 2394 } 2395 } 2396 return ((img->put.contig = put) != 0); 2321 case PHOTOMETRIC_RGB: 2322 switch (img->bitspersample) { 2323 case 8: 2324 if (img->alpha == EXTRASAMPLE_ASSOCALPHA) 2325 img->put.contig = putRGBAAcontig8bittile; 2326 else if (img->alpha == EXTRASAMPLE_UNASSALPHA) 2327 { 2328 img->put.contig = putRGBUAcontig8bittile; 2329 } 2330 else 2331 img->put.contig = putRGBcontig8bittile; 2332 break; 2333 case 16: 2334 if (img->alpha == EXTRASAMPLE_ASSOCALPHA) 2335 { 2336 img->put.contig = putRGBAAcontig16bittile; 2337 } 2338 else if (img->alpha == EXTRASAMPLE_UNASSALPHA) 2339 { 2340 img->put.contig = putRGBUAcontig16bittile; 2341 } 2342 else 2343 { 2344 img->put.contig = putRGBcontig16bittile; 2345 } 2346 break; 2347 } 2348 break; 2349 case PHOTOMETRIC_SEPARATED: 2350 if (buildMap(img)) { 2351 if (img->bitspersample == 8) { 2352 if (!img->Map) 2353 img->put.contig = putRGBcontig8bitCMYKtile; 2354 else 2355 img->put.contig = putRGBcontig8bitCMYKMaptile; 2356 } 2357 } 2358 break; 2359 case PHOTOMETRIC_PALETTE: 2360 if (buildMap(img)) { 2361 switch (img->bitspersample) { 2362 case 8: 2363 img->put.contig = put8bitcmaptile; 2364 break; 2365 case 4: 2366 img->put.contig = put4bitcmaptile; 2367 break; 2368 case 2: 2369 img->put.contig = put2bitcmaptile; 2370 break; 2371 case 1: 2372 img->put.contig = put1bitcmaptile; 2373 break; 2374 } 2375 } 2376 break; 2377 case PHOTOMETRIC_MINISWHITE: 2378 case PHOTOMETRIC_MINISBLACK: 2379 if (buildMap(img)) { 2380 switch (img->bitspersample) { 2381 case 16: 2382 img->put.contig = put16bitbwtile; 2383 break; 2384 case 8: 2385 img->put.contig = putgreytile; 2386 break; 2387 case 4: 2388 img->put.contig = put4bitbwtile; 2389 break; 2390 case 2: 2391 img->put.contig = put2bitbwtile; 2392 break; 2393 case 1: 2394 img->put.contig = put1bitbwtile; 2395 break; 2396 } 2397 } 2398 break; 2399 case PHOTOMETRIC_YCBCR: 2400 if (img->bitspersample == 8) 2401 { 2402 if (initYCbCrConversion(img)!=0) 2403 { 2404 /* 2405 * The 6.0 spec says that subsampling must be 2406 * one of 1, 2, or 4, and that vertical subsampling 2407 * must always be <= horizontal subsampling; so 2408 * there are only a few possibilities and we just 2409 * enumerate the cases. 2410 * Joris: added support for the [1,2] case, nonetheless, to accomodate 2411 * some OJPEG files 2412 */ 2413 uint16 SubsamplingHor; 2414 uint16 SubsamplingVer; 2415 TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &SubsamplingHor, &SubsamplingVer); 2416 switch ((SubsamplingHor<<4)|SubsamplingVer) { 2417 case 0x44: 2418 img->put.contig = putcontig8bitYCbCr44tile; 2419 break; 2420 case 0x42: 2421 img->put.contig = putcontig8bitYCbCr42tile; 2422 break; 2423 case 0x41: 2424 img->put.contig = putcontig8bitYCbCr41tile; 2425 break; 2426 case 0x22: 2427 img->put.contig = putcontig8bitYCbCr22tile; 2428 break; 2429 case 0x21: 2430 img->put.contig = putcontig8bitYCbCr21tile; 2431 break; 2432 case 0x12: 2433 img->put.contig = putcontig8bitYCbCr12tile; 2434 break; 2435 case 0x11: 2436 img->put.contig = putcontig8bitYCbCr11tile; 2437 break; 2438 } 2439 } 2440 } 2441 break; 2442 case PHOTOMETRIC_CIELAB: 2443 if (buildMap(img)) { 2444 if (img->bitspersample == 8) 2445 img->put.contig = initCIELabConversion(img); 2446 break; 2447 } 2448 } 2449 return ((img->get!=NULL) && (img->put.contig!=NULL)); 2397 2450 } 2398 2451 … … 2404 2457 */ 2405 2458 static int 2406 pickTileSeparateCase(TIFFRGBAImage* img) 2407 { 2408 tileSeparateRoutine put = 0; 2409 2410 if (buildMap(img)) { 2459 PickSeparateCase(TIFFRGBAImage* img) 2460 { 2461 img->get = TIFFIsTiled(img->tif) ? gtTileSeparate : gtStripSeparate; 2462 img->put.separate = NULL; 2411 2463 switch (img->photometric) { 2412 case PHOTOMETRIC_RGB: 2413 switch (img->bitspersample) { 2414 case 8: 2415 if (!img->Map) { 2416 if (img->alpha == EXTRASAMPLE_ASSOCALPHA) 2417 put = putRGBAAseparate8bittile; 2418 else if (img->alpha == EXTRASAMPLE_UNASSALPHA) 2419 put = putRGBUAseparate8bittile; 2420 else 2421 put = putRGBseparate8bittile; 2422 } else 2423 put = putRGBseparate8bitMaptile; 2424 break; 2425 case 16: 2426 put = putRGBseparate16bittile; 2427 if (!img->Map) { 2428 if (img->alpha == EXTRASAMPLE_ASSOCALPHA) 2429 put = putRGBAAseparate16bittile; 2430 else if (img->alpha == EXTRASAMPLE_UNASSALPHA) 2431 put = putRGBUAseparate16bittile; 2432 } 2433 break; 2434 } 2435 break; 2436 } 2437 } 2438 return ((img->put.separate = put) != 0); 2464 case PHOTOMETRIC_RGB: 2465 switch (img->bitspersample) { 2466 case 8: 2467 if (img->alpha == EXTRASAMPLE_ASSOCALPHA) 2468 img->put.separate = putRGBAAseparate8bittile; 2469 else if (img->alpha == EXTRASAMPLE_UNASSALPHA) 2470 { 2471 img->put.separate = putRGBUAseparate8bittile; 2472 } 2473 else 2474 img->put.separate = putRGBseparate8bittile; 2475 break; 2476 case 16: 2477 if (img->alpha == EXTRASAMPLE_ASSOCALPHA) 2478 { 2479 img->put.separate = putRGBAAseparate16bittile; 2480 } 2481 else if (img->alpha == EXTRASAMPLE_UNASSALPHA) 2482 { 2483 img->put.separate = putRGBUAseparate16bittile; 2484 } 2485 else 2486 { 2487 img->put.separate = putRGBseparate16bittile; 2488 } 2489 break; 2490 } 2491 break; 2492 case PHOTOMETRIC_YCBCR: 2493 if ((img->bitspersample==8) && (img->samplesperpixel==3)) 2494 { 2495 if (initYCbCrConversion(img)!=0) 2496 { 2497 uint16 hs, vs; 2498 TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &hs, &vs); 2499 switch ((hs<<4)|vs) { 2500 case 0x11: 2501 img->put.separate = putseparate8bitYCbCr11tile; 2502 break; 2503 /* TODO: add other cases here */ 2504 } 2505 } 2506 } 2507 break; 2508 } 2509 return ((img->get!=NULL) && (img->put.separate!=NULL)); 2439 2510 } 2440 2511 … … 2485 2556 TIFFRGBAImageEnd(&img); 2486 2557 } else { 2487 TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), emsg);2558 TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg); 2488 2559 ok = 0; 2489 2560 } … … 2537 2608 if (!TIFFRGBAImageOK(tif, emsg) 2538 2609 || !TIFFRGBAImageBegin(&img, tif, 0, emsg)) { 2539 TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), emsg);2610 TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg); 2540 2611 return( 0 ); 2541 2612 } -
trunk/src/3rdparty/libtiff/libtiff/tif_jpeg.c
r2 r846 1 /* $Id: tif_jpeg.c,v 1. 45 2006/03/16 12:38:24 dron Exp $ */1 /* $Id: tif_jpeg.c,v 1.50.2.4 2009-08-30 16:21:46 bfriesen Exp $ */ 2 2 3 3 /* … … 153 153 TIFFVGetMethod vgetparent; /* super-class method */ 154 154 TIFFVSetMethod vsetparent; /* super-class method */ 155 TIFFPrintMethod printdir; /* super-class method */ 155 156 TIFFStripMethod defsparent; /* super-class method */ 156 157 TIFFTileMethod deftparent; /* super-class method */ … … 226 227 227 228 (*cinfo->err->format_message) (cinfo, buffer); 228 TIFFErrorExt(sp->tif->tif_clientdata, "JPEGLib", buffer); /* display the error message */229 TIFFErrorExt(sp->tif->tif_clientdata, "JPEGLib", "%s", buffer); /* display the error message */ 229 230 jpeg_abort(cinfo); /* clean up libjpeg state */ 230 231 LONGJMP(sp->exit_jmpbuf, 1); /* return to libtiff caller */ … … 242 243 243 244 (*cinfo->err->format_message) (cinfo, buffer); 244 TIFFWarningExt(((JPEGState *) cinfo)->tif->tif_clientdata, "JPEGLib", buffer);245 TIFFWarningExt(((JPEGState *) cinfo)->tif->tif_clientdata, "JPEGLib", "%s", buffer); 245 246 } 246 247 … … 713 714 if (segment_height > td->td_rowsperstrip) 714 715 segment_height = td->td_rowsperstrip; 715 sp->bytesperline = TIFF ScanlineSize(tif);716 sp->bytesperline = TIFFOldScanlineSize(tif); 716 717 } 717 718 if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s > 0) { … … 723 724 segment_height = TIFFhowmany(segment_height, sp->v_sampling); 724 725 } 725 if (sp->cinfo.d.image_width !=segment_width ||726 sp->cinfo.d.image_height !=segment_height) {726 if (sp->cinfo.d.image_width < segment_width || 727 sp->cinfo.d.image_height < segment_height) { 727 728 TIFFWarningExt(tif->tif_clientdata, module, 728 "Improper JPEG strip/tile size, expected %dx%d, got %dx%d", 729 segment_width, 730 segment_height, 731 sp->cinfo.d.image_width, 732 sp->cinfo.d.image_height); 729 "Improper JPEG strip/tile size, " 730 "expected %dx%d, got %dx%d", 731 segment_width, segment_height, 732 sp->cinfo.d.image_width, 733 sp->cinfo.d.image_height); 734 } 735 if (sp->cinfo.d.image_width > segment_width || 736 sp->cinfo.d.image_height > segment_height) { 737 /* 738 * This case could be dangerous, if the strip or tile size has 739 * been reported as less than the amount of data jpeg will 740 * return, some potential security issues arise. Catch this 741 * case and error out. 742 */ 743 TIFFErrorExt(tif->tif_clientdata, module, 744 "JPEG strip/tile size exceeds expected dimensions," 745 " expected %dx%d, got %dx%d", 746 segment_width, segment_height, 747 sp->cinfo.d.image_width, sp->cinfo.d.image_height); 748 return (0); 733 749 } 734 750 if (sp->cinfo.d.num_components != … … 761 777 sp->cinfo.d.comp_info[0].v_samp_factor, 762 778 sp->h_sampling, sp->v_sampling); 779 780 /* 781 * There are potential security issues here 782 * for decoders that have already allocated 783 * buffers based on the expected sampling 784 * factors. Lets check the sampling factors 785 * dont exceed what we were expecting. 786 */ 787 if (sp->cinfo.d.comp_info[0].h_samp_factor 788 > sp->h_sampling 789 || sp->cinfo.d.comp_info[0].v_samp_factor 790 > sp->v_sampling) { 791 TIFFErrorExt(tif->tif_clientdata, 792 module, 793 "Cannot honour JPEG sampling factors" 794 " that exceed those specified."); 795 return (0); 796 } 763 797 764 798 /* … … 951 985 JPEGDecodeRaw(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s) 952 986 { 953 954 955 956 957 958 959 960 JDIMENSION clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width; 961 962 987 JPEGState *sp = JState(tif); 988 tsize_t nrows; 989 (void) s; 990 991 /* data is expected to be read in multiples of a scanline */ 992 if ( (nrows = sp->cinfo.d.image_height) ) { 993 /* Cb,Cr both have sampling factors 1, so this is correct */ 994 JDIMENSION clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width; 995 int samples_per_clump = sp->samplesperclump; 996 963 997 #ifdef JPEG_LIB_MK1 964 965 966 998 unsigned short* tmpbuf = _TIFFmalloc(sizeof(unsigned short) * 999 sp->cinfo.d.output_width * 1000 sp->cinfo.d.num_components); 967 1001 #endif 968 969 do { 970 jpeg_component_info *compptr; 971 int ci, clumpoffset; 972 973 /* Reload downsampled-data buffer if needed */ 974 if (sp->scancount >= DCTSIZE) { 975 int n = sp->cinfo.d.max_v_samp_factor * DCTSIZE; 976 if (TIFFjpeg_read_raw_data(sp, sp->ds_buffer, n) 977 != n) 978 return (0); 979 sp->scancount = 0; 980 } 981 /* 982 * Fastest way to unseparate data is to make one pass 983 * over the scanline for each row of each component. 984 */ 985 clumpoffset = 0; /* first sample in clump */ 986 for (ci = 0, compptr = sp->cinfo.d.comp_info; 987 ci < sp->cinfo.d.num_components; 988 ci++, compptr++) { 989 int hsamp = compptr->h_samp_factor; 990 int vsamp = compptr->v_samp_factor; 991 int ypos; 992 993 for (ypos = 0; ypos < vsamp; ypos++) { 994 JSAMPLE *inptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos]; 1002 1003 do { 1004 jpeg_component_info *compptr; 1005 int ci, clumpoffset; 1006 1007 /* Reload downsampled-data buffer if needed */ 1008 if (sp->scancount >= DCTSIZE) { 1009 int n = sp->cinfo.d.max_v_samp_factor * DCTSIZE; 1010 if (TIFFjpeg_read_raw_data(sp, sp->ds_buffer, n) != n) 1011 return (0); 1012 sp->scancount = 0; 1013 } 1014 /* 1015 * Fastest way to unseparate data is to make one pass 1016 * over the scanline for each row of each component. 1017 */ 1018 clumpoffset = 0; /* first sample in clump */ 1019 for (ci = 0, compptr = sp->cinfo.d.comp_info; 1020 ci < sp->cinfo.d.num_components; 1021 ci++, compptr++) { 1022 int hsamp = compptr->h_samp_factor; 1023 int vsamp = compptr->v_samp_factor; 1024 int ypos; 1025 1026 for (ypos = 0; ypos < vsamp; ypos++) { 1027 JSAMPLE *inptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos]; 995 1028 #ifdef JPEG_LIB_MK1 996 1029 JSAMPLE *outptr = (JSAMPLE*)tmpbuf + clumpoffset; 997 1030 #else 998 1031 JSAMPLE *outptr = (JSAMPLE*)buf + clumpoffset; 999 1032 #endif 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1033 JDIMENSION nclump; 1034 1035 if (hsamp == 1) { 1036 /* fast path for at least Cb and Cr */ 1037 for (nclump = clumps_per_line; nclump-- > 0; ) { 1038 outptr[0] = *inptr++; 1039 outptr += samples_per_clump; 1040 } 1041 } else { 1042 int xpos; 1043 1044 /* general case */ 1045 for (nclump = clumps_per_line; nclump-- > 0; ) { 1046 for (xpos = 0; xpos < hsamp; xpos++) 1047 outptr[xpos] = *inptr++; 1048 outptr += samples_per_clump; 1049 } 1050 } 1051 clumpoffset += hsamp; 1052 } 1053 } 1021 1054 1022 1055 #ifdef JPEG_LIB_MK1 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1056 { 1057 if (sp->cinfo.d.data_precision == 8) 1058 { 1059 int i=0; 1060 int len = sp->cinfo.d.output_width * sp->cinfo.d.num_components; 1061 for (i=0; i<len; i++) 1062 { 1063 ((unsigned char*)buf)[i] = tmpbuf[i] & 0xff; 1064 } 1065 } 1066 else 1067 { // 12-bit 1068 int value_pairs = (sp->cinfo.d.output_width 1069 * sp->cinfo.d.num_components) / 2; 1070 int iPair; 1071 for( iPair = 0; iPair < value_pairs; iPair++ ) 1072 { 1073 unsigned char *out_ptr = ((unsigned char *) buf) + iPair * 3; 1074 JSAMPLE *in_ptr = tmpbuf + iPair * 2; 1075 out_ptr[0] = (in_ptr[0] & 0xff0) >> 4; 1076 out_ptr[1] = ((in_ptr[0] & 0xf) << 4) 1077 | ((in_ptr[1] & 0xf00) >> 8); 1078 out_ptr[2] = ((in_ptr[1] & 0xff) >> 0); 1079 } 1080 } 1081 } 1049 1082 #endif 1050 1083 1051 ++sp->scancount; 1052 ++tif->tif_row; 1053 buf += sp->bytesperline; 1054 cc -= sp->bytesperline; 1055 } while (--nrows > 0); 1056 1084 sp->scancount ++; 1085 tif->tif_row += sp->v_sampling; 1086 /* increment/decrement of buf and cc is still incorrect, but should not matter 1087 * TODO: resolve this */ 1088 buf += sp->bytesperline; 1089 cc -= sp->bytesperline; 1090 nrows -= sp->v_sampling; 1091 } while (nrows > 0); 1092 1057 1093 #ifdef JPEG_LIB_MK1 1058 1094 _TIFFfree(tmpbuf); 1059 1095 #endif 1060 1096 1061 1062 1063 1064 1065 1097 } 1098 1099 /* Close down the decompressor if done. */ 1100 return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height 1101 || TIFFjpeg_finish_decompress(sp); 1066 1102 } 1067 1103 … … 1198 1234 if (td->td_bitspersample != 8 && td->td_bitspersample != 12) 1199 1235 #else 1200 if (td->td_bitspersample != BITS_IN_JSAMPLE ) 1236 if (td->td_bitspersample != BITS_IN_JSAMPLE ) 1201 1237 #endif 1202 1238 { 1203 1239 TIFFErrorExt(tif->tif_clientdata, module, "BitsPerSample %d not allowed for JPEG", 1204 1240 (int) td->td_bitspersample); … … 1278 1314 if (segment_height > td->td_rowsperstrip) 1279 1315 segment_height = td->td_rowsperstrip; 1280 sp->bytesperline = TIFF ScanlineSize(tif);1316 sp->bytesperline = TIFFOldScanlineSize(tif); 1281 1317 } 1282 1318 if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s > 0) { … … 1390 1426 TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline discarded"); 1391 1427 1428 /* The last strip will be limited to image size */ 1429 if( !isTiled(tif) && tif->tif_row+nrows > tif->tif_dir.td_imagelength ) 1430 nrows = tif->tif_dir.td_imagelength - tif->tif_row; 1431 1392 1432 while (nrows-- > 0) { 1393 1433 bufptr[0] = (JSAMPROW) buf; … … 1416 1456 jpeg_component_info* compptr; 1417 1457 int samples_per_clump = sp->samplesperclump; 1458 tsize_t bytesperclumpline; 1418 1459 1419 1460 (void) s; 1420 1461 assert(sp != NULL); 1421 /* data is expected to be supplied in multiples of a scanline */ 1422 nrows = cc / sp->bytesperline; 1423 if (cc % sp->bytesperline) 1462 /* data is expected to be supplied in multiples of a clumpline */ 1463 /* a clumpline is equivalent to v_sampling desubsampled scanlines */ 1464 /* TODO: the following calculation of bytesperclumpline, should substitute calculation of sp->bytesperline, except that it is per v_sampling lines */ 1465 bytesperclumpline = (((sp->cinfo.c.image_width+sp->h_sampling-1)/sp->h_sampling) 1466 *(sp->h_sampling*sp->v_sampling+2)*sp->cinfo.c.data_precision+7) 1467 /8; 1468 1469 nrows = ( cc / bytesperclumpline ) * sp->v_sampling; 1470 if (cc % bytesperclumpline) 1424 1471 TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline discarded"); 1425 1472 … … 1427 1474 clumps_per_line = sp->cinfo.c.comp_info[1].downsampled_width; 1428 1475 1429 while (nrows --> 0) {1476 while (nrows > 0) { 1430 1477 /* 1431 1478 * Fastest way to separate the data is to make one pass … … 1472 1519 sp->scancount = 0; 1473 1520 } 1474 if (nrows > 0) 1475 tif->tif_row++; 1521 tif->tif_row += sp->v_sampling; 1476 1522 buf += sp->bytesperline; 1523 nrows -= sp->v_sampling; 1477 1524 } 1478 1525 return (1); … … 1526 1573 tif->tif_tagmethods.vgetfield = sp->vgetparent; 1527 1574 tif->tif_tagmethods.vsetfield = sp->vsetparent; 1575 tif->tif_tagmethods.printdir = sp->printdir; 1528 1576 1529 1577 if( sp->cinfo_initialized ) … … 1537 1585 } 1538 1586 1539 static int1540 JPEG VSetField(TIFF* tif, ttag_t tag, va_list ap)1587 static void 1588 JPEGResetUpsampled( TIFF* tif ) 1541 1589 { 1542 1590 JPEGState* sp = JState(tif); 1543 1591 TIFFDirectory* td = &tif->tif_dir; 1592 1593 /* 1594 * Mark whether returned data is up-sampled or not so TIFFStripSize 1595 * and TIFFTileSize return values that reflect the true amount of 1596 * data. 1597 */ 1598 tif->tif_flags &= ~TIFF_UPSAMPLED; 1599 if (td->td_planarconfig == PLANARCONFIG_CONTIG) { 1600 if (td->td_photometric == PHOTOMETRIC_YCBCR && 1601 sp->jpegcolormode == JPEGCOLORMODE_RGB) { 1602 tif->tif_flags |= TIFF_UPSAMPLED; 1603 } else { 1604 #ifdef notdef 1605 if (td->td_ycbcrsubsampling[0] != 1 || 1606 td->td_ycbcrsubsampling[1] != 1) 1607 ; /* XXX what about up-sampling? */ 1608 #endif 1609 } 1610 } 1611 1612 /* 1613 * Must recalculate cached tile size in case sampling state changed. 1614 * Should we really be doing this now if image size isn't set? 1615 */ 1616 tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tsize_t) -1; 1617 } 1618 1619 static int 1620 JPEGVSetField(TIFF* tif, ttag_t tag, va_list ap) 1621 { 1622 JPEGState* sp = JState(tif); 1623 const TIFFFieldInfo* fip; 1544 1624 uint32 v32; 1545 1625 … … 1563 1643 case TIFFTAG_JPEGCOLORMODE: 1564 1644 sp->jpegcolormode = va_arg(ap, int); 1565 /* 1566 * Mark whether returned data is up-sampled or not 1567 * so TIFFStripSize and TIFFTileSize return values 1568 * that reflect the true amount of data. 1569 */ 1570 tif->tif_flags &= ~TIFF_UPSAMPLED; 1571 if (td->td_planarconfig == PLANARCONFIG_CONTIG) { 1572 if (td->td_photometric == PHOTOMETRIC_YCBCR && 1573 sp->jpegcolormode == JPEGCOLORMODE_RGB) { 1574 tif->tif_flags |= TIFF_UPSAMPLED; 1575 } else { 1576 if (td->td_ycbcrsubsampling[0] != 1 || 1577 td->td_ycbcrsubsampling[1] != 1) 1578 ; /* XXX what about up-sampling? */ 1579 } 1580 } 1581 /* 1582 * Must recalculate cached tile size 1583 * in case sampling state changed. 1584 */ 1585 tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tsize_t) -1; 1645 JPEGResetUpsampled( tif ); 1586 1646 return (1); /* pseudo tag */ 1647 case TIFFTAG_PHOTOMETRIC: 1648 { 1649 int ret_value = (*sp->vsetparent)(tif, tag, ap); 1650 JPEGResetUpsampled( tif ); 1651 return ret_value; 1652 } 1587 1653 case TIFFTAG_JPEGTABLESMODE: 1588 1654 sp->jpegtablesmode = va_arg(ap, int); … … 1591 1657 /* mark the fact that we have a real ycbcrsubsampling! */ 1592 1658 sp->ycbcrsampling_fetched = 1; 1659 /* should we be recomputing upsampling info here? */ 1593 1660 return (*sp->vsetparent)(tif, tag, ap); 1594 1661 case TIFFTAG_FAXRECVPARAMS: … … 1607 1674 return (*sp->vsetparent)(tif, tag, ap); 1608 1675 } 1609 TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif, tag)->field_bit); 1676 1677 if ((fip = _TIFFFieldWithTag(tif, tag))) { 1678 TIFFSetFieldBit(tif, fip->field_bit); 1679 } else { 1680 return (0); 1681 } 1682 1610 1683 tif->tif_flags |= TIFF_DIRTYDIRECT; 1611 1684 return (1); … … 1703 1776 JPEGFixupTestSubsampling( tif ); 1704 1777 return (*sp->vgetparent)(tif, tag, ap); 1705 break;1706 1778 case TIFFTAG_FAXRECVPARAMS: 1707 1779 *va_arg(ap, uint32*) = sp->recvparams; … … 1797 1869 int decompress; 1798 1870 1799 if( sp->cinfo_initialized ) 1800 return 1; 1871 1872 if(sp->cinfo_initialized) 1873 { 1874 if( force_encode && sp->cinfo.comm.is_decompressor ) 1875 TIFFjpeg_destroy( sp ); 1876 else if( force_decode && !sp->cinfo.comm.is_decompressor ) 1877 TIFFjpeg_destroy( sp ); 1878 else 1879 return 1; 1880 1881 sp->cinfo_initialized = 0; 1882 } 1801 1883 1802 1884 /* … … 1854 1936 1855 1937 /* 1938 * Merge codec-specific tag information. 1939 */ 1940 if (!_TIFFMergeFieldInfo(tif, jpegFieldInfo, N(jpegFieldInfo))) { 1941 TIFFErrorExt(tif->tif_clientdata, 1942 "TIFFInitJPEG", 1943 "Merging JPEG codec-specific tags failed"); 1944 return 0; 1945 } 1946 1947 /* 1856 1948 * Allocate state block so tag methods have storage to record values. 1857 1949 */ … … 1859 1951 1860 1952 if (tif->tif_data == NULL) { 1861 TIFFErrorExt(tif->tif_clientdata, "TIFFInitJPEG", "No space for JPEG state block"); 1862 return (0); 1863 } 1864 _TIFFmemset( tif->tif_data, 0, sizeof(JPEGState)); 1953 TIFFErrorExt(tif->tif_clientdata, 1954 "TIFFInitJPEG", "No space for JPEG state block"); 1955 return 0; 1956 } 1957 _TIFFmemset(tif->tif_data, 0, sizeof(JPEGState)); 1865 1958 1866 1959 sp = JState(tif); … … 1868 1961 1869 1962 /* 1870 * Merge codec-specific tag information and override parent get/set 1871 * field methods. 1963 * Override parent get/set field methods. 1872 1964 */ 1873 _TIFFMergeFieldInfo(tif, jpegFieldInfo, N(jpegFieldInfo));1874 1965 sp->vgetparent = tif->tif_tagmethods.vgetfield; 1875 1966 tif->tif_tagmethods.vgetfield = JPEGVGetField; /* hook for codec tags */ 1876 1967 sp->vsetparent = tif->tif_tagmethods.vsetfield; 1877 1968 tif->tif_tagmethods.vsetfield = JPEGVSetField; /* hook for codec tags */ 1969 sp->printdir = tif->tif_tagmethods.printdir; 1878 1970 tif->tif_tagmethods.printdir = JPEGPrintDir; /* hook for codec tags */ 1879 1971 … … 1941 2033 1942 2034 /* vim: set ts=8 sts=8 sw=8 noet: */ 2035 -
trunk/src/3rdparty/libtiff/libtiff/tif_luv.c
r2 r846 1 /* $Id: tif_luv.c,v 1.17 2006/03/16 12:38:24 dronExp $ */1 /* $Id: tif_luv.c,v 1.17.2.3 2009-06-30 17:06:25 fwarmerdam Exp $ */ 2 2 3 3 /* … … 452 452 tif->tif_rawcc = tif->tif_rawdatasize - occ; 453 453 454 return ( 0);454 return (1); 455 455 } 456 456 … … 497 497 tif->tif_rawcc = tif->tif_rawdatasize - occ; 498 498 499 return ( 0);499 return (1); 500 500 } 501 501 … … 586 586 tif->tif_rawcc = tif->tif_rawdatasize - occ; 587 587 588 return ( 0);588 return (1); 589 589 } 590 590 … … 599 599 600 600 assert(cc%rowlen == 0); 601 while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 0)601 while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) 602 602 bp += rowlen, cc -= rowlen; 603 603 return (cc == 0); … … 614 614 615 615 assert(cc%rowlen == 0); 616 while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 0)616 while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) 617 617 bp += rowlen, cc -= rowlen; 618 618 return (cc == 0); … … 1201 1201 return (0); 1202 1202 } 1203 sp->tbuflen = multiply(td->td_imagewidth, td->td_rowsperstrip); 1203 if( isTiled(tif) ) 1204 sp->tbuflen = multiply(td->td_tilewidth, td->td_tilelength); 1205 else 1206 sp->tbuflen = multiply(td->td_imagewidth, td->td_rowsperstrip); 1204 1207 if (multiply(sp->tbuflen, sizeof (int16)) == 0 || 1205 1208 (sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (int16))) == NULL) { … … 1299 1302 return (0); 1300 1303 } 1301 sp->tbuflen = multiply(td->td_imagewidth, td->td_rowsperstrip); 1304 if( isTiled(tif) ) 1305 sp->tbuflen = multiply(td->td_tilewidth, td->td_tilelength); 1306 else 1307 sp->tbuflen = multiply(td->td_imagewidth, td->td_rowsperstrip); 1302 1308 if (multiply(sp->tbuflen, sizeof (uint32)) == 0 || 1303 1309 (sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (uint32))) == NULL) { … … 1562 1568 1563 1569 /* 1570 * Merge codec-specific tag information. 1571 */ 1572 if (!_TIFFMergeFieldInfo(tif, LogLuvFieldInfo, 1573 TIFFArrayCount(LogLuvFieldInfo))) { 1574 TIFFErrorExt(tif->tif_clientdata, module, 1575 "Merging SGILog codec-specific tags failed"); 1576 return 0; 1577 } 1578 1579 /* 1564 1580 * Allocate state block so tag methods have storage to record values. 1565 1581 */ … … 1588 1604 tif->tif_cleanup = LogLuvCleanup; 1589 1605 1590 /* override SetField so we can handle our private pseudo-tag */1591 _TIFFMergeFieldInfo(tif, LogLuvFieldInfo,1592 TIFFArrayCount(LogLuvFieldInfo));1606 /* 1607 * Override parent get/set field methods. 1608 */ 1593 1609 sp->vgetparent = tif->tif_tagmethods.vgetfield; 1594 1610 tif->tif_tagmethods.vgetfield = LogLuvVGetField; /* hook for codec tags */ -
trunk/src/3rdparty/libtiff/libtiff/tif_lzw.c
r2 r846 1 /* $Id: tif_lzw.c,v 1.2 8 2006/03/16 12:38:24 dronExp $ */1 /* $Id: tif_lzw.c,v 1.29.2.5 2009-06-22 04:57:31 fwarmerdam Exp $ */ 2 2 3 3 /* … … 225 225 sp->dec_codetab = (code_t*)_TIFFmalloc(CSIZE*sizeof (code_t)); 226 226 if (sp->dec_codetab == NULL) { 227 TIFFErrorExt(tif->tif_clientdata, module, "No space for LZW code table"); 227 TIFFErrorExt(tif->tif_clientdata, module, 228 "No space for LZW code table"); 228 229 return (0); 229 230 } … … 238 239 sp->dec_codetab[code].next = NULL; 239 240 } while (code--); 241 /* 242 * Zero-out the unused entries 243 */ 244 _TIFFmemset(&sp->dec_codetab[CODE_CLEAR], 0, 245 (CODE_FIRST - CODE_CLEAR) * sizeof (code_t)); 240 246 } 241 247 return (1); … … 252 258 (void) s; 253 259 assert(sp != NULL); 260 if( sp->dec_codetab == NULL ) 261 { 262 tif->tif_setupdecode( tif ); 263 } 264 254 265 /* 255 266 * Check for old bit-reversed codes. … … 351 362 (void) s; 352 363 assert(sp != NULL); 364 assert(sp->dec_codetab != NULL); 353 365 /* 354 366 * Restart interrupted output operation. … … 409 421 if (code == CODE_CLEAR) { 410 422 free_entp = sp->dec_codetab + CODE_FIRST; 423 _TIFFmemset(free_entp, 0, 424 (CSIZE - CODE_FIRST) * sizeof (code_t)); 411 425 nbits = BITS_MIN; 412 426 nbitsmask = MAXCODE(BITS_MIN); … … 415 429 if (code == CODE_EOI) 416 430 break; 431 if (code == CODE_CLEAR) { 432 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 433 "LZWDecode: Corrupted LZW table at scanline %d", 434 tif->tif_row); 435 return (0); 436 } 417 437 *op++ = (char)code, occ--; 418 438 oldcodep = sp->dec_codetab + code; … … 515 535 if (occ > 0) { 516 536 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 517 "LZWDecode: Not enough data at scanline %d (short % d bytes)",537 "LZWDecode: Not enough data at scanline %d (short %ld bytes)", 518 538 tif->tif_row, occ); 519 539 return (0); … … 605 625 if (code == CODE_CLEAR) { 606 626 free_entp = sp->dec_codetab + CODE_FIRST; 627 _TIFFmemset(free_entp, 0, 628 (CSIZE - CODE_FIRST) * sizeof (code_t)); 607 629 nbits = BITS_MIN; 608 630 nbitsmask = MAXCODE(BITS_MIN); … … 611 633 if (code == CODE_EOI) 612 634 break; 635 if (code == CODE_CLEAR) { 636 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 637 "LZWDecode: Corrupted LZW table at scanline %d", 638 tif->tif_row); 639 return (0); 640 } 613 641 *op++ = code, occ--; 614 642 oldcodep = sp->dec_codetab + code; … … 648 676 oldcodep = codep; 649 677 if (code >= 256) { 678 char *op_orig = op; 650 679 /* 651 680 * Code maps to a string, copy string … … 682 711 do { 683 712 *--tp = codep->value; 684 } while( (codep = codep->next) != NULL );713 } while( (codep = codep->next) != NULL && tp > op_orig); 685 714 } else 686 715 *op++ = code, occ--; … … 698 727 if (occ > 0) { 699 728 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 700 "LZWDecodeCompat: Not enough data at scanline %d (short % d bytes)",729 "LZWDecodeCompat: Not enough data at scanline %d (short %ld bytes)", 701 730 tif->tif_row, occ); 702 731 return (0); … … 735 764 (void) s; 736 765 assert(sp != NULL); 766 767 if( sp->enc_hashtab == NULL ) 768 { 769 tif->tif_setupencode( tif ); 770 } 771 737 772 sp->lzw_nbits = BITS_MIN; 738 773 sp->lzw_maxcode = MAXCODE(BITS_MIN); … … 804 839 if (sp == NULL) 805 840 return (0); 841 842 assert(sp->enc_hashtab != NULL); 843 806 844 /* 807 845 * Load local state. -
trunk/src/3rdparty/libtiff/libtiff/tif_msdos.c
r2 r846 1 /* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_msdos.c,v 1. 2 2005/12/21 12:23:13 jorisExp $ */1 /* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_msdos.c,v 1.3 2006/07/25 18:26:33 fwarmerdam Exp $ */ 2 2 3 3 /* … … 103 103 static const char module[] = "TIFFOpen"; 104 104 int m, fd; 105 TIFF *ret; 105 106 106 107 m = _TIFFgetMode(mode, module); … … 113 114 } 114 115 return (TIFFFdOpen(fd, name, mode)); 116 117 ret = TIFFFdOpen(fd, name, mode); 118 119 if (ret == NULL) close(fd); 120 121 return ret; 115 122 } 116 123 -
trunk/src/3rdparty/libtiff/libtiff/tif_next.c
r2 r846 1 /* $Id: tif_next.c,v 1. 6 2005/12/21 12:23:13 jorisExp $ */1 /* $Id: tif_next.c,v 1.8 2006/10/12 15:00:49 dron Exp $ */ 2 2 3 3 /* … … 49 49 NeXTDecode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s) 50 50 { 51 register unsigned char *bp, *op; 52 register tsize_t cc; 53 register int n; 51 unsigned char *bp, *op; 52 tsize_t cc; 54 53 tidata_t row; 55 tsize_t scanline ;54 tsize_t scanline, n; 56 55 57 56 (void) s; … … 67 66 cc = tif->tif_rawcc; 68 67 scanline = tif->tif_scanlinesize; 69 for (row = buf; (long)occ > 0; occ -= scanline, row += scanline) {68 for (row = buf; occ > 0; occ -= scanline, row += scanline) { 70 69 n = *bp++, cc--; 71 70 switch (n) { … … 81 80 break; 82 81 case LITERALSPAN: { 83 int off;82 tsize_t off; 84 83 /* 85 * The scanline has a literal span 86 * that begins at someoffset.84 * The scanline has a literal span that begins at some 85 * offset. 87 86 */ 88 87 off = (bp[0] * 256) + bp[1]; … … 96 95 } 97 96 default: { 98 register intnpixels = 0, grey;99 u nsigned longimagewidth = tif->tif_dir.td_imagewidth;97 uint32 npixels = 0, grey; 98 uint32 imagewidth = tif->tif_dir.td_imagewidth; 100 99 101 100 /* 102 * The scanline is composed of a sequence 103 * of constant color ``runs''. We shift 104 * into ``run mode'' and interpret bytes 105 * as codes of the form <color><npixels> 106 * until we've filled the scanline. 101 * The scanline is composed of a sequence of constant 102 * color ``runs''. We shift into ``run mode'' and 103 * interpret bytes as codes of the form 104 * <color><npixels> until we've filled the scanline. 107 105 */ 108 106 op = row; … … 110 108 grey = (n>>6) & 0x3; 111 109 n &= 0x3f; 112 while (n-- > 0) 110 /* 111 * Ensure the run does not exceed the scanline 112 * bounds, potentially resulting in a security 113 * issue. 114 */ 115 while (n-- > 0 && npixels < imagewidth) 113 116 SETPIXEL(op, grey); 114 if (npixels >= (int)imagewidth)117 if (npixels >= imagewidth) 115 118 break; 116 119 if (cc == 0) -
trunk/src/3rdparty/libtiff/libtiff/tif_ojpeg.c
r2 r846 1 /* $Id: tif_ojpeg.c,v 1.16 2006/03/01 11:09:13 dron Exp $ */ 1 /* $Id: tif_ojpeg.c,v 1.24.2.4 2009-09-03 20:45:10 bfriesen Exp $ */ 2 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 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 7 to write such files. Writing new-style JPEG compressed TIFFs is implemented 8 in tif_jpeg.c. 9 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 12 fail on some. If you encounter problems, please report them on the TIFF 13 mailing list and/or to Joris Van Damme <info@awaresystems.be>. 14 15 Please read the file called "TIFF Technical Note #2" if you need to be 16 convinced this compression scheme is bad and breaks TIFF. That document 17 is linked to from the LibTiff site <http://www.remotesensing.org/libtiff/> 18 and from AWare Systems' TIFF section 19 <http://www.awaresystems.be/imaging/tiff.html>. It is also absorbed 20 in Adobe's specification supplements, marked "draft" up to this day, but 21 supported by the TIFF community. 22 23 This file interfaces with Release 6B of the JPEG Library written by the 24 Independent JPEG Group. Previous versions of this file required a hack inside 25 the LibJpeg library. This version no longer requires that. Remember to 26 remove the hack if you update from the old version. 27 28 Copyright (c) Joris Van Damme <info@awaresystems.be> 29 Copyright (c) AWare Systems <http://www.awaresystems.be/> 30 31 The licence agreement for this file is the same as the rest of the LibTiff 32 library. 33 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, 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 38 LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 39 OF THIS SOFTWARE. 40 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, 43 contact <info@awaresystems.be>. 44 */ 45 46 /* What is what, and what is not? 47 48 This decoder starts with an input stream, that is essentially the JpegInterchangeFormat 49 stream, if any, followed by the strile data, if any. This stream is read in 50 OJPEGReadByte and related functions. 51 52 It analyzes the start of this stream, until it encounters non-marker data, i.e. 53 compressed image data. Some of the header markers it sees have no actual content, 54 like the SOI marker, and APP/COM markers that really shouldn't even be there. Some 55 other markers do have content, and the valuable bits and pieces of information 56 in these markers are saved, checking all to verify that the stream is more or 57 less within expected bounds. This happens inside the OJPEGReadHeaderInfoSecStreamXxx 58 functions. 59 60 Some OJPEG imagery contains no valid JPEG header markers. This situation is picked 61 up on if we've seen no SOF marker when we're at the start of the compressed image 62 data. In this case, the tables are read from JpegXxxTables tags, and the other 63 bits and pieces of information is initialized to its most basic value. This is 64 implemented in the OJPEGReadHeaderInfoSecTablesXxx functions. 65 66 When this is complete, a good and valid JPEG header can be assembled, and this is 67 passed through to LibJpeg. When that's done, the remainder of the input stream, i.e. 68 the compressed image data, can be passed through unchanged. This is done in 69 OJPEGWriteStream functions. 70 71 LibTiff rightly expects to know the subsampling values before decompression. Just like 72 in new-style JPEG-in-TIFF, though, or even more so, actually, the YCbCrsubsampling 73 tag is notoriously unreliable. To correct these tag values with the ones inside 74 the JPEG stream, the first part of the input stream is pre-scanned in 75 OJPEGSubsamplingCorrect, making no note of any other data, reporting no warnings 76 or errors, up to the point where either these values are read, or it's clear they 77 aren't there. This means that some of the data is read twice, but we feel speed 78 in correcting these values is important enough to warrant this sacrifice. Allthough 79 there is currently no define or other configuration mechanism to disable this behaviour, 80 the actual header scanning is build to robustly respond with error report if it 81 should encounter an uncorrected mismatch of subsampling values. See 82 OJPEGReadHeaderInfoSecStreamSof. 83 84 The restart interval and restart markers are the most tricky part... The restart 85 interval can be specified in a tag. It can also be set inside the input JPEG stream. 86 It can be used inside the input JPEG stream. If reading from strile data, we've 87 consistenly discovered the need to insert restart markers in between the different 88 striles, as is also probably the most likely interpretation of the original TIFF 6.0 89 specification. With all this setting of interval, and actual use of markers that is not 90 predictable at the time of valid JPEG header assembly, the restart thing may turn 91 out the Achilles heel of this implementation. Fortunately, most OJPEG writer vendors 92 succeed in reading back what they write, which may be the reason why we've been able 93 to discover ways that seem to work. 94 95 Some special provision is made for planarconfig separate OJPEG files. These seem 96 to consistently contain header info, a SOS marker, a plane, SOS marker, plane, SOS, 97 and plane. This may or may not be a valid JPEG configuration, we don't know and don't 98 care. We want LibTiff to be able to access the planes individually, without huge 99 buffering inside LibJpeg, anyway. So we compose headers to feed to LibJpeg, in this 100 case, that allow us to pass a single plane such that LibJpeg sees a valid 101 single-channel JPEG stream. Locating subsequent SOS markers, and thus subsequent 102 planes, is done inside OJPEGReadSecondarySos. 103 104 The benefit of the scheme is... that it works, basically. We know of no other that 105 does. It works without checking software tag, or otherwise going about things in an 106 OJPEG flavor specific manner. Instead, it is a single scheme, that covers the cases 107 with and without JpegInterchangeFormat, with and without striles, with part of 108 the header in JpegInterchangeFormat and remainder in first strile, etc. It is forgiving 109 and robust, may likely work with OJPEG flavors we've not seen yet, and makes most out 110 of the data. 111 112 Another nice side-effect is that a complete JPEG single valid stream is build if 113 planarconfig is not separate (vast majority). We may one day use that to build 114 converters to JPEG, and/or to new-style JPEG compression inside TIFF. 115 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 OJPEGPreDecode. 118 Applications would do well accessing all striles in order, as this will result in 119 a single sequential scan of the input stream, and no restarting of LibJpeg decoding 120 session. 121 */ 122 2 123 3 124 #include "tiffiop.h" 4 125 #ifdef OJPEG_SUPPORT 5 126 6 /* JPEG Compression support, as per the original TIFF 6.0 specification. 7 8 WARNING: KLUDGE ALERT! The type of JPEG encapsulation defined by the TIFF 9 Version 6.0 specification is now totally obsolete and 10 deprecated for new applications and images. This file is an unsupported hack 11 that was created solely in order to read (but NOT write!) a few old, 12 unconverted images still present on some users' computer systems. The code 13 isn't pretty or robust, and it won't read every "old format" JPEG-in-TIFF 14 file (see Samuel Leffler's draft "TIFF Technical Note No. 2" for a long and 15 incomplete list of known problems), but it seems to work well enough in the 16 few cases of practical interest to the author; so, "caveat emptor"! This 17 file should NEVER be enhanced to write new images using anything other than 18 the latest approved JPEG-in-TIFF encapsulation method, implemented by the 19 "tif_jpeg.c" file elsewhere in this library. 20 21 This file interfaces with Release 6B of the JPEG Library written by theu 22 Independent JPEG Group, which you can find on the Internet at: 23 ftp://ftp.uu.net:/graphics/jpeg/. 24 25 The "C" Preprocessor macros, "[CD]_LOSSLESS_SUPPORTED", are defined by your 26 JPEG Library Version 6B only if you have applied a (massive!) patch by Ken 27 Murchison of Oceana Matrix Ltd. <ken@oceana.com> to support lossless Huffman 28 encoding (TIFF "JPEGProc" tag value = 14). This patch can be found on the 29 Internet at: ftp://ftp.oceana.com/pub/ljpeg-6b.tar.gz. 30 31 Some old files produced by the Wang Imaging application for Microsoft Windows 32 apparently can be decoded only with a special patch to the JPEG Library, 33 which defines a subroutine named "jpeg_reset_huff_decode()" in its "jdhuff.c" 34 module (the "jdshuff.c" module, if Ken Murchison's patch has been applied). 35 Unfortunately the patch differs slightly in each case, and some TIFF Library 36 have reported problems finding the code, so both versions appear below; you 37 should carefully extract and apply only the version that applies to your JPEG 38 Library! 39 40 Contributed by Scott Marovich <marovich@hpl.hp.com> with considerable help 41 from Charles Auer <Bumble731@msn.com> to unravel the mysteries of image files 42 created by the Wang Imaging application for Microsoft Windows. 43 */ 44 #if 0 /* Patch for JPEG Library WITHOUT lossless Huffman coding */ 45 *** jdhuff.c.orig Mon Oct 20 17:51:10 1997 46 --- jdhuff.c Sun Nov 11 17:33:58 2001 47 *************** 48 *** 648,651 **** 49 --- 648,683 ---- 50 for (i = 0; i < NUM_HUFF_TBLS; i++) { 51 entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL; 52 } 53 } 54 + 55 + /* 56 + * BEWARE OF KLUDGE: This subroutine is a hack for decoding illegal JPEG-in- 57 + * TIFF encapsulations produced by Microsoft's Wang Imaging 58 + * for Windows application with the public-domain TIFF Library. Based upon an 59 + * examination of selected output files, this program apparently divides a JPEG 60 + * bit-stream into consecutive horizontal TIFF "strips", such that the JPEG 61 + * encoder's/decoder's DC coefficients for each image component are reset before 62 + * each "strip". Moreover, a "strip" is not necessarily encoded in a multiple 63 + * of 8 bits, so one must sometimes discard 1-7 bits at the end of each "strip" 64 + * for alignment to the next input-Byte storage boundary. IJG JPEG Library 65 + * decoder state is not normally exposed to client applications, so this sub- 66 + * routine provides the TIFF Library with a "hook" to make these corrections. 67 + * It should be called after "jpeg_start_decompress()" and before 68 + * "jpeg_finish_decompress()", just before decoding each "strip" using 69 + * "jpeg_read_raw_data()" or "jpeg_read_scanlines()". 70 + * 71 + * This kludge is not sanctioned or supported by the Independent JPEG Group, and 72 + * future changes to the IJG JPEG Library might invalidate it. Do not send bug 73 + * reports about this code to IJG developers. Instead, contact the author for 74 + * advice: Scott B. Marovich <marovich@hpl.hp.com>, Hewlett-Packard Labs, 6/01. 75 + */ 76 + GLOBAL(void) 77 + jpeg_reset_huff_decode (register j_decompress_ptr cinfo) 78 + { register huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy; 79 + register int ci = 0; 80 + 81 + /* Discard encoded input bits, up to the next Byte boundary */ 82 + entropy->bitstate.bits_left &= ~7; 83 + /* Re-initialize DC predictions to 0 */ 84 + do entropy->saved.last_dc_val[ci] = 0; while (++ci < cinfo->comps_in_scan); 85 + } 86 #endif /* Patch for JPEG Library WITHOUT lossless Huffman coding */ 87 #if 0 /* Patch for JPEG Library WITH lossless Huffman coding */ 88 *** jdshuff.c.orig Mon Mar 11 16:44:54 2002 89 --- jdshuff.c Mon Mar 11 16:44:54 2002 90 *************** 91 *** 357,360 **** 92 --- 357,393 ---- 93 for (i = 0; i < NUM_HUFF_TBLS; i++) { 94 entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL; 95 } 96 } 97 + 98 + /* 99 + * BEWARE OF KLUDGE: This subroutine is a hack for decoding illegal JPEG-in- 100 + * TIFF encapsulations produced by Microsoft's Wang Imaging 101 + * for Windows application with the public-domain TIFF Library. Based upon an 102 + * examination of selected output files, this program apparently divides a JPEG 103 + * bit-stream into consecutive horizontal TIFF "strips", such that the JPEG 104 + * encoder's/decoder's DC coefficients for each image component are reset before 105 + * each "strip". Moreover, a "strip" is not necessarily encoded in a multiple 106 + * of 8 bits, so one must sometimes discard 1-7 bits at the end of each "strip" 107 + * for alignment to the next input-Byte storage boundary. IJG JPEG Library 108 + * decoder state is not normally exposed to client applications, so this sub- 109 + * routine provides the TIFF Library with a "hook" to make these corrections. 110 + * It should be called after "jpeg_start_decompress()" and before 111 + * "jpeg_finish_decompress()", just before decoding each "strip" using 112 + * "jpeg_read_raw_data()" or "jpeg_read_scanlines()". 113 + * 114 + * This kludge is not sanctioned or supported by the Independent JPEG Group, and 115 + * future changes to the IJG JPEG Library might invalidate it. Do not send bug 116 + * reports about this code to IJG developers. Instead, contact the author for 117 + * advice: Scott B. Marovich <marovich@hpl.hp.com>, Hewlett-Packard Labs, 6/01. 118 + */ 119 + GLOBAL(void) 120 + jpeg_reset_huff_decode (register j_decompress_ptr cinfo) 121 + { register shuff_entropy_ptr entropy = (shuff_entropy_ptr) 122 + ((j_lossy_d_ptr)cinfo->codec)->entropy_private; 123 + register int ci = 0; 124 + 125 + /* Discard encoded input bits, up to the next Byte boundary */ 126 + entropy->bitstate.bits_left &= ~7; 127 + /* Re-initialize DC predictions to 0 */ 128 + do entropy->saved.last_dc_val[ci] = 0; while (++ci < cinfo->comps_in_scan); 129 + } 130 #endif /* Patch for JPEG Library WITH lossless Huffman coding */ 127 /* Configuration defines here are: 128 * JPEG_ENCAP_EXTERNAL: The normal way to call libjpeg, uses longjump. In some environments, 129 * like eg LibTiffDelphi, this is not possible. For this reason, the actual calls to 130 * libjpeg, with longjump stuff, are encapsulated in dedicated functions. When 131 * JPEG_ENCAP_EXTERNAL is defined, these encapsulating functions are declared external 132 * to this unit, and can be defined elsewhere to use stuff other then longjump. 133 * The default mode, without JPEG_ENCAP_EXTERNAL, implements the call encapsulators 134 * here, internally, with normal longjump. 135 * SETJMP, LONGJMP, JMP_BUF: On some machines/environments a longjump equivalent is 136 * conviniently available, but still it may be worthwhile to use _setjmp or sigsetjmp 137 * in place of plain setjmp. These macros will make it easier. It is useless 138 * to fiddle with these if you define JPEG_ENCAP_EXTERNAL. 139 * OJPEG_BUFFER: Define the size of the desired buffer here. Should be small enough so as to guarantee 140 * instant processing, optimal streaming and optimal use of processor cache, but also big 141 * enough so as to not result in significant call overhead. It should be at least a few 142 * bytes to accomodate some structures (this is verified in asserts), but it would not be 143 * sensible to make it this small anyway, and it should be at most 64K since it is indexed 144 * with uint16. We recommend 2K. 145 * EGYPTIANWALK: You could also define EGYPTIANWALK here, but it is not used anywhere and has 146 * absolutely no effect. That is why most people insist the EGYPTIANWALK is a bit silly. 147 */ 148 149 /* #define LIBJPEG_ENCAP_EXTERNAL */ 150 #define SETJMP(jbuf) setjmp(jbuf) 151 #define LONGJMP(jbuf,code) longjmp(jbuf,code) 152 #define JMP_BUF jmp_buf 153 #define OJPEG_BUFFER 2048 154 /* define EGYPTIANWALK */ 155 156 #define JPEG_MARKER_SOF0 0xC0 157 #define JPEG_MARKER_SOF1 0xC1 158 #define JPEG_MARKER_SOF3 0xC3 159 #define JPEG_MARKER_DHT 0xC4 160 #define JPEG_MARKER_RST0 0XD0 161 #define JPEG_MARKER_SOI 0xD8 162 #define JPEG_MARKER_EOI 0xD9 163 #define JPEG_MARKER_SOS 0xDA 164 #define JPEG_MARKER_DQT 0xDB 165 #define JPEG_MARKER_DRI 0xDD 166 #define JPEG_MARKER_APP0 0xE0 167 #define JPEG_MARKER_COM 0xFE 168 169 #define FIELD_OJPEG_JPEGINTERCHANGEFORMAT (FIELD_CODEC+0) 170 #define FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH (FIELD_CODEC+1) 171 #define FIELD_OJPEG_JPEGQTABLES (FIELD_CODEC+2) 172 #define FIELD_OJPEG_JPEGDCTABLES (FIELD_CODEC+3) 173 #define FIELD_OJPEG_JPEGACTABLES (FIELD_CODEC+4) 174 #define FIELD_OJPEG_JPEGPROC (FIELD_CODEC+5) 175 #define FIELD_OJPEG_JPEGRESTARTINTERVAL (FIELD_CODEC+6) 176 #define FIELD_OJPEG_COUNT 7 177 178 static const TIFFFieldInfo ojpeg_field_info[] = { 179 {TIFFTAG_JPEGIFOFFSET,1,1,TIFF_LONG,FIELD_OJPEG_JPEGINTERCHANGEFORMAT,TRUE,FALSE,"JpegInterchangeFormat"}, 180 {TIFFTAG_JPEGIFBYTECOUNT,1,1,TIFF_LONG,FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH,TRUE,FALSE,"JpegInterchangeFormatLength"}, 181 {TIFFTAG_JPEGQTABLES,TIFF_VARIABLE,TIFF_VARIABLE,TIFF_LONG,FIELD_OJPEG_JPEGQTABLES,FALSE,TRUE,"JpegQTables"}, 182 {TIFFTAG_JPEGDCTABLES,TIFF_VARIABLE,TIFF_VARIABLE,TIFF_LONG,FIELD_OJPEG_JPEGDCTABLES,FALSE,TRUE,"JpegDcTables"}, 183 {TIFFTAG_JPEGACTABLES,TIFF_VARIABLE,TIFF_VARIABLE,TIFF_LONG,FIELD_OJPEG_JPEGACTABLES,FALSE,TRUE,"JpegAcTables"}, 184 {TIFFTAG_JPEGPROC,1,1,TIFF_SHORT,FIELD_OJPEG_JPEGPROC,FALSE,FALSE,"JpegProc"}, 185 {TIFFTAG_JPEGRESTARTINTERVAL,1,1,TIFF_SHORT,FIELD_OJPEG_JPEGRESTARTINTERVAL,FALSE,FALSE,"JpegRestartInterval"}, 186 }; 187 188 #ifndef LIBJPEG_ENCAP_EXTERNAL 131 189 #include <setjmp.h> 132 #include <stdio.h>133 #ifdef FAR134 #undef FAR /* Undefine FAR to avoid conflict with JPEG definition */135 190 #endif 136 #define JPEG_INTERNALS /* Include "jpegint.h" for "DSTATE_*" symbols */ 137 #define JPEG_CJPEG_DJPEG /* Include all Version 6B+ "jconfig.h" options */ 138 #undef INLINE 191 139 192 #include "jpeglib.h" 140 #undef JPEG_CJPEG_DJPEG 141 #undef JPEG_INTERNALS 142 143 /* Hack for files produced by Wang Imaging application on Microsoft Windows */ 144 extern void jpeg_reset_huff_decode(j_decompress_ptr); 145 146 /* On some machines, it may be worthwhile to use "_setjmp()" or "sigsetjmp()" 147 instead of "setjmp()". These macros make it easier: 148 */ 149 #define SETJMP(jbuf)setjmp(jbuf) 150 #define LONGJMP(jbuf,code)longjmp(jbuf,code) 151 #define JMP_BUF jmp_buf 152 153 #define TIFFTAG_WANG_PAGECONTROL 32934 154 155 /* Bit-vector offsets for keeping track of TIFF records that we've parsed. */ 156 157 #define FIELD_JPEGPROC FIELD_CODEC 158 #define FIELD_JPEGIFOFFSET (FIELD_CODEC+1) 159 #define FIELD_JPEGIFBYTECOUNT (FIELD_CODEC+2) 160 #define FIELD_JPEGRESTARTINTERVAL (FIELD_CODEC+3) 161 #define FIELD_JPEGTABLES (FIELD_CODEC+4) /* New, post-6.0 JPEG-in-TIFF tag! */ 162 #define FIELD_JPEGLOSSLESSPREDICTORS (FIELD_CODEC+5) 163 #define FIELD_JPEGPOINTTRANSFORM (FIELD_CODEC+6) 164 #define FIELD_JPEGQTABLES (FIELD_CODEC+7) 165 #define FIELD_JPEGDCTABLES (FIELD_CODEC+8) 166 #define FIELD_JPEGACTABLES (FIELD_CODEC+9) 167 #define FIELD_WANG_PAGECONTROL (FIELD_CODEC+10) 168 #define FIELD_JPEGCOLORMODE (FIELD_CODEC+11) 169 170 typedef struct jpeg_destination_mgr jpeg_destination_mgr; 193 #include "jerror.h" 194 195 typedef struct jpeg_error_mgr jpeg_error_mgr; 196 typedef struct jpeg_common_struct jpeg_common_struct; 197 typedef struct jpeg_decompress_struct jpeg_decompress_struct; 171 198 typedef struct jpeg_source_mgr jpeg_source_mgr; 172 typedef struct jpeg_error_mgr jpeg_error_mgr; 173 174 /* State variable for each open TIFF file that uses "libjpeg" for JPEG 175 decompression. (Note: This file should NEVER perform JPEG compression 176 except in the manner implemented by the "tif_jpeg.c" file, elsewhere in this 177 library; see comments above.) JPEG Library internal state is recorded in a 178 "jpeg_{de}compress_struct", while a "jpeg_common_struct" records a few items 179 common to both compression and expansion. The "cinfo" field containing JPEG 180 Library state MUST be the 1st member of our own state variable, so that we 181 can safely "cast" pointers back and forth. 182 */ 183 typedef struct /* This module's private, per-image state variable */ 184 { 185 union /* JPEG Library state variable; this MUST be our 1st field! */ 186 { 187 struct jpeg_compress_struct c; 188 struct jpeg_decompress_struct d; 189 struct jpeg_common_struct comm; 190 } cinfo; 191 jpeg_error_mgr err; /* JPEG Library error manager */ 192 JMP_BUF exit_jmpbuf; /* ...for catching JPEG Library failures */ 193 # ifdef never 194 195 /* (The following two fields could be a "union", but they're small enough that 196 it's not worth the effort.) 197 */ 198 jpeg_destination_mgr dest; /* Destination for compressed data */ 199 # endif 200 jpeg_source_mgr src; /* Source of expanded data */ 201 JSAMPARRAY ds_buffer[MAX_COMPONENTS]; /* ->Temporary downsampling buffers */ 202 TIFF *tif; /* Reverse pointer, needed by some code */ 203 TIFFVGetMethod vgetparent; /* "Super class" methods... */ 204 TIFFVSetMethod vsetparent; 205 TIFFStripMethod defsparent; 206 TIFFTileMethod deftparent; 207 void *jpegtables; /* ->"New" JPEG tables, if we synthesized any */ 208 uint32 is_WANG, /* <=> Wang Imaging for Microsoft Windows output file? */ 209 jpegtables_length; /* Length of "new" JPEG tables, if they exist */ 210 tsize_t bytesperline; /* No. of decompressed Bytes per scan line */ 211 int jpegquality, /* Compression quality level */ 212 jpegtablesmode, /* What to put in JPEGTables */ 213 samplesperclump, 214 scancount; /* No. of scan lines accumulated */ 215 J_COLOR_SPACE photometric; /* IJG JPEG Library's photometry code */ 216 unsigned char h_sampling, /* Luminance sampling factors */ 217 v_sampling, 218 jpegcolormode; /* Who performs RGB <-> YCbCr conversion? */ 219 /* JPEGCOLORMODE_RAW <=> TIFF Library or its client */ 220 /* JPEGCOLORMODE_RGB <=> JPEG Library */ 221 /* These fields are added to support TIFFGetField */ 222 uint16 jpegproc; 223 uint32 jpegifoffset; 224 uint32 jpegifbytecount; 225 uint32 jpegrestartinterval; 226 void* jpeglosslesspredictors; 227 uint16 jpeglosslesspredictors_length; 228 void* jpegpointtransform; 229 uint32 jpegpointtransform_length; 230 void* jpegqtables; 231 uint32 jpegqtables_length; 232 void* jpegdctables; 233 uint32 jpegdctables_length; 234 void* jpegactables; 235 uint32 jpegactables_length; 236 237 } OJPEGState; 238 #define OJState(tif)((OJPEGState*)(tif)->tif_data) 239 240 static const TIFFFieldInfo ojpegFieldInfo[]=/* JPEG-specific TIFF-record tags */ 241 { 242 243 /* This is the current JPEG-in-TIFF metadata-encapsulation tag, and its 244 treatment in this file is idiosyncratic. It should never appear in a 245 "source" image conforming to the TIFF Version 6.0 specification, so we 246 arrange to report an error if it appears. But in order to support possible 247 future conversion of "old" JPEG-in-TIFF encapsulations to "new" ones, we 248 might wish to synthesize an equivalent value to be returned by the TIFF 249 Library's "getfield" method. So, this table tells the TIFF Library to pass 250 these records to us in order to filter them below. 251 */ 252 { 253 TIFFTAG_JPEGTABLES ,TIFF_VARIABLE2,TIFF_VARIABLE2, 254 TIFF_UNDEFINED,FIELD_JPEGTABLES ,FALSE,TRUE ,"JPEGTables" 255 }, 256 257 /* These tags are defined by the TIFF Version 6.0 specification and are now 258 obsolete. This module reads them from an old "source" image, but it never 259 writes them to a new "destination" image. 260 */ 261 { 262 TIFFTAG_JPEGPROC ,1 ,1 , 263 TIFF_SHORT ,FIELD_JPEGPROC ,FALSE,FALSE,"JPEGProc" 264 }, 265 { 266 TIFFTAG_JPEGIFOFFSET ,1 ,1 , 267 TIFF_LONG ,FIELD_JPEGIFOFFSET ,FALSE,FALSE,"JPEGInterchangeFormat" 268 }, 269 { 270 TIFFTAG_JPEGIFBYTECOUNT ,1 ,1 , 271 TIFF_LONG ,FIELD_JPEGIFBYTECOUNT ,FALSE,FALSE,"JPEGInterchangeFormatLength" 272 }, 273 { 274 TIFFTAG_JPEGRESTARTINTERVAL ,1 ,1 , 275 TIFF_SHORT ,FIELD_JPEGRESTARTINTERVAL ,FALSE,FALSE,"JPEGRestartInterval" 276 }, 277 { 278 TIFFTAG_JPEGLOSSLESSPREDICTORS,TIFF_VARIABLE,TIFF_VARIABLE, 279 TIFF_SHORT ,FIELD_JPEGLOSSLESSPREDICTORS,FALSE,TRUE ,"JPEGLosslessPredictors" 280 }, 281 { 282 TIFFTAG_JPEGPOINTTRANSFORM ,TIFF_VARIABLE,TIFF_VARIABLE, 283 TIFF_SHORT ,FIELD_JPEGPOINTTRANSFORM ,FALSE,TRUE ,"JPEGPointTransforms" 284 }, 285 { 286 TIFFTAG_JPEGQTABLES ,TIFF_VARIABLE,TIFF_VARIABLE, 287 TIFF_LONG ,FIELD_JPEGQTABLES ,FALSE,TRUE ,"JPEGQTables" 288 }, 289 { 290 TIFFTAG_JPEGDCTABLES ,TIFF_VARIABLE,TIFF_VARIABLE, 291 TIFF_LONG ,FIELD_JPEGDCTABLES ,FALSE,TRUE ,"JPEGDCTables" 292 }, 293 { 294 TIFFTAG_JPEGACTABLES ,TIFF_VARIABLE,TIFF_VARIABLE, 295 TIFF_LONG ,FIELD_JPEGACTABLES ,FALSE,TRUE ,"JPEGACTables" 296 }, 297 { 298 TIFFTAG_WANG_PAGECONTROL ,TIFF_VARIABLE,1 , 299 TIFF_LONG ,FIELD_WANG_PAGECONTROL ,FALSE,FALSE,"WANG PageControl" 300 }, 301 302 /* This is a pseudo tag intended for internal use only by the TIFF Library and 303 its clients, which should never appear in an input/output image file. It 304 specifies whether the TIFF Library (or its client) should do YCbCr <-> RGB 305 color-space conversion (JPEGCOLORMODE_RAW <=> 0) or whether we should ask 306 the JPEG Library to do it (JPEGCOLORMODE_RGB <=> 1). 307 */ 308 { 309 TIFFTAG_JPEGCOLORMODE ,0 ,0 , 310 TIFF_ANY ,FIELD_PSEUDO ,FALSE,FALSE,"JPEGColorMode" 311 } 312 }; 313 static const char JPEGLib_name[]={"JPEG Library"}, 314 bad_bps[]={"%u BitsPerSample not allowed for JPEG"}, 315 bad_photometry[]={"PhotometricInterpretation %u not allowed for JPEG"}, 316 bad_subsampling[]={"invalid YCbCr subsampling factor(s)"}, 317 # ifdef never 318 no_write_frac[]={"fractional scan line discarded"}, 319 # endif 320 no_read_frac[]={"fractional scan line not read"}, 321 no_jtable_space[]={"No space for JPEGTables"}; 322 323 /* The following diagnostic subroutines interface with and replace default 324 subroutines in the JPEG Library. Our basic strategy is to use "setjmp()"/ 325 "longjmp()" in order to return control to the TIFF Library when the JPEG 326 library detects an error, and to use TIFF Library subroutines for displaying 327 diagnostic messages to a client application. 328 */ 199 200 typedef enum { 201 osibsNotSetYet, 202 osibsJpegInterchangeFormat, 203 osibsStrile, 204 osibsEof 205 } OJPEGStateInBufferSource; 206 207 typedef enum { 208 ososSoi, 209 ososQTable0,ososQTable1,ososQTable2,ososQTable3, 210 ososDcTable0,ososDcTable1,ososDcTable2,ososDcTable3, 211 ososAcTable0,ososAcTable1,ososAcTable2,ososAcTable3, 212 ososDri, 213 ososSof, 214 ososSos, 215 ososCompressed, 216 ososRst, 217 ososEoi 218 } OJPEGStateOutState; 219 220 typedef struct { 221 TIFF* tif; 222 #ifndef LIBJPEG_ENCAP_EXTERNAL 223 JMP_BUF exit_jmpbuf; 224 #endif 225 TIFFVGetMethod vgetparent; 226 TIFFVSetMethod vsetparent; 227 toff_t file_size; 228 uint32 image_width; 229 uint32 image_length; 230 uint32 strile_width; 231 uint32 strile_length; 232 uint32 strile_length_total; 233 uint8 samples_per_pixel; 234 uint8 plane_sample_offset; 235 uint8 samples_per_pixel_per_plane; 236 toff_t jpeg_interchange_format; 237 toff_t jpeg_interchange_format_length; 238 uint8 jpeg_proc; 239 uint8 subsamplingcorrect; 240 uint8 subsamplingcorrect_done; 241 uint8 subsampling_tag; 242 uint8 subsampling_hor; 243 uint8 subsampling_ver; 244 uint8 subsampling_force_desubsampling_inside_decompression; 245 uint8 qtable_offset_count; 246 uint8 dctable_offset_count; 247 uint8 actable_offset_count; 248 toff_t qtable_offset[3]; 249 toff_t dctable_offset[3]; 250 toff_t actable_offset[3]; 251 uint8* qtable[4]; 252 uint8* dctable[4]; 253 uint8* actable[4]; 254 uint16 restart_interval; 255 uint8 restart_index; 256 uint8 sof_log; 257 uint8 sof_marker_id; 258 uint32 sof_x; 259 uint32 sof_y; 260 uint8 sof_c[3]; 261 uint8 sof_hv[3]; 262 uint8 sof_tq[3]; 263 uint8 sos_cs[3]; 264 uint8 sos_tda[3]; 265 struct { 266 uint8 log; 267 OJPEGStateInBufferSource in_buffer_source; 268 tstrile_t in_buffer_next_strile; 269 toff_t in_buffer_file_pos; 270 toff_t in_buffer_file_togo; 271 } sos_end[3]; 272 uint8 readheader_done; 273 uint8 writeheader_done; 274 tsample_t write_cursample; 275 tstrile_t write_curstrile; 276 uint8 libjpeg_session_active; 277 uint8 libjpeg_jpeg_query_style; 278 jpeg_error_mgr libjpeg_jpeg_error_mgr; 279 jpeg_decompress_struct libjpeg_jpeg_decompress_struct; 280 jpeg_source_mgr libjpeg_jpeg_source_mgr; 281 uint8 subsampling_convert_log; 282 uint32 subsampling_convert_ylinelen; 283 uint32 subsampling_convert_ylines; 284 uint32 subsampling_convert_clinelen; 285 uint32 subsampling_convert_clines; 286 uint32 subsampling_convert_ybuflen; 287 uint32 subsampling_convert_cbuflen; 288 uint32 subsampling_convert_ycbcrbuflen; 289 uint8* subsampling_convert_ycbcrbuf; 290 uint8* subsampling_convert_ybuf; 291 uint8* subsampling_convert_cbbuf; 292 uint8* subsampling_convert_crbuf; 293 uint32 subsampling_convert_ycbcrimagelen; 294 uint8** subsampling_convert_ycbcrimage; 295 uint32 subsampling_convert_clinelenout; 296 uint32 subsampling_convert_state; 297 uint32 bytes_per_line; /* if the codec outputs subsampled data, a 'line' in bytes_per_line */ 298 uint32 lines_per_strile; /* and lines_per_strile means subsampling_ver desubsampled rows */ 299 OJPEGStateInBufferSource in_buffer_source; 300 tstrile_t in_buffer_next_strile; 301 tstrile_t in_buffer_strile_count; 302 toff_t in_buffer_file_pos; 303 uint8 in_buffer_file_pos_log; 304 toff_t in_buffer_file_togo; 305 uint16 in_buffer_togo; 306 uint8* in_buffer_cur; 307 uint8 in_buffer[OJPEG_BUFFER]; 308 OJPEGStateOutState out_state; 309 uint8 out_buffer[OJPEG_BUFFER]; 310 uint8* skip_buffer; 311 } OJPEGState; 312 313 static int OJPEGVGetField(TIFF* tif, ttag_t tag, va_list ap); 314 static int OJPEGVSetField(TIFF* tif, ttag_t tag, va_list ap); 315 static void OJPEGPrintDir(TIFF* tif, FILE* fd, long flags); 316 317 static int OJPEGSetupDecode(TIFF* tif); 318 static int OJPEGPreDecode(TIFF* tif, tsample_t s); 319 static int OJPEGPreDecodeSkipRaw(TIFF* tif); 320 static int OJPEGPreDecodeSkipScanlines(TIFF* tif); 321 static int OJPEGDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s); 322 static int OJPEGDecodeRaw(TIFF* tif, tidata_t buf, tsize_t cc); 323 static int OJPEGDecodeScanlines(TIFF* tif, tidata_t buf, tsize_t cc); 324 static void OJPEGPostDecode(TIFF* tif, tidata_t buf, tsize_t cc); 325 static int OJPEGSetupEncode(TIFF* tif); 326 static int OJPEGPreEncode(TIFF* tif, tsample_t s); 327 static int OJPEGEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s); 328 static int OJPEGPostEncode(TIFF* tif); 329 static void OJPEGCleanup(TIFF* tif); 330 331 static void OJPEGSubsamplingCorrect(TIFF* tif); 332 static int OJPEGReadHeaderInfo(TIFF* tif); 333 static int OJPEGReadSecondarySos(TIFF* tif, tsample_t s); 334 static int OJPEGWriteHeaderInfo(TIFF* tif); 335 static void OJPEGLibjpegSessionAbort(TIFF* tif); 336 337 static int OJPEGReadHeaderInfoSec(TIFF* tif); 338 static int OJPEGReadHeaderInfoSecStreamDri(TIFF* tif); 339 static int OJPEGReadHeaderInfoSecStreamDqt(TIFF* tif); 340 static int OJPEGReadHeaderInfoSecStreamDht(TIFF* tif); 341 static int OJPEGReadHeaderInfoSecStreamSof(TIFF* tif, uint8 marker_id); 342 static int OJPEGReadHeaderInfoSecStreamSos(TIFF* tif); 343 static int OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif); 344 static int OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif); 345 static int OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif); 346 347 static int OJPEGReadBufferFill(OJPEGState* sp); 348 static int OJPEGReadByte(OJPEGState* sp, uint8* byte); 349 static int OJPEGReadBytePeek(OJPEGState* sp, uint8* byte); 350 static void OJPEGReadByteAdvance(OJPEGState* sp); 351 static int OJPEGReadWord(OJPEGState* sp, uint16* word); 352 static int OJPEGReadBlock(OJPEGState* sp, uint16 len, void* mem); 353 static void OJPEGReadSkip(OJPEGState* sp, uint16 len); 354 355 static int OJPEGWriteStream(TIFF* tif, void** mem, uint32* len); 356 static void OJPEGWriteStreamSoi(TIFF* tif, void** mem, uint32* len); 357 static void OJPEGWriteStreamQTable(TIFF* tif, uint8 table_index, void** mem, uint32* len); 358 static void OJPEGWriteStreamDcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len); 359 static void OJPEGWriteStreamAcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len); 360 static void OJPEGWriteStreamDri(TIFF* tif, void** mem, uint32* len); 361 static void OJPEGWriteStreamSof(TIFF* tif, void** mem, uint32* len); 362 static void OJPEGWriteStreamSos(TIFF* tif, void** mem, uint32* len); 363 static int OJPEGWriteStreamCompressed(TIFF* tif, void** mem, uint32* len); 364 static void OJPEGWriteStreamRst(TIFF* tif, void** mem, uint32* len); 365 static void OJPEGWriteStreamEoi(TIFF* tif, void** mem, uint32* len); 366 367 #ifdef LIBJPEG_ENCAP_EXTERNAL 368 extern int jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo); 369 extern int jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image); 370 extern int jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo); 371 extern int jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines); 372 extern int jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines); 373 extern void jpeg_encap_unwind(TIFF* tif); 374 #else 375 static int jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* j); 376 static int jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image); 377 static int jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo); 378 static int jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines); 379 static int jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines); 380 static void jpeg_encap_unwind(TIFF* tif); 381 #endif 382 383 static void OJPEGLibjpegJpegErrorMgrOutputMessage(jpeg_common_struct* cinfo); 384 static void OJPEGLibjpegJpegErrorMgrErrorExit(jpeg_common_struct* cinfo); 385 static void OJPEGLibjpegJpegSourceMgrInitSource(jpeg_decompress_struct* cinfo); 386 static boolean OJPEGLibjpegJpegSourceMgrFillInputBuffer(jpeg_decompress_struct* cinfo); 387 static void OJPEGLibjpegJpegSourceMgrSkipInputData(jpeg_decompress_struct* cinfo, long num_bytes); 388 static boolean OJPEGLibjpegJpegSourceMgrResyncToRestart(jpeg_decompress_struct* cinfo, int desired); 389 static void OJPEGLibjpegJpegSourceMgrTermSource(jpeg_decompress_struct* cinfo); 390 391 int 392 TIFFInitOJPEG(TIFF* tif, int scheme) 393 { 394 static const char module[]="TIFFInitOJPEG"; 395 OJPEGState* sp; 396 397 assert(scheme==COMPRESSION_OJPEG); 398 399 /* 400 * Merge codec-specific tag information. 401 */ 402 if (!_TIFFMergeFieldInfo(tif,ojpeg_field_info,FIELD_OJPEG_COUNT)) { 403 TIFFErrorExt(tif->tif_clientdata, module, 404 "Merging Old JPEG codec-specific tags failed"); 405 return 0; 406 } 407 408 /* state block */ 409 sp=_TIFFmalloc(sizeof(OJPEGState)); 410 if (sp==NULL) 411 { 412 TIFFErrorExt(tif->tif_clientdata,module,"No space for OJPEG state block"); 413 return(0); 414 } 415 _TIFFmemset(sp,0,sizeof(OJPEGState)); 416 sp->tif=tif; 417 sp->jpeg_proc=1; 418 sp->subsampling_hor=2; 419 sp->subsampling_ver=2; 420 TIFFSetField(tif,TIFFTAG_YCBCRSUBSAMPLING,2,2); 421 /* tif codec methods */ 422 tif->tif_setupdecode=OJPEGSetupDecode; 423 tif->tif_predecode=OJPEGPreDecode; 424 tif->tif_postdecode=OJPEGPostDecode; 425 tif->tif_decoderow=OJPEGDecode; 426 tif->tif_decodestrip=OJPEGDecode; 427 tif->tif_decodetile=OJPEGDecode; 428 tif->tif_setupencode=OJPEGSetupEncode; 429 tif->tif_preencode=OJPEGPreEncode; 430 tif->tif_postencode=OJPEGPostEncode; 431 tif->tif_encoderow=OJPEGEncode; 432 tif->tif_encodestrip=OJPEGEncode; 433 tif->tif_encodetile=OJPEGEncode; 434 tif->tif_cleanup=OJPEGCleanup; 435 tif->tif_data=(tidata_t)sp; 436 /* tif tag methods */ 437 sp->vgetparent=tif->tif_tagmethods.vgetfield; 438 tif->tif_tagmethods.vgetfield=OJPEGVGetField; 439 sp->vsetparent=tif->tif_tagmethods.vsetfield; 440 tif->tif_tagmethods.vsetfield=OJPEGVSetField; 441 tif->tif_tagmethods.printdir=OJPEGPrintDir; 442 /* Some OJPEG files don't have strip or tile offsets or bytecounts tags. 443 Some others do, but have totally meaningless or corrupt values 444 in these tags. In these cases, the JpegInterchangeFormat stream is 445 reliable. In any case, this decoder reads the compressed data itself, 446 from the most reliable locations, and we need to notify encapsulating 447 LibTiff not to read raw strips or tiles for us. */ 448 tif->tif_flags|=TIFF_NOREADRAW; 449 return(1); 450 } 451 452 static int 453 OJPEGVGetField(TIFF* tif, ttag_t tag, va_list ap) 454 { 455 OJPEGState* sp=(OJPEGState*)tif->tif_data; 456 switch(tag) 457 { 458 case TIFFTAG_JPEGIFOFFSET: 459 *va_arg(ap,uint32*)=(uint32)sp->jpeg_interchange_format; 460 break; 461 case TIFFTAG_JPEGIFBYTECOUNT: 462 *va_arg(ap,uint32*)=(uint32)sp->jpeg_interchange_format_length; 463 break; 464 case TIFFTAG_YCBCRSUBSAMPLING: 465 if (sp->subsamplingcorrect_done==0) 466 OJPEGSubsamplingCorrect(tif); 467 *va_arg(ap,uint16*)=(uint16)sp->subsampling_hor; 468 *va_arg(ap,uint16*)=(uint16)sp->subsampling_ver; 469 break; 470 case TIFFTAG_JPEGQTABLES: 471 *va_arg(ap,uint32*)=(uint32)sp->qtable_offset_count; 472 *va_arg(ap,void**)=(void*)sp->qtable_offset; 473 break; 474 case TIFFTAG_JPEGDCTABLES: 475 *va_arg(ap,uint32*)=(uint32)sp->dctable_offset_count; 476 *va_arg(ap,void**)=(void*)sp->dctable_offset; 477 break; 478 case TIFFTAG_JPEGACTABLES: 479 *va_arg(ap,uint32*)=(uint32)sp->actable_offset_count; 480 *va_arg(ap,void**)=(void*)sp->actable_offset; 481 break; 482 case TIFFTAG_JPEGPROC: 483 *va_arg(ap,uint16*)=(uint16)sp->jpeg_proc; 484 break; 485 case TIFFTAG_JPEGRESTARTINTERVAL: 486 *va_arg(ap,uint16*)=sp->restart_interval; 487 break; 488 default: 489 return (*sp->vgetparent)(tif,tag,ap); 490 } 491 return (1); 492 } 493 494 static int 495 OJPEGVSetField(TIFF* tif, ttag_t tag, va_list ap) 496 { 497 static const char module[]="OJPEGVSetField"; 498 OJPEGState* sp=(OJPEGState*)tif->tif_data; 499 uint32 ma; 500 uint32* mb; 501 uint32 n; 502 switch(tag) 503 { 504 case TIFFTAG_JPEGIFOFFSET: 505 sp->jpeg_interchange_format=(toff_t)va_arg(ap,uint32); 506 break; 507 case TIFFTAG_JPEGIFBYTECOUNT: 508 sp->jpeg_interchange_format_length=(toff_t)va_arg(ap,uint32); 509 break; 510 case TIFFTAG_YCBCRSUBSAMPLING: 511 sp->subsampling_tag=1; 512 sp->subsampling_hor=(uint8)va_arg(ap,int); 513 sp->subsampling_ver=(uint8)va_arg(ap,int); 514 tif->tif_dir.td_ycbcrsubsampling[0]=sp->subsampling_hor; 515 tif->tif_dir.td_ycbcrsubsampling[1]=sp->subsampling_ver; 516 break; 517 case TIFFTAG_JPEGQTABLES: 518 ma=va_arg(ap,uint32); 519 if (ma!=0) 520 { 521 if (ma>3) 522 { 523 TIFFErrorExt(tif->tif_clientdata,module,"JpegQTables tag has incorrect count"); 524 return(0); 525 } 526 sp->qtable_offset_count=(uint8)ma; 527 mb=va_arg(ap,uint32*); 528 for (n=0; n<ma; n++) 529 sp->qtable_offset[n]=(toff_t)mb[n]; 530 } 531 break; 532 case TIFFTAG_JPEGDCTABLES: 533 ma=va_arg(ap,uint32); 534 if (ma!=0) 535 { 536 if (ma>3) 537 { 538 TIFFErrorExt(tif->tif_clientdata,module,"JpegDcTables tag has incorrect count"); 539 return(0); 540 } 541 sp->dctable_offset_count=(uint8)ma; 542 mb=va_arg(ap,uint32*); 543 for (n=0; n<ma; n++) 544 sp->dctable_offset[n]=(toff_t)mb[n]; 545 } 546 break; 547 case TIFFTAG_JPEGACTABLES: 548 ma=va_arg(ap,uint32); 549 if (ma!=0) 550 { 551 if (ma>3) 552 { 553 TIFFErrorExt(tif->tif_clientdata,module,"JpegAcTables tag has incorrect count"); 554 return(0); 555 } 556 sp->actable_offset_count=(uint8)ma; 557 mb=va_arg(ap,uint32*); 558 for (n=0; n<ma; n++) 559 sp->actable_offset[n]=(toff_t)mb[n]; 560 } 561 break; 562 case TIFFTAG_JPEGPROC: 563 sp->jpeg_proc=(uint8)va_arg(ap,uint32); 564 break; 565 case TIFFTAG_JPEGRESTARTINTERVAL: 566 sp->restart_interval=(uint16)va_arg(ap,uint32); 567 break; 568 default: 569 return (*sp->vsetparent)(tif,tag,ap); 570 } 571 TIFFSetFieldBit(tif,_TIFFFieldWithTag(tif,tag)->field_bit); 572 tif->tif_flags|=TIFF_DIRTYDIRECT; 573 return(1); 574 } 575 329 576 static void 330 TIFFojpeg_error_exit(register j_common_ptr cinfo) 331 { 332 char buffer[JMSG_LENGTH_MAX]; 333 int code = cinfo->err->msg_code; 334 335 if (((OJPEGState *)cinfo)->is_WANG) { 336 if (code == JERR_SOF_DUPLICATE || code == JERR_SOI_DUPLICATE) 337 return; /* ignore it */ 338 } 339 340 (*cinfo->err->format_message)(cinfo,buffer); 341 TIFFError(JPEGLib_name,buffer); /* Display error message */ 342 jpeg_abort(cinfo); /* Clean up JPEG Library state */ 343 LONGJMP(((OJPEGState *)cinfo)->exit_jmpbuf,1); /* Return to TIFF client */ 577 OJPEGPrintDir(TIFF* tif, FILE* fd, long flags) 578 { 579 OJPEGState* sp=(OJPEGState*)tif->tif_data; 580 uint8 m; 581 (void)flags; 582 assert(sp!=NULL); 583 if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGINTERCHANGEFORMAT)) 584 fprintf(fd," JpegInterchangeFormat: %lu\n",(unsigned long)sp->jpeg_interchange_format); 585 if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH)) 586 fprintf(fd," JpegInterchangeFormatLength: %lu\n",(unsigned long)sp->jpeg_interchange_format_length); 587 if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGQTABLES)) 588 { 589 fprintf(fd," JpegQTables:"); 590 for (m=0; m<sp->qtable_offset_count; m++) 591 fprintf(fd," %lu",(unsigned long)sp->qtable_offset[m]); 592 fprintf(fd,"\n"); 593 } 594 if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGDCTABLES)) 595 { 596 fprintf(fd," JpegDcTables:"); 597 for (m=0; m<sp->dctable_offset_count; m++) 598 fprintf(fd," %lu",(unsigned long)sp->dctable_offset[m]); 599 fprintf(fd,"\n"); 600 } 601 if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGACTABLES)) 602 { 603 fprintf(fd," JpegAcTables:"); 604 for (m=0; m<sp->actable_offset_count; m++) 605 fprintf(fd," %lu",(unsigned long)sp->actable_offset[m]); 606 fprintf(fd,"\n"); 607 } 608 if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGPROC)) 609 fprintf(fd," JpegProc: %u\n",(unsigned int)sp->jpeg_proc); 610 if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGRESTARTINTERVAL)) 611 fprintf(fd," JpegRestartInterval: %u\n",(unsigned int)sp->restart_interval); 612 } 613 614 static int 615 OJPEGSetupDecode(TIFF* tif) 616 { 617 static const char module[]="OJPEGSetupDecode"; 618 TIFFWarningExt(tif->tif_clientdata,module,"Depreciated and troublesome old-style JPEG compression mode, please convert to new-style JPEG compression and notify vendor of writing software"); 619 return(1); 620 } 621 622 static int 623 OJPEGPreDecode(TIFF* tif, tsample_t s) 624 { 625 OJPEGState* sp=(OJPEGState*)tif->tif_data; 626 tstrile_t m; 627 if (sp->subsamplingcorrect_done==0) 628 OJPEGSubsamplingCorrect(tif); 629 if (sp->readheader_done==0) 630 { 631 if (OJPEGReadHeaderInfo(tif)==0) 632 return(0); 633 } 634 if (sp->sos_end[s].log==0) 635 { 636 if (OJPEGReadSecondarySos(tif,s)==0) 637 return(0); 638 } 639 if isTiled(tif) 640 m=(tstrile_t)tif->tif_curtile; 641 else 642 m=(tstrile_t)tif->tif_curstrip; 643 if ((sp->writeheader_done!=0) && ((sp->write_cursample!=s) || (sp->write_curstrile>m))) 644 { 645 if (sp->libjpeg_session_active!=0) 646 OJPEGLibjpegSessionAbort(tif); 647 sp->writeheader_done=0; 648 } 649 if (sp->writeheader_done==0) 650 { 651 sp->plane_sample_offset=s; 652 sp->write_cursample=s; 653 sp->write_curstrile=s*tif->tif_dir.td_stripsperimage; 654 if ((sp->in_buffer_file_pos_log==0) || 655 (sp->in_buffer_file_pos-sp->in_buffer_togo!=sp->sos_end[s].in_buffer_file_pos)) 656 { 657 sp->in_buffer_source=sp->sos_end[s].in_buffer_source; 658 sp->in_buffer_next_strile=sp->sos_end[s].in_buffer_next_strile; 659 sp->in_buffer_file_pos=sp->sos_end[s].in_buffer_file_pos; 660 sp->in_buffer_file_pos_log=0; 661 sp->in_buffer_file_togo=sp->sos_end[s].in_buffer_file_togo; 662 sp->in_buffer_togo=0; 663 sp->in_buffer_cur=0; 664 } 665 if (OJPEGWriteHeaderInfo(tif)==0) 666 return(0); 667 } 668 while (sp->write_curstrile<m) 669 { 670 if (sp->libjpeg_jpeg_query_style==0) 671 { 672 if (OJPEGPreDecodeSkipRaw(tif)==0) 673 return(0); 674 } 675 else 676 { 677 if (OJPEGPreDecodeSkipScanlines(tif)==0) 678 return(0); 679 } 680 sp->write_curstrile++; 681 } 682 return(1); 683 } 684 685 static int 686 OJPEGPreDecodeSkipRaw(TIFF* tif) 687 { 688 OJPEGState* sp=(OJPEGState*)tif->tif_data; 689 uint32 m; 690 m=sp->lines_per_strile; 691 if (sp->subsampling_convert_state!=0) 692 { 693 if (sp->subsampling_convert_clines-sp->subsampling_convert_state>=m) 694 { 695 sp->subsampling_convert_state+=m; 696 if (sp->subsampling_convert_state==sp->subsampling_convert_clines) 697 sp->subsampling_convert_state=0; 698 return(1); 699 } 700 m-=sp->subsampling_convert_clines-sp->subsampling_convert_state; 701 sp->subsampling_convert_state=0; 702 } 703 while (m>=sp->subsampling_convert_clines) 704 { 705 if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0) 706 return(0); 707 m-=sp->subsampling_convert_clines; 708 } 709 if (m>0) 710 { 711 if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0) 712 return(0); 713 sp->subsampling_convert_state=m; 714 } 715 return(1); 716 } 717 718 static int 719 OJPEGPreDecodeSkipScanlines(TIFF* tif) 720 { 721 static const char module[]="OJPEGPreDecodeSkipScanlines"; 722 OJPEGState* sp=(OJPEGState*)tif->tif_data; 723 uint32 m; 724 if (sp->skip_buffer==NULL) 725 { 726 sp->skip_buffer=_TIFFmalloc(sp->bytes_per_line); 727 if (sp->skip_buffer==NULL) 728 { 729 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 730 return(0); 731 } 732 } 733 for (m=0; m<sp->lines_per_strile; m++) 734 { 735 if (jpeg_read_scanlines_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),&sp->skip_buffer,1)==0) 736 return(0); 737 } 738 return(1); 739 } 740 741 static int 742 OJPEGDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s) 743 { 744 OJPEGState* sp=(OJPEGState*)tif->tif_data; 745 (void)s; 746 if (sp->libjpeg_jpeg_query_style==0) 747 { 748 if (OJPEGDecodeRaw(tif,buf,cc)==0) 749 return(0); 750 } 751 else 752 { 753 if (OJPEGDecodeScanlines(tif,buf,cc)==0) 754 return(0); 755 } 756 return(1); 757 } 758 759 static int 760 OJPEGDecodeRaw(TIFF* tif, tidata_t buf, tsize_t cc) 761 { 762 static const char module[]="OJPEGDecodeRaw"; 763 OJPEGState* sp=(OJPEGState*)tif->tif_data; 764 uint8* m; 765 uint32 n; 766 uint8* oy; 767 uint8* ocb; 768 uint8* ocr; 769 uint8* p; 770 uint32 q; 771 uint8* r; 772 uint8 sx,sy; 773 if (cc%sp->bytes_per_line!=0) 774 { 775 TIFFErrorExt(tif->tif_clientdata,module,"Fractional scanline not read"); 776 return(0); 777 } 778 assert(cc>0); 779 m=buf; 780 n=cc; 781 do 782 { 783 if (sp->subsampling_convert_state==0) 784 { 785 if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0) 786 return(0); 787 } 788 oy=sp->subsampling_convert_ybuf+sp->subsampling_convert_state*sp->subsampling_ver*sp->subsampling_convert_ylinelen; 789 ocb=sp->subsampling_convert_cbbuf+sp->subsampling_convert_state*sp->subsampling_convert_clinelen; 790 ocr=sp->subsampling_convert_crbuf+sp->subsampling_convert_state*sp->subsampling_convert_clinelen; 791 p=m; 792 for (q=0; q<sp->subsampling_convert_clinelenout; q++) 793 { 794 r=oy; 795 for (sy=0; sy<sp->subsampling_ver; sy++) 796 { 797 for (sx=0; sx<sp->subsampling_hor; sx++) 798 *p++=*r++; 799 r+=sp->subsampling_convert_ylinelen-sp->subsampling_hor; 800 } 801 oy+=sp->subsampling_hor; 802 *p++=*ocb++; 803 *p++=*ocr++; 804 } 805 sp->subsampling_convert_state++; 806 if (sp->subsampling_convert_state==sp->subsampling_convert_clines) 807 sp->subsampling_convert_state=0; 808 m+=sp->bytes_per_line; 809 n-=sp->bytes_per_line; 810 } while(n>0); 811 return(1); 812 } 813 814 static int 815 OJPEGDecodeScanlines(TIFF* tif, tidata_t buf, tsize_t cc) 816 { 817 static const char module[]="OJPEGDecodeScanlines"; 818 OJPEGState* sp=(OJPEGState*)tif->tif_data; 819 uint8* m; 820 uint32 n; 821 if (cc%sp->bytes_per_line!=0) 822 { 823 TIFFErrorExt(tif->tif_clientdata,module,"Fractional scanline not read"); 824 return(0); 825 } 826 assert(cc>0); 827 m=buf; 828 n=cc; 829 do 830 { 831 if (jpeg_read_scanlines_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),&m,1)==0) 832 return(0); 833 m+=sp->bytes_per_line; 834 n-=sp->bytes_per_line; 835 } while(n>0); 836 return(1); 344 837 } 345 838 346 839 static void 347 TIFFojpeg_output_message(register j_common_ptr cinfo) 348 { char buffer[JMSG_LENGTH_MAX]; 349 350 /* This subroutine is invoked only for warning messages, since the JPEG 351 Library's "error_exit" method does its own thing and "trace_level" is never 352 set > 0. 353 */ 354 (*cinfo->err->format_message)(cinfo,buffer); 355 TIFFWarning(JPEGLib_name,buffer); 356 } 357 358 /* The following subroutines, which also interface with the JPEG Library, exist 359 mainly in limit the side effects of "setjmp()" and convert JPEG normal/error 360 conditions into TIFF Library return codes. 361 */ 362 #define CALLJPEG(sp,fail,op)(SETJMP((sp)->exit_jmpbuf)?(fail):(op)) 363 #define CALLVJPEG(sp,op)CALLJPEG(sp,0,((op),1)) 364 #ifdef never 365 366 static int 367 TIFFojpeg_create_compress(register OJPEGState *sp) 368 { 369 sp->cinfo.c.err = jpeg_std_error(&sp->err); /* Initialize error handling */ 370 sp->err.error_exit = TIFFojpeg_error_exit; 371 sp->err.output_message = TIFFojpeg_output_message; 372 return CALLVJPEG(sp,jpeg_create_compress(&sp->cinfo.c)); 373 } 374 375 /* The following subroutines comprise a JPEG Library "destination" data manager 376 by directing compressed data from the JPEG Library to a TIFF Library output 377 buffer. 378 */ 840 OJPEGPostDecode(TIFF* tif, tidata_t buf, tsize_t cc) 841 { 842 OJPEGState* sp=(OJPEGState*)tif->tif_data; 843 (void)buf; 844 (void)cc; 845 sp->write_curstrile++; 846 if (sp->write_curstrile%tif->tif_dir.td_stripsperimage==0) 847 { 848 assert(sp->libjpeg_session_active!=0); 849 OJPEGLibjpegSessionAbort(tif); 850 sp->writeheader_done=0; 851 } 852 } 853 854 static int 855 OJPEGSetupEncode(TIFF* tif) 856 { 857 static const char module[]="OJPEGSetupEncode"; 858 TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); 859 return(0); 860 } 861 862 static int 863 OJPEGPreEncode(TIFF* tif, tsample_t s) 864 { 865 static const char module[]="OJPEGPreEncode"; 866 (void)s; 867 TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); 868 return(0); 869 } 870 871 static int 872 OJPEGEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s) 873 { 874 static const char module[]="OJPEGEncode"; 875 (void)buf; 876 (void)cc; 877 (void)s; 878 TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); 879 return(0); 880 } 881 882 static int 883 OJPEGPostEncode(TIFF* tif) 884 { 885 static const char module[]="OJPEGPostEncode"; 886 TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); 887 return(0); 888 } 889 379 890 static void 380 std_init_destination(register j_compress_ptr cinfo){} /* "Dummy" stub */ 891 OJPEGCleanup(TIFF* tif) 892 { 893 OJPEGState* sp=(OJPEGState*)tif->tif_data; 894 if (sp!=0) 895 { 896 tif->tif_tagmethods.vgetfield=sp->vgetparent; 897 tif->tif_tagmethods.vsetfield=sp->vsetparent; 898 if (sp->qtable[0]!=0) 899 _TIFFfree(sp->qtable[0]); 900 if (sp->qtable[1]!=0) 901 _TIFFfree(sp->qtable[1]); 902 if (sp->qtable[2]!=0) 903 _TIFFfree(sp->qtable[2]); 904 if (sp->qtable[3]!=0) 905 _TIFFfree(sp->qtable[3]); 906 if (sp->dctable[0]!=0) 907 _TIFFfree(sp->dctable[0]); 908 if (sp->dctable[1]!=0) 909 _TIFFfree(sp->dctable[1]); 910 if (sp->dctable[2]!=0) 911 _TIFFfree(sp->dctable[2]); 912 if (sp->dctable[3]!=0) 913 _TIFFfree(sp->dctable[3]); 914 if (sp->actable[0]!=0) 915 _TIFFfree(sp->actable[0]); 916 if (sp->actable[1]!=0) 917 _TIFFfree(sp->actable[1]); 918 if (sp->actable[2]!=0) 919 _TIFFfree(sp->actable[2]); 920 if (sp->actable[3]!=0) 921 _TIFFfree(sp->actable[3]); 922 if (sp->libjpeg_session_active!=0) 923 OJPEGLibjpegSessionAbort(tif); 924 if (sp->subsampling_convert_ycbcrbuf!=0) 925 _TIFFfree(sp->subsampling_convert_ycbcrbuf); 926 if (sp->subsampling_convert_ycbcrimage!=0) 927 _TIFFfree(sp->subsampling_convert_ycbcrimage); 928 if (sp->skip_buffer!=0) 929 _TIFFfree(sp->skip_buffer); 930 _TIFFfree(sp); 931 tif->tif_data=NULL; 932 _TIFFSetDefaultCompressionState(tif); 933 } 934 } 935 936 static void 937 OJPEGSubsamplingCorrect(TIFF* tif) 938 { 939 static const char module[]="OJPEGSubsamplingCorrect"; 940 OJPEGState* sp=(OJPEGState*)tif->tif_data; 941 uint8 mh; 942 uint8 mv; 943 assert(sp->subsamplingcorrect_done==0); 944 if ((tif->tif_dir.td_samplesperpixel!=3) || ((tif->tif_dir.td_photometric!=PHOTOMETRIC_YCBCR) && 945 (tif->tif_dir.td_photometric!=PHOTOMETRIC_ITULAB))) 946 { 947 if (sp->subsampling_tag!=0) 948 TIFFWarningExt(tif->tif_clientdata,module,"Subsampling tag not appropriate for this Photometric and/or SamplesPerPixel"); 949 sp->subsampling_hor=1; 950 sp->subsampling_ver=1; 951 sp->subsampling_force_desubsampling_inside_decompression=0; 952 } 953 else 954 { 955 sp->subsamplingcorrect_done=1; 956 mh=sp->subsampling_hor; 957 mv=sp->subsampling_ver; 958 sp->subsamplingcorrect=1; 959 OJPEGReadHeaderInfoSec(tif); 960 if (sp->subsampling_force_desubsampling_inside_decompression!=0) 961 { 962 sp->subsampling_hor=1; 963 sp->subsampling_ver=1; 964 } 965 sp->subsamplingcorrect=0; 966 if (((sp->subsampling_hor!=mh) || (sp->subsampling_ver!=mv)) && (sp->subsampling_force_desubsampling_inside_decompression==0)) 967 { 968 if (sp->subsampling_tag==0) 969 TIFFWarningExt(tif->tif_clientdata,module,"Subsampling tag is not set, yet subsampling inside JPEG data [%d,%d] does not match default values [2,2]; assuming subsampling inside JPEG data is correct",sp->subsampling_hor,sp->subsampling_ver); 970 else 971 TIFFWarningExt(tif->tif_clientdata,module,"Subsampling inside JPEG data [%d,%d] does not match subsampling tag values [%d,%d]; assuming subsampling inside JPEG data is correct",sp->subsampling_hor,sp->subsampling_ver,mh,mv); 972 } 973 if (sp->subsampling_force_desubsampling_inside_decompression!=0) 974 { 975 if (sp->subsampling_tag==0) 976 TIFFWarningExt(tif->tif_clientdata,module,"Subsampling tag is not set, yet subsampling inside JPEG data does not match default values [2,2] (nor any other values allowed in TIFF); assuming subsampling inside JPEG data is correct and desubsampling inside JPEG decompression"); 977 else 978 TIFFWarningExt(tif->tif_clientdata,module,"Subsampling inside JPEG data does not match subsampling tag values [%d,%d] (nor any other values allowed in TIFF); assuming subsampling inside JPEG data is correct and desubsampling inside JPEG decompression",mh,mv); 979 } 980 if (sp->subsampling_force_desubsampling_inside_decompression==0) 981 { 982 if (sp->subsampling_hor<sp->subsampling_ver) 983 TIFFWarningExt(tif->tif_clientdata,module,"Subsampling values [%d,%d] are not allowed in TIFF",sp->subsampling_hor,sp->subsampling_ver); 984 } 985 } 986 sp->subsamplingcorrect_done=1; 987 } 988 989 static int 990 OJPEGReadHeaderInfo(TIFF* tif) 991 { 992 static const char module[]="OJPEGReadHeaderInfo"; 993 OJPEGState* sp=(OJPEGState*)tif->tif_data; 994 assert(sp->readheader_done==0); 995 sp->image_width=tif->tif_dir.td_imagewidth; 996 sp->image_length=tif->tif_dir.td_imagelength; 997 if isTiled(tif) 998 { 999 sp->strile_width=tif->tif_dir.td_tilewidth; 1000 sp->strile_length=tif->tif_dir.td_tilelength; 1001 sp->strile_length_total=((sp->image_length+sp->strile_length-1)/sp->strile_length)*sp->strile_length; 1002 } 1003 else 1004 { 1005 sp->strile_width=sp->image_width; 1006 sp->strile_length=tif->tif_dir.td_rowsperstrip; 1007 sp->strile_length_total=sp->image_length; 1008 } 1009 sp->samples_per_pixel=tif->tif_dir.td_samplesperpixel; 1010 if (sp->samples_per_pixel==1) 1011 { 1012 sp->plane_sample_offset=0; 1013 sp->samples_per_pixel_per_plane=sp->samples_per_pixel; 1014 sp->subsampling_hor=1; 1015 sp->subsampling_ver=1; 1016 } 1017 else 1018 { 1019 if (sp->samples_per_pixel!=3) 1020 { 1021 TIFFErrorExt(tif->tif_clientdata,module,"SamplesPerPixel %d not supported for this compression scheme",sp->samples_per_pixel); 1022 return(0); 1023 } 1024 sp->plane_sample_offset=0; 1025 if (tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG) 1026 sp->samples_per_pixel_per_plane=3; 1027 else 1028 sp->samples_per_pixel_per_plane=1; 1029 } 1030 if (sp->strile_length<sp->image_length) 1031 { 1032 if (sp->strile_length%(sp->subsampling_ver*8)!=0) 1033 { 1034 TIFFErrorExt(tif->tif_clientdata,module,"Incompatible vertical subsampling and image strip/tile length"); 1035 return(0); 1036 } 1037 sp->restart_interval=((sp->strile_width+sp->subsampling_hor*8-1)/(sp->subsampling_hor*8))*(sp->strile_length/(sp->subsampling_ver*8)); 1038 } 1039 if (OJPEGReadHeaderInfoSec(tif)==0) 1040 return(0); 1041 sp->sos_end[0].log=1; 1042 sp->sos_end[0].in_buffer_source=sp->in_buffer_source; 1043 sp->sos_end[0].in_buffer_next_strile=sp->in_buffer_next_strile; 1044 sp->sos_end[0].in_buffer_file_pos=sp->in_buffer_file_pos-sp->in_buffer_togo; 1045 sp->sos_end[0].in_buffer_file_togo=sp->in_buffer_file_togo+sp->in_buffer_togo; 1046 sp->readheader_done=1; 1047 return(1); 1048 } 1049 1050 static int 1051 OJPEGReadSecondarySos(TIFF* tif, tsample_t s) 1052 { 1053 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1054 uint8 m; 1055 assert(s>0); 1056 assert(s<3); 1057 assert(sp->sos_end[0].log!=0); 1058 assert(sp->sos_end[s].log==0); 1059 sp->plane_sample_offset=s-1; 1060 while(sp->sos_end[sp->plane_sample_offset].log==0) 1061 sp->plane_sample_offset--; 1062 sp->in_buffer_source=sp->sos_end[sp->plane_sample_offset].in_buffer_source; 1063 sp->in_buffer_next_strile=sp->sos_end[sp->plane_sample_offset].in_buffer_next_strile; 1064 sp->in_buffer_file_pos=sp->sos_end[sp->plane_sample_offset].in_buffer_file_pos; 1065 sp->in_buffer_file_pos_log=0; 1066 sp->in_buffer_file_togo=sp->sos_end[sp->plane_sample_offset].in_buffer_file_togo; 1067 sp->in_buffer_togo=0; 1068 sp->in_buffer_cur=0; 1069 while(sp->plane_sample_offset<s) 1070 { 1071 do 1072 { 1073 if (OJPEGReadByte(sp,&m)==0) 1074 return(0); 1075 if (m==255) 1076 { 1077 do 1078 { 1079 if (OJPEGReadByte(sp,&m)==0) 1080 return(0); 1081 if (m!=255) 1082 break; 1083 } while(1); 1084 if (m==JPEG_MARKER_SOS) 1085 break; 1086 } 1087 } while(1); 1088 sp->plane_sample_offset++; 1089 if (OJPEGReadHeaderInfoSecStreamSos(tif)==0) 1090 return(0); 1091 sp->sos_end[sp->plane_sample_offset].log=1; 1092 sp->sos_end[sp->plane_sample_offset].in_buffer_source=sp->in_buffer_source; 1093 sp->sos_end[sp->plane_sample_offset].in_buffer_next_strile=sp->in_buffer_next_strile; 1094 sp->sos_end[sp->plane_sample_offset].in_buffer_file_pos=sp->in_buffer_file_pos-sp->in_buffer_togo; 1095 sp->sos_end[sp->plane_sample_offset].in_buffer_file_togo=sp->in_buffer_file_togo+sp->in_buffer_togo; 1096 } 1097 return(1); 1098 } 1099 1100 static int 1101 OJPEGWriteHeaderInfo(TIFF* tif) 1102 { 1103 static const char module[]="OJPEGWriteHeaderInfo"; 1104 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1105 uint8** m; 1106 uint32 n; 1107 assert(sp->libjpeg_session_active==0); 1108 sp->out_state=ososSoi; 1109 sp->restart_index=0; 1110 jpeg_std_error(&(sp->libjpeg_jpeg_error_mgr)); 1111 sp->libjpeg_jpeg_error_mgr.output_message=OJPEGLibjpegJpegErrorMgrOutputMessage; 1112 sp->libjpeg_jpeg_error_mgr.error_exit=OJPEGLibjpegJpegErrorMgrErrorExit; 1113 sp->libjpeg_jpeg_decompress_struct.err=&(sp->libjpeg_jpeg_error_mgr); 1114 sp->libjpeg_jpeg_decompress_struct.client_data=(void*)tif; 1115 if (jpeg_create_decompress_encap(sp,&(sp->libjpeg_jpeg_decompress_struct))==0) 1116 return(0); 1117 sp->libjpeg_session_active=1; 1118 sp->libjpeg_jpeg_source_mgr.bytes_in_buffer=0; 1119 sp->libjpeg_jpeg_source_mgr.init_source=OJPEGLibjpegJpegSourceMgrInitSource; 1120 sp->libjpeg_jpeg_source_mgr.fill_input_buffer=OJPEGLibjpegJpegSourceMgrFillInputBuffer; 1121 sp->libjpeg_jpeg_source_mgr.skip_input_data=OJPEGLibjpegJpegSourceMgrSkipInputData; 1122 sp->libjpeg_jpeg_source_mgr.resync_to_restart=OJPEGLibjpegJpegSourceMgrResyncToRestart; 1123 sp->libjpeg_jpeg_source_mgr.term_source=OJPEGLibjpegJpegSourceMgrTermSource; 1124 sp->libjpeg_jpeg_decompress_struct.src=&(sp->libjpeg_jpeg_source_mgr); 1125 if (jpeg_read_header_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),1)==0) 1126 return(0); 1127 if ((sp->subsampling_force_desubsampling_inside_decompression==0) && (sp->samples_per_pixel_per_plane>1)) 1128 { 1129 sp->libjpeg_jpeg_decompress_struct.raw_data_out=1; 1130 #if JPEG_LIB_VERSION >= 70 1131 sp->libjpeg_jpeg_decompress_struct.do_fancy_upsampling=FALSE; 1132 #endif 1133 sp->libjpeg_jpeg_query_style=0; 1134 if (sp->subsampling_convert_log==0) 1135 { 1136 assert(sp->subsampling_convert_ycbcrbuf==0); 1137 assert(sp->subsampling_convert_ycbcrimage==0); 1138 sp->subsampling_convert_ylinelen=((sp->strile_width+sp->subsampling_hor*8-1)/(sp->subsampling_hor*8)*sp->subsampling_hor*8); 1139 sp->subsampling_convert_ylines=sp->subsampling_ver*8; 1140 sp->subsampling_convert_clinelen=sp->subsampling_convert_ylinelen/sp->subsampling_hor; 1141 sp->subsampling_convert_clines=8; 1142 sp->subsampling_convert_ybuflen=sp->subsampling_convert_ylinelen*sp->subsampling_convert_ylines; 1143 sp->subsampling_convert_cbuflen=sp->subsampling_convert_clinelen*sp->subsampling_convert_clines; 1144 sp->subsampling_convert_ycbcrbuflen=sp->subsampling_convert_ybuflen+2*sp->subsampling_convert_cbuflen; 1145 sp->subsampling_convert_ycbcrbuf=_TIFFmalloc(sp->subsampling_convert_ycbcrbuflen); 1146 if (sp->subsampling_convert_ycbcrbuf==0) 1147 { 1148 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1149 return(0); 1150 } 1151 sp->subsampling_convert_ybuf=sp->subsampling_convert_ycbcrbuf; 1152 sp->subsampling_convert_cbbuf=sp->subsampling_convert_ybuf+sp->subsampling_convert_ybuflen; 1153 sp->subsampling_convert_crbuf=sp->subsampling_convert_cbbuf+sp->subsampling_convert_cbuflen; 1154 sp->subsampling_convert_ycbcrimagelen=3+sp->subsampling_convert_ylines+2*sp->subsampling_convert_clines; 1155 sp->subsampling_convert_ycbcrimage=_TIFFmalloc(sp->subsampling_convert_ycbcrimagelen*sizeof(uint8*)); 1156 if (sp->subsampling_convert_ycbcrimage==0) 1157 { 1158 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1159 return(0); 1160 } 1161 m=sp->subsampling_convert_ycbcrimage; 1162 *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3); 1163 *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3+sp->subsampling_convert_ylines); 1164 *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3+sp->subsampling_convert_ylines+sp->subsampling_convert_clines); 1165 for (n=0; n<sp->subsampling_convert_ylines; n++) 1166 *m++=sp->subsampling_convert_ybuf+n*sp->subsampling_convert_ylinelen; 1167 for (n=0; n<sp->subsampling_convert_clines; n++) 1168 *m++=sp->subsampling_convert_cbbuf+n*sp->subsampling_convert_clinelen; 1169 for (n=0; n<sp->subsampling_convert_clines; n++) 1170 *m++=sp->subsampling_convert_crbuf+n*sp->subsampling_convert_clinelen; 1171 sp->subsampling_convert_clinelenout=((sp->strile_width+sp->subsampling_hor-1)/sp->subsampling_hor); 1172 sp->subsampling_convert_state=0; 1173 sp->bytes_per_line=sp->subsampling_convert_clinelenout*(sp->subsampling_ver*sp->subsampling_hor+2); 1174 sp->lines_per_strile=((sp->strile_length+sp->subsampling_ver-1)/sp->subsampling_ver); 1175 sp->subsampling_convert_log=1; 1176 } 1177 } 1178 else 1179 { 1180 sp->libjpeg_jpeg_decompress_struct.jpeg_color_space=JCS_UNKNOWN; 1181 sp->libjpeg_jpeg_decompress_struct.out_color_space=JCS_UNKNOWN; 1182 sp->libjpeg_jpeg_query_style=1; 1183 sp->bytes_per_line=sp->samples_per_pixel_per_plane*sp->strile_width; 1184 sp->lines_per_strile=sp->strile_length; 1185 } 1186 if (jpeg_start_decompress_encap(sp,&(sp->libjpeg_jpeg_decompress_struct))==0) 1187 return(0); 1188 sp->writeheader_done=1; 1189 return(1); 1190 } 1191 1192 static void 1193 OJPEGLibjpegSessionAbort(TIFF* tif) 1194 { 1195 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1196 assert(sp->libjpeg_session_active!=0); 1197 jpeg_destroy((jpeg_common_struct*)(&(sp->libjpeg_jpeg_decompress_struct))); 1198 sp->libjpeg_session_active=0; 1199 } 1200 1201 static int 1202 OJPEGReadHeaderInfoSec(TIFF* tif) 1203 { 1204 static const char module[]="OJPEGReadHeaderInfoSec"; 1205 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1206 uint8 m; 1207 uint16 n; 1208 uint8 o; 1209 if (sp->file_size==0) 1210 sp->file_size=TIFFGetFileSize(tif); 1211 if (sp->jpeg_interchange_format!=0) 1212 { 1213 if (sp->jpeg_interchange_format>=sp->file_size) 1214 { 1215 sp->jpeg_interchange_format=0; 1216 sp->jpeg_interchange_format_length=0; 1217 } 1218 else 1219 { 1220 if ((sp->jpeg_interchange_format_length==0) || (sp->jpeg_interchange_format+sp->jpeg_interchange_format_length>sp->file_size)) 1221 sp->jpeg_interchange_format_length=sp->file_size-sp->jpeg_interchange_format; 1222 } 1223 } 1224 sp->in_buffer_source=osibsNotSetYet; 1225 sp->in_buffer_next_strile=0; 1226 sp->in_buffer_strile_count=tif->tif_dir.td_nstrips; 1227 sp->in_buffer_file_togo=0; 1228 sp->in_buffer_togo=0; 1229 do 1230 { 1231 if (OJPEGReadBytePeek(sp,&m)==0) 1232 return(0); 1233 if (m!=255) 1234 break; 1235 OJPEGReadByteAdvance(sp); 1236 do 1237 { 1238 if (OJPEGReadByte(sp,&m)==0) 1239 return(0); 1240 } while(m==255); 1241 switch(m) 1242 { 1243 case JPEG_MARKER_SOI: 1244 /* this type of marker has no data, and should be skipped */ 1245 break; 1246 case JPEG_MARKER_COM: 1247 case JPEG_MARKER_APP0: 1248 case JPEG_MARKER_APP0+1: 1249 case JPEG_MARKER_APP0+2: 1250 case JPEG_MARKER_APP0+3: 1251 case JPEG_MARKER_APP0+4: 1252 case JPEG_MARKER_APP0+5: 1253 case JPEG_MARKER_APP0+6: 1254 case JPEG_MARKER_APP0+7: 1255 case JPEG_MARKER_APP0+8: 1256 case JPEG_MARKER_APP0+9: 1257 case JPEG_MARKER_APP0+10: 1258 case JPEG_MARKER_APP0+11: 1259 case JPEG_MARKER_APP0+12: 1260 case JPEG_MARKER_APP0+13: 1261 case JPEG_MARKER_APP0+14: 1262 case JPEG_MARKER_APP0+15: 1263 /* this type of marker has data, but it has no use to us (and no place here) and should be skipped */ 1264 if (OJPEGReadWord(sp,&n)==0) 1265 return(0); 1266 if (n<2) 1267 { 1268 if (sp->subsamplingcorrect==0) 1269 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JPEG data"); 1270 return(0); 1271 } 1272 if (n>2) 1273 OJPEGReadSkip(sp,n-2); 1274 break; 1275 case JPEG_MARKER_DRI: 1276 if (OJPEGReadHeaderInfoSecStreamDri(tif)==0) 1277 return(0); 1278 break; 1279 case JPEG_MARKER_DQT: 1280 if (OJPEGReadHeaderInfoSecStreamDqt(tif)==0) 1281 return(0); 1282 break; 1283 case JPEG_MARKER_DHT: 1284 if (OJPEGReadHeaderInfoSecStreamDht(tif)==0) 1285 return(0); 1286 break; 1287 case JPEG_MARKER_SOF0: 1288 case JPEG_MARKER_SOF1: 1289 case JPEG_MARKER_SOF3: 1290 if (OJPEGReadHeaderInfoSecStreamSof(tif,m)==0) 1291 return(0); 1292 if (sp->subsamplingcorrect!=0) 1293 return(1); 1294 break; 1295 case JPEG_MARKER_SOS: 1296 if (sp->subsamplingcorrect!=0) 1297 return(1); 1298 assert(sp->plane_sample_offset==0); 1299 if (OJPEGReadHeaderInfoSecStreamSos(tif)==0) 1300 return(0); 1301 break; 1302 default: 1303 TIFFErrorExt(tif->tif_clientdata,module,"Unknown marker type %d in JPEG data",m); 1304 return(0); 1305 } 1306 } while(m!=JPEG_MARKER_SOS); 1307 if (sp->subsamplingcorrect) 1308 return(1); 1309 if (sp->sof_log==0) 1310 { 1311 if (OJPEGReadHeaderInfoSecTablesQTable(tif)==0) 1312 return(0); 1313 sp->sof_marker_id=JPEG_MARKER_SOF0; 1314 for (o=0; o<sp->samples_per_pixel; o++) 1315 sp->sof_c[o]=o; 1316 sp->sof_hv[0]=((sp->subsampling_hor<<4)|sp->subsampling_ver); 1317 for (o=1; o<sp->samples_per_pixel; o++) 1318 sp->sof_hv[o]=17; 1319 sp->sof_x=sp->strile_width; 1320 sp->sof_y=sp->strile_length_total; 1321 sp->sof_log=1; 1322 if (OJPEGReadHeaderInfoSecTablesDcTable(tif)==0) 1323 return(0); 1324 if (OJPEGReadHeaderInfoSecTablesAcTable(tif)==0) 1325 return(0); 1326 for (o=1; o<sp->samples_per_pixel; o++) 1327 sp->sos_cs[o]=o; 1328 } 1329 return(1); 1330 } 1331 1332 static int 1333 OJPEGReadHeaderInfoSecStreamDri(TIFF* tif) 1334 { 1335 /* this could easilly cause trouble in some cases... but no such cases have occured sofar */ 1336 static const char module[]="OJPEGReadHeaderInfoSecStreamDri"; 1337 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1338 uint16 m; 1339 if (OJPEGReadWord(sp,&m)==0) 1340 return(0); 1341 if (m!=4) 1342 { 1343 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DRI marker in JPEG data"); 1344 return(0); 1345 } 1346 if (OJPEGReadWord(sp,&m)==0) 1347 return(0); 1348 sp->restart_interval=m; 1349 return(1); 1350 } 1351 1352 static int 1353 OJPEGReadHeaderInfoSecStreamDqt(TIFF* tif) 1354 { 1355 /* this is a table marker, and it is to be saved as a whole for exact pushing on the jpeg stream later on */ 1356 static const char module[]="OJPEGReadHeaderInfoSecStreamDqt"; 1357 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1358 uint16 m; 1359 uint32 na; 1360 uint8* nb; 1361 uint8 o; 1362 if (OJPEGReadWord(sp,&m)==0) 1363 return(0); 1364 if (m<=2) 1365 { 1366 if (sp->subsamplingcorrect==0) 1367 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DQT marker in JPEG data"); 1368 return(0); 1369 } 1370 if (sp->subsamplingcorrect!=0) 1371 OJPEGReadSkip(sp,m-2); 1372 else 1373 { 1374 m-=2; 1375 do 1376 { 1377 if (m<65) 1378 { 1379 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DQT marker in JPEG data"); 1380 return(0); 1381 } 1382 na=sizeof(uint32)+69; 1383 nb=_TIFFmalloc(na); 1384 if (nb==0) 1385 { 1386 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1387 return(0); 1388 } 1389 *(uint32*)nb=na; 1390 nb[sizeof(uint32)]=255; 1391 nb[sizeof(uint32)+1]=JPEG_MARKER_DQT; 1392 nb[sizeof(uint32)+2]=0; 1393 nb[sizeof(uint32)+3]=67; 1394 if (OJPEGReadBlock(sp,65,&nb[sizeof(uint32)+4])==0) 1395 return(0); 1396 o=nb[sizeof(uint32)+4]&15; 1397 if (3<o) 1398 { 1399 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DQT marker in JPEG data"); 1400 return(0); 1401 } 1402 if (sp->qtable[o]!=0) 1403 _TIFFfree(sp->qtable[o]); 1404 sp->qtable[o]=nb; 1405 m-=65; 1406 } while(m>0); 1407 } 1408 return(1); 1409 } 1410 1411 static int 1412 OJPEGReadHeaderInfoSecStreamDht(TIFF* tif) 1413 { 1414 /* this is a table marker, and it is to be saved as a whole for exact pushing on the jpeg stream later on */ 1415 /* TODO: the following assumes there is only one table in this marker... but i'm not quite sure that assumption is guaranteed correct */ 1416 static const char module[]="OJPEGReadHeaderInfoSecStreamDht"; 1417 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1418 uint16 m; 1419 uint32 na; 1420 uint8* nb; 1421 uint8 o; 1422 if (OJPEGReadWord(sp,&m)==0) 1423 return(0); 1424 if (m<=2) 1425 { 1426 if (sp->subsamplingcorrect==0) 1427 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); 1428 return(0); 1429 } 1430 if (sp->subsamplingcorrect!=0) 1431 { 1432 OJPEGReadSkip(sp,m-2); 1433 } 1434 else 1435 { 1436 na=sizeof(uint32)+2+m; 1437 nb=_TIFFmalloc(na); 1438 if (nb==0) 1439 { 1440 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1441 return(0); 1442 } 1443 *(uint32*)nb=na; 1444 nb[sizeof(uint32)]=255; 1445 nb[sizeof(uint32)+1]=JPEG_MARKER_DHT; 1446 nb[sizeof(uint32)+2]=(m>>8); 1447 nb[sizeof(uint32)+3]=(m&255); 1448 if (OJPEGReadBlock(sp,m-2,&nb[sizeof(uint32)+4])==0) 1449 return(0); 1450 o=nb[sizeof(uint32)+4]; 1451 if ((o&240)==0) 1452 { 1453 if (3<o) 1454 { 1455 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); 1456 return(0); 1457 } 1458 if (sp->dctable[o]!=0) 1459 _TIFFfree(sp->dctable[o]); 1460 sp->dctable[o]=nb; 1461 } 1462 else 1463 { 1464 if ((o&240)!=16) 1465 { 1466 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); 1467 return(0); 1468 } 1469 o&=15; 1470 if (3<o) 1471 { 1472 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); 1473 return(0); 1474 } 1475 if (sp->actable[o]!=0) 1476 _TIFFfree(sp->actable[o]); 1477 sp->actable[o]=nb; 1478 } 1479 } 1480 return(1); 1481 } 1482 1483 static int 1484 OJPEGReadHeaderInfoSecStreamSof(TIFF* tif, uint8 marker_id) 1485 { 1486 /* this marker needs to be checked, and part of its data needs to be saved for regeneration later on */ 1487 static const char module[]="OJPEGReadHeaderInfoSecStreamSof"; 1488 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1489 uint16 m; 1490 uint16 n; 1491 uint8 o; 1492 uint16 p; 1493 uint16 q; 1494 if (sp->sof_log!=0) 1495 { 1496 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JPEG data"); 1497 return(0); 1498 } 1499 if (sp->subsamplingcorrect==0) 1500 sp->sof_marker_id=marker_id; 1501 /* Lf: data length */ 1502 if (OJPEGReadWord(sp,&m)==0) 1503 return(0); 1504 if (m<11) 1505 { 1506 if (sp->subsamplingcorrect==0) 1507 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOF marker in JPEG data"); 1508 return(0); 1509 } 1510 m-=8; 1511 if (m%3!=0) 1512 { 1513 if (sp->subsamplingcorrect==0) 1514 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOF marker in JPEG data"); 1515 return(0); 1516 } 1517 n=m/3; 1518 if (sp->subsamplingcorrect==0) 1519 { 1520 if (n!=sp->samples_per_pixel) 1521 { 1522 TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected number of samples"); 1523 return(0); 1524 } 1525 } 1526 /* P: Sample precision */ 1527 if (OJPEGReadByte(sp,&o)==0) 1528 return(0); 1529 if (o!=8) 1530 { 1531 if (sp->subsamplingcorrect==0) 1532 TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected number of bits per sample"); 1533 return(0); 1534 } 1535 /* Y: Number of lines, X: Number of samples per line */ 1536 if (sp->subsamplingcorrect) 1537 OJPEGReadSkip(sp,4); 1538 else 1539 { 1540 /* TODO: probably best to also add check on allowed upper bound, especially x, may cause buffer overflow otherwise i think */ 1541 /* Y: Number of lines */ 1542 if (OJPEGReadWord(sp,&p)==0) 1543 return(0); 1544 if ((p<sp->image_length) && (p<sp->strile_length_total)) 1545 { 1546 TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected height"); 1547 return(0); 1548 } 1549 sp->sof_y=p; 1550 /* X: Number of samples per line */ 1551 if (OJPEGReadWord(sp,&p)==0) 1552 return(0); 1553 if ((p<sp->image_width) && (p<sp->strile_width)) 1554 { 1555 TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected width"); 1556 return(0); 1557 } 1558 sp->sof_x=p; 1559 } 1560 /* Nf: Number of image components in frame */ 1561 if (OJPEGReadByte(sp,&o)==0) 1562 return(0); 1563 if (o!=n) 1564 { 1565 if (sp->subsamplingcorrect==0) 1566 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOF marker in JPEG data"); 1567 return(0); 1568 } 1569 /* per component stuff */ 1570 /* TODO: double-check that flow implies that n cannot be as big as to make us overflow sof_c, sof_hv and sof_tq arrays */ 1571 for (q=0; q<n; q++) 1572 { 1573 /* C: Component identifier */ 1574 if (OJPEGReadByte(sp,&o)==0) 1575 return(0); 1576 if (sp->subsamplingcorrect==0) 1577 sp->sof_c[q]=o; 1578 /* H: Horizontal sampling factor, and V: Vertical sampling factor */ 1579 if (OJPEGReadByte(sp,&o)==0) 1580 return(0); 1581 if (sp->subsamplingcorrect!=0) 1582 { 1583 if (q==0) 1584 { 1585 sp->subsampling_hor=(o>>4); 1586 sp->subsampling_ver=(o&15); 1587 if (((sp->subsampling_hor!=1) && (sp->subsampling_hor!=2) && (sp->subsampling_hor!=4)) || 1588 ((sp->subsampling_ver!=1) && (sp->subsampling_ver!=2) && (sp->subsampling_ver!=4))) 1589 sp->subsampling_force_desubsampling_inside_decompression=1; 1590 } 1591 else 1592 { 1593 if (o!=17) 1594 sp->subsampling_force_desubsampling_inside_decompression=1; 1595 } 1596 } 1597 else 1598 { 1599 sp->sof_hv[q]=o; 1600 if (sp->subsampling_force_desubsampling_inside_decompression==0) 1601 { 1602 if (q==0) 1603 { 1604 if (o!=((sp->subsampling_hor<<4)|sp->subsampling_ver)) 1605 { 1606 TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected subsampling values"); 1607 return(0); 1608 } 1609 } 1610 else 1611 { 1612 if (o!=17) 1613 { 1614 TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected subsampling values"); 1615 return(0); 1616 } 1617 } 1618 } 1619 } 1620 /* Tq: Quantization table destination selector */ 1621 if (OJPEGReadByte(sp,&o)==0) 1622 return(0); 1623 if (sp->subsamplingcorrect==0) 1624 sp->sof_tq[q]=o; 1625 } 1626 if (sp->subsamplingcorrect==0) 1627 sp->sof_log=1; 1628 return(1); 1629 } 1630 1631 static int 1632 OJPEGReadHeaderInfoSecStreamSos(TIFF* tif) 1633 { 1634 /* this marker needs to be checked, and part of its data needs to be saved for regeneration later on */ 1635 static const char module[]="OJPEGReadHeaderInfoSecStreamSos"; 1636 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1637 uint16 m; 1638 uint8 n; 1639 uint8 o; 1640 assert(sp->subsamplingcorrect==0); 1641 if (sp->sof_log==0) 1642 { 1643 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOS marker in JPEG data"); 1644 return(0); 1645 } 1646 /* Ls */ 1647 if (OJPEGReadWord(sp,&m)==0) 1648 return(0); 1649 if (m!=6+sp->samples_per_pixel_per_plane*2) 1650 { 1651 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOS marker in JPEG data"); 1652 return(0); 1653 } 1654 /* Ns */ 1655 if (OJPEGReadByte(sp,&n)==0) 1656 return(0); 1657 if (n!=sp->samples_per_pixel_per_plane) 1658 { 1659 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOS marker in JPEG data"); 1660 return(0); 1661 } 1662 /* Cs, Td, and Ta */ 1663 for (o=0; o<sp->samples_per_pixel_per_plane; o++) 1664 { 1665 /* Cs */ 1666 if (OJPEGReadByte(sp,&n)==0) 1667 return(0); 1668 sp->sos_cs[sp->plane_sample_offset+o]=n; 1669 /* Td and Ta */ 1670 if (OJPEGReadByte(sp,&n)==0) 1671 return(0); 1672 sp->sos_tda[sp->plane_sample_offset+o]=n; 1673 } 1674 /* skip Ss, Se, Ah, en Al -> no check, as per Tom Lane recommendation, as per LibJpeg source */ 1675 OJPEGReadSkip(sp,3); 1676 return(1); 1677 } 1678 1679 static int 1680 OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif) 1681 { 1682 static const char module[]="OJPEGReadHeaderInfoSecTablesQTable"; 1683 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1684 uint8 m; 1685 uint8 n; 1686 uint32 oa; 1687 uint8* ob; 1688 uint32 p; 1689 if (sp->qtable_offset[0]==0) 1690 { 1691 TIFFErrorExt(tif->tif_clientdata,module,"Missing JPEG tables"); 1692 return(0); 1693 } 1694 sp->in_buffer_file_pos_log=0; 1695 for (m=0; m<sp->samples_per_pixel; m++) 1696 { 1697 if ((sp->qtable_offset[m]!=0) && ((m==0) || (sp->qtable_offset[m]!=sp->qtable_offset[m-1]))) 1698 { 1699 for (n=0; n<m-1; n++) 1700 { 1701 if (sp->qtable_offset[m]==sp->qtable_offset[n]) 1702 { 1703 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JpegQTables tag value"); 1704 return(0); 1705 } 1706 } 1707 oa=sizeof(uint32)+69; 1708 ob=_TIFFmalloc(oa); 1709 if (ob==0) 1710 { 1711 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1712 return(0); 1713 } 1714 *(uint32*)ob=oa; 1715 ob[sizeof(uint32)]=255; 1716 ob[sizeof(uint32)+1]=JPEG_MARKER_DQT; 1717 ob[sizeof(uint32)+2]=0; 1718 ob[sizeof(uint32)+3]=67; 1719 ob[sizeof(uint32)+4]=m; 1720 TIFFSeekFile(tif,sp->qtable_offset[m],SEEK_SET); 1721 p=TIFFReadFile(tif,&ob[sizeof(uint32)+5],64); 1722 if (p!=64) 1723 return(0); 1724 sp->qtable[m]=ob; 1725 sp->sof_tq[m]=m; 1726 } 1727 else 1728 sp->sof_tq[m]=sp->sof_tq[m-1]; 1729 } 1730 return(1); 1731 } 1732 1733 static int 1734 OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif) 1735 { 1736 static const char module[]="OJPEGReadHeaderInfoSecTablesDcTable"; 1737 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1738 uint8 m; 1739 uint8 n; 1740 uint8 o[16]; 1741 uint32 p; 1742 uint32 q; 1743 uint32 ra; 1744 uint8* rb; 1745 if (sp->dctable_offset[0]==0) 1746 { 1747 TIFFErrorExt(tif->tif_clientdata,module,"Missing JPEG tables"); 1748 return(0); 1749 } 1750 sp->in_buffer_file_pos_log=0; 1751 for (m=0; m<sp->samples_per_pixel; m++) 1752 { 1753 if ((sp->dctable_offset[m]!=0) && ((m==0) || (sp->dctable_offset[m]!=sp->dctable_offset[m-1]))) 1754 { 1755 for (n=0; n<m-1; n++) 1756 { 1757 if (sp->dctable_offset[m]==sp->dctable_offset[n]) 1758 { 1759 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JpegDcTables tag value"); 1760 return(0); 1761 } 1762 } 1763 TIFFSeekFile(tif,sp->dctable_offset[m],SEEK_SET); 1764 p=TIFFReadFile(tif,o,16); 1765 if (p!=16) 1766 return(0); 1767 q=0; 1768 for (n=0; n<16; n++) 1769 q+=o[n]; 1770 ra=sizeof(uint32)+21+q; 1771 rb=_TIFFmalloc(ra); 1772 if (rb==0) 1773 { 1774 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1775 return(0); 1776 } 1777 *(uint32*)rb=ra; 1778 rb[sizeof(uint32)]=255; 1779 rb[sizeof(uint32)+1]=JPEG_MARKER_DHT; 1780 rb[sizeof(uint32)+2]=((19+q)>>8); 1781 rb[sizeof(uint32)+3]=((19+q)&255); 1782 rb[sizeof(uint32)+4]=m; 1783 for (n=0; n<16; n++) 1784 rb[sizeof(uint32)+5+n]=o[n]; 1785 p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); 1786 if (p!=q) 1787 return(0); 1788 sp->dctable[m]=rb; 1789 sp->sos_tda[m]=(m<<4); 1790 } 1791 else 1792 sp->sos_tda[m]=sp->sos_tda[m-1]; 1793 } 1794 return(1); 1795 } 1796 1797 static int 1798 OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif) 1799 { 1800 static const char module[]="OJPEGReadHeaderInfoSecTablesAcTable"; 1801 OJPEGState* sp=(OJPEGState*)tif->tif_data; 1802 uint8 m; 1803 uint8 n; 1804 uint8 o[16]; 1805 uint32 p; 1806 uint32 q; 1807 uint32 ra; 1808 uint8* rb; 1809 if (sp->actable_offset[0]==0) 1810 { 1811 TIFFErrorExt(tif->tif_clientdata,module,"Missing JPEG tables"); 1812 return(0); 1813 } 1814 sp->in_buffer_file_pos_log=0; 1815 for (m=0; m<sp->samples_per_pixel; m++) 1816 { 1817 if ((sp->actable_offset[m]!=0) && ((m==0) || (sp->actable_offset[m]!=sp->actable_offset[m-1]))) 1818 { 1819 for (n=0; n<m-1; n++) 1820 { 1821 if (sp->actable_offset[m]==sp->actable_offset[n]) 1822 { 1823 TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JpegAcTables tag value"); 1824 return(0); 1825 } 1826 } 1827 TIFFSeekFile(tif,sp->actable_offset[m],SEEK_SET); 1828 p=TIFFReadFile(tif,o,16); 1829 if (p!=16) 1830 return(0); 1831 q=0; 1832 for (n=0; n<16; n++) 1833 q+=o[n]; 1834 ra=sizeof(uint32)+21+q; 1835 rb=_TIFFmalloc(ra); 1836 if (rb==0) 1837 { 1838 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); 1839 return(0); 1840 } 1841 *(uint32*)rb=ra; 1842 rb[sizeof(uint32)]=255; 1843 rb[sizeof(uint32)+1]=JPEG_MARKER_DHT; 1844 rb[sizeof(uint32)+2]=((19+q)>>8); 1845 rb[sizeof(uint32)+3]=((19+q)&255); 1846 rb[sizeof(uint32)+4]=(16|m); 1847 for (n=0; n<16; n++) 1848 rb[sizeof(uint32)+5+n]=o[n]; 1849 p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); 1850 if (p!=q) 1851 return(0); 1852 sp->actable[m]=rb; 1853 sp->sos_tda[m]=(sp->sos_tda[m]|m); 1854 } 1855 else 1856 sp->sos_tda[m]=(sp->sos_tda[m]|(sp->sos_tda[m-1]&15)); 1857 } 1858 return(1); 1859 } 1860 1861 static int 1862 OJPEGReadBufferFill(OJPEGState* sp) 1863 { 1864 uint16 m; 1865 tsize_t n; 1866 /* TODO: double-check: when subsamplingcorrect is set, no call to TIFFErrorExt or TIFFWarningExt should be made 1867 * in any other case, seek or read errors should be passed through */ 1868 do 1869 { 1870 if (sp->in_buffer_file_togo!=0) 1871 { 1872 if (sp->in_buffer_file_pos_log==0) 1873 { 1874 TIFFSeekFile(sp->tif,sp->in_buffer_file_pos,SEEK_SET); 1875 sp->in_buffer_file_pos_log=1; 1876 } 1877 m=OJPEG_BUFFER; 1878 if (m>sp->in_buffer_file_togo) 1879 m=(uint16)sp->in_buffer_file_togo; 1880 n=TIFFReadFile(sp->tif,sp->in_buffer,(tsize_t)m); 1881 if (n==0) 1882 return(0); 1883 assert(n>0); 1884 assert(n<=OJPEG_BUFFER); 1885 assert(n<65536); 1886 assert((uint16)n<=sp->in_buffer_file_togo); 1887 m=(uint16)n; 1888 sp->in_buffer_togo=m; 1889 sp->in_buffer_cur=sp->in_buffer; 1890 sp->in_buffer_file_togo-=m; 1891 sp->in_buffer_file_pos+=m; 1892 break; 1893 } 1894 sp->in_buffer_file_pos_log=0; 1895 switch(sp->in_buffer_source) 1896 { 1897 case osibsNotSetYet: 1898 if (sp->jpeg_interchange_format!=0) 1899 { 1900 sp->in_buffer_file_pos=sp->jpeg_interchange_format; 1901 sp->in_buffer_file_togo=sp->jpeg_interchange_format_length; 1902 } 1903 sp->in_buffer_source=osibsJpegInterchangeFormat; 1904 break; 1905 case osibsJpegInterchangeFormat: 1906 sp->in_buffer_source=osibsStrile; 1907 case osibsStrile: 1908 if (sp->in_buffer_next_strile==sp->in_buffer_strile_count) 1909 sp->in_buffer_source=osibsEof; 1910 else 1911 { 1912 sp->in_buffer_file_pos=sp->tif->tif_dir.td_stripoffset[sp->in_buffer_next_strile]; 1913 if (sp->in_buffer_file_pos!=0) 1914 { 1915 if (sp->in_buffer_file_pos>=sp->file_size) 1916 sp->in_buffer_file_pos=0; 1917 else 1918 { 1919 sp->in_buffer_file_togo=sp->tif->tif_dir.td_stripbytecount[sp->in_buffer_next_strile]; 1920 if (sp->in_buffer_file_togo==0) 1921 sp->in_buffer_file_pos=0; 1922 else if (sp->in_buffer_file_pos+sp->in_buffer_file_togo>sp->file_size) 1923 sp->in_buffer_file_togo=sp->file_size-sp->in_buffer_file_pos; 1924 } 1925 } 1926 sp->in_buffer_next_strile++; 1927 } 1928 break; 1929 default: 1930 return(0); 1931 } 1932 } while (1); 1933 return(1); 1934 } 1935 1936 static int 1937 OJPEGReadByte(OJPEGState* sp, uint8* byte) 1938 { 1939 if (sp->in_buffer_togo==0) 1940 { 1941 if (OJPEGReadBufferFill(sp)==0) 1942 return(0); 1943 assert(sp->in_buffer_togo>0); 1944 } 1945 *byte=*(sp->in_buffer_cur); 1946 sp->in_buffer_cur++; 1947 sp->in_buffer_togo--; 1948 return(1); 1949 } 1950 1951 static int 1952 OJPEGReadBytePeek(OJPEGState* sp, uint8* byte) 1953 { 1954 if (sp->in_buffer_togo==0) 1955 { 1956 if (OJPEGReadBufferFill(sp)==0) 1957 return(0); 1958 assert(sp->in_buffer_togo>0); 1959 } 1960 *byte=*(sp->in_buffer_cur); 1961 return(1); 1962 } 1963 1964 static void 1965 OJPEGReadByteAdvance(OJPEGState* sp) 1966 { 1967 assert(sp->in_buffer_togo>0); 1968 sp->in_buffer_cur++; 1969 sp->in_buffer_togo--; 1970 } 1971 1972 static int 1973 OJPEGReadWord(OJPEGState* sp, uint16* word) 1974 { 1975 uint8 m; 1976 if (OJPEGReadByte(sp,&m)==0) 1977 return(0); 1978 *word=(m<<8); 1979 if (OJPEGReadByte(sp,&m)==0) 1980 return(0); 1981 *word|=m; 1982 return(1); 1983 } 1984 1985 static int 1986 OJPEGReadBlock(OJPEGState* sp, uint16 len, void* mem) 1987 { 1988 uint16 mlen; 1989 uint8* mmem; 1990 uint16 n; 1991 assert(len>0); 1992 mlen=len; 1993 mmem=mem; 1994 do 1995 { 1996 if (sp->in_buffer_togo==0) 1997 { 1998 if (OJPEGReadBufferFill(sp)==0) 1999 return(0); 2000 assert(sp->in_buffer_togo>0); 2001 } 2002 n=mlen; 2003 if (n>sp->in_buffer_togo) 2004 n=sp->in_buffer_togo; 2005 _TIFFmemcpy(mmem,sp->in_buffer_cur,n); 2006 sp->in_buffer_cur+=n; 2007 sp->in_buffer_togo-=n; 2008 mlen-=n; 2009 mmem+=n; 2010 } while(mlen>0); 2011 return(1); 2012 } 2013 2014 static void 2015 OJPEGReadSkip(OJPEGState* sp, uint16 len) 2016 { 2017 uint16 m; 2018 uint16 n; 2019 m=len; 2020 n=m; 2021 if (n>sp->in_buffer_togo) 2022 n=sp->in_buffer_togo; 2023 sp->in_buffer_cur+=n; 2024 sp->in_buffer_togo-=n; 2025 m-=n; 2026 if (m>0) 2027 { 2028 assert(sp->in_buffer_togo==0); 2029 n=m; 2030 if (n>sp->in_buffer_file_togo) 2031 n=sp->in_buffer_file_togo; 2032 sp->in_buffer_file_pos+=n; 2033 sp->in_buffer_file_togo-=n; 2034 sp->in_buffer_file_pos_log=0; 2035 /* we don't skip past jpeginterchangeformat/strile block... 2036 * if that is asked from us, we're dealing with totally bazurk 2037 * data anyway, and we've not seen this happening on any 2038 * testfile, so we might as well likely cause some other 2039 * meaningless error to be passed at some later time 2040 */ 2041 } 2042 } 2043 2044 static int 2045 OJPEGWriteStream(TIFF* tif, void** mem, uint32* len) 2046 { 2047 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2048 *len=0; 2049 do 2050 { 2051 assert(sp->out_state<=ososEoi); 2052 switch(sp->out_state) 2053 { 2054 case ososSoi: 2055 OJPEGWriteStreamSoi(tif,mem,len); 2056 break; 2057 case ososQTable0: 2058 OJPEGWriteStreamQTable(tif,0,mem,len); 2059 break; 2060 case ososQTable1: 2061 OJPEGWriteStreamQTable(tif,1,mem,len); 2062 break; 2063 case ososQTable2: 2064 OJPEGWriteStreamQTable(tif,2,mem,len); 2065 break; 2066 case ososQTable3: 2067 OJPEGWriteStreamQTable(tif,3,mem,len); 2068 break; 2069 case ososDcTable0: 2070 OJPEGWriteStreamDcTable(tif,0,mem,len); 2071 break; 2072 case ososDcTable1: 2073 OJPEGWriteStreamDcTable(tif,1,mem,len); 2074 break; 2075 case ososDcTable2: 2076 OJPEGWriteStreamDcTable(tif,2,mem,len); 2077 break; 2078 case ososDcTable3: 2079 OJPEGWriteStreamDcTable(tif,3,mem,len); 2080 break; 2081 case ososAcTable0: 2082 OJPEGWriteStreamAcTable(tif,0,mem,len); 2083 break; 2084 case ososAcTable1: 2085 OJPEGWriteStreamAcTable(tif,1,mem,len); 2086 break; 2087 case ososAcTable2: 2088 OJPEGWriteStreamAcTable(tif,2,mem,len); 2089 break; 2090 case ososAcTable3: 2091 OJPEGWriteStreamAcTable(tif,3,mem,len); 2092 break; 2093 case ososDri: 2094 OJPEGWriteStreamDri(tif,mem,len); 2095 break; 2096 case ososSof: 2097 OJPEGWriteStreamSof(tif,mem,len); 2098 break; 2099 case ososSos: 2100 OJPEGWriteStreamSos(tif,mem,len); 2101 break; 2102 case ososCompressed: 2103 if (OJPEGWriteStreamCompressed(tif,mem,len)==0) 2104 return(0); 2105 break; 2106 case ososRst: 2107 OJPEGWriteStreamRst(tif,mem,len); 2108 break; 2109 case ososEoi: 2110 OJPEGWriteStreamEoi(tif,mem,len); 2111 break; 2112 } 2113 } while (*len==0); 2114 return(1); 2115 } 2116 2117 static void 2118 OJPEGWriteStreamSoi(TIFF* tif, void** mem, uint32* len) 2119 { 2120 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2121 assert(OJPEG_BUFFER>=2); 2122 sp->out_buffer[0]=255; 2123 sp->out_buffer[1]=JPEG_MARKER_SOI; 2124 *len=2; 2125 *mem=(void*)sp->out_buffer; 2126 sp->out_state++; 2127 } 2128 2129 static void 2130 OJPEGWriteStreamQTable(TIFF* tif, uint8 table_index, void** mem, uint32* len) 2131 { 2132 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2133 if (sp->qtable[table_index]!=0) 2134 { 2135 *mem=(void*)(sp->qtable[table_index]+sizeof(uint32)); 2136 *len=*((uint32*)sp->qtable[table_index])-sizeof(uint32); 2137 } 2138 sp->out_state++; 2139 } 2140 2141 static void 2142 OJPEGWriteStreamDcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len) 2143 { 2144 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2145 if (sp->dctable[table_index]!=0) 2146 { 2147 *mem=(void*)(sp->dctable[table_index]+sizeof(uint32)); 2148 *len=*((uint32*)sp->dctable[table_index])-sizeof(uint32); 2149 } 2150 sp->out_state++; 2151 } 2152 2153 static void 2154 OJPEGWriteStreamAcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len) 2155 { 2156 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2157 if (sp->actable[table_index]!=0) 2158 { 2159 *mem=(void*)(sp->actable[table_index]+sizeof(uint32)); 2160 *len=*((uint32*)sp->actable[table_index])-sizeof(uint32); 2161 } 2162 sp->out_state++; 2163 } 2164 2165 static void 2166 OJPEGWriteStreamDri(TIFF* tif, void** mem, uint32* len) 2167 { 2168 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2169 assert(OJPEG_BUFFER>=6); 2170 if (sp->restart_interval!=0) 2171 { 2172 sp->out_buffer[0]=255; 2173 sp->out_buffer[1]=JPEG_MARKER_DRI; 2174 sp->out_buffer[2]=0; 2175 sp->out_buffer[3]=4; 2176 sp->out_buffer[4]=(sp->restart_interval>>8); 2177 sp->out_buffer[5]=(sp->restart_interval&255); 2178 *len=6; 2179 *mem=(void*)sp->out_buffer; 2180 } 2181 sp->out_state++; 2182 } 2183 2184 static void 2185 OJPEGWriteStreamSof(TIFF* tif, void** mem, uint32* len) 2186 { 2187 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2188 uint8 m; 2189 assert(OJPEG_BUFFER>=2+8+sp->samples_per_pixel_per_plane*3); 2190 assert(255>=8+sp->samples_per_pixel_per_plane*3); 2191 sp->out_buffer[0]=255; 2192 sp->out_buffer[1]=sp->sof_marker_id; 2193 /* Lf */ 2194 sp->out_buffer[2]=0; 2195 sp->out_buffer[3]=8+sp->samples_per_pixel_per_plane*3; 2196 /* P */ 2197 sp->out_buffer[4]=8; 2198 /* Y */ 2199 sp->out_buffer[5]=(sp->sof_y>>8); 2200 sp->out_buffer[6]=(sp->sof_y&255); 2201 /* X */ 2202 sp->out_buffer[7]=(sp->sof_x>>8); 2203 sp->out_buffer[8]=(sp->sof_x&255); 2204 /* Nf */ 2205 sp->out_buffer[9]=sp->samples_per_pixel_per_plane; 2206 for (m=0; m<sp->samples_per_pixel_per_plane; m++) 2207 { 2208 /* C */ 2209 sp->out_buffer[10+m*3]=sp->sof_c[sp->plane_sample_offset+m]; 2210 /* H and V */ 2211 sp->out_buffer[10+m*3+1]=sp->sof_hv[sp->plane_sample_offset+m]; 2212 /* Tq */ 2213 sp->out_buffer[10+m*3+2]=sp->sof_tq[sp->plane_sample_offset+m]; 2214 } 2215 *len=10+sp->samples_per_pixel_per_plane*3; 2216 *mem=(void*)sp->out_buffer; 2217 sp->out_state++; 2218 } 2219 2220 static void 2221 OJPEGWriteStreamSos(TIFF* tif, void** mem, uint32* len) 2222 { 2223 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2224 uint8 m; 2225 assert(OJPEG_BUFFER>=2+6+sp->samples_per_pixel_per_plane*2); 2226 assert(255>=6+sp->samples_per_pixel_per_plane*2); 2227 sp->out_buffer[0]=255; 2228 sp->out_buffer[1]=JPEG_MARKER_SOS; 2229 /* Ls */ 2230 sp->out_buffer[2]=0; 2231 sp->out_buffer[3]=6+sp->samples_per_pixel_per_plane*2; 2232 /* Ns */ 2233 sp->out_buffer[4]=sp->samples_per_pixel_per_plane; 2234 for (m=0; m<sp->samples_per_pixel_per_plane; m++) 2235 { 2236 /* Cs */ 2237 sp->out_buffer[5+m*2]=sp->sos_cs[sp->plane_sample_offset+m]; 2238 /* Td and Ta */ 2239 sp->out_buffer[5+m*2+1]=sp->sos_tda[sp->plane_sample_offset+m]; 2240 } 2241 /* Ss */ 2242 sp->out_buffer[5+sp->samples_per_pixel_per_plane*2]=0; 2243 /* Se */ 2244 sp->out_buffer[5+sp->samples_per_pixel_per_plane*2+1]=63; 2245 /* Ah and Al */ 2246 sp->out_buffer[5+sp->samples_per_pixel_per_plane*2+2]=0; 2247 *len=8+sp->samples_per_pixel_per_plane*2; 2248 *mem=(void*)sp->out_buffer; 2249 sp->out_state++; 2250 } 2251 2252 static int 2253 OJPEGWriteStreamCompressed(TIFF* tif, void** mem, uint32* len) 2254 { 2255 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2256 if (sp->in_buffer_togo==0) 2257 { 2258 if (OJPEGReadBufferFill(sp)==0) 2259 return(0); 2260 assert(sp->in_buffer_togo>0); 2261 } 2262 *len=sp->in_buffer_togo; 2263 *mem=(void*)sp->in_buffer_cur; 2264 sp->in_buffer_togo=0; 2265 if (sp->in_buffer_file_togo==0) 2266 { 2267 switch(sp->in_buffer_source) 2268 { 2269 case osibsStrile: 2270 if (sp->in_buffer_next_strile<sp->in_buffer_strile_count) 2271 sp->out_state=ososRst; 2272 else 2273 sp->out_state=ososEoi; 2274 break; 2275 case osibsEof: 2276 sp->out_state=ososEoi; 2277 break; 2278 default: 2279 break; 2280 } 2281 } 2282 return(1); 2283 } 2284 2285 static void 2286 OJPEGWriteStreamRst(TIFF* tif, void** mem, uint32* len) 2287 { 2288 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2289 assert(OJPEG_BUFFER>=2); 2290 sp->out_buffer[0]=255; 2291 sp->out_buffer[1]=JPEG_MARKER_RST0+sp->restart_index; 2292 sp->restart_index++; 2293 if (sp->restart_index==8) 2294 sp->restart_index=0; 2295 *len=2; 2296 *mem=(void*)sp->out_buffer; 2297 sp->out_state=ososCompressed; 2298 } 2299 2300 static void 2301 OJPEGWriteStreamEoi(TIFF* tif, void** mem, uint32* len) 2302 { 2303 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2304 assert(OJPEG_BUFFER>=2); 2305 sp->out_buffer[0]=255; 2306 sp->out_buffer[1]=JPEG_MARKER_EOI; 2307 *len=2; 2308 *mem=(void*)sp->out_buffer; 2309 } 2310 2311 #ifndef LIBJPEG_ENCAP_EXTERNAL 2312 static int 2313 jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo) 2314 { 2315 return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_create_decompress(cinfo),1)); 2316 } 2317 #endif 2318 2319 #ifndef LIBJPEG_ENCAP_EXTERNAL 2320 static int 2321 jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image) 2322 { 2323 return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_header(cinfo,require_image),1)); 2324 } 2325 #endif 2326 2327 #ifndef LIBJPEG_ENCAP_EXTERNAL 2328 static int 2329 jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo) 2330 { 2331 return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_start_decompress(cinfo),1)); 2332 } 2333 #endif 2334 2335 #ifndef LIBJPEG_ENCAP_EXTERNAL 2336 static int 2337 jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines) 2338 { 2339 return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_scanlines(cinfo,scanlines,max_lines),1)); 2340 } 2341 #endif 2342 2343 #ifndef LIBJPEG_ENCAP_EXTERNAL 2344 static int 2345 jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines) 2346 { 2347 return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_raw_data(cinfo,data,max_lines),1)); 2348 } 2349 #endif 2350 2351 #ifndef LIBJPEG_ENCAP_EXTERNAL 2352 static void 2353 jpeg_encap_unwind(TIFF* tif) 2354 { 2355 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2356 LONGJMP(sp->exit_jmpbuf,1); 2357 } 2358 #endif 2359 2360 static void 2361 OJPEGLibjpegJpegErrorMgrOutputMessage(jpeg_common_struct* cinfo) 2362 { 2363 char buffer[JMSG_LENGTH_MAX]; 2364 (*cinfo->err->format_message)(cinfo,buffer); 2365 TIFFWarningExt(((TIFF*)(cinfo->client_data))->tif_clientdata,"LibJpeg", "%s", buffer); 2366 } 2367 2368 static void 2369 OJPEGLibjpegJpegErrorMgrErrorExit(jpeg_common_struct* cinfo) 2370 { 2371 char buffer[JMSG_LENGTH_MAX]; 2372 (*cinfo->err->format_message)(cinfo,buffer); 2373 TIFFErrorExt(((TIFF*)(cinfo->client_data))->tif_clientdata,"LibJpeg", "%s", buffer); 2374 jpeg_encap_unwind((TIFF*)(cinfo->client_data)); 2375 } 2376 2377 static void 2378 OJPEGLibjpegJpegSourceMgrInitSource(jpeg_decompress_struct* cinfo) 2379 { 2380 (void)cinfo; 2381 } 381 2382 382 2383 static boolean 383 std_empty_output_buffer(register j_compress_ptr cinfo) 384 { 385 # define sp ((OJPEGState *)cinfo) 386 register TIFF *tif = sp->tif; 387 388 tif->tif_rawcc = tif->tif_rawdatasize; /* Entire buffer has been filled */ 389 TIFFFlushData1(tif); 390 sp->dest.next_output_byte = (JOCTET *)tif->tif_rawdata; 391 sp->dest.free_in_buffer = (size_t)tif->tif_rawdatasize; 392 return TRUE; 393 # undef sp 394 } 2384 OJPEGLibjpegJpegSourceMgrFillInputBuffer(jpeg_decompress_struct* cinfo) 2385 { 2386 TIFF* tif=(TIFF*)cinfo->client_data; 2387 OJPEGState* sp=(OJPEGState*)tif->tif_data; 2388 void* mem=0; 2389 uint32 len=0; 2390 if (OJPEGWriteStream(tif,&mem,&len)==0) 2391 { 2392 TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Premature end of JPEG data"); 2393 jpeg_encap_unwind(tif); 2394 } 2395 sp->libjpeg_jpeg_source_mgr.bytes_in_buffer=len; 2396 sp->libjpeg_jpeg_source_mgr.next_input_byte=mem; 2397 return(1); 2398 } 395 2399 396 2400 static void 397 std_term_destination(register j_compress_ptr cinfo) 398 { 399 # define sp ((OJPEGState *)cinfo) 400 register TIFF *tif = sp->tif; 401 402 /* NB: The TIFF Library does the final buffer flush. */ 403 tif->tif_rawcp = (tidata_t)sp->dest.next_output_byte; 404 tif->tif_rawcc = tif->tif_rawdatasize - (tsize_t)sp->dest.free_in_buffer; 405 # undef sp 406 } 407 408 /* Alternate destination manager to output JPEGTables field: */ 2401 OJPEGLibjpegJpegSourceMgrSkipInputData(jpeg_decompress_struct* cinfo, long num_bytes) 2402 { 2403 TIFF* tif=(TIFF*)cinfo->client_data; 2404 (void)num_bytes; 2405 TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Unexpected error"); 2406 jpeg_encap_unwind(tif); 2407 } 2408 2409 static boolean 2410 OJPEGLibjpegJpegSourceMgrResyncToRestart(jpeg_decompress_struct* cinfo, int desired) 2411 { 2412 TIFF* tif=(TIFF*)cinfo->client_data; 2413 (void)desired; 2414 TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Unexpected error"); 2415 jpeg_encap_unwind(tif); 2416 return(0); 2417 } 409 2418 410 2419 static void 411 tables_init_destination(register j_compress_ptr cinfo) 412 { 413 # define sp ((OJPEGState *)cinfo) 414 /* The "jpegtables_length" field is the allocated buffer size while building */ 415 sp->dest.next_output_byte = (JOCTET *)sp->jpegtables; 416 sp->dest.free_in_buffer = (size_t)sp->jpegtables_length; 417 # undef sp 418 } 419 420 static boolean 421 tables_empty_output_buffer(register j_compress_ptr cinfo) 422 { void *newbuf; 423 # define sp ((OJPEGState *)cinfo) 424 425 /* The entire buffer has been filled, so enlarge it by 1000 bytes. */ 426 if (!( newbuf = _TIFFrealloc( (tdata_t)sp->jpegtables 427 , (tsize_t)(sp->jpegtables_length + 1000) 428 ) 429 ) 430 ) ERREXIT1(cinfo,JERR_OUT_OF_MEMORY,100); 431 sp->dest.next_output_byte = (JOCTET *)newbuf + sp->jpegtables_length; 432 sp->dest.free_in_buffer = (size_t)1000; 433 sp->jpegtables = newbuf; 434 sp->jpegtables_length += 1000; 435 return TRUE; 436 # undef sp 437 } 438 439 static void 440 tables_term_destination(register j_compress_ptr cinfo) 441 { 442 # define sp ((OJPEGState *)cinfo) 443 /* Set tables length to no. of Bytes actually emitted. */ 444 sp->jpegtables_length -= sp->dest.free_in_buffer; 445 # undef sp 446 } 447 448 /*ARGSUSED*/ static int 449 TIFFojpeg_tables_dest(register OJPEGState *sp, TIFF *tif) 450 { 451 452 /* Allocate a working buffer for building tables. The initial size is 1000 453 Bytes, which is usually adequate. 454 */ 455 if (sp->jpegtables) _TIFFfree(sp->jpegtables); 456 if (!(sp->jpegtables = (void*) 457 _TIFFmalloc((tsize_t)(sp->jpegtables_length = 1000)) 458 ) 459 ) 460 { 461 sp->jpegtables_length = 0; 462 TIFFError("TIFFojpeg_tables_dest",no_jtable_space); 463 return 0; 464 }; 465 sp->cinfo.c.dest = &sp->dest; 466 sp->dest.init_destination = tables_init_destination; 467 sp->dest.empty_output_buffer = tables_empty_output_buffer; 468 sp->dest.term_destination = tables_term_destination; 469 return 1; 470 } 471 #else /* well, hardly ever */ 472 473 static int 474 _notSupported(register TIFF *tif) 475 { const TIFFCodec *c = TIFFFindCODEC(tif->tif_dir.td_compression); 476 477 TIFFError(tif->tif_name,"%s compression not supported",c->name); 478 return 0; 479 } 480 #endif /* never */ 481 482 /* The following subroutines comprise a JPEG Library "source" data manager by 483 by directing compressed data to the JPEG Library from a TIFF Library input 484 buffer. 485 */ 486 static void 487 std_init_source(register j_decompress_ptr cinfo) 488 { 489 # define sp ((OJPEGState *)cinfo) 490 register TIFF *tif = sp->tif; 491 492 if (sp->src.bytes_in_buffer == 0) 493 { 494 sp->src.next_input_byte = (const JOCTET *)tif->tif_rawdata; 495 sp->src.bytes_in_buffer = (size_t)tif->tif_rawcc; 496 }; 497 # undef sp 498 } 499 500 static boolean 501 std_fill_input_buffer(register j_decompress_ptr cinfo) 502 { static const JOCTET dummy_EOI[2]={0xFF,JPEG_EOI}; 503 # define sp ((OJPEGState *)cinfo) 504 505 /* Control should never get here, since an entire strip/tile is read into 506 memory before the decompressor is called; thus, data should have been 507 supplied by the "init_source" method. ...But, sometimes things fail. 508 */ 509 WARNMS(cinfo,JWRN_JPEG_EOF); 510 sp->src.next_input_byte = dummy_EOI; /* Insert a fake EOI marker */ 511 sp->src.bytes_in_buffer = sizeof dummy_EOI; 512 return TRUE; 513 # undef sp 514 } 515 516 static void 517 std_skip_input_data(register j_decompress_ptr cinfo, long num_bytes) 518 { 519 # define sp ((OJPEGState *)cinfo) 520 521 if (num_bytes > 0) 522 { 523 if (num_bytes > (long)sp->src.bytes_in_buffer) /* oops: buffer overrun */ 524 (void)std_fill_input_buffer(cinfo); 525 else 526 { 527 sp->src.next_input_byte += (size_t)num_bytes; 528 sp->src.bytes_in_buffer -= (size_t)num_bytes; 529 } 530 } 531 # undef sp 532 } 533 534 /*ARGSUSED*/ static void 535 std_term_source(register j_decompress_ptr cinfo){} /* "Dummy" stub */ 536 537 /* Allocate temporary I/O buffers for downsampled data, using values computed in 538 "jpeg_start_{de}compress()". We use the JPEG Library's allocator so that 539 buffers will be released automatically when done with a strip/tile. This is 540 also a handy place to compute samplesperclump, bytesperline, etc. 541 */ 542 static int 543 alloc_downsampled_buffers(TIFF *tif,jpeg_component_info *comp_info, 544 int num_components) 545 { register OJPEGState *sp = OJState(tif); 546 547 sp->samplesperclump = 0; 548 if (num_components > 0) 549 { tsize_t size = sp->cinfo.comm.is_decompressor 550 # ifdef D_LOSSLESS_SUPPORTED 551 ? sp->cinfo.d.min_codec_data_unit 552 # else 553 ? DCTSIZE 554 # endif 555 # ifdef C_LOSSLESS_SUPPORTED 556 : sp->cinfo.c.data_unit; 557 # else 558 : DCTSIZE; 559 # endif 560 int ci = 0; 561 register jpeg_component_info *compptr = comp_info; 562 563 do 564 { JSAMPARRAY buf; 565 566 sp->samplesperclump += 567 compptr->h_samp_factor * compptr->v_samp_factor; 568 # if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED) 569 if (!(buf = CALLJPEG(sp,0,(*sp->cinfo.comm.mem->alloc_sarray)(&sp->cinfo.comm,JPOOL_IMAGE,compptr->width_in_data_units*size,compptr->v_samp_factor*size)))) 570 # else 571 if (!(buf = CALLJPEG(sp,0,(*sp->cinfo.comm.mem->alloc_sarray)(&sp->cinfo.comm,JPOOL_IMAGE,compptr->width_in_blocks*size,compptr->v_samp_factor*size)))) 572 # endif 573 return 0; 574 sp->ds_buffer[ci] = buf; 575 } 576 while (++compptr,++ci < num_components); 577 }; 578 return 1; 579 } 580 #ifdef never 581 582 /* JPEG Encoding begins here. */ 583 584 /*ARGSUSED*/ static int 585 OJPEGEncode(register TIFF *tif,tidata_t buf,tsize_t cc,tsample_t s) 586 { tsize_t rows; /* No. of unprocessed rows in file */ 587 register OJPEGState *sp = OJState(tif); 588 589 /* Encode a chunk of pixels, where returned data is NOT down-sampled (the 590 standard case). The data is expected to be written in scan-line multiples. 591 */ 592 if (cc % sp->bytesperline) TIFFWarning(tif->tif_name,no_write_frac); 593 if ( (cc /= bytesperline) /* No. of complete rows in caller's buffer */ 594 > (rows = sp->cinfo.c.image_height - sp->cinfo.c.next_scanline) 595 ) cc = rows; 596 while (--cc >= 0) 597 { 598 if ( CALLJPEG(sp,-1,jpeg_write_scanlines(&sp->cinfo.c,(JSAMPARRAY)&buf,1)) 599 != 1 600 ) return 0; 601 ++tif->tif_row; 602 buf += sp->bytesperline; 603 }; 604 return 1; 605 } 606 607 /*ARGSUSED*/ static int 608 OJPEGEncodeRaw(register TIFF *tif,tidata_t buf,tsize_t cc,tsample_t s) 609 { tsize_t rows; /* No. of unprocessed rows in file */ 610 JDIMENSION lines_per_MCU, size; 611 register OJPEGState *sp = OJState(tif); 612 613 /* Encode a chunk of pixels, where returned data is down-sampled as per the 614 sampling factors. The data is expected to be written in scan-line 615 multiples. 616 */ 617 cc /= sp->bytesperline; 618 if (cc % sp->bytesperline) TIFFWarning(tif->tif_name,no_write_frac); 619 if ( (cc /= bytesperline) /* No. of complete rows in caller's buffer */ 620 > (rows = sp->cinfo.c.image_height - sp->cinfo.c.next_scanline) 621 ) cc = rows; 622 # ifdef C_LOSSLESS_SUPPORTED 623 lines_per_MCU = sp->cinfo.c.max_samp_factor*(size = sp->cinfo.d.data_unit); 624 # else 625 lines_per_MCU = sp->cinfo.c.max_samp_factor*(size = DCTSIZE); 626 # endif 627 while (--cc >= 0) 628 { int ci = 0, clumpoffset = 0; 629 register jpeg_component_info *compptr = sp->cinfo.c.comp_info; 630 631 /* The fastest way to separate the data is to make 1 pass over the scan 632 line for each row of each component. 633 */ 634 do 635 { int ypos = 0; 636 637 do 638 { int padding; 639 register JSAMPLE *inptr = (JSAMPLE*)buf + clumpoffset, 640 *outptr = 641 sp->ds_buffer[ci][sp->scancount*compptr->v_samp_factor+ypos]; 642 /* Cb,Cr both have sampling factors 1, so this is correct */ 643 register int clumps_per_line = 644 sp->cinfo.c.comp_info[1].downsampled_width, 645 xpos; 646 647 padding = (int) 648 # ifdef C_LOSSLESS_SUPPORTED 649 ( compptr->width_in_data_units * size 650 # else 651 ( compptr->width_in_blocks * size 652 # endif 653 - clumps_per_line * compptr->h_samp_factor 654 ); 655 if (compptr->h_samp_factor == 1) /* Cb & Cr fast path */ 656 do *outptr++ = *inptr; 657 while ((inptr += sp->samplesperclump),--clumps_per_line > 0); 658 else /* general case */ 659 do 660 { 661 xpos = 0; 662 do *outptr++ = inptr[xpos]; 663 while (++xpos < compptr->h_samp_factor); 664 } 665 while ((inptr += sp->samplesperclump),--clumps_per_line > 0); 666 xpos = 0; /* Pad each scan line as needed */ 667 do outptr[0] = outptr[-1]; while (++outptr,++xpos < padding); 668 clumpoffset += compptr->h_samp_factor; 669 } 670 while (++ypos < compptr->v_samp_factor); 671 } 672 while (++compptr,++ci < sp->cinfo.c.num_components); 673 if (++sp->scancount >= size) 674 { 675 if ( CALLJPEG(sp,-1,jpeg_write_raw_data(&sp->cinfo.c,sp->ds_buffer,lines_per_MCU)) 676 != lines_per_MCU 677 ) return 0; 678 sp->scancount = 0; 679 }; 680 ++tif->tif_row++ 681 buf += sp->bytesperline; 682 }; 683 return 1; 684 } 685 686 static int 687 OJPEGSetupEncode(register TIFF *tif) 688 { static const char module[]={"OJPEGSetupEncode"}; 689 uint32 segment_height, segment_width; 690 int status = 1; /* Assume success by default */ 691 register OJPEGState *sp = OJState(tif); 692 # define td (&tif->tif_dir) 693 694 /* Verify miscellaneous parameters. This will need work if the TIFF Library 695 ever supports different depths for different components, or if the JPEG 696 Library ever supports run-time depth selection. Neither seems imminent. 697 */ 698 if (td->td_bitspersample != 8) 699 { 700 TIFFError(module,bad_bps,td->td_bitspersample); 701 status = 0; 702 }; 703 704 /* The TIFF Version 6.0 specification and IJG JPEG Library accept different 705 sets of color spaces, so verify that our image belongs to the common subset 706 and map its photometry code, then initialize to handle subsampling and 707 optional JPEG Library YCbCr <-> RGB color-space conversion. 708 */ 709 switch (td->td_photometric) 710 { 711 case PHOTOMETRIC_YCBCR : 712 713 /* ISO IS 10918-1 requires that JPEG subsampling factors be 1-4, but 714 TIFF Version 6.0 is more restrictive: only 1, 2, and 4 are allowed. 715 */ 716 if ( ( td->td_ycbcrsubsampling[0] == 1 717 || td->td_ycbcrsubsampling[0] == 2 718 || td->td_ycbcrsubsampling[0] == 4 719 ) 720 && ( td->td_ycbcrsubsampling[1] == 1 721 || td->td_ycbcrsubsampling[1] == 2 722 || td->td_ycbcrsubsampling[1] == 4 723 ) 724 ) 725 sp->cinfo.c.raw_data_in = 726 ( (sp->h_sampling = td->td_ycbcrsubsampling[0]) << 3 727 | (sp->v_sampling = td->td_ycbcrsubsampling[1]) 728 ) != 011; 729 else 730 { 731 TIFFError(module,bad_subsampling); 732 status = 0; 733 }; 734 735 /* A ReferenceBlackWhite field MUST be present, since the default value 736 is inapproriate for YCbCr. Fill in the proper value if the 737 application didn't set it. 738 */ 739 if (!TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) 740 { float refbw[6]; 741 long top = 1L << td->td_bitspersample; 742 743 refbw[0] = 0; 744 refbw[1] = (float)(top-1L); 745 refbw[2] = (float)(top>>1); 746 refbw[3] = refbw[1]; 747 refbw[4] = refbw[2]; 748 refbw[5] = refbw[1]; 749 TIFFSetField(tif,TIFFTAG_REFERENCEBLACKWHITE,refbw); 750 }; 751 sp->cinfo.c.jpeg_color_space = JCS_YCbCr; 752 if (sp->jpegcolormode == JPEGCOLORMODE_RGB) 753 { 754 sp->cinfo.c.raw_data_in = FALSE; 755 sp->in_color_space = JCS_RGB; 756 break; 757 }; 758 goto L2; 759 case PHOTOMETRIC_MINISBLACK: 760 sp->cinfo.c.jpeg_color_space = JCS_GRAYSCALE; 761 goto L1; 762 case PHOTOMETRIC_RGB : 763 sp->cinfo.c.jpeg_color_space = JCS_RGB; 764 goto L1; 765 case PHOTOMETRIC_SEPARATED : 766 sp->cinfo.c.jpeg_color_space = JCS_CMYK; 767 L1: sp->jpegcolormode = JPEGCOLORMODE_RAW; /* No JPEG Lib. conversion */ 768 L2: sp->cinfo.d.in_color_space = sp->cinfo.d.jpeg_color-space; 769 break; 770 default : 771 TIFFError(module,bad_photometry,td->td_photometric); 772 status = 0; 773 }; 774 tif->tif_encoderow = tif->tif_encodestrip = tif->tif_encodetile = 775 sp->cinfo.c.raw_data_in ? OJPEGEncodeRaw : OJPEGEncode; 776 if (isTiled(tif)) 777 { tsize_t size; 778 779 # ifdef C_LOSSLESS_SUPPORTED 780 if ((size = sp->v_sampling*sp->cinfo.c.data_unit) < 16) size = 16; 781 # else 782 if ((size = sp->v_sampling*DCTSIZE) < 16) size = 16; 783 # endif 784 if ((segment_height = td->td_tilelength) % size) 785 { 786 TIFFError(module,"JPEG tile height must be multiple of %d",size); 787 status = 0; 788 }; 789 # ifdef C_LOSSLESS_SUPPORTED 790 if ((size = sp->h_sampling*sp->cinfo.c.data_unit) < 16) size = 16; 791 # else 792 if ((size = sp->h_sampling*DCTSIZE) < 16) size = 16; 793 # endif 794 if ((segment_width = td->td_tilewidth) % size) 795 { 796 TIFFError(module,"JPEG tile width must be multiple of %d",size); 797 status = 0; 798 }; 799 sp->bytesperline = TIFFTileRowSize(tif); 800 } 801 else 802 { tsize_t size; 803 804 # ifdef C_LOSSLESS_SUPPORTED 805 if ((size = sp->v_sampling*sp->cinfo.c.data_unit) < 16) size = 16; 806 # else 807 if ((size = sp->v_sampling*DCTSIZE) < 16) size = 16; 808 # endif 809 if (td->td_rowsperstrip < (segment_height = td->td_imagelength)) 810 { 811 if (td->td_rowsperstrip % size) 812 { 813 TIFFError(module,"JPEG RowsPerStrip must be multiple of %d",size); 814 status = 0; 815 }; 816 segment_height = td->td_rowsperstrip; 817 }; 818 segment_width = td->td_imagewidth; 819 sp->bytesperline = tif->tif_scanlinesize; 820 }; 821 if (segment_width > 65535 || segment_height > 65535) 822 { 823 TIFFError(module,"Strip/tile too large for JPEG"); 824 status = 0; 825 }; 826 827 /* Initialize all JPEG parameters to default values. Note that the JPEG 828 Library's "jpeg_set_defaults()" method needs legal values for the 829 "in_color_space" and "input_components" fields. 830 */ 831 sp->cinfo.c.input_components = 1; /* Default for JCS_UNKNOWN */ 832 if (!CALLVJPEG(sp,jpeg_set_defaults(&sp->cinfo.c))) status = 0; 833 switch (sp->jpegtablesmode & (JPEGTABLESMODE_HUFF|JPEGTABLESMODE_QUANT)) 834 { register JHUFF_TBL *htbl; 835 register JQUANT_TBL *qtbl; 836 837 case 0 : 838 sp->cinfo.c.optimize_coding = TRUE; 839 case JPEGTABLESMODE_HUFF : 840 if (!CALLVJPEG(sp,jpeg_set_quality(&sp->cinfo.c,sp->jpegquality,FALSE))) 841 return 0; 842 if (qtbl = sp->cinfo.c.quant_tbl_ptrs[0]) qtbl->sent_table = FALSE; 843 if (qtbl = sp->cinfo.c.quant_tbl_ptrs[1]) qtbl->sent_table = FALSE; 844 goto L3; 845 case JPEGTABLESMODE_QUANT : 846 sp->cinfo.c.optimize_coding = TRUE; 847 848 /* We do not support application-supplied JPEG tables, so mark the field 849 "not present". 850 */ 851 L3: TIFFClrFieldBit(tif,FIELD_JPEGTABLES); 852 break; 853 case JPEGTABLESMODE_HUFF|JPEGTABLESMODE_QUANT: 854 if ( !CALLVJPEG(sp,jpeg_set_quality(&sp->cinfo.c,sp->jpegquality,FALSE)) 855 || !CALLVJPEG(sp,jpeg_suppress_tables(&sp->cinfo.c,TRUE)) 856 ) 857 { 858 status = 0; 859 break; 860 }; 861 if (qtbl = sp->cinfo.c.quant_tbl_ptrs[0]) qtbl->sent_table = FALSE; 862 if (htbl = sp->cinfo.c.dc_huff_tbl_ptrs[0]) htbl->sent_table = FALSE; 863 if (htbl = sp->cinfo.c.ac_huff_tbl_ptrs[0]) htbl->sent_table = FALSE; 864 if (sp->cinfo.c.jpeg_color_space == JCS_YCbCr) 865 { 866 if (qtbl = sp->cinfo.c.quant_tbl_ptrs[1]) 867 qtbl->sent_table = FALSE; 868 if (htbl = sp->cinfo.c.dc_huff_tbl_ptrs[1]) 869 htbl->sent_table = FALSE; 870 if (htbl = sp->cinfo.c.ac_huff_tbl_ptrs[1]) 871 htbl->sent_table = FALSE; 872 }; 873 if ( TIFFojpeg_tables_dest(sp,tif) 874 && CALLVJPEG(sp,jpeg_write_tables(&sp->cinfo.c)) 875 ) 876 { 877 878 /* Mark the field "present". We can't use "TIFFSetField()" because 879 "BEENWRITING" is already set! 880 */ 881 TIFFSetFieldBit(tif,FIELD_JPEGTABLES); 882 tif->tif_flags |= TIFF_DIRTYDIRECT; 883 } 884 else status = 0; 885 }; 886 if ( sp->cinfo.c.raw_data_in 887 && !alloc_downsampled_buffers(tif,sp->cinfo.c.comp_info, 888 sp->cinfo.c.num_components) 889 ) status = 0; 890 if (status == 0) return 0; /* If TIFF errors, don't bother to continue */ 891 /* Grab parameters that are same for all strips/tiles. */ 892 893 sp->dest.init_destination = std_init_destination; 894 sp->dest.empty_output_buffer = std_empty_output_buffer; 895 sp->dest.term_destination = std_term_destination; 896 sp->cinfo.c.dest = &sp->dest; 897 sp->cinfo.c.data_precision = td->td_bitspersample; 898 sp->cinfo.c.write_JFIF_header = /* Don't write extraneous markers */ 899 sp->cinfo.c.write_Adobe_marker = FALSE; 900 sp->cinfo.c.image_width = segment_width; 901 sp->cinfo.c.image_height = segment_height; 902 sp->cinfo.c.comp_info[0].h_samp_factor = 903 sp->cinfo.c.comp_info[0].v_samp_factor = 1; 904 return CALLVJPEG(sp,jpeg_start_compress(&sp->cinfo.c,FALSE)); 905 # undef td 906 } 907 908 static int 909 OJPEGPreEncode(register TIFF *tif,tsample_t s) 910 { register OJPEGState *sp = OJState(tif); 911 # define td (&tif->tif_dir) 912 913 /* If we are about to write the first row of an image plane, which should 914 coincide with a JPEG "scan", reset the JPEG Library's compressor. Otherwise 915 let the compressor run "as is" and return a "success" status without further 916 ado. 917 */ 918 if ( (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip) 919 % td->td_stripsperimage 920 == 0 921 ) 922 { 923 if ( (sp->cinfo.c.comp_info[0].component_id = s) == 1) 924 && sp->cinfo.c.jpeg_color_space == JCS_YCbCr 925 ) 926 { 927 sp->cinfo.c.comp_info[0].quant_tbl_no = 928 sp->cinfo.c.comp_info[0].dc_tbl_no = 929 sp->cinfo.c.comp_info[0].ac_tbl_no = 1; 930 sp->cinfo.c.comp_info[0].h_samp_factor = sp->h_sampling; 931 sp->cinfo.c.comp_info[0].v_samp_factor = sp->v_sampling; 932 933 /* Scale expected strip/tile size to match a downsampled component. */ 934 935 sp->cinfo.c.image_width = TIFFhowmany(segment_width,sp->h_sampling); 936 sp->cinfo.c.image_height=TIFFhowmany(segment_height,sp->v_sampling); 937 }; 938 sp->scancount = 0; /* Mark subsampling buffer(s) empty */ 939 }; 940 return 1; 941 # undef td 942 } 943 944 static int 945 OJPEGPostEncode(register TIFF *tif) 946 { register OJPEGState *sp = OJState(tif); 947 948 /* Finish up at the end of a strip or tile. */ 949 950 if (sp->scancount > 0) /* emit partial buffer of down-sampled data */ 951 { JDIMENSION n; 952 953 # ifdef C_LOSSLESS_SUPPORTED 954 if ( sp->scancount < sp->cinfo.c.data_unit 955 && sp->cinfo.c.num_components > 0 956 ) 957 # else 958 if (sp->scancount < DCTSIZE && sp->cinfo.c.num_components > 0) 959 # endif 960 { int ci = 0, /* Pad the data vertically */ 961 # ifdef C_LOSSLESS_SUPPORTED 962 size = sp->cinfo.c.data_unit; 963 # else 964 size = DCTSIZE; 965 # endif 966 register jpeg_component_info *compptr = sp->cinfo.c.comp_info; 967 968 do 969 # ifdef C_LOSSLESS_SUPPORTED 970 { tsize_t row_width = compptr->width_in_data_units 971 # else 972 tsize_t row_width = compptr->width_in_blocks 973 # endif 974 *size*sizeof(JSAMPLE); 975 int ypos = sp->scancount*compptr->v_samp_factor; 976 977 do _TIFFmemcpy( (tdata_t)sp->ds_buffer[ci][ypos] 978 , (tdata_t)sp->ds_buffer[ci][ypos-1] 979 , row_width 980 ); 981 while (++ypos < compptr->v_samp_factor*size); 982 } 983 while (++compptr,++ci < sp->cinfo.c.num_components); 984 }; 985 n = sp->cinfo.c.max_v_samp_factor*size; 986 if (CALLJPEG(sp,-1,jpeg_write_raw_data(&sp->cinfo.c,sp->ds_buffer,n)) != n) 987 return 0; 988 }; 989 return CALLVJPEG(sp,jpeg_finish_compress(&sp->cinfo.c)); 990 } 991 #endif /* never */ 992 993 /* JPEG Decoding begins here. */ 994 995 /*ARGSUSED*/ static int 996 OJPEGDecode(register TIFF *tif,tidata_t buf,tsize_t cc,tsample_t s) 997 { tsize_t bytesperline = isTiled(tif) 998 ? TIFFTileRowSize(tif) 999 : tif->tif_scanlinesize, 1000 rows; /* No. of unprocessed rows in file */ 1001 register OJPEGState *sp = OJState(tif); 1002 1003 /* Decode a chunk of pixels, where the input data has not NOT been down- 1004 sampled, or else the TIFF Library's client has used the "JPEGColorMode" TIFF 1005 pseudo-tag to request that the JPEG Library do color-space conversion; this 1006 is the normal case. The data is expected to be read in scan-line multiples, 1007 and this subroutine is called for both pixel-interleaved and separate color 1008 planes. 1009 1010 WARNING: Unlike "OJPEGDecodeRawContig()", below, the no. of Bytes in each 1011 decoded row is calculated here as "bytesperline" instead of 1012 using "sp->bytesperline", which might be a little smaller. This can 1013 occur for an old tiled image whose width isn't a multiple of 8 pixels. 1014 That's illegal according to the TIFF Version 6 specification, but some 1015 test files, like "zackthecat.tif", were built that way. In those cases, 1016 we want to embed the image's true width in our caller's buffer (which is 1017 presumably allocated according to the expected tile width) by 1018 effectively "padding" it with unused Bytes at the end of each row. 1019 */ 1020 if ( (cc /= bytesperline) /* No. of complete rows in caller's buffer */ 1021 > (rows = sp->cinfo.d.output_height - sp->cinfo.d.output_scanline) 1022 ) cc = rows; 1023 while (--cc >= 0) 1024 { 1025 if ( CALLJPEG(sp,-1,jpeg_read_scanlines(&sp->cinfo.d,(JSAMPARRAY)&buf,1)) 1026 != 1 1027 ) return 0; 1028 buf += bytesperline; 1029 ++tif->tif_row; 1030 }; 1031 1032 /* BEWARE OF KLUDGE: If our input file was produced by Microsoft's Wang 1033 Imaging for Windows application, the DC coefficients of 1034 each JPEG image component (Y,Cb,Cr) must be reset at the end of each TIFF 1035 "strip", and any JPEG data bits remaining in the current Byte of the 1036 decoder's input buffer must be discarded. To do so, we create an "ad hoc" 1037 interface in the "jdhuff.c" module of IJG JPEG Library Version 6 (module 1038 "jdshuff.c", if Ken Murchison's lossless-Huffman patch is applied), and we 1039 invoke that interface here after decoding each "strip". 1040 */ 1041 if (sp->is_WANG) jpeg_reset_huff_decode(&sp->cinfo.d); 1042 return 1; 1043 } 1044 1045 /*ARGSUSED*/ static int 1046 OJPEGDecodeRawContig(register TIFF *tif,tidata_t buf,tsize_t cc,tsample_t s) 1047 { tsize_t rows; /* No. of unprocessed rows in file */ 1048 JDIMENSION lines_per_MCU, size; 1049 register OJPEGState *sp = OJState(tif); 1050 1051 /* Decode a chunk of pixels, where the input data has pixel-interleaved color 1052 planes, some of which have been down-sampled, but the TIFF Library's client 1053 has NOT used the "JPEGColorMode" TIFF pseudo-tag to request that the JPEG 1054 Library do color-space conversion. In other words, we must up-sample/ 1055 expand/duplicate image components according to the image's sampling factors, 1056 without changing its color space. The data is expected to be read in scan- 1057 line multiples. 1058 */ 1059 if ( (cc /= sp->bytesperline) /* No. of complete rows in caller's buffer */ 1060 > (rows = sp->cinfo.d.output_height - sp->cinfo.d.output_scanline) 1061 ) cc = rows; 1062 lines_per_MCU = sp->cinfo.d.max_v_samp_factor 1063 # ifdef D_LOSSLESS_SUPPORTED 1064 * (size = sp->cinfo.d.min_codec_data_unit); 1065 # else 1066 * (size = DCTSIZE); 1067 # endif 1068 while (--cc >= 0) 1069 { int clumpoffset, ci; 1070 register jpeg_component_info *compptr; 1071 1072 if (sp->scancount >= size) /* reload downsampled-data buffers */ 1073 { 1074 if ( CALLJPEG(sp,-1,jpeg_read_raw_data(&sp->cinfo.d,sp->ds_buffer,lines_per_MCU)) 1075 != lines_per_MCU 1076 ) return 0; 1077 sp->scancount = 0; 1078 }; 1079 1080 /* The fastest way to separate the data is: make 1 pass over the scan 1081 line for each row of each component. 1082 */ 1083 clumpoffset = ci = 0; 1084 compptr = sp->cinfo.d.comp_info; 1085 do 1086 { int ypos = 0; 1087 1088 if (compptr->h_samp_factor == 1) /* fast path */ 1089 do 1090 { register JSAMPLE *inptr = 1091 sp->ds_buffer[ci][sp->scancount*compptr->v_samp_factor+ypos], 1092 *outptr = (JSAMPLE *)buf + clumpoffset; 1093 register int clumps_per_line = compptr->downsampled_width; 1094 1095 do *outptr = *inptr++; 1096 while ((outptr += sp->samplesperclump),--clumps_per_line > 0); 1097 } 1098 while ( (clumpoffset += compptr->h_samp_factor) 1099 , ++ypos < compptr->v_samp_factor 1100 ); 1101 else /* general case */ 1102 do 1103 { register JSAMPLE *inptr = 1104 sp->ds_buffer[ci][sp->scancount*compptr->v_samp_factor+ypos], 1105 *outptr = (JSAMPLE *)buf + clumpoffset; 1106 register int clumps_per_line = compptr->downsampled_width; 1107 1108 do 1109 { register int xpos = 0; 1110 1111 do outptr[xpos] = *inptr++; 1112 while (++xpos < compptr->h_samp_factor); 1113 } 1114 while ((outptr += sp->samplesperclump),--clumps_per_line > 0); 1115 } 1116 while ( (clumpoffset += compptr->h_samp_factor) 1117 , ++ypos < compptr->v_samp_factor 1118 ); 1119 } 1120 while (++compptr,++ci < sp->cinfo.d.num_components); 1121 ++sp->scancount; 1122 buf += sp->bytesperline; 1123 ++tif->tif_row; 1124 }; 1125 1126 /* BEWARE OF KLUDGE: If our input file was produced by Microsoft's Wang 1127 Imaging for Windows application, the DC coefficients of 1128 each JPEG image component (Y,Cb,Cr) must be reset at the end of each TIFF 1129 "strip", and any JPEG data bits remaining in the current Byte of the 1130 decoder's input buffer must be discarded. To do so, we create an "ad hoc" 1131 interface in the "jdhuff.c" module of IJG JPEG Library Version 6 (module 1132 "jdshuff.c", if Ken Murchison's lossless-Huffman patch is applied), and we 1133 invoke that interface here after decoding each "strip". 1134 */ 1135 if (sp->is_WANG) jpeg_reset_huff_decode(&sp->cinfo.d); 1136 return 1; 1137 } 1138 1139 /*ARGSUSED*/ static int 1140 OJPEGDecodeRawSeparate(TIFF *tif,register tidata_t buf,tsize_t cc,tsample_t s) 1141 { tsize_t rows; /* No. of unprocessed rows in file */ 1142 JDIMENSION lines_per_MCU, 1143 size, /* ...of MCU */ 1144 v; /* Component's vertical up-sampling ratio */ 1145 register OJPEGState *sp = OJState(tif); 1146 register jpeg_component_info *compptr = sp->cinfo.d.comp_info + s; 1147 1148 /* Decode a chunk of pixels, where the input data has separate color planes, 1149 some of which have been down-sampled, but the TIFF Library's client has NOT 1150 used the "JPEGColorMode" TIFF pseudo-tag to request that the JPEG Library 1151 do color-space conversion. The data is expected to be read in scan-line 1152 multiples. 1153 */ 1154 v = sp->cinfo.d.max_v_samp_factor/compptr->v_samp_factor; 1155 if ( (cc /= compptr->downsampled_width) /* No. of rows in caller's buffer */ 1156 > (rows = (sp->cinfo.d.output_height-sp->cinfo.d.output_scanline+v-1)/v) 1157 ) cc = rows; /* No. of rows of "clumps" to read */ 1158 lines_per_MCU = sp->cinfo.d.max_v_samp_factor 1159 # ifdef D_LOSSLESS_SUPPORTED 1160 * (size = sp->cinfo.d.min_codec_data_unit); 1161 # else 1162 * (size = DCTSIZE); 1163 # endif 1164 L: if (sp->scancount >= size) /* reload downsampled-data buffers */ 1165 { 1166 if ( CALLJPEG(sp,-1,jpeg_read_raw_data(&sp->cinfo.d,sp->ds_buffer,lines_per_MCU)) 1167 != lines_per_MCU 1168 ) return 0; 1169 sp->scancount = 0; 1170 }; 1171 rows = 0; 1172 do 1173 { register JSAMPLE *inptr = 1174 sp->ds_buffer[s][sp->scancount*compptr->v_samp_factor + rows]; 1175 register int clumps_per_line = compptr->downsampled_width; 1176 1177 do *buf++ = *inptr++; while (--clumps_per_line > 0); /* Copy scanline */ 1178 tif->tif_row += v; 1179 if (--cc <= 0) return 1; /* End of caller's buffer? */ 1180 } 1181 while (++rows < compptr->v_samp_factor); 1182 ++sp->scancount; 1183 goto L; 1184 } 1185 1186 /* "OJPEGSetupDecode()" temporarily forces the JPEG Library to use the following 1187 subroutine as a "dummy" input reader in order to fool the library into 1188 thinking that it has read the image's first "Start of Scan" (SOS) marker, so 1189 that it initializes accordingly. 1190 */ 1191 /*ARGSUSED*/ METHODDEF(int) 1192 fake_SOS_marker(j_decompress_ptr cinfo){return JPEG_REACHED_SOS;} 1193 1194 /*ARGSUSED*/ METHODDEF(int) 1195 suspend(j_decompress_ptr cinfo){return JPEG_SUSPENDED;} 1196 1197 /* The JPEG Library's "null" color-space converter actually re-packs separate 1198 color planes (it's native image representation) into a pixel-interleaved, 1199 contiguous plane. But if our TIFF Library client is tryng to process a 1200 PLANARCONFIG_SEPARATE image, we don't want that; so here are modifications of 1201 code in the JPEG Library's "jdcolor.c" file, which simply copy Bytes to a 1202 color plane specified by the current JPEG "scan". 1203 */ 1204 METHODDEF(void) 1205 ycc_rgb_convert(register j_decompress_ptr cinfo,JSAMPIMAGE in,JDIMENSION row, 1206 register JSAMPARRAY out,register int nrows) 1207 { typedef struct /* "jdcolor.c" color-space conversion state */ 1208 { 1209 1210 /* WARNING: This declaration is ugly and dangerous! It's supposed to be 1211 private to the JPEG Library's "jdcolor.c" module, but we also 1212 need it here. Since the library's copy might change without notice, be 1213 sure to keep this one synchronized or the following code will break! 1214 */ 1215 struct jpeg_color_deconverter pub; /* Public fields */ 1216 /* Private state for YCC->RGB conversion */ 1217 int *Cr_r_tab, /* ->Cr to R conversion table */ 1218 *Cb_b_tab; /* ->Cb to B conversion table */ 1219 INT32 *Cr_g_tab, /* ->Cr to G conversion table */ 1220 *Cb_g_tab; /* ->Cb to G conversion table */ 1221 } *my_cconvert_ptr; 1222 my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert; 1223 JSAMPARRAY irow0p = in[0] + row; 1224 register JSAMPLE *range_limit = cinfo->sample_range_limit; 1225 register JSAMPROW outp, Y; 1226 1227 switch (cinfo->output_scan_number - 1) 1228 { JSAMPARRAY irow1p, irow2p; 1229 register INT32 *table0, *table1; 1230 SHIFT_TEMPS 1231 1232 case RGB_RED : irow2p = in[2] + row; 1233 table0 = (INT32 *)cconvert->Cr_r_tab; 1234 while (--nrows >= 0) 1235 { register JSAMPROW Cr = *irow2p++; 1236 register int i = cinfo->output_width; 1237 1238 Y = *irow0p++; 1239 outp = *out++; 1240 while (--i >= 0) 1241 *outp++ = range_limit[*Y++ + table0[*Cr++]]; 1242 }; 1243 return; 1244 case RGB_GREEN: irow1p = in[1] + row; 1245 irow2p = in[2] + row; 1246 table0 = cconvert->Cb_g_tab; 1247 table1 = cconvert->Cr_g_tab; 1248 while (--nrows >= 0) 1249 { register JSAMPROW Cb = *irow1p++, 1250 Cr = *irow2p++; 1251 register int i = cinfo->output_width; 1252 1253 Y = *irow0p++; 1254 outp = *out++; 1255 while (--i >= 0) 1256 *outp++ = 1257 range_limit[ *Y++ 1258 + RIGHT_SHIFT(table0[*Cb++]+table1[*Cr++],16) 1259 ]; 1260 }; 1261 return; 1262 case RGB_BLUE : irow1p = in[1] + row; 1263 table0 = (INT32 *)cconvert->Cb_b_tab; 1264 while (--nrows >= 0) 1265 { register JSAMPROW Cb = *irow1p++; 1266 register int i = cinfo->output_width; 1267 1268 Y = *irow0p++; 1269 outp = *out++; 1270 while (--i >= 0) 1271 *outp++ = range_limit[*Y++ + table0[*Cb++]]; 1272 } 1273 } 1274 } 1275 1276 METHODDEF(void) 1277 null_convert(register j_decompress_ptr cinfo,JSAMPIMAGE in,JDIMENSION row, 1278 register JSAMPARRAY out,register int nrows) 1279 { register JSAMPARRAY irowp = in[cinfo->output_scan_number - 1] + row; 1280 1281 while (--nrows >= 0) _TIFFmemcpy(*out++,*irowp++,cinfo->output_width); 1282 } 1283 1284 static int 1285 OJPEGSetupDecode(register TIFF *tif) 1286 { static char module[]={"OJPEGSetupDecode"}; 1287 J_COLOR_SPACE jpeg_color_space, /* Color space of JPEG-compressed image */ 1288 out_color_space; /* Color space of decompressed image */ 1289 uint32 segment_width; 1290 int status = 1; /* Assume success by default */ 1291 boolean downsampled_output=FALSE, /* <=> Want JPEG Library's "raw" image? */ 1292 is_JFIF; /* <=> JFIF image? */ 1293 register OJPEGState *sp = OJState(tif); 1294 # define td (&tif->tif_dir) 1295 1296 /* Verify miscellaneous parameters. This will need work if the TIFF Library 1297 ever supports different depths for different components, or if the JPEG 1298 Library ever supports run-time depth selection. Neither seems imminent. 1299 */ 1300 if (td->td_bitspersample != sp->cinfo.d.data_precision) 1301 { 1302 TIFFError(module,bad_bps,td->td_bitspersample); 1303 status = 0; 1304 }; 1305 1306 /* The TIFF Version 6.0 specification and IJG JPEG Library accept different 1307 sets of color spaces, so verify that our image belongs to the common subset 1308 and map its photometry code, then initialize to handle subsampling and 1309 optional JPEG Library YCbCr <-> RGB color-space conversion. 1310 */ 1311 switch (td->td_photometric) 1312 { 1313 case PHOTOMETRIC_YCBCR : 1314 1315 /* ISO IS 10918-1 requires that JPEG subsampling factors be 1-4, but 1316 TIFF Version 6.0 is more restrictive: only 1, 2, and 4 are allowed. 1317 */ 1318 if ( ( td->td_ycbcrsubsampling[0] == 1 1319 || td->td_ycbcrsubsampling[0] == 2 1320 || td->td_ycbcrsubsampling[0] == 4 1321 ) 1322 && ( td->td_ycbcrsubsampling[1] == 1 1323 || td->td_ycbcrsubsampling[1] == 2 1324 || td->td_ycbcrsubsampling[1] == 4 1325 ) 1326 ) 1327 downsampled_output = 1328 ( 1329 (sp->h_sampling = td->td_ycbcrsubsampling[0]) << 3 1330 | (sp->v_sampling = td->td_ycbcrsubsampling[1]) 1331 ) != 011; 1332 else 1333 { 1334 TIFFError(module,bad_subsampling); 1335 status = 0; 1336 }; 1337 jpeg_color_space = JCS_YCbCr; 1338 if (sp->jpegcolormode == JPEGCOLORMODE_RGB) 1339 { 1340 downsampled_output = FALSE; 1341 out_color_space = JCS_RGB; 1342 break; 1343 }; 1344 goto L2; 1345 case PHOTOMETRIC_MINISBLACK: 1346 jpeg_color_space = JCS_GRAYSCALE; 1347 goto L1; 1348 case PHOTOMETRIC_RGB : 1349 jpeg_color_space = JCS_RGB; 1350 goto L1; 1351 case PHOTOMETRIC_SEPARATED : 1352 jpeg_color_space = JCS_CMYK; 1353 L1: sp->jpegcolormode = JPEGCOLORMODE_RAW; /* No JPEG Lib. conversion */ 1354 L2: out_color_space = jpeg_color_space; 1355 break; 1356 default : 1357 TIFFError(module,bad_photometry,td->td_photometric); 1358 status = 0; 1359 }; 1360 if (status == 0) return 0; /* If TIFF errors, don't bother to continue */ 1361 1362 /* Set parameters that are same for all strips/tiles. */ 1363 1364 sp->cinfo.d.src = &sp->src; 1365 sp->src.init_source = std_init_source; 1366 sp->src.fill_input_buffer = std_fill_input_buffer; 1367 sp->src.skip_input_data = std_skip_input_data; 1368 sp->src.resync_to_restart = jpeg_resync_to_restart; 1369 sp->src.term_source = std_term_source; 1370 1371 /* BOGOSITY ALERT! The Wang Imaging application for Microsoft Windows produces 1372 images containing "JPEGInterchangeFormat[Length]" TIFF 1373 records that resemble JFIF-in-TIFF encapsulations but, in fact, violate the 1374 TIFF Version 6 specification in several ways; nevertheless, we try to handle 1375 them gracefully because there are apparently a lot of them around. The 1376 purported "JFIF" data stream in one of these files vaguely resembles a JPEG 1377 "tables only" data stream, except that there's no trailing EOI marker. The 1378 rest of the JPEG data stream lies in a discontiguous file region, identified 1379 by the 0th Strip offset (which is *also* illegal!), where it begins with an 1380 SOS marker and apparently continues to the end of the file. There is no 1381 trailing EOI marker here, either. 1382 */ 1383 is_JFIF = !sp->is_WANG && TIFFFieldSet(tif,FIELD_JPEGIFOFFSET); 1384 1385 /* Initialize decompression parameters that won't be overridden by JPEG Library 1386 defaults set during the "jpeg_read_header()" call, below. 1387 */ 1388 segment_width = td->td_imagewidth; 1389 if (isTiled(tif)) 1390 { 1391 if (sp->is_WANG) /* we don't know how to handle it */ 1392 { 1393 TIFFError(module,"Tiled Wang image not supported"); 1394 return 0; 1395 }; 1396 1397 /* BOGOSITY ALERT! "TIFFTileRowSize()" seems to work fine for modern JPEG- 1398 in-TIFF encapsulations where the image width--like the 1399 tile width--is a multiple of 8 or 16 pixels. But image widths and 1400 heights are aren't restricted to 8- or 16-bit multiples, and we need 1401 the exact Byte count of decompressed scan lines when we call the JPEG 1402 Library. At least one old file ("zackthecat.tif") in the TIFF Library 1403 test suite has widths and heights slightly less than the tile sizes, and 1404 it apparently used the bogus computation below to determine the number 1405 of Bytes per scan line (was this due to an old, broken version of 1406 "TIFFhowmany()"?). Before we get here, "OJPEGSetupDecode()" verified 1407 that our image uses 8-bit samples, so the following check appears to 1408 return the correct answer in all known cases tested to date. 1409 */ 1410 if (is_JFIF || (segment_width & 7) == 0) 1411 sp->bytesperline = TIFFTileRowSize(tif); /* Normal case */ 1412 else 1413 { 1414 /* Was the file-encoder's segment-width calculation bogus? */ 1415 segment_width = (segment_width/sp->h_sampling + 1) * sp->h_sampling; 1416 sp->bytesperline = segment_width * td->td_samplesperpixel; 1417 } 1418 } 1419 else sp->bytesperline = TIFFVStripSize(tif,1); 1420 1421 /* BEWARE OF KLUDGE: If we have JPEG Interchange File Format (JFIF) image, 1422 then we want to read "metadata" in the bit-stream's 1423 header and validate it against corresponding information in TIFF records. 1424 But if we have a *really old* JPEG file that's not JFIF, then we simply 1425 assign TIFF-record values to JPEG Library variables without checking. 1426 */ 1427 if (is_JFIF) /* JFIF image */ 1428 { unsigned char *end_of_data; 1429 int subsampling_factors; 1430 register unsigned char *p; 1431 register int i; 1432 1433 /* WARNING: Although the image file contains a JFIF bit stream, it might 1434 also contain some old TIFF records causing "OJPEGVSetField()" 1435 to have allocated quantization or Huffman decoding tables. But when the 1436 JPEG Library reads and parses the JFIF header below, it reallocate these 1437 tables anew without checking for "dangling" pointers, thereby causing a 1438 memory "leak". We have enough information to potentially deallocate the 1439 old tables here, but unfortunately JPEG Library Version 6B uses a "pool" 1440 allocator for small objects, with no deallocation procedure; instead, it 1441 reclaims a whole pool when an image is closed/destroyed, so well-behaved 1442 TIFF client applications (i.e., those which close their JPEG images as 1443 soon as they're no longer needed) will waste memory for a short time but 1444 recover it eventually. But ill-behaved TIFF clients (i.e., those which 1445 keep many JPEG images open gratuitously) can exhaust memory prematurely. 1446 If the JPEG Library ever implements a deallocation procedure, insert 1447 this clean-up code: 1448 */ 1449 # ifdef someday 1450 if (sp->jpegtablesmode & JPEGTABLESMODE_QUANT) /* free quant. tables */ 1451 { register int i = 0; 1452 1453 do 1454 { register JQUANT_TBL *q; 1455 1456 if (q = sp->cinfo.d.quant_tbl_ptrs[i]) 1457 { 1458 jpeg_free_small(&sp->cinfo.comm,q,sizeof *q); 1459 sp->cinfo.d.quant_tbl_ptrs[i] = 0; 1460 } 1461 } 1462 while (++i < NUM_QUANT_TBLS); 1463 }; 1464 if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF) /* free Huffman tables */ 1465 { register int i = 0; 1466 1467 do 1468 { register JHUFF_TBL *h; 1469 1470 if (h = sp->cinfo.d.dc_huff_tbl_ptrs[i]) 1471 { 1472 jpeg_free_small(&sp->cinfo.comm,h,sizeof *h); 1473 sp->cinfo.d.dc_huff_tbl_ptrs[i] = 0; 1474 }; 1475 if (h = sp->cinfo.d.ac_huff_tbl_ptrs[i]) 1476 { 1477 jpeg_free_small(&sp->cinfo.comm,h,sizeof *h); 1478 sp->cinfo.d.ac_huff_tbl_ptrs[i] = 0; 1479 } 1480 } 1481 while (++i < NUM_HUFF_TBLS); 1482 }; 1483 # endif /* someday */ 1484 1485 /* Since we might someday wish to try rewriting "old format" JPEG-in-TIFF 1486 encapsulations in "new format" files, try to synthesize the value of a 1487 modern "JPEGTables" TIFF record by scanning the JPEG data from just past 1488 the "Start of Information" (SOI) marker until something other than a 1489 legitimate "table" marker is found, as defined in ISO IS 10918-1 1490 Appending B.2.4; namely: 1491 1492 -- Define Quantization Table (DQT) 1493 -- Define Huffman Table (DHT) 1494 -- Define Arithmetic Coding table (DAC) 1495 -- Define Restart Interval (DRI) 1496 -- Comment (COM) 1497 -- Application data (APPn) 1498 1499 For convenience, we also accept "Expansion" (EXP) markers, although they 1500 are apparently not a part of normal "table" data. 1501 */ 1502 sp->jpegtables = p = (unsigned char *)sp->src.next_input_byte; 1503 end_of_data = p + sp->src.bytes_in_buffer; 1504 p += 2; 1505 while (p < end_of_data && p[0] == 0xFF) 1506 switch (p[1]) 1507 { 1508 default : goto L; 1509 case 0xC0: /* SOF0 */ 1510 case 0xC1: /* SOF1 */ 1511 case 0xC2: /* SOF2 */ 1512 case 0xC3: /* SOF3 */ 1513 case 0xC4: /* DHT */ 1514 case 0xC5: /* SOF5 */ 1515 case 0xC6: /* SOF6 */ 1516 case 0xC7: /* SOF7 */ 1517 case 0xC9: /* SOF9 */ 1518 case 0xCA: /* SOF10 */ 1519 case 0xCB: /* SOF11 */ 1520 case 0xCC: /* DAC */ 1521 case 0xCD: /* SOF13 */ 1522 case 0xCE: /* SOF14 */ 1523 case 0xCF: /* SOF15 */ 1524 case 0xDB: /* DQT */ 1525 case 0xDD: /* DRI */ 1526 case 0xDF: /* EXP */ 1527 case 0xE0: /* APP0 */ 1528 case 0xE1: /* APP1 */ 1529 case 0xE2: /* APP2 */ 1530 case 0xE3: /* APP3 */ 1531 case 0xE4: /* APP4 */ 1532 case 0xE5: /* APP5 */ 1533 case 0xE6: /* APP6 */ 1534 case 0xE7: /* APP7 */ 1535 case 0xE8: /* APP8 */ 1536 case 0xE9: /* APP9 */ 1537 case 0xEA: /* APP10 */ 1538 case 0xEB: /* APP11 */ 1539 case 0xEC: /* APP12 */ 1540 case 0xED: /* APP13 */ 1541 case 0xEE: /* APP14 */ 1542 case 0xEF: /* APP15 */ 1543 case 0xFE: /* COM */ 1544 p += (p[2] << 8 | p[3]) + 2; 1545 }; 1546 L: if (p - (unsigned char *)sp->jpegtables > 2) /* fake "JPEGTables" */ 1547 { 1548 1549 /* In case our client application asks, pretend that this image file 1550 contains a modern "JPEGTables" TIFF record by copying to a buffer 1551 the initial part of the JFIF bit-stream that we just scanned, from 1552 the SOI marker through the "metadata" tables, then append an EOI 1553 marker and flag the "JPEGTables" TIFF record as "present". 1554 */ 1555 sp->jpegtables_length = p - (unsigned char*)sp->jpegtables + 2; 1556 p = sp->jpegtables; 1557 if (!(sp->jpegtables = _TIFFmalloc(sp->jpegtables_length))) 1558 { 1559 TIFFError(module,no_jtable_space); 1560 return 0; 1561 }; 1562 _TIFFmemcpy(sp->jpegtables,p,sp->jpegtables_length-2); 1563 p = (unsigned char *)sp->jpegtables + sp->jpegtables_length; 1564 p[-2] = 0xFF; p[-1] = JPEG_EOI; /* Append EOI marker */ 1565 TIFFSetFieldBit(tif,FIELD_JPEGTABLES); 1566 tif->tif_flags |= TIFF_DIRTYDIRECT; 1567 } 1568 else sp->jpegtables = 0; /* Don't simulate "JPEGTables" */ 1569 if ( CALLJPEG(sp,-1,jpeg_read_header(&sp->cinfo.d,TRUE)) 1570 != JPEG_HEADER_OK 1571 ) return 0; 1572 if ( sp->cinfo.d.image_width != segment_width 1573 || sp->cinfo.d.image_height != td->td_imagelength 1574 ) 1575 { 1576 TIFFError(module,"Improper JPEG strip/tile size"); 1577 return 0; 1578 }; 1579 if (sp->cinfo.d.num_components != td->td_samplesperpixel) 1580 { 1581 TIFFError(module,"Improper JPEG component count"); 1582 return 0; 1583 }; 1584 if (sp->cinfo.d.data_precision != td->td_bitspersample) 1585 { 1586 TIFFError(module,"Improper JPEG data precision"); 1587 return 0; 1588 }; 1589 1590 /* Check that JPEG image components all have the same subsampling factors 1591 declared (or defaulted) in the TIFF file, since TIFF Version 6.0 is more 1592 restrictive than JPEG: Only the 0th component may have horizontal and 1593 vertical subsampling factors other than <1,1>. 1594 */ 1595 subsampling_factors = sp->h_sampling << 3 | sp->v_sampling; 1596 i = 0; 1597 do 1598 { 1599 if ( ( sp->cinfo.d.comp_info[i].h_samp_factor << 3 1600 | sp->cinfo.d.comp_info[i].v_samp_factor 1601 ) 1602 != subsampling_factors 1603 ) 1604 { 1605 TIFFError(module,"Improper JPEG subsampling factors"); 1606 return 0; 1607 }; 1608 subsampling_factors = 011; /* Required for image components > 0 */ 1609 } 1610 while (++i < sp->cinfo.d.num_components); 1611 } 1612 else /* not JFIF image */ 1613 { int (*save)(j_decompress_ptr cinfo) = sp->cinfo.d.marker->read_markers; 1614 register int i; 1615 1616 /* We're not assuming that this file's JPEG bit stream has any header 1617 "metadata", so fool the JPEG Library into thinking that we read a 1618 "Start of Input" (SOI) marker and a "Start of Frame" (SOFx) marker, then 1619 force it to read a simulated "Start of Scan" (SOS) marker when we call 1620 "jpeg_read_header()" below. This should cause the JPEG Library to 1621 establish reasonable defaults. 1622 */ 1623 sp->cinfo.d.marker->saw_SOI = /* Pretend we saw SOI marker */ 1624 sp->cinfo.d.marker->saw_SOF = TRUE; /* Pretend we saw SOF marker */ 1625 sp->cinfo.d.marker->read_markers = 1626 sp->is_WANG ? suspend : fake_SOS_marker; 1627 sp->cinfo.d.global_state = DSTATE_INHEADER; 1628 sp->cinfo.d.Se = DCTSIZE2-1; /* Suppress JPEG Library warning */ 1629 sp->cinfo.d.image_width = segment_width; 1630 sp->cinfo.d.image_height = td->td_imagelength; 1631 1632 /* The following color-space initialization, including the complicated 1633 "switch"-statement below, essentially duplicates the logic used by the 1634 JPEG Library's "jpeg_init_colorspace()" subroutine during compression. 1635 */ 1636 sp->cinfo.d.num_components = td->td_samplesperpixel; 1637 sp->cinfo.d.comp_info = (jpeg_component_info *) 1638 (*sp->cinfo.d.mem->alloc_small) 1639 ( &sp->cinfo.comm 1640 , JPOOL_IMAGE 1641 , sp->cinfo.d.num_components * sizeof *sp->cinfo.d.comp_info 1642 ); 1643 i = 0; 1644 do 1645 { 1646 sp->cinfo.d.comp_info[i].component_index = i; 1647 sp->cinfo.d.comp_info[i].component_needed = TRUE; 1648 sp->cinfo.d.cur_comp_info[i] = &sp->cinfo.d.comp_info[i]; 1649 } 1650 while (++i < sp->cinfo.d.num_components); 1651 switch (jpeg_color_space) 1652 { 1653 case JCS_UNKNOWN : 1654 i = 0; 1655 do 1656 { 1657 sp->cinfo.d.comp_info[i].component_id = i; 1658 sp->cinfo.d.comp_info[i].h_samp_factor = 1659 sp->cinfo.d.comp_info[i].v_samp_factor = 1; 1660 } 1661 while (++i < sp->cinfo.d.num_components); 1662 break; 1663 case JCS_GRAYSCALE: 1664 sp->cinfo.d.comp_info[0].component_id = 1665 sp->cinfo.d.comp_info[0].h_samp_factor = 1666 sp->cinfo.d.comp_info[0].v_samp_factor = 1; 1667 break; 1668 case JCS_RGB : 1669 sp->cinfo.d.comp_info[0].component_id = 'R'; 1670 sp->cinfo.d.comp_info[1].component_id = 'G'; 1671 sp->cinfo.d.comp_info[2].component_id = 'B'; 1672 i = 0; 1673 do sp->cinfo.d.comp_info[i].h_samp_factor = 1674 sp->cinfo.d.comp_info[i].v_samp_factor = 1; 1675 while (++i < sp->cinfo.d.num_components); 1676 break; 1677 case JCS_CMYK : 1678 sp->cinfo.d.comp_info[0].component_id = 'C'; 1679 sp->cinfo.d.comp_info[1].component_id = 'M'; 1680 sp->cinfo.d.comp_info[2].component_id = 'Y'; 1681 sp->cinfo.d.comp_info[3].component_id = 'K'; 1682 i = 0; 1683 do sp->cinfo.d.comp_info[i].h_samp_factor = 1684 sp->cinfo.d.comp_info[i].v_samp_factor = 1; 1685 while (++i < sp->cinfo.d.num_components); 1686 break; 1687 case JCS_YCbCr : 1688 i = 0; 1689 do 1690 { 1691 sp->cinfo.d.comp_info[i].component_id = i+1; 1692 sp->cinfo.d.comp_info[i].h_samp_factor = 1693 sp->cinfo.d.comp_info[i].v_samp_factor = 1; 1694 sp->cinfo.d.comp_info[i].quant_tbl_no = 1695 sp->cinfo.d.comp_info[i].dc_tbl_no = 1696 sp->cinfo.d.comp_info[i].ac_tbl_no = i > 0; 1697 } 1698 while (++i < sp->cinfo.d.num_components); 1699 sp->cinfo.d.comp_info[0].h_samp_factor = sp->h_sampling; 1700 sp->cinfo.d.comp_info[0].v_samp_factor = sp->v_sampling; 1701 }; 1702 sp->cinfo.d.comps_in_scan = td->td_planarconfig == PLANARCONFIG_CONTIG 1703 ? sp->cinfo.d.num_components 1704 : 1; 1705 i = CALLJPEG(sp,-1,jpeg_read_header(&sp->cinfo.d,!sp->is_WANG)); 1706 sp->cinfo.d.marker->read_markers = save; /* Restore input method */ 1707 if (sp->is_WANG) /* produced by Wang Imaging on Microsoft Windows */ 1708 { 1709 if (i != JPEG_SUSPENDED) return 0; 1710 1711 /* BOGOSITY ALERT! Files prooduced by the Wang Imaging application for 1712 Microsoft Windows are a special--and, technically 1713 illegal--case. A JPEG SOS marker and rest of the data stream should 1714 be located at the end of the file, in a position identified by the 1715 0th Strip offset. 1716 */ 1717 i = td->td_nstrips - 1; 1718 sp->src.next_input_byte = tif->tif_base + td->td_stripoffset[0]; 1719 sp->src.bytes_in_buffer = td->td_stripoffset[i] - 1720 td->td_stripoffset[0] + td->td_stripbytecount[i]; 1721 i = CALLJPEG(sp,-1,jpeg_read_header(&sp->cinfo.d,TRUE)); 1722 }; 1723 if (i != JPEG_HEADER_OK) return 0; 1724 }; 1725 1726 /* Some of our initialization must wait until the JPEG Library is initialized 1727 above, in order to override its defaults. 1728 */ 1729 if ( (sp->cinfo.d.raw_data_out = downsampled_output) 1730 && !alloc_downsampled_buffers(tif,sp->cinfo.d.comp_info, 1731 sp->cinfo.d.num_components) 1732 ) return 0; 1733 sp->cinfo.d.jpeg_color_space = jpeg_color_space; 1734 sp->cinfo.d.out_color_space = out_color_space; 1735 sp->cinfo.d.dither_mode = JDITHER_NONE; /* Reduce image "noise" */ 1736 sp->cinfo.d.two_pass_quantize = FALSE; 1737 1738 /* If the image consists of separate, discontiguous TIFF "samples" (= color 1739 planes, hopefully = JPEG "scans"), then we must use the JPEG Library's 1740 "buffered image" mode to decompress the entire image into temporary buffers, 1741 because the JPEG Library must parse the entire JPEG bit-stream in order to 1742 be satsified that it has a complete set of color components for each pixel, 1743 but the TIFF Library must allow our client to extract 1 component at a time. 1744 Initializing the JPEG Library's "buffered image" mode is tricky: First, we 1745 start its decompressor, then we tell the decompressor to "consume" (i.e., 1746 buffer) the entire bit-stream. 1747 1748 WARNING: Disabling "fancy" up-sampling seems to slightly reduce "noise" for 1749 certain old Wang Imaging files, but it absolutely *must* be 1750 enabled if the image has separate color planes, since in that case, the JPEG 1751 Library doesn't use an "sp->cinfo.d.cconvert" structure (so de-referencing 1752 this pointer below will cause a fatal crash) but writing our own code to up- 1753 sample separate color planes is too much work for right now. Maybe someday? 1754 */ 1755 sp->cinfo.d.do_fancy_upsampling = /* Always let this default (to TRUE)? */ 1756 sp->cinfo.d.buffered_image = td->td_planarconfig == PLANARCONFIG_SEPARATE; 1757 if (!CALLJPEG(sp,0,jpeg_start_decompress(&sp->cinfo.d))) return 0; 1758 if (sp->cinfo.d.buffered_image) /* separate color planes */ 1759 { 1760 if (sp->cinfo.d.raw_data_out) 1761 tif->tif_decoderow = tif->tif_decodestrip = tif->tif_decodetile = 1762 OJPEGDecodeRawSeparate; 1763 else 1764 { 1765 tif->tif_decoderow = tif->tif_decodestrip = tif->tif_decodetile = 1766 OJPEGDecode; 1767 1768 /* In JPEG Library Version 6B, color-space conversion isn't implemented 1769 for separate color planes, so we must do it ourself if our TIFF 1770 client doesn't want to: 1771 */ 1772 sp->cinfo.d.cconvert->color_convert = 1773 sp->cinfo.d.jpeg_color_space == sp->cinfo.d.out_color_space 1774 ? null_convert : ycc_rgb_convert; 1775 }; 1776 L3: switch (CALLJPEG(sp,0,jpeg_consume_input(&sp->cinfo.d))) 1777 { 1778 default : goto L3; 1779 1780 /* If no JPEG "End of Information" (EOI) marker is found when bit- 1781 stream parsing ends, check whether we have enough data to proceed 1782 before reporting an error. 1783 */ 1784 case JPEG_SUSPENDED : if ( sp->cinfo.d.input_scan_number 1785 *sp->cinfo.d.image_height 1786 + sp->cinfo.d.input_iMCU_row 1787 *sp->cinfo.d.max_v_samp_factor 1788 # ifdef D_LOSSLESS_SUPPORTED 1789 *sp->cinfo.d.data_units_in_MCU 1790 *sp->cinfo.d.min_codec_data_unit 1791 # else 1792 *sp->cinfo.d.blocks_in_MCU 1793 *DCTSIZE 1794 # endif 1795 < td->td_samplesperpixel 1796 *sp->cinfo.d.image_height 1797 ) 1798 { 1799 TIFFError(tif->tif_name, 1800 "Premature end of JPEG bit-stream"); 1801 return 0; 1802 } 1803 case JPEG_REACHED_EOI: ; 1804 } 1805 } 1806 else /* pixel-interleaved color planes */ 1807 tif->tif_decoderow = tif->tif_decodestrip = tif->tif_decodetile = 1808 downsampled_output ? OJPEGDecodeRawContig : OJPEGDecode; 1809 return 1; 1810 # undef td 1811 } 1812 1813 static int 1814 OJPEGPreDecode(register TIFF *tif,tsample_t s) 1815 { register OJPEGState *sp = OJState(tif); 1816 # define td (&tif->tif_dir) 1817 1818 /* If we are about to read the first row of an image plane (hopefully, these 1819 are coincident with JPEG "scans"!), reset the JPEG Library's decompressor 1820 appropriately. Otherwise, let the decompressor run "as is" and return a 1821 "success" status without further ado. 1822 */ 1823 if ( (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip) 1824 % td->td_stripsperimage 1825 == 0 1826 ) 1827 { 1828 if ( sp->cinfo.d.buffered_image 1829 && !CALLJPEG(sp,0,jpeg_start_output(&sp->cinfo.d,s+1)) 1830 ) return 0; 1831 sp->cinfo.d.output_scanline = 0; 1832 1833 /* Mark subsampling buffers "empty". */ 1834 1835 # ifdef D_LOSSLESS_SUPPORTED 1836 sp->scancount = sp->cinfo.d.min_codec_data_unit; 1837 # else 1838 sp->scancount = DCTSIZE; 1839 # endif 1840 }; 1841 return 1; 1842 # undef td 1843 } 1844 1845 /*ARGSUSED*/ static void 1846 OJPEGPostDecode(register TIFF *tif,tidata_t buf,tsize_t cc) 1847 { register OJPEGState *sp = OJState(tif); 1848 # define td (&tif->tif_dir) 1849 1850 /* The JPEG Library decompressor has reached the end of a strip/tile. If this 1851 is the end of a TIFF image "sample" (= JPEG "scan") in a file with separate 1852 components (color planes), then end the "scan". If it ends the image's last 1853 sample/scan, then also stop the JPEG Library's decompressor. 1854 */ 1855 if (sp->cinfo.d.output_scanline >= sp->cinfo.d.output_height) 1856 { 1857 if (sp->cinfo.d.buffered_image) 1858 CALLJPEG(sp,-1,jpeg_finish_output(&sp->cinfo.d)); /* End JPEG scan */ 1859 if ( (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip) 1860 >= td->td_nstrips-1 1861 ) CALLJPEG(sp,0,jpeg_finish_decompress(&sp->cinfo.d)); 1862 } 1863 # undef td 1864 } 1865 1866 static int 1867 OJPEGVSetField(register TIFF *tif,ttag_t tag,va_list ap) 1868 { 1869 uint32 v32; 1870 register OJPEGState *sp = OJState(tif); 1871 # define td (&tif->tif_dir) 1872 toff_t tiffoff=0; 1873 uint32 bufoff=0; 1874 uint32 code_count=0; 1875 int i2=0; 1876 int k2=0; 1877 1878 switch (tag) 1879 { 1880 default : return 1881 (*sp->vsetparent)(tif,tag,ap); 1882 1883 /* BEWARE OF KLUDGE: Some old-format JPEG-in-TIFF files, including those 1884 produced by the Wang Imaging application for Micro- 1885 soft Windows, illegally omit a "ReferenceBlackWhite" TIFF tag, even 1886 though the TIFF specification's default is intended for the RGB color 1887 space and is inappropriate for the YCbCr color space ordinarily used for 1888 JPEG images. Since many TIFF client applications request the value of 1889 this tag immediately after a TIFF image directory is parsed, and before 1890 any other code in this module receives control, we are forced to fix 1891 this problem very early in image-file processing. Fortunately, legal 1892 TIFF files are supposed to store their tags in numeric order, so a 1893 mandatory "PhotometricInterpretation" tag should always appear before 1894 an optional "ReferenceBlackWhite" tag. Hence, we slyly peek ahead when 1895 we discover the desired photometry, by installing modified black and 1896 white reference levels. 1897 */ 1898 case TIFFTAG_PHOTOMETRIC : 1899 if ( (v32 = (*sp->vsetparent)(tif,tag,ap)) 1900 && td->td_photometric == PHOTOMETRIC_YCBCR 1901 ) 1902 { 1903 float *ref; 1904 if (!TIFFGetField(tif, TIFFTAG_REFERENCEBLACKWHITE, &ref)) { 1905 float refbw[6]; 1906 long top = 1L << td->td_bitspersample; 1907 refbw[0] = 0; 1908 refbw[1] = (float)(top-1L); 1909 refbw[2] = (float)(top>>1); 1910 refbw[3] = refbw[1]; 1911 refbw[4] = refbw[2]; 1912 refbw[5] = refbw[1]; 1913 TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, refbw); 1914 } 1915 } 1916 return v32; 1917 1918 /* BEWARE OF KLUDGE: According to Charles Auer <Bumble731@msn.com>, if our 1919 input is a multi-image (multi-directory) JPEG-in-TIFF 1920 file is produced by the Wang Imaging application on Microsoft Windows, 1921 for some reason the first directory excludes the vendor-specific "WANG 1922 PageControl" tag (32934) that we check below, so the only other way to 1923 identify these directories is apparently to look for a software- 1924 identification tag with the substring, "Wang Labs". Single-image files 1925 can apparently pass both tests, which causes no harm here, but what a 1926 mess this is! 1927 */ 1928 case TIFFTAG_SOFTWARE : 1929 { 1930 char *software; 1931 1932 v32 = (*sp->vsetparent)(tif,tag,ap); 1933 if( TIFFGetField( tif, TIFFTAG_SOFTWARE, &software ) 1934 && strstr( software, "Wang Labs" ) ) 1935 sp->is_WANG = 1; 1936 return v32; 1937 } 1938 1939 case TIFFTAG_JPEGPROC : 1940 case TIFFTAG_JPEGIFOFFSET : 1941 case TIFFTAG_JPEGIFBYTECOUNT : 1942 case TIFFTAG_JPEGRESTARTINTERVAL : 1943 case TIFFTAG_JPEGLOSSLESSPREDICTORS: 1944 case TIFFTAG_JPEGPOINTTRANSFORM : 1945 case TIFFTAG_JPEGQTABLES : 1946 case TIFFTAG_JPEGDCTABLES : 1947 case TIFFTAG_JPEGACTABLES : 1948 case TIFFTAG_WANG_PAGECONTROL : 1949 case TIFFTAG_JPEGCOLORMODE : ; 1950 }; 1951 v32 = va_arg(ap,uint32); /* No. of values in this TIFF record */ 1952 1953 /* This switch statement is added for OJPEGVSetField */ 1954 if(v32 !=0){ 1955 switch(tag){ 1956 case TIFFTAG_JPEGPROC: 1957 sp->jpegproc=v32; 1958 break; 1959 case TIFFTAG_JPEGIFOFFSET: 1960 sp->jpegifoffset=v32; 1961 break; 1962 case TIFFTAG_JPEGIFBYTECOUNT: 1963 sp->jpegifbytecount=v32; 1964 break; 1965 case TIFFTAG_JPEGRESTARTINTERVAL: 1966 sp->jpegrestartinterval=v32; 1967 break; 1968 case TIFFTAG_JPEGLOSSLESSPREDICTORS: 1969 sp->jpeglosslesspredictors_length=v32; 1970 break; 1971 case TIFFTAG_JPEGPOINTTRANSFORM: 1972 sp->jpegpointtransform_length=v32; 1973 break; 1974 case TIFFTAG_JPEGQTABLES: 1975 sp->jpegqtables_length=v32; 1976 break; 1977 case TIFFTAG_JPEGACTABLES: 1978 sp->jpegactables_length=v32; 1979 break; 1980 case TIFFTAG_JPEGDCTABLES: 1981 sp->jpegdctables_length=v32; 1982 break; 1983 default: 1984 break; 1985 } 1986 } 1987 1988 /* BEWARE: The following actions apply only if we are reading a "source" TIFF 1989 image to be decompressed for a client application program. If we 1990 ever enhance this file's CODEC to write "destination" JPEG-in-TIFF images, 1991 we'll need an "if"- and another "switch"-statement below, because we'll 1992 probably want to store these records' values in some different places. Most 1993 of these need not be parsed here in order to decode JPEG bit stream, so we 1994 set boolean flags to note that they have been seen, but we otherwise ignore 1995 them. 1996 */ 1997 switch (tag) 1998 { JHUFF_TBL **h; 1999 2000 /* Validate the JPEG-process code. */ 2001 2002 case TIFFTAG_JPEGPROC : 2003 switch (v32) 2004 { 2005 default : TIFFError(tif->tif_name, 2006 "Unknown JPEG process"); 2007 return 0; 2008 # ifdef C_LOSSLESS_SUPPORTED 2009 2010 /* Image uses (lossy) baseline sequential coding. */ 2011 2012 case JPEGPROC_BASELINE: sp->cinfo.d.process = JPROC_SEQUENTIAL; 2013 sp->cinfo.d.data_unit = DCTSIZE; 2014 break; 2015 2016 /* Image uses (lossless) Huffman coding. */ 2017 2018 case JPEGPROC_LOSSLESS: sp->cinfo.d.process = JPROC_LOSSLESS; 2019 sp->cinfo.d.data_unit = 1; 2020 # else /* not C_LOSSLESS_SUPPORTED */ 2021 case JPEGPROC_LOSSLESS: TIFFError(JPEGLib_name, 2022 "Does not support lossless Huffman coding"); 2023 return 0; 2024 case JPEGPROC_BASELINE: ; 2025 # endif /* C_LOSSLESS_SUPPORTED */ 2026 }; 2027 break; 2028 2029 /* The TIFF Version 6.0 specification says that if the value of a TIFF 2030 "JPEGInterchangeFormat" record is 0, then we are to behave as if this 2031 record were absent; i.e., the data does *not* represent a JPEG Inter- 2032 change Format File (JFIF), so don't even set the boolean "I've been 2033 here" flag below. Otherwise, the field's value represents the file 2034 offset of the JPEG SOI marker. 2035 */ 2036 case TIFFTAG_JPEGIFOFFSET : 2037 if (v32) 2038 { 2039 sp->src.next_input_byte = tif->tif_base + v32; 2040 break; 2041 }; 2042 return 1; 2043 case TIFFTAG_JPEGIFBYTECOUNT : 2044 sp->src.bytes_in_buffer = v32; 2045 break; 2046 2047 /* The TIFF Version 6.0 specification says that if the JPEG "Restart" 2048 marker interval is 0, then the data has no "Restart" markers; i.e., we 2049 must behave as if this TIFF record were absent. So, don't even set the 2050 boolean "I've been here" flag below. 2051 */ 2052 /* 2053 * Instead, set the field bit so TIFFGetField can get whether or not 2054 * it was set. 2055 */ 2056 case TIFFTAG_JPEGRESTARTINTERVAL : 2057 if (v32) 2058 sp->cinfo.d.restart_interval = v32; 2059 break; 2060 /* The TIFF Version 6.0 specification says that this tag is supposed to be 2061 a vector containing a value for each image component, but for lossless 2062 Huffman coding (the only JPEG process defined by the specification for 2063 which this tag should be needed), ISO IS 10918-1 uses only a single 2064 value, equivalent to the "Ss" field in a JPEG bit-stream's "Start of 2065 Scan" (SOS) marker. So, we extract the first vector element and ignore 2066 the rest. (I hope this is correct!) 2067 */ 2068 case TIFFTAG_JPEGLOSSLESSPREDICTORS: 2069 if (v32) 2070 { 2071 sp->cinfo.d.Ss = *va_arg(ap,uint16 *); 2072 sp->jpeglosslesspredictors = 2073 _TIFFmalloc(sp->jpeglosslesspredictors_length 2074 * sizeof(uint16)); 2075 if(sp->jpeglosslesspredictors==NULL){return(0);} 2076 for(i2=0;i2<sp->jpeglosslesspredictors_length;i2++){ 2077 ((uint16*)sp->jpeglosslesspredictors)[i2] = 2078 ((uint16*)sp->cinfo.d.Ss)[i2]; 2079 } 2080 sp->jpeglosslesspredictors_length*=sizeof(uint16); 2081 break; 2082 }; 2083 return v32; 2084 2085 /* The TIFF Version 6.0 specification says that this tag is supposed to be 2086 a vector containing a value for each image component, but for lossless 2087 Huffman coding (the only JPEG process defined by the specification for 2088 which this tag should be needed), ISO IS 10918-1 uses only a single 2089 value, equivalent to the "Al" field in a JPEG bit-stream's "Start of 2090 Scan" (SOS) marker. So, we extract the first vector element and ignore 2091 the rest. (I hope this is correct!) 2092 */ 2093 case TIFFTAG_JPEGPOINTTRANSFORM : 2094 if (v32) 2095 { 2096 sp->cinfo.d.Al = *va_arg(ap,uint16 *); 2097 sp->jpegpointtransform = 2098 _TIFFmalloc(sp->jpegpointtransform_length*sizeof(uint16)); 2099 if(sp->jpegpointtransform==NULL){return(0);} 2100 for(i2=0;i2<sp->jpegpointtransform_length;i2++) { 2101 ((uint16*)sp->jpegpointtransform)[i2] = 2102 ((uint16*)sp->cinfo.d.Al)[i2]; 2103 } 2104 sp->jpegpointtransform_length*=sizeof(uint16); 2105 break; 2106 } 2107 return v32; 2108 2109 /* We have a vector of offsets to quantization tables, so load 'em! */ 2110 2111 case TIFFTAG_JPEGQTABLES : 2112 if (v32) 2113 { uint32 *v; 2114 int i; 2115 if (v32 > NUM_QUANT_TBLS) 2116 { 2117 TIFFError(tif->tif_name,"Too many quantization tables"); 2118 return 0; 2119 }; 2120 i = 0; 2121 v = va_arg(ap,uint32 *); 2122 sp->jpegqtables=_TIFFmalloc(64*sp->jpegqtables_length); 2123 if(sp->jpegqtables==NULL){return(0);} 2124 tiffoff = TIFFSeekFile(tif, 0, SEEK_CUR); 2125 bufoff=0; 2126 for(i2=0;i2<sp->jpegqtables_length;i2++){ 2127 TIFFSeekFile(tif, v[i2], SEEK_SET); 2128 TIFFReadFile(tif, &(((unsigned char*)(sp->jpegqtables))[bufoff]), 2129 64); 2130 bufoff+=64; 2131 } 2132 sp->jpegqtables_length=bufoff; 2133 TIFFSeekFile(tif, tiffoff, SEEK_SET); 2134 2135 do /* read quantization table */ 2136 { register UINT8 *from = tif->tif_base + *v++; 2137 register UINT16 *to; 2138 register int j = DCTSIZE2; 2139 2140 if (!( sp->cinfo.d.quant_tbl_ptrs[i] 2141 = CALLJPEG(sp,0,jpeg_alloc_quant_table(&sp->cinfo.comm)) 2142 ) 2143 ) 2144 { 2145 TIFFError(JPEGLib_name,"No space for quantization table"); 2146 return 0; 2147 }; 2148 to = sp->cinfo.d.quant_tbl_ptrs[i]->quantval; 2149 do *to++ = *from++; while (--j > 0); 2150 } 2151 while (++i < v32); 2152 sp->jpegtablesmode |= JPEGTABLESMODE_QUANT; 2153 }; 2154 break; 2155 2156 /* We have a vector of offsets to DC Huffman tables, so load 'em! */ 2157 2158 case TIFFTAG_JPEGDCTABLES : 2159 h = sp->cinfo.d.dc_huff_tbl_ptrs; 2160 goto L; 2161 2162 /* We have a vector of offsets to AC Huffman tables, so load 'em! */ 2163 2164 case TIFFTAG_JPEGACTABLES : 2165 h = sp->cinfo.d.ac_huff_tbl_ptrs; 2166 L: if (v32) 2167 { uint32 *v; 2168 int i; 2169 if (v32 > NUM_HUFF_TBLS) 2170 { 2171 TIFFError(tif->tif_name,"Too many Huffman tables"); 2172 return 0; 2173 }; 2174 v = va_arg(ap,uint32 *); 2175 if(tag == TIFFTAG_JPEGDCTABLES) { 2176 sp->jpegdctables=_TIFFmalloc(272*sp->jpegdctables_length); 2177 if(sp->jpegdctables==NULL){return(0);} 2178 tiffoff = TIFFSeekFile(tif, 0, SEEK_CUR); 2179 bufoff=0; 2180 code_count=0; 2181 for(i2=0;i2<sp->jpegdctables_length;i2++){ 2182 TIFFSeekFile(tif, v[i2], SEEK_SET); 2183 TIFFReadFile(tif, 2184 &(((unsigned char*)(sp->jpegdctables))[bufoff]), 2185 16); 2186 code_count=0; 2187 for(k2=0;k2<16;k2++){ 2188 code_count+=((unsigned char*)(sp->jpegdctables))[k2+bufoff]; 2189 } 2190 TIFFReadFile(tif, 2191 &(((unsigned char*)(sp->jpegdctables))[bufoff+16]), 2192 code_count); 2193 bufoff+=16; 2194 bufoff+=code_count; 2195 } 2196 sp->jpegdctables_length=bufoff; 2197 TIFFSeekFile(tif, tiffoff, SEEK_SET); 2198 } 2199 if(tag==TIFFTAG_JPEGACTABLES){ 2200 sp->jpegactables=_TIFFmalloc(272*sp->jpegactables_length); 2201 if(sp->jpegactables==NULL){return(0);} 2202 tiffoff = TIFFSeekFile(tif, 0, SEEK_CUR); 2203 bufoff=0; 2204 code_count=0; 2205 for(i2=0;i2<sp->jpegactables_length;i2++){ 2206 TIFFSeekFile(tif, v[i2], SEEK_SET); 2207 TIFFReadFile(tif, &(((unsigned char*)(sp->jpegactables))[bufoff]), 16); 2208 code_count=0; 2209 for(k2=0;k2<16;k2++){ 2210 code_count+=((unsigned char*)(sp->jpegactables))[k2+bufoff]; 2211 } 2212 TIFFReadFile(tif, &(((unsigned char*)(sp->jpegactables))[bufoff+16]), code_count); 2213 bufoff+=16; 2214 bufoff+=code_count; 2215 } 2216 sp->jpegactables_length=bufoff; 2217 TIFFSeekFile(tif, tiffoff, SEEK_SET); 2218 } 2219 i = 0; 2220 do /* copy each Huffman table */ 2221 { int size = 0; 2222 register UINT8 *from = tif->tif_base + *v++, *to; 2223 register int j = sizeof (*h)->bits; 2224 2225 /* WARNING: This code relies on the fact that an image file not 2226 "memory mapped" was read entirely into a single 2227 buffer by "TIFFInitOJPEG()", so we can do a fast memory-to- 2228 memory copy here. Each table consists of 16 Bytes, which are 2229 suffixed to a 0 Byte when copied, followed by a variable 2230 number of Bytes whose length is the sum of the first 16. 2231 */ 2232 if (!( *h 2233 = CALLJPEG(sp,0,jpeg_alloc_huff_table(&sp->cinfo.comm)) 2234 ) 2235 ) 2236 { 2237 TIFFError(JPEGLib_name,"No space for Huffman table"); 2238 return 0; 2239 }; 2240 to = (*h++)->bits; 2241 *to++ = 0; 2242 while (--j > 0) size += *to++ = *from++; /* Copy 16 Bytes */ 2243 if (size > sizeof (*h)->huffval/sizeof *(*h)->huffval) 2244 { 2245 TIFFError(tif->tif_name,"Huffman table too big"); 2246 return 0; 2247 }; 2248 if ((j = size) > 0) do *to++ = *from++; while (--j > 0); 2249 while (++size <= sizeof (*h)->huffval/sizeof *(*h)->huffval) 2250 *to++ = 0; /* Zero the rest of the table for cleanliness */ 2251 } 2252 while (++i < v32); 2253 sp->jpegtablesmode |= JPEGTABLESMODE_HUFF; 2254 }; 2255 break; 2256 2257 /* The following vendor-specific TIFF tag occurs in (highly illegal) files 2258 produced by the Wang Imaging application for Microsoft Windows. These 2259 can apparently have several "pages", in which case this tag specifies 2260 the offset of a "page control" structure, which we don't currently know 2261 how to handle. 0 indicates a 1-page image with no "page control", which 2262 we make a feeble effort to handle. 2263 */ 2264 case TIFFTAG_WANG_PAGECONTROL : 2265 if (v32 == 0) v32 = -1; 2266 sp->is_WANG = v32; 2267 tag = TIFFTAG_JPEGPROC+FIELD_WANG_PAGECONTROL-FIELD_JPEGPROC; 2268 break; 2269 2270 /* This pseudo tag indicates whether our caller is expected to do YCbCr <-> 2271 RGB color-space conversion (JPEGCOLORMODE_RAW <=> 0) or whether we must 2272 ask the JPEG Library to do it (JPEGCOLORMODE_RGB <=> 1). 2273 */ 2274 case TIFFTAG_JPEGCOLORMODE : 2275 sp->jpegcolormode = v32; 2276 2277 /* Mark the image to indicate whether returned data is up-sampled, so 2278 that "TIFF{Strip,Tile}Size()" reflect the true amount of data present. 2279 */ 2280 v32 = tif->tif_flags; /* Save flags temporarily */ 2281 tif->tif_flags &= ~TIFF_UPSAMPLED; 2282 if ( td->td_photometric == PHOTOMETRIC_YCBCR 2283 && (td->td_ycbcrsubsampling[0]<<3 | td->td_ycbcrsubsampling[1]) 2284 != 011 2285 && sp->jpegcolormode == JPEGCOLORMODE_RGB 2286 ) tif->tif_flags |= TIFF_UPSAMPLED; 2287 2288 /* If the up-sampling state changed, re-calculate tile size. */ 2289 2290 if ((tif->tif_flags ^ v32) & TIFF_UPSAMPLED) 2291 { 2292 tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tsize_t) -1; 2293 tif->tif_flags |= TIFF_DIRTYDIRECT; 2294 }; 2295 return 1; 2296 }; 2297 TIFFSetFieldBit(tif,tag-TIFFTAG_JPEGPROC+FIELD_JPEGPROC); 2298 return 1; 2299 # undef td 2300 } 2301 2302 static int 2303 OJPEGVGetField(register TIFF *tif,ttag_t tag,va_list ap) 2304 { register OJPEGState *sp = OJState(tif); 2305 2306 switch (tag) 2307 { 2308 2309 /* If this file has managed to synthesize a set of consolidated "metadata" 2310 tables for the current (post-TIFF Version 6.0 specification) JPEG-in- 2311 TIFF encapsulation strategy, then tell our caller about them; otherwise, 2312 keep mum. 2313 */ 2314 case TIFFTAG_JPEGTABLES : 2315 if (sp->jpegtables_length) /* we have "new"-style JPEG tables */ 2316 { 2317 *va_arg(ap,uint32 *) = sp->jpegtables_length; 2318 *va_arg(ap,char **) = sp->jpegtables; 2319 return 1; 2320 }; 2321 2322 /* This pseudo tag indicates whether our caller is expected to do YCbCr <-> 2323 RGB color-space conversion (JPEGCOLORMODE_RAW <=> 0) or whether we must 2324 ask the JPEG Library to do it (JPEGCOLORMODE_RGB <=> 1). 2325 */ 2326 case TIFFTAG_JPEGCOLORMODE : 2327 *va_arg(ap,uint32 *) = sp->jpegcolormode; 2328 return 1; 2329 2330 /* The following tags are defined by the TIFF Version 6.0 specification 2331 and are obsolete. If our caller asks for information about them, do not 2332 return anything, even if we parsed them in an old-format "source" image. 2333 */ 2334 case TIFFTAG_JPEGPROC : 2335 *va_arg(ap, uint16*)=sp->jpegproc; 2336 return(1); 2337 break; 2338 case TIFFTAG_JPEGIFOFFSET : 2339 *va_arg(ap, uint32*)=sp->jpegifoffset; 2340 return(1); 2341 break; 2342 case TIFFTAG_JPEGIFBYTECOUNT : 2343 *va_arg(ap, uint32*)=sp->jpegifbytecount; 2344 return(1); 2345 break; 2346 case TIFFTAG_JPEGRESTARTINTERVAL : 2347 *va_arg(ap, uint32*)=sp->jpegrestartinterval; 2348 return(1); 2349 break; 2350 case TIFFTAG_JPEGLOSSLESSPREDICTORS: 2351 *va_arg(ap, uint32*)=sp->jpeglosslesspredictors_length; 2352 *va_arg(ap, void**)=sp->jpeglosslesspredictors; 2353 return(1); 2354 break; 2355 case TIFFTAG_JPEGPOINTTRANSFORM : 2356 *va_arg(ap, uint32*)=sp->jpegpointtransform_length; 2357 *va_arg(ap, void**)=sp->jpegpointtransform; 2358 return(1); 2359 break; 2360 case TIFFTAG_JPEGQTABLES : 2361 *va_arg(ap, uint32*)=sp->jpegqtables_length; 2362 *va_arg(ap, void**)=sp->jpegqtables; 2363 return(1); 2364 break; 2365 case TIFFTAG_JPEGDCTABLES : 2366 *va_arg(ap, uint32*)=sp->jpegdctables_length; 2367 *va_arg(ap, void**)=sp->jpegdctables; 2368 return(1); 2369 break; 2370 case TIFFTAG_JPEGACTABLES : 2371 *va_arg(ap, uint32*)=sp->jpegactables_length; 2372 *va_arg(ap, void**)=sp->jpegactables; 2373 return(1); 2374 break; 2375 }; 2376 return (*sp->vgetparent)(tif,tag,ap); 2377 } 2378 2379 static void 2380 OJPEGPrintDir(register TIFF *tif,FILE *fd,long flags) 2381 { register OJPEGState *sp = OJState(tif); 2382 2383 if ( ( flags 2384 & (TIFFPRINT_JPEGQTABLES|TIFFPRINT_JPEGDCTABLES|TIFFPRINT_JPEGACTABLES) 2385 ) 2386 && sp->jpegtables_length 2387 ) 2388 fprintf(fd," JPEG Table Data: <present>, %lu bytes\n", 2389 sp->jpegtables_length); 2390 } 2391 2392 static uint32 2393 OJPEGDefaultStripSize(register TIFF *tif,register uint32 s) 2394 { register OJPEGState *sp = OJState(tif); 2395 # define td (&tif->tif_dir) 2396 2397 if ((s = (*sp->defsparent)(tif,s)) < td->td_imagelength) 2398 { register tsize_t size = sp->cinfo.comm.is_decompressor 2399 # ifdef D_LOSSLESS_SUPPORTED 2400 ? sp->cinfo.d.min_codec_data_unit 2401 # else 2402 ? DCTSIZE 2403 # endif 2404 # ifdef C_LOSSLESS_SUPPORTED 2405 : sp->cinfo.c.data_unit; 2406 # else 2407 : DCTSIZE; 2408 # endif 2409 2410 size = TIFFroundup(size,16); 2411 s = TIFFroundup(s,td->td_ycbcrsubsampling[1]*size); 2412 }; 2413 return s; 2414 # undef td 2415 } 2416 2417 static void 2418 OJPEGDefaultTileSize(register TIFF *tif,register uint32 *tw,register uint32 *th) 2419 { register OJPEGState *sp = OJState(tif); 2420 register tsize_t size; 2421 # define td (&tif->tif_dir) 2422 2423 size = sp->cinfo.comm.is_decompressor 2424 # ifdef D_LOSSLESS_SUPPORTED 2425 ? sp->cinfo.d.min_codec_data_unit 2426 # else 2427 ? DCTSIZE 2428 # endif 2429 # ifdef C_LOSSLESS_SUPPORTED 2430 : sp->cinfo.c.data_unit; 2431 # else 2432 : DCTSIZE; 2433 # endif 2434 size = TIFFroundup(size,16); 2435 (*sp->deftparent)(tif,tw,th); 2436 *tw = TIFFroundup(*tw,td->td_ycbcrsubsampling[0]*size); 2437 *th = TIFFroundup(*th,td->td_ycbcrsubsampling[1]*size); 2438 # undef td 2439 } 2440 2441 static void 2442 OJPEGCleanUp(register TIFF *tif) 2443 { register OJPEGState *sp; 2444 2445 if ( (sp = OJState(tif)) ) 2446 { 2447 CALLVJPEG(sp,jpeg_destroy(&sp->cinfo.comm)); /* Free JPEG Lib. vars. */ 2448 if (sp->jpegtables) {_TIFFfree(sp->jpegtables);sp->jpegtables=0;} 2449 if (sp->jpeglosslesspredictors) { 2450 _TIFFfree(sp->jpeglosslesspredictors); 2451 sp->jpeglosslesspredictors = 0; 2452 } 2453 if (sp->jpegpointtransform) { 2454 _TIFFfree(sp->jpegpointtransform); 2455 sp->jpegpointtransform=0; 2456 } 2457 if (sp->jpegqtables) {_TIFFfree(sp->jpegqtables);sp->jpegqtables=0;} 2458 if (sp->jpegactables) {_TIFFfree(sp->jpegactables);sp->jpegactables=0;} 2459 if (sp->jpegdctables) {_TIFFfree(sp->jpegdctables);sp->jpegdctables=0;} 2460 /* If the image file isn't "memory mapped" and we read it all into a 2461 single, large memory buffer, free the buffer now. 2462 */ 2463 if (!isMapped(tif) && tif->tif_base) /* free whole-file buffer */ 2464 { 2465 _TIFFfree(tif->tif_base); 2466 tif->tif_base = 0; 2467 tif->tif_size = 0; 2468 }; 2469 _TIFFfree(sp); /* Release local variables */ 2470 tif->tif_data = 0; 2471 } 2472 } 2473 2474 int 2475 TIFFInitOJPEG(register TIFF *tif,int scheme) 2476 { register OJPEGState *sp; 2477 # define td (&tif->tif_dir) 2478 # ifndef never 2479 2480 /* This module supports a decompression-only CODEC, which is intended strictly 2481 for viewing old image files using the obsolete JPEG-in-TIFF encapsulation 2482 specified by the TIFF Version 6.0 specification. It does not, and never 2483 should, support compression for new images. If a client application asks us 2484 to, refuse and complain loudly! 2485 */ 2486 if (tif->tif_mode != O_RDONLY) return _notSupported(tif); 2487 # endif /* never */ 2488 if (!isMapped(tif)) 2489 { 2490 2491 /* BEWARE OF KLUDGE: If our host operating-system doesn't let an image 2492 file be "memory mapped", then we want to read the 2493 entire file into a single (possibly large) memory buffer as if it had 2494 been "memory mapped". Although this is likely to waste space, because 2495 analysis of the file's content might cause parts of it to be read into 2496 smaller buffers duplicatively, it appears to be the lesser of several 2497 evils. Very old JPEG-in-TIFF encapsulations aren't guaranteed to be 2498 JFIF bit streams, or to have a TIFF "JPEGTables" record or much other 2499 "metadata" to help us locate the decoding tables and entropy-coded data, 2500 so we're likely do a lot of random-access grokking around, and we must 2501 ultimately tell the JPEG Library to sequentially scan much of the file 2502 anyway. This is all likely to be easier if we use "brute force" to 2503 read the entire file, once, and don't use incremental disc I/O. If our 2504 client application tries to process a file so big that we can't buffer 2505 it entirely, then tough shit: we'll give up and exit! 2506 */ 2507 if (!(tif->tif_base = _TIFFmalloc(tif->tif_size=TIFFGetFileSize(tif)))) 2508 { 2509 TIFFError(tif->tif_name,"Cannot allocate file buffer"); 2510 return 0; 2511 }; 2512 if (!SeekOK(tif,0) || !ReadOK(tif,tif->tif_base,tif->tif_size)) 2513 { 2514 TIFFError(tif->tif_name,"Cannot read file"); 2515 return 0; 2516 } 2517 }; 2518 2519 /* Allocate storage for this module's per-file variables. */ 2520 2521 if (!(tif->tif_data = (tidata_t)_TIFFmalloc(sizeof *sp))) 2522 { 2523 TIFFError("TIFFInitOJPEG","No space for JPEG state block"); 2524 return 0; 2525 }; 2526 (sp = OJState(tif))->tif = tif; /* Initialize reverse pointer */ 2527 sp->cinfo.d.err = jpeg_std_error(&sp->err); /* Initialize error handling */ 2528 sp->err.error_exit = TIFFojpeg_error_exit; 2529 sp->err.output_message = TIFFojpeg_output_message; 2530 if (!CALLVJPEG(sp,jpeg_create_decompress(&sp->cinfo.d))) return 0; 2531 2532 /* Install CODEC-specific tag information and override default TIFF Library 2533 "method" subroutines with our own, CODEC-specific methods. Like all good 2534 members of an object-class, we save some of these subroutine pointers for 2535 "fall back" in case our own methods fail. 2536 */ 2537 _TIFFMergeFieldInfo(tif,ojpegFieldInfo, 2538 sizeof ojpegFieldInfo/sizeof *ojpegFieldInfo); 2539 sp->defsparent = tif->tif_defstripsize; 2540 sp->deftparent = tif->tif_deftilesize; 2541 sp->vgetparent = tif->tif_tagmethods.vgetfield; 2542 sp->vsetparent = tif->tif_tagmethods.vsetfield; 2543 tif->tif_defstripsize = OJPEGDefaultStripSize; 2544 tif->tif_deftilesize = OJPEGDefaultTileSize; 2545 tif->tif_tagmethods.vgetfield = OJPEGVGetField; 2546 tif->tif_tagmethods.vsetfield = OJPEGVSetField; 2547 tif->tif_tagmethods.printdir = OJPEGPrintDir; 2548 # ifdef never 2549 tif->tif_setupencode = OJPEGSetupEncode; 2550 tif->tif_preencode = OJPEGPreEncode; 2551 tif->tif_postencode = OJPEGPostEncode; 2552 # else /* well, hardly ever */ 2553 tif->tif_setupencode = tif->tif_postencode = _notSupported; 2554 tif->tif_preencode = (TIFFPreMethod)_notSupported; 2555 # endif /* never */ 2556 tif->tif_setupdecode = OJPEGSetupDecode; 2557 tif->tif_predecode = OJPEGPreDecode; 2558 tif->tif_postdecode = OJPEGPostDecode; 2559 tif->tif_cleanup = OJPEGCleanUp; 2560 2561 /* If the image file doesn't have "JPEGInterchangeFormat[Length]" TIFF records 2562 to guide us, we have few clues about where its encapsulated JPEG bit stream 2563 is located, so establish intelligent defaults: If the Image File Directory 2564 doesn't immediately follow the TIFF header, assume that the JPEG data lies 2565 in between; otherwise, assume that it follows the Image File Directory. 2566 */ 2567 if (tif->tif_header.tiff_diroff > sizeof tif->tif_header) 2568 { 2569 sp->src.next_input_byte = tif->tif_base + sizeof tif->tif_header; 2570 sp->src.bytes_in_buffer = tif->tif_header.tiff_diroff 2571 - sizeof tif->tif_header; 2572 } 2573 else /* this case is ugly! */ 2574 { uint32 maxoffset = tif->tif_size; 2575 uint16 dircount; 2576 2577 /* Calculate the offset to the next Image File Directory, if there is one, 2578 or to the end of the file, if not. Then arrange to read the file from 2579 the end of the Image File Directory to that offset. 2580 */ 2581 if (tif->tif_nextdiroff) maxoffset = tif->tif_nextdiroff; /* Not EOF */ 2582 _TIFFmemcpy(&dircount,(const tdata_t) 2583 (sp->src.next_input_byte = tif->tif_base+tif->tif_header.tiff_diroff), 2584 sizeof dircount); 2585 if (tif->tif_flags & TIFF_SWAB) TIFFSwabShort(&dircount); 2586 sp->src.next_input_byte += dircount*sizeof(TIFFDirEntry) 2587 + sizeof maxoffset + sizeof dircount; 2588 sp->src.bytes_in_buffer = tif->tif_base - sp->src.next_input_byte 2589 + maxoffset; 2590 }; 2591 2592 /* IJG JPEG Library Version 6B can be configured for either 8- or 12-bit sample 2593 precision, but we assume that "old JPEG" TIFF clients only need 8 bits. 2594 */ 2595 sp->cinfo.d.data_precision = 8; 2596 # ifdef C_LOSSLESS_SUPPORTED 2597 2598 /* If the "JPEGProc" TIFF tag is missing from the Image File Dictionary, the 2599 JPEG Library will use its (lossy) baseline sequential process by default. 2600 */ 2601 sp->cinfo.d.data_unit = DCTSIZE; 2602 # endif /* C_LOSSLESS_SUPPORTED */ 2603 2604 /* Initialize other CODEC-specific variables requiring default values. */ 2605 2606 tif->tif_flags |= TIFF_NOBITREV; /* No bit-reversal within data bytes */ 2607 sp->h_sampling = sp->v_sampling = 1; /* No subsampling by default */ 2608 sp->is_WANG = 0; /* Assume not a MS Windows Wang Imaging file by default */ 2609 sp->jpegtables = 0; /* No "new"-style JPEG tables synthesized yet */ 2610 sp->jpegtables_length = 0; 2611 sp->jpegquality = 75; /* Default IJG quality */ 2612 sp->jpegcolormode = JPEGCOLORMODE_RAW; 2613 sp->jpegtablesmode = 0; /* No tables found yet */ 2614 sp->jpeglosslesspredictors=0; 2615 sp->jpeglosslesspredictors_length=0; 2616 sp->jpegpointtransform=0; 2617 sp->jpegpointtransform_length=0; 2618 sp->jpegqtables=0; 2619 sp->jpegqtables_length=0; 2620 sp->jpegdctables=0; 2621 sp->jpegdctables_length=0; 2622 sp->jpegactables=0; 2623 sp->jpegactables_length=0; 2624 return 1; 2625 # undef td 2626 } 2627 #endif /* OJPEG_SUPPORT */ 2628 2629 /* vim: set ts=8 sts=8 sw=8 noet: */ 2420 OJPEGLibjpegJpegSourceMgrTermSource(jpeg_decompress_struct* cinfo) 2421 { 2422 (void)cinfo; 2423 } 2424 2425 #endif 2426 2427 -
trunk/src/3rdparty/libtiff/libtiff/tif_open.c
r2 r846 1 /* $Id: tif_open.c,v 1.3 1 2006/03/16 12:23:02dron Exp $ */1 /* $Id: tif_open.c,v 1.33 2006/06/08 14:27:17 dron Exp $ */ 2 2 3 3 /* … … 199 199 tif->tif_flags = FILLORDER_MSB2LSB; 200 200 if (m == O_RDONLY ) 201 201 tif->tif_flags |= TIFF_MAPPED; 202 202 203 203 #ifdef STRIPCHOP_DEFAULT … … 308 308 !ReadOK(tif, &tif->tif_header, sizeof (TIFFHeader))) { 309 309 if (tif->tif_mode == O_RDONLY) { 310 TIFFErrorExt(tif->tif_clientdata, name, "Cannot read TIFF header"); 310 TIFFErrorExt(tif->tif_clientdata, name, 311 "Cannot read TIFF header"); 311 312 goto bad; 312 313 } … … 337 338 338 339 if (!WriteOK(tif, &tif->tif_header, sizeof (TIFFHeader))) { 339 TIFFErrorExt(tif->tif_clientdata, name, "Error writing TIFF header"); 340 TIFFErrorExt(tif->tif_clientdata, name, 341 "Error writing TIFF header"); 340 342 goto bad; 341 343 } … … 351 353 tif->tif_diroff = 0; 352 354 tif->tif_dirlist = NULL; 355 tif->tif_dirlistsize = 0; 353 356 tif->tif_dirnumber = 0; 354 357 return (tif); … … 367 370 #endif 368 371 ) { 369 TIFFErrorExt(tif->tif_clientdata, name, "Not a TIFF or MDI file, bad magic number %d (0x%x)", 372 TIFFErrorExt(tif->tif_clientdata, name, 373 "Not a TIFF or MDI file, bad magic number %d (0x%x)", 370 374 #else 371 375 ) { 372 TIFFErrorExt(tif->tif_clientdata, name, "Not a TIFF file, bad magic number %d (0x%x)", 376 TIFFErrorExt(tif->tif_clientdata, name, 377 "Not a TIFF file, bad magic number %d (0x%x)", 373 378 #endif 374 379 tif->tif_header.tiff_magic, … … 399 404 "Not a TIFF file, bad version number %d (0x%x)", 400 405 tif->tif_header.tiff_version, 401 tif->tif_header.tiff_version); 406 tif->tif_header.tiff_version); 402 407 goto bad; 403 408 } -
trunk/src/3rdparty/libtiff/libtiff/tif_packbits.c
r2 r846 1 /* $Id: tif_packbits.c,v 1.13 2006/02/07 11:03:29 dron Exp $ */1 /* $Id: tif_packbits.c,v 1.13.2.1 2009-01-01 00:10:43 bfriesen Exp $ */ 2 2 3 3 /* … … 241 241 { 242 242 TIFFWarningExt(tif->tif_clientdata, tif->tif_name, 243 "PackBitsDecode: discarding % d bytes "243 "PackBitsDecode: discarding %ld bytes " 244 244 "to avoid buffer overrun", 245 245 n - occ); … … 254 254 { 255 255 TIFFWarningExt(tif->tif_clientdata, tif->tif_name, 256 "PackBitsDecode: discarding % d bytes "256 "PackBitsDecode: discarding %ld bytes " 257 257 "to avoid buffer overrun", 258 258 n - occ + 1); -
trunk/src/3rdparty/libtiff/libtiff/tif_pixarlog.c
r2 r846 1 /* $Id: tif_pixarlog.c,v 1.1 4 2006/03/16 12:38:24 dron Exp $ */1 /* $Id: tif_pixarlog.c,v 1.15.2.3 2009-01-01 00:10:43 bfriesen Exp $ */ 2 2 3 3 /* … … 328 328 REPEAT(stride, 329 329 wp[stride] += *wp; *op = *wp&mask; wp++; op++) 330 330 n -= stride; 331 331 } 332 332 } … … 594 594 static int PixarLogDecode(TIFF*, tidata_t, tsize_t, tsample_t); 595 595 596 #define N(a) (sizeof(a)/sizeof(a[0]))597 596 #define PIXARLOGDATAFMT_UNKNOWN -1 598 597 … … 768 767 if (tif->tif_flags & TIFF_SWAB) 769 768 TIFFSwabArrayOfShort(up, nsamples); 769 770 /* 771 * if llen is not an exact multiple of nsamples, the decode operation 772 * may overflow the output buffer, so truncate it enough to prevent 773 * that but still salvage as much data as possible. 774 */ 775 if (nsamples % llen) { 776 TIFFWarningExt(tif->tif_clientdata, module, 777 "%s: stride %d is not a multiple of sample count, " 778 "%d, data truncated.", tif->tif_name, llen, nsamples); 779 nsamples -= nsamples % llen; 780 } 770 781 771 782 for (i = 0; i < nsamples; i += llen, up += llen) { … … 1037 1048 PixarLogState *sp = EncoderState(tif); 1038 1049 static const char module[] = "PixarLogEncode"; 1039 int 1050 int i, n, llen; 1040 1051 unsigned short * up; 1041 1052 … … 1279 1290 TIFFInitPixarLog(TIFF* tif, int scheme) 1280 1291 { 1292 static const char module[] = "TIFFInitPixarLog"; 1293 1281 1294 PixarLogState* sp; 1282 1295 1283 1296 assert(scheme == COMPRESSION_PIXARLOG); 1297 1298 /* 1299 * Merge codec-specific tag information. 1300 */ 1301 if (!_TIFFMergeFieldInfo(tif, pixarlogFieldInfo, 1302 TIFFArrayCount(pixarlogFieldInfo))) { 1303 TIFFErrorExt(tif->tif_clientdata, module, 1304 "Merging PixarLog codec-specific tags failed"); 1305 return 0; 1306 } 1284 1307 1285 1308 /* … … 1312 1335 1313 1336 /* Override SetField so we can handle our private pseudo-tag */ 1314 _TIFFMergeFieldInfo(tif, pixarlogFieldInfo, N(pixarlogFieldInfo));1315 1337 sp->vgetparent = tif->tif_tagmethods.vgetfield; 1316 1338 tif->tif_tagmethods.vgetfield = PixarLogVGetField; /* hook for codec tags */ … … 1334 1356 return (1); 1335 1357 bad: 1336 TIFFErrorExt(tif->tif_clientdata, "TIFFInitPixarLog",1358 TIFFErrorExt(tif->tif_clientdata, module, 1337 1359 "No space for PixarLog state block"); 1338 1360 return (0); -
trunk/src/3rdparty/libtiff/libtiff/tif_predict.c
r2 r846 1 /* $Id: tif_predict.c,v 1.11 2006/03/03 14:10:09 dronExp $ */1 /* $Id: tif_predict.c,v 1.11.2.3 2009-01-23 15:57:18 fwarmerdam Exp $ */ 2 2 3 3 /* … … 37 37 static void horAcc8(TIFF*, tidata_t, tsize_t); 38 38 static void horAcc16(TIFF*, tidata_t, tsize_t); 39 static void horAcc32(TIFF*, tidata_t, tsize_t); 39 40 static void swabHorAcc16(TIFF*, tidata_t, tsize_t); 41 static void swabHorAcc32(TIFF*, tidata_t, tsize_t); 40 42 static void horDiff8(TIFF*, tidata_t, tsize_t); 41 43 static void horDiff16(TIFF*, tidata_t, tsize_t); 44 static void horDiff32(TIFF*, tidata_t, tsize_t); 42 45 static void fpAcc(TIFF*, tidata_t, tsize_t); 43 46 static void fpDiff(TIFF*, tidata_t, tsize_t); … … 61 64 case PREDICTOR_HORIZONTAL: 62 65 if (td->td_bitspersample != 8 63 && td->td_bitspersample != 16) { 66 && td->td_bitspersample != 16 67 && td->td_bitspersample != 32) { 64 68 TIFFErrorExt(tif->tif_clientdata, module, 65 69 "Horizontal differencing \"Predictor\" not supported with %d-bit samples", … … 106 110 if (sp->predictor == 2) { 107 111 switch (td->td_bitspersample) { 108 case 8: sp->pfunc = horAcc8; break; 109 case 16: sp->pfunc = horAcc16; break; 112 case 8: sp->decodepfunc = horAcc8; break; 113 case 16: sp->decodepfunc = horAcc16; break; 114 case 32: sp->decodepfunc = horAcc32; break; 110 115 } 111 116 /* … … 113 118 * predictor stuff. 114 119 */ 115 sp->coderow = tif->tif_decoderow; 116 tif->tif_decoderow = PredictorDecodeRow; 117 sp->codestrip = tif->tif_decodestrip; 118 tif->tif_decodestrip = PredictorDecodeTile; 119 sp->codetile = tif->tif_decodetile; 120 tif->tif_decodetile = PredictorDecodeTile; 120 if( tif->tif_decoderow != PredictorDecodeRow ) 121 { 122 sp->decoderow = tif->tif_decoderow; 123 tif->tif_decoderow = PredictorDecodeRow; 124 sp->decodestrip = tif->tif_decodestrip; 125 tif->tif_decodestrip = PredictorDecodeTile; 126 sp->decodetile = tif->tif_decodetile; 127 tif->tif_decodetile = PredictorDecodeTile; 128 } 121 129 /* 122 130 * If the data is horizontally differenced 16-bit data that … … 127 135 */ 128 136 if (tif->tif_flags & TIFF_SWAB) { 129 if (sp-> pfunc == horAcc16) {130 sp-> pfunc = swabHorAcc16;137 if (sp->decodepfunc == horAcc16) { 138 sp->decodepfunc = swabHorAcc16; 131 139 tif->tif_postdecode = _TIFFNoPostDecode; 132 } /* else handle 32-bit case... */ 140 } else if (sp->decodepfunc == horAcc32) { 141 sp->decodepfunc = swabHorAcc32; 142 tif->tif_postdecode = _TIFFNoPostDecode; 143 } 133 144 } 134 145 } 135 146 136 147 else if (sp->predictor == 3) { 137 sp-> pfunc = fpAcc;148 sp->decodepfunc = fpAcc; 138 149 /* 139 150 * Override default decoding method with one that does the 140 151 * predictor stuff. 141 152 */ 142 sp->coderow = tif->tif_decoderow; 143 tif->tif_decoderow = PredictorDecodeRow; 144 sp->codestrip = tif->tif_decodestrip; 145 tif->tif_decodestrip = PredictorDecodeTile; 146 sp->codetile = tif->tif_decodetile; 147 tif->tif_decodetile = PredictorDecodeTile; 153 if( tif->tif_decoderow != PredictorDecodeRow ) 154 { 155 sp->decoderow = tif->tif_decoderow; 156 tif->tif_decoderow = PredictorDecodeRow; 157 sp->decodestrip = tif->tif_decodestrip; 158 tif->tif_decodestrip = PredictorDecodeTile; 159 sp->decodetile = tif->tif_decodetile; 160 tif->tif_decodetile = PredictorDecodeTile; 161 } 148 162 /* 149 163 * The data should not be swapped outside of the floating … … 174 188 if (sp->predictor == 2) { 175 189 switch (td->td_bitspersample) { 176 case 8: sp->pfunc = horDiff8; break; 177 case 16: sp->pfunc = horDiff16; break; 190 case 8: sp->encodepfunc = horDiff8; break; 191 case 16: sp->encodepfunc = horDiff16; break; 192 case 32: sp->encodepfunc = horDiff32; break; 178 193 } 179 194 /* … … 181 196 * predictor stuff. 182 197 */ 183 sp->coderow = tif->tif_encoderow; 184 tif->tif_encoderow = PredictorEncodeRow; 185 sp->codestrip = tif->tif_encodestrip; 186 tif->tif_encodestrip = PredictorEncodeTile; 187 sp->codetile = tif->tif_encodetile; 188 tif->tif_encodetile = PredictorEncodeTile; 198 if( tif->tif_encoderow != PredictorEncodeRow ) 199 { 200 sp->encoderow = tif->tif_encoderow; 201 tif->tif_encoderow = PredictorEncodeRow; 202 sp->encodestrip = tif->tif_encodestrip; 203 tif->tif_encodestrip = PredictorEncodeTile; 204 sp->encodetile = tif->tif_encodetile; 205 tif->tif_encodetile = PredictorEncodeTile; 206 } 189 207 } 190 208 191 209 else if (sp->predictor == 3) { 192 sp-> pfunc = fpDiff;210 sp->encodepfunc = fpDiff; 193 211 /* 194 212 * Override default encoding method with one that does the 195 213 * predictor stuff. 196 214 */ 197 sp->coderow = tif->tif_encoderow; 198 tif->tif_encoderow = PredictorEncodeRow; 199 sp->codestrip = tif->tif_encodestrip; 200 tif->tif_encodestrip = PredictorEncodeTile; 201 sp->codetile = tif->tif_encodetile; 202 tif->tif_encodetile = PredictorEncodeTile; 215 if( tif->tif_encoderow != PredictorEncodeRow ) 216 { 217 sp->encoderow = tif->tif_encoderow; 218 tif->tif_encoderow = PredictorEncodeRow; 219 sp->encodestrip = tif->tif_encodestrip; 220 tif->tif_encodestrip = PredictorEncodeTile; 221 sp->encodetile = tif->tif_encodetile; 222 tif->tif_encodetile = PredictorEncodeTile; 223 } 203 224 } 204 225 … … 292 313 } 293 314 315 static void 316 swabHorAcc32(TIFF* tif, tidata_t cp0, tsize_t cc) 317 { 318 tsize_t stride = PredictorState(tif)->stride; 319 uint32* wp = (uint32*) cp0; 320 tsize_t wc = cc / 4; 321 322 if (wc > stride) { 323 TIFFSwabArrayOfLong(wp, wc); 324 wc -= stride; 325 do { 326 REPEAT4(stride, wp[stride] += wp[0]; wp++) 327 wc -= stride; 328 } while ((int32) wc > 0); 329 } 330 } 331 332 static void 333 horAcc32(TIFF* tif, tidata_t cp0, tsize_t cc) 334 { 335 tsize_t stride = PredictorState(tif)->stride; 336 uint32* wp = (uint32*) cp0; 337 tsize_t wc = cc / 4; 338 339 if (wc > stride) { 340 wc -= stride; 341 do { 342 REPEAT4(stride, wp[stride] += wp[0]; wp++) 343 wc -= stride; 344 } while ((int32) wc > 0); 345 } 346 } 347 294 348 /* 295 349 * Floating point predictor accumulation routine. … … 338 392 339 393 assert(sp != NULL); 340 assert(sp-> coderow != NULL);341 assert(sp-> pfunc != NULL);342 343 if ((*sp-> coderow)(tif, op0, occ0, s)) {344 (*sp-> pfunc)(tif, op0, occ0);394 assert(sp->decoderow != NULL); 395 assert(sp->decodepfunc != NULL); 396 397 if ((*sp->decoderow)(tif, op0, occ0, s)) { 398 (*sp->decodepfunc)(tif, op0, occ0); 345 399 return 1; 346 400 } else … … 361 415 362 416 assert(sp != NULL); 363 assert(sp-> codetile != NULL);364 365 if ((*sp-> codetile)(tif, op0, occ0, s)) {417 assert(sp->decodetile != NULL); 418 419 if ((*sp->decodetile)(tif, op0, occ0, s)) { 366 420 tsize_t rowsize = sp->rowsize; 367 421 assert(rowsize > 0); 368 assert(sp-> pfunc != NULL);422 assert(sp->decodepfunc != NULL); 369 423 while ((long)occ0 > 0) { 370 (*sp-> pfunc)(tif, op0, (tsize_t) rowsize);424 (*sp->decodepfunc)(tif, op0, (tsize_t) rowsize); 371 425 occ0 -= rowsize; 372 426 op0 += rowsize; … … 440 494 } 441 495 496 static void 497 horDiff32(TIFF* tif, tidata_t cp0, tsize_t cc) 498 { 499 TIFFPredictorState* sp = PredictorState(tif); 500 tsize_t stride = sp->stride; 501 int32 *wp = (int32*) cp0; 502 tsize_t wc = cc/4; 503 504 if (wc > stride) { 505 wc -= stride; 506 wp += wc - 1; 507 do { 508 REPEAT4(stride, wp[stride] -= wp[0]; wp--) 509 wc -= stride; 510 } while ((int32) wc > 0); 511 } 512 } 513 442 514 /* 443 515 * Floating point predictor differencing routine. … … 482 554 483 555 assert(sp != NULL); 484 assert(sp-> pfunc != NULL);485 assert(sp-> coderow != NULL);556 assert(sp->encodepfunc != NULL); 557 assert(sp->encoderow != NULL); 486 558 487 559 /* XXX horizontal differencing alters user's data XXX */ 488 (*sp-> pfunc)(tif, bp, cc);489 return (*sp-> coderow)(tif, bp, cc, s);560 (*sp->encodepfunc)(tif, bp, cc); 561 return (*sp->encoderow)(tif, bp, cc, s); 490 562 } 491 563 … … 493 565 PredictorEncodeTile(TIFF* tif, tidata_t bp0, tsize_t cc0, tsample_t s) 494 566 { 567 static const char module[] = "PredictorEncodeTile"; 495 568 TIFFPredictorState *sp = PredictorState(tif); 569 uint8 *working_copy; 496 570 tsize_t cc = cc0, rowsize; 497 unsigned char* bp = bp0; 571 unsigned char* bp; 572 int result_code; 498 573 499 574 assert(sp != NULL); 500 assert(sp->pfunc != NULL); 501 assert(sp->codetile != NULL); 575 assert(sp->encodepfunc != NULL); 576 assert(sp->encodetile != NULL); 577 578 /* 579 * Do predictor manipulation in a working buffer to avoid altering 580 * the callers buffer. http://trac.osgeo.org/gdal/ticket/1965 581 */ 582 working_copy = (uint8*) _TIFFmalloc(cc0); 583 if( working_copy == NULL ) 584 { 585 TIFFErrorExt(tif->tif_clientdata, module, 586 "Out of memory allocating %d byte temp buffer.", 587 cc0 ); 588 return 0; 589 } 590 memcpy( working_copy, bp0, cc0 ); 591 bp = working_copy; 502 592 503 593 rowsize = sp->rowsize; 504 594 assert(rowsize > 0); 505 while ((long)cc > 0) { 506 (*sp->pfunc)(tif, bp, (tsize_t) rowsize); 595 assert((cc0%rowsize)==0); 596 while (cc > 0) { 597 (*sp->encodepfunc)(tif, bp, rowsize); 507 598 cc -= rowsize; 508 599 bp += rowsize; 509 600 } 510 return (*sp->codetile)(tif, bp0, cc0, s); 601 result_code = (*sp->encodetile)(tif, working_copy, cc0, s); 602 603 _TIFFfree( working_copy ); 604 605 return result_code; 511 606 } 512 607 … … 517 612 FALSE, FALSE, "Predictor" }, 518 613 }; 519 #define N(a) (sizeof (a) / sizeof (a[0]))520 614 521 615 static int … … 584 678 585 679 /* 586 * Merge codec-specific tag information and 587 * override parent get/set field methods. 680 * Merge codec-specific tag information. 588 681 */ 589 _TIFFMergeFieldInfo(tif, predictFieldInfo, N(predictFieldInfo)); 682 if (!_TIFFMergeFieldInfo(tif, predictFieldInfo, 683 TIFFArrayCount(predictFieldInfo))) { 684 TIFFErrorExt(tif->tif_clientdata, "TIFFPredictorInit", 685 "Merging Predictor codec-specific tags failed"); 686 return 0; 687 } 688 689 /* 690 * Override parent get/set field methods. 691 */ 590 692 sp->vgetparent = tif->tif_tagmethods.vgetfield; 591 693 tif->tif_tagmethods.vgetfield = … … 604 706 605 707 sp->predictor = 1; /* default value */ 606 sp->pfunc = NULL; /* no predictor routine */ 708 sp->encodepfunc = NULL; /* no predictor routine */ 709 sp->decodepfunc = NULL; /* no predictor routine */ 607 710 return 1; 608 711 } -
trunk/src/3rdparty/libtiff/libtiff/tif_predict.h
r2 r846 1 /* $Id: tif_predict.h,v 1.3 2006/03/03 14:10:09 dronExp $ */1 /* $Id: tif_predict.h,v 1.3.2.1 2007/11/22 21:24:51 fwarmerdam Exp $ */ 2 2 3 3 /* … … 41 41 tsize_t rowsize; /* tile/strip row size */ 42 42 43 TIFFPostMethod pfunc; /* horizontal differencer/accumulator */ 44 TIFFCodeMethod coderow; /* parent codec encode/decode row */ 45 TIFFCodeMethod codestrip; /* parent codec encode/decode strip */ 46 TIFFCodeMethod codetile; /* parent codec encode/decode tile */ 43 TIFFCodeMethod encoderow; /* parent codec encode/decode row */ 44 TIFFCodeMethod encodestrip; /* parent codec encode/decode strip */ 45 TIFFCodeMethod encodetile; /* parent codec encode/decode tile */ 46 TIFFPostMethod encodepfunc; /* horizontal differencer */ 47 48 TIFFCodeMethod decoderow; /* parent codec encode/decode row */ 49 TIFFCodeMethod decodestrip; /* parent codec encode/decode strip */ 50 TIFFCodeMethod decodetile; /* parent codec encode/decode tile */ 51 TIFFPostMethod decodepfunc; /* horizontal accumulator */ 52 47 53 TIFFVGetMethod vgetparent; /* super-class method */ 48 54 TIFFVSetMethod vsetparent; /* super-class method */ -
trunk/src/3rdparty/libtiff/libtiff/tif_print.c
r2 r846 1 /* $Id: tif_print.c,v 1.3 5 2006/03/13 07:53:28 dron Exp $ */1 /* $Id: tif_print.c,v 1.36.2.2 2009-09-17 18:00:28 bfriesen Exp $ */ 2 2 3 3 /* … … 32 32 #include "tiffiop.h" 33 33 #include <stdio.h> 34 34 #include <string.h> 35 35 #include <ctype.h> 36 36 … … 492 492 fprintf(fd, "(present)\n"); 493 493 } 494 if (TIFFFieldSet(tif, FIELD_SUBIFD) ) {494 if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd)) { 495 495 fprintf(fd, " SubIFD Offsets:"); 496 496 for (i = 0; i < td->td_nsubifd; i++) … … 510 510 ttag_t tag = TIFFGetTagListEntry(tif, i); 511 511 const TIFFFieldInfo *fip; 512 uint 16value_count;512 uint32 value_count; 513 513 int mem_alloc = 0; 514 514 void *raw_data; -
trunk/src/3rdparty/libtiff/libtiff/tif_read.c
r2 r846 1 /* $Id: tif_read.c,v 1.1 3 2005/12/21 12:23:13 jorisExp $ */1 /* $Id: tif_read.c,v 1.16 2007/02/22 11:33:44 dron Exp $ */ 2 2 3 3 /* … … 51 51 52 52 if (row >= td->td_imagelength) { /* out of range */ 53 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%lu: Row out of range, max %lu", 54 (unsigned long) row, (unsigned long) td->td_imagelength); 53 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 54 "%lu: Row out of range, max %lu", 55 (unsigned long) row, 56 (unsigned long) td->td_imagelength); 55 57 return (0); 56 58 } … … 65 67 } else 66 68 strip = row / td->td_rowsperstrip; 67 if (strip != tif->tif_curstrip) { 69 if (strip != tif->tif_curstrip) { /* different strip, refill */ 68 70 if (!TIFFFillStrip(tif, strip)) 69 71 return (0); … … 105 107 (tif, (tidata_t) buf, tif->tif_scanlinesize, sample); 106 108 107 108 109 /* we are now poised at the beginning of the next row */ 110 tif->tif_row = row + 1; 109 111 110 112 if (e) … … 130 132 return (-1); 131 133 if (strip >= td->td_nstrips) { 132 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%ld: Strip out of range, max %ld", 133 (long) strip, (long) td->td_nstrips); 134 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 135 "%ld: Strip out of range, max %ld", 136 (long) strip, (long) td->td_nstrips); 134 137 return (-1); 135 138 } … … 137 140 * Calculate the strip size according to the number of 138 141 * rows in the strip (check for truncated last strip on any 139 142 * of the separations). 140 143 */ 141 142 143 144 145 146 147 144 if( td->td_rowsperstrip >= td->td_imagelength ) 145 strips_per_sep = 1; 146 else 147 strips_per_sep = (td->td_imagelength+td->td_rowsperstrip-1) 148 / td->td_rowsperstrip; 149 150 sep_strip = strip % strips_per_sep; 148 151 149 152 if (sep_strip != strips_per_sep-1 || … … 156 159 else if (size > stripsize) 157 160 size = stripsize; 158 if (TIFFFillStrip(tif, strip) 159 && (*tif->tif_decodestrip)(tif, (tidata_t) buf, size,160 161 if (TIFFFillStrip(tif, strip) 162 && (*tif->tif_decodestrip)(tif, (tidata_t) buf, size, 163 (tsample_t)(strip / td->td_stripsperimage)) > 0 ) { 161 164 (*tif->tif_postdecode)(tif, (tidata_t) buf, size); 162 165 return (size); … … 171 174 TIFFDirectory *td = &tif->tif_dir; 172 175 176 assert((tif->tif_flags&TIFF_NOREADRAW)==0); 173 177 if (!isMapped(tif)) { 174 178 tsize_t cc; … … 216 220 static const char module[] = "TIFFReadRawStrip"; 217 221 TIFFDirectory *td = &tif->tif_dir; 218 tsize_t bytecount; 222 /* 223 * FIXME: butecount should have tsize_t type, but for now libtiff 224 * defines tsize_t as a signed 32-bit integer and we are losing 225 * ability to read arrays larger than 2^31 bytes. So we are using 226 * uint32 instead of tsize_t here. 227 */ 228 uint32 bytecount; 219 229 220 230 if (!TIFFCheckRead(tif, 0)) 221 231 return ((tsize_t) -1); 222 232 if (strip >= td->td_nstrips) { 223 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%lu: Strip out of range, max %lu", 224 (unsigned long) strip, (unsigned long) td->td_nstrips); 233 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 234 "%lu: Strip out of range, max %lu", 235 (unsigned long) strip, 236 (unsigned long) td->td_nstrips); 237 return ((tsize_t) -1); 238 } 239 if (tif->tif_flags&TIFF_NOREADRAW) 240 { 241 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 242 "Compression scheme does not support access to raw uncompressed data"); 225 243 return ((tsize_t) -1); 226 244 } … … 232 250 return ((tsize_t) -1); 233 251 } 234 if (size != (tsize_t)-1 && size < bytecount)252 if (size != (tsize_t)-1 && (uint32)size < bytecount) 235 253 bytecount = size; 236 254 return (TIFFReadRawStrip1(tif, strip, buf, bytecount, module)); … … 238 256 239 257 /* 240 * Read the specified strip and setup for decoding. 241 * The data buffer is expanded, as necessary, to 242 * hold the strip's data. 258 * Read the specified strip and setup for decoding. The data buffer is 259 * expanded, as necessary, to hold the strip's data. 243 260 */ 244 261 int … … 247 264 static const char module[] = "TIFFFillStrip"; 248 265 TIFFDirectory *td = &tif->tif_dir; 249 tsize_t bytecount; 250 251 bytecount = td->td_stripbytecount[strip]; 252 if (bytecount <= 0) { 253 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 254 "%lu: Invalid strip byte count, strip %lu", 255 (unsigned long) bytecount, (unsigned long) strip); 256 return (0); 257 } 258 if (isMapped(tif) && 259 (isFillOrder(tif, td->td_fillorder) 260 || (tif->tif_flags & TIFF_NOBITREV))) { 266 267 if ((tif->tif_flags&TIFF_NOREADRAW)==0) 268 { 261 269 /* 262 * The image is mapped into memory and we either don't 263 * need to flip bits or the compression routine is going 264 * to handle this operation itself. In this case, avoid 265 * copying the raw data and instead just reference the 266 * data from the memory mapped file image. This assumes 267 * that the decompression routines do not modify the 268 * contents of the raw data buffer (if they try to, 269 * the application will get a fault since the file is 270 * mapped read-only). 270 * FIXME: butecount should have tsize_t type, but for now 271 * libtiff defines tsize_t as a signed 32-bit integer and we 272 * are losing ability to read arrays larger than 2^31 bytes. 273 * So we are using uint32 instead of tsize_t here. 271 274 */ 272 if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) 273 _TIFFfree(tif->tif_rawdata); 274 tif->tif_flags &= ~TIFF_MYBUFFER; 275 if ( td->td_stripoffset[strip] + bytecount > tif->tif_size) { 275 uint32 bytecount = td->td_stripbytecount[strip]; 276 if (bytecount <= 0) { 277 TIFFErrorExt(tif->tif_clientdata, module, 278 "%s: Invalid strip byte count %lu, strip %lu", 279 tif->tif_name, (unsigned long) bytecount, 280 (unsigned long) strip); 281 return (0); 282 } 283 if (isMapped(tif) && 284 (isFillOrder(tif, td->td_fillorder) 285 || (tif->tif_flags & TIFF_NOBITREV))) { 276 286 /* 277 * This error message might seem strange, but it's 278 * what would happen if a read were done instead. 287 * The image is mapped into memory and we either don't 288 * need to flip bits or the compression routine is 289 * going to handle this operation itself. In this 290 * case, avoid copying the raw data and instead just 291 * reference the data from the memory mapped file 292 * image. This assumes that the decompression 293 * routines do not modify the contents of the raw data 294 * buffer (if they try to, the application will get a 295 * fault since the file is mapped read-only). 279 296 */ 280 TIFFErrorExt(tif->tif_clientdata, module, 281 "%s: Read error on strip %lu; got %lu bytes, expected %lu", 282 tif->tif_name, 283 (unsigned long) strip, 284 (unsigned long) tif->tif_size - td->td_stripoffset[strip], 285 (unsigned long) bytecount); 286 tif->tif_curstrip = NOSTRIP; 287 return (0); 288 } 289 tif->tif_rawdatasize = bytecount; 290 tif->tif_rawdata = tif->tif_base + td->td_stripoffset[strip]; 291 } else { 292 /* 293 * Expand raw data buffer, if needed, to 294 * hold data strip coming from file 295 * (perhaps should set upper bound on 296 * the size of a buffer we'll use?). 297 */ 298 if (bytecount > tif->tif_rawdatasize) { 299 tif->tif_curstrip = NOSTRIP; 300 if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { 297 if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) 298 _TIFFfree(tif->tif_rawdata); 299 tif->tif_flags &= ~TIFF_MYBUFFER; 300 /* 301 * We must check for overflow, potentially causing 302 * an OOB read. Instead of simple 303 * 304 * td->td_stripoffset[strip]+bytecount > tif->tif_size 305 * 306 * comparison (which can overflow) we do the following 307 * two comparisons: 308 */ 309 if (bytecount > tif->tif_size || 310 td->td_stripoffset[strip] > tif->tif_size - bytecount) { 311 /* 312 * This error message might seem strange, but 313 * it's what would happen if a read were done 314 * instead. 315 */ 301 316 TIFFErrorExt(tif->tif_clientdata, module, 302 "%s: Data buffer too small to hold strip %lu", 303 tif->tif_name, (unsigned long) strip); 317 318 "%s: Read error on strip %lu; " 319 "got %lu bytes, expected %lu", 320 tif->tif_name, (unsigned long) strip, 321 (unsigned long) tif->tif_size - td->td_stripoffset[strip], 322 (unsigned long) bytecount); 323 tif->tif_curstrip = NOSTRIP; 304 324 return (0); 305 325 } 306 if (!TIFFReadBufferSetup(tif, 0, 307 TIFFroundup(bytecount, 1024))) 326 tif->tif_rawdatasize = bytecount; 327 tif->tif_rawdata = tif->tif_base + td->td_stripoffset[strip]; 328 } else { 329 /* 330 * Expand raw data buffer, if needed, to hold data 331 * strip coming from file (perhaps should set upper 332 * bound on the size of a buffer we'll use?). 333 */ 334 if (bytecount > (uint32)tif->tif_rawdatasize) { 335 tif->tif_curstrip = NOSTRIP; 336 if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { 337 TIFFErrorExt(tif->tif_clientdata, 338 module, 339 "%s: Data buffer too small to hold strip %lu", 340 tif->tif_name, 341 (unsigned long) strip); 342 return (0); 343 } 344 if (!TIFFReadBufferSetup(tif, 0, 345 TIFFroundup(bytecount, 1024))) 346 return (0); 347 } 348 if ((uint32)TIFFReadRawStrip1(tif, strip, 349 (unsigned char *)tif->tif_rawdata, 350 bytecount, module) != bytecount) 308 351 return (0); 309 } 310 if (TIFFReadRawStrip1(tif, strip, (unsigned char *)tif->tif_rawdata, 311 bytecount, module) != bytecount) 312 return (0); 313 if (!isFillOrder(tif, td->td_fillorder) && 314 (tif->tif_flags & TIFF_NOBITREV) == 0) 315 TIFFReverseBits(tif->tif_rawdata, bytecount); 352 if (!isFillOrder(tif, td->td_fillorder) && 353 (tif->tif_flags & TIFF_NOBITREV) == 0) 354 TIFFReverseBits(tif->tif_rawdata, bytecount); 355 } 316 356 } 317 357 return (TIFFStartStrip(tif, strip)); … … 350 390 return (-1); 351 391 if (tile >= td->td_nstrips) { 352 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%ld: Tile out of range, max %ld", 353 (long) tile, (unsigned long) td->td_nstrips); 392 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 393 "%ld: Tile out of range, max %ld", 394 (long) tile, (unsigned long) td->td_nstrips); 354 395 return (-1); 355 396 } … … 372 413 TIFFDirectory *td = &tif->tif_dir; 373 414 415 assert((tif->tif_flags&TIFF_NOREADRAW)==0); 374 416 if (!isMapped(tif)) { 375 417 tsize_t cc; … … 420 462 static const char module[] = "TIFFReadRawTile"; 421 463 TIFFDirectory *td = &tif->tif_dir; 422 tsize_t bytecount; 464 /* 465 * FIXME: butecount should have tsize_t type, but for now libtiff 466 * defines tsize_t as a signed 32-bit integer and we are losing 467 * ability to read arrays larger than 2^31 bytes. So we are using 468 * uint32 instead of tsize_t here. 469 */ 470 uint32 bytecount; 423 471 424 472 if (!TIFFCheckRead(tif, 1)) 425 473 return ((tsize_t) -1); 426 474 if (tile >= td->td_nstrips) { 427 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%lu: Tile out of range, max %lu", 475 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 476 "%lu: Tile out of range, max %lu", 428 477 (unsigned long) tile, (unsigned long) td->td_nstrips); 429 478 return ((tsize_t) -1); 430 479 } 480 if (tif->tif_flags&TIFF_NOREADRAW) 481 { 482 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 483 "Compression scheme does not support access to raw uncompressed data"); 484 return ((tsize_t) -1); 485 } 431 486 bytecount = td->td_stripbytecount[tile]; 432 if (size != (tsize_t) -1 && size < bytecount)487 if (size != (tsize_t) -1 && (uint32)size < bytecount) 433 488 bytecount = size; 434 489 return (TIFFReadRawTile1(tif, tile, buf, bytecount, module)); … … 436 491 437 492 /* 438 * Read the specified tile and setup for decoding. 439 * The data buffer is expanded, as necessary, to 440 * hold the tile's data. 493 * Read the specified tile and setup for decoding. The data buffer is 494 * expanded, as necessary, to hold the tile's data. 441 495 */ 442 496 int … … 445 499 static const char module[] = "TIFFFillTile"; 446 500 TIFFDirectory *td = &tif->tif_dir; 447 tsize_t bytecount; 448 449 bytecount = td->td_stripbytecount[tile]; 450 if (bytecount <= 0) { 451 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 452 "%lu: Invalid tile byte count, tile %lu", 453 (unsigned long) bytecount, (unsigned long) tile); 454 return (0); 455 } 456 if (isMapped(tif) && 457 (isFillOrder(tif, td->td_fillorder) 458 || (tif->tif_flags & TIFF_NOBITREV))) { 501 502 if ((tif->tif_flags&TIFF_NOREADRAW)==0) 503 { 459 504 /* 460 * The image is mapped into memory and we either don't 461 * need to flip bits or the compression routine is going 462 * to handle this operation itself. In this case, avoid 463 * copying the raw data and instead just reference the 464 * data from the memory mapped file image. This assumes 465 * that the decompression routines do not modify the 466 * contents of the raw data buffer (if they try to, 467 * the application will get a fault since the file is 468 * mapped read-only). 505 * FIXME: butecount should have tsize_t type, but for now 506 * libtiff defines tsize_t as a signed 32-bit integer and we 507 * are losing ability to read arrays larger than 2^31 bytes. 508 * So we are using uint32 instead of tsize_t here. 469 509 */ 470 if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)471 _TIFFfree(tif->tif_rawdata);472 tif->tif_flags &= ~TIFF_MYBUFFER;473 if ( td->td_stripoffset[tile] + bytecount > tif->tif_size) {474 tif->tif_curtile = NOTILE;510 uint32 bytecount = td->td_stripbytecount[tile]; 511 if (bytecount <= 0) { 512 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 513 "%lu: Invalid tile byte count, tile %lu", 514 (unsigned long) bytecount, (unsigned long) tile); 475 515 return (0); 476 516 } 477 tif->tif_rawdatasize = bytecount; 478 tif->tif_rawdata = tif->tif_base + td->td_stripoffset[tile]; 479 } else { 480 /* 481 * Expand raw data buffer, if needed, to 482 * hold data tile coming from file 483 * (perhaps should set upper bound on 484 * the size of a buffer we'll use?). 485 */ 486 if (bytecount > tif->tif_rawdatasize) { 487 tif->tif_curtile = NOTILE; 488 if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { 489 TIFFErrorExt(tif->tif_clientdata, module, 490 "%s: Data buffer too small to hold tile %ld", 491 tif->tif_name, (long) tile); 517 if (isMapped(tif) && 518 (isFillOrder(tif, td->td_fillorder) 519 || (tif->tif_flags & TIFF_NOBITREV))) { 520 /* 521 * The image is mapped into memory and we either don't 522 * need to flip bits or the compression routine is 523 * going to handle this operation itself. In this 524 * case, avoid copying the raw data and instead just 525 * reference the data from the memory mapped file 526 * image. This assumes that the decompression 527 * routines do not modify the contents of the raw data 528 * buffer (if they try to, the application will get a 529 * fault since the file is mapped read-only). 530 */ 531 if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) 532 _TIFFfree(tif->tif_rawdata); 533 tif->tif_flags &= ~TIFF_MYBUFFER; 534 /* 535 * We must check for overflow, potentially causing 536 * an OOB read. Instead of simple 537 * 538 * td->td_stripoffset[tile]+bytecount > tif->tif_size 539 * 540 * comparison (which can overflow) we do the following 541 * two comparisons: 542 */ 543 if (bytecount > tif->tif_size || 544 td->td_stripoffset[tile] > tif->tif_size - bytecount) { 545 tif->tif_curtile = NOTILE; 492 546 return (0); 493 547 } 494 if (!TIFFReadBufferSetup(tif, 0, 495 TIFFroundup(bytecount, 1024))) 548 tif->tif_rawdatasize = bytecount; 549 tif->tif_rawdata = 550 tif->tif_base + td->td_stripoffset[tile]; 551 } else { 552 /* 553 * Expand raw data buffer, if needed, to hold data 554 * tile coming from file (perhaps should set upper 555 * bound on the size of a buffer we'll use?). 556 */ 557 if (bytecount > (uint32)tif->tif_rawdatasize) { 558 tif->tif_curtile = NOTILE; 559 if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { 560 TIFFErrorExt(tif->tif_clientdata, 561 module, 562 "%s: Data buffer too small to hold tile %ld", 563 tif->tif_name, 564 (long) tile); 565 return (0); 566 } 567 if (!TIFFReadBufferSetup(tif, 0, 568 TIFFroundup(bytecount, 1024))) 569 return (0); 570 } 571 if ((uint32)TIFFReadRawTile1(tif, tile, 572 (unsigned char *)tif->tif_rawdata, 573 bytecount, module) != bytecount) 496 574 return (0); 497 } 498 if (TIFFReadRawTile1(tif, tile, 499 (unsigned char *)tif->tif_rawdata, 500 bytecount, module) != bytecount) 501 return (0); 502 if (!isFillOrder(tif, td->td_fillorder) && 503 (tif->tif_flags & TIFF_NOBITREV) == 0) 504 TIFFReverseBits(tif->tif_rawdata, bytecount); 575 if (!isFillOrder(tif, td->td_fillorder) && 576 (tif->tif_flags & TIFF_NOBITREV) == 0) 577 TIFFReverseBits(tif->tif_rawdata, bytecount); 578 } 505 579 } 506 580 return (TIFFStartTile(tif, tile)); … … 521 595 static const char module[] = "TIFFReadBufferSetup"; 522 596 597 assert((tif->tif_flags&TIFF_NOREADRAW)==0); 523 598 if (tif->tif_rawdata) { 524 599 if (tif->tif_flags & TIFF_MYBUFFER) … … 561 636 tif->tif_curstrip = strip; 562 637 tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip; 563 tif->tif_rawcp = tif->tif_rawdata; 564 tif->tif_rawcc = td->td_stripbytecount[strip]; 638 if (tif->tif_flags&TIFF_NOREADRAW) 639 { 640 tif->tif_rawcp = NULL; 641 tif->tif_rawcc = 0; 642 } 643 else 644 { 645 tif->tif_rawcp = tif->tif_rawdata; 646 tif->tif_rawcc = td->td_stripbytecount[strip]; 647 } 565 648 return ((*tif->tif_predecode)(tif, 566 649 (tsample_t)(strip / td->td_stripsperimage))); … … 588 671 (tile % TIFFhowmany(td->td_imagelength, td->td_tilelength)) * 589 672 td->td_tilewidth; 590 tif->tif_rawcp = tif->tif_rawdata; 591 tif->tif_rawcc = td->td_stripbytecount[tile]; 673 if (tif->tif_flags&TIFF_NOREADRAW) 674 { 675 tif->tif_rawcp = NULL; 676 tif->tif_rawcc = 0; 677 } 678 else 679 { 680 tif->tif_rawcp = tif->tif_rawdata; 681 tif->tif_rawcc = td->td_stripbytecount[tile]; 682 } 592 683 return ((*tif->tif_predecode)(tif, 593 684 (tsample_t)(tile/td->td_stripsperimage))); -
trunk/src/3rdparty/libtiff/libtiff/tif_stream.cxx
r2 r846 1 /* $Id: tif_stream.cxx,v 1. 5 2005/07/26 08:11:13 dron Exp $ */1 /* $Id: tif_stream.cxx,v 1.6.2.1 2009-01-01 00:10:43 bfriesen Exp $ */ 2 2 3 3 /* … … 31 31 #include <iostream> 32 32 33 #ifndef __VMS 33 34 using namespace std; 35 #endif 34 36 35 37 class tiffis_data … … 110 112 // '\0' characters. 111 113 if( os->fail() ) { 114 #ifdef __VMS 115 int old_state; 116 #else 112 117 ios::iostate old_state; 113 toff_t origin; 118 #endif 119 toff_t origin=0; 114 120 115 121 old_state = os->rdstate(); -
trunk/src/3rdparty/libtiff/libtiff/tif_strip.c
r2 r846 1 /* $Id: tif_strip.c,v 1.1 7 2006/03/21 16:29:33 dronExp $ */1 /* $Id: tif_strip.c,v 1.19 2006/03/25 18:04:35 joris Exp $ */ 2 2 3 3 /* … … 122 122 * YCbCr data for the extended image. 123 123 */ 124 125 126 127 TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING, 128 ycbcrsubsampling + 0, 129 124 uint16 ycbcrsubsampling[2]; 125 tsize_t w, scanline, samplingarea; 126 127 TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING, 128 ycbcrsubsampling + 0, 129 ycbcrsubsampling + 1 ); 130 130 131 131 samplingarea = ycbcrsubsampling[0]*ycbcrsubsampling[1]; … … 229 229 TIFFDirectory *td = &tif->tif_dir; 230 230 tsize_t scanline; 231 231 232 232 if (td->td_planarconfig == PLANARCONFIG_CONTIG) { 233 233 if (td->td_photometric == PHOTOMETRIC_YCBCR … … 235 235 uint16 ycbcrsubsampling[2]; 236 236 237 TIFFGetField(tif, TIFFTAG_YCBCRSUBSAMPLING, 237 TIFFGetField(tif, TIFFTAG_YCBCRSUBSAMPLING, 238 238 ycbcrsubsampling + 0, 239 239 ycbcrsubsampling + 1); … … 269 269 270 270 /* 271 * Some stuff depends on this older version of TIFFScanlineSize 272 * TODO: resolve this 273 */ 274 tsize_t 275 TIFFOldScanlineSize(TIFF* tif) 276 { 277 TIFFDirectory *td = &tif->tif_dir; 278 tsize_t scanline; 279 280 scanline = multiply (tif, td->td_bitspersample, td->td_imagewidth, 281 "TIFFScanlineSize"); 282 if (td->td_planarconfig == PLANARCONFIG_CONTIG) 283 scanline = multiply (tif, scanline, td->td_samplesperpixel, 284 "TIFFScanlineSize"); 285 return ((tsize_t) TIFFhowmany8(scanline)); 286 } 287 288 /* 289 * Return the number of bytes to read/write in a call to 290 * one of the scanline-oriented i/o routines. Note that 291 * this number may be 1/samples-per-pixel if data is 292 * stored as separate planes. 293 * The ScanlineSize in case of YCbCrSubsampling is defined as the 294 * strip size divided by the strip height, i.e. the size of a pack of vertical 295 * subsampling lines divided by vertical subsampling. It should thus make 296 * sense when multiplied by a multiple of vertical subsampling. 297 * Some stuff depends on this newer version of TIFFScanlineSize 298 * TODO: resolve this 299 */ 300 tsize_t 301 TIFFNewScanlineSize(TIFF* tif) 302 { 303 TIFFDirectory *td = &tif->tif_dir; 304 tsize_t scanline; 305 306 if (td->td_planarconfig == PLANARCONFIG_CONTIG) { 307 if (td->td_photometric == PHOTOMETRIC_YCBCR 308 && !isUpSampled(tif)) { 309 uint16 ycbcrsubsampling[2]; 310 311 TIFFGetField(tif, TIFFTAG_YCBCRSUBSAMPLING, 312 ycbcrsubsampling + 0, 313 ycbcrsubsampling + 1); 314 315 if (ycbcrsubsampling[0]*ycbcrsubsampling[1] == 0) { 316 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 317 "Invalid YCbCr subsampling"); 318 return 0; 319 } 320 321 return((tsize_t) ((((td->td_imagewidth+ycbcrsubsampling[0]-1) 322 /ycbcrsubsampling[0]) 323 *(ycbcrsubsampling[0]*ycbcrsubsampling[1]+2) 324 *td->td_bitspersample+7) 325 /8)/ycbcrsubsampling[1]); 326 327 } else { 328 scanline = multiply(tif, td->td_imagewidth, 329 td->td_samplesperpixel, 330 "TIFFScanlineSize"); 331 } 332 } else 333 scanline = td->td_imagewidth; 334 return ((tsize_t) TIFFhowmany8(multiply(tif, scanline, 335 td->td_bitspersample, 336 "TIFFScanlineSize"))); 337 } 338 339 /* 271 340 * Return the number of bytes required to store a complete 272 341 * decoded and packed raster scanline (as opposed to the -
trunk/src/3rdparty/libtiff/libtiff/tif_win32.c
r2 r846 1 /* $Id: tif_win32.c,v 1. 18 2006/02/07 11:03:29 dronExp $ */1 /* $Id: tif_win32.c,v 1.21 2007/03/07 17:10:31 joris Exp $ */ 2 2 3 3 /* … … 32 32 #include <windows.h> 33 33 34 #include <windows.h> 35 34 36 static tsize_t 35 37 _tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) … … 53 55 _tiffSeekProc(thandle_t fd, toff_t off, int whence) 54 56 { 55 DWORD dwMoveMethod, dwMoveHigh; 56 57 /* we use this as a special code, so avoid accepting it */ 58 if( off == 0xFFFFFFFF ) 59 return 0xFFFFFFFF; 57 ULARGE_INTEGER li; 58 DWORD dwMoveMethod; 59 60 li.QuadPart = off; 60 61 61 62 switch(whence) … … 74 75 break; 75 76 } 76 dwMoveHigh = 0; 77 return ((toff_t)SetFilePointer(fd, (LONG) off, (PLONG)&dwMoveHigh, 78 dwMoveMethod)); 77 return ((toff_t)SetFilePointer(fd, (LONG) li.LowPart, 78 (PLONG)&li.HighPart, dwMoveMethod)); 79 79 } 80 80 … … 91 91 } 92 92 93 #ifdef __BORLANDC__94 #pragma argsused95 #endif96 93 static int 97 94 _tiffDummyMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) 98 95 { 96 (void) fd; 97 (void) pbase; 98 (void) psize; 99 99 return (0); 100 100 } … … 130 130 } 131 131 132 #ifdef __BORLANDC__133 #pragma argsused134 #endif135 132 static void 136 133 _tiffDummyUnmapProc(thandle_t fd, tdata_t base, toff_t size) 137 134 { 135 (void) fd; 136 (void) base; 137 (void) size; 138 138 } 139 139 … … 164 164 return (tif); 165 165 } 166 167 #ifndef _WIN32_WCE 166 168 167 169 /* … … 274 276 } 275 277 278 #endif /* ndef _WIN32_WCE */ 279 280 276 281 tdata_t 277 282 _TIFFmalloc(tsize_t s) … … 290 295 _TIFFrealloc(tdata_t p, tsize_t s) 291 296 { 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 297 void* pvTmp; 298 tsize_t old; 299 300 if(p == NULL) 301 return ((tdata_t)GlobalAlloc(GMEM_FIXED, s)); 302 303 old = GlobalSize(p); 304 305 if (old>=s) { 306 if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) { 307 CopyMemory(pvTmp, p, s); 308 GlobalFree(p); 309 } 310 } else { 311 if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) { 312 CopyMemory(pvTmp, p, old); 313 GlobalFree(p); 314 } 315 } 316 return ((tdata_t)pvTmp); 312 317 } 313 318 … … 335 340 return (iTmp); 336 341 } 342 343 #ifndef _WIN32_WCE 337 344 338 345 static void … … 391 398 TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler; 392 399 400 #endif /* ndef _WIN32_WCE */ 401 393 402 /* vim: set ts=8 sts=8 sw=8 noet: */ -
trunk/src/3rdparty/libtiff/libtiff/tif_write.c
r2 r846 1 /* $Id: tif_write.c,v 1.2 1 2006/02/27 14:29:20 dron Exp $ */1 /* $Id: tif_write.c,v 1.22.2.4 2009-08-28 02:23:19 bfriesen Exp $ */ 2 2 3 3 /* … … 228 228 if( td->td_stripbytecount[strip] > 0 ) 229 229 { 230 /* if we are writing over existing tiles, zero length. */ 231 td->td_stripbytecount[strip] = 0; 232 233 /* this forces TIFFAppendToStrip() to do a seek */ 230 /* Force TIFFAppendToStrip() to consider placing data at end 231 of file. */ 234 232 tif->tif_curoff = 0; 235 233 } … … 364 362 if( td->td_stripbytecount[tile] > 0 ) 365 363 { 366 /* if we are writing over existing tiles, zero length. */ 367 td->td_stripbytecount[tile] = 0; 368 369 /* this forces TIFFAppendToStrip() to do a seek */ 364 /* Force TIFFAppendToStrip() to consider placing data at end 365 of file. */ 370 366 tif->tif_curoff = 0; 371 367 } … … 522 518 * in the single band case. 523 519 */ 524 tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG; 520 if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) 521 tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG; 525 522 } else { 526 523 if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) { … … 626 623 TIFFAppendToStrip(TIFF* tif, tstrip_t strip, tidata_t data, tsize_t cc) 627 624 { 625 static const char module[] = "TIFFAppendToStrip"; 628 626 TIFFDirectory *td = &tif->tif_dir; 629 static const char module[] = "TIFFAppendToStrip";630 627 631 628 if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) { 632 /* 633 * No current offset, set the current strip. 634 */ 635 assert(td->td_nstrips > 0); 636 if (td->td_stripoffset[strip] != 0) { 637 /* 638 * Prevent overlapping of the data chunks. We need 639 * this to enable in place updating of the compressed 640 * images. Larger blocks will be moved at the end of 641 * the file without any optimization of the spare 642 * space, so such scheme is not too much effective. 643 */ 644 if (td->td_stripbytecountsorted) { 645 if (strip == td->td_nstrips - 1 646 || td->td_stripoffset[strip + 1] < 647 td->td_stripoffset[strip] + cc) { 648 td->td_stripoffset[strip] = 649 TIFFSeekFile(tif, (toff_t)0, 650 SEEK_END); 651 } 652 } else { 653 tstrip_t i; 654 for (i = 0; i < td->td_nstrips; i++) { 655 if (td->td_stripoffset[i] > 656 td->td_stripoffset[strip] 657 && td->td_stripoffset[i] < 658 td->td_stripoffset[strip] + cc) { 659 td->td_stripoffset[strip] = 660 TIFFSeekFile(tif, 661 (toff_t)0, 662 SEEK_END); 663 } 664 } 665 } 666 667 if (!SeekOK(tif, td->td_stripoffset[strip])) { 668 TIFFErrorExt(tif->tif_clientdata, module, 669 "%s: Seek error at scanline %lu", 670 tif->tif_name, 671 (unsigned long)tif->tif_row); 672 return (0); 673 } 674 } else 675 td->td_stripoffset[strip] = 676 TIFFSeekFile(tif, (toff_t) 0, SEEK_END); 677 tif->tif_curoff = td->td_stripoffset[strip]; 629 assert(td->td_nstrips > 0); 630 631 if( td->td_stripbytecount[strip] != 0 632 && td->td_stripoffset[strip] != 0 633 && td->td_stripbytecount[strip] >= cc ) 634 { 635 /* 636 * There is already tile data on disk, and the new tile 637 * data we have to will fit in the same space. The only 638 * aspect of this that is risky is that there could be 639 * more data to append to this strip before we are done 640 * depending on how we are getting called. 641 */ 642 if (!SeekOK(tif, td->td_stripoffset[strip])) { 643 TIFFErrorExt(tif->tif_clientdata, module, 644 "Seek error at scanline %lu", 645 (unsigned long)tif->tif_row); 646 return (0); 647 } 648 } 649 else 650 { 651 /* 652 * Seek to end of file, and set that as our location to 653 * write this strip. 654 */ 655 td->td_stripoffset[strip] = TIFFSeekFile(tif, 0, SEEK_END); 656 } 657 658 tif->tif_curoff = td->td_stripoffset[strip]; 659 660 /* 661 * We are starting a fresh strip/tile, so set the size to zero. 662 */ 663 td->td_stripbytecount[strip] = 0; 678 664 } 679 665 680 666 if (!WriteOK(tif, data, cc)) { 681 TIFFErrorExt(tif->tif_clientdata, module, " %s:Write error at scanline %lu",682 tif->tif_name,(unsigned long) tif->tif_row);683 return (0);684 } 685 tif->tif_curoff +=cc;667 TIFFErrorExt(tif->tif_clientdata, module, "Write error at scanline %lu", 668 (unsigned long) tif->tif_row); 669 return (0); 670 } 671 tif->tif_curoff = tif->tif_curoff+cc; 686 672 td->td_stripbytecount[strip] += cc; 687 673 return (1); -
trunk/src/3rdparty/libtiff/libtiff/tif_zip.c
r2 r846 1 /* $Id: tif_zip.c,v 1.1 0 2006/03/16 12:38:24 dronExp $ */1 /* $Id: tif_zip.c,v 1.11.2.3 2007/11/22 21:24:51 fwarmerdam Exp $ */ 2 2 3 3 /* … … 71 71 int zipquality; /* compression level */ 72 72 int state; /* state flags */ 73 #define ZSTATE_INIT 0x1 /* zlib setup successfully */ 73 #define ZSTATE_INIT_DECODE 0x01 74 #define ZSTATE_INIT_ENCODE 0x02 74 75 75 76 TIFFVGetMethod vgetparent; /* super-class method */ … … 91 92 92 93 assert(sp != NULL); 94 95 /* if we were last encoding, terminate this mode */ 96 if (sp->state & ZSTATE_INIT_ENCODE) { 97 deflateEnd(&sp->stream); 98 sp->state = 0; 99 } 100 93 101 if (inflateInit(&sp->stream) != Z_OK) { 94 102 TIFFErrorExt(tif->tif_clientdata, module, "%s: %s", tif->tif_name, sp->stream.msg); 95 103 return (0); 96 104 } else { 97 sp->state |= ZSTATE_INIT ;105 sp->state |= ZSTATE_INIT_DECODE; 98 106 return (1); 99 107 } … … 110 118 (void) s; 111 119 assert(sp != NULL); 120 121 if( (sp->state & ZSTATE_INIT_DECODE) == 0 ) 122 tif->tif_setupdecode( tif ); 123 112 124 sp->stream.next_in = tif->tif_rawdata; 113 125 sp->stream.avail_in = tif->tif_rawcc; … … 123 135 (void) s; 124 136 assert(sp != NULL); 137 assert(sp->state == ZSTATE_INIT_DECODE); 138 125 139 sp->stream.next_out = op; 126 140 sp->stream.avail_out = occ; … … 159 173 160 174 assert(sp != NULL); 175 if (sp->state & ZSTATE_INIT_DECODE) { 176 inflateEnd(&sp->stream); 177 sp->state = 0; 178 } 179 161 180 if (deflateInit(&sp->stream, sp->zipquality) != Z_OK) { 162 181 TIFFErrorExt(tif->tif_clientdata, module, "%s: %s", tif->tif_name, sp->stream.msg); 163 182 return (0); 164 183 } else { 165 sp->state |= ZSTATE_INIT ;184 sp->state |= ZSTATE_INIT_ENCODE; 166 185 return (1); 167 186 } … … 178 197 (void) s; 179 198 assert(sp != NULL); 199 if( sp->state != ZSTATE_INIT_ENCODE ) 200 tif->tif_setupencode( tif ); 201 180 202 sp->stream.next_out = tif->tif_rawdata; 181 203 sp->stream.avail_out = tif->tif_rawdatasize; … … 191 213 ZIPState *sp = EncoderState(tif); 192 214 static const char module[] = "ZIPEncode"; 215 216 assert(sp != NULL); 217 assert(sp->state == ZSTATE_INIT_ENCODE); 193 218 194 219 (void) s; … … 258 283 tif->tif_tagmethods.vsetfield = sp->vsetparent; 259 284 260 if (sp->state &ZSTATE_INIT) {261 /* NB: avoid problems in the library */ 262 if (tif->tif_mode == O_RDONLY) 263 inflateEnd(&sp->stream); 264 else 265 deflateEnd(&sp->stream);285 if (sp->state & ZSTATE_INIT_ENCODE) { 286 deflateEnd(&sp->stream); 287 sp->state = 0; 288 } else if( sp->state & ZSTATE_INIT_DECODE) { 289 inflateEnd(&sp->stream); 290 sp->state = 0; 266 291 } 267 292 _TIFFfree(sp); … … 280 305 case TIFFTAG_ZIPQUALITY: 281 306 sp->zipquality = va_arg(ap, int); 282 if ( tif->tif_mode != O_RDONLY && (sp->state&ZSTATE_INIT)) {307 if ( sp->state&ZSTATE_INIT_ENCODE ) { 283 308 if (deflateParams(&sp->stream, 284 309 sp->zipquality, Z_DEFAULT_STRATEGY) != Z_OK) { … … 318 343 TIFFInitZIP(TIFF* tif, int scheme) 319 344 { 345 static const char module[] = "TIFFInitZIP"; 320 346 ZIPState* sp; 321 347 322 348 assert( (scheme == COMPRESSION_DEFLATE) 323 349 || (scheme == COMPRESSION_ADOBE_DEFLATE)); 350 351 /* 352 * Merge codec-specific tag information. 353 */ 354 if (!_TIFFMergeFieldInfo(tif, zipFieldInfo, 355 TIFFArrayCount(zipFieldInfo))) { 356 TIFFErrorExt(tif->tif_clientdata, module, 357 "Merging Deflate codec-specific tags failed"); 358 return 0; 359 } 324 360 325 361 /* … … 336 372 337 373 /* 338 * Merge codec-specific tag information and 339 * override parent get/set field methods. 374 * Override parent get/set field methods. 340 375 */ 341 _TIFFMergeFieldInfo(tif, zipFieldInfo, TIFFArrayCount(zipFieldInfo));342 376 sp->vgetparent = tif->tif_tagmethods.vgetfield; 343 377 tif->tif_tagmethods.vgetfield = ZIPVGetField; /* hook for codec tags */ … … 370 404 return (1); 371 405 bad: 372 TIFFErrorExt(tif->tif_clientdata, "TIFFInitZIP",406 TIFFErrorExt(tif->tif_clientdata, module, 373 407 "No space for ZIP state block"); 374 408 return (0); -
trunk/src/3rdparty/libtiff/libtiff/tiff.h
r2 r846 1 /* $Id: tiff.h,v 1.4 2 2005/12/23 15:10:45dron Exp $ */1 /* $Id: tiff.h,v 1.43 2006-10-05 15:20:40 dron Exp $ */ 2 2 3 3 /* … … 44 44 * 45 45 * For Big TIFF design notes see the following link 46 * http:// gdal.maptools.org/twiki/bin/view/libtiff/BigTIFFDesign46 * http://www.remotesensing.org/libtiff/bigtiffdesign.html 47 47 */ 48 48 #define TIFF_VERSION 42 -
trunk/src/3rdparty/libtiff/libtiff/tiffconf.h
r2 r846 1 1 /* 2 Configuration defines by Trolltech.2 Configuration defines for Qt. 3 3 This file maintained for backward compatibility. Do not use definitions 4 4 from this file in your programs. -
trunk/src/3rdparty/libtiff/libtiff/tiffconf.h.in
r2 r846 41 41 /* Support JPEG compression (requires IJG JPEG library) */ 42 42 #undef JPEG_SUPPORT 43 44 /* Support JBIG compression (requires JBIG-KIT library) */ 45 #undef JBIG_SUPPORT 43 46 44 47 /* Support LogLuv high dynamic range encoding */ -
trunk/src/3rdparty/libtiff/libtiff/tiffio.h
r561 r846 1 /* $Id: tiffio.h,v 1.5 0 2006/03/21 16:37:51 dron Exp $ */1 /* $Id: tiffio.h,v 1.56.2.3 2009-01-01 00:10:43 bfriesen Exp $ */ 2 2 3 3 /* … … 59 59 * that it is unsigned, rather than signed. 60 60 */ 61 typedef uint32 ttag_t; /* directory tag */ 62 typedef uint16 tdir_t; /* directory index */ 63 typedef uint16 tsample_t; /* sample number */ 64 typedef uint32 tstrip_t; /* strip number */ 65 typedef uint32 ttile_t; /* tile number */ 66 typedef int32 tsize_t; /* i/o size in bytes */ 67 typedef void* tdata_t; /* image data ref */ 68 typedef uint32 toff_t; /* file offset */ 61 typedef uint32 ttag_t; /* directory tag */ 62 typedef uint16 tdir_t; /* directory index */ 63 typedef uint16 tsample_t; /* sample number */ 64 typedef uint32 tstrile_t; /* strip or tile number */ 65 typedef tstrile_t tstrip_t; /* strip number */ 66 typedef tstrile_t ttile_t; /* tile number */ 67 typedef int32 tsize_t; /* i/o size in bytes */ 68 typedef void* tdata_t; /* image data ref */ 69 typedef uint32 toff_t; /* file offset */ 69 70 70 71 #if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32)) … … 98 99 typedef void* thandle_t; /* client data handle */ 99 100 #endif /* USE_WIN32_FILEIO */ 100 101 #ifndef NULL102 # define NULL (void *)0103 #endif104 101 105 102 /* … … 194 191 */ 195 192 struct _TIFFRGBAImage { 196 TIFF* tif; /* image handle */ 197 int stoponerr; /* stop on read error */ 198 int isContig; /* data is packed/separate */ 199 int alpha; /* type of alpha data present */ 200 uint32 width; /* image width */ 201 uint32 height; /* image height */ 202 uint16 bitspersample; /* image bits/sample */ 203 uint16 samplesperpixel; /* image samples/pixel */ 204 uint16 orientation; /* image orientation */ 205 uint16 req_orientation; /* requested orientation */ 206 uint16 photometric; /* image photometric interp */ 207 uint16* redcmap; /* colormap pallete */ 208 uint16* greencmap; 209 uint16* bluecmap; 210 /* get image data routine */ 211 int (*get)(TIFFRGBAImage*, uint32*, uint32, uint32); 193 TIFF* tif; /* image handle */ 194 int stoponerr; /* stop on read error */ 195 int isContig; /* data is packed/separate */ 196 int alpha; /* type of alpha data present */ 197 uint32 width; /* image width */ 198 uint32 height; /* image height */ 199 uint16 bitspersample; /* image bits/sample */ 200 uint16 samplesperpixel; /* image samples/pixel */ 201 uint16 orientation; /* image orientation */ 202 uint16 req_orientation; /* requested orientation */ 203 uint16 photometric; /* image photometric interp */ 204 uint16* redcmap; /* colormap pallete */ 205 uint16* greencmap; 206 uint16* bluecmap; 207 /* get image data routine */ 208 int (*get)(TIFFRGBAImage*, uint32*, uint32, uint32); 209 /* put decoded strip/tile */ 212 210 union { 213 211 void (*any)(TIFFRGBAImage*); 214 tileContigRoutine 215 tileSeparateRoutine 216 } put; /* put decoded strip/tile */217 TIFFRGBValue* Map; 218 uint32** BWmap; 219 uint32** PALmap; 220 TIFFYCbCrToRGB* ycbcr; 221 TIFFCIELabToRGB* cielab;/* CIE L*a*b conversion state */222 223 introw_offset;224 intcol_offset;212 tileContigRoutine contig; 213 tileSeparateRoutine separate; 214 } put; 215 TIFFRGBValue* Map; /* sample mapping array */ 216 uint32** BWmap; /* black&white map */ 217 uint32** PALmap; /* palette image map */ 218 TIFFYCbCrToRGB* ycbcr; /* YCbCr conversion state */ 219 TIFFCIELabToRGB* cielab; /* CIE L*a*b conversion state */ 220 221 int row_offset; 222 int col_offset; 225 223 }; 226 224 … … 254 252 #ifndef LOGLUV_PUBLIC 255 253 #define LOGLUV_PUBLIC 1 254 #endif 255 256 #if !defined(__GNUC__) && !defined(__attribute__) 257 # define __attribute__(x) /*nothing*/ 256 258 #endif 257 259 … … 352 354 extern int TIFFReadEXIFDirectory(TIFF*, toff_t); 353 355 extern tsize_t TIFFScanlineSize(TIFF*); 356 extern tsize_t TIFFOldScanlineSize(TIFF*); 357 extern tsize_t TIFFNewScanlineSize(TIFF*); 354 358 extern tsize_t TIFFRasterScanlineSize(TIFF*); 355 359 extern tsize_t TIFFStripSize(TIFF*); … … 436 440 extern const char* TIFFFileName(TIFF*); 437 441 extern const char* TIFFSetFileName(TIFF*, const char *); 438 extern void TIFFError(const char*, const char*, ...);439 extern void TIFFErrorExt(thandle_t, const char*, const char*, ...);440 extern void TIFFWarning(const char*, const char*, ...);441 extern void TIFFWarningExt(thandle_t, const char*, const char*, ...);442 extern void TIFFError(const char*, const char*, ...) __attribute__((format (printf,2,3))); 443 extern void TIFFErrorExt(thandle_t, const char*, const char*, ...) __attribute__((format (printf,3,4))); 444 extern void TIFFWarning(const char*, const char*, ...) __attribute__((format (printf,2,3))); 445 extern void TIFFWarningExt(thandle_t, const char*, const char*, ...) __attribute__((format (printf,3,4))); 442 446 extern TIFFErrorHandler TIFFSetErrorHandler(TIFFErrorHandler); 443 447 extern TIFFErrorHandlerExt TIFFSetErrorHandlerExt(TIFFErrorHandlerExt); -
trunk/src/3rdparty/libtiff/libtiff/tiffiop.h
r2 r846 1 /* $Id: tiffiop.h,v 1. 46 2006/03/16 12:22:27 dron Exp $ */1 /* $Id: tiffiop.h,v 1.51.2.1 2009-01-06 19:08:09 bfriesen Exp $ */ 2 2 3 3 /* … … 63 63 #endif 64 64 65 /* 66 Libtiff itself does not require a 64-bit type, but bundled TIFF 67 utilities may use it. 68 */ 69 typedef TIFF_INT64_T int64; 70 typedef TIFF_UINT64_T uint64; 71 65 72 #include "tiffio.h" 66 73 #include "tif_dir.h" … … 103 110 int tif_mode; /* open mode (O_*) */ 104 111 uint32 tif_flags; 105 #define TIFF_FILLORDER 0x000 3 /* natural bit fill order for machine */106 #define TIFF_DIRTYHEADER 0x000 4 /* header must be written on close */107 #define TIFF_DIRTYDIRECT 0x000 8 /* current directory must be written */108 #define TIFF_BUFFERSETUP 0x00 10 /* data buffers setup */109 #define TIFF_CODERSETUP 0x00 20 /* encoder/decoder setup done */110 #define TIFF_BEENWRITING 0x00 40 /* written 1+ scanlines to file */111 #define TIFF_SWAB 0x00 80 /* byte swap file information */112 #define TIFF_NOBITREV 0x0 100 /* inhibit bit reversal logic */113 #define TIFF_MYBUFFER 0x0 200 /* my raw data buffer; free on close */114 #define TIFF_ISTILED 0x0 400 /* file is tile, not strip- based */115 #define TIFF_MAPPED 0x0 800 /* file is mapped into memory */116 #define TIFF_POSTENCODE 0x 1000 /* need call to postencode routine */117 #define TIFF_INSUBIFD 0x 2000 /* currently writing a subifd */118 #define TIFF_UPSAMPLED 0x 4000 /* library is doing data up-sampling */119 #define TIFF_STRIPCHOP 0x 8000 /* enable strip chopping support */112 #define TIFF_FILLORDER 0x00003 /* natural bit fill order for machine */ 113 #define TIFF_DIRTYHEADER 0x00004 /* header must be written on close */ 114 #define TIFF_DIRTYDIRECT 0x00008 /* current directory must be written */ 115 #define TIFF_BUFFERSETUP 0x00010 /* data buffers setup */ 116 #define TIFF_CODERSETUP 0x00020 /* encoder/decoder setup done */ 117 #define TIFF_BEENWRITING 0x00040 /* written 1+ scanlines to file */ 118 #define TIFF_SWAB 0x00080 /* byte swap file information */ 119 #define TIFF_NOBITREV 0x00100 /* inhibit bit reversal logic */ 120 #define TIFF_MYBUFFER 0x00200 /* my raw data buffer; free on close */ 121 #define TIFF_ISTILED 0x00400 /* file is tile, not strip- based */ 122 #define TIFF_MAPPED 0x00800 /* file is mapped into memory */ 123 #define TIFF_POSTENCODE 0x01000 /* need call to postencode routine */ 124 #define TIFF_INSUBIFD 0x02000 /* currently writing a subifd */ 125 #define TIFF_UPSAMPLED 0x04000 /* library is doing data up-sampling */ 126 #define TIFF_STRIPCHOP 0x08000 /* enable strip chopping support */ 120 127 #define TIFF_HEADERONLY 0x10000 /* read header only, do not process */ 121 128 /* the first directory */ 129 #define TIFF_NOREADRAW 0x20000 /* skip reading of raw uncompressed */ 130 /* image data */ 131 #define TIFF_INCUSTOMIFD 0x40000 /* currently writing a custom IFD */ 122 132 toff_t tif_diroff; /* file offset of current directory */ 123 133 toff_t tif_nextdiroff; /* file offset of following directory */ 124 134 toff_t* tif_dirlist; /* list of offsets to already seen */ 125 135 /* directories to prevent IFD looping */ 136 tsize_t tif_dirlistsize;/* number of entires in offset list */ 126 137 uint16 tif_dirnumber; /* number of already seen directories */ 127 138 TIFFDirectory tif_dir; /* internal rep of current directory */ 139 TIFFDirectory tif_customdir; /* custom IFDs are separated from 140 the main ones */ 128 141 TIFFHeader tif_header; /* file's header block */ 129 142 const int* tif_typeshift; /* data type shift counts */ … … 170 183 /* memory-mapped file support */ 171 184 tidata_t tif_base; /* base of mapped file */ 172 toff_t tif_size; /* size of mapped file region (bytes) */ 185 toff_t tif_size; /* size of mapped file region (bytes) 186 FIXME: it should be tsize_t */ 173 187 TIFFMapFileProc tif_mapproc; /* map file method */ 174 188 TIFFUnmapFileProc tif_unmapproc;/* unmap file method */ … … 279 293 280 294 extern tdata_t _TIFFCheckMalloc(TIFF*, size_t, size_t, const char*); 295 extern tdata_t _TIFFCheckRealloc(TIFF*, tdata_t, size_t, size_t, const char*); 281 296 282 297 extern int TIFFInitDumpMode(TIFF*, int); -
trunk/src/3rdparty/libtiff/libtiff/tiffvers.h
r2 r846 1 #define TIFFLIB_VERSION_STR "LIBTIFF, Version 3. 8.2\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."1 #define TIFFLIB_VERSION_STR "LIBTIFF, Version 3.9.2\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." 2 2 /* 3 3 * This define can be used in code that requires … … 7 7 * string returned by TIFFGetVersion. 8 8 */ 9 #define TIFFLIB_VERSION 200 603239 #define TIFFLIB_VERSION 20091104 -
trunk/src/3rdparty/libtiff/nmake.opt
r2 r846 1 # $Id: nmake.opt,v 1.1 6 2006/03/23 14:54:01dron Exp $1 # $Id: nmake.opt,v 1.18 2006/06/07 16:33:45 dron Exp $ 2 2 # 3 3 # Copyright (C) 2004, Andrey Kiselev <dron@ak4719.spb.edu> … … 61 61 62 62 # 63 # Uncomment following lines to enable Old JPEG support64 # (modified IJG JPEG library required, read the contrib\ojpeg\README first).65 #66 #OJPEG_SUPPORT = 167 68 #69 63 # Uncomment and edit following lines to enable ZIP support 70 64 # (required for Deflate compression and Pixar log-format) … … 76 70 77 71 # 72 # Uncomment and edit following lines to enable ISO JBIG support 73 # 74 #JBIG_SUPPORT = 1 75 #JBIGDIR = d:/projects/jbigkit 76 #JBIG_INCLUDE = -I$(JBIGDIR)/libjbig 77 #JBIG_LIB = $(JBIGDIR)/libjbig/jbig.lib 78 79 # 78 80 # Uncomment following line to enable Pixar log-format algorithm 79 81 # (Zlib required). … … 111 113 # Pick debug or optimized build flags. We default to an optimized build 112 114 # with no debugging information. 113 # NOTE: / GXoption required if you want to build the C++ stream API114 # 115 OPTFLAGS = /Ox /MD / GX /W3115 # NOTE: /EHsc option required if you want to build the C++ stream API 116 # 117 OPTFLAGS = /Ox /MD /EHsc /W3 /D_CRT_SECURE_NO_DEPRECATE 116 118 #OPTFLAGS = /Zi 117 119 … … 182 184 !IFDEF JPEG_SUPPORT 183 185 LIBS = $(LIBS) $(JPEG_LIB) 184 EXTRAFLAGS = -DJPEG_SUPPORT $(EXTRAFLAGS) 185 !IFDEF OJPEG_SUPPORT 186 EXTRAFLAGS = -DOJPEG_SUPPORT $(EXTRAFLAGS) 187 !ENDIF 186 EXTRAFLAGS = -DJPEG_SUPPORT -DOJPEG_SUPPORT $(EXTRAFLAGS) 188 187 !ENDIF 189 188 … … 196 195 !ENDIF 197 196 197 !IFDEF JBIG_SUPPORT 198 LIBS = $(LIBS) $(JBIG_LIB) 199 EXTRAFLAGS = -DJBIG_SUPPORT $(EXTRAFLAGS) 200 !ENDIF 201 198 202 !IFDEF STRIPCHOP_SUPPORT 199 203 EXTRAFLAGS = -DSTRIPCHOP_DEFAULT=TIFF_STRIPCHOP -DSTRIP_SIZE_DEFAULT=$(STRIP_SIZE_DEFAULT) $(EXTRAFLAGS) -
trunk/src/3rdparty/libtiff/port/dummy.c
r2 r846 1 /* $Id: dummy.c,v 1.2 2005/07/07 15:21:52dron Exp $ */1 /* $Id: dummy.c,v 1.2.2.1 2007/03/21 14:53:46 dron Exp $ */ 2 2 3 3 /* … … 5 5 */ 6 6 7 staticvoid7 void 8 8 libport_dummy_function() 9 9 { -
trunk/src/3rdparty/libtiff/port/lfind.c
r2 r846 1 /* $Id: lfind.c,v 1. 3 2005/12/27 15:08:22 dronExp $ */1 /* $Id: lfind.c,v 1.4 2007/01/15 18:40:39 mloskot Exp $ */ 2 2 3 3 /* … … 38 38 #endif 39 39 40 #include <sys/types.h> 40 #ifdef _WIN32_WCE 41 # include <wce_types.h> 42 #else 43 # include <sys/types.h> 44 #endif 41 45 42 46 #ifndef NULL
Note:
See TracChangeset
for help on using the changeset viewer.