Compare commits

...
732 Commits
Author SHA1 Message Date
Even Rouault 685c73260e Merge branch 'theta682-fix-Oi-GFS' into 'master'
Fix parsing a private tag 0x80a6

Closes #647

See merge request libtiff/libtiff!661
2024-09-22 19:07:14 +00:00
Timothy Lyanguzov 7753fff93e Do not error out on a tag whose tag count value is zero, just issue a warning.
Fix parsing a private tag 0x80a6
2024-09-22 19:07:14 +00:00
Even Rouault 4dbeb487fa Merge branch 'fix_648_ASCII_length_at_WriteDirectorySec_codec_part' into 'master'
Increment string length for ASCII tags in TIFFWriteDirectorySec() for codec...

Closes #648

See merge request libtiff/libtiff!663
2024-09-21 18:23:06 +00:00
Su_Laus 6216805c10 Increment string length for ASCII tags in TIFFWriteDirectorySec() for codec tags defined with FIELD_xxx bits, as it is done for FIELD_CUSTOM tags.
Fixes #648
2024-09-21 19:03:09 +02:00
Even Rouault 9dff73bebc Merge branch '4_7_0_rc2' into 'master'
Fixes for 4.7.0rc2

See merge request libtiff/libtiff!660
2024-09-11 07:41:37 +00:00
Even Rouault 5650dd434b configure.ac: also look for python3.11 2024-09-11 01:30:52 +02:00
Even Rouault db5972e098 Update RELEASE-DATE 2024-09-11 01:17:02 +02:00
Even Rouault 9c97172706 Update ChangeLog for 3.7.0rc2 2024-09-11 01:16:21 +02:00
Even Rouault a60b9d75e9 configure.ac: make a provision to look for up to python 3.16 ...
hopefully we'll have ditched autoconf support at that point...
2024-09-11 01:13:32 +02:00
Even Rouault 94f6f7315b Fix test dependency on tiff2rgba-32BPP that breaks 'make check -jX' 2024-09-11 01:11:21 +02:00
Even Rouault b535e2bf6f test/tiff2ps*.sh scripts: try to use POSIX only diff flags 2024-09-11 01:11:21 +02:00
Even Rouault 95911a1c2c Merge branch 'automake_doc_fix' into 'master'
doc/Makefile.am: make sure that 'doc-html' and 'doc-man' targets have dependencies to avoid them to be rebuilt by successive make

See merge request libtiff/libtiff!657
2024-09-10 22:37:20 +00:00
Even Rouault 3d206dd424 Merge branch '4_7_0_rst_rgb2ycbcr_thumbnail' into 'master'
v4.7.0.rst: clarify that rgb2ycbcr and thumbnail are not installed

See merge request libtiff/libtiff!659
2024-09-10 21:31:15 +00:00
Even Rouault e81febb70f v4.7.0.rst: clarify that rgb2ycbcr and thumbnail are not installed 2024-09-10 22:03:54 +02:00
Even Rouault eba593294d doc/Makefile.am: make sure that 'doc-html' and 'doc-man' targets have dependencies to avoid them to be rebuilt by successive make 2024-09-08 17:00:36 +02:00
Even Rouault 88152bebaf doc/Makefile.am: move rst_sources and EXTRA_DIST variables on top of file 2024-09-08 16:59:48 +02:00
Even Rouault 81b26f034d Merge branch 'index_rst_formatting_issue' into 'master'
index.rst: fix formatting issue

See merge request libtiff/libtiff!656
2024-09-07 14:53:03 +00:00
Even Rouault 5087fe8507 index.rst: fix formatting issue 2024-09-07 16:52:25 +02:00
Even Rouault a664b35b96 Merge branch 'prepare_release_4_7_0' into 'master'
Prepare release 4.7.0

See merge request libtiff/libtiff!654
2024-09-07 14:50:40 +00:00
Even Rouault f8dd26d304 Doc: remove 'Master' terminlogy 2024-09-07 13:19:53 +02:00
Even Rouault d40aa2dba4 v4.7.0.rst: remove mention about autoconf-archive since that change has been reverted 2024-09-07 13:19:53 +02:00
Even Rouault 0d6e6bc228 Revert "autotools: allow pulling in updated macros from autoconf-archive"
This reverts commit c820d16c30.
2024-09-07 13:19:53 +02:00
Even Rouault a55124f960 Revert "HOWTO-RELEASE: document the necessary dependencies for producing dist tarballs"
This reverts commit f1a91e42b3.
2024-09-07 13:19:53 +02:00
Even Rouault ea53869fb6 Revert "configure.ac: fix HAVE_OPENGL determination due to recent changes"
This reverts commit c370e67f7fd9320674544113218b7fbca4f65c2b.
2024-09-07 13:19:53 +02:00
Even Rouault a7cb83ff00 configure.ac: fix HAVE_OPENGL determination due to recent changes 2024-09-07 13:19:53 +02:00
Even Rouault 02230f5642 Update version numbers for 4.7.0 2024-09-07 13:19:53 +02:00
Even Rouault cadfff2e1d Update ChangeLog and create release notes for v4.7.0 2024-09-07 13:19:53 +02:00
Even Rouault eccbe7112e typo fixes 2024-09-06 17:53:58 +02:00
Even Rouault 6589e863d8 Merge branch 'autoconf-archive' into 'master'
autotools: allow pulling in updated macros from autoconf-archive

See merge request libtiff/libtiff!645
2024-09-06 14:58:17 +00:00
Even Rouault 6272852b8d Merge branch 'remove_last_usage_of_get_field_type' into 'master'
Change last usage of get_field_type at TIFFWriteDirectorySec() to set_field_type

See merge request libtiff/libtiff!653
2024-09-06 14:25:09 +00:00
Su_Laus d1487d7be3 Change last usage of get_field_type at TIFFWriteDirectorySec() for codec related tags to set_field_type. 2024-09-05 18:21:06 +02:00
Eli Schwartz f1a91e42b3 HOWTO-RELEASE: document the necessary dependencies for producing dist tarballs 2024-09-03 12:44:16 -04:00
Eli Schwartz 8929277ee7 autogen.sh: actually return failure if any step failed
Previously, it exited with failure if and only if the wget calls failed.
But it is possible for any command to fail, e.g. if the autotools are
broken, misconfigured, or missing dependencies.
2024-09-03 12:44:16 -04:00
Eli Schwartz c820d16c30 autotools: allow pulling in updated macros from autoconf-archive
Instead of inlining a few macros in acinclude.m4 and forgetting about
them, teach aclocal to install the macros to m4/ when autoreconf is run.
They are no longer tracked in one big file, nor tracked at all in git,
but producing dist tarballs will bundle them up just like `configure`
and `Makefile.in`.

Note: previous behavior of AX_CHECK_GL* was to simply ignore support and
proceed, if it was asked for and not found. The updated macros expect to
opt into this by specifying action-if-not-found.

VL_* is obsolete. Upgrade to AX_CFLAGS_WARN_ALL.
2024-09-03 12:44:16 -04:00
Even Rouault 6d616b716d Merge branch 'XZY2RGB' into 'master'
Fixes #644 Index comparison as size_t to avoid overflow in TIFFXYZToRGB

Closes #644

See merge request libtiff/libtiff!649
2024-09-03 12:33:47 +00:00
Nicolas Badoux 1c7b4f59c4 Fixes #644 Index comparison as size_t to avoid overflow in TIFFXYZToRGB 2024-09-03 12:33:47 +00:00
Even Rouault 821e91d79e Merge branch 'ci_werror' into 'master'
CI: build with -Wall -Wextra -Werror

See merge request libtiff/libtiff!652
2024-09-01 10:01:33 +00:00
Even Rouault f00e8166da configure.ac: avoid -Werror passed to CFLAGS to interfere with feature detection 2024-08-30 23:05:39 +02:00
Even Rouault 36cbce4d58 CI: build with -Wall -Wextra -Werror 2024-08-30 22:38:38 +02:00
Roger Leigh f59f4a0d43 Merge branch 'ci-old-update' into 'master'
ci: Update "old" build jobs to use Ubuntu 22.04

See merge request libtiff/libtiff!651
2024-08-30 11:12:33 +00:00
Roger Leigh fa7a5b36a5 ci: Update "old" build jobs to use Ubuntu 22.04 2024-08-30 10:49:14 +01:00
Even Rouault 9d6c745d68 Merge branch 'ci-ubuntu-22.04' into 'master'
ci: Update to use Ubuntu 24.04 CI images

See merge request libtiff/libtiff!650
2024-08-29 23:28:54 +00:00
Roger Leigh 3cdffebd6d ci: Update to use Ubuntu 24.04 CI images 2024-08-29 23:35:19 +01:00
Even Rouault 8e269601ce Merge branch 'uv_encode' into 'master'
Fix #645 by using unsigned int for variable indexing an array in uv_decode() and uv_encode()

Closes #645

See merge request libtiff/libtiff!648
2024-08-28 10:38:26 +00:00
Nicolas Badoux c2789e2dc1 Fix #645 by using unsigned int for variable indexing an array in uv_decode() and uv_encode()
Change `vi` to unsigned int in `uv_decode()` and `uv_encode()` to ensure that upper bound `UV_NVS` cannot be satisfied by a negative value which will overflow when cast to an unsigned value at array access time. This fixes issue #645 where a segmentation fault was caused.
2024-08-28 10:38:26 +00:00
Even Rouault 6360737552 Merge branch 'fix_643_solitary_CustomDirectory_read' into 'master'
Fix #643 by initializing pointer to TIFFSetField() and TIFFGetField() before TIFFReadGPSDirectory

Closes #643

See merge request libtiff/libtiff!647
2024-08-27 21:45:54 +00:00
Su Laus 986f906ed0 Fix #643 by initializing pointer to TIFFSetField() and TIFFGetField() before TIFFReadGPSDirectory
Initialize pointer to TIFFSetField() and TIFFGetField() (i.e. tif-\>tif_tagmethods.vsetfield and tif-\>tif_tagmethods.vgetfield) even if the file is opened with "h" option. This fixes issue #643 where a segmentation fault was caused.
2024-08-27 21:45:54 +00:00
Even Rouault b00d0060ba Merge branch 'tiff_strip' into 'master'
Add non-zero check before division in TIFFComputeStrip

See merge request libtiff/libtiff!646
2024-08-25 15:20:49 +00:00
Nicolas Badoux 27fc7da3f0 Add non-zero check before division in TIFFComputeStrip 2024-08-23 11:46:17 +02:00
Even Rouault 9a19607464 Merge branch 'fix_564' into 'master'
TIFFScanlineSize64(): revert merge request #564

See merge request libtiff/libtiff!644
2024-08-15 21:35:07 +00:00
Even Rouault 8f8916c1d3 TIFFScanlineSize64(): revert merge request #564
https://gitlab.com/libtiff/libtiff/-/merge_requests/564 broke decoding of: "tools/tiffcp -c none in.tif out.tif"
with [in.tif](/uploads/0475a88cf6e66652b030a0a3a0c47313/in.tif)
leading to shift each line of the target image by one extra pixel at each line.
Unfortunately, this cancels what https://gitlab.com/libtiff/libtiff/-/merge_requests/564 tried to fix. I'll let @caolanm propose an alternative fix in a follow-up merge request
2024-08-15 23:34:34 +02:00
Even Rouault de67665367 Merge branch 'coverity_fix_from_MR_634' into 'master'
Fix some Coverity Scan issues introduced by MR 634.

See merge request libtiff/libtiff!643
2024-08-15 20:50:54 +00:00
Su_Laus e5bacb710f Fix some Coverity Scan issues introduced by MR 634. 2024-08-14 21:03:04 +02:00
Even Rouault 9f528cd1d0 Merge branch 'lerc-pkgconfig' into 'master'
libtiff-4.pc: Fix `Requires.private` missing `Lerc`.

See merge request libtiff/libtiff!633
2024-08-11 16:02:39 +00:00
Even Rouault 942e1d5787 Merge branch 'manpage_update_directory_incrementing' into 'master'
Amend manpages for changes in current directory index behaviour.

See merge request libtiff/libtiff!639
2024-08-11 16:01:27 +00:00
Su Laus dbdda56243 Amend manpages for changes in current directory index behaviour. 2024-08-11 16:01:26 +00:00
Even Rouault 6357fdfe72 Merge branch 'tiffcrop_coverity_20240723' into 'master'
Attempt to address tiffcrop Coverity scan issues 1605444, 1605445, and 1605449.

See merge request libtiff/libtiff!642
2024-08-11 16:01:07 +00:00
Lee Howard 8a7a48d7a6 Attempt to address tiffcrop Coverity scan issues 1605444, 1605445, and 1605449. 2024-08-11 16:01:07 +00:00
Even Rouault 05cc3842bc Merge branch 'fix_CurDir_wrong_incrementing' into 'master'
Fix cases where tif_curdir is set incorrectly

See merge request libtiff/libtiff!634
2024-08-11 15:59:39 +00:00
Su Laus 5eb068a4cd Fix cases where tif_curdir is set incorrectly
Fix cases where the current directory number (tif_curdir) is set inconsistently or incorrectly, depending on the previous history.

See additional checks and tests in test/test_directory.c of this MR for intended setting of tif_curdir (i.e. TIFFCurrentDirectory(tif)).
2024-08-11 15:59:39 +00:00
Even Rouault 2653d1f860 Merge branch 'coverity_fixes_tiff2pdf_#2' into 'master'
Try to fix additional Coverity issues in tiff2pdf

See merge request libtiff/libtiff!641
2024-07-12 16:45:44 +00:00
Su Laus 2c020586ef Try to fix additional Coverity issues in tiff2pdf 2024-07-12 16:45:43 +00:00
Even Rouault e847ff922d Merge branch 'fix_autoconf_diff_parameter_crlf' into 'master'
Add parameter for "diff" used in autoconf test scripts to ignore LF and CRLF differences.

See merge request libtiff/libtiff!640
2024-07-10 18:49:08 +00:00
Even Rouault 3688f59a88 Merge branch 'coverity_fixes_tiff2pdf' into 'master'
Fix Coverity issues in tiff2pdf.

See merge request libtiff/libtiff!638
2024-07-09 14:04:31 +00:00
Su Laus 62d76b6942 Fix Coverity issues in tiff2pdf. 2024-07-09 14:04:30 +00:00
Su_Laus 07ad8fc313 Add parameter for "diff" used in autoconf test scripts to ignore LF and CRLF differences. 2024-06-29 22:27:50 +02:00
Even Rouault 7a3fb2deb1 Merge branch 'coverity_fixes_test_thumbnail' into 'master'
Coverity Scan fixes in thumbnail.c and custom_dir_EXIF_231.c

See merge request libtiff/libtiff!637
2024-06-28 13:36:36 +00:00
Su Laus fe77ab2933 Coverity Scan fixes in thumbnail.c and custom_dir_EXIF_231.c 2024-06-28 13:36:35 +00:00
Even Rouault 15a6e537df Merge branch 'coverity_fixes' into 'master'
Try to silence new Coverity Scan false positives

See merge request libtiff/libtiff!636
2024-06-25 21:00:45 +00:00
Even Rouault dd29a569fb Try to silence new Coverity Scan false positives
There are other warnings in tools/ that I'll let others deal with.
2024-06-24 22:27:26 +02:00
Even Rouault b8ac0e1a08 Merge branch 'fix/make' into 'master'
fix: error when running make clean

Closes #630

See merge request libtiff/libtiff!635
2024-06-24 19:19:37 +00:00
Kévin Dunglas e9aeaa60bf fix: error when running make clean 2024-06-24 10:10:21 +02:00
Niklas Hambüchen ea882c3c24 libtiff-4.pc: Fix Requires.private missing Lerc.
It provides a `.pc` file starting from version 4 in:

https://github.com/Esri/lerc/blob/8d6e8251544bbe1379feb0fe0a0934e43ca1a6cd/Lerc.pc.in

libtiff's CMake build system already has support for this,
adding `Lerc` to `Requires.private` if Lerc is >= 4.

In contrast to the CMake build system, autoconf has no good way
to check for checking the Lerc version, we do it unconditionally
there.
2024-06-15 19:22:08 +02:00
Even Rouault 03666cb5fd Merge branch 'rfc02_text__restore_tools' into 'master'
Text for RFC 2: Restoring needed libtiff tools

See merge request libtiff/libtiff!581
2024-06-13 18:24:50 +00:00
Even Rouault 1baa2ae009 Merge branch 'add_some_conversion_test_to_cmake' into 'master'
Port some basic sanity checks from autoconf to cmake.

See merge request libtiff/libtiff!630
2024-06-13 18:24:06 +00:00
Even Rouault 4ff9b5bd57 Merge branch 'tiffcp_coverity_check_malloc_return' into 'master'
tiffcp: Add check for limitMalloc return to fix Coverity CID 1603334

See merge request libtiff/libtiff!632
2024-06-10 20:10:54 +00:00
Su_Laus e59805a542 tiffcp add check for limitMalloc return to fix Coverity CID 1603334 2024-06-10 21:25:51 +02:00
Even Rouault 6507678444 Merge branch 'aim-nara-master-patch-67955' into 'master'
Remove unnecessary `2` in tiffcmp name

See merge request libtiff/libtiff!631
2024-06-07 12:36:04 +00:00
AIM | Nara be023be419 Remove unnecessary 2 in tiffcmp name 2024-06-07 12:36:04 +00:00
Su_Laus 27cb3445f8 Port some basic sanity checks from autoconf to cmake.
Checks are for tiffcp and tiffcrop RGB->YCbCr JPEG conversions (see MR !611 / 'tiffcp_tiffcrop_RGB_YCbCr_tests')
2024-05-30 23:25:18 +02:00
Even Rouault 4e63559f2b Merge branch 'ofz65182' into 'master'
an issue seen in putcontig8bitYCbCr22tile

See merge request libtiff/libtiff!564
2024-05-29 10:08:24 +00:00
Caolán McNamara 706e895071 TIFFScanlineSize64(): fix computation in non-JPEG YCbCr case (#564)
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65182
2024-05-29 10:08:24 +00:00
Even Rouault 23194d8dc1 Merge branch 'fix_375' into 'master'
TIFFRead[Scanline/EncodedStrip/EncodeTile]: 0-initialize output buffer if setupdecode fails ; most codecs: zero-initialize (not-yet-written parts of) output buffer if failure

Closes #375

See merge request libtiff/libtiff!628
2024-05-29 10:03:14 +00:00
Even Rouault 08e11fcab4 Merge branch 'tiff2pdf-planar' into 'master'
Inconsistent PLANARCONFIG value for the input and output TIFF in tiff2pdf.c

See merge request libtiff/libtiff!629
2024-05-29 10:02:56 +00:00
Timothy Lyanguzov f600f4783f Inconsistent PLANARCONFIG value for the input and output TIFF in tiff2pdf.c
Fixed a bug in tiff2pdf.c whereas the PLANARCONFIG for the output TIFF is set to a fixed value of PLANARCONFIG_CONTIG as opposed to match the value of the input TIFF.
This mainly manifest in the heap-buffer-overread due to the difference of sizes in the buffers (between input and output) allocated and read to the size of output buffer.

Reimplementation of !92
2024-05-29 16:06:05 +12:00
Even Rouault 3c73bd4e3f tif_lzma/tif_lzw: add code comments 2024-05-27 23:33:21 +02:00
Even Rouault ffdae44185 ZSTDDecode: zero-initialize (not-yet-written parts of) output buffer if failure 2024-05-26 19:59:57 +02:00
Even Rouault 5a5f71ebed PixarLogDecode: zero-initialize output buffer if failure 2024-05-26 19:58:23 +02:00
Even Rouault 2fc4422e3c PackBitsDecode: zero-initialize (not-yet-written parts of) output buffer if failure 2024-05-26 19:57:08 +02:00
Even Rouault 585b795bd3 JPEGDecode: zero-initialize (not-yet-written parts of) output buffer if failure 2024-05-26 19:55:44 +02:00
Even Rouault b8d67338a4 LERCDecode: zero-initialize output buffer if failure 2024-05-26 19:53:44 +02:00
Even Rouault 0171fffd8b LZMADecode: zero-initialize (not-yet-written parts of) output buffer if failure, and handle repeated calls to decoding same tile/strip if previous failure occured 2024-05-26 19:52:53 +02:00
Even Rouault 0b13e4c54e TWebPDecode: zero-initialize output buffer if failure, and handle repeated calls to decoding same tile/strip if previous failure occured 2024-05-26 19:50:31 +02:00
Even Rouault 5576398153 ThunderDecode: zero-initialize (not-yet-written parts of) output buffer if failure 2024-05-26 19:49:48 +02:00
Even Rouault 5dd28a6d5d OJPEGDecode: zero-initialize output buffer if failure 2024-05-26 19:49:27 +02:00
Even Rouault dcfd41ac4e JBIGDecode: zero-initialize (not-yet-written parts of) output buffer if failure 2024-05-26 19:49:14 +02:00
Even Rouault 60c7dd4b17 ZIPDecode: zero-initialize (not-yet-written parts of) output buffer if failure, and handle repeated calls to decoding same tile/strip if previous failure occured 2024-05-26 19:48:58 +02:00
Even Rouault a455f07aa0 LZWDecode: zero-initialize (not-yet-written parts of) output buffer if failure 2024-05-26 19:48:23 +02:00
Even Rouault 28c38d648b TIFFRead[Scanline/EncodedStrip/EncodeTile]: 0-initialize output buffer if setupdecode fails
Fixes #375
2024-05-26 19:47:19 +02:00
Su_Laus 00a7af3b4c Text for RFC 2: Restoring needed libtiff tools - file added to doc/Makefile.am and rebased. 2024-05-25 21:02:43 +02:00
Su_Laus 969ec37b5d Text for RFC 2: Restoring needed libtiff tools - approved with voting history updated. 2024-05-25 20:59:59 +02:00
Su_Laus e3b387e000 Text for RFC 2: Restoring needed libtiff tools - further amended 2024-05-25 20:59:59 +02:00
Su_Laus c785239cdc Text for RFC 2: Restoring needed libtiff tools - amended 2024-05-25 20:59:58 +02:00
Su_Laus aed77c7271 Text for RFC 2: Restoring needed libtiff tools 2024-05-25 20:59:58 +02:00
Even Rouault 9676263f0a Merge branch 'tiff2pdf_539' into 'master'
fix tiff2pdf issue #539; however, there certainly remain many JPEG-compressed...

See merge request libtiff/libtiff!597
2024-05-23 17:30:44 +00:00
Lee Howard a6db4dba26 tiff2pdf: fix issue with JPEG restart-interval marker when converting from JPEG-compressed files
Fixes #539

however, there certainly remain many JPEG-compressed TIFFs which tiff2pdf will fumble without disabling data passthrough (using the -n option) - I supect that it has to do with the JPEG tables being removed from the JPEG and placed into the TIFF headers - as tiff2pdf would need to put these back into the JPEG instead of just passing the data through to the PDF
2024-05-23 17:30:43 +00:00
Even Rouault d4149c6ea0 Merge branch 'test_fix' into 'master'
test/Makefile.am: make sure that all test images are bundled by make dist even...

See merge request libtiff/libtiff!626
2024-05-22 20:47:26 +00:00
Even Rouault a47d88dfe5 Merge branch 'add_missing_rst_files' into 'master'
doc/Makefile.am: add rfcs/ files in rst_sources variable

See merge request libtiff/libtiff!624
2024-05-22 03:13:52 +00:00
Even Rouault ac0dc61642 test/Makefile.am: make sure that all test images are bundled by make dist even if JPEG or JBIG is not available 2024-05-22 04:38:00 +02:00
Even Rouault e41d6f7f6d Merge branch 'timothyl/32bpp-cmake-test' into 'master'
Add new test to CMake

See merge request libtiff/libtiff!625
2024-05-22 02:37:42 +00:00
Timothy Lyanguzov c8473efc35 Add new test to CMake
See previous merge request libtiff/libtiff!611
2024-05-22 14:20:57 +12:00
Even Rouault deb4fc9dc8 doc/Makefile.am: add rfcs/ files in rst_sources variable 2024-05-22 04:12:08 +02:00
Even Rouault 360f37108f Merge branch 'tiffcp_tiffcrop_RGB_YCbCr_tests' into 'master'
Add some basic sanity checks for tiffcp and tiffcrop RGB->YCbCr JPEG conversions.

See merge request libtiff/libtiff!611
2024-05-22 01:42:18 +00:00
Lee Howard 5d8db4b5af Add some basic sanity checks for tiffcp and tiffcrop RGB->YCbCr JPEG conversions. 2024-05-22 01:42:18 +00:00
Even Rouault 72bd93dd2b Merge branch 'tiffcp_LZW_JBIG_test' into 'master'
Add basic sanity check for tiffcp LZW->JBIG conversion.

See merge request libtiff/libtiff!612
2024-05-21 21:35:45 +00:00
Even Rouault 693d7bc0f5 Merge branch 'tiffcrop_masonwilde_fix' into 'master'
Apply "Fix heap-buffer-overflow in function extractImageSection"

See merge request libtiff/libtiff!613
2024-05-21 21:35:02 +00:00
Lee Howard cffd2852c4 tiffcrop: Apply "Fix heap-buffer-overflow in function extractImageSection"
https://gitlab.com/masonwilde/libtiff/-/commit/848434a81c443f59ec90d41218eba6e48a450a11

authored by zhailiangliang commit 848434a81c443f59ec90d41218eba6e48a450a11

The overflow conditions were previously addressed, but this provides additional error messages.
2024-05-21 21:35:02 +00:00
Even Rouault 845243dbf0 Merge branch 'fix_183_alternative' into 'master'
OJPEG: reset subsampling_convert_state =0 in OJPEGPreDecode (fixes tiff2pdf issue #183)

See merge request libtiff/libtiff!621
2024-05-21 21:33:30 +00:00
Even Rouault 178c3ec53e Merge branch 'thunder-fix' into 'master'
A fix for Thunder RLE

See merge request libtiff/libtiff!623
2024-05-21 21:28:51 +00:00
Timothy Lyanguzov 7dc39d1820 A fix for Thunder RLE
The commit https://gitlab.com/robinwatts/libtiff/-/commit/be0519ca3d222c19008fe160873f3b5c28e6b36b states:

Thunder RLE can fail to decode last run. Bug seen with GhostPDL. Decode of test tif file gives valgrind errors due to the "thunder decode" failing to extract the final run of compressed pixels.

The logic in the decoder, presumably intended to spot overruns of data, is incorrect in that runs that end at the end of a row (npixels == maxpixels) will not be decoded.

Fix this by limiting 'n', the number of pixels to copy. Note that npixels is updated by the 'unlimited' value to ensure the error reporting at the end of the loop still works.
2024-05-21 21:28:51 +00:00
Even Rouault 80b47cbc63 Merge branch 'tiff2ps_fax2tiff_476' into 'master'
fix fax2ps and fax2tiff bugs #476

See merge request libtiff/libtiff!598
2024-05-18 16:17:10 +00:00
Lee Howard 462f1f475f Fix fax2ps and fax2tiff memory leaks.
Fixes #476
2024-05-18 16:17:10 +00:00
Even Rouault f3d5c259a5 Merge branch 'tiff2rgba_469' into 'master'
fix tiff2rgba issue #469

See merge request libtiff/libtiff!600
2024-05-17 17:40:04 +00:00
Even Rouault 0d92971bcb Merge branch 'formatting-fixes' into 'master'
Formatting fixes

See merge request libtiff/libtiff!622
2024-05-17 16:45:38 +00:00
Even Rouault 699c7d4cbd Formatting fixes 2024-05-17 18:45:05 +02:00
Even Rouault fb0adc29d6 Merge branch 'coverity_fixes' into 'master'
3 Coverity Scan fixes in tools & contrib

See merge request libtiff/libtiff!592
2024-05-17 16:35:41 +00:00
Even Rouault 8528b2efcc Merge branch 'tiff2pdf_596' into 'master'
tiff2pdf issue #596

See merge request libtiff/libtiff!594
2024-05-17 16:35:20 +00:00
Even Rouault c798b6d73e Merge branch 'tiffdither_473' into 'master'
fix tiffdither bug #473

See merge request libtiff/libtiff!599
2024-05-17 16:32:27 +00:00
Even Rouault e0523817f3 Merge branch 'fax2tiff_468' into 'master'
fix fax2tiff issue #468

See merge request libtiff/libtiff!601
2024-05-17 16:26:38 +00:00
Even Rouault dee840de72 Merge branch 'tiff2rgba_background' into 'master'
Add background gradient option for tiff2rgba alpha compositing.

See merge request libtiff/libtiff!610
2024-05-17 16:26:07 +00:00
Lee Howard 5da038136c Add background gradient option for tiff2rgba alpha compositing. 2024-05-17 16:26:07 +00:00
Even Rouault 7f785d921a Merge branch 'tiff2pdf_253' into 'master'
Fix tiff2pdf issue #253 - red and blue were being swapped for RGBA decoding

See merge request libtiff/libtiff!603
2024-05-17 16:19:50 +00:00
Even Rouault 5abbbaa014 Merge branch 'fax2tiff_249' into 'master'
Fix fax2tiff issue #249, unreasonable width input

See merge request libtiff/libtiff!604
2024-05-17 16:15:46 +00:00
Even Rouault b72ff5be4e Merge branch 'tiffcp_tiffcrop_228' into 'master'
correct tiffcp and tiffcrop issue #228

See merge request libtiff/libtiff!605
2024-05-17 16:15:01 +00:00
Even Rouault 4d80f0a0c7 OJPEG: reset subsampling_convert_state =0 in OJPEGPreDecode (fixes tiff2pdf issue #183) 2024-05-17 18:06:02 +02:00
Even Rouault bbd0873cff Merge branch 'fax2tiff_191' into 'master'
Fix fax2tiff issue #191 - EOFB interpretation

See merge request libtiff/libtiff!606
2024-05-17 15:52:23 +00:00
Even Rouault de4eb41ff3 Merge branch 'tiff2pdf_98' into 'master'
Fix tiff2pdf documentation issue #98

See merge request libtiff/libtiff!608
2024-05-17 15:26:52 +00:00
Even Rouault 29d7641553 Merge branch 'tiffgt_warning' into 'master'
Avoids a warning regarding fallthrough.

See merge request libtiff/libtiff!609
2024-05-17 15:25:31 +00:00
Even Rouault 1b74e216e7 Merge branch 'tiffcrop_542_550_552' into 'master'
tiffcrop: fixes #542, #550, #552 (buffer overflows, use after free)

See merge request libtiff/libtiff!595
2024-05-17 15:11:10 +00:00
Lee Howard a20298c478 tiffcrop: fixes #542, #550, #552 (buffer overflows, use after free) 2024-05-17 15:11:10 +00:00
Even Rouault 1398819a20 Merge branch 'Fedora_am_version' into 'master'
libtiff-am-version.patch from Fedora stating:

See merge request libtiff/libtiff!617
2024-05-17 14:29:37 +00:00
Even Rouault c0b80d25ec Merge branch 'formatting-fixes' into 'master'
Code formatting fixes

See merge request libtiff/libtiff!620
2024-05-17 13:02:47 +00:00
Even Rouault 8833b848d3 Code formatting fixes
Result of running ``pre-commit run --all``
2024-05-17 15:01:55 +02:00
Even Rouault 9a23b3c4c5 Merge branch 'sphinx_quotes_dashes' into 'master'
Don't let Sphinx inconsistently alter quotes and dashes in rst files.

See merge request libtiff/libtiff!615
2024-05-17 12:57:32 +00:00
Even Rouault c4b8c35a84 Merge branch 'tiffmedian_599' into 'master'
tiffmedian issue #599

See merge request libtiff/libtiff!593
2024-05-17 12:52:30 +00:00
Lee Howard 04118f8a42 tiffmedian: fix memory leaks
Closes #599
2024-05-17 12:52:30 +00:00
Even Rouault 3f84a2b453 Merge branch 'more_spelling_corrections' into 'master'
Typo fixes following...

See merge request libtiff/libtiff!618
2024-05-17 12:49:22 +00:00
Lee Howard 51d00bc6d5 Typo fixes following https://gitlab.com/libtiff/libtiff/-/commit/c95c77350820e19c8e273925bc97259727d19695 2024-05-16 16:43:45 -07:00
Lee Howard dfb4383686 libtiff-am-version.patch from Fedora stating:
Back off the minimum required automake version to 1.11.  There isn't
anything in libtiff currently that actually requires 1.12, and changing
this allows the package to be built on pre-F18 machines for easier testing.
2024-05-16 12:54:47 -07:00
Lee Howard e1fee35139 Don't let Sphinx inconsistently alter quotes and dashes in rst files.
Author: Laszlo Boszormenyi (GCS) <gcs@debian.org>
Bug-Debian: https://bugs.debian.org/1028456
2024-05-16 12:52:32 -07:00
Lee Howard d4253ba1d3 Add basic sanity check for tiffcp LZW->JBIG conversion. 2024-05-16 12:43:09 -07:00
Lee Howard 6c40341116 Avoids a warning regarding fallthrough. 2024-05-16 12:35:48 -07:00
Lee Howard 8825c4b021 Fix tiff2pdf documentation issue #98 2024-05-16 12:33:13 -07:00
Lee Howard dfd5e8fda0 Fix fax2tiff issue #191 - EOFB interpretation 2024-05-16 12:30:04 -07:00
Lee Howard 41bb7c3a85 Update tiffcp.c 2024-05-16 19:26:59 +00:00
Lee Howard dee5bda6c0 Correct tiffcrop output of RGB JPEG and tiffcp/tiffcrop documentation - issue #228 2024-05-16 12:11:14 -07:00
Lee Howard 251395dd28 Fix tiffcp and tiffcrop issue 228 - step 1 2024-05-16 12:11:10 -07:00
Lee Howard 58b32c8ea6 Fix fax2tiff issue #249, unreasonable width input 2024-05-16 12:08:09 -07:00
Lee Howard d753cc15a2 Fix tiff2pdf issue #253 - red and blue were being swapped for RGBA decoding 2024-05-16 12:06:39 -07:00
Lee Howard 928fc695df fix fax2tiff issue #468 2024-05-16 11:39:47 -07:00
Lee Howard 6c778e6b1f fix tiff2rgba issue #469 2024-05-16 11:38:00 -07:00
Lee Howard d7bdca8c4b fix tiffdither bug #473 2024-05-16 11:36:12 -07:00
Lee Howard 99554bc7b7 tiff2pdf issue #596 2024-05-16 10:57:00 -07:00
Even Rouault 2454463357 contrib/addtiffo: validate return of TIFFWriteEncodedXXXX() calls (CID 1024680) 2024-05-16 18:50:46 +02:00
Even Rouault 4b0bbcfacf tiffdump.c: fix wrong printf formattre in error message (CID 1472932) 2024-05-16 18:49:50 +02:00
Even Rouault 6fd7d51025 tiffset.c: avoid false positive Coverity Scan warning on 64-bit builds (CID 1518997) 2024-05-16 18:49:21 +02:00
Even Rouault e924dd999f Merge branch 'master' into 'master'
Fix some Coverity warnings.

See merge request libtiff/libtiff!590
2024-05-16 16:13:28 +00:00
Lee Howard b4ca093e73 Fix some Coverity warnings. 2024-05-16 16:13:28 +00:00
Even Rouault b94c2313ce Merge branch 'revert_tools_removement' into 'master'
Restore tools from archive and unsupported and tiffcp -i option with revert.

See merge request libtiff/libtiff!589
2024-05-13 15:42:26 +00:00
Su_Laus a6cd5e5960 Apply some newer changes to the reverted code and prepare note for 4.7.0. 2024-05-11 17:03:29 +02:00
Su_Laus 1c3ecce849 Revert "Remove -i option (ignore errors) from tiffcp, because almost all fuzzer issues were consequential errors from ignored errors because of the "-i" option."
This reverts commit 280a568ae8.
2024-05-11 16:52:35 +02:00
Su_Laus 9ab54a8580 Revert "Move most TIFF tools to archive and keep some as unsupported (see #580)."
This reverts commit eab89a627f.

# Conflicts:
#	tools/unsupported/CMakeLists.txt
#	tools/unsupported/tif_tools-unsupported_versioninfo.rc
2024-05-11 16:49:55 +02:00
Even Rouault 2af10009a5 Merge branch 'calloc-transposed-args' into 'master'
Fix -Werror=calloc-transposed-args with gcc 14

See merge request libtiff/libtiff!588
2024-05-10 14:40:56 +00:00
Even Rouault 2d1e74dbd1 Fix -Werror=calloc-transposed-args with gcc 14 2024-05-10 15:38:55 +02:00
Even Rouault 20503843ab Merge branch 'EvaluateIFDdatasizeReading_ossfuzz_68327' into 'master'
EvaluateIFDdatasizeReading(): avoid unsigned integer overflow (master only)

See merge request libtiff/libtiff!586
2024-05-09 17:48:51 +00:00
Even Rouault ce1477da0b EvaluateIFDdatasizeReading(): avoid unsigned integer overflow (master only)
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=68327
2024-04-27 12:57:03 +02:00
Even Rouault cf0bdb6729 Merge branch 'ci-appveyor-cygwin-upgrade' into 'master'
appveyor: Upgrade cygwin packages

See merge request libtiff/libtiff!585
2024-04-25 14:59:03 +00:00
Roger Leigh b4acdea3e7 appveyor: Upgrade cygwin packages 2024-04-25 13:40:25 +01:00
Even Rouault 1ae923da26 Merge branch 'libjpeg_turbo_3_0' into 'master'
Change messages/comments refering libjpeg-turbo 2.2 to 3.0

See merge request libtiff/libtiff!584
2024-04-25 11:12:55 +00:00
Even Rouault a56c5a0975 Change messages/comments refering libjpeg-turbo 2.2 to 3.0
libjpeg-turbo 2.2 was actually released as 3.0. Reflect that
2024-04-24 22:42:54 +02:00
Even Rouault b2387f3324 Merge branch 'EvaluateIFDdatasizeReading_unsigned_int_overflow_fix' into 'master'
EvaluateIFDdatasizeReading(): avoid potential unsigned integer overflow on corrupted tag

See merge request libtiff/libtiff!582
2024-04-22 18:10:54 +00:00
Even Rouault 87d39ea1b9 EvaluateIFDdatasizeReading(): avoid potential unsigned integer overflow on corrupted tag 2024-04-22 18:10:54 +00:00
Even Rouault c503d6a65b Merge branch 'tif_dir_logging-627' into 'master'
tif_dir.c: Log source file, line number, and input tif for directory count error.

Closes #627

See merge request libtiff/libtiff!583
2024-04-22 11:14:46 +00:00
Kurt Schwehr 358b1938e1 tif_dir.c: Log source file, line number, and input tif for directory count error. 2024-04-22 11:14:46 +00:00
Even Rouault c5c9e6f077 Merge branch 'fix_readrgbastrip_fpe' into 'master'
Avoiding FPEs (division by zero) in tif_getimage.c

See merge request libtiff/libtiff!580
2024-04-14 10:01:26 +00:00
Zurab Tsinadze 5e9d713ed4 Avoid FPEs (division by zero) in tif_getimage.c 2024-04-09 23:52:40 +02:00
Even Rouault 5ebecad3d4 Merge branch 'appveyor-vs2022' into 'master'
appveyor: Add VS2022 builds

See merge request libtiff/libtiff!579
2024-04-06 20:39:25 +00:00
Roger Leigh 91d24c2585 appveyor: Add VS2022 builds 2024-04-06 20:39:25 +00:00
Roger Leigh a4a26fc753 Merge branch 'appveyor-mingw-fix' into 'master'
appveyor: Use MinGW-w64

See merge request libtiff/libtiff!578
2024-04-04 10:07:54 +00:00
Roger Leigh e217f9d5a0 appveyor: Use MinGW-w64 2024-04-04 10:47:11 +01:00
Even Rouault 4d019acf96 Merge branch 'update_rfc1_status' into 'master'
RFC1: update status to adopted

See merge request libtiff/libtiff!577
2024-04-03 20:24:42 +00:00
Even Rouault a571789645 RFC1: update status to adopted 2024-04-03 21:53:59 +02:00
Even Rouault 6b9cb37577 Merge branch 'rfc1_psc' into 'master'
Doc: add 'RFC 1: Project Steering Committee Guidelines' and a PSC page

See merge request libtiff/libtiff!566
2024-04-03 12:23:37 +00:00
Even Rouault 5a8e565482 Doc: add 'RFC 1: Project Steering Committee Guidelines' and a PSC page 2024-04-03 12:23:37 +00:00
Even Rouault 395a3c881b Merge branch 'fix_coverity_test_directory_expansion' into 'master'
Fix coverity scan issue in test_directory.c

See merge request libtiff/libtiff!576
2024-04-02 20:05:53 +00:00
Su_Laus e79965bbe7 Fix coverity scan issue in test_directory.c 2024-04-02 21:56:21 +02:00
Even Rouault 307afbc66d Merge branch 'typo_fixes' into 'master'
Various typo fixes

See merge request libtiff/libtiff!575
2024-04-02 08:15:44 +00:00
Even Rouault c95c773508 Various typo fixes 2024-04-02 02:21:50 +02:00
Even Rouault cc5f3312a7 Merge branch 'test_directory_expansion_endianness' into 'master'
Enhance test_directory.c with big-endian and little-endian test cases

See merge request libtiff/libtiff!574
2024-03-31 15:23:54 +00:00
Su_Laus c69be56bce Enhance test/test_directory.c with big-endian and little-endian test cases.
Insert testcase into test_directory.c for #618 "Failure in TIFFSetSubDirectory() will break subsequent TIFFSetDirectory() calls".
2024-03-30 19:45:33 +01:00
Even Rouault c662851405 Merge branch 'correct_coverity_issues_from_avoid_IFD_overwriting' into 'master'
Correct some coverity issues from "avoid IFD overwriting"

See merge request libtiff/libtiff!573
2024-03-29 13:01:38 +00:00
Su_Laus e1ab15b90b Correct some coverity issues from "avoid IFD overwriting". 2024-03-29 12:15:21 +01:00
Even Rouault ffb7c45730 Merge branch 'fix_gdal_9548' into 'master'
LERC codec: deal with issues with multi-band PlanarConfig=Contig and NaN values

See merge request libtiff/libtiff!572
2024-03-28 18:43:09 +00:00
Even Rouault f46f73ba1a Merge branch 'avoid_IFD_overwriting_other_data_TIFFWriteDirectory' into 'master'
TIFFWriteDirectory: Avoid overwriting following data if an IFD is enlarged.

See merge request libtiff/libtiff!565
2024-03-26 22:17:05 +00:00
Su Laus 4c809ccf16 TIFFWriteDirectory: Avoid overwriting following data if an IFD is enlarged.
Avoid overwriting other data if an IFD that has already been written is enlarged. If entries are to be changed in an IFD that has already been written to the file, the memory area can be overwritten as long as the IFD data volume has not increased. Otherwise, the IFD must be written to a different location in the file. Up to now, LibTIFF has simply overwritten the IFD and other data areas in the file.

With this MR, the size of the IFD, and location of IFD data, is tracked and checked if the IFD can be safely overwritten or has to be re-written to another location.
2024-03-26 22:17:04 +00:00
Even Rouault e414a9d579 LERC codec: deal with issues with multi-band PlanarConfig=Contig and NaN values
Fixes https://github.com/OSGeo/gdal/issues/9530.
Cf https://github.com/OSGeo/gdal/pull/9548 for the GDAL specific fix.

The LERC codec up-to-now didn't do any special processing when writing a strile
in a multi-band PlanarConfig=Contig file, resulting in corruptions. Now we
generate a mask buffer in that situation. Actually, if the NaN values are not
at the same location accross bands, we need to write one mask-per-band, which
requires liblerc >= 3.0, and in that situation change the LERC blob to
multi-band instead of multi-depth/dim, with liblerc >= 3.0. When all bands have
NaN values at the same location, we generate a single mask, which is compatible
of liblerc < 3.0, but requires at last this version of libtiff to be read. This
is the best solution we come with to fix the issue while having the maximum
backward compatibility.
2024-03-24 18:14:00 +01:00
Even Rouault af3dfc78a4 Merge branch 'harmonize_TIFFheader_swapping' into 'master'
Correct and harmonize swapping of internal 'tif_header' parameters.

See merge request libtiff/libtiff!571
2024-03-24 14:35:42 +00:00
Su Laus 3c8480e3b7 Correct and harmonize swapping of internal 'tif_header' parameters. 2024-03-24 14:35:42 +00:00
Even Rouault bb1ff4f80e Merge branch 'chore/printf-format-specifiers' into 'master'
chore: use correct format specifiers

See merge request libtiff/libtiff!570
2024-03-19 08:37:46 +00:00
Tom 8ce83e402f chore: use correct format specifiers
When building on my Mac, I get the following warnings:

    libtiff/tools/tiffcp.c:154:24: warning: format specifies type 'unsigned short' but the argument has type 'tdir_t' (aka 'unsigned int') [-Wformat]
                    comma, nextImage);
                           ^~~~~~~~~
    libtiff/tools/tiffcp.c:1295:39: warning: format specifies type 'unsigned short' but the argument has type 'tdir_t' (aka 'unsigned int') [-Wformat]
                      TIFFFileName(bias), TIFFCurrentDirectory(bias),
                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~
    libtiff/tools/tiffcp.c:1296:37: warning: format specifies type 'unsigned short' but the argument has type 'tdir_t' (aka 'unsigned int') [-Wformat]
                      TIFFFileName(in), TIFFCurrentDirectory(in));
                                        ^~~~~~~~~~~~~~~~~~~~~~~~
    libtiff/tools/tiffcp.c:1303:37: warning: format specifies type 'unsigned short' but the argument has type 'tdir_t' (aka 'unsigned int') [-Wformat]
                      TIFFFileName(in), TIFFCurrentDirectory(in));
                                        ^~~~~~~~~~~~~~~~~~~~~~~~
    libtiff/tools/tiffsplit.c:174:21: warning: format specifies type 'long long' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
                        path_len);
                        ^~~~~~~~

This updates the format specifiers from `PRIu16` to `PRIu32` for `tdir_t`
(which is a `typdef`ed `uint32_t`) and from `TIFF_SSIZE_FORMAT` to
`TIFF_SIZE_FORMAT` for `size_t`, which makes sense given that it's an unsigned
type.
2024-03-19 19:31:54 +11:00
Even Rouault 2005dbb4f8 Merge branch 'fix_628_FPE_at_TIFFhowmany' into 'master'
Avoiding FPE (division by zero) for TIFFhowmany_32() and TIFFhowmany_64()...

Closes #628

See merge request libtiff/libtiff!568
2024-03-16 17:23:51 +00:00
Su_Laus 021a737bfa Avoiding FPE (division by zero) for TIFFhowmany_32() and TIFFhowmany_64() macros by checking for denominator not zero before macros are executed.
Fixes #628.
2024-03-15 15:47:29 +01:00
Even Rouault 025467ab01 Merge branch 'fix_wrong_return_TIFFIsBigTIFF_if_swapping_case' into 'master'
Fix wrong return of TIFFIsBigTIFF() in case byte-swapping is acitve

See merge request libtiff/libtiff!567
2024-03-14 20:35:13 +00:00
Su_Laus 562bfcad1d Fix wrong return of TIFFIsBigTIFF() in case byte-swapping is acitve (i.e. little endian image on a big endian machine). 2024-03-13 19:58:04 +01:00
Even Rouault 1d28fe6380 Merge branch 'master' into 'master'
Setting the TIFFFieldInfo field `set_field_type` should consider `field_writecount` not `field_readcount`

See merge request libtiff/libtiff!544
2024-01-30 20:59:04 +00:00
Timo Stüber cee5e991e5 Setting the TIFFFieldInfo field set_field_type should consider field_writecount not field_readcount
In most of the cases the field_writecount and field_readcount of the TIFFFieldInfo are equal. But they do not have to be the same.

I encountered this issues when using an older release of Pillow. Since they use custom fields for decoding only, they set the readcount value to 0. As the result _TIFFSetGetType can not identify the type correctly and set TIFF_SETGET_UNDEFINED.

Error Message:
```
TIFFLib: _TIFFWriteDirectorySec(): Rational2Double: .set_field_type is not 4 but 1.
```

During the execution of TIFFMergeFieldInfo the fields get_field_type and set_field_type set. I guess the set_field_type should dependent on the field_writecount.
2024-01-30 20:59:04 +00:00
Even Rouault 25bad3798f Merge branch 'avoid_memory_leaks_using_TIFFCreateDirectory' into 'master'
Avoiding memory leaks when using TIFFCreateDirectory()

See merge request libtiff/libtiff!563
2024-01-24 20:54:00 +00:00
Su_Laus 376916d25f Avoiding memory leaks when using TIFFCreateDirectory() by releasing the allocated memory in the tif-structure. 2024-01-24 20:42:34 +01:00
Even Rouault e0f66bf0c2 Merge branch 'WIN32' into 'master'
Use #ifdef _WIN32 to test for Windows, and tiffio.h: remove definition of __WIN32__

See merge request libtiff/libtiff!562
2024-01-10 13:18:19 +00:00
Even Rouault f964953812 test/raw_decode.c: remove likely ifdef tricks related to old compilers or unusual setups 2024-01-08 13:49:02 +01:00
Even Rouault 10fe25bddf tif_jpeg.c/tif_ojpeg.c: remove likely ifdef tricks related to old compilers or unusual setups 2024-01-08 12:20:51 +01:00
Even Rouault 19af4e4ab5 Remove _TIFFUInt64ToFloat() and _TIFFUInt64ToDouble() 2024-01-08 12:20:51 +01:00
Even Rouault 97e9225fa5 Remove support for _MSC_VER < 1500 2024-01-08 12:20:51 +01:00
Even Rouault 651b14ffa9 Use #ifdef _WIN32 to test for Windows, and tiffio.h: remove definition of __WIN32__ 2024-01-07 23:14:24 +01:00
Even Rouault 0c74f424b1 Merge branch 'fix_579_non_terminated_ASCII_deletes_one_byte' into 'master'
Fixed issue with non-terminated ASCII arrays where the last character is overwritten (fixes #579)

Closes #579

See merge request libtiff/libtiff!561
2023-12-20 20:10:09 +00:00
Su_Laus 5fd944398f For non-terminated ASCII arrays, the buffer is first enlarged before a NULL is set at the end to avoid deleting the last character. Fixes #579.
Some editorials in tif_dir.c.
2023-12-20 20:57:40 +01:00
Even Rouault 3705f82b64 Merge branch 'fix_624_check_TIFFCreateAnonField_return' into 'master'
Fix 624: Check return value of _TIFFCreateAnonField()

Closes #624

See merge request libtiff/libtiff!560
2023-12-09 17:04:23 +00:00
Su_Laus 818fb8ce88 Check return value of _TIFFCreateAnonField().
Fixes #624
2023-12-01 20:27:26 +01:00
Even Rouault 9d9c83d279 Merge branch 'TIFFOpenOptionsSetMaxCumulatedMemAlloc' into 'master'
Add TIFFOpenOptionsSetMaxCumulatedMemAlloc()

See merge request libtiff/libtiff!556
2023-11-27 00:07:47 +00:00
Even Rouault f53258e4bb Add TIFFOpenOptionsSetMaxCumulatedMemAlloc()
This function complements ``TIFFOpenOptionsSetMaxSingleMemAlloc()`` to define the maximum cumulated memory allocations in byte, for a given TIFF handle, that libtiff internal memory allocation functions are allowed.
2023-11-27 00:07:46 +00:00
Even Rouault 3dff9205c1 Merge branch 'unity_clang_fixes' into 'master'
Fixes to avoid CLang warnings on unity builds

See merge request libtiff/libtiff!558
2023-11-23 15:55:17 +00:00
Even Rouault 9d62554d07 Fixes to avoid CLang warnings on unity builds 2023-11-23 16:40:01 +01:00
Even Rouault 3375c9aef3 Merge branch 'cmake_UNITY_BUILD' into 'master'
Changes to allow building with cmake -DCMAKE_UNITY_BUILD=ON

See merge request libtiff/libtiff!557
2023-11-22 22:16:59 +00:00
Even Rouault 4e2a38d58a CI: test -DCMAKE_UNITY_BUILD=ON 2023-11-22 21:09:46 +01:00
Even Rouault 2a78a5bcfb Changes to allow building with cmake -DCMAKE_UNITY_BUILD=ON 2023-11-22 21:09:46 +01:00
Even Rouault 67e5cfe29a Merge branch 'manpage_506_TIFFClose_check_with_TIFFFlush' into 'master'
manpage: Note on using TIFFFlush() before TIFFClose()

Closes #506

See merge request libtiff/libtiff!555
2023-11-22 16:21:06 +00:00
Su_Laus 85a286648d manpage: Note on using TIFFFlush() before TIFFClose() to check that the data has been successfully written to the file.
Closes #506
2023-11-16 20:54:00 +01:00
Even Rouault 6791bff9f7 Merge branch 'manpage_621_TIFFOpenOptionsSetMaxSingleMemAlloc' into 'master'
manpage: Update TIFF documentation about TIFFOpenOptions.rst and memory limitting.

Closes #621

See merge request libtiff/libtiff!553
2023-11-11 16:31:27 +00:00
Even Rouault 393bed45bd Merge branch 'rectify_some_shadowed_declarations' into 'master'
Rectify some shadowed declarations and warnings in tools and test modules.

See merge request libtiff/libtiff!552
2023-11-11 16:30:00 +00:00
Even Rouault c7d27f3758 Merge branch 'fix_TIFFRealloc_usage_to_TIFFReallocExt' into 'master'
Change internally used _TIFFRealloc() to _TIFFReallocExt()

See merge request libtiff/libtiff!554
2023-11-11 16:29:18 +00:00
Su_Laus b87fadea8e Change internally used _TIFFRealloc() to _TIFFReallocExt(), which respects the TIFFOpenOptionsSetMaxSingleMemAlloc() limit. 2023-11-11 17:18:53 +01:00
Timothy Lyanguzov 16ab4a205c Fix typo. 2023-11-11 15:25:38 +00:00
Su_Laus 335947359c manpage: Update TIFF documentation about TIFFOpenOptions.rst and TIFFOpenOptionsSetMaxSingleMemAlloc() usage and some other small fixes. 2023-11-09 22:17:26 +01:00
Su_Laus 68d62c65a0 Rectify some shadowed declarations and warnings in tools and test modules. 2023-11-08 20:57:50 +01:00
Even Rouault cf118ec82e Merge branch 'fix_583' into 'master'
tif_fax3.c: error out after a number of times end-of-file has been reached (fixes #583)

Closes #583

See merge request libtiff/libtiff!547
2023-11-04 13:54:25 +00:00
Even Rouault dfacff5a84 Merge branch 'fix_622' into 'master'
TIFFReadRGBAStrip/TIFFReadRGBATile: add more validation of col/row (fixes #622)

Closes #622

See merge request libtiff/libtiff!546
2023-11-04 13:53:15 +00:00
Even Rouault 65feafdf64 Merge branch 'extra_limit_getfilesize' into 'master'
tif_dirread.c: only issue TIFFGetFileSize() for large enough RAM requests

See merge request libtiff/libtiff!551
2023-10-31 20:45:10 +00:00
Even Rouault dbb825a831 tif_dirread.c: only issue TIFFGetFileSize() for large enough RAM requests 2023-10-31 21:30:58 +01:00
Even Rouault ea185ba31a Merge branch 'TIFFFetchDirectory_remove_useless_check' into 'master'
TIFFFetchDirectory(): remove useless allocsize vs filesize check

See merge request libtiff/libtiff!550
2023-10-31 19:28:13 +00:00
Even Rouault de7bfd7d43 TIFFFetchDirectory(): remove useless allocsize vs filesize check
CoverityScan rightly points that the max value for dircount16 * dirsize
is 4096 * 20. That's small enough not to do any check
2023-10-31 20:13:48 +01:00
Even Rouault e7b57edcbf Merge branch 'limit_getfilesize' into 'master'
tif_dirread.c: only issue TIFFGetFileSize() for large enough RAM requests

See merge request libtiff/libtiff!549
2023-10-31 19:03:21 +00:00
Even Rouault 0b02532471 tif_dirread.c: only issue TIFFGetFileSize() for large enough RAM requests
Ammends 5320c9d89c

This fixes a performance regression caught by the GDAL regression test
suite.
2023-10-31 19:47:25 +01:00
Even Rouault ce3d768b4d Merge branch 'tif_dirread-typo' into 'master'
tif_dirread.c: Fix typo: greather -> greater

See merge request libtiff/libtiff!548
2023-10-31 16:24:05 +00:00
Kurt Schwehr 55a8ed454b tif_dirread.c: Fix typo: greather -> greater 2023-10-31 09:14:49 -07:00
Even Rouault 4728ce9b8e Merge branch 'fix_614_check_mem_allocation_vs_filelength' into 'master'
Prevent some out-of-memory attacks

See merge request libtiff/libtiff!545
2023-10-31 15:43:31 +00:00
Su Laus 5320c9d89c Prevent some out-of-memory attacks
Some small fuzzer files fake large amounts of data and provoke out-of-memory situations. For non-compressed data content / tags, out-of-memory can be prevented by comparing with the file size.

At image reading, data size of some tags / data structures (StripByteCounts, StripOffsets, StripArray, TIFF directory) is compared with file size to prevent provoked out-of-memory attacks.

See issue https://gitlab.com/libtiff/libtiff/-/issues/614#note_1602683857
2023-10-31 15:43:29 +00:00
Even Rouault 8d0bf12233 tif_fax3.c: error out after a number of times end-of-file has been reached (fixes #583) 2023-10-31 16:39:43 +01:00
Even Rouault 51558511bd TIFFReadRGBAStrip/TIFFReadRGBATile: add more validation of col/row (fixes #622) 2023-10-31 15:58:41 +01:00
Even Rouault a4db8cd398 Merge branch 'fix_failed_subdirectory_read' into 'master'
#618: ensure absolute seeking is forced independent

See merge request libtiff/libtiff!543
2023-10-30 20:31:09 +00:00
Manuel Massing 95994b65ea #618: ensure absolute seeking is forced independent
of TIFFReadDirectory success.

This fixes TIFFSetDirectory calls for the case where
TIFFReadDirectory was unsuccessful.
2023-10-25 15:35:40 +02:00
Even Rouault 3c7e2aff4f Merge branch 'cmake' into 'master'
CMake: Fix TIFF_INCLUDE_DIRS

See merge request libtiff/libtiff!541
2023-10-17 12:31:39 +00:00
Even Rouault d14d67ef38 Merge branch 'fix_616' into 'master'
tif_lzw.c: avoid warning about misaligned address with UBSAN (fixes #616)

Closes #616

See merge request libtiff/libtiff!542
2023-10-12 11:31:59 +00:00
Even Rouault 5769bfea8c Merge branch 'tiffcp_cancel_ycbcr' into 'master'
tiffcp: replace PHOTOMETRIC_YCBCR with PHOTOMETRIC_RGB when outputing to...

See merge request libtiff/libtiff!540
2023-10-12 11:31:45 +00:00
Even Rouault e1b4eef40f tif_lzw.c: avoid warning about misaligned address with UBSAN (fixes #616)
The branch suppressed by this commit wasn't useful as I've verified that
with -O2 and -O3 and gcc or clang, doing a memcpy() + _byteswap_uint64()
generates exactly the same code as _byteswap_uint64(*ptr).
The warning with UBSAN thus only comes from UBSAN generating special code
to catch the misalignment, but is unlikely to cause any issue in
practice given the above observation.
2023-10-12 12:38:58 +02:00
Julien Schueller f8498e2a9a CMake: Fix TIFF_INCLUDE_DIRS 2023-10-12 09:36:52 +02:00
Even Rouault 86d31b233b tiffcp: preserve TIFFTAG_REFERENCEBLACKWHITE when doing YCbCr JPEG -> YCbCr JPEG 2023-10-08 20:20:14 +02:00
Even Rouault 2cccf6d75b tiffcp: replace PHOTOMETRIC_YCBCR with PHOTOMETRIC_RGB when outputing to compression != JPEG (refs #571) 2023-10-07 00:40:50 +02:00
Even Rouault cfc9269c0a Merge branch 'kmilos-master-patch-42063' into 'master'
CMake: MinGW compilers don't need a .def file for shared library

See merge request libtiff/libtiff!448
2023-10-05 18:32:32 +00:00
Even Rouault efa56cdc07 Merge branch 'kmilos-master-patch-64997' into 'master'
CMake: move libdeflate and Lerc to Requires.private

See merge request libtiff/libtiff!536
2023-10-05 18:30:42 +00:00
Even Rouault 4be388f1a6 Merge branch 'clarify_archive' into 'master'
Doc: clarify unsupported (still in tarball) and archived (only in git) utilities

See merge request libtiff/libtiff!532
2023-10-05 18:27:50 +00:00
Even Rouault 6c4d39c6ed Merge branch 'fix_571_alternative' into 'master'
tiffcp: Setting the correct photometric interpretation for the output image...

Closes #571

See merge request libtiff/libtiff!539
2023-10-05 18:27:20 +00:00
Even Rouault 8c6676d883 tiffcp: do not copy tags YCBCRCOEFFICIENTS, YCBCRSUBSAMPLING, YCBCRPOSITIONING, REFERENCEBLACKWHITE. Only set TIFFTAG_YCBCRSUBSAMPLING when generating YCbCr JPEG 2023-10-04 22:35:50 +02:00
Even Rouault ef4a936e3e tiffcp: Setting the correct photometric interpretation for the output image when converting JPEG-YCBCR to JPEG-RGB images.
Closes #571
2023-10-04 22:35:50 +02:00
Miloš Komarčević 995763a316 CMake: move libdeflate and Lerc to Requires.private 2023-09-28 13:43:29 +02:00
Even Rouault 5e7c59d6a9 Merge branch 'kmilos-windres' into 'master'
CMake: enable resource compilation on all Windows

See merge request libtiff/libtiff!537
2023-09-27 20:29:37 +00:00
Miloš Komarčević 1fb779037d CMake: enable resource compilation on all Windows 2023-09-27 20:29:37 +00:00
Even Rouault 4d0329a453 Merge branch 'fix_608' into 'master'
tif_dirinfo.c: re-enable TIFFTAG_EP_CFAREPEATPATTERNDIM and TIFFTAG_EP_CFAPATTERN tags (fixes #608)

Closes #608

See merge request libtiff/libtiff!534
2023-09-15 10:07:06 +00:00
Even Rouault 49856998c3 tif_dirinfo.c: re-enable TIFFTAG_EP_CFAREPEATPATTERNDIM and TIFFTAG_EP_CFAPATTERN tags (fixes #608) 2023-09-15 10:07:06 +00:00
Even Rouault 668d2c1a52 Merge branch 'fix_606_tiffcp_check_also_input_compression_codec' into 'master'
tiffcp: Fixes #606. Check also codec of input image, not only from output image.

Closes #606

See merge request libtiff/libtiff!533
2023-09-09 15:11:42 +00:00
Su_Laus 1e7d217a32 Check also if codec of input image is available, independently from codec check of output image and return with error if not.
Fixes #606.
2023-09-09 15:45:47 +02:00
Even Rouault f56fbd4528 Doc: clarify unsupported (still in tarball) and archived (only in git) utilities 2023-09-08 14:18:07 +02:00
Even Rouault ed6f7be3ef Merge branch 'update_release_date' into 'master'
Update RELEASE-DATE

See merge request libtiff/libtiff!531
2023-09-08 09:13:29 +00:00
Even Rouault 8b20804fc0 Update RELEASE-DATE 2023-09-08 11:12:35 +02:00
Even Rouault 05b38946b1 Merge branch 'fix_605' into 'master'
autoconf.ac: fix detection of windows.h for mingw (fixes #605)

Closes #605

See merge request libtiff/libtiff!530
2023-09-08 09:11:54 +00:00
Even Rouault 341588333e autoconf.ac: fix detection of windows.h for mingw (fixes #605) 2023-09-07 22:40:59 +02:00
Even Rouault bb33843b63 Merge branch 'prepare_v4_6_0' into 'master'
Prepare for libtiff 4.6.0 release

See merge request libtiff/libtiff!528
2023-09-06 13:07:33 +00:00
Even Rouault f438759105 doc/index.rst: add warning about tools removal 2023-09-05 23:06:24 +02:00
Even Rouault b57c8b03ea Merge branch 'fix_603_readme_doc_reference_update' into 'master'
Update documentation reference within README.md. Fixes #603.

Closes #603

See merge request libtiff/libtiff!529
2023-09-05 16:30:16 +00:00
Su_Laus 32cbd32218 Update documentation reference within README.md. Fixes #603. 2023-09-05 18:13:47 +02:00
Even Rouault 5fd37d37e6 Fix references to mailing list 2023-09-05 18:00:43 +02:00
Even Rouault a4acea370f Prepare for libtiff 4.6.0 release 2023-09-05 15:04:12 +02:00
Even Rouault 5177b6a638 Merge branch 'fix_600' into 'master'
CMake: fix build with -Dstrip-chopping=off (fixes #600)

See merge request libtiff/libtiff!527
2023-09-05 09:57:38 +00:00
Even Rouault 7b3c170189 Merge branch 'georgthegreat-master-patch-87447' into 'master'
Fix using __attribute__ libtiff with clang-for-windows

See merge request libtiff/libtiff!525
2023-09-05 09:44:52 +00:00
Yuriy Chernyshov 36c522699b Fix using __attribute__ libtiff with clang-for-windows 2023-09-05 09:44:52 +00:00
Even Rouault 7d2df16340 Merge branch 'manpage_TIFFField_docu_update' into 'master'
manpages: TiffField functions documentation updated with return behaviour for...

See merge request libtiff/libtiff!526
2023-09-05 09:44:04 +00:00
Even Rouault f71fc35535 CMake: fix build with -Dstrip-chopping=off (fixes #600) 2023-09-05 11:42:19 +02:00
Even Rouault f0c1b25f4a Merge branch 'consistently_update_TIFF-version_from_configure-ac' into 'master'
Update CMake and autoconf scripts to consistently update LibTIFF version...

See merge request libtiff/libtiff!456
2023-09-03 18:11:13 +00:00
Su Laus 432a3b64ad Update CMake and autoconf scripts to consistently update LibTIFF version defines and references in various files when version definition in configure.ac has been changed.
- Move in tiffvers.h from .\libtiff source directory to .\libtiff  build directory.
- Remove unused version information from tif_config.h
- With every CMake build the version defines (e.g. 4.5.1) within tiffvers.h are consistently updated from configure.ac. The version release-date is taken from file RELEASE-DATE.
- The files VERSION and RELEASE-DATE are only updated with a special CMake target build: cmake --build . --target tiff_release.

- For autotools, version information is updated from configure.ac with ./autogen.sh. LIBTIFF_RELEASE_DATE is taken form file RELEASE-DATE.
- ./configure generates tiffvers.h with the cached version information and LIBTIFF_RELEASE_DATE.
- "make release" updates tiffvers.h and VERSION file with cached version info and RELEASE-DATE file and tiffves.h with the current date.
2023-09-03 18:11:13 +00:00
Su_Laus fc733c6a26 manpages: TiffField functions documentation updated with return behaviour for not defined tags and determination of write-/read-count size. 2023-08-28 17:07:53 +02:00
Even Rouault 07f922106b Merge branch 'change_long_to_int32_t_in_two_test_apps' into 'master'
Change "long" to "int32_t" in two test apps, because can be either int32_t or...

See merge request libtiff/libtiff!524
2023-08-22 20:54:15 +00:00
Su_Laus 12140bfdb2 Change "long" to "int32_t" in two test apps, because can be either int32_t or int64_t, depending on compiler and system. 2023-08-21 20:54:37 +02:00
Even Rouault 69eef88fc0 Merge branch 'CI_CMake_static_build' into 'master'
Add static build for CI/CD to run testcases which need private interface functions.

See merge request libtiff/libtiff!521
2023-08-16 13:03:22 +00:00
Even Rouault 4126f6d794 Merge branch 'fix_#597_tiffset_different_signedness' into 'master'
tiffset fix #597: warning: comparison of integer expressions of different signedness.

Closes #597

See merge request libtiff/libtiff!523
2023-08-16 13:02:24 +00:00
Even Rouault 83384f847f Merge branch 'tiffcp_remove_i_option' into 'master'
tiffcp: remove -i option (ignore errors)

See merge request libtiff/libtiff!522
2023-08-16 13:01:57 +00:00
Even Rouault 27b26dfcee Merge branch 'move_tools_to_unsupported_a_archive' into 'master'
Move most TIFF tools to archive and keep some as unsupported (see #580).

See merge request libtiff/libtiff!520
2023-08-16 13:01:04 +00:00
Su Laus eab89a627f Move most TIFF tools to archive and keep some as unsupported (see #580). 2023-08-16 13:01:04 +00:00
Su_Laus ca85b5f760 Add static build for CI/CD to run testcases which need private interface functions. 2023-08-12 16:51:44 +02:00
Su_Laus 91e7bd01d0 tiffset fix #597: warning: comparison of integer expressions of different signedness. 2023-08-12 16:38:23 +02:00
Su_Laus 280a568ae8 Remove -i option (ignore errors) from tiffcp, because almost all fuzzer issues were consequential errors from ignored errors because of the "-i" option. 2023-08-12 15:52:28 +02:00
Even Rouault 3225f137a9 Merge branch 'fix_585_test_write_read_tags_autoconf' into 'master'
Add missing test_write_read_tags.c and test_transferfunction_write_read.c in...

Closes #585

See merge request libtiff/libtiff!519
2023-08-11 11:58:22 +00:00
Even Rouault 4b54117c6d Fix copy paste error. 2023-07-24 19:23:58 +00:00
Su_Laus ce304fe647 Add missing test_write_read_tags.c and test_transferfunction_write_read.c in tarball (fixes #585) and correct „long“ issue.
Don't use "long" because can be int32_t or int64_t, depending on compiler and system.
2023-07-23 11:00:43 +02:00
Even Rouault 1dff4271ad Merge branch 'clang-format-tools' into 'master'
Automatically format with clang-format

See merge request libtiff/libtiff!518
2023-07-20 09:03:53 +00:00
Timothy Lyanguzov ac72178f1a Automatically format with clang-format 2023-07-20 13:30:59 +12:00
Even Rouault 73692ebdf8 Merge branch 'fix_589' into 'master'
TiffConfig.cmake.in: set TIFF_INCLUDE_DIR, TIFF_INCLUDE_DIRS and...

Closes #589

See merge request libtiff/libtiff!514
2023-07-19 22:05:16 +00:00
Even Rouault eabde1635a TiffConfig.cmake.in: set TIFF_INCLUDE_DIR, TIFF_INCLUDE_DIRS and... 2023-07-19 22:05:15 +00:00
Even Rouault 6ac40fefa1 Merge branch 'master-patch-6fc6' into 'master'
raw2tiff: fix integer overflow and bypass of the check (fixes #592)

See merge request libtiff/libtiff!516
2023-07-19 19:40:02 +00:00
Arie Haenel 6e2dac5f90 raw2tiff: fix integer overflow and bypass of the check (fixes #592) 2023-07-19 19:40:01 +00:00
Even Rouault add28aa361 Merge branch 'master-patch-05a4' into 'master'
tiffcp: fix memory corruption (overflow) on hostile images (fixes #591)

See merge request libtiff/libtiff!515
2023-07-19 19:34:25 +00:00
Arie Haenel 4fc16f649f tiffcp: fix memory corruption (overflow) on hostile images (fixes #591) 2023-07-19 19:34:25 +00:00
Even Rouault cb88a5b6bf Merge branch 'fix-numtrunc' into 'master'
fix numtrunc at tiff_dirread.c

See merge request libtiff/libtiff!512
2023-07-17 09:50:42 +00:00
headshog 54eeadb88b TIFFReadDirectoryCheckOrder: avoid integer overflow
When it occurs, it should be harmless in practice though
2023-07-17 09:50:42 +00:00
Even Rouault 74e8d3cf71 Merge branch 'webp_lossless_exact' into 'master'
WebP codec: turn exact mode when creating lossless files to avoid altering...

See merge request libtiff/libtiff!511
2023-07-17 08:46:34 +00:00
Even Rouault 6aeda415e0 WebP codec: turn exact mode when creating lossless files to avoid altering R,G,B values in areas where alpha=0
Fixes https://github.com/OSGeo/gdal/issues/8038
2023-07-11 21:10:56 +02:00
Even Rouault df547d0ee5 Merge branch 'webp_reg_fix' into 'master'
WebP decoder: fix error when reading a 3-band blob in a RGBA image

See merge request libtiff/libtiff!510
2023-07-05 10:51:12 +00:00
Even Rouault 130ef8d657 WebP decoder: fix error when reading a 3-band blob in a RGBA image
Fixes regression of 350ff161c8 (master only)
2023-07-05 12:29:17 +02:00
Even Rouault ccbdbd5258 Merge branch 'appveyor_fix' into 'master'
.appveyor.yml: workaround build error

See merge request libtiff/libtiff!509
2023-06-26 14:31:10 +00:00
Even Rouault 493d328e92 .appveyor.yml: workaround build error 2023-06-26 16:24:05 +02:00
Even Rouault e429387c54 Merge branch 'tif_webp_warning_fixes' into 'master'
tif_webp.c: fix signed vs unsigned comparison warnings (fix previous commit)

See merge request libtiff/libtiff!508
2023-06-26 13:25:39 +00:00
Even Rouault 1bcbc6bcf0 tif_webp.c: fix signed vs unsigned comparison warnings (fix previous commit) 2023-06-26 15:19:40 +02:00
Even Rouault f127333d8c Merge branch 'fix_TransferFunction_writing' into 'master'
Fix TransferFunction writing of only two transfer functions.

See merge request libtiff/libtiff!502
2023-06-26 08:43:59 +00:00
Even Rouault d1028f7a8d Merge branch 'fix_581_582' into 'master'
WebP decoder: validate WebP blob width, height, band count against TIFF parameters

Closes #582 et #581

See merge request libtiff/libtiff!507
2023-06-26 08:43:10 +00:00
Even Rouault 7f7258f25b Merge branch 'warning_cmake_config_file' into 'master'
v4.5.1 release note: add warning about CMake config file being preview

See merge request libtiff/libtiff!506
2023-06-19 11:00:24 +00:00
Even Rouault 350ff161c8 WebP decoder: validate WebP blob width, height, band count against TIFF parameters
to avoid use of uninitialized variable, or decoding corrupted content
without explicit error

Fixes #581, fixes #582
2023-06-17 16:24:56 +02:00
Even Rouault 9812658366 v4.5.1 release note: add warning about CMake config file being preview 2023-06-15 15:55:55 +02:00
Even Rouault df665f6077 Merge branch 'HOWTO-RELEASE-gitlab-release' into 'master'
HOWTO-RELEASE: mention creating a gitlab release

See merge request libtiff/libtiff!505
2023-06-14 16:01:04 +00:00
Even Rouault c2755a3d20 HOWTO-RELEASE: mention creating a gitlab release 2023-06-14 14:43:24 +02:00
Even Rouault 4f34a374b2 Merge branch 'TIFFOpenWExt_O_RDWR' into 'master'
TIFFOpenWExt(): mode r+ in the Windows implementation adjusted to that of Linux

See merge request libtiff/libtiff!504
2023-06-10 20:36:49 +00:00
Even Rouault e97e716e21 TIFFOpenWExt(): mode r+ in the Windows implementation adjusted to that of Linux 2023-06-10 22:35:51 +02:00
Even Rouault 5fc887f552 Merge branch 'fix_ossfuzz_59751' into 'master'
TIFFReadDirectory(): fix crash when reading tag TIFFTAG_EP_BATTERYLEVEL

See merge request libtiff/libtiff!503
2023-06-10 20:32:35 +00:00
Even Rouault 74bcfc74da TIFFReadDirectory(): fix crash when reading tag TIFFTAG_EP_BATTERYLEVEL
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59751

In 738e0409 (refs #575), we disabled DNG / EP tags, but there was a
special proessing for TIFFTAG_EP_BATTERYLEVEL that must be disabled
since the tag is no longer defined.
2023-06-10 22:29:26 +02:00
Su_Laus 7b1f03c386 Fix TransferFunction writing of only two transfer functions.
The TIFFWriteDirectoryTagTransferfunction() function writes in some cases only two transfer functions, although only exactly one or exactly three transfer functions are allowed.
This then leads to an error when reading.
--> TIFFReadDirectory: Warning, Incorrect count for "TransferFunction"; tag ignored.

This MR corrects the behaviour of TIFFWriteDirectoryTagTransferfunction() accordingly. Furthermore, a possible buffer overflow is avoided.
2023-06-09 17:56:36 +02:00
Even Rouault b36bb2f9be Merge branch 'fix_win_build' into 'master'
Fix Windows build

Closes #578

See merge request libtiff/libtiff!501
2023-06-09 13:43:10 +00:00
Even Rouault 72187a0fb7 cmake/PkgConfig.cmake: avoid CMake error when prefix or suffix is empty 2023-06-09 15:40:17 +02:00
Even Rouault 70f8d926cc Add tif_win32_versioninfo.rc and tif_tools_versioninfo.rc to EXTRA_DIST 2023-06-09 15:39:38 +02:00
Even Rouault 78b1977875 Merge branch 'fix_coverity_build' into 'master'
build/gitlab-ci: fix coverity_build()

See merge request libtiff/libtiff!499
2023-06-09 12:57:34 +00:00
Even Rouault 56aa5d01e6 build/gitlab-ci: fix coverity_build() 2023-06-09 14:55:58 +02:00
Even Rouault 7583f9f3ed Merge branch 'v4.5.1rc1_preparation' into 'master'
Prepare release 4.5.1

See merge request libtiff/libtiff!498
2023-06-09 12:44:50 +00:00
Even Rouault 8e424c701e Prepare for v4.5.1 release 2023-06-09 14:38:34 +02:00
Even Rouault cff0aeba96 Merge remote-tracking branch 'sulaus/Rel_4.5.1_preparation' 2023-06-09 14:14:39 +02:00
Even Rouault 6ac0ab5064 Merge branch 'disable_dng_tags' into 'master'
tif_dirinfo.c: disable DNG 1.2->1.6 tags

Closes #575

See merge request libtiff/libtiff!497
2023-06-09 12:10:18 +00:00
Even Rouault e2ac7e48ac Merge branch 'fix_577' into 'master'
CMake related fixes

Closes #577

See merge request libtiff/libtiff!496
2023-06-09 12:09:43 +00:00
Even Rouault 738e04099b tif_dirinfo.c: disable DNG 1.2->1.6 tags
They were added per b90b20d36d but it has
been found in https://gitlab.com/libtiff/libtiff/-/issues/575 that it
could cause compatibity issues with libtiff users, so this addition
should be defered for a feature release (likely 4.6.0) and not a patch one.

Fixes #575
2023-06-07 22:30:30 +02:00
Timothy Lyanguzov b8d15d9dbe Apply 1 suggestion(s) to 1 file(s) 2023-06-05 23:23:50 +00:00
Even Rouault 97785f8527 CI: add testing of find_package(Tiff CONFIG) 2023-06-05 17:20:37 +02:00
Even Rouault 71c90a51bc CMake: export TiffConfig.cmake and TiffConfigVersion.cmake files 2023-06-05 17:20:37 +02:00
Even Rouault c978a6c3ea libtiff/CMakeLists.txt: fix export of INTERFACE_INCLUDE_DIRECTORIES 2023-06-05 17:20:37 +02:00
Even Rouault 50eab58d6e libtiff/CMakeLists.txt: correctly define TIFF::tiff alias (fixes #577) 2023-06-05 16:18:57 +02:00
Even Rouault 46ea8e2a5c Merge branch 'TIFFField_downgrade_errors_to_warnings' into 'master'
TIFFFieldWithName() and TIFFFieldWithTag() downgrade errors to warnings.

See merge request libtiff/libtiff!495
2023-06-05 14:05:26 +00:00
Su_Laus a693d1f365 TIFFFieldWithName() and TIFFFieldWithTag() downgrade errors to warnings.
see https://gitlab.com/libtiff/libtiff/-/issues/575#note_1407633888
2023-05-28 21:05:49 +02:00
Even Rouault be9785ac6d Merge branch 'bebuch-master-patch-58347' into 'master'
check if upstream lzma (xz) config was used and bind to it if so

See merge request libtiff/libtiff!494
2023-05-25 14:41:50 +00:00
Benjamin Buch c58e47a183 check if upstream lzma (xz) config was used and bind to it if so 2023-05-25 14:41:49 +00:00
Even Rouault 7eb0f8ca76 Merge branch 'upstream-zstd-config' into 'master'
check if upstream zstd config was used and bind to it if so

See merge request libtiff/libtiff!493
2023-05-25 14:40:48 +00:00
Even Rouault be0bac4c88 Merge branch 'cmake_FindDeflate_bugs_see_526' into 'master'
CMake: FindDeflate several errors fixed (see #526)

See merge request libtiff/libtiff!491
2023-05-25 14:40:13 +00:00
Su_Laus b2cdf4292a CMake: FindDeflate several errors (see #526)
There are CMake issues if the library is not included in the environment path and only set with CMake -D option.
- For FindDeflate.cmake, FindJBIG.cmake, FindLERC.cmake, FindWebP.cmake, FindZSTD.cmake:
  Set IMPORTED_LOCATION (without debug or release) if neither <library>_LIBRARY_RELEASE nor <library>_LIBRARY_DEBUG were set.
- FindDeflate.cmake: Correct code to retrieve library version information from libdeflate.h
- FindLERC.cmake version string return added.
2023-05-24 21:49:43 +02:00
Benjamin Buch 211704a9e6 prefer shared over static 2023-05-24 10:20:27 +00:00
Benjamin Buch 527208be70 check if upstream zstd config was used and bind to it if so 2023-05-24 09:37:16 +00:00
Even Rouault 33cda33473 Merge branch 'master' into 'master'
make WebP component name compatible with upstream ConfigWebP.cmake

See merge request libtiff/libtiff!492
2023-05-24 09:07:25 +00:00
Benjamin Buch 86e058e4ed CMake: make WebP component name compatible with upstream ConfigWebP.cmake 2023-05-24 09:07:25 +00:00
Su_Laus 118c5d1082 Prepare release 4.5.1
- Update till 18.05.23 after fix_559_DNG_1.6_passcount_error
2023-05-18 22:45:26 +02:00
Su_Laus c6c80cefa6 Prepare release 4.5.1 2023-05-18 22:45:26 +02:00
Even Rouault e3e23b1dd0 Merge branch 'fix_559_DNG_1.6_passcount_error' into 'master'
Fix #559 DNG 1.6 passcount assertion

Closes #574 et #559

See merge request libtiff/libtiff!489
2023-05-18 20:22:21 +00:00
Even Rouault 95942e5048 Merge branch 'fix_557_TagExtender_for_CustomDirectories_not_possible' into 'master'
manpage: TIFFSetTagExtender() cannot add tags to custom directories. Closes #557.

Closes #557

See merge request libtiff/libtiff!490
2023-05-18 20:21:55 +00:00
Su_Laus 9f0c7bff9b Documentation update: TIFFSetTagExtender() cannot add tags to custom directories.
Closes #557.
2023-05-17 22:50:12 +02:00
Even Rouault a0a18437d6 Merge branch 'fix_558' into 'master'
Hardcode HOST_FILLORDER to FILLORDER_LSB2MSB, and make 'H' flag of TIFFOpen()...

See merge request libtiff/libtiff!488
2023-05-16 17:40:05 +00:00
Su_Laus e8874d75f5 Fix #559 DNG 1.6 passcount assertion
Amend DNG tags definition introduced with MR 482:
- DNG 1.6 tags specified as UTF-8 strings are defined as variable TIFF_BYTE with  passcount=TRUE.
- For all tags with TIFF_SETGET_C32_UINT8 the readcount and writecount were corrected to -3 (TIFF_VARIABLE2).

Testprogram to write and read all tags defined within LibTIFF is introduced.
It also checks for valid passcount flag setting for the defined tags but some special tags are excluded from that check.

Closes #559.
2023-05-16 19:33:40 +02:00
Even Rouault 0dabdfe857 Hardcode HOST_FILLORDER to FILLORDER_LSB2MSB, and make 'H' flag of TIFFOpen() to warn and an alias of FILLORDER_MSB2LSB 2023-05-09 14:47:49 +02:00
Even Rouault 6fd4237b0b tif_lerc.c: use WORDS_BIGENDIAN instead of HOST_BIGENDIAN 2023-05-09 14:47:28 +02:00
Even Rouault cea6047054 Merge branch 'fix_484_TIFFDirectory_32_64_bit' into 'master'
Fix 484 TIFFDirectory td_fieldsset uses unsigned long which can be 32 or 64 bits.

Closes #484

See merge request libtiff/libtiff!471
2023-05-07 11:14:25 +00:00
Even Rouault ba425745d6 Merge branch 'DNG_1.6_EP_tags' into 'master'
Add DNG tags up to version 1.6.0.0 and some TIFF/EP tags and update documentation

See merge request libtiff/libtiff!482
2023-05-07 11:12:20 +00:00
Even Rouault f79d2d5d1e Merge branch 'issue547' into 'master'
do not install libtiff-4.pc when tiff-install is reset

Closes #547

See merge request libtiff/libtiff!481
2023-05-07 11:11:36 +00:00
Even Rouault 7e28cd362b Merge branch 'fix_548' into 'master'
LZWDecode(): avoid crash when trying to read again from a strip whith a...

Closes #548

See merge request libtiff/libtiff!484
2023-05-06 18:47:00 +00:00
Even Rouault 7ead6c42c7 Merge branch 'tiffcrop_fix_553_multi-image-errors' into 'master'
tiffcrop: fix 553 by considering error return of writeSelections()

Closes #553

See merge request libtiff/libtiff!485
2023-05-06 18:46:35 +00:00
Even Rouault e53b14876f Merge branch 'tif_ojpeg_fix-554_FPE' into 'master'
tif_ojpeg.c fix 554 by checking for division by zero

Closes #554

See merge request libtiff/libtiff!486
2023-05-06 18:45:50 +00:00
Su Laus d0c721cad7 tif_ojpeg.c fix 554 by checking for division by zero 2023-05-06 18:45:50 +00:00
Su_Laus b5c7d4c4e0 Consider error return of writeSelections().
Fixes #553
2023-05-05 19:43:46 +02:00
Even Rouault 9be22b639e LZWDecode(): avoid crash when trying to read again from a strip whith a missing end-of-information marker (fixes #548) 2023-04-29 12:20:46 +02:00
Su_Laus b90b20d36d Add DNG tags up to version 1.6.0.0 and some TIFF/EP tags and update documentation
Amend MR !337 'Add support for DNG tags up to version 1.6.0.0 and some TIFF/EP tags' from Sami Liedes:
- Set most tags to OkToChange=1.
- Define BATTERYLEVEL tag as ASCII and convert values of rational variant to ASCII.
- TIFF documentation updated for tags recognized by LibTiff (DNG 1.6 and others).
- TIFF/EP tags added, which are equivalent to EXIF tags. This addresses part of #418 as well.
- Definition of tags reformatted (clang-format off) for better readability of tag comments in tiff.h and tif_dirinfo.c
2023-04-25 20:05:14 +02:00
Roman d2f2dbc392 do not install libtiff-4.pc when tiff-install is reset 2023-04-23 13:49:35 +10:00
Even Rouault 9bd48f0dbd Merge branch 'mymaster1' into 'master'
fix runtime error: applying zero offset to null pointer

See merge request libtiff/libtiff!479
2023-04-21 13:01:34 +00:00
xiaoxiaoafeifei 8c0859a804 countInkNamesString(): fix UndefinedBehaviorSanitizer: applying zero offset to null pointer 2023-04-21 13:01:34 +00:00
Even Rouault 17adf4308c Merge branch 'tif_ovrcache_TIFFSetSubDirectory' into 'master'
tif_ovrcache.c: check TIFFSetSubDirectory() return value (CID 1524573)

See merge request libtiff/libtiff!478
2023-03-26 15:51:21 +00:00
Even Rouault b8b12c44c1 tif_ovrcache.c: check TIFFSetSubDirectory() return value (CID 1524573) 2023-03-26 16:27:40 +02:00
Even Rouault 214fe59954 Merge branch 'even_faster_setdirectory_with_IFDlist' into 'master'
Even faster TIFFSetDirectory() using IFD list.

See merge request libtiff/libtiff!477
2023-03-26 14:09:24 +00:00
Su Laus ada85f3663 Even faster TIFFSetDirectory() using IFD list. 2023-03-26 14:09:24 +00:00
Even Rouault ddd7f04482 Merge branch 'faster-setdirectory_newMR' into 'master'
Optimize relative seeking with TIFFSetDirectory

See merge request libtiff/libtiff!474
2023-03-12 21:05:56 +00:00
Su Laus f0a7bb7bdc Optimize relative seeking with TIFFSetDirectory 2023-03-12 21:05:56 +00:00
Even Rouault 1d5b1181c9 Merge branch 'master' into 'master'
Fix memory leak in tiffcrop.c

See merge request libtiff/libtiff!475
2023-03-11 13:23:49 +00:00
zhailiangliang 881a070194 Fix memory leak in tiffcrop.c 2023-03-08 10:08:09 +08:00
Even Rouault 6bb0f1171a Merge branch 'skip-thumbnail-test' into 'master'
test: avoid running tool tests if not built

Closes #421

See merge request libtiff/libtiff!334
2023-02-23 21:20:14 +00:00
Sam James bda075a7f3 test (cmake): skip script tests if tools aren't built
In Gentoo, we avoid building the tools for multilib (32-bit, x86) builds on
amd64/x86_64 because we only need the library to keep binary applications working.

This causes a test failure in e.g. tiffcp-thumbnail.sh as the 'thumbnail'
binary isn't built. Skip it if unavailable.

Fixes: https://gitlab.com/libtiff/libtiff/-/issues/421
Signed-off-by: Sam James <sam@gentoo.org>
2023-02-22 22:59:11 +00:00
Sam James 223078d722 test (autotools): skip script tests if tools aren't built
In Gentoo, we avoid building the tools for multilib (32-bit, x86) builds on
amd64/x86_64 because we only need the library to keep binary applications working.

This causes a test failure in e.g. tiffcp-thumbnail.sh as the 'thumbnail'
binary isn't built. Skip it if unavailable.

Fixes: https://gitlab.com/libtiff/libtiff/-/issues/421
2023-02-22 22:58:39 +00:00
Even Rouault 61656f9218 Merge branch 'fix_Unlink_first_directory_0' into 'master'
Fix TIFFUnlinkDirectory(0) case and unlink of first directory.

See merge request libtiff/libtiff!460
2023-02-16 22:46:38 +00:00
Even Rouault d1f658afa5 Merge branch 'tif_luv_check_NaN_fix_#530' into 'master'
tif_luv: Check and correct for NaN data in uv_encode().

Closes #530

See merge request libtiff/libtiff!473
2023-02-16 15:18:55 +00:00
Su_Laus b0e1c25dd1 tif_luv: Check and correct for NaN data in uv_encode().
Closes #530

See merge request !473
2023-02-16 15:49:42 +01:00
Even Rouault c861f25cbc Merge branch 'tiffcrop_dont_reuse_input_buffer_fix_527' into 'master'
tiffcrop: Do not reuse input buffer for subsequent images. Fix issue 527

Closes #527

See merge request libtiff/libtiff!472
2023-02-14 20:41:35 +00:00
Su_Laus ec8ef90c1f tiffcrop: Do not reuse input buffer for subsequent images. Fix issue 527
Reuse of read_buff within loadImage() from previous image is quite unsafe, because other functions (like rotateImage() etc.) reallocate that buffer with different size without updating the local prev_readsize value.

Closes #527
2023-02-14 20:43:43 +01:00
Su_Laus aa2cd98b3e Fix 484 TIFFDirectory td_fieldsset uses unsigned long which can be 32 or 64 bits.
Closes #484
2023-02-08 21:36:18 +01:00
Even Rouault feb8db628d Merge branch 'test_ifd_loop_detection_fix_CoverityScan_ln_55' into 'master'
test_ifd_loop_detection: fix Coverity Scan issue CID 1520750: Null pointer...

See merge request libtiff/libtiff!470
2023-02-08 16:05:37 +00:00
Su_Laus 538b8f2935 test_ifd_loop_detection: fix Coverity Scan issue CID 1520750: Null pointer dereferences (NULL_RETURNS) line 55. 2023-02-08 14:14:09 +01:00
Even Rouault c8e1289def Merge branch 'tiffcrop_fix_CoverityScan_line_9676' into 'master'
Fix Coverity Scan issue CID 1520761: Integer handling issues...

See merge request libtiff/libtiff!469
2023-02-06 20:48:42 +00:00
Su_Laus 3f37593175 Fix Coverity Scan issue CID 1520761: Integer handling issues (OVERFLOW_BEFORE_WIDEN) tiffcrop.c: 9676 in rotateImage() 2023-02-06 21:10:30 +01:00
Even Rouault afaabc3e50 Merge branch 'tiffcrop_R270_fix#492' into 'master'
tiffcrop: Amend rotateImage() not to toggle the input (main) image width and...

Closes #519, #518, #499, #495, #494, #493 et #492

See merge request libtiff/libtiff!465
2023-02-05 17:49:05 +00:00
Su_Laus 69818e2f2d tiffcrop: Amend rotateImage() not to toggle the input (main) image width and length parameters when only cropped image sections are rotated.
Remove buffptr from region structure because never used.

Closes #492 #493 #494 #495 #499 #518 #519
2023-02-05 18:18:19 +01:00
Even Rouault 6366e8f776 Merge branch 'tiffcrop_correctly_update_buffersize_after_rotate_fix#520' into 'master'
tiffcrop correctly update buffersize after rotateImage() fix#520

Closes #520

See merge request libtiff/libtiff!467
2023-02-05 16:04:07 +00:00
Even Rouault 33aee1275d Merge branch 'tiffcrop_composite_image_assumption_test_fix#496' into 'master'
tiffcrop: added check for assumption on composite images (fixes #496)

Closes #501, #500, #498, #497 et #496

See merge request libtiff/libtiff!466
2023-02-05 15:53:16 +00:00
Su Laus 82a7fbb1fa tiffcrop: added check for assumption on composite images (fixes #496)
tiffcrop: For composite images with more than one region, the combined_length or combined_width always needs to be equal, respectively. Otherwise, even the first section/region copy action might cause buffer overrun. This is now checked before the first copy action.

Closes #496, #497, #498, #500, #501.
2023-02-05 15:53:15 +00:00
Su_Laus 688012dca2 tiffcrop correctly update buffersize after rotateImage() fix#520 -- enlarge buffsize and check integer overflow within rotateImage(). 2023-02-04 23:24:21 +01:00
Even Rouault ff049e353e Merge branch 'test_subidf_loop' into 'master'
test_ifd_loop_detection: Added test to check loops in SubIFDs that are chained.

See merge request libtiff/libtiff!464
2023-02-04 19:34:11 +00:00
Su Laus 8ef8f7ce21 test_ifd_loop_detection: Added test to check loops in SubIFDs that are chained. 2023-02-04 19:34:11 +00:00
Su_Laus 12ba27949b Fix TIFFUnlinkDirectory(0) case and unlink of first directory.
If directory number 0 is unlinked, then the base offset variables within LibTiff are not updated. As a result, a subsequent TIFFSetDirectory() first goes to the unlinked former directory  number 0.

In addition, the error case for dirn=0 is handled.

This MR fixes that by updating the base offset variables  tif->tif_header.classic.tiff_diroff and tif->tif_header.big.tiff_diroff.
2023-02-04 20:27:14 +01:00
Even Rouault f171d7a2cd Merge branch 'TiffClose_NULL_ptr_dereferencing_fix_515' into 'master'
TIFFClose() avoid NULL pointer dereferencing. fix#515

Closes #515

See merge request libtiff/libtiff!468
2023-02-03 17:46:26 +00:00
Su_Laus d63de61b1e TIFFClose() avoid NULL pointer dereferencing. fix#515
Closes #515
2023-02-03 17:38:55 +01:00
Su_Laus 9c22495e5e tiffcrop correctly update buffersize after rotateImage() fix#520
rotateImage() set up a new buffer and calculates its size individually. Therefore, seg_buffs[] size needs to be updated accordingly. Before this fix, the seg_buffs buffer size was calculated with a different formula than within rotateImage().

Closes #520.
2023-02-03 15:31:31 +01:00
Even Rouault a63e18ca43 Merge branch 'add_windows_DLL_versioninfo' into 'master'
Add versioninfo resource files for DLL and tools compiled with Windows MSVC and MINGW.

See merge request libtiff/libtiff!455
2023-01-25 16:04:51 +00:00
Su Laus e304e5a5cb Add versioninfo resource files for DLL and tools compiled with Windows MSVC and MINGW. 2023-01-25 16:04:50 +00:00
Even Rouault 0f8ae9442a Merge branch 'tif_hash_set_order_include' into 'master'
tif_hash_set.c: include tif_hash_set.h after tif_config.h to let a chance for...

See merge request libtiff/libtiff!462
2023-01-22 12:50:21 +00:00
Even Rouault bc4d708262 tif_hash_set.c: include tif_hash_set.h after tif_config.h to let a chance for GDAL symbol renaming trick 2023-01-22 13:31:46 +01:00
Even Rouault 46832efcb0 Merge branch 'fix_513' into 'master'
Fax3: fix failure to decode some fax3 images (fixes #513)

Closes #513

See merge request libtiff/libtiff!461
2023-01-22 12:26:22 +00:00
Even Rouault 9477634d2a Add test for Fax3 decoding issues (refs #513) 2023-01-21 22:51:55 +01:00
Even Rouault d1b6b9c1b3 Merge branch 'tiffcrop_fix_#488' into 'master'
tiffcrop: Correct simple copy paste error. Fix #488.

Closes #488

See merge request libtiff/libtiff!459
2023-01-21 15:58:10 +00:00
Su Laus 97d65859bc tiffcrop: Correct simple copy paste error. Fix #488. 2023-01-21 15:58:10 +00:00
Even Rouault 8a4f6b587b Fax3: fix failure to decode some fax3 images (fixes #513)
Patch by @jsummers26
2023-01-21 16:55:40 +01:00
Even Rouault 6be14e882f Merge branch 'tiffmedian_fix_#477' into 'master'
tiffmedian: avoid zero num_colors, fixes #477

Closes #477

See merge request libtiff/libtiff!458
2023-01-12 21:42:55 +00:00
Even Rouault c0f0316931 Merge branch 'fax2ps_fixes_#475' into 'master'
fax2ps: fixes #475 buffer overflow in qsort function pcompar.

Closes #475

See merge request libtiff/libtiff!457
2023-01-12 21:41:07 +00:00
Su_Laus 3c774f1903 tiffmedian: avoid zero num_colors, fixes #477 2023-01-12 22:33:46 +01:00
Su_Laus 188e054164 fax2ps: fixes #475 buffer overflow in qsort function pcompar. 2023-01-12 21:51:44 +01:00
Even Rouault 3f8db71882 Merge branch 'fix_241_tiffset_file_size_limit' into 'master'
tiffset: get filesize to allocate only the required memory. Fixes issue #241

Closes #241

See merge request libtiff/libtiff!451
2023-01-09 18:13:18 +00:00
Su Laus 7be6324424 tiffset: get filesize to allocate only the required memory. Fixes issue #241 2023-01-09 18:13:18 +00:00
Even Rouault 9ce5083225 Merge branch '_TIFFCleanupIFDOffsetAndNumberMaps' into 'master'
Add _TIFFCleanupIFDOffsetAndNumberMaps() and call it from TIFFUnlinkDirectory()

See merge request libtiff/libtiff!454
2023-01-09 18:11:33 +00:00
Even Rouault c074eb73d3 Remove use of tif_dirnumber 2023-01-06 15:23:06 +01:00
Even Rouault 47591619e1 TIFFSetSubDirectory(): call _TIFFCleanupIFDOffsetAndNumberMaps() 2023-01-06 15:19:40 +01:00
Even Rouault 1123f312b4 struct tiff: remove unused tif_dirlistoff 2023-01-06 15:18:36 +01:00
Even Rouault e146a61d9d TIFFUnlinkDirectory(): reset tif_dirnumber 2023-01-06 15:17:58 +01:00
Even Rouault 4eea4d5d93 Add _TIFFCleanupIFDOffsetAndNumberMaps() and call it from TIFFUnlinkDirectory() 2023-01-06 00:33:09 +01:00
Even Rouault 9f84326b13 Merge branch 'cmake_in_files_formatting_sensitive' into 'master'
Disable clang-formatting for tif_config.h.cmake.in and tiffconf.h.cmake.in...

See merge request libtiff/libtiff!452
2022-12-29 16:49:27 +00:00
Su_Laus bdaf7c7f4f Disable clang-formatting for tif_config.h.cmake.in and tiffconf.h.cmake.in because sensitive for CMake scripts. - explanation added 2022-12-28 20:21:22 +01:00
Su_Laus e131fde62b Disable clang-formatting for tif_config.h.cmake.in and tiffconf.h.cmake.in because sensitive for CMake scripts. 2022-12-26 17:39:48 +01:00
Even Rouault 3bde37ac83 Merge branch 'manpage_multi-page-TIFF' into 'master'
manpage: Add multi page TIFF and SubIFDs description and read / write example.

See merge request libtiff/libtiff!450
2022-12-19 21:30:42 +00:00
Su Laus dc3369a794 manpage: Add multi page TIFF and SubIFDs description and read / write example. 2022-12-19 21:30:42 +00:00
Even Rouault a34d7ddee2 Merge branch 'TIFFOpen_r+_windows_behaviour' into 'master'
Behavior of TIFFOpen() mode "r+" in the Windows implementation adjusted to that of Linux.

See merge request libtiff/libtiff!449
2022-12-18 20:23:52 +00:00
Su_Laus d46354584f Behavior of TIFFOpen() mode "r+" in the Windows implementation adjusted to that of Linux. 2022-12-16 18:47:55 +01:00
Miloš Komarčević 70645941f9 MinGW compilers don't need a .def file for shared library 2022-12-16 08:26:15 +00:00
Even Rouault 4bcdec3734 Merge branch 'ossfuzz_54343' into 'master'
TIFFSetDirectory: avoid harmless unsigned-integer-overflow

See merge request libtiff/libtiff!447
2022-12-15 21:34:00 +00:00
Even Rouault f1f86eedee TIFFSetDirectory: avoid harmless unsigned-integer-overflow
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54343
2022-12-15 22:15:03 +01:00
Even Rouault 0c16f2d84b Merge branch 'ossfuzz_54311' into 'master'
TIFFWriteDirectorySec(): avoid harmless unsigned-integer-overflow

See merge request libtiff/libtiff!446
2022-12-14 20:12:19 +00:00
Even Rouault c2a28a12c6 TIFFWriteDirectorySec(): avoid harmless unsigned-integer-overflow
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54311
2022-12-14 20:53:41 +01:00
Even Rouault 193c94b30c Merge branch 'hash_set_config' into 'master'
tif_hash_set.c: add a tif_config.h include (mostly for GDAL renaming symbols trick)

See merge request libtiff/libtiff!445
2022-12-13 23:49:42 +00:00
Even Rouault 3cfa4b9b12 tif_hash_set.c: add a tif_config.h include (mostly for GDAL renaming symbols trick) 2022-12-14 00:29:50 +01:00
Even Rouault 38eb7b00cb Merge branch 'fix_type_related_warnings_in_error' into 'master'
TIFFAdvanceDirectory()/TIFFUnlinkDirectory(): fix build warnings/errors on OSX...

See merge request libtiff/libtiff!444
2022-12-13 22:24:39 +00:00
Even Rouault a9de164cfa tiffinfo/tiffgt: more corect casts related to tdir_t changes 2022-12-13 22:56:54 +01:00
Even Rouault 8d5fbea923 TIFFAdvanceDirectory()/TIFFUnlinkDirectory(): fix build warnings/errors on OSX due to uint16_t->tdir_t type change 2022-12-13 22:45:19 +01:00
Even Rouault 06910438d1 Merge branch 'TIFFHashSetInsert_memleak_fix' into 'master'
TIFFHashSetInsert(): fix potential memleak

See merge request libtiff/libtiff!443
2022-12-13 19:04:26 +00:00
Even Rouault a03faa56c5 TIFFHashSetInsert(): fix potential memleak 2022-12-13 19:43:00 +01:00
Even Rouault 393a5ebe49 Merge branch '_TIFFCheckDirNumberAndOffset_use_after_free_fix' into 'master'
_TIFFCheckDirNumberAndOffset(): fix recently introduced use-after-free found by CIFuzz on GDAL

See merge request libtiff/libtiff!442
2022-12-13 17:26:47 +00:00
Even Rouault ff9a315b42 _TIFFCheckDirNumberAndOffset(): fix recently introduced use-after-free found by CIFuzz on GDAL 2022-12-13 18:06:33 +01:00
Even Rouault aec4ed6c3c Merge branch 'update_4_5_0rc2' into 'master'
Changelog: latest updates for 4.5.0rc2

See merge request libtiff/libtiff!441
2022-12-13 16:39:43 +00:00
Even Rouault be62af1f18 Changelog: latest updates for 4.5.0rc2 2022-12-13 17:39:00 +01:00
Even Rouault c4516f9dc7 Merge branch 'tiffinfo_adapt_curdir_tdir_t' into 'master'
tiffinfo: update curdir from uint16_t to tdir_t for more than 64k IFD handling.

See merge request libtiff/libtiff!440
2022-12-13 16:35:26 +00:00
Su_Laus 9103999432 tiffinfo: update curdir from uint16_t to tdir_t for more than 64k IFD handling. 2022-12-13 17:28:01 +01:00
Even Rouault 86993bbeb8 Merge branch '4_5_0rc2' into 'master'
Prepare libtiff v4.5.0rc2

See merge request libtiff/libtiff!439
2022-12-13 16:18:07 +00:00
Even Rouault 6e83cb0ea9 Update v4.5.0rst 2022-12-13 16:37:10 +01:00
Even Rouault 749edaed71 _TIFFCheckDirNumberAndOffset: fix a previous commit 2022-12-13 16:32:52 +01:00
Even Rouault 35f53f7a0b Prepare libtiff v4.5.0rc2 2022-12-13 16:26:51 +01:00
Even Rouault 87e0190d2d Merge branch 'fix_502' into 'master'
Make TIFFSetDirectory(tiff, 65534) work again (fixes #502)

Closes #502

See merge request libtiff/libtiff!436
2022-12-13 15:24:16 +00:00
Even Rouault 565b8923af Add tests for IFD loop detection 2022-12-13 15:19:46 +01:00
Even Rouault 2c0f2ed803 Fix IFD loop detection 2022-12-13 15:14:47 +01:00
Even Rouault 2c1d4b6b01 Use UINT_MAX 2022-12-13 13:14:30 +01:00
Even Rouault a1be870b1f Make TIFF_MAX_DIR_COUNT a autoconf/CMake setting 2022-12-13 13:12:49 +01:00
Even Rouault fa6f622f40 Merge branch 'build-shared-by-default' into 'master'
Restore shared libraries by default

See merge request libtiff/libtiff!437
2022-12-13 12:00:17 +00:00
shaun walbridge 21ad9b4412 CMake: restore shared libraries by default for top-level build 2022-12-13 12:00:17 +00:00
Even Rouault 0530835da4 Add a TIFF_MAX_DIR_COUNT public #define 2022-12-12 21:20:59 +01:00
Even Rouault 8f38557ef6 TIFFCurrentDirectory(), TIFFNumberOfDirectories(), TIFFSetDirectory(), TIFFUnlinkDirectory(): use tdir_t that is now a uint32_t, and raise limit of IFDs to 1048576 2022-12-12 20:35:46 +01:00
Even Rouault 2c015f27ba IFD loop checking: use hashmap to avoid quadratic performance 2022-12-12 19:42:56 +01:00
Even Rouault 1650d657ba Add a hashset/hashmap implementation (ported from GDAL's CPLHashSet) 2022-12-12 19:42:56 +01:00
Even Rouault 490a7df08f Make TIFFSetDirectory(tiff, 65534) work again (fixes #502) 2022-12-12 17:58:17 +01:00
Even Rouault 3da0dddadb Merge branch 'do_not_format_tiffvers_h' into 'master'
Revert formatting of tiffvers.h and add TIFFLIB_MAJOR_VERSION, TIFFLIB_MINOR_VERSION, TIFFLIB_MICRO_VERSION defines

See merge request libtiff/libtiff!434
2022-12-11 13:13:35 +00:00
Even Rouault 07042f1941 Merge branch 'tiffcrop_exclude_some_comment_from_clang-format' into 'master'
tiffcrop: Exclude some comments from clang-format

See merge request libtiff/libtiff!435
2022-12-11 11:22:56 +00:00
Su Laus f37aa3718f tiffcrop: Exclude some comments from clang-format 2022-12-11 11:22:56 +00:00
Even Rouault 23b315d10f tiffvers.h.in: add clang-format off/on 2022-12-11 12:21:56 +01:00
Even Rouault 2e7640c966 tiffvers.h: add TIFFLIB_MAJOR_VERSION, TIFFLIB_MINOR_VERSION, TIFFLIB_MICRO_VERSION defines
Also add a TIFFLIB_AT_LEAST() macro
2022-12-10 16:21:44 +01:00
Even Rouault 234971dfd8 tiffvers.h: revert formatting 2022-12-10 14:20:17 +01:00
Even Rouault ac45771ea4 Exclude reformatting of tiffvers.h which breaks version detection for FindTIFF.cmake 2022-12-10 14:20:06 +01:00
Even Rouault 9e233f6077 Merge branch 'release_4_5_0' into 'master'
Prepare v4.5.0 release

See merge request libtiff/libtiff!433
2022-12-09 15:33:24 +00:00
Even Rouault 59b6cd308a v4.5.0.rst: mention CVE numbers 2022-12-09 16:02:15 +01:00
Even Rouault c83c038d35 Prepare v4.5.0 release 2022-12-09 15:54:08 +01:00
Even Rouault cbb492c279 Merge branch 'reformat' into 'master'
Whole code-base reformatting

See merge request libtiff/libtiff!431
2022-12-08 18:44:45 +00:00
Even Rouault d7e78c1b37 Add .git-blame-ignore-revs 2022-12-08 19:20:35 +01:00
Even Rouault a51efc12b2 tiffcrop: remove version_id and rev_date 2022-12-08 19:20:05 +01:00
pre-commit run by Even Rouault aee0113f5e Reformatting in all other directories using 'pre-commit run' 2022-12-08 19:19:36 +01:00
pre-commit run by Even Rouault dee020782c Reformatting in test/ using 'pre-commit run' 2022-12-08 19:19:21 +01:00
pre-commit run by Even Rouault b0ae5d7071 Reformatting in tools/ using 'pre-commit run' 2022-12-08 19:19:07 +01:00
pre-commit run by Even Rouault 42173d6ace Reformatting in libtiff/ using 'pre-commit run' 2022-12-08 19:18:55 +01:00
Even Rouault 5e6a5fd6fa Add .clang-format, .pre-commit-config.yaml and CONTRIBUTING.md 2022-12-08 19:18:23 +01:00
Even Rouault 2d32ae7305 Remove vim/emacs formatting footers 2022-12-08 19:18:23 +01:00
Even Rouault 1bdbd03fbb Merge branch 'fix_489' into 'master'
TIFFWriteRawStrip(): restore capabilities to append data in the current strip (fixes #489)

Closes #489

See merge request libtiff/libtiff!430
2022-11-29 17:02:09 +00:00
Even Rouault db1d212786 Add test case for scenario of issue #489 2022-11-29 17:23:26 +01:00
Even Rouault 72de8fd00b TIFFWriteRawStrip(): restore capabilities to append data in the current strip (fixes #489)
This fixes a regression of libtiff 4.4.0
2022-11-29 15:00:27 +01:00
Even Rouault e72bfcfa0d Merge branch 'manpage_re-entrant_error_handler' into 'master'
manpage update for re-entrant error handler TIFFErrorExtR(), TIFFOpenExt() and...

See merge request libtiff/libtiff!427
2022-11-28 23:16:00 +00:00
Su Laus a2c551ee06 manpage update for re-entrant error handler TIFFErrorExtR(), TIFFOpenExt() and... 2022-11-28 23:16:00 +00:00
Even Rouault 0be1bf06c7 Merge branch 'tiffcrop_fix_#169' into 'master'
tiffcrop: Add check if (bps != 1) in writeSingleSection() for...

Closes #169

See merge request libtiff/libtiff!429
2022-11-27 20:34:40 +00:00
Su Laus d700853112 tiffcrop: Add check if (bps != 1) in writeSingleSection() for... 2022-11-27 20:34:40 +00:00
Even Rouault 94854a8dbc Merge branch 'TIFFErrorExtR_fix_missing_calls' into 'master'
TIFFErrorExt() was not replaced with TIFFErrorExtR() everywhere in libtiff....

See merge request libtiff/libtiff!428
2022-11-26 21:00:49 +00:00
Su Laus 4331d27569 TIFFErrorExt() was not replaced with TIFFErrorExtR() everywhere in libtiff.... 2022-11-26 21:00:49 +00:00
Even Rouault 70a164524e Merge branch 'tif_jpeg_build_fix' into 'master'
tif_jpeg.c: fix compilation with MSVC (fixes commit 0fd1a81d35)

See merge request libtiff/libtiff!426
2022-11-25 16:11:10 +00:00
Even Rouault ced264e91c tif_jpeg.c: fix compilation with MSVC (fixes commit 0fd1a81d35) 2022-11-25 16:34:26 +01:00
Even Rouault 5109b2bf50 Merge branch 'fix_0fd1a81d3547acb8f5be50bbbc3e44bde01c014b' into 'master'
JPEGEncode(): fix wrong pointer data type with libjpeg-turbo 2.2dev in 12-bit mode

See merge request libtiff/libtiff!425
2022-11-25 11:48:20 +00:00
Even Rouault ba51f97994 JPEGEncode(): fix wrong pointer data type with libjpeg-turbo 2.2dev in 12-bit mode
(fixes commit 0fd1a81d35)
2022-11-25 12:47:11 +01:00
Even Rouault 137e90d14d Merge branch 'libjpegturbo_dual' into 'master'
Add support for libjpeg-turbo 2.2-dev 8/12 bit dual mode

See merge request libtiff/libtiff!422
2022-11-25 11:26:45 +00:00
Even Rouault 0fd1a81d35 Add support for libjpeg-turbo 2.2-dev 8/12 bit dual mode 2022-11-25 11:26:45 +00:00
Even Rouault 38a582016c Merge branch 'windows-fix' into 'master'
libtiff: Fix TIFFOpen* for the Windows platform in tif_unix.c

See merge request libtiff/libtiff!424
2022-11-23 22:56:12 +00:00
Francois Bleibel 166accba60 libtiff: Fix TIFFOpen* for the Windows platform in tif_unix.c
I'm not sure where this change was made, but it must have been in a recent update. TIFFOpenWEx is now TIFFOpenWExt, and _TIFFgetMode takes additional arguments.

Verified: Tested libtiff on a local Windows build.
2022-11-23 14:29:41 -08:00
Even Rouault 0c4a6a72ad Merge branch 'tiffcrop_signed_vs_unsigned' into 'master'
tiffcrop.c: fix warning about signed vs unsigned comparison

See merge request libtiff/libtiff!423
2022-11-23 21:17:09 +00:00
Even Rouault 24d3b2425a tiffcrop.c: fix warning about signed vs unsigned comparison 2022-11-23 21:29:52 +01:00
Even Rouault 9b69732fec Merge branch 'TIFFClientOpenExt_warning_fix' into 'master'
TIFFClientOpenExt(): fix warning on 32-bit platforms (master only)

See merge request libtiff/libtiff!421
2022-11-23 13:32:26 +00:00
Even Rouault 6bcaf4a163 TIFFClientOpenExt(): fix warning on 32-bit platforms (master only) 2022-11-23 14:14:30 +01:00
Even Rouault 8e264807f1 Merge branch 'tiffcp_TIFFOpenOptionsFree_memleak_fix' into 'master'
tiffcp: fix leak of TIFFOpenOptionsAlloc() introduced in latest commit (master only)

See merge request libtiff/libtiff!420
2022-11-23 11:03:03 +00:00
Even Rouault b6480e872a tiffcp: fix leak of TIFFOpenOptionsAlloc() introduced in latest commit (master only)
Fixes Coverity CID 1517032
2022-11-23 11:44:47 +01:00
Even Rouault e920f4fee3 Merge branch 'TIFFOpenOptionsSetMaxSingleMemAlloc' into 'master'
Add TIFFOpenOptionsSetMaxSingleMemAlloc() to define a limit in bytes for a single memory allocation done by libtiff

See merge request libtiff/libtiff!419
2022-11-23 10:30:24 +00:00
Even Rouault ffe0666b8f Emit explicit error message when tif_max_single_mem_alloc is exceeded 2022-11-23 02:10:39 +01:00
Even Rouault 11afc7b734 test_open_options: test TIFFOpenOptionsSetMaxSingleMemAlloc() 2022-11-23 02:09:41 +01:00
Even Rouault 3727ce6fe1 Rename test_error_handlers to test_open_options 2022-11-23 02:09:40 +01:00
Even Rouault 0ad56c292a tiffinfo, tiffcp, tiffcrop, tiffsplit, tiff2rgba, tiff2ps: use TIFFOpenOptionsSetMaxSingleMemAlloc() 2022-11-23 02:09:40 +01:00
Even Rouault 553bb4b207 Convert uses of _TIFFmalloc/realloc/calloc/free to the Ext functions 2022-11-23 02:09:40 +01:00
Even Rouault b88c3f9af2 Add TIFFOpenOptionsSetMaxSingleMemAlloc()
to define a limit in bytes for a single memory allocation done by libtiff.

Also add internal functions used in replacement of the non Ext ones:
void* _TIFFmallocExt(TIFF* tif, tmsize_t s);
void* _TIFFcallocExt(TIFF* tif, tmsize_t nmemb, tmsize_t siz);
void* _TIFFreallocExt(TIFF* tif, void* p, tmsize_t s);
void _TIFFfreeExt(TIFF* tif, void* p);
2022-11-22 18:17:34 +01:00
Even Rouault d95b5b7628 Merge branch 'TIFFOpenEx' into 'master'
Add TIFFOpenExt(), TIFFOpenWExt() and TIFFFdOpenExt() with re-entrant error handlers

See merge request libtiff/libtiff!413
2022-11-21 23:59:12 +00:00
Even Rouault ec18caeb67 Remove TIFFSetErrorHandlerExtR() and TIFFSetWarningHandlerExtR() that were temporarily added in master 2022-11-21 23:23:45 +01:00
Even Rouault 73d34370e1 Add a _TIFFErrorEarly() function to be able to use the re-entrant error handler, even before TIFF* is valid 2022-11-21 23:23:23 +01:00
Even Rouault 21d7dac23f Rework TIFFOpenExt() and similar to use an opaque TIFFOpenOptions* opts argument, with alloc, free and setters 2022-11-21 23:23:23 +01:00
Even Rouault 352c1a7d03 Document TIFFOpenExt, TIFFOpenWExt, TIFFFdOpenExt, TIFFClientOpenExt, TIFFSetErrorHandlerExtR, TIFFSetWarningHandlerExtR 2022-11-21 23:22:43 +01:00
Even Rouault 91e95ee9ae Add TIFFOpenExt(), TIFFOpenWExt() and TIFFFdOpenExt() with re-entrant error handlers
Rename TIFFClientOpenEx() to TIFFClientOpenExt()

Rework signature of the re-entrant error handlers and of
TIFFSetWarningHandlerExt() and TIFFSetErrorHandlerExt()

Use structures that can be extended as extra argument.

Leverages and ammends https://gitlab.com/libtiff/libtiff/-/merge_requests/409
2022-11-21 23:21:13 +01:00
Even Rouault e7e567536b Merge branch 'manpage_fix485_file-descriptor_clientdata' into 'master'
manpage: Correct description of file handle/descriptors tif_fd and tif_clientdata. Closes #485.

Closes #485

See merge request libtiff/libtiff!418
2022-11-21 22:20:18 +00:00
Su Laus 56d05b4c38 manpage: Correct description of file handle/descriptors tif_fd and tif_clientdata. Closes #485. 2022-11-21 22:20:18 +00:00
Even Rouault f29061e600 Merge branch 'manpage_fix440_fix28_TIFFOpen_SubIFD_update' into 'master'
manpage: fix28, fix440, update TIFFOpen and SubIFD

Closes #440 et #28

See merge request libtiff/libtiff!417
2022-11-20 19:39:23 +00:00
Su Laus eee54b38ec manpage: fix28, fix440, update TIFFOpen and SubIFD 2022-11-20 19:39:22 +00:00
Even Rouault a0f7b1ed8a Merge branch 'cmake_tiff_install_warning' into 'master'
CMakeLists.txt: fix warning with -Wdev

See merge request libtiff/libtiff!416
2022-11-17 21:11:13 +00:00
Even Rouault 1e5e7f346b CMakeLists.txt: fix warning with -Wdev
```
CMake Warning (dev) at CMakeLists.txt:62 (option):
  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  For compatibility with older versions of CMake, option is clearing the
  normal variable 'tiff-install'.
This warning is for project developers.  Use -Wno-dev to suppress it.
```
2022-11-13 17:28:00 +01:00
Even Rouault 31d9e9f73d Merge branch 'fix_479' into 'master'
_TIFFReadEncodedTileAndAllocBuffer(): avoid excessive memory allocation on...

See merge request libtiff/libtiff!412
2022-11-12 16:05:12 +00:00
Even Rouault 056dd97f45 Merge branch 'typo_fix' into 'master'
tif_dirread.c: fix typo in comment

See merge request libtiff/libtiff!414
2022-11-12 01:40:24 +00:00
Even Rouault a907281532 tif_dirread.c: fix typo in comment 2022-11-12 02:24:11 +01:00
Even Rouault 876aa5168f _TIFFReadEncodedTileAndAllocBuffer(): avoid excessive memory allocation on broken files (fixes #479) 2022-11-11 12:58:08 +01:00
Even Rouault 9b630b86ba Merge branch 'bugfix/tiff2pdf-stdout' into 'master'
tiff2pdf Don't try to seek into stdout.

See merge request libtiff/libtiff!367
2022-11-10 13:45:08 +00:00
Claus-Justus Heine 1e013463ae tiff2pdf: Don't try to seek into stdout.
Fixes #441
2022-11-10 13:45:08 +00:00
Even Rouault 43c28e3f6a Merge branch 'fix_coverity_1516759' into 'master'
TIFFErrorExtR(): fix Dereference after null check (CID 1516759)

See merge request libtiff/libtiff!411
2022-11-08 15:13:56 +00:00
Even Rouault a05860a087 Merge branch 'fix_ossfuzz_53137' into 'master'
TIFFReadRGBATileExt(): fix (unsigned) integer overflow on strips/tiles > 2 GB

See merge request libtiff/libtiff!410
2022-11-08 14:55:36 +00:00
Even Rouault 4e17d7fbe2 TIFFErrorExtR(): fix Dereference after null check (CID 1516759) 2022-11-08 15:54:59 +01:00
Even Rouault f25d951a1c Merge branch 'no_sprintf' into 'master'
Replace sprintf calls with snprintf

See merge request libtiff/libtiff!408
2022-11-08 14:47:45 +00:00
Mark Mentovai 72e90d07fb Replace sprintf calls with snprintf
This makes it possible to build libtiff without warnings using the macOS
13 SDK. Calls to sprintf are replaced with snprintf, passing appropriate
buffer sizes.

It doesn’t appear that any of the changed uses of sprintf were actually
unsafe, so no behavior change is expected aside from SDK compatibility.

The macOS 13 SDK deprecates sprintf as it’s difficult to use safely. The
deprecation warning message is visible when building C++, but it is not
normally visible when building plain C code due to a quirk in how
sprintf is declared in the SDK. However, the deprecation message is
visible when building plain C under Address Sanitizer
(-fsanitize=address). This discrepancy was discovered at
https://crbug.com/1381706 and reported to Apple with a copy at
https://openradar.appspot.com/FB11761475.

The macOS 13 SDK is packaged in Xcode 14.1, released on 2022-11-01. This
also affects the iOS 16 SDK and other 2022-era Apple OS SDKs packaged in
Xcode 14.0, released on 2022-09-12.

libtiff is visible to the Chromium build via PDFium, and this change is
needed to allow Chromium to move forward to the macOS 13 SDK.

This change is limited to the libtiff directory. Other uses of sprintf
were found in contrib, test, and tools.
2022-11-08 09:44:14 -05:00
Even Rouault c20132c278 Merge branch 'reentrant' into 'master'
Add reentrant error functions

See merge request libtiff/libtiff!409
2022-11-08 14:38:58 +00:00
Even Rouault 227500897d TIFFReadRGBATileExt(): fix (unsigned) integer overflow on strips/tiles > 2 GB
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53137
2022-11-08 15:17:00 +01:00
Laramie Leavitt aa863b5e82 Add reentrant error functions
Prior to this change, libtiff relied on global error handlers,
which is problematic when libtiff used by multiple independent
libraries from within the same process, as they may unwittingly
clobber the error handling, introduce race conditions when setting
handlers, or otherwise have unintended side effects.

This change adds error handlers to the TIFF struct, which are
used preferentially when available. The error handlers are invoked
when the re-entrant error functions are called:

void TIFFErrorExtR(TIFF*, const char* module, const char* fmt, ...)
void TIFFWarningExtR(TIFF*, const char* module, const char* fmt, ...)

The handlers have a similar signature to the existing extended
handlers, additionally returning an int:

int TIFFErrorHandlerExtR(thandle_t, const char*, const char*, va_list)

 thandle_t is the userdata passed to TIFFOpen
 When the handler returns 1, the global handlers are not called.

Custom error/warning handlers may be installed on a per-file
basis by calling the Set functions:

  TIFF* tif = TIFFOpen(...);
  TIFFSetErrorHandlerExtR(tif, MyErrorHandler);
  TIFFSetWarningHandlerExtR(tif, MyWarningHandler);

Additionally, the callsites to TIFFErrorExt and TIFFWarningExt
have been updated to call the reentrant versions.
2022-11-08 15:12:51 +01:00
Even Rouault ec862ac774 Merge branch 'tiffcrop_fix_CoverityScan_tmsize_issue' into 'master'
tiffcrop: should fix some Coverity Scan issues OVERFLOW_BEFORE_WIDEN

See merge request libtiff/libtiff!403
2022-11-08 14:03:05 +00:00
Su Laus bdd7eba876 tiffcrop: should fix some Coverity Scan issues OVERFLOW_BEFORE_WIDEN 2022-11-08 14:03:05 +00:00
Even Rouault ddef030d3d Merge branch 'typo_fix' into 'master'
tif_dirread.c: fix typo in comment

See merge request libtiff/libtiff!407
2022-11-02 11:45:19 +00:00
Even Rouault 36a18e2401 tif_dirread.c: fix typo in comment 2022-11-02 12:28:01 +01:00
Even Rouault a7ac2a4235 Merge branch 'tiffcrop_formatting_fix' into 'master'
tiffcrop: add casts in TIFFError() to fix compiler warnings

See merge request libtiff/libtiff!406
2022-10-23 13:16:16 +00:00
Even Rouault fcbc4798ab Merge branch 'fix_482' into 'master'
CMake: correctly set default value of 'lzma' option when liblzma is detected (fixes #482)

Closes #482

See merge request libtiff/libtiff!404
2022-10-23 12:44:06 +00:00
Even Rouault 6f7c1ce57f tiffcrop: add casts in TIFFError() to fix compiler warnings 2022-10-23 14:40:02 +02:00
Even Rouault 58ad3b5635 CMake: correctly set default value of 'lzma' option when liblzma is detected (fixes #482) 2022-10-23 14:27:28 +02:00
Even Rouault 777080cd1f Merge branch 'fix_480' into 'master'
Fix incorrect printf() formatters introduced in recent commits (fixes #480)

Closes #480

See merge request libtiff/libtiff!401
2022-10-20 10:32:24 +00:00
Even Rouault 226345c23e Fix incorrect printf() formatters introduced in recent commits (fixes #480) 2022-10-19 18:30:54 +02:00
Even Rouault 096a228dba Merge branch 'CLIPPATH_tags_corrected' into 'master'
CLIPPATH tags defined twice but differently and also wrongly (#439) - corrected

Closes #439

See merge request libtiff/libtiff!366
2022-10-13 19:32:02 +00:00
Even Rouault 923d0f34c4 Merge branch 'FIELD_IGNORE_warning-messages' into 'master'
Warning messages for FIELD_IGNORE tags for writing and for TIFF_SETGET_UNDEFINED for reading added. (#438)

Closes #438

See merge request libtiff/libtiff!365
2022-10-13 19:30:59 +00:00
Su Laus 2abc5c6a28 Warning messages for FIELD_IGNORE tags for writing and for TIFF_SETGET_UNDEFINED for reading added. (#438) 2022-10-13 19:30:59 +00:00
Even Rouault caabf73d19 Merge branch 'tag-def_COMPRESSION_corrected' into 'master'
tif_dirinfo.c TIFFTAG_COMPRESSION and _BITSPERSAMPLE definition corrected

See merge request libtiff/libtiff!364
2022-10-13 19:28:29 +00:00
Even Rouault 32c6d09814 Merge branch 'fix_getopt_included_twice' into 'master'
Fix including module getopt.c twice with CMake and HAVE_GETOPT=false

See merge request libtiff/libtiff!381
2022-10-13 19:26:53 +00:00
Even Rouault cccc118091 Merge branch 'tiffcrop_CoverityScan_fix_PRINTF_ARGS' into 'master'
tiffcrop: fix Coverity Scan issues about PRINTF_ARGS.

See merge request libtiff/libtiff!400
2022-10-13 19:26:11 +00:00
Su_Laus ef68c48815 tiffcrop fix Coverity Scan issues about PRINTF_ARGS. 2022-10-13 20:50:58 +02:00
Even Rouault 49e8f80394 Merge branch 'tiffcrop_fix_#450_too-many-mode-options' into 'master'
tiffcrop: fix #450 too many 'mode' options on command line.

Closes #470 et #450

See merge request libtiff/libtiff!384
2022-10-13 15:16:33 +00:00
Su Laus f65c079c28 tiffcrop: fix #450 too many 'mode' options on command line. 2022-10-13 15:16:33 +00:00
Even Rouault cfbb883bf6 Merge branch 'tiffcrop_fix_#435' into 'master'
tiffcrop subroutines require a larger buffer (fixes #271, #381, #386, #388, #389, #435)

Closes #465, #464, #435, #389, #388, #386, #381 et #271

See merge request libtiff/libtiff!382
2022-10-13 14:33:28 +00:00
Su Laus afd7086090 tiffcrop subroutines require a larger buffer (fixes #271, #381, #386, #388, #389, #435) 2022-10-13 14:33:27 +00:00
Even Rouault e813112545 Merge branch 'InkNames_NumberOfInks_handling_revised' into 'master'
Revised handling of TIFFTAG_INKNAMES and related TIFFTAG_NUMBEROFINKS value (fixes #149, #150, #152, #168, #250, #269, #398 and #456)

Closes #474, #463, #387, #456, #398, #269, #250, #168, #152, #150 et #149

See merge request libtiff/libtiff!385
2022-10-12 21:03:31 +00:00
Even Rouault 236b7191f0 Merge branch 'tiffcrop_fix_#411_#413' into 'master'
tiffcrop: disable incompatibility of -Z, -X, -Y, -z options with any PAGE_MODE_x option (fixes #411, #413 and #426)

Closes #426, #413 et #411

See merge request libtiff/libtiff!383
2022-10-12 20:54:01 +00:00
Even Rouault a5c596561a Merge branch 'TIFFAdvanceDirectory_mapped_uio' into 'master'
TIFFAdvanceDirectory(): fix unsigned-integer-overflow in mapped case

See merge request libtiff/libtiff!398
2022-10-10 21:05:51 +00:00
Even Rouault 343118c63c TIFFAdvanceDirectory(): fix unsigned-integer-overflow in mapped case
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52309
2022-10-10 22:25:02 +02:00
Even Rouault 8bfc011991 Merge branch 'tiffinfo_parse_SubIFDs' into 'master'
tiffinfo: Updated to parse through SubIFDs and show their tags.

See merge request libtiff/libtiff!396
2022-10-08 14:52:24 +00:00
Su Laus fa99e8c88d tiffinfo: Updated to parse through SubIFDs and show their tags. 2022-10-08 14:52:24 +00:00
Roger Leigh 47e61f69b3 Merge branch 'master' into 'master'
Moved linking of CMath::CMath into CMath_LIBRARY check

See merge request libtiff/libtiff!397
2022-10-07 13:53:09 +00:00
Frei Herr eed69b50e7 Moved linking of CMath::CMath into CMath_LIBRARY check 2022-10-07 11:26:41 +00:00
Even Rouault f21ecf4a77 Merge branch 'rational_precision2double_coverity-fix' into 'master'
rational_precision2double.c: Fix issue from Coverity Scan.

See merge request libtiff/libtiff!395
2022-10-06 13:06:29 +00:00
Su_Laus 692870df22 rational_precision2double.c: Fix issue from Coverity Scan. 2022-10-06 14:37:38 +02:00
Su_Laus d1d87635f1 Fix including module getopt.c twice with CMake and HAVE_GETOPT=false
The "make-files" for the tools- and test- programmes include the module getopt.c once directly as additional source and then again by including port.lib.
This can be avoided by including getopt.c as source in port.lib within port\CMakeLists.txt not with PUBLIC but with PRIVATE.
2022-10-06 13:41:27 +02:00
Even Rouault d093eb5d96 Merge branch 'fix-455_Improved-IFD-loop-handling' into 'master'
Improved IFD-Loop Handling (fixes #455)

Closes #455

See merge request libtiff/libtiff!386
2022-10-06 10:11:06 +00:00
Su Laus c7caec9a4d Improved IFD-Loop Handling (fixes #455)
IFD infinite looping was not fixed by MR 20 (see #455).
An improved IFD loop handling is proposed.

Basic approach:

- The order in the entire chain must be checked, and not only whether an offset has already been read once.
- To do this, pairs of directory number and offset are stored and checked.
- The offset of a directory number can change.
- TIFFAdvanceDirectory() must also perform an IFD loop check.
- TIFFCheckDirOffset() is replaced by _TIFFCheckDirNumberAndOffset().

Rules for the check:

- If an offset is already in the list, it must have the same IFD number. Otherwise it is an IDF loop.
- If the offset is not in the list and the IFD number is greater than there are list entries, a new list entry is added.
- Otherwise, the offset of the IFD number is updated.

Reference is also made to old bugzilla bug 2772 and MR 20, which did not solve the general issue.
This MR closes #455
2022-10-06 10:11:05 +00:00
Roger Leigh 3a1647ea9c Merge branch 'fix-cmake-subproject' into 'master'
Fix CMake build to be compatible with FetchContent

See merge request libtiff/libtiff!394
2022-10-05 05:39:31 +00:00
Timothy Lyanguzov 7d0ed2ed5e Apply 9 suggestion(s) to 3 file(s) 2022-10-04 16:38:06 +00:00
Jeremy Maitin-Shepard 814a2441e7 Fix CMake build to be compatible with FetchContent
Recent versions of CMake have improved support for including
dependencies, using the FetchContent module, which allows a dependency
to be imported as a subproject and then later found automatically by
calls to `find_package`.

This change makes libtiff's CMake better behaved when used as a
sub-project:

- CMake has a single global namespace for all target names in all
  sub-projects.  This commit renames the following CMake targets:

  - port -> tiff_port
  - mkg3states -> tiff_mkg3states
  - faxtable -> tiff_faxtable
  - release -> tiff_release

- When building TIFF as a sub-project, it is not normally useful to
  create install rules for its targets.  This commit adds a
  `tiff-install` option that controls whether the install rules are
  added and defaults to OFF when libtiff is included as a sub-project.

- Previously, libtiff set `BUILD_SHARED_LIBS` to ON by default.  With
  this commit, that default is only set if libtiff is the top-level
  project.

- When using `find_package(TIFF)`, the targets `TIFF::TIFF` and
  `TIFF::CXX` are defined.  This commit makes libtiff itself define
  those targets as aliases, to allow other cmake projects to use
  either `find_package` or `FetchContent` interchangeably.

- Adds ZSTD_HAVE_DECOMPRESS_STREAM variable which may be set to bypass
  `check_symbol_exists` call.  Fixes
  https://gitlab.com/libtiff/libtiff/-/issues/472.
2022-10-03 15:41:07 -07:00
Even Rouault 99c2808521 Merge branch 'getimage_overflow' into 'master'
Update getimage to support reading large raster images

See merge request libtiff/libtiff!389
2022-09-27 18:54:38 +00:00
Even Rouault 8c23b6fa5c Merge branch 'MinGW-warnings_ipctutil' into 'master'
Fix #458: MinGW Windows 64: warning because 'long' is a 32 bits type in...

Closes #458

See merge request libtiff/libtiff!391
2022-09-26 18:06:11 +00:00
Su Laus 6ac3c7a0b0 Fix #458: MinGW Windows 64: warning because 'long' is a 32 bits type in... 2022-09-26 18:06:11 +00:00
Eric Siegel 993c4885c6 Update getimage to support large raster images 2022-09-15 20:26:34 -07:00
Even Rouault 4c3ddd99b6 Merge branch 'typo_fix' into 'master'
tif_lzw.c: fix typo in code comment

See merge request libtiff/libtiff!387
2022-09-08 16:32:59 +00:00
Even Rouault 300ca7731c tif_lzw.c: fix typo in code comment 2022-09-08 18:15:45 +02:00
Su_Laus f00484b951 Revised handling of TIFFTAG_INKNAMES and related TIFFTAG_NUMBEROFINKS value
In order to solve the buffer overflow issues related to TIFFTAG_INKNAMES and related TIFFTAG_NUMBEROFINKS value, a revised handling of those tags within LibTiff is proposed:

Behaviour for writing:
    `NumberOfInks`  MUST fit to the number of inks in the `InkNames` string.
    `NumberOfInks` is automatically set when `InkNames` is set.
    If `NumberOfInks` is different to the number of inks within `InkNames` string, that will be corrected and a warning is issued.
    If `NumberOfInks` is not equal to samplesperpixel only a warning will be issued.

Behaviour for reading:
    When reading `InkNames` from a TIFF file, the `NumberOfInks` will be set automatically to the number of inks in `InkNames` string.
    If `NumberOfInks` is different to the number of inks within `InkNames` string, that will be corrected and a warning is issued.
    If  `NumberOfInks` is not equal to samplesperpixel only a warning will be issued.

This allows the safe use of the NumberOfInks value to read out the InkNames without buffer overflow

This MR will close the following issues:  #149, #150, #152, #168 (to be checked), #250, #269, #398 and #456.

It also fixes the old bug at http://bugzilla.maptools.org/show_bug.cgi?id=2599, for which the limitation of `NumberOfInks = SPP` was introduced, which is in my opinion not necessary and does not solve the general issue.
2022-08-30 16:56:48 +02:00
Su_Laus 4746f16253 tiffcrop: disable incompatibility of -Z, -X, -Y, -z options with any PAGE_MODE_x option (fixes #411 and #413)
tiffcrop does not support –Z, -z, -X and –Y options together with any other PAGE_MODE_x options like  -H, -V, -P, -J, -K or –S.

Code analysis:

With the options –Z, -z, the crop.selections are set to a value > 0. Within main(), this triggers the call of processCropSelections(), which copies the sections from the read_buff into seg_buffs[].
In the following code in main(), the only supported step, where that seg_buffs are further handled are within an if-clause with  if (page.mode == PAGE_MODE_NONE) .

Execution of the else-clause often leads to buffer-overflows.

Therefore, the above option combination is not supported and will be disabled to prevent those buffer-overflows.

The MR solves issues #411 and #413.
2022-08-25 16:31:26 +02:00
Even Rouault 48d6ece838 Merge branch 'tiffcrop_S-option_mutually_exclusive' into 'master'
tiffcrop:  -S option mutually exclusive (fixes #349, #414, #422, #423, #424)

Closes #424, #423, #422, #414 et #349

See merge request libtiff/libtiff!378
2022-08-21 09:45:03 +00:00
Su_Laus bad48e90b4 tiffcrop -S option: Make decision simpler. 2022-08-20 23:35:26 +02:00
Even Rouault a10572b70d Merge branch 'remove_death_commented_code' into 'master'
Remove dead code from tif_dirread.c, tif_dirwrite.c and tif_getimage.c

See merge request libtiff/libtiff!380
2022-08-20 18:01:33 +00:00
Su Laus 8fc154b6c5 Remove dead code from tif_dirread.c, tif_dirwrite.c and tif_getimage.c 2022-08-20 18:01:33 +00:00
Even Rouault 728e1495e4 Merge branch 'coverity_fixes' into 'master'
Silence Coverity Scan false positive warnings about out-of-bounds access

See merge request libtiff/libtiff!379
2022-08-16 09:14:12 +00:00
Even Rouault c5c9864714 tif_zip.c: silence Coverity Scan false positive warnings about out-of-bounds access (CID 1491190, 1491197, 1491201) 2022-08-16 10:43:47 +02:00
Even Rouault 3b727a6b17 tif_dirread.c: silence Coverity Scan false positive warnings about out-of-bounds access (CID 1491182, 1491186) 2022-08-16 10:40:07 +02:00
Even Rouault ac6ddaf678 Merge branch 'default_tag_values_extended' into 'master'
Presetting of default tag values extended (e.g. PlanarConfig). (fixes #449)

Closes #449

See merge request libtiff/libtiff!377
2022-08-16 07:04:19 +00:00
Su Laus e70dee48f5 Presetting of default tag values extended (e.g. PlanarConfig). (fixes #449) 2022-08-16 07:04:19 +00:00
Su_Laus 8fe3735942 According to Richard Nolde https://gitlab.com/libtiff/libtiff/-/issues/401#note_877637400 the tiffcrop option „-S“ is also mutually exclusive to the other crop options (-X|-Y), -Z and -z.
This is now checked and ends tiffcrop if those arguments are not mutually exclusive.

This MR will fix the following tiffcrop issues: #349, #414, #422, #423, #424
2022-08-15 22:11:03 +02:00
Even Rouault 5b1f85b55c Merge branch 'warning_fix' into 'master'
Fix warning about shadowing

See merge request libtiff/libtiff!376
2022-08-09 21:06:57 +00:00
Even Rouault 5934fd2d88 Fix warning about shadowing 2022-08-09 22:48:25 +02:00
Even Rouault 84218df092 Merge branch 'fix_225' into 'master'
Deal with RichTIFFIPTC tag written with LONG type (fixes #225)

Closes #225

See merge request libtiff/libtiff!374
2022-08-09 20:35:26 +00:00
Even Rouault 9c03a345fe Merge branch 'Writing_IFD8_to_ClassicTIFF_bugfix' into 'master'
Correcting defects reported by Coverity Scan for MR !369

See merge request libtiff/libtiff!375
2022-08-09 19:59:23 +00:00
Su Laus 27a45b790e Correcting defects reported by Coverity Scan for MR !369 2022-08-09 19:59:23 +00:00
Even Rouault ed8b658bf9 Merge branch 'fix_442_Writing_IFD8_to_ClassicTIFF' into 'master'
TIFFSetValue(): Writing IFD8 & LONG8 tags to ClassicTIFF corrected (fixes #442)

Closes #442

See merge request libtiff/libtiff!369
2022-08-09 15:15:57 +00:00
Su Laus af1cf0789a TIFFSetValue(): Writing IFD8 & LONG8 tags to ClassicTIFF corrected (fixes #442) 2022-08-09 15:15:57 +00:00
Even Rouault e6b07b2ef4 Deal with RichTIFFIPTC tag written with LONG type (fixes #225) 2022-08-09 11:16:27 +02:00
Roger Leigh b5d7d508ff Merge branch 'manpage-functions-added' into 'master'
doc: Missing public functions added to TIFF documentation in Sphinx

See merge request libtiff/libtiff!372
2022-08-07 20:52:27 +00:00
Su Laus 644558a24f doc: Missing public functions added to TIFF documentation in Sphinx 2022-08-07 20:52:27 +00:00
Even Rouault 372371501b Merge branch 'tifjpeg_version_check' into 'master'
tif_jpeg.c: allow to pass -DEXPECTED_JPEG_LIB_VERSION=number to do optional...

See merge request libtiff/libtiff!373
2022-07-29 14:38:50 +00:00
Even Rouault fd82c68d18 tif_jpeg.c: allow to pass -DEXPECTED_JPEG_LIB_VERSION=number to do optional compile-time version check 2022-07-29 13:13:34 +02:00
Even Rouault c3f095e6cd Merge branch 'TIFFReadFromUserBuffer_fix' into 'master'
TIFFReadFromUserBuffer(): fix clearing of TIFF_CODERSETUP flag that could...

See merge request libtiff/libtiff!371
2022-07-21 10:42:18 +00:00
Even Rouault c1dfe33a8c TIFFReadFromUserBuffer(): fix clearing of TIFF_CODERSETUP flag that could cause issues with reading JPEG compressed files 2022-07-21 11:25:57 +02:00
Roger Leigh 71d5d20f11 Merge branch 'vs2022-fixes' into 'master'
cmake: Correct duplicate definition of _CRT_SECURE_NO_WARNINGS

Closes #443

See merge request libtiff/libtiff!370
2022-07-20 23:43:53 +00:00
Roger Leigh 7da8c385e0 cmake: Correct duplicate definition of _CRT_SECURE_NO_WARNINGS 2022-07-13 21:29:41 +01:00
Even Rouault 35abe37853 Merge branch 'vs2022-fixes' into 'master'
cmake: Fixes for Visual Studio 2022

See merge request libtiff/libtiff!368
2022-07-13 09:13:36 +00:00
Roger Leigh 42fc3324e1 cmake: Fixes for Visual Studio 2022 2022-07-13 06:56:03 +01:00
Roger Leigh 115e1aea6b Merge branch 'elf-symbol-export' into 'master'
Explicit export of versioned ELF symbols

Closes #437

See merge request libtiff/libtiff!361
2022-07-03 18:34:06 +00:00
Even Rouault 5e60251ea8 Merge branch 'fix_433' into 'master'
_TIFFCheckFieldIsValidForCodec(): return FALSE when passed a codec-specific...

Closes #433

See merge request libtiff/libtiff!363
2022-07-03 17:28:04 +00:00
Su_Laus d4dd5c66d4 CLIPPATH tags defined twice but differently and also wrongly
In tif_dirinfo.c the tags for clippath are wrongly defined and the tag TIFFTAG_XCLIPPATHUNITS is even different twice. Therefore, those tags cannot be written / read correctly and may even lead to buffer overflow.
E.g.: In the case of TIFFSetField(YCLIPPATHUNITS), a 1 byte storage space is allocated because of TIFF_SETGET_UNDEFINED, in which an  int32_t value should be stored because of TIFF_SLONG type definition. Then, an int32_t value is read from that 1 byte storage location.

The current definition is:

{ TIFFTAG_CLIPPATH, -1, -3, TIFF_BYTE, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ClipPath", NULL },
{ TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_SLONG, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL },
{ TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_SBYTE, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL },
{ TIFFTAG_YCLIPPATHUNITS, 1, 1, TIFF_SLONG, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YClipPathUnits", NULL },

Whereas the correct definition according to TIFF Specification Supplement 1 (https://www.awaresystems.be/imaging/tiff/specification/TIFFPM6.pdf) should be:

{ TIFFTAG_CLIPPATH, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ClipPath", NULL },
{ TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL },
{ TIFFTAG_YCLIPPATHUNITS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YClipPathUnits", NULL },

Also the set_get_field of the following tag should be corrected from

{ TIFFTAG_INTEROPERABILITYIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InteroperabilityIFDOffset", NULL },
to
{ TIFFTAG_INTEROPERABILITYIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InteroperabilityIFDOffset", NULL },

However, if those tags schould not be handled by LibTiff because they are deamed as abandoned or unwanted tags, those tags need to be defined with FIELD_IGNORE instead of FIELD_CUSTOM and keeping set_field_type  = TIFF_SETGET_UNDEFINED
2022-07-01 22:28:16 +02:00
Su_Laus 6e3d33b5c0 In tif_dirinfo.c the definition for TIFFTAG_COMPRESSION has different settings of field_readcount=TIFF_VARIABLE (-1) and field_writecount=1. The tag is defined with Count=1, thus field_readcount is wrong and should also be 1.
Although TIFFTAG_BITSPERSAMPLE is defined with Count:N=SamplesPerPixel, only ONE uint16_t value is passed with TIFFSetField() and TIFFGetField(). However, an array with N=SamplesPerPixel equal values is written into the TIFF file.
Shouldn't field_readcount = field_writecount = 1 then?  The behaviour of TiffLib does not change, because the handling is coded directly.
2022-07-01 21:10:29 +02:00
Even Rouault 275735d035 _TIFFCheckFieldIsValidForCodec(): return FALSE when passed a codec-specific tag and the codec is not configured (fixes #433)
This avoids crashes when querying such tags
2022-06-27 16:09:54 +02:00
Even Rouault 1dbcacd786 Merge branch '16bit_cielab' into 'master'
add basic 16bit-cielab support

See merge request libtiff/libtiff!336
2022-06-27 10:19:39 +00:00
Caolán McNamara f828040e88 Add basic 16bit-cielab support
just a copy of putcontig8bitCIELab that reads 16bit vals but divide l by
257, a and b by 256 before passing to TIFFCIELabToXYZ

motivation: https://bugs.documentfoundation.org/show_bug.cgi?id=131199
the "clavijo16bitlab.tiff" example where tiffinfo says:
```
  Image Width: 2601 Image Length: 3503
  Resolution: 96, 96 pixels/inch
  Bits/Sample: 16
  Compression Scheme: AdobeDeflate
  Photometric Interpretation: CIE L*a*b*
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Rows/Strip: 1
  Planar Configuration: single image plane
  DateTime: 2020:03:07 10:20:42
```
2022-06-27 10:19:38 +00:00
Roger Leigh eb4087c526 Merge branch 'manpage-fixes' into 'master'
Sphinx documentation fixes

See merge request libtiff/libtiff!362
2022-06-24 15:56:26 +00:00
Roger Leigh 107070b9ab doc: Correct types and cross-references 2022-06-24 15:49:14 +01:00
Roger Leigh 6ab8136187 doc: Correct manual page path 2022-06-24 15:07:40 +01:00
Roger Leigh 38f67894cd build: Make rational2double static only for automake
This copies the same logic as used by CMake.
2022-06-24 12:57:56 +01:00
Roger Leigh dc73ae317e build: Update autoconf version to 4.5.0 and soname to 6.0.0 2022-06-24 11:44:19 +01:00
Roger Leigh 276c34252e build: Update autoconf ld-version-script default 2022-06-24 11:43:59 +01:00
Roger Leigh a6cc522a4c libtiff: Correct version script for changes since v4.4.0 2022-06-24 10:55:13 +01:00
Roger Leigh d3057d8568 libtiff: Update version script documentation 2022-06-24 10:54:52 +01:00
Roger Leigh 23cbc60863 libtiff: Add symbol versioning of all exported symbols 2022-06-24 10:30:19 +01:00
Even Rouault 870fc59cac Merge branch 'webp_mem_improvements' into 'master'
WEBP codec: avoid temporary buffer and memcpy() on whole tile/strip decoding

See merge request libtiff/libtiff!360
2022-06-24 09:28:57 +00:00
Roger Leigh 3791130d21 build: Enable symbol versioning by default 2022-06-24 10:28:17 +01:00
Roger Leigh 3923d24ac2 Merge branch 'sphinx-manpages' into 'master'
doc: Add Sphinx conversion of all manpages

Closes #361

See merge request libtiff/libtiff!356
2022-06-24 08:13:56 +00:00
Roger Leigh 8887c9e936 Merge branch 'remove-wince' into 'master'
Remove obsolete WinCE source file

See merge request libtiff/libtiff!357
2022-06-24 08:11:29 +00:00
Even Rouault e6d7e0b76d WEBP codec: avoid temporary buffer and memcpy() on whole tile/strip decoding 2022-06-23 12:09:08 +02:00
Even Rouault 6c0cbc28e7 Merge branch 'horAcc8_fix' into 'master'
tif_predict.c: make horAcc8() work with icc (ICC) 2021.6.0 20220226 -O2

See merge request libtiff/libtiff!359
2022-06-22 08:00:33 +00:00
Even Rouault 2e78780ea5 tif_predict.c: make horAcc8() work with icc (ICC) 2021.6.0 20220226 -O2
For a reason I don't understand, recent ICC generates wrong code in -O2
mode for the stride = 3 and 4 cases. The modified code is more
straightfoward, so go for it.
2022-06-22 03:16:51 +02:00
Roger Leigh e696b8f92a Merge branch 'ci-restore-old' into 'master'
ci: Restore testing with Ubuntu 20.04

See merge request libtiff/libtiff!358
2022-06-19 10:06:55 +00:00
Roger Leigh be617a9b90 ci: Restore testing with Ubuntu 20.04 2022-06-19 10:50:31 +01:00
Roger Leigh 9bba86183f Remove obsolete WinCE source file 2022-06-19 08:39:27 +01:00
Roger Leigh ad886e10c5 doc: Add missing punctuation 2022-06-19 08:36:19 +01:00
Roger Leigh 9ba52d00ac doc: Remove semicolon from c:function definition 2022-06-19 08:35:24 +01:00
Roger Leigh 73f45cfb3c doc: Remove remaining HTML entities 2022-06-19 08:32:11 +01:00
Roger Leigh 47b55634ec doc: Improve the build page 2022-06-19 08:27:44 +01:00
Roger Leigh 7faec51e2b doc: Add Sphinx conversion of all manpages 2022-06-18 22:54:20 +01:00
Roger Leigh 69f95389ac Merge branch 'dist-html' into 'master'
build: Distribute and install HTML documentation

See merge request libtiff/libtiff!352
2022-06-18 20:35:38 +00:00
Even Rouault 8e9ce05290 Merge branch 'pkgconfig' into 'master'
Adding Requires.private generation

See merge request libtiff/libtiff!355
2022-06-13 17:04:20 +00:00
Yishen Miao 0afda60116 Adding Requires.private generation
Adds Requires.private generation so that pkg-config can correctly find
the dependencies of libtiff.
2022-06-13 09:56:15 -07:00
Roger Leigh 7915e7c6c7 Merge branch 'ci-dist' into 'master'
ci: Archive distribution tar and zip files

See merge request libtiff/libtiff!354
2022-06-11 21:23:52 +00:00
Roger Leigh 0bd28e7c1c ci: Archive distribution tar and zip files 2022-06-11 12:20:13 +01:00
Even Rouault 1c6dbb52f2 Merge branch 'export_TIFFClampDoubleToUInt32' into 'master'
libtiff.def: export _TIFFClampDoubleToUInt32

See merge request libtiff/libtiff!353
2022-06-11 10:22:11 +00:00
Even Rouault c5e6b2fff0 libtiff.def: export _TIFFClampDoubleToUInt32 2022-06-11 12:02:38 +02:00
Even Rouault f3a5e0107f Merge branch 'issue-415+427+428' into 'master'
fix the FPE in tiffcrop (#415, #427, and #428)

Closes #428, #427 et #415

See merge request libtiff/libtiff!346
2022-06-11 09:31:44 +00:00
4ugustus dd1bcc7abb fix the FPE in tiffcrop (#415, #427, and #428) 2022-06-11 09:31:43 +00:00
Roger Leigh 47d0894f13 build: Distribute and install HTML documentation 2022-06-11 10:10:08 +01:00
Even Rouault 033f8b51b8 Merge branch 'tif_jpeg_warning_fix' into 'master'
tif_jpeg.c: fix error message

See merge request libtiff/libtiff!351
2022-06-10 20:11:44 +00:00
Even Rouault c9b9e0d856 tif_jpeg.c: fix error message 2022-06-10 21:45:45 +02:00
Roger Leigh 6aec9314ee Merge branch 'android_libm' into 'master'
Fix dependency on libm on Android

See merge request libtiff/libtiff!350
2022-06-10 06:48:32 +00:00
Matthias Kuhn cd38e31d6e Always link to libm if available 2022-06-09 13:21:13 +02:00
Roger Leigh e990bbfad2 Merge branch 'vasyl5-master-patch-97651' into 'master'
libtoolize: command not found on macOS.

See merge request libtiff/libtiff!289
2022-06-05 16:33:32 +00:00
Roger Leigh 62f90c42fc Merge branch 'rst-docs' into 'master'
Convert HTML documentation to Sphinx RST

See merge request libtiff/libtiff!349
2022-06-05 15:58:02 +00:00
Roger Leigh 7968c365b5 Merge remote-tracking branch 'origin/master' into rst-docs 2022-06-05 16:40:32 +01:00
Roger Leigh 003b7a5cb9 Merge branch 'cmake-xc-faxtable' into 'master'
cmake: Do not build faxtable target when cross-compiling

See merge request libtiff/libtiff!342
2022-06-05 13:45:12 +00:00
Roger Leigh d66540a28f Merge branch 'cmake-disable-options' into 'master'
Add options for disabling tools, tests, contrib and docs

See merge request libtiff/libtiff!343
2022-06-05 13:44:17 +00:00
Roger Leigh da29b078c3 Merge branch 'cmake-msvc-options' into 'master'
cmake: Add MSVC options when building all libraries and executables

See merge request libtiff/libtiff!344
2022-06-05 13:42:31 +00:00
Roger Leigh a812a39cb5 Merge branch 'cmake-win32-libtiffxx-static' into 'master'
cmake: libtiffxx is static on win32

See merge request libtiff/libtiff!338
2022-06-05 13:41:19 +00:00
Roger Leigh 91e878fa1e Merge branch 'licence-file' into 'master'
Rename COPYRIGHT to LICENSE.md

See merge request libtiff/libtiff!345
2022-06-05 12:45:40 +00:00
Roger Leigh fa1d6d787f Rename COPYRIGHT to LICENSE.md 2022-06-05 12:45:40 +00:00
Roger Leigh ab6b92b271 doc: Fix make distcheck 2022-06-05 13:34:32 +01:00
Roger Leigh 67d94e4a19 doc: Update automake configuration 2022-06-05 13:11:23 +01:00
Roger Leigh 661e747ab9 doc: Do not pass srcdir and builddir to sphinx-build 2022-06-05 11:21:00 +01:00
Roger Leigh 4252a61d3f doc: Additional top-level tidying 2022-06-05 11:19:38 +01:00
Roger Leigh ffeff66cf2 doc: Tidy top-level index 2022-06-05 11:08:52 +01:00
Roger Leigh 582455a501 doc: Move bugs to project 2022-06-05 10:39:22 +01:00
Roger Leigh 835319ab8f doc: Move misc to project 2022-06-05 10:16:59 +01:00
Roger Leigh 48d4340963 doc: Move all BigTIFF documentation into specification directory
* Remove the BigTIFF proposal since this has long been completed
* Update the BigTIFF PR to note completion of the work and replace
  present with past tense.
2022-06-05 10:00:45 +01:00
Roger Leigh 16354c94ee doc: Split release history
This permits the newer releases to be included in the top-level
toctree without polluting it with dozens of old releases.
2022-06-05 09:47:40 +01:00
Roger Leigh 28fc6ff780 doc: Correct accents 2022-06-05 09:39:23 +01:00
Roger Leigh f80227b9e7 doc: BigTIFF design markup improvements 2022-06-05 09:33:53 +01:00
Roger Leigh 50904e4381 Add doc/_static 2022-06-05 09:25:02 +01:00
Roger Leigh 963b928845 doc: Move TIFF specification and design notes into subdirectory 2022-06-05 09:24:20 +01:00
Roger Leigh 8088d606a8 doc: Move releases into subdirectory 2022-06-05 08:27:24 +01:00
Roger Leigh 7fae4544fc doc: Mark up TIFF tech note 2 2022-06-05 08:20:55 +01:00
Roger Leigh a15a68df39 doc: Use sphinxdox theme
The sphix_rtd_theme formats complex tables badly.
2022-06-05 07:25:32 +01:00
Roger Leigh 6fcf5fd957 doc: Clean up HTML tags 2022-06-05 07:25:24 +01:00
Roger Leigh 276579611c ci: Install Sphinx manual for use by GitLab pages 2022-06-04 21:53:09 +01:00
Roger Leigh 32f075901f doc: Use sphinx_rtd_theme 2022-06-04 21:52:33 +01:00
Roger Leigh 21ae5bbb02 Convert HTML documentation to Sphinx RST
* Add CMake build logic
* Add Autotools build logic
* Move from html/ to doc/
* Manual pages are still generated HTML for the time being
2022-06-04 20:53:23 +01:00
Roger Leigh 9ba9c66cca git: Ignore common IDE build files 2022-06-04 20:28:52 +01:00
Roger Leigh b2d6198417 Merge branch 'ci-ubuntu-22.04' into 'master'
ci: Update to use Ubuntu 22.04 CI images

Closes #429

See merge request libtiff/libtiff!348
2022-06-04 19:12:47 +00:00
Roger Leigh 560f1b0115 Merge branch 'opengl-option' into 'master'
cmake: Add tiff-opengl option

See merge request libtiff/libtiff!340
2022-06-04 19:07:23 +00:00
Roger Leigh 7643b4c434 tiffdump: Avoid overflow warning when reading 2022-06-04 19:56:51 +01:00
Roger Leigh fa8b983a26 ci: Update to use Ubuntu 22.04 CI images 2022-06-04 18:27:17 +01:00
Even Rouault ce539dc06b Merge branch 'master' into 'master'
Include stdlib.h in tif_lzw.c.

See merge request libtiff/libtiff!347
2022-06-04 01:45:44 +00:00
Brian Ledger dfe8aa027c Merge branch 'master' of https://gitlab.com/libtiff/libtiff 2022-06-03 21:40:54 -04:00
Brian Ledger cbd71793f5 Include stdlib.h in tif_lzw.c.
In `tif_lzw.c`, a call is made to `_byteswap_uint64`. This is declared in `stdlib.h`. `stdlib.h` is not included in `tib_lzw.c`, so a name error may occur.

This change adds `#include stdlib.h` to `tif_lzw.c`, to prevent a name error from occuring when `stdlib.h` is not included.
2022-06-03 21:23:51 -04:00
Roger Leigh 1ab0e2696a Add options for disabling tools, tests, contrib and docs 2022-05-29 22:38:36 +01:00
Roger Leigh f45ed446e9 cmake: Add MSVC options when building all libraries and executables 2022-05-29 22:31:08 +01:00
Roger Leigh fa3806c158 cmake: Do not build faxtable target when cross-compiling 2022-05-29 20:57:20 +01:00
Roger Leigh ef984ef786 cmake: Use add_compile_definitions and add_compile_options
It seems that some CMake versions can't export targets using PRIVATE
linking, even though the private target is never used.
2022-05-29 20:55:39 +01:00
Roger Leigh 88727514f0 Merge remote-tracking branch 'origin/master' into cmake-msvc-options 2022-05-29 20:07:29 +01:00
Roger Leigh 03620e4c31 Merge remote-tracking branch 'origin/master' into cmake-win32-libtiffxx-static 2022-05-29 20:07:00 +01:00
Roger Leigh 182bd6716c Merge branch 'ci-x64' into 'master'
ci: Remove arm64 temporarily

See merge request libtiff/libtiff!341
2022-05-29 18:53:16 +00:00
Roger Leigh c3f0b90df5 ci: Remove arm64 temporarily 2022-05-29 19:38:01 +01:00
Roger Leigh b63e40603b autoconf: Add --disable-opengl option 2022-05-29 12:05:27 +01:00
Roger Leigh 36c8177fe8 cmake: Add tiff-opengl option 2022-05-29 11:36:14 +01:00
Roger Leigh 2582c406b0 cmake: Add MSVC options when building all libraries and executables 2022-05-29 11:33:49 +01:00
Roger Leigh 0e58c40f80 cmake: libtiffxx is static on win32 2022-05-29 11:24:56 +01:00
Even Rouault 19db1d316b html/Makefile.am: add v4.4.0.html to docfiles 2022-05-22 11:01:54 +02:00
Even Rouault cbe3e496a9 Update HOWTO-RELEASE with .tar.xz 2022-05-20 18:35:49 +02:00
Timothy Lyanguzov 7d5ad29ed0 Apply 1 suggestion(s) to 1 file(s) 2022-01-20 22:20:11 +00:00
Vasyl Sokolyk db2622a63b libtoolize: command not found on macOS.
Typically need to use glibtool and glibtoolize, since libtool already exists on OS X as a binary

More details you can read here here https://stackoverflow.com/questions/15448582/installed-libtool-but-libtoolize-not-found/15448876
2022-01-19 13:17:38 +00:00
635 changed files with 119646 additions and 117079 deletions
+47 -40
View File
@@ -1,3 +1,14 @@
# Operating system (build VM template)
image:
- "Visual Studio 2022"
- "Visual Studio 2019"
platform: x64
configuration:
- Release
- Debug
environment:
AV_PROJECTS: 'c:\projects'
AV_TIFF_DOWNLOAD: 'c:\projects\download'
@@ -6,78 +17,75 @@ environment:
AV_TIFF_INSTALL: 'c:\projects\install'
matrix:
- compiler: vc-cmake
- compiler: cygwin-cmake
configuration: Release
generator: Unix Makefiles
shared: ON
- compiler: cygwin-cmake
configuration: Debug
generator: Unix Makefiles
shared: OFF
- compiler: mingw-cmake
configuration: Release
generator: MinGW Makefiles
shared: ON
- compiler: mingw-cmake
configuration: Debug
generator: MinGW Makefiles
shared: OFF
- compiler: vc14-cmake
configuration: Release
arch: x64
generator: Visual Studio 16 2019
shared: ON
- compiler: vc14-cmake
configuration: Debug
arch: Win32
generator: Visual Studio 16 2019
shared: OFF
matrix:
exclude:
- image: "Visual Studio 2019"
compiler: cygwin-cmake
configuration: Release
- image: "Visual Studio 2019"
compiler: cygwin-cmake
configuration: Debug
- image: "Visual Studio 2019"
compiler: mingw-cmake
configuration: Release
- image: "Visual Studio 2019"
compiler: mingw-cmake
configuration: Debug
cache:
#- 'c:\projects\download -> appveyor.yml'
# Operating system (build VM template)
os: 'Visual Studio 2019'
# clone directory
# Clone directory
clone_folder: 'c:\projects\libtiff'
clone_depth: 5
platform: x64
init:
- git config --global core.autocrlf input
before_build:
- 'if %compiler%==vc-cmake if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2022" set "generator=Visual Studio 17 2022"'
- 'if %compiler%==vc-cmake if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2019" set "generator=Visual Studio 16 2019"'
- 'if %compiler%==cygwin-cmake set "generator=Unix Makefiles"'
- 'if %compiler%==mingw-cmake set "generator=Ninja"'
- 'if %Configuration%==Release set "shared=ON"'
- 'if %Configuration%==Debug set "shared=OFF"'
- 'if %compiler%==vc-cmake if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2022" set "arch=x64"'
- 'if %compiler%==vc-cmake if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2019" set "arch=Win32"'
- 'FOR /F "tokens=* USEBACKQ" %%F IN (`C:\cygwin64\bin\cygpath -u %AV_TIFF_SOURCE%`) DO SET AV_TIFF_CYG_SOURCE=%%F'
- 'FOR /F "tokens=* USEBACKQ" %%F IN (`C:\cygwin64\bin\cygpath -u %AV_TIFF_INSTALL%`) DO SET AV_TIFF_CYG_INSTALL=%%F'
- 'if %compiler%==cygwin-cmake C:\cygwin64\setup-x86_64 -q -R C:\cygwin64 -s http://cygwin.mirror.constant.com -l %AV_TIFF_DOWNLOAD%\cygwin -P cmake,libjpeg-devel,zlib-devel'
- 'if %compiler%==cygwin-cmake C:\cygwin64\setup-x86_64 -q -R C:\cygwin64 -s http://cygwin.mirror.constant.com -l %AV_TIFF_DOWNLOAD%\cygwin -g -P cmake,libjpeg-devel,zlib-devel'
- 'if %compiler%==cygwin-cmake set "PATH=C:\cygwin64\bin;%PATH%"'
- set
- 'if %compiler%==cygwin-cmake cygpath --version || echo cygpath not found'
- 'if %compiler%==cygwin-cmake cmake --version || echo CMake not found'
- set "AV_CMAKE_ARGS=-DBUILD_SHARED_LIBS:BOOL=%shared%"
- 'if %compiler%==cygwin-cmake set "AV_CMAKE_ARGS=%AV_CMAKE_ARGS% -Dfatal-warnings=ON"'
- 'if %compiler%==mingw32-cmake set "AV_CMAKE_ARGS=%AV_CMAKE_ARGS% -Dfatal-warnings=ON"'
- 'if %compiler%==mingw-cmake set "AV_CMAKE_ARGS=%AV_CMAKE_ARGS% -Dfatal-warnings=ON"'
- set "AV_TIFF_CMAKE_SOURCE=%AV_TIFF_SOURCE%"
- set "AV_TIFF_CMAKE_INSTALL=%AV_TIFF_INSTALL%"
- 'if %compiler%==cygwin-cmake set "AV_TIFF_CMAKE_SOURCE=%AV_TIFF_CYG_SOURCE%'
- 'if %compiler%==cygwin-cmake set "AV_TIFF_CMAKE_INSTALL=%AV_TIFF_CYG_INSTALL%'
- 'if %compiler%==mingw-cmake set "PATH=C:\MinGW\bin;%PATH%"'
- 'if %compiler%==mingw-cmake C:\msys64\usr\bin\bash -lc "pacman -Syuu --noconfirm"'
- 'if %compiler%==mingw-cmake C:\msys64\usr\bin\bash -lc "pacman -Syuu --noconfirm"'
- 'if %compiler%==mingw-cmake C:\msys64\usr\bin\bash -lc "pacman -S --needed --noconfirm mingw-w64-ucrt-x86_64-{toolchain,cmake,ninja,zlib,libjpeg-turbo}"'
- 'if %compiler%==mingw-cmake set "PATH=C:\msys64\ucrt64\bin;C:\msys64\usr\bin;%PATH%"'
- mkdir %AV_TIFF_BUILD%
- cd %AV_TIFF_BUILD%
- set
- echo Running cmake -G "%generator%" -DCMAKE_INSTALL_PREFIX=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_TIFF_CMAKE_SOURCE%
- 'if %compiler%==cygwin-cmake bash -c "cmake -G \"%generator%\" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%"'
# Disable doc building because of 'Could not import extension sphinxcontrib.applehelp (exception: No module named 'sphinxcontrib.applehelp')'
- 'if %compiler%==cygwin-cmake bash -c "cmake -G \"%generator%\" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE% -Dtiff-docs=off"'
- 'if %compiler%==mingw-cmake cmake -G "%generator%" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%'
- 'if %compiler%==vc14-cmake cmake -G "%generator%" -A %arch% -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%'
- 'if %compiler%==vc-cmake cmake -G "%generator%" -A %arch% -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%'
build_script:
- cd %AV_TIFF_BUILD%
- 'if %compiler%==cygwin-cmake bash -c "cmake --build . --config %configuration% --target install"'
- 'if %compiler%==mingw-cmake cmake --build . --config %configuration% --target install'
- 'if %compiler%==vc14-cmake cmake --build . --config %configuration% --target install'
- 'if %compiler%==vc9-cmake cmake --build . --config %configuration% --target install'
- 'if %compiler%==vc-cmake cmake --build . --config %configuration% --target install'
# scripts to run after build
after_build:
@@ -90,8 +98,7 @@ before_test:
- cd %AV_TIFF_BUILD%
- 'if %compiler%==cygwin-cmake bash -c "ctest -V -C %configuration%"'
- 'if %compiler%==mingw-cmake ctest -V -C %configuration%'
- 'if %compiler%==vc14-cmake ctest -V -C %configuration%'
- 'if %compiler%==vc9-cmake ctest -V -C %configuration%'
- 'if %compiler%==vc-cmake ctest -V -C %configuration%'
# AppVeyor don't yet have a configurable retention policy, so this will
# eventually use up all the storage allowance.
+6
View File
@@ -0,0 +1,6 @@
---
BasedOnStyle: llvm
IndentWidth: 4
ColumnLimit: 80
BreakBeforeBraces: Allman
IndentCaseLabels: true
+4
View File
@@ -0,0 +1,4 @@
42173d6ace476b5228d866640b5355f74e5a108d
b0ae5d7071890160da67d2e833d84a400e0406d0
dee020782c17c1388ca5774f9904d318b51b288b
aee0113f5ec1fd39b97458539bd79a1447425ac4
+4
View File
@@ -76,3 +76,7 @@ test/*.log
test/*.trs
test/o-*
*~
.idea
.vs
cmake-build*
build*
+28 -11
View File
@@ -1,38 +1,54 @@
image: registry.gitlab.com/libtiff/libtiff-ci-ubuntu20.04:latest
image: registry.gitlab.com/libtiff/libtiff-ci-ubuntu24.04:latest
stages:
- build
- static-analysis
- pages
autoconf:
autoconf-current:
stage: build
script:
- sh build/gitlab-ci autoconf
after_script:
- 'cat autoconf-build/test/test-suite.log'
artifacts:
name: distribution
paths:
- distribution
cmake-makefiles:
autoconf-old:
stage: build
image: registry.gitlab.com/libtiff/libtiff-ci-ubuntu22.04:latest
script:
- sh build/gitlab-ci autoconf-minimal
after_script:
- 'cat autoconf-build/test/test-suite.log'
cmake-makefiles-current:
stage: build
script:
- sh build/gitlab-ci cmake "Unix Makefiles" Release
cmake-ninja:
cmake-makefiles-current-static:
stage: build
script:
- sh build/gitlab-ci cmake "Unix Makefiles" Release static
cmake-ninja-current:
stage: build
script:
- sh build/gitlab-ci cmake "Ninja" Debug
cmake-ninja-arm64:
tags: [arm64,freebsd]
cmake-makefiles-old:
stage: build
image: registry.gitlab.com/libtiff/libtiff-ci-ubuntu22.04:latest
script:
- sh build/gitlab-ci cmake "Ninja" Release
rules:
- if: '$CI_PROJECT_PATH == "libtiff/libtiff"'
- sh build/gitlab-ci cmake "Unix Makefiles" Release
coverity:
stage: static-analysis
image: registry.gitlab.com/libtiff/libtiff-ci-ubuntu20.04-coverity:latest
image: registry.gitlab.com/libtiff/libtiff-ci-ubuntu24.04-coverity:latest
script:
- sh build/gitlab-ci coverity "Ninja" Debug
only:
@@ -42,7 +58,8 @@ coverity:
pages:
stage: pages
script:
- cp -r html public
- sh build/gitlab-ci cmake "Ninja" Debug
- cp -r cmake-install/share/doc/tiff/manual/html public
artifacts:
name: $CI_PROJECT_NAME-$CI_JOB_NAME
paths:
+22
View File
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: 'v15.0.4'
hooks:
- id: clang-format
# tif_fax3sm.c is a generated file
# tiffvers.h as well, and its formatting is sensitive for
# FindTIFF.cmake to detect the version number
# Furthermore, the .in files are formatting sensitive for
# cmake functions.
exclude: >
(?x)^(
libtiff/tif_fax3sm.c|
libtiff/tiffvers.h|
libtiff/tiffvers.h.in|
libtiff/tif_config.h|
libtiff/tif_config.h.in|
libtiff/tif_config.h.cmake.in|
libtiff/tiffconf.h|
libtiff/tiffconf.h.in|
libtiff/tiffconf.h.cmake.in
)
+52 -21
View File
@@ -35,17 +35,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# Read version information from configure.ac.
include(AutotoolsVersion)
message(STATUS "Building tiff version ${LIBTIFF_VERSION_FULL}")
message(STATUS "libtiff library version ${SO_VERSION}")
string(TIMESTAMP BUILD_DATE "%Y%m%d")
message(STATUS "libtiff build date: ${BUILD_DATE}")
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
# Disable deprecated features to ensure clean build
add_definitions(-DTIFF_DISABLE_DEPRECATED)
# Project definition
set(CMAKE_C_STANDARD 99)
@@ -53,6 +42,26 @@ project(tiff
VERSION "${LIBTIFF_VERSION}"
LANGUAGES C CXX)
if(NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# libtiff is being included as a subproject of some other project.
set(TIFF_INSTALL_DEFAULT OFF)
else()
set(TIFF_INSTALL_DEFAULT ON)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
endif()
option(tiff-tools "build TIFF tools" ON)
option(tiff-tests "build TIFF tests" ON)
option(tiff-contrib "build TIFF contrib" ON)
option(tiff-docs "build TIFF documentation" ON)
option(tiff-deprecated "build TIFF deprecated features" OFF)
option(tiff-install "install TIFF targets" ${TIFF_INSTALL_DEFAULT})
# Disable deprecated features to ensure clean build
if (tiff-deprecated)
add_definitions(-DTIFF_DISABLE_DEPRECATED)
endif()
# Autotools compatibility
include(AutotoolsCompat)
@@ -131,16 +140,22 @@ find_package(CMath REQUIRED)
# Release support
include(Release)
# Process subdirectories
add_subdirectory(port)
add_subdirectory(libtiff)
add_subdirectory(tools)
add_subdirectory(test)
add_subdirectory(contrib)
if(tiff-tools)
add_subdirectory(tools)
endif()
if(tiff-tests)
add_subdirectory(test)
endif()
if(tiff-contrib)
add_subdirectory(contrib)
endif()
add_subdirectory(build)
add_subdirectory(man)
add_subdirectory(html)
if(tiff-docs)
add_subdirectory(doc)
endif()
# pkg-config support
include(PkgConfig)
@@ -148,11 +163,23 @@ include(PkgConfig)
message(STATUS "")
message(STATUS "Libtiff is now configured for ${CMAKE_SYSTEM}")
message(STATUS "")
if (NOT LIBTIFF_RELEASE_VERSION STREQUAL LIBTIFF_VERSION_FULL)
message(STATUS " Libtiff release version ${LIBTIFF_RELEASE_VERSION} is not equal to build version!")
endif()
message(STATUS " Libtiff build version: ${LIBTIFF_VERSION_FULL}")
message(STATUS " Libtiff library version: ${SO_VERSION}")
message(STATUS " Libtiff release date: ${LIBTIFF_RELEASE_DATE}")
message(STATUS "")
message(STATUS " Installation directory: ${prefix}")
message(STATUS " Documentation directory: ${LIBTIFF_DOCDIR}")
message(STATUS " C compiler: ${CMAKE_C_COMPILER}")
message(STATUS " C++ compiler: ${CMAKE_CXX_COMPILER}")
message(STATUS " Build shared libraries: ${BUILD_SHARED_LIBS}")
message(STATUS " Build tools: ${tiff-tools}")
message(STATUS " Build tests: ${tiff-tests}")
message(STATUS " Build contrib: ${tiff-contrib}")
message(STATUS " Build docs: ${tiff-docs}")
message(STATUS " Build deprecated features: ${tiff-deprecated}")
message(STATUS " Enable linker symbol versioning: ${HAVE_LD_VERSION_SCRIPT}")
message(STATUS " Support Microsoft Document Imaging: ${mdi}")
message(STATUS " Use win32 IO: ${USE_WIN32_FILEIO}")
@@ -183,19 +210,23 @@ if(JPEG_SUPPORT)
else()
message(STATUS " Old JPEG support: Requested:${old-jpeg} Availability:${JPEG_SUPPORT} Support:${OJPEG_SUPPORT} (Depends on JPEG Support)")
endif()
message(STATUS " JPEG 8/12 bit dual mode: Requested:${jpeg12} Availability:${JPEG12_FOUND} Support:${JPEG_DUAL_MODE_8_12}")
if(JPEG_SUPPORT AND HAVE_JPEGTURBO_DUAL_MODE_8_12)
message(STATUS " JPEG 8/12 bit dual mode: Support: yes (libjpeg turbo >= 3.0 dual mode)")
else()
message(STATUS " JPEG 8/12 bit dual mode: Requested:${jpeg12} Availability:${JPEG12_FOUND} Support:${JPEG_DUAL_MODE_8_12}")
endif()
message(STATUS " ISO JBIG support: Requested:${jbig} Availability:${JBIG_FOUND} Support:${JBIG_SUPPORT}")
if(ZLIB_SUPPORT)
message(STATUS " LERC support: Requested:${lerc} Availability:${LERC_FOUND} Support:${LERC_SUPPORT}")
else()
message(STATUS " LERC support: Requested:${lerc} Availability:${LERC_FOUND} Support:${LERC_SUPPORT} (Depends on ZLIB Support)")
endif()
message(STATUS " LZMA2 support: Requested:${lzma} Availability:${LIBLZMA_FOUND} Support:${LZMA_SUPPORT}")
message(STATUS " LZMA2 support: Requested:${lzma} Availability:${liblzma_FOUND} Support:${LZMA_SUPPORT}")
message(STATUS " ZSTD support: Requested:${zstd} Availability:${ZSTD_USABLE} Support:${ZSTD_SUPPORT}")
message(STATUS " WEBP support: Requested:${webp} Availability:${WEBP_FOUND} Support:${WEBP_SUPPORT}")
message(STATUS " WEBP support: Requested:${webp} Availability:${WebP_FOUND} Support:${WEBP_SUPPORT}")
message(STATUS "")
message(STATUS " C++ support: ${cxx} (requested) ${CXX_SUPPORT} (availability)")
message(STATUS "")
# message(STATUS " X Athena Widgets support: ${HAVE_XAW}")
message(STATUS " OpenGL support: ${HAVE_OPENGL}")
message(STATUS " OpenGL support: Requested:${tiff-opengl} Availability:${HAVE_OPENGL} Support:${OPENGL_SUPPORT}")
message(STATUS "")
+19
View File
@@ -0,0 +1,19 @@
Contributing
------------
libtiff uses a ``.clang-format`` file to enforce code formatting rules.
Automatic code reformatting can be done with pre-commit.
Install (once) pre-commit with ``python -m pip install pre-commit``.
Install it (once) in the libtiff git repository with ``pre-commit install``.
Then the rules defined in the ``.pre-commit-config.yaml`` file will be
enforced at ``git commit`` time, with automatic reformatting.
Due to whole-tree code reformatting done during libtiff 4.5 development,
``git blame`` information might be misleading. To avoid that, you need
to modify your git configuration as following to ignore the revision of
the whole-tree reformatting:
``git config blame.ignoreRevsFile .git-blame-ignore-revs``.
+4088 -14
View File
File diff suppressed because it is too large Load Diff
+17 -13
View File
@@ -41,14 +41,14 @@ Notes on releasing.
mv ChangeLog.new ChangeLog
rm ChangeLog.added
3. Create html/vX.X.html and add it to git with 'git add html/vX.X.html'.
Take ChangeLog entries and html-ify in there.
Easist thing to do is take html/vX.(X-1).html and use it as a template.
3. Create doc/releases/vX.X.rst and add it to git with 'git add doc/releases/vX.X.rst'.
Update doc/releases/index.rst to point to the new file
Take ChangeLog entries and rst-ify in there.
Easist thing to do is take doc/releases/vX.(X-1).rst and use it as a template.
4. Add vX.X.html file to the list of 'docfiles' files in the html/Makefile.am.
4. Add vX.X.rst file to the list of 'rst_sources' files in the doc/Makefile.am.
5. Update html/index.html to refer to this new page as the current release,
and update date at the bottom of the page
5. Update "Latest Stable Release" in doc/index.rst.
6. Increment the release version in configure.ac. Put 'alpha' or
'beta' after the version, if applicable. For example:
@@ -100,11 +100,13 @@ Notes on releasing.
make release
This will update "RELEASE-DATE", "VERSION", and libtiff/tiffvers.h
in the source tree.
This will update "RELEASE-DATE", "VERSION" in the source tree,
and libtiff/tiffvers.h in the build tree.
12. In the source tree, verify that the version info in RELEASE-DATE,
VERSION and libtiff/tiffvers.h is right.
VERSION is right.
In the build tree, verify that the version info in
libtiff/tiffvers.h is right.
13. In the build tree do
@@ -134,18 +136,20 @@ Notes on releasing.
16. Sign the release files in the build tree using your private key
export GPG_TTY=$(tty)
for file in tiff-*.tar.gz tiff-*.zip ; do \
for file in tiff-*.tar.gz tiff-*.tar.xz tiff-*.zip ; do \
gpg2 --output ${file}.sig --detach-sig $file ; \
done
for file in tiff-*.tar.gz tiff-*.zip ; do \
for file in tiff-*.tar.gz tiff-*.tar.xz tiff-*.zip ; do \
gpg2 --verify ${file}.sig $file ; \
done
17. Copy release packages from the build tree to the
ftp.remotesensing.org ftp site.
scp tiff-*.tar.gz tiff-*.tar.gz.sig tiff-*.zip tiff-*.zip.sig \
scp tiff-*.tar.gz tiff-*.tar.gz.sig tiff-*.tar.xz tiff-*.tar.xz.sig tiff-*.zip tiff-*.zip.sig \
bfriesen@upload.osgeo.org:/osgeo/download/libtiff
18. Announce to list: tiff@lists.osgeo.org
18. Create a gitlab release at https://gitlab.com/libtiff/libtiff/-/releases
19. Announce to list: tiff@lists.osgeo.org
+4 -2
View File
@@ -1,5 +1,7 @@
Copyright (c) 1988-1997 Sam Leffler
Copyright (c) 1991-1997 Silicon Graphics, Inc.
# LibTIFF license
Copyright © 1988-1997 Sam Leffler\
Copyright © 1991-1997 Silicon Graphics, Inc.
Permission to use, copy, modify, distribute, and sell this software and
its documentation for any purpose is hereby granted without fee, provided
+12 -6
View File
@@ -25,12 +25,12 @@
docdir = $(LIBTIFF_DOCDIR)
AUTOMAKE_OPTIONS = 1.12 dist-zip foreign
AUTOMAKE_OPTIONS = 1.11 dist-zip foreign
ACLOCAL_AMFLAGS = -I m4
docfiles = \
COPYRIGHT \
ChangeLog \
LICENSE.md \
README.md \
RELEASE-DATE \
TODO \
@@ -44,13 +44,15 @@ EXTRA_DIST = \
autogen.sh \
libtiff-4.pc.in
if TIFF_DOCS
dist_doc_DATA = $(docfiles)
endif
distcheck-hook:
if [ -x "$(CMAKE)" ]; then \
mkdir $(distdir)/_build/cmake \
&& cd $(distdir)/_build/cmake \
&& cmake ../.. \
&& cmake -Dsphinx=OFF ../.. \
&& $(MAKE) \
&& ctest -V \
&& $(MAKE) DESTDIR=../../_inst/cmake install ; \
@@ -58,12 +60,16 @@ distcheck-hook:
rm -rf $(distdir)/_build/cmake
rm -rf $(distdir)/_inst/cmake
SUBDIRS = port libtiff tools build contrib test man html
SUBDIRS = port libtiff tools build contrib test doc
NEW_LIBTIFF_RELEASE_DATE=$(shell date +"%Y%m%d")
release:
(rm -f $(top_srcdir)/RELEASE-DATE && echo $(LIBTIFF_RELEASE_DATE) > $(top_srcdir)/RELEASE-DATE)
@(echo --- Setting release date to $(NEW_LIBTIFF_RELEASE_DATE) and release version to $(LIBTIFF_VERSION) ---)
(rm -f $(top_srcdir)/RELEASE-DATE && echo $(NEW_LIBTIFF_RELEASE_DATE) > $(top_srcdir)/RELEASE-DATE)
(rm -f $(top_srcdir)/VERSION && echo $(LIBTIFF_VERSION) > $(top_srcdir)/VERSION)
(rm -f $(top_srcdir)/libtiff/tiffvers.h && sed 's,LIBTIFF_VERSION,$(LIBTIFF_VERSION),;s,LIBTIFF_RELEASE_DATE,$(LIBTIFF_RELEASE_DATE),' $(top_srcdir)/libtiff/tiffvers.h.in > $(top_srcdir)/libtiff/tiffvers.h)
(rm -f $(top_builddir)/libtiff/tiffvers.h && sed 's,LIBTIFF_VERSION,$(LIBTIFF_VERSION),;s,LIBTIFF_RELEASE_DATE,$(NEW_LIBTIFF_RELEASE_DATE),;s,LIBTIFF_MAJOR_VERSION,$(LIBTIFF_MAJOR_VERSION),;s,LIBTIFF_MINOR_VERSION,$(LIBTIFF_MINOR_VERSION),;s,LIBTIFF_MICRO_VERSION,$(LIBTIFF_MICRO_VERSION),' $(top_srcdir)/libtiff/tiffvers.h.in > $(top_builddir)/libtiff/tiffvers.h && sed -i 's,@,,g' $(top_builddir)/libtiff/tiffvers.h)
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libtiff-4.pc
+8 -10
View File
@@ -1,17 +1,15 @@
TIFF Software Distribution
--------------------------
This file is just a placeholder; all the documentation is now in
HTML in the html directory. To view the documentation point your
favorite WWW viewer at html/index.html;
This file is just a placeholder; the entire documentation is now located
as reStructuredText in the doc directory. To view the documentation
as HTML, visit https://libtiff.gitlab.io/libtiff/ or
http://www.simplesystems.org/libtiff/ or within the release package
in the doc/html-prebuilt directory. The manual pages are
located at doc/man-prebuilt.
e.g.
The release package can be downloaded at
firefox html/index.html
If you don't have an HTML viewer then you can read the HTML source
or fetch a PostScript version of this documentation from the directory
http://download.osgeo.org/libtiff/
http://download.osgeo.org/libtiff/
If you can't hack either of these options then basically what you
want to do is:
+1 -1
View File
@@ -1 +1 @@
20220520
20240911
+1 -1
View File
@@ -1 +1 @@
4.4.0
4.7.0
+829 -761
View File
File diff suppressed because it is too large Load Diff
+336 -294
View File
@@ -2,30 +2,30 @@
* Copyright (c) 1990-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
/*
* convert a GIF file into a TIFF file.
* based on Paul Haeberli's fromgif program which in turn is
* based on a GIF file reader by Marcel J.E. Mol March 23 1989
* based on a GIF file reader by Marcel J.E. Mol March 23 1989
*
* if input is 320 by 200 pixel aspect is probably 1.2
* if input is 640 350 pixel aspect is probably 1.37
@@ -33,67 +33,65 @@
*/
#include "tif_config.h"
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#include <unistd.h>
#endif
#ifdef NEED_LIBPORT
# include "libport.h"
#include "libport.h"
#endif
#include "tiffio.h"
#define GIFGAMMA (1.5) /* smaller makes output img brighter */
#define IMAX 0xffff /* max intensity value */
#define EXTRAFUDGE 128 /* some people write BAD .gif files */
#define GIFGAMMA (1.5) /* smaller makes output img brighter */
#define IMAX 0xffff /* max intensity value */
#define EXTRAFUDGE 128 /* some people write BAD .gif files */
#define streq(a,b) (strcmp(a,b) == 0)
#define strneq(a,b,n) (strncmp(a,b,n) == 0)
#define streq(a, b) (strcmp(a, b) == 0)
#define strneq(a, b, n) (strncmp(a, b, n) == 0)
unsigned short gamtab[256];
void
makegamtab(float gam)
void makegamtab(float gam)
{
int i;
for(i=0; i<256; i++)
gamtab[i] = (unsigned short) (IMAX*pow(i/255.0,gam)+0.5);
for (i = 0; i < 256; i++)
gamtab[i] = (unsigned short)(IMAX * pow(i / 255.0, gam) + 0.5);
}
char* stuff[] = {
"usage: gif2tiff [options] input.gif output.tif",
"where options are:",
" -r # make each strip have no more than # rows",
"",
" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
" -c zip[:opts] compress output with deflate encoding",
" -c packbits compress output with packbits encoding",
" -c none use no compression algorithm on output",
"",
"LZW and deflate options:",
" # set predictor value",
"For example, -c lzw:2 to get LZW-encoded data with horizontal differencing",
NULL
};
char *stuff[] = {
"usage: gif2tiff [options] input.gif output.tif",
"where options are:",
" -r # make each strip have no more than # rows",
"",
" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
" -c zip[:opts] compress output with deflate encoding",
" -c packbits compress output with packbits encoding",
" -c none use no compression algorithm on output",
"",
"LZW and deflate options:",
" # set predictor value",
"For example, -c lzw:2 to get LZW-encoded data with horizontal "
"differencing",
NULL};
static void
usage(void)
static void usage(void)
{
char buf[BUFSIZ];
int i;
char buf[BUFSIZ];
int i;
setbuf(stderr, buf);
fprintf(stderr, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
fprintf(stderr, "%s\n", stuff[i]);
exit(-1);
setbuf(stderr, buf);
fprintf(stderr, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
fprintf(stderr, "%s\n", stuff[i]);
exit(-1);
}
#define COLSIZE 256
@@ -102,38 +100,37 @@ unsigned char *stackp;
unsigned int prefix[4096];
unsigned char suffix[4096];
unsigned char stack[4096];
int datasize,codesize,codemask; /* Decoder working variables */
int clear,eoi; /* Special code values */
int datasize, codesize, codemask; /* Decoder working variables */
int clear, eoi; /* Special code values */
int avail, oldcode;
FILE *infile;
int global; /* Is there a global color map? */
int globalbits; /* Number of bits of global colors */
unsigned char globalmap[COLSIZE][3];/* RGB values for global color map */
unsigned char *raster; /* Decoded image data */
int global; /* Is there a global color map? */
int globalbits; /* Number of bits of global colors */
unsigned char globalmap[COLSIZE][3]; /* RGB values for global color map */
unsigned char *raster; /* Decoded image data */
unsigned long width, height;
unsigned short red[COLSIZE];
unsigned short green[COLSIZE];
unsigned short blue[COLSIZE];
char *filename, *imagename;
static uint16_t compression = COMPRESSION_PACKBITS;
static uint16_t predictor = 0;
static uint32_t rowsperstrip = (uint32_t) -1;
static int processCompressOptions(char*);
static uint16_t compression = COMPRESSION_PACKBITS;
static uint16_t predictor = 0;
static uint32_t rowsperstrip = (uint32_t)-1;
static int processCompressOptions(char *);
int convert(void);
int checksignature(void);
int readscreen(void);
int readgifimage(char*);
int readextension(void);
int readraster(void);
int process(int, unsigned char**);
void initcolors(unsigned char [COLSIZE][3], int);
void rasterize(int, char*);
int convert(void);
int checksignature(void);
int readscreen(void);
int readgifimage(char *);
int readextension(void);
int readraster(void);
int process(int, unsigned char **);
void initcolors(unsigned char[COLSIZE][3], int);
void rasterize(int, char *);
int
main(int argc, char* argv[])
int main(int argc, char *argv[])
{
#if !HAVE_DECL_OPTARG
extern int optind;
@@ -143,105 +140,119 @@ main(int argc, char* argv[])
int c, status;
while ((c = getopt(argc, argv, "c:r:")) != -1)
switch (c) {
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
usage();
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
break;
case '?':
usage();
/*NOTREACHED*/
}
switch (c)
{
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
usage();
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
break;
case '?':
usage();
/*NOTREACHED*/
}
if (argc - optind != 2)
usage();
usage();
makegamtab(GIFGAMMA);
filename = argv[optind];
imagename = argv[optind+1];
if ((infile = fopen(imagename, "rb")) != NULL) {
int c;
fclose(infile);
printf("overwrite %s? ", imagename); fflush(stdout);
c = getc(stdin);
if (c != 'y' && c != 'Y')
return (1);
imagename = argv[optind + 1];
if ((infile = fopen(imagename, "rb")) != NULL)
{
int c;
fclose(infile);
printf("overwrite %s? ", imagename);
fflush(stdout);
c = getc(stdin);
if (c != 'y' && c != 'Y')
return (1);
}
if ((infile = fopen(filename, "rb")) == NULL) {
perror(filename);
return (1);
if ((infile = fopen(filename, "rb")) == NULL)
{
perror(filename);
return (1);
}
status = convert();
fclose(infile);
return (status);
}
static int
processCompressOptions(char* opt)
static int processCompressOptions(char *opt)
{
if (streq(opt, "none"))
compression = COMPRESSION_NONE;
else if (streq(opt, "packbits"))
compression = COMPRESSION_PACKBITS;
else if (strneq(opt, "lzw", 3)) {
char* cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp+1);
compression = COMPRESSION_LZW;
} else if (strneq(opt, "zip", 3)) {
char* cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp+1);
compression = COMPRESSION_ADOBE_DEFLATE;
} else
return (0);
return (1);
if (streq(opt, "none"))
compression = COMPRESSION_NONE;
else if (streq(opt, "packbits"))
compression = COMPRESSION_PACKBITS;
else if (strneq(opt, "lzw", 3))
{
char *cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp + 1);
compression = COMPRESSION_LZW;
}
else if (strneq(opt, "zip", 3))
{
char *cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp + 1);
compression = COMPRESSION_ADOBE_DEFLATE;
}
else
return (0);
return (1);
}
int
convert(void)
int convert(void)
{
int ch;
char* mode = "w";
char *mode = "w";
if (!checksignature())
return (-1);
if (!readscreen())
return (-1);
while ((ch = getc(infile)) != ';' && ch != EOF) {
switch (ch) {
case '\0': break; /* this kludge for non-standard files */
case ',': if (!readgifimage(mode))
return (-1);
mode = "a"; /* subsequent images append */
break;
case '!': if (!readextension())
return (-1);
break;
default: fprintf(stderr, "illegal GIF block type\n");
return (-1);
while ((ch = getc(infile)) != ';' && ch != EOF)
{
switch (ch)
{
case '\0':
break; /* this kludge for non-standard files */
case ',':
if (!readgifimage(mode))
return (-1);
mode = "a"; /* subsequent images append */
break;
case '!':
if (!readextension())
return (-1);
break;
default:
fprintf(stderr, "illegal GIF block type\n");
return (-1);
}
}
return (0);
}
int
checksignature(void)
int checksignature(void)
{
char buf[6];
if (fread(buf,1,6,infile) != 6) {
fprintf(stderr, "short read from file %s (%s)\n",
filename, strerror(errno));
if (fread(buf, 1, 6, infile) != 6)
{
fprintf(stderr, "short read from file %s (%s)\n", filename,
strerror(errno));
return 0;
}
if (strncmp(buf,"GIF",3)) {
if (strncmp(buf, "GIF", 3))
{
fprintf(stderr, "file is not a GIF file\n");
return 0;
}
if (strncmp(&buf[3],"87a",3)) {
if (strncmp(&buf[3], "87a", 3))
{
fprintf(stderr, "unknown GIF version number\n");
return 0;
}
@@ -249,35 +260,36 @@ checksignature(void)
}
/*
* readscreen -
* Get information which is global to all the images stored
* readscreen -
* Get information which is global to all the images stored
* in the file
*/
int
readscreen(void)
int readscreen(void)
{
unsigned char buf[7];
if (fread(buf,1,7,infile) != 7) {
fprintf(stderr, "short read from file %s (%s)\n",
filename, strerror(errno));
if (fread(buf, 1, 7, infile) != 7)
{
fprintf(stderr, "short read from file %s (%s)\n", filename,
strerror(errno));
return 0;
}
global = buf[4] & 0x80;
if (global) {
if (global)
{
globalbits = (buf[4] & 0x07) + 1;
if (fread(globalmap,3,((size_t)1)<<globalbits,infile) !=
((size_t)1)<<globalbits) {
fprintf(stderr, "short read from file %s (%s)\n",
filename, strerror(errno));
if (fread(globalmap, 3, ((size_t)1) << globalbits, infile) !=
((size_t)1) << globalbits)
{
fprintf(stderr, "short read from file %s (%s)\n", filename,
strerror(errno));
return 0;
}
}
return 1;
}
int
readgifimage(char* mode)
int readgifimage(char *mode)
{
unsigned char buf[9];
int local, interleaved;
@@ -286,50 +298,61 @@ readgifimage(char* mode)
int status;
size_t raster_size;
if (fread(buf, 1, 9, infile) != 9) {
fprintf(stderr, "short read from file %s (%s)\n",
filename, strerror(errno));
return (0);
if (fread(buf, 1, 9, infile) != 9)
{
fprintf(stderr, "short read from file %s (%s)\n", filename,
strerror(errno));
return (0);
}
width = (buf[4] + (buf[5] << 8)) & 0xffff; /* 16 bit */
height = (buf[6] + (buf[7] << 8)) & 0xffff; /* 16 bit */
width = (buf[4] + (buf[5] << 8)) & 0xffff; /* 16 bit */
height = (buf[6] + (buf[7] << 8)) & 0xffff; /* 16 bit */
local = buf[8] & 0x80;
interleaved = buf[8] & 0x40;
if (width == 0UL || height == 0UL || (width > 2000000000UL / height)) {
if (width == 0UL || height == 0UL || (width > 2000000000UL / height))
{
fprintf(stderr, "Invalid value of width or height\n");
return(0);
return (0);
}
if (local == 0 && global == 0) {
if (local == 0 && global == 0)
{
fprintf(stderr, "no colormap present for image\n");
return (0);
}
raster_size=width*height;
if ((raster_size/width) == height) {
raster_size += EXTRAFUDGE; /* Add elbow room */
} else {
raster_size=0;
raster_size = width * height;
if ((raster_size / width) == height)
{
raster_size += EXTRAFUDGE; /* Add elbow room */
}
if ((raster = (unsigned char*) _TIFFmalloc(raster_size)) == NULL) {
else
{
raster_size = 0;
}
if ((raster = (unsigned char *)_TIFFmalloc(raster_size)) == NULL)
{
fprintf(stderr, "not enough memory for image\n");
return (0);
}
if (local) {
if (local)
{
localbits = (buf[8] & 0x7) + 1;
fprintf(stderr, " local colors: %d\n", 1<<localbits);
fprintf(stderr, " local colors: %d\n", 1 << localbits);
if (fread(localmap, 3, ((size_t)1)<<localbits, infile) !=
((size_t)1)<<localbits) {
fprintf(stderr, "short read from file %s (%s)\n",
filename, strerror(errno));
if (fread(localmap, 3, ((size_t)1) << localbits, infile) !=
((size_t)1) << localbits)
{
fprintf(stderr, "short read from file %s (%s)\n", filename,
strerror(errno));
return (0);
}
initcolors(localmap, 1<<localbits);
} else if (global) {
initcolors(globalmap, 1<<globalbits);
initcolors(localmap, 1 << localbits);
}
else if (global)
{
initcolors(globalmap, 1 << globalbits);
}
if ((status = readraster()))
rasterize(interleaved, mode);
rasterize(interleaved, mode);
_TIFFfree(raster);
return status;
}
@@ -339,18 +362,18 @@ readgifimage(char* mode)
* Read a GIF extension block (and do nothing with it).
*
*/
int
readextension(void)
int readextension(void)
{
int count;
char buf[255];
int status = 1;
(void) getc(infile);
(void)getc(infile);
while ((count = getc(infile)) && count <= 255)
if (fread(buf, 1, count, infile) != (size_t) count) {
fprintf(stderr, "short read from file %s (%s)\n",
filename, strerror(errno));
if (fread(buf, 1, count, infile) != (size_t)count)
{
fprintf(stderr, "short read from file %s (%s)\n", filename,
strerror(errno));
status = 0;
break;
}
@@ -362,114 +385,129 @@ readextension(void)
* Decode a raster image
*
*/
int
readraster(void)
int readraster(void)
{
unsigned char *fill = raster;
unsigned char buf[255];
register int bits=0;
register unsigned long datum=0;
register int bits = 0;
register unsigned long datum = 0;
register unsigned char *ch;
register int count, code;
int status = 1;
datasize = getc(infile);
if (datasize > 12)
return 0;
return 0;
clear = 1 << datasize;
eoi = clear + 1;
avail = clear + 2;
oldcode = -1;
codesize = datasize + 1;
codemask = (1 << codesize) - 1;
for (code = 0; code < clear; code++) {
prefix[code] = 0;
suffix[code] = code;
for (code = 0; code < clear; code++)
{
prefix[code] = 0;
suffix[code] = code;
}
stackp = stack;
for (count = getc(infile); count > 0 && count <= 255; count = getc(infile)) {
if (fread(buf,1,count,infile) != (size_t)count) {
fprintf(stderr, "short read from file %s (%s)\n",
filename, strerror(errno));
for (count = getc(infile); count > 0 && count <= 255; count = getc(infile))
{
if (fread(buf, 1, count, infile) != (size_t)count)
{
fprintf(stderr, "short read from file %s (%s)\n", filename,
strerror(errno));
return 0;
}
for (ch=buf; count-- > 0; ch++) {
datum += (unsigned long) *ch << bits;
bits += 8;
while (bits >= codesize) {
code = datum & codemask;
datum >>= codesize;
bits -= codesize;
if (code == eoi) { /* This kludge put in */
goto exitloop; /* because some GIF files*/
} /* aren't standard */
if (!process(code, &fill)) {
status = 0;
goto exitloop;
}
}
}
if (fill >= raster + width*height) {
fprintf(stderr, "raster full before eoi code\n");
break;
}
for (ch = buf; count-- > 0; ch++)
{
datum += (unsigned long)*ch << bits;
bits += 8;
while (bits >= codesize)
{
code = datum & codemask;
datum >>= codesize;
bits -= codesize;
if (code == eoi)
{ /* This kludge put in */
goto exitloop; /* because some GIF files*/
} /* aren't standard */
if (!process(code, &fill))
{
status = 0;
goto exitloop;
}
}
}
if (fill >= raster + width * height)
{
fprintf(stderr, "raster full before eoi code\n");
break;
}
}
exitloop:
if (fill != raster + width*height) {
fprintf(stderr, "warning: wrong rastersize: %ld bytes\n",
(long) (fill-raster));
fprintf(stderr, " instead of %ld bytes\n",
(long) width*height);
if (fill != raster + width * height)
{
fprintf(stderr, "warning: wrong rastersize: %ld bytes\n",
(long)(fill - raster));
fprintf(stderr, " instead of %ld bytes\n",
(long)width * height);
}
return status;
}
/*
* process -
* Process a compression code. "clear" resets the code table.
* Otherwise make a new code table entry, and output the bytes
* process -
* Process a compression code. "clear" resets the code table.
* Otherwise make a new code table entry, and output the bytes
* associated with the code.
*/
int
process(register int code, unsigned char** fill)
int process(register int code, unsigned char **fill)
{
int incode;
static unsigned char firstchar;
if (code == clear) {
codesize = datasize + 1;
codemask = (1 << codesize) - 1;
avail = clear + 2;
oldcode = -1;
return 1;
if (code == clear)
{
codesize = datasize + 1;
codemask = (1 << codesize) - 1;
avail = clear + 2;
oldcode = -1;
return 1;
}
if (oldcode == -1) {
if (code >= clear) {
fprintf(stderr, "bad input: code=%d is larger than clear=%d\n",code, clear);
if (oldcode == -1)
{
if (code >= clear)
{
fprintf(stderr, "bad input: code=%d is larger than clear=%d\n",
code, clear);
return 0;
}
if (*fill >= raster + width*height) {
if (*fill >= raster + width * height)
{
fprintf(stderr, "raster full before eoi code\n");
return 0;
}
*(*fill)++ = suffix[code];
firstchar = oldcode = code;
return 1;
*(*fill)++ = suffix[code];
firstchar = oldcode = code;
return 1;
}
if (code > avail) {
fprintf(stderr, "code %d too large for %d\n", code, avail);
return 0;
if (code > avail)
{
fprintf(stderr, "code %d too large for %d\n", code, avail);
return 0;
}
incode = code;
if (code == avail) { /* the first code is always < avail */
*stackp++ = firstchar;
code = oldcode;
if (code == avail)
{ /* the first code is always < avail */
*stackp++ = firstchar;
code = oldcode;
}
while (code > clear) {
*stackp++ = suffix[code];
code = prefix[code];
while (code > clear)
{
*stackp++ = suffix[code];
code = prefix[code];
}
*stackp++ = firstchar = suffix[code];
@@ -477,17 +515,20 @@ process(register int code, unsigned char** fill)
suffix[avail] = firstchar;
avail++;
if (((avail & codemask) == 0) && (avail < 4096)) {
codesize++;
codemask += avail;
if (((avail & codemask) == 0) && (avail < 4096))
{
codesize++;
codemask += avail;
}
oldcode = incode;
do {
if (*fill >= raster + width*height) {
do
{
if (*fill >= raster + width * height)
{
fprintf(stderr, "raster full before eoi code\n");
return 0;
}
*(*fill)++ = *--stackp;
*(*fill)++ = *--stackp;
} while (stackp > stack);
return 1;
}
@@ -495,23 +536,22 @@ process(register int code, unsigned char** fill)
/*
* initcolors -
* Convert a color map (local or global) to arrays with R, G and B
* values.
* values.
*
*/
void
initcolors(unsigned char colormap[COLSIZE][3], int ncolors)
void initcolors(unsigned char colormap[COLSIZE][3], int ncolors)
{
register int i;
for (i = 0; i < ncolors; i++) {
red[i] = gamtab[colormap[i][0]];
for (i = 0; i < ncolors; i++)
{
red[i] = gamtab[colormap[i][0]];
green[i] = gamtab[colormap[i][1]];
blue[i] = gamtab[colormap[i][2]];
blue[i] = gamtab[colormap[i][2]];
}
}
void
rasterize(int interleaved, char* mode)
void rasterize(int interleaved, char *mode)
{
register unsigned long row;
unsigned char *newras;
@@ -520,71 +560,73 @@ rasterize(int interleaved, char* mode)
tstrip_t strip;
tsize_t stripsize;
if ((newras = (unsigned char*) _TIFFmalloc(width*height+EXTRAFUDGE)) == NULL) {
if ((newras = (unsigned char *)_TIFFmalloc(width * height + EXTRAFUDGE)) ==
NULL)
{
fprintf(stderr, "not enough memory for image\n");
return;
}
#define DRAWSEGMENT(offset, step) { \
for (row = offset; row < height; row += step) { \
_TIFFmemcpy(newras + row*width, ras, width);\
ras += width; \
} \
#define DRAWSEGMENT(offset, step) \
{ \
for (row = offset; row < height; row += step) \
{ \
_TIFFmemcpy(newras + row * width, ras, width); \
ras += width; \
} \
}
ras = raster;
if (interleaved) {
if (interleaved)
{
DRAWSEGMENT(0, 8);
DRAWSEGMENT(4, 8);
DRAWSEGMENT(2, 4);
DRAWSEGMENT(1, 2);
} else
}
else
DRAWSEGMENT(0, 1);
#undef DRAWSEGMENT
tif = TIFFOpen(imagename, mode);
if (!tif) {
TIFFError(imagename,"Can not open output image");
exit(-1);
if (!tif)
{
TIFFError(imagename, "Can not open output image");
exit(-1);
}
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (uint32_t) width);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (uint32_t) height);
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (uint32_t)width);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (uint32_t)height);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_PALETTE);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,
rowsperstrip = TIFFDefaultStripSize(tif, rowsperstrip));
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,
rowsperstrip = TIFFDefaultStripSize(tif, rowsperstrip));
TIFFSetField(tif, TIFFTAG_COMPRESSION, compression);
switch (compression) {
case COMPRESSION_LZW:
case COMPRESSION_ADOBE_DEFLATE:
case COMPRESSION_DEFLATE:
if (predictor != 0)
TIFFSetField(tif, TIFFTAG_PREDICTOR, predictor);
break;
switch (compression)
{
case COMPRESSION_LZW:
case COMPRESSION_ADOBE_DEFLATE:
case COMPRESSION_DEFLATE:
if (predictor != 0)
TIFFSetField(tif, TIFFTAG_PREDICTOR, predictor);
break;
}
TIFFSetField(tif, TIFFTAG_COLORMAP, red, green, blue);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
strip = 0;
stripsize = TIFFStripSize(tif);
for (row=0; row<height; row += rowsperstrip) {
if (rowsperstrip > height-row) {
rowsperstrip = height-row;
stripsize = TIFFVStripSize(tif, rowsperstrip);
}
if (TIFFWriteEncodedStrip(tif, strip, newras+row*width, stripsize) < 0)
break;
strip++;
for (row = 0; row < height; row += rowsperstrip)
{
if (rowsperstrip > height - row)
{
rowsperstrip = height - row;
stripsize = TIFFVStripSize(tif, rowsperstrip);
}
if (TIFFWriteEncodedStrip(tif, strip, newras + row * width, stripsize) <
0)
break;
strip++;
}
TIFFClose(tif);
_TIFFfree(newras);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
+309 -287
View File
@@ -2,344 +2,366 @@
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include "tif_config.h"
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#include <unistd.h>
#endif
#ifdef NEED_LIBPORT
# include "libport.h"
#include "libport.h"
#endif
#include "rasterfile.h"
#include "tiffio.h"
#ifndef howmany
#define howmany(x, y) (((x)+((y)-1))/(y))
#define howmany(x, y) (((x) + ((y)-1)) / (y))
#endif
#define streq(a,b) (strcmp(a,b) == 0)
#define strneq(a,b,n) (strncmp(a,b,n) == 0)
#define streq(a, b) (strcmp(a, b) == 0)
#define strneq(a, b, n) (strncmp(a, b, n) == 0)
static uint16_t compression = (uint16_t) -1;
static int jpegcolormode = JPEGCOLORMODE_RGB;
static int quality = 75; /* JPEG quality */
static uint16_t predictor = 0;
static uint16_t compression = (uint16_t)-1;
static int jpegcolormode = JPEGCOLORMODE_RGB;
static int quality = 75; /* JPEG quality */
static uint16_t predictor = 0;
static void usage(void);
static int processCompressOptions(char*);
static int processCompressOptions(char *);
int
main(int argc, char* argv[])
int main(int argc, char *argv[])
{
unsigned char* buf;
long row;
tsize_t linebytes, scanline;
TIFF *out;
FILE *in;
struct rasterfile h;
uint16_t photometric;
uint16_t config = PLANARCONFIG_CONTIG;
uint32_t rowsperstrip = (uint32_t) -1;
int c;
unsigned char *buf;
long row;
tsize_t linebytes, scanline;
TIFF *out;
FILE *in;
struct rasterfile h;
uint16_t photometric;
uint16_t config = PLANARCONFIG_CONTIG;
uint32_t rowsperstrip = (uint32_t)-1;
int c;
#if !HAVE_DECL_OPTARG
extern int optind;
extern char* optarg;
extern int optind;
extern char *optarg;
#endif
while ((c = getopt(argc, argv, "c:r:h")) != -1)
switch (c) {
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
usage();
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
break;
case 'h':
usage();
/*NOTREACHED*/
}
if (argc - optind != 2)
usage();
in = fopen(argv[optind], "rb");
if (in == NULL) {
fprintf(stderr, "%s: Can not open.\n", argv[optind]);
return (-1);
}
if (fread(&h, sizeof (h), 1, in) != 1) {
fprintf(stderr, "%s: Can not read header.\n", argv[optind]);
fclose(in);
return (-2);
}
if (strcmp(h.ras_magic, RAS_MAGIC) == 0) {
while ((c = getopt(argc, argv, "c:r:h")) != -1)
switch (c)
{
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
usage();
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
break;
case 'h':
usage();
/*NOTREACHED*/
}
if (argc - optind != 2)
usage();
in = fopen(argv[optind], "rb");
if (in == NULL)
{
fprintf(stderr, "%s: Can not open.\n", argv[optind]);
return (-1);
}
if (fread(&h, sizeof(h), 1, in) != 1)
{
fprintf(stderr, "%s: Can not read header.\n", argv[optind]);
fclose(in);
return (-2);
}
if (strcmp(h.ras_magic, RAS_MAGIC) == 0)
{
#ifndef WORDS_BIGENDIAN
TIFFSwabLong((uint32_t *)&h.ras_width);
TIFFSwabLong((uint32_t *)&h.ras_height);
TIFFSwabLong((uint32_t *)&h.ras_depth);
TIFFSwabLong((uint32_t *)&h.ras_length);
TIFFSwabLong((uint32_t *)&h.ras_type);
TIFFSwabLong((uint32_t *)&h.ras_maptype);
TIFFSwabLong((uint32_t *)&h.ras_maplength);
TIFFSwabLong((uint32_t *)&h.ras_width);
TIFFSwabLong((uint32_t *)&h.ras_height);
TIFFSwabLong((uint32_t *)&h.ras_depth);
TIFFSwabLong((uint32_t *)&h.ras_length);
TIFFSwabLong((uint32_t *)&h.ras_type);
TIFFSwabLong((uint32_t *)&h.ras_maptype);
TIFFSwabLong((uint32_t *)&h.ras_maplength);
#endif
} else if (strcmp(h.ras_magic, RAS_MAGIC_INV) == 0) {
}
else if (strcmp(h.ras_magic, RAS_MAGIC_INV) == 0)
{
#ifdef WORDS_BIGENDIAN
TIFFSwabLong((uint32_t *)&h.ras_width);
TIFFSwabLong((uint32_t *)&h.ras_height);
TIFFSwabLong((uint32_t *)&h.ras_depth);
TIFFSwabLong((uint32_t *)&h.ras_length);
TIFFSwabLong((uint32_t *)&h.ras_type);
TIFFSwabLong((uint32_t *)&h.ras_maptype);
TIFFSwabLong((uint32_t *)&h.ras_maplength);
TIFFSwabLong((uint32_t *)&h.ras_width);
TIFFSwabLong((uint32_t *)&h.ras_height);
TIFFSwabLong((uint32_t *)&h.ras_depth);
TIFFSwabLong((uint32_t *)&h.ras_length);
TIFFSwabLong((uint32_t *)&h.ras_type);
TIFFSwabLong((uint32_t *)&h.ras_maptype);
TIFFSwabLong((uint32_t *)&h.ras_maplength);
#endif
} else {
fprintf(stderr, "%s: Not a rasterfile.\n", argv[optind]);
fclose(in);
return (-3);
}
if ((h.ras_width <= 0) || (h.ras_width >= INT_MAX) ||
(h.ras_height <= 0) || (h.ras_height >= INT_MAX) ||
(h.ras_depth <= 0) || (h.ras_depth >= INT_MAX) ||
(h.ras_length <= 0) || (h.ras_length >= INT_MAX) ||
(h.ras_type <= 0) ||
(h.ras_maptype <= 0) ||
(h.ras_maplength <= 0) || (h.ras_maplength >= INT_MAX)) {
fprintf(stderr, "%s: Improper image header.\n", argv[optind]);
fclose(in);
return (-2);
}
else
{
fprintf(stderr, "%s: Not a rasterfile.\n", argv[optind]);
fclose(in);
return (-3);
}
if ((h.ras_width <= 0) || (h.ras_width >= INT_MAX) || (h.ras_height <= 0) ||
(h.ras_height >= INT_MAX) || (h.ras_depth <= 0) ||
(h.ras_depth >= INT_MAX) || (h.ras_length <= 0) ||
(h.ras_length >= INT_MAX) || (h.ras_type <= 0) ||
(h.ras_maptype <= 0) || (h.ras_maplength <= 0) ||
(h.ras_maplength >= INT_MAX))
{
fprintf(stderr, "%s: Improper image header.\n", argv[optind]);
fclose(in);
return (-2);
}
if ((h.ras_depth != 1) && (h.ras_depth != 8) && (h.ras_depth != 24))
{
fprintf(stderr, "%s: Improper image depth (%d).\n", argv[optind],
h.ras_depth);
fclose(in);
return (-2);
}
out = TIFFOpen(argv[optind + 1], "w");
if (out == NULL)
{
fclose(in);
return (-4);
}
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32_t)h.ras_width);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32_t)h.ras_height);
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, h.ras_depth > 8 ? 3 : 1);
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, h.ras_depth > 1 ? 8 : 1);
TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);
if (h.ras_maptype != RMT_NONE)
{
uint16_t *red;
register uint16_t *map;
register int i, j;
int mapsize;
buf = (unsigned char *)_TIFFmalloc(h.ras_maplength);
if (buf == NULL)
{
fprintf(stderr, "No space to read in colormap.\n");
fclose(in);
(void)TIFFClose(out);
return (-5);
}
if ((h.ras_depth != 1) &&
(h.ras_depth != 8) &&
(h.ras_depth != 24)) {
fprintf(stderr, "%s: Improper image depth (%d).\n",
argv[optind], h.ras_depth);
fclose(in);
return (-2);
if (fread(buf, h.ras_maplength, 1, in) != 1)
{
fprintf(stderr, "%s: Read error on colormap.\n", argv[optind]);
fclose(in);
(void)TIFFClose(out);
return (-6);
}
out = TIFFOpen(argv[optind+1], "w");
if (out == NULL)
{
fclose(in);
return (-4);
}
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32_t) h.ras_width);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32_t) h.ras_height);
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, h.ras_depth > 8 ? 3 : 1);
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, h.ras_depth > 1 ? 8 : 1);
TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);
if (h.ras_maptype != RMT_NONE) {
uint16_t* red;
register uint16_t* map;
register int i, j;
int mapsize;
buf = (unsigned char *)_TIFFmalloc(h.ras_maplength);
if (buf == NULL) {
fprintf(stderr, "No space to read in colormap.\n");
fclose(in);
(void) TIFFClose(out);
return (-5);
}
if (fread(buf, h.ras_maplength, 1, in) != 1) {
fprintf(stderr, "%s: Read error on colormap.\n",
argv[optind]);
fclose(in);
(void) TIFFClose(out);
return (-6);
}
mapsize = 1<<h.ras_depth;
if (h.ras_maplength > mapsize*3) {
fprintf(stderr,
"%s: Huh, %d colormap entries, should be %d?\n",
argv[optind], h.ras_maplength, mapsize*3);
fclose(in);
(void) TIFFClose(out);
return (-7);
}
red = (uint16_t*)_TIFFmalloc(mapsize * 3 * sizeof (uint16_t));
if (red == NULL) {
fprintf(stderr, "No space for colormap.\n");
fclose(in);
(void) TIFFClose(out);
return (-8);
}
map = red;
for (j = 0; j < 3; j++) {
#define SCALE(x) (((x)*((1L<<16)-1))/255)
for (i = h.ras_maplength/3; i-- > 0;)
*map++ = SCALE(*buf++);
if ((i = h.ras_maplength/3) < mapsize) {
i = mapsize - i;
_TIFFmemset(map, 0, i*sizeof (uint16_t));
map += i;
}
}
TIFFSetField(out, TIFFTAG_COLORMAP,
red, red + mapsize, red + 2*mapsize);
photometric = PHOTOMETRIC_PALETTE;
if (compression == (uint16_t) -1)
compression = COMPRESSION_PACKBITS;
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
} else {
/* XXX this is bogus... */
photometric = h.ras_depth == 24 ?
PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK;
if (compression == (uint16_t) -1)
compression = COMPRESSION_LZW;
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
}
switch (compression) {
case COMPRESSION_JPEG:
if (photometric == PHOTOMETRIC_RGB && jpegcolormode == JPEGCOLORMODE_RGB)
photometric = PHOTOMETRIC_YCBCR;
TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);
TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
break;
case COMPRESSION_LZW:
case COMPRESSION_ADOBE_DEFLATE:
case COMPRESSION_DEFLATE:
if (predictor != 0)
TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
break;
}
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric);
linebytes = ((h.ras_depth*h.ras_width+15) >> 3) &~ 1;
scanline = TIFFScanlineSize(out);
if (scanline > linebytes) {
buf = (unsigned char *)_TIFFmalloc(scanline);
_TIFFmemset(buf+linebytes, 0, scanline-linebytes);
} else
buf = (unsigned char *)_TIFFmalloc(linebytes);
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(out, rowsperstrip));
for (row = 0; row < h.ras_height; row++) {
if (fread(buf, linebytes, 1, in) != 1) {
fprintf(stderr, "%s: scanline %ld: Read error.\n",
argv[optind], row);
break;
}
if (h.ras_type == RT_STANDARD && h.ras_depth == 24) {
tsize_t cc = h.ras_width;
unsigned char* cp = buf;
#define SWAP(a,b) { unsigned char t = (a); (a) = (b); (b) = t; }
do {
SWAP(cp[0], cp[2]);
cp += 3;
} while (--cc);
}
if (TIFFWriteScanline(out, buf, row, 0) < 0)
break;
}
(void) TIFFClose(out);
fclose(in);
return (0);
mapsize = 1 << h.ras_depth;
if (h.ras_maplength > mapsize * 3)
{
fprintf(stderr, "%s: Huh, %d colormap entries, should be %d?\n",
argv[optind], h.ras_maplength, mapsize * 3);
fclose(in);
(void)TIFFClose(out);
return (-7);
}
red = (uint16_t *)_TIFFmalloc(mapsize * 3 * sizeof(uint16_t));
if (red == NULL)
{
fprintf(stderr, "No space for colormap.\n");
fclose(in);
(void)TIFFClose(out);
return (-8);
}
map = red;
for (j = 0; j < 3; j++)
{
#define SCALE(x) (((x) * ((1L << 16) - 1)) / 255)
for (i = h.ras_maplength / 3; i-- > 0;)
*map++ = SCALE(*buf++);
if ((i = h.ras_maplength / 3) < mapsize)
{
i = mapsize - i;
_TIFFmemset(map, 0, i * sizeof(uint16_t));
map += i;
}
}
TIFFSetField(out, TIFFTAG_COLORMAP, red, red + mapsize,
red + 2 * mapsize);
photometric = PHOTOMETRIC_PALETTE;
if (compression == (uint16_t)-1)
compression = COMPRESSION_PACKBITS;
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
}
else
{
/* XXX this is bogus... */
photometric =
h.ras_depth == 24 ? PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK;
if (compression == (uint16_t)-1)
compression = COMPRESSION_LZW;
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
}
switch (compression)
{
case COMPRESSION_JPEG:
if (photometric == PHOTOMETRIC_RGB &&
jpegcolormode == JPEGCOLORMODE_RGB)
photometric = PHOTOMETRIC_YCBCR;
TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);
TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
break;
case COMPRESSION_LZW:
case COMPRESSION_ADOBE_DEFLATE:
case COMPRESSION_DEFLATE:
if (predictor != 0)
TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
break;
}
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric);
linebytes = ((h.ras_depth * h.ras_width + 15) >> 3) & ~1;
scanline = TIFFScanlineSize(out);
if (scanline > linebytes)
{
buf = (unsigned char *)_TIFFmalloc(scanline);
_TIFFmemset(buf + linebytes, 0, scanline - linebytes);
}
else
buf = (unsigned char *)_TIFFmalloc(linebytes);
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(out, rowsperstrip));
for (row = 0; row < h.ras_height; row++)
{
if (fread(buf, linebytes, 1, in) != 1)
{
fprintf(stderr, "%s: scanline %ld: Read error.\n", argv[optind],
row);
break;
}
if (h.ras_type == RT_STANDARD && h.ras_depth == 24)
{
tsize_t cc = h.ras_width;
unsigned char *cp = buf;
#define SWAP(a, b) \
{ \
unsigned char t = (a); \
(a) = (b); \
(b) = t; \
}
do
{
SWAP(cp[0], cp[2]);
cp += 3;
} while (--cc);
}
if (TIFFWriteScanline(out, buf, row, 0) < 0)
break;
}
(void)TIFFClose(out);
fclose(in);
return (0);
}
static int
processCompressOptions(char* opt)
static int processCompressOptions(char *opt)
{
if (streq(opt, "none"))
compression = COMPRESSION_NONE;
else if (streq(opt, "packbits"))
compression = COMPRESSION_PACKBITS;
else if (strneq(opt, "jpeg", 4)) {
char* cp = strchr(opt, ':');
if (streq(opt, "none"))
compression = COMPRESSION_NONE;
else if (streq(opt, "packbits"))
compression = COMPRESSION_PACKBITS;
else if (strneq(opt, "jpeg", 4))
{
char *cp = strchr(opt, ':');
compression = COMPRESSION_JPEG;
while( cp )
{
if (isdigit((int)cp[1]))
quality = atoi(cp+1);
else if (cp[1] == 'r' )
jpegcolormode = JPEGCOLORMODE_RAW;
else
usage();
compression = COMPRESSION_JPEG;
while (cp)
{
if (isdigit((int)cp[1]))
quality = atoi(cp + 1);
else if (cp[1] == 'r')
jpegcolormode = JPEGCOLORMODE_RAW;
else
usage();
cp = strchr(cp+1,':');
}
} else if (strneq(opt, "lzw", 3)) {
char* cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp+1);
compression = COMPRESSION_LZW;
} else if (strneq(opt, "zip", 3)) {
char* cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp+1);
compression = COMPRESSION_ADOBE_DEFLATE;
} else
return (0);
return (1);
cp = strchr(cp + 1, ':');
}
}
else if (strneq(opt, "lzw", 3))
{
char *cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp + 1);
compression = COMPRESSION_LZW;
}
else if (strneq(opt, "zip", 3))
{
char *cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp + 1);
compression = COMPRESSION_ADOBE_DEFLATE;
}
else
return (0);
return (1);
}
char* stuff[] = {
"usage: ras2tiff [options] input.ras output.tif",
"where options are:",
" -r # make each strip have no more than # rows",
"",
" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
" -c zip[:opts] compress output with deflate encoding",
" -c jpeg[:opts] compress output with JPEG encoding",
" -c packbits compress output with packbits encoding",
" -c none use no compression algorithm on output",
"",
"JPEG options:",
" # set compression quality level (0-100, default 75)",
" r output color image as RGB rather than YCbCr",
"For example, -c jpeg:r:50 to get JPEG-encoded RGB data with 50% comp. quality",
"",
"LZW and deflate options:",
" # set predictor value",
"For example, -c lzw:2 to get LZW-encoded data with horizontal differencing",
" -h this help message",
NULL
};
char *stuff[] = {
"usage: ras2tiff [options] input.ras output.tif",
"where options are:",
" -r # make each strip have no more than # rows",
"",
" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
" -c zip[:opts] compress output with deflate encoding",
" -c jpeg[:opts] compress output with JPEG encoding",
" -c packbits compress output with packbits encoding",
" -c none use no compression algorithm on output",
"",
"JPEG options:",
" # set compression quality level (0-100, default 75)",
" r output color image as RGB rather than YCbCr",
"For example, -c jpeg:r:50 to get JPEG-encoded RGB data with 50% comp. "
"quality",
"",
"LZW and deflate options:",
" # set predictor value",
"For example, -c lzw:2 to get LZW-encoded data with horizontal "
"differencing",
" -h this help message",
NULL};
static void
usage(void)
static void usage(void)
{
char buf[BUFSIZ];
int i;
char buf[BUFSIZ];
int i;
setbuf(stderr, buf);
fprintf(stderr, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
fprintf(stderr, "%s\n", stuff[i]);
exit(-1);
setbuf(stderr, buf);
fprintf(stderr, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
fprintf(stderr, "%s\n", stuff[i]);
exit(-1);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+23 -22
View File
@@ -3,31 +3,32 @@
/*
* Description of header for files containing raster images
*/
struct rasterfile {
char ras_magic[4]; /* magic number */
int32_t ras_width; /* width (pixels) of image */
int32_t ras_height; /* height (pixels) of image */
int32_t ras_depth; /* depth (1, 8, or 24 bits) of pixel */
int32_t ras_length; /* length (bytes) of image */
int32_t ras_type; /* type of file; see RT_* below */
int32_t ras_maptype; /* type of colormap; see RMT_* below */
int32_t ras_maplength; /* length (bytes) of following map */
/* color map follows for ras_maplength bytes, followed by image */
struct rasterfile
{
char ras_magic[4]; /* magic number */
int32_t ras_width; /* width (pixels) of image */
int32_t ras_height; /* height (pixels) of image */
int32_t ras_depth; /* depth (1, 8, or 24 bits) of pixel */
int32_t ras_length; /* length (bytes) of image */
int32_t ras_type; /* type of file; see RT_* below */
int32_t ras_maptype; /* type of colormap; see RMT_* below */
int32_t ras_maplength; /* length (bytes) of following map */
/* color map follows for ras_maplength bytes, followed by image */
};
#define RAS_MAGIC "\x59\xa6\x6a\x95"
#define RAS_MAGIC_INV "\x95\x6a\xa6\x59"
#define RAS_MAGIC "\x59\xa6\x6a\x95"
#define RAS_MAGIC_INV "\x95\x6a\xa6\x59"
/* Sun supported ras_type's */
#define RT_OLD 0 /* Raw pixrect image in 68000 byte order */
#define RT_STANDARD 1 /* Raw pixrect image in 68000 byte order */
#define RT_BYTE_ENCODED 2 /* Run-length compression of bytes */
#define RT_EXPERIMENTAL 0xffff /* Reserved for testing */
/* Sun supported ras_type's */
#define RT_OLD 0 /* Raw pixrect image in 68000 byte order */
#define RT_STANDARD 1 /* Raw pixrect image in 68000 byte order */
#define RT_BYTE_ENCODED 2 /* Run-length compression of bytes */
#define RT_EXPERIMENTAL 0xffff /* Reserved for testing */
/* Sun registered ras_maptype's */
#define RMT_RAW 2
/* Sun supported ras_maptype's */
#define RMT_NONE 0 /* ras_maplength is expected to be 0 */
#define RMT_EQUAL_RGB 1 /* red[ras_maplength/3],green[],blue[] */
/* Sun registered ras_maptype's */
#define RMT_RAW 2
/* Sun supported ras_maptype's */
#define RMT_NONE 0 /* ras_maplength is expected to be 0 */
#define RMT_EQUAL_RGB 1 /* red[ras_maplength/3],green[],blue[] */
/*
* NOTES:
+289 -279
View File
@@ -2,335 +2,345 @@
* Copyright (c) 1991-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include <ctype.h>
#include <gl/image.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gl/image.h>
#include <ctype.h>
#include "tiffio.h"
#define streq(a,b) (strcmp(a,b) == 0)
#define strneq(a,b,n) (strncmp(a,b,n) == 0)
#define streq(a, b) (strcmp(a, b) == 0)
#define strneq(a, b, n) (strncmp(a, b, n) == 0)
static short config = PLANARCONFIG_CONTIG;
static uint16_t compression = COMPRESSION_PACKBITS;
static uint16_t predictor = 0;
static uint16_t fillorder = 0;
static uint32_t rowsperstrip = (uint32_t) -1;
static int jpegcolormode = JPEGCOLORMODE_RGB;
static int quality = 75; /* JPEG quality */
static uint16_t photometric;
static short config = PLANARCONFIG_CONTIG;
static uint16_t compression = COMPRESSION_PACKBITS;
static uint16_t predictor = 0;
static uint16_t fillorder = 0;
static uint32_t rowsperstrip = (uint32_t)-1;
static int jpegcolormode = JPEGCOLORMODE_RGB;
static int quality = 75; /* JPEG quality */
static uint16_t photometric;
static void usage(void);
static int cpContig(IMAGE*, TIFF*);
static int cpSeparate(IMAGE*, TIFF*);
static int processCompressOptions(char*);
static void usage(void);
static int cpContig(IMAGE *, TIFF *);
static int cpSeparate(IMAGE *, TIFF *);
static int processCompressOptions(char *);
/* XXX image library has no prototypes */
extern IMAGE* iopen(const char*, const char*);
extern void iclose(IMAGE*);
extern void getrow(IMAGE*, short*, int, int);
extern IMAGE *iopen(const char *, const char *);
extern void iclose(IMAGE *);
extern void getrow(IMAGE *, short *, int, int);
int
main(int argc, char* argv[])
int main(int argc, char *argv[])
{
IMAGE *in;
TIFF *out;
int c;
IMAGE *in;
TIFF *out;
int c;
#if !HAVE_DECL_OPTARG
extern int optind;
extern char* optarg;
extern int optind;
extern char *optarg;
#endif
while ((c = getopt(argc, argv, "c:p:r:")) != -1)
switch (c) {
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
usage();
break;
case 'f': /* fill order */
if (streq(optarg, "lsb2msb"))
fillorder = FILLORDER_LSB2MSB;
else if (streq(optarg, "msb2lsb"))
fillorder = FILLORDER_MSB2LSB;
else
usage();
break;
case 'p': /* planar configuration */
if (streq(optarg, "separate"))
config = PLANARCONFIG_SEPARATE;
else if (streq(optarg, "contig"))
config = PLANARCONFIG_CONTIG;
else
usage();
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
break;
case '?':
usage();
/*NOTREACHED*/
}
if (argc - optind != 2)
usage();
in = iopen(argv[optind], "r");
if (in == NULL)
return (-1);
out = TIFFOpen(argv[optind+1], "w");
if (out == NULL)
return (-2);
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32_t) in->xsize);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32_t) in->ysize);
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
if (in->zsize == 1)
photometric = PHOTOMETRIC_MINISBLACK;
else
photometric = PHOTOMETRIC_RGB;
switch (compression) {
case COMPRESSION_JPEG:
if (photometric == PHOTOMETRIC_RGB && jpegcolormode == JPEGCOLORMODE_RGB)
photometric = PHOTOMETRIC_YCBCR;
TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);
TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
break;
case COMPRESSION_LZW:
case COMPRESSION_ADOBE_DEFLATE:
case COMPRESSION_DEFLATE:
if (predictor != 0)
TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
break;
}
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric);
if (fillorder != 0)
TIFFSetField(out, TIFFTAG_FILLORDER, fillorder);
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, in->zsize);
if (in->zsize > 3) {
uint16_t v[1];
v[0] = EXTRASAMPLE_UNASSALPHA;
TIFFSetField(out, TIFFTAG_EXTRASAMPLES, 1, v);
}
TIFFSetField(out, TIFFTAG_MINSAMPLEVALUE, (uint16_t) in->min);
TIFFSetField(out, TIFFTAG_MAXSAMPLEVALUE, (uint16_t) in->max);
TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);
if (config != PLANARCONFIG_SEPARATE)
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(out, rowsperstrip));
else /* force 1 row/strip for library limitation */
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, 1L);
if (in->name[0] != '\0')
TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, in->name);
if (config == PLANARCONFIG_CONTIG)
cpContig(in, out);
else
cpSeparate(in, out);
(void) iclose(in);
(void) TIFFClose(out);
return (0);
while ((c = getopt(argc, argv, "c:p:r:")) != -1)
switch (c)
{
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
usage();
break;
case 'f': /* fill order */
if (streq(optarg, "lsb2msb"))
fillorder = FILLORDER_LSB2MSB;
else if (streq(optarg, "msb2lsb"))
fillorder = FILLORDER_MSB2LSB;
else
usage();
break;
case 'p': /* planar configuration */
if (streq(optarg, "separate"))
config = PLANARCONFIG_SEPARATE;
else if (streq(optarg, "contig"))
config = PLANARCONFIG_CONTIG;
else
usage();
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
break;
case '?':
usage();
/*NOTREACHED*/
}
if (argc - optind != 2)
usage();
in = iopen(argv[optind], "r");
if (in == NULL)
return (-1);
out = TIFFOpen(argv[optind + 1], "w");
if (out == NULL)
return (-2);
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32_t)in->xsize);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32_t)in->ysize);
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
if (in->zsize == 1)
photometric = PHOTOMETRIC_MINISBLACK;
else
photometric = PHOTOMETRIC_RGB;
switch (compression)
{
case COMPRESSION_JPEG:
if (photometric == PHOTOMETRIC_RGB &&
jpegcolormode == JPEGCOLORMODE_RGB)
photometric = PHOTOMETRIC_YCBCR;
TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);
TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
break;
case COMPRESSION_LZW:
case COMPRESSION_ADOBE_DEFLATE:
case COMPRESSION_DEFLATE:
if (predictor != 0)
TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
break;
}
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric);
if (fillorder != 0)
TIFFSetField(out, TIFFTAG_FILLORDER, fillorder);
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, in->zsize);
if (in->zsize > 3)
{
uint16_t v[1];
v[0] = EXTRASAMPLE_UNASSALPHA;
TIFFSetField(out, TIFFTAG_EXTRASAMPLES, 1, v);
}
TIFFSetField(out, TIFFTAG_MINSAMPLEVALUE, (uint16_t)in->min);
TIFFSetField(out, TIFFTAG_MAXSAMPLEVALUE, (uint16_t)in->max);
TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);
if (config != PLANARCONFIG_SEPARATE)
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(out, rowsperstrip));
else /* force 1 row/strip for library limitation */
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, 1L);
if (in->name[0] != '\0')
TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, in->name);
if (config == PLANARCONFIG_CONTIG)
cpContig(in, out);
else
cpSeparate(in, out);
(void)iclose(in);
(void)TIFFClose(out);
return (0);
}
static int
processCompressOptions(char* opt)
static int processCompressOptions(char *opt)
{
if (streq(opt, "none"))
compression = COMPRESSION_NONE;
else if (streq(opt, "packbits"))
compression = COMPRESSION_PACKBITS;
else if (strneq(opt, "jpeg", 4)) {
char* cp = strchr(opt, ':');
if (streq(opt, "none"))
compression = COMPRESSION_NONE;
else if (streq(opt, "packbits"))
compression = COMPRESSION_PACKBITS;
else if (strneq(opt, "jpeg", 4))
{
char *cp = strchr(opt, ':');
defcompression = COMPRESSION_JPEG;
while( cp )
{
if (isdigit((int)cp[1]))
quality = atoi(cp+1);
else if (cp[1] == 'r' )
jpegcolormode = JPEGCOLORMODE_RAW;
else
usage();
defcompression = COMPRESSION_JPEG;
while (cp)
{
if (isdigit((int)cp[1]))
quality = atoi(cp + 1);
else if (cp[1] == 'r')
jpegcolormode = JPEGCOLORMODE_RAW;
else
usage();
cp = strchr(cp+1,':');
}
} else if (strneq(opt, "lzw", 3)) {
char* cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp+1);
compression = COMPRESSION_LZW;
} else if (strneq(opt, "zip", 3)) {
char* cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp+1);
compression = COMPRESSION_ADOBE_DEFLATE;
} else
return (0);
return (1);
cp = strchr(cp + 1, ':');
}
}
else if (strneq(opt, "lzw", 3))
{
char *cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp + 1);
compression = COMPRESSION_LZW;
}
else if (strneq(opt, "zip", 3))
{
char *cp = strchr(opt, ':');
if (cp)
predictor = atoi(cp + 1);
compression = COMPRESSION_ADOBE_DEFLATE;
}
else
return (0);
return (1);
}
static int
cpContig(IMAGE* in, TIFF* out)
static int cpContig(IMAGE *in, TIFF *out)
{
tdata_t buf = _TIFFmalloc(TIFFScanlineSize(out));
short *r = NULL;
int x, y;
tdata_t buf = _TIFFmalloc(TIFFScanlineSize(out));
short *r = NULL;
int x, y;
if (in->zsize == 3) {
short *g, *b;
if (in->zsize == 3)
{
short *g, *b;
r = (short *)_TIFFmalloc(3 * in->xsize * sizeof (short));
g = r + in->xsize;
b = g + in->xsize;
for (y = in->ysize-1; y >= 0; y--) {
uint8_t* pp = (uint8_t*) buf;
r = (short *)_TIFFmalloc(3 * in->xsize * sizeof(short));
g = r + in->xsize;
b = g + in->xsize;
for (y = in->ysize - 1; y >= 0; y--)
{
uint8_t *pp = (uint8_t *)buf;
getrow(in, r, y, 0);
getrow(in, g, y, 1);
getrow(in, b, y, 2);
for (x = 0; x < in->xsize; x++) {
pp[0] = r[x];
pp[1] = g[x];
pp[2] = b[x];
pp += 3;
}
if (TIFFWriteScanline(out, buf, in->ysize-y-1, 0) < 0)
goto bad;
}
} else if (in->zsize == 4) {
short *g, *b, *a;
getrow(in, r, y, 0);
getrow(in, g, y, 1);
getrow(in, b, y, 2);
for (x = 0; x < in->xsize; x++)
{
pp[0] = r[x];
pp[1] = g[x];
pp[2] = b[x];
pp += 3;
}
if (TIFFWriteScanline(out, buf, in->ysize - y - 1, 0) < 0)
goto bad;
}
}
else if (in->zsize == 4)
{
short *g, *b, *a;
r = (short *)_TIFFmalloc(4 * in->xsize * sizeof (short));
g = r + in->xsize;
b = g + in->xsize;
a = b + in->xsize;
for (y = in->ysize-1; y >= 0; y--) {
uint8_t* pp = (uint8_t*) buf;
r = (short *)_TIFFmalloc(4 * in->xsize * sizeof(short));
g = r + in->xsize;
b = g + in->xsize;
a = b + in->xsize;
for (y = in->ysize - 1; y >= 0; y--)
{
uint8_t *pp = (uint8_t *)buf;
getrow(in, r, y, 0);
getrow(in, g, y, 1);
getrow(in, b, y, 2);
getrow(in, a, y, 3);
for (x = 0; x < in->xsize; x++) {
pp[0] = r[x];
pp[1] = g[x];
pp[2] = b[x];
pp[3] = a[x];
pp += 4;
}
if (TIFFWriteScanline(out, buf, in->ysize-y-1, 0) < 0)
goto bad;
}
} else {
uint8_t* pp = (uint8_t*) buf;
getrow(in, r, y, 0);
getrow(in, g, y, 1);
getrow(in, b, y, 2);
getrow(in, a, y, 3);
for (x = 0; x < in->xsize; x++)
{
pp[0] = r[x];
pp[1] = g[x];
pp[2] = b[x];
pp[3] = a[x];
pp += 4;
}
if (TIFFWriteScanline(out, buf, in->ysize - y - 1, 0) < 0)
goto bad;
}
}
else
{
uint8_t *pp = (uint8_t *)buf;
r = (short *)_TIFFmalloc(in->xsize * sizeof (short));
for (y = in->ysize-1; y >= 0; y--) {
getrow(in, r, y, 0);
for (x = in->xsize-1; x >= 0; x--)
pp[x] = r[x];
if (TIFFWriteScanline(out, buf, in->ysize-y-1, 0) < 0)
goto bad;
}
}
if (r)
_TIFFfree(r);
_TIFFfree(buf);
return (1);
r = (short *)_TIFFmalloc(in->xsize * sizeof(short));
for (y = in->ysize - 1; y >= 0; y--)
{
getrow(in, r, y, 0);
for (x = in->xsize - 1; x >= 0; x--)
pp[x] = r[x];
if (TIFFWriteScanline(out, buf, in->ysize - y - 1, 0) < 0)
goto bad;
}
}
if (r)
_TIFFfree(r);
_TIFFfree(buf);
return (1);
bad:
if (r)
_TIFFfree(r);
_TIFFfree(buf);
return (0);
if (r)
_TIFFfree(r);
_TIFFfree(buf);
return (0);
}
static int
cpSeparate(IMAGE* in, TIFF* out)
static int cpSeparate(IMAGE *in, TIFF *out)
{
tdata_t buf = _TIFFmalloc(TIFFScanlineSize(out));
short *r = (short *)_TIFFmalloc(in->xsize * sizeof (short));
uint8_t* pp = (uint8_t*) buf;
int x, y, z;
tdata_t buf = _TIFFmalloc(TIFFScanlineSize(out));
short *r = (short *)_TIFFmalloc(in->xsize * sizeof(short));
uint8_t *pp = (uint8_t *)buf;
int x, y, z;
for (z = 0; z < in->zsize; z++) {
for (y = in->ysize-1; y >= 0; y--) {
getrow(in, r, y, z);
for (x = 0; x < in->xsize; x++)
pp[x] = r[x];
if (TIFFWriteScanline(out, buf, in->ysize-y-1, z) < 0)
goto bad;
}
}
_TIFFfree(r);
_TIFFfree(buf);
return (1);
for (z = 0; z < in->zsize; z++)
{
for (y = in->ysize - 1; y >= 0; y--)
{
getrow(in, r, y, z);
for (x = 0; x < in->xsize; x++)
pp[x] = r[x];
if (TIFFWriteScanline(out, buf, in->ysize - y - 1, z) < 0)
goto bad;
}
}
_TIFFfree(r);
_TIFFfree(buf);
return (1);
bad:
_TIFFfree(r);
_TIFFfree(buf);
return (0);
_TIFFfree(r);
_TIFFfree(buf);
return (0);
}
char* stuff[] = {
"usage: sgi2tiff [options] input.rgb output.tif",
"where options are:",
" -r # make each strip have no more than # rows",
"",
" -p contig pack samples contiguously (e.g. RGBRGB...)",
" -p separate store samples separately (e.g. RRR...GGG...BBB...)",
"",
" -f lsb2msb force lsb-to-msb FillOrder for output",
" -f msb2lsb force msb-to-lsb FillOrder for output",
"",
" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
" -c zip[:opts] compress output with deflate encoding",
" -c jpeg[:opts]compress output with JPEG encoding",
" -c packbits compress output with packbits encoding",
" -c none use no compression algorithm on output",
"",
"JPEG options:",
" # set compression quality level (0-100, default 75)",
" r output color image as RGB rather than YCbCr",
"",
"LZW and deflate options:",
" # set predictor value",
"For example, -c lzw:2 to get LZW-encoded data with horizontal differencing",
NULL
};
char *stuff[] = {
"usage: sgi2tiff [options] input.rgb output.tif",
"where options are:",
" -r # make each strip have no more than # rows",
"",
" -p contig pack samples contiguously (e.g. RGBRGB...)",
" -p separate store samples separately (e.g. RRR...GGG...BBB...)",
"",
" -f lsb2msb force lsb-to-msb FillOrder for output",
" -f msb2lsb force msb-to-lsb FillOrder for output",
"",
" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
" -c zip[:opts] compress output with deflate encoding",
" -c jpeg[:opts]compress output with JPEG encoding",
" -c packbits compress output with packbits encoding",
" -c none use no compression algorithm on output",
"",
"JPEG options:",
" # set compression quality level (0-100, default 75)",
" r output color image as RGB rather than YCbCr",
"",
"LZW and deflate options:",
" # set predictor value",
"For example, -c lzw:2 to get LZW-encoded data with horizontal "
"differencing",
NULL};
static void
usage(void)
static void usage(void)
{
char buf[BUFSIZ];
int i;
char buf[BUFSIZ];
int i;
setbuf(stderr, buf);
for (i = 0; stuff[i] != NULL; i++)
fprintf(stderr, "%s\n", stuff[i]);
exit(-1);
setbuf(stderr, buf);
for (i = 0; stuff[i] != NULL; i++)
fprintf(stderr, "%s\n", stuff[i]);
exit(-1);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+259 -253
View File
@@ -2,23 +2,23 @@
* Copyright (c) 1990-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
@@ -26,291 +26,297 @@
#include <stdlib.h>
#include <string.h>
#include <gl.h>
#include <ctype.h>
#include <gl.h>
#include "tiffio.h"
typedef unsigned char unsigned char;
typedef unsigned long uint32_t;
#define streq(a,b) (strcmp(a,b) == 0)
#define strneq(a,b,n) (strncmp(a,b,n) == 0)
#define streq(a, b) (strcmp(a, b) == 0)
#define strneq(a, b, n) (strncmp(a, b, n) == 0)
uint32_t rowsperstrip = (uint32_t) -1;
uint16_t compression = COMPRESSION_PACKBITS;
uint16_t config = PLANARCONFIG_CONTIG;
uint16_t predictor = 0;
int xmaxscreen;
int ymaxscreen;
uint16_t photometric = PHOTOMETRIC_RGB;
int jpegcolormode = JPEGCOLORMODE_RGB;
int quality = 75; /* JPEG quality */
uint32_t rowsperstrip = (uint32_t)-1;
uint16_t compression = COMPRESSION_PACKBITS;
uint16_t config = PLANARCONFIG_CONTIG;
uint16_t predictor = 0;
int xmaxscreen;
int ymaxscreen;
uint16_t photometric = PHOTOMETRIC_RGB;
int jpegcolormode = JPEGCOLORMODE_RGB;
int quality = 75; /* JPEG quality */
static void usage(void);
static void tiffsv(char*, int, int, int, int);
static void usage(void);
static void tiffsv(char *, int, int, int, int);
int
main(int argc, char* argv[])
int main(int argc, char *argv[])
{
int c;
int c;
#if !HAVE_DECL_OPTARG
extern int optind;
extern char* optarg;
extern int optind;
extern char *optarg;
#endif
while ((c = getopt(argc, argv, "c:p:r:")) != -1)
switch (c) {
case 'b': /* save as b&w */
photometric = PHOTOMETRIC_MINISBLACK;
break;
case 'c': /* compression scheme */
if (streq(optarg, "none"))
compression = COMPRESSION_NONE;
else if (streq(optarg, "packbits"))
compression = COMPRESSION_PACKBITS;
else if (strneq(optarg, "jpeg", 4)) {
char* cp = strchr(optarg, ':');
if (cp && isdigit(cp[1]))
quality = atoi(cp+1);
if (cp && strchr(cp, 'r'))
jpegcolormode = JPEGCOLORMODE_RAW;
compression = COMPRESSION_JPEG;
} else if (strneq(optarg, "lzw", 3)) {
char* cp = strchr(optarg, ':');
if (cp)
predictor = atoi(cp+1);
compression = COMPRESSION_LZW;
} else
usage();
break;
case 'p': /* planar configuration */
if (streq(optarg, "separate"))
config = PLANARCONFIG_SEPARATE;
else if (streq(optarg, "contig"))
config = PLANARCONFIG_CONTIG;
else
usage();
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
break;
case '?':
usage();
/*NOTREACHED*/
}
if (argc - optind != 1 && argc - optind != 5)
usage();
xmaxscreen = getgdesc(GD_XPMAX)-1;
ymaxscreen = getgdesc(GD_YPMAX)-1;
foreground();
noport();
winopen("tiffsv");
if (argc - optind == 5)
tiffsv(argv[optind],
atoi(argv[optind+1]), atoi(argv[optind+2]),
atoi(argv[optind+3]), atoi(argv[optind+4]));
else
tiffsv(argv[optind], 0, xmaxscreen, 0, ymaxscreen);
return (0);
while ((c = getopt(argc, argv, "c:p:r:")) != -1)
switch (c)
{
case 'b': /* save as b&w */
photometric = PHOTOMETRIC_MINISBLACK;
break;
case 'c': /* compression scheme */
if (streq(optarg, "none"))
compression = COMPRESSION_NONE;
else if (streq(optarg, "packbits"))
compression = COMPRESSION_PACKBITS;
else if (strneq(optarg, "jpeg", 4))
{
char *cp = strchr(optarg, ':');
if (cp && isdigit(cp[1]))
quality = atoi(cp + 1);
if (cp && strchr(cp, 'r'))
jpegcolormode = JPEGCOLORMODE_RAW;
compression = COMPRESSION_JPEG;
}
else if (strneq(optarg, "lzw", 3))
{
char *cp = strchr(optarg, ':');
if (cp)
predictor = atoi(cp + 1);
compression = COMPRESSION_LZW;
}
else
usage();
break;
case 'p': /* planar configuration */
if (streq(optarg, "separate"))
config = PLANARCONFIG_SEPARATE;
else if (streq(optarg, "contig"))
config = PLANARCONFIG_CONTIG;
else
usage();
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
break;
case '?':
usage();
/*NOTREACHED*/
}
if (argc - optind != 1 && argc - optind != 5)
usage();
xmaxscreen = getgdesc(GD_XPMAX) - 1;
ymaxscreen = getgdesc(GD_YPMAX) - 1;
foreground();
noport();
winopen("tiffsv");
if (argc - optind == 5)
tiffsv(argv[optind], atoi(argv[optind + 1]), atoi(argv[optind + 2]),
atoi(argv[optind + 3]), atoi(argv[optind + 4]));
else
tiffsv(argv[optind], 0, xmaxscreen, 0, ymaxscreen);
return (0);
}
char* stuff[] = {
"usage: tiffsv [options] outimage.tif [x1 x2 y1 y2] [-b]",
"where options are:",
" -p contig pack samples contiguously (e.g. RGBRGB...)",
" -p separate store samples separately (e.g. RRR...GGG...BBB...)",
"",
" -r # make each strip have no more than # rows",
"",
" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
" -c jpeg[:opts]compress output with JPEG encoding",
" -c packbits compress output with packbits encoding",
" -c none use no compression algorithm on output",
"",
"JPEG options:",
" # set compression quality level (0-100, default 75)",
" r output color image as RGB rather than YCbCr",
"",
"LZW options:",
" # set predictor value for Lempel-Ziv & Welch encoding",
"For example, -c lzw:2 to get LZW-encoded data with horizontal differencing",
NULL
};
char *stuff[] = {
"usage: tiffsv [options] outimage.tif [x1 x2 y1 y2] [-b]",
"where options are:",
" -p contig pack samples contiguously (e.g. RGBRGB...)",
" -p separate store samples separately (e.g. RRR...GGG...BBB...)",
"",
" -r # make each strip have no more than # rows",
"",
" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
" -c jpeg[:opts]compress output with JPEG encoding",
" -c packbits compress output with packbits encoding",
" -c none use no compression algorithm on output",
"",
"JPEG options:",
" # set compression quality level (0-100, default 75)",
" r output color image as RGB rather than YCbCr",
"",
"LZW options:",
" # set predictor value for Lempel-Ziv & Welch encoding",
"For example, -c lzw:2 to get LZW-encoded data with horizontal "
"differencing",
NULL};
static void
usage(void)
static void usage(void)
{
char buf[BUFSIZ];
int i;
char buf[BUFSIZ];
int i;
setbuf(stderr, buf);
for (i = 0; stuff[i] != NULL; i++)
fprintf(stderr, "%s\n", stuff[i]);
exit(-1);
setbuf(stderr, buf);
for (i = 0; stuff[i] != NULL; i++)
fprintf(stderr, "%s\n", stuff[i]);
exit(-1);
}
static void
svRGBSeparate(TIFF* tif, uint32_t* ss, int xsize, int ysize)
static void svRGBSeparate(TIFF *tif, uint32_t *ss, int xsize, int ysize)
{
tsize_t stripsize = TIFFStripSize(tif);
unsigned char *rbuf = (unsigned char *)_TIFFmalloc(3*stripsize);
unsigned char *gbuf = rbuf + stripsize;
unsigned char *bbuf = gbuf + stripsize;
register int y;
tsize_t stripsize = TIFFStripSize(tif);
unsigned char *rbuf = (unsigned char *)_TIFFmalloc(3 * stripsize);
unsigned char *gbuf = rbuf + stripsize;
unsigned char *bbuf = gbuf + stripsize;
register int y;
for (y = 0; y <= ysize; y += rowsperstrip) {
unsigned char *rp, *gp, *bp;
register int x;
register uint32_t n;
for (y = 0; y <= ysize; y += rowsperstrip)
{
unsigned char *rp, *gp, *bp;
register int x;
register uint32_t n;
n = rowsperstrip;
if (n > ysize-y+1)
n = ysize-y+1;
rp = rbuf; gp = gbuf; bp = bbuf;
do {
for (x = 0; x <= xsize; x++) {
uint32_t v = ss[x];
rp[x] = v;
gp[x] = v >> 8;
bp[x] = v >> 16;
}
rp += xsize+1, gp += xsize+1, bp += xsize+1;
ss += xsize+1;
} while (--n);
if (TIFFWriteEncodedStrip(tif, TIFFComputeStrip(tif,y,0),
rbuf, stripsize) < 0)
break;
if (TIFFWriteEncodedStrip(tif, TIFFComputeStrip(tif,y,1),
gbuf, stripsize) < 0)
break;
if (TIFFWriteEncodedStrip(tif, TIFFComputeStrip(tif,y,2),
bbuf, stripsize) < 0)
break;
}
_TIFFfree(rbuf);
n = rowsperstrip;
if (n > ysize - y + 1)
n = ysize - y + 1;
rp = rbuf;
gp = gbuf;
bp = bbuf;
do
{
for (x = 0; x <= xsize; x++)
{
uint32_t v = ss[x];
rp[x] = v;
gp[x] = v >> 8;
bp[x] = v >> 16;
}
rp += xsize + 1, gp += xsize + 1, bp += xsize + 1;
ss += xsize + 1;
} while (--n);
if (TIFFWriteEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), rbuf,
stripsize) < 0)
break;
if (TIFFWriteEncodedStrip(tif, TIFFComputeStrip(tif, y, 1), gbuf,
stripsize) < 0)
break;
if (TIFFWriteEncodedStrip(tif, TIFFComputeStrip(tif, y, 2), bbuf,
stripsize) < 0)
break;
}
_TIFFfree(rbuf);
}
static void
svRGBContig(TIFF* tif, uint32_t* ss, int xsize, int ysize)
static void svRGBContig(TIFF *tif, uint32_t *ss, int xsize, int ysize)
{
register int x, y;
tsize_t stripsize = TIFFStripSize(tif);
unsigned char *strip = (unsigned char *)_TIFFmalloc(stripsize);
register int x, y;
tsize_t stripsize = TIFFStripSize(tif);
unsigned char *strip = (unsigned char *)_TIFFmalloc(stripsize);
for (y = 0; y <= ysize; y += rowsperstrip) {
register unsigned char *pp = strip;
register uint32_t n;
for (y = 0; y <= ysize; y += rowsperstrip)
{
register unsigned char *pp = strip;
register uint32_t n;
n = rowsperstrip;
if (n > ysize-y+1)
n = ysize-y+1;
do {
for (x = 0; x <= xsize; x++) {
uint32_t v = ss[x];
pp[0] = v;
pp[1] = v >> 8;
pp[2] = v >> 16;
pp += 3;
}
ss += xsize+1;
} while (--n);
if (TIFFWriteEncodedStrip(tif, TIFFComputeStrip(tif,y,0),
strip, stripsize) < 0)
break;
}
_TIFFfree(strip);
n = rowsperstrip;
if (n > ysize - y + 1)
n = ysize - y + 1;
do
{
for (x = 0; x <= xsize; x++)
{
uint32_t v = ss[x];
pp[0] = v;
pp[1] = v >> 8;
pp[2] = v >> 16;
pp += 3;
}
ss += xsize + 1;
} while (--n);
if (TIFFWriteEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), strip,
stripsize) < 0)
break;
}
_TIFFfree(strip);
}
#undef RED
#undef GREEN
#undef BLUE
#define CVT(x) (((x)*255)/100)
#define RED CVT(28) /* 28% */
#define GREEN CVT(59) /* 59% */
#define BLUE CVT(11) /* 11% */
#define CVT(x) (((x)*255) / 100)
#define RED CVT(28) /* 28% */
#define GREEN CVT(59) /* 59% */
#define BLUE CVT(11) /* 11% */
static void
svGrey(TIFF* tif, uint32_t* ss, int xsize, int ysize)
static void svGrey(TIFF *tif, uint32_t *ss, int xsize, int ysize)
{
register int x, y;
unsigned char *buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif));
register int x, y;
unsigned char *buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif));
for (y = 0; y <= ysize; y++) {
for (x = 0; x <= xsize; x++) {
unsigned char *cp = (unsigned char *)&ss[x];
buf[x] = (RED*cp[3] + GREEN*cp[2] + BLUE*cp[1]) >> 8;
}
if (TIFFWriteScanline(tif, buf, (uint32_t) y, 0) < 0)
break;
ss += xsize+1;
}
_TIFFfree(buf);
for (y = 0; y <= ysize; y++)
{
for (x = 0; x <= xsize; x++)
{
unsigned char *cp = (unsigned char *)&ss[x];
buf[x] = (RED * cp[3] + GREEN * cp[2] + BLUE * cp[1]) >> 8;
}
if (TIFFWriteScanline(tif, buf, (uint32_t)y, 0) < 0)
break;
ss += xsize + 1;
}
_TIFFfree(buf);
}
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(x) ((x) < 0 ? -(x) : (x))
static void
tiffsv(char* name, int x1, int x2, int y1, int y2)
static void tiffsv(char *name, int x1, int x2, int y1, int y2)
{
TIFF *tif;
int xsize, ysize;
int xorg, yorg;
uint32_t *scrbuf;
TIFF *tif;
int xsize, ysize;
int xorg, yorg;
uint32_t *scrbuf;
xorg = MIN(x1,x2);
yorg = MIN(y1,y2);
if (xorg<0)
xorg = 0;
if (yorg<0)
yorg = 0;
xsize = ABS(x2-x1);
ysize = ABS(y2-y1);
if (xorg+xsize > xmaxscreen)
xsize = xmaxscreen-xorg;
if (yorg+ysize > ymaxscreen)
ysize = ymaxscreen-yorg;
tif = TIFFOpen(name, "w");
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (uint32_t) (xsize+1));
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (uint32_t) (ysize+1));
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL,
photometric == PHOTOMETRIC_RGB ? 3 : 1);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, config);
TIFFSetField(tif, TIFFTAG_COMPRESSION, compression);
switch (compression) {
case COMPRESSION_JPEG:
if (photometric == PHOTOMETRIC_RGB && jpegcolormode == JPEGCOLORMODE_RGB)
photometric = PHOTOMETRIC_YCBCR;
TIFFSetField(tif, TIFFTAG_JPEGQUALITY, quality);
TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
break;
case COMPRESSION_LZW:
if (predictor != 0)
TIFFSetField(tif, TIFFTAG_PREDICTOR, predictor);
break;
}
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
rowsperstrip = TIFFDefaultStripSize(tif, rowsperstrip);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
scrbuf = (uint32_t *)_TIFFmalloc((xsize+1)*(ysize+1)*sizeof (uint32_t));
readdisplay(xorg, yorg, xorg+xsize, yorg+ysize, scrbuf, RD_FREEZE);
if (photometric == PHOTOMETRIC_RGB) {
if (config == PLANARCONFIG_SEPARATE)
svRGBSeparate(tif, scrbuf, xsize, ysize);
else
svRGBContig(tif, scrbuf, xsize, ysize);
} else
svGrey(tif, scrbuf, xsize, ysize);
(void) TIFFClose(tif);
_TIFFfree((char *)scrbuf);
xorg = MIN(x1, x2);
yorg = MIN(y1, y2);
if (xorg < 0)
xorg = 0;
if (yorg < 0)
yorg = 0;
xsize = ABS(x2 - x1);
ysize = ABS(y2 - y1);
if (xorg + xsize > xmaxscreen)
xsize = xmaxscreen - xorg;
if (yorg + ysize > ymaxscreen)
ysize = ymaxscreen - yorg;
tif = TIFFOpen(name, "w");
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (uint32_t)(xsize + 1));
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (uint32_t)(ysize + 1));
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL,
photometric == PHOTOMETRIC_RGB ? 3 : 1);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, config);
TIFFSetField(tif, TIFFTAG_COMPRESSION, compression);
switch (compression)
{
case COMPRESSION_JPEG:
if (photometric == PHOTOMETRIC_RGB &&
jpegcolormode == JPEGCOLORMODE_RGB)
photometric = PHOTOMETRIC_YCBCR;
TIFFSetField(tif, TIFFTAG_JPEGQUALITY, quality);
TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
break;
case COMPRESSION_LZW:
if (predictor != 0)
TIFFSetField(tif, TIFFTAG_PREDICTOR, predictor);
break;
}
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
rowsperstrip = TIFFDefaultStripSize(tif, rowsperstrip);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
scrbuf =
(uint32_t *)_TIFFmalloc((xsize + 1) * (ysize + 1) * sizeof(uint32_t));
readdisplay(xorg, yorg, xorg + xsize, yorg + ysize, scrbuf, RD_FREEZE);
if (photometric == PHOTOMETRIC_RGB)
{
if (config == PLANARCONFIG_SEPARATE)
svRGBSeparate(tif, scrbuf, xsize, ysize);
else
svRGBContig(tif, scrbuf, xsize, ysize);
}
else
svGrey(tif, scrbuf, xsize, ysize);
(void)TIFFClose(tif);
_TIFFfree((char *)scrbuf);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+79 -99
View File
@@ -1,17 +1,17 @@
float ycbcrCoeffs[3] = { .299, .587, .114 };
float ycbcrCoeffs[3] = {.299, .587, .114};
/* default coding range is CCIR Rec 601-1 with no headroom/footroom */
unsigned long refBlackWhite[6] = { 0, 255, 128, 255, 128, 255 };
unsigned long refBlackWhite[6] = {0, 255, 128, 255, 128, 255};
#define LumaRed ycbcrCoeffs[0]
#define LumaGreen ycbcrCoeffs[1]
#define LumaBlue ycbcrCoeffs[2]
#define LumaRed ycbcrCoeffs[0]
#define LumaGreen ycbcrCoeffs[1]
#define LumaBlue ycbcrCoeffs[2]
long eRtotal = 0;
long eGtotal = 0;
long eBtotal = 0;
long preveRtotal = 0;
long preveGtotal = 0;
long preveBtotal = 0;
long eRtotal = 0;
long eGtotal = 0;
long eBtotal = 0;
long preveRtotal = 0;
long preveGtotal = 0;
long preveBtotal = 0;
unsigned long AbseRtotal = 0;
unsigned long AbseGtotal = 0;
unsigned long AbseBtotal = 0;
@@ -20,101 +20,90 @@ unsigned long preveCodes = 0;
unsigned long eBits = 0;
unsigned long preveBits = 0;
static void setupLumaTables();
static void setupLumaTables();
static int abs(int v) { return (v < 0 ? -v : v); }
static double pct(int v,double range) { return (v*100. / range); }
static double pct(int v, double range) { return (v * 100. / range); }
static void check(int R, int G, int B);
float D1, D2;
float D3, D4;
float D5, D6;
float D1, D2;
float D3, D4;
float D5, D6;
int
main(int argc, char** argv)
int main(int argc, char **argv)
{
int R, G, B;
if (argc > 1) {
refBlackWhite[0] = 16;
refBlackWhite[1] = 235;
refBlackWhite[2] = 128;
refBlackWhite[3] = 240;
refBlackWhite[4] = 128;
refBlackWhite[5] = 240;
if (argc > 1)
{
refBlackWhite[0] = 16;
refBlackWhite[1] = 235;
refBlackWhite[2] = 128;
refBlackWhite[3] = 240;
refBlackWhite[4] = 128;
refBlackWhite[5] = 240;
}
D3 = 2 - 2*LumaRed;
D4 = 2 - 2*LumaBlue;
D3 = 2 - 2 * LumaRed;
D4 = 2 - 2 * LumaBlue;
D1 = 1. / D3;
D2 = 1. / D4;
D5 = D3*LumaRed / LumaGreen;
D6 = D4*LumaBlue / LumaGreen;
D5 = D3 * LumaRed / LumaGreen;
D6 = D4 * LumaBlue / LumaGreen;
setupLumaTables();
for (R = 0; R < 256; R++) {
for (G = 0; G < 256; G++)
for (B = 0; B < 256; B++)
check(R, G, B);
printf("[%3u] c %u/%u b %u/%u (R %u/%d/%u G %u/%d/%u B %u/%d/%u)\n"
, R
, eCodes - preveCodes, eCodes
, eBits - preveBits, eBits
, abs(AbseRtotal - preveRtotal), eRtotal , AbseRtotal
, abs(AbseGtotal - preveGtotal), eGtotal , AbseGtotal
, abs(AbseBtotal - preveBtotal), eBtotal , AbseBtotal
);
preveRtotal = AbseRtotal;
preveGtotal = AbseGtotal;
preveBtotal = AbseBtotal;
preveCodes = eCodes;
preveBits = eBits;
for (R = 0; R < 256; R++)
{
for (G = 0; G < 256; G++)
for (B = 0; B < 256; B++)
check(R, G, B);
printf("[%3u] c %u/%u b %u/%u (R %u/%d/%u G %u/%d/%u B %u/%d/%u)\n", R,
eCodes - preveCodes, eCodes, eBits - preveBits, eBits,
abs(AbseRtotal - preveRtotal), eRtotal, AbseRtotal,
abs(AbseGtotal - preveGtotal), eGtotal, AbseGtotal,
abs(AbseBtotal - preveBtotal), eBtotal, AbseBtotal);
preveRtotal = AbseRtotal;
preveGtotal = AbseGtotal;
preveBtotal = AbseBtotal;
preveCodes = eCodes;
preveBits = eBits;
}
printf("%u total codes\n", 256*256*256);
printf("total error: %u codes %u bits (R %d/%u G %d/%u B %d/%u)\n"
, eCodes
, eBits
, eRtotal , AbseRtotal
, eGtotal , AbseGtotal
, eBtotal , AbseBtotal
);
printf("%u total codes\n", 256 * 256 * 256);
printf("total error: %u codes %u bits (R %d/%u G %d/%u B %d/%u)\n", eCodes,
eBits, eRtotal, AbseRtotal, eGtotal, AbseGtotal, eBtotal,
AbseBtotal);
return (0);
}
float *lumaRed;
float *lumaGreen;
float *lumaBlue;
float *lumaRed;
float *lumaGreen;
float *lumaBlue;
static float*
setupLuma(float c)
static float *setupLuma(float c)
{
float *v = (float *)_TIFFmalloc(256 * sizeof (float));
float *v = (float *)_TIFFmalloc(256 * sizeof(float));
int i;
for (i = 0; i < 256; i++)
v[i] = c * i;
v[i] = c * i;
return (v);
}
static void
setupLumaTables(void)
static void setupLumaTables(void)
{
lumaRed = setupLuma(LumaRed);
lumaGreen = setupLuma(LumaGreen);
lumaBlue = setupLuma(LumaBlue);
}
static unsigned
V2Code(float f, unsigned long RB, unsigned long RW, int CR)
static unsigned V2Code(float f, unsigned long RB, unsigned long RW, int CR)
{
unsigned int c = (unsigned int)((((f)*(RW-RB)/CR)+RB)+.5);
unsigned int c = (unsigned int)((((f) * (RW - RB) / CR) + RB) + .5);
return (c > 255 ? 255 : c);
}
#define Code2V(c, RB, RW, CR) ((((c)-(int)RB)*(float)CR)/(float)(RW-RB))
#define Code2V(c, RB, RW, CR) ((((c) - (int)RB) * (float)CR) / (float)(RW - RB))
#define CLAMP(f,min,max) \
(int)((f)+.5 < (min) ? (min) : (f)+.5 > (max) ? (max) : (f)+.5)
#define CLAMP(f, min, max) \
(int)((f) + .5 < (min) ? (min) : (f) + .5 > (max) ? (max) : (f) + .5)
static
void
check(int R, int G, int B)
static void check(int R, int G, int B)
{
float Y, Cb, Cr;
int iY, iCb, iCr;
@@ -123,31 +112,29 @@ check(int R, int G, int B)
int eR, eG, eB;
Y = lumaRed[R] + lumaGreen[G] + lumaBlue[B];
Cb = (B - Y)*D2;
Cr = (R - Y)*D1;
Cb = (B - Y) * D2;
Cr = (R - Y) * D1;
iY = V2Code(Y, refBlackWhite[0], refBlackWhite[1], 255);
iCb = V2Code(Cb, refBlackWhite[2], refBlackWhite[3], 127);
iCr = V2Code(Cr, refBlackWhite[4], refBlackWhite[5], 127);
rCb = Code2V(iCb, refBlackWhite[2], refBlackWhite[3], 127);
rCr = Code2V(iCr, refBlackWhite[4], refBlackWhite[5], 127);
rY = Code2V(iY, refBlackWhite[0], refBlackWhite[1], 255);
rR = rY + rCr*D3;
rB = rY + rCb*D4;
rG = rY - rCb*D6 - rCr*D5;
eR = R - CLAMP(rR,0,255);
eG = G - CLAMP(rG,0,255);
eB = B - CLAMP(rB,0,255);
if (abs(eR) > 1 || abs(eG) > 1 || abs(eB) > 1) {
printf("R %u G %u B %u", R, G, B);
printf(" Y %g Cb %g Cr %g", Y, Cb, Cr);
printf(" iY %u iCb %u iCr %u", iY, iCb, iCr);
printf("\n -> Y %g Cb %g Cr %g", rY, rCb, rCr);
printf(" R %g (%u) G %g (%u) B %g (%u) E=[%d %d %d])\n"
, rR, CLAMP(rR,0,255)
, rG, CLAMP(rG,0,255)
, rB, CLAMP(rB,0,255)
, eR, eG, eB
);
rR = rY + rCr * D3;
rB = rY + rCb * D4;
rG = rY - rCb * D6 - rCr * D5;
eR = R - CLAMP(rR, 0, 255);
eG = G - CLAMP(rG, 0, 255);
eB = B - CLAMP(rB, 0, 255);
if (abs(eR) > 1 || abs(eG) > 1 || abs(eB) > 1)
{
printf("R %u G %u B %u", R, G, B);
printf(" Y %g Cb %g Cr %g", Y, Cb, Cr);
printf(" iY %u iCb %u iCr %u", iY, iCb, iCr);
printf("\n -> Y %g Cb %g Cr %g", rY, rCb, rCr);
printf(" R %g (%u) G %g (%u) B %g (%u) E=[%d %d %d])\n", rR,
CLAMP(rR, 0, 255), rG, CLAMP(rG, 0, 255), rB, CLAMP(rB, 0, 255),
eR, eG, eB);
}
eRtotal += eR;
eGtotal += eG;
@@ -156,13 +143,6 @@ check(int R, int G, int B)
AbseGtotal += abs(eG);
AbseBtotal += abs(eB);
if (eR | eG | eB)
eCodes++;
eCodes++;
eBits += abs(eR) + abs(eG) + abs(eB);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+19 -8
View File
@@ -1,10 +1,21 @@
#!/bin/sh
retval=0
set -x
libtoolize --force --copy
aclocal -I ./m4
autoheader
automake --foreign --add-missing --copy
autoconf
case `uname` in
Darwin*)
glibtoolize --force --copy || retval=$?
;;
*)
libtoolize --force --copy || retval=$?
;;
esac
aclocal -I ./m4 || retval=$?
autoheader || retval=$?
automake --foreign --add-missing --copy || retval=$?
autoconf || retval=$?
# Get latest config.guess and config.sub from upstream master since
# these are often out of date.
for file in config.guess config.sub
@@ -13,8 +24,8 @@ do
wget -q --timeout=5 -O config/$file.tmp \
"https://git.savannah.gnu.org/cgit/config.git/plain/${file}" \
&& mv -f config/$file.tmp config/$file \
&& chmod a+x config/$file
retval=$?
&& chmod a+x config/$file || retval=$?
rm -f config/$file.tmp
test $retval -eq 0 || exit $retval
done
exit $retval
+46 -3
View File
@@ -13,11 +13,27 @@ autoconf_build()
mkdir autoconf-build
cd autoconf-build
echo "Running ../configure --prefix=$(pwd)/../autoconf-install) ${opts}"
../configure --prefix=$(pwd)/../autoconf-install ${opts}
CFLAGS="-Wall -Wextra -Werror" ../configure --prefix=$(pwd)/../autoconf-install ${opts}
make
make install
make check
make distcheck
mkdir ../distribution
cp tiff-*.tar.* tiff*.zip ../distribution
}
# Test autoconf build (minimal; no distcheck)
autoconf_build_minimal()
{
autoreconf -ivf
mkdir autoconf-build
cd autoconf-build
echo "Running ../configure --prefix=$(pwd)/../autoconf-install) ${opts}"
CFLAGS="-Wall -Wextra -Werror" ../configure --prefix=$(pwd)/../autoconf-install ${opts}
make
make install
make check
}
# Test cmake build
@@ -30,11 +46,34 @@ cmake_build()
mkdir cmake-build
cd cmake-build
opts="-Dfatal-warnings=ON"
echo "Running cmake -G "$1" -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../cmake-install ${opts} .."
cmake -G "$1" -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../cmake-install ${opts} ..
para3=`echo "$3" | sed 's/./\L&/g'`
if [ "$para3" = "static" ]; then
opts2="-DBUILD_SHARED_LIBS:BOOL=OFF"
else
opts2=""
fi
echo "Running cmake -G "$1" -DCMAKE_UNITY_BUILD=ON -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../cmake-install ${opts} ${opts2} .."
cmake -G "$1" -DCMAKE_UNITY_BUILD=ON -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../cmake-install -DCMAKE_C_FLAGS="-Wall -Wextra -Werror" ${opts} ${opts2} ..
$COVERITY_BUILD cmake --build .
cmake --build . --target install
ctest -V
cd ..
if [ "$para3" = "static" ]; then
echo No test project build for STATIC CI/CD build - skipped -.
else
# Build test project using find_package(Tiff CONFIG)
mkdir cmake-test-build
cd cmake-test-build
cmake -G "$1" -DCMAKE_BUILD_TYPE="$2" "-DTiff_DIR=$PWD/../cmake-install/lib/cmake/tiff" -S ../build/test_cmake -B .
cmake --build .
cd ..
mkdir cmake-test-no-target-build
cd cmake-test-no-target-build
cmake -G "$1" -DCMAKE_BUILD_TYPE="$2" "-DTiff_DIR=$PWD/../cmake-install/lib/cmake/tiff" -S ../build/test_cmake_no_target -B .
cmake --build .
# Return to cmake-build for coverity_build()
cd ../cmake-build
fi
}
# Static-analysis with coverity
@@ -64,6 +103,10 @@ case $build in
echo "Testing Autoconf build"
autoconf_build "$@"
;;
autoconf-minimal)
echo "Testing Autoconf build (minimal)"
autoconf_build_minimal "$@"
;;
cmake)
echo "Testing CMake build"
cmake_build "$@"
+7
View File
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.9.0)
project(test)
find_package(Tiff CONFIG REQUIRED)
add_executable(test test.c)
target_link_libraries(test PRIVATE TIFF::tiff)
+7
View File
@@ -0,0 +1,7 @@
#include "tiffio.h"
int main()
{
TIFFGetVersion();
return 0;
}
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.9.0)
project(test)
find_package(Tiff CONFIG REQUIRED)
add_executable(test test.c)
target_include_directories(test PRIVATE ${TIFF_INCLUDE_DIR})
target_link_libraries(test PRIVATE ${TIFF_LIBRARIES})
+7
View File
@@ -0,0 +1,7 @@
#include "tiffio.h"
int main()
{
TIFFGetVersion();
return 0;
}
+1 -1
View File
@@ -29,4 +29,4 @@ set(PACKAGE_NAME "LibTIFF Software")
set(PACKAGE_TARNAME "${PROJECT_NAME}")
set(PACKAGE_VERSION "${PROJECT_VERSION}${LIBTIFF_ALPHA_VERSION}")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "tiff@lists.maptools.org")
set(PACKAGE_BUGREPORT "tiff@lists.osgeo.org")
+6
View File
@@ -40,6 +40,12 @@ endforeach()
set(LIBTIFF_VERSION "${LIBTIFF_MAJOR_VERSION}.${LIBTIFF_MINOR_VERSION}.${LIBTIFF_MICRO_VERSION}")
set(LIBTIFF_VERSION_FULL "${LIBTIFF_VERSION}${LIBTIFF_ALPHA_VERSION}")
# Get release version from file VERSION
FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" LIBTIFF_RELEASE_VERSION)
# Package date - get it from file RELEASE-DATE
FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/RELEASE-DATE" LIBTIFF_RELEASE_DATE)
# Convert the libtool version variables to proper major and minor versions
math(EXPR SO_MAJOR "${LIBTIFF_CURRENT} - ${LIBTIFF_AGE}")
set(SO_MINOR "${LIBTIFF_AGE}")
+2 -2
View File
@@ -31,9 +31,9 @@ include(CheckSymbolExists)
include(CheckLibraryExists)
check_symbol_exists(pow "math.h" CMath_HAVE_LIBC_POW)
if(NOT CMath_HAVE_LIBC_POW)
find_library(CMath_LIBRARY NAMES m)
find_library(CMath_LIBRARY NAMES m)
if(NOT CMath_HAVE_LIBC_POW)
set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CMath_LIBRARY})
check_symbol_exists(pow "math.h" CMath_HAVE_LIBM_POW)
+7 -8
View File
@@ -66,15 +66,14 @@ unset(Deflate_OLD_FIND_LIBRARY_PREFIXES)
mark_as_advanced(Deflate_INCLUDE_DIR)
if(Deflate_INCLUDE_DIR AND EXISTS "${Deflate_INCLUDE_DIR}/deflate.h")
file(STRINGS "${Deflate_INCLUDE_DIR}/libdeflate.h" Deflate_H REGEX "^#define LIBDEFLATE_VERSION_STRING\s+\"[^\"]*\"$")
string(REGEX REPLACE "^.*Deflate_VERSION \"([0-9]+).*$" "\\1" Deflate_MAJOR_VERSION "${Deflate_H}")
string(REGEX REPLACE "^.*Deflate_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" Deflate_MINOR_VERSION "${Deflate_H}")
if(Deflate_INCLUDE_DIR AND EXISTS "${Deflate_INCLUDE_DIR}/libdeflate.h")
file(STRINGS "${Deflate_INCLUDE_DIR}/libdeflate.h" Deflate_H REGEX "^#define[\t ]+LIBDEFLATE_VERSION_STRING[\t ]+.*")
string(REGEX REPLACE "^.*LIBDEFLATE_VERSION_STRING[\t ]+\"([0-9]+).*$" "\\1" Deflate_MAJOR_VERSION "${Deflate_H}")
string(REGEX REPLACE "^.*LIBDEFLATE_VERSION_STRING[\t ]\"[0-9]+\\.([0-9]+).*$" "\\1" Deflate_MINOR_VERSION "${Deflate_H}")
set(Deflate_VERSION_STRING "${Deflate_MAJOR_VERSION}.${Deflate_MINOR_VERSION}")
set(Deflate_MAJOR_VERSION "${Deflate_VERSION_MAJOR}")
set(Deflate_MINOR_VERSION "${Deflate_VERSION_MINOR}")
set(Deflate_VERSION_MAJOR "${Deflate_MAJOR_VERSION}")
set(Deflate_VERSION_MINOR "${Deflate_MINOR_VERSION}")
endif()
include(FindPackageHandleStandardArgs)
@@ -110,7 +109,7 @@ if(Deflate_FOUND)
if(NOT Deflate_LIBRARY_RELEASE AND NOT Deflate_LIBRARY_DEBUG)
set_target_properties(Deflate::Deflate PROPERTIES
IMPORTED_LOCATION_RELEASE "${Deflate_LIBRARY}")
IMPORTED_LOCATION "${Deflate_LIBRARY}")
endif()
endif()
endif()
+1 -1
View File
@@ -110,7 +110,7 @@ if(JBIG_FOUND)
if(NOT JBIG_LIBRARY_RELEASE AND NOT JBIG_LIBRARY_DEBUG)
set_target_properties(JBIG::JBIG PROPERTIES
IMPORTED_LOCATION_RELEASE "${JBIG_LIBRARY}")
IMPORTED_LOCATION "${JBIG_LIBRARY}")
endif()
endif()
endif()
+16 -2
View File
@@ -11,7 +11,7 @@ IMPORTED Targets
^^^^^^^^^^^^^^^^
This module defines :prop_tgt:`IMPORTED` target ``LERC::LERC``, if
CMath has been found.
LERC has been found.
Result Variables
^^^^^^^^^^^^^^^^
@@ -23,6 +23,7 @@ This module defines the following variables:
LERC_INCLUDE_DIRS - where to find Lerc_c_api.h, etc.
LERC_LIBRARIES - List of libraries when using LERC.
LERC_FOUND - True if LERC found.
LERC_VERSION_STRING - version number as a string (ex: "4.0.1")
#]=======================================================================]
@@ -47,6 +48,19 @@ unset(LERC_NAMES)
mark_as_advanced(LERC_INCLUDE_DIR)
if(LERC_INCLUDE_DIR AND EXISTS "${LERC_INCLUDE_DIR}/Lerc_c_api.h")
file(STRINGS "${LERC_INCLUDE_DIR}/Lerc_c_api.h" LERC_H REGEX "^#define[\t ]+LERC_VERSION_[A-Z]+[\t ]+[0-9]+")
string(REGEX REPLACE "^.*#define[\t ]+LERC_VERSION_MAJOR[\t ]+([0-9]+).*$" "\\1" LERC_VERSION_MAJOR "${LERC_H}")
string(REGEX REPLACE "^.*#define[\t ]+LERC_VERSION_MINOR[\t ]+([0-9]+).*$" "\\1" LERC_VERSION_MINOR "${LERC_H}")
string(REGEX REPLACE "^.*#define[\t ]+LERC_VERSION_PATCH[\t ]+([0-9]+).*$" "\\1" LERC_VERSION_PATCH "${LERC_H}")
set(LERC_VERSION_STRING "${LERC_VERSION_MAJOR}.${LERC_VERSION_MINOR}.${LERC_VERSION_PATCH}")
unset(LERC_H)
unset(LERC_VERSION_MAJOR)
unset(LERC_VERSION_MINOR)
unset(LERC_VERSION_PATCH)
endif()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LERC
REQUIRED_VARS LERC_LIBRARY LERC_INCLUDE_DIR
@@ -80,7 +94,7 @@ if(LERC_FOUND)
if(NOT LERC_LIBRARY_RELEASE AND NOT LERC_LIBRARY_DEBUG)
set_target_properties(LERC::LERC PROPERTIES
IMPORTED_LOCATION_RELEASE "${LERC_LIBRARY}")
IMPORTED_LOCATION "${LERC_LIBRARY}")
endif()
endif()
endif()
+10 -10
View File
@@ -10,7 +10,7 @@ Find the native WebP includes and library.
IMPORTED Targets
^^^^^^^^^^^^^^^^
This module defines :prop_tgt:`IMPORTED` target ``WebP::WebP``, if
This module defines :prop_tgt:`IMPORTED` target ``WebP::webp``, if
WebP has been found.
Result Variables
@@ -64,28 +64,28 @@ if(WebP_FOUND)
set(WebP_LIBRARIES ${WebP_LIBRARY})
endif()
if(NOT TARGET WebP::WebP)
add_library(WebP::WebP UNKNOWN IMPORTED)
set_target_properties(WebP::WebP PROPERTIES
if(NOT TARGET WebP::webp)
add_library(WebP::webp UNKNOWN IMPORTED)
set_target_properties(WebP::webp PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${WebP_INCLUDE_DIRS}")
if(WebP_LIBRARY_RELEASE)
set_property(TARGET WebP::WebP APPEND PROPERTY
set_property(TARGET WebP::webp APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(WebP::WebP PROPERTIES
set_target_properties(WebP::webp PROPERTIES
IMPORTED_LOCATION_RELEASE "${WebP_LIBRARY_RELEASE}")
endif()
if(WebP_LIBRARY_DEBUG)
set_property(TARGET WebP::WebP APPEND PROPERTY
set_property(TARGET WebP::webp APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(WebP::WebP PROPERTIES
set_target_properties(WebP::webp PROPERTIES
IMPORTED_LOCATION_DEBUG "${WebP_LIBRARY_DEBUG}")
endif()
if(NOT WebP_LIBRARY_RELEASE AND NOT WebP_LIBRARY_DEBUG)
set_target_properties(WebP::WebP PROPERTIES
IMPORTED_LOCATION_RELEASE "${WebP_LIBRARY}")
set_target_properties(WebP::webp PROPERTIES
IMPORTED_LOCATION "${WebP_LIBRARY}")
endif()
endif()
endif()
+1 -1
View File
@@ -101,7 +101,7 @@ if(ZSTD_FOUND)
if(NOT ZSTD_LIBRARY_RELEASE AND NOT ZSTD_LIBRARY_DEBUG)
set_target_properties(ZSTD::ZSTD PROPERTIES
IMPORTED_LOCATION_RELEASE "${ZSTD_LIBRARY}")
IMPORTED_LOCATION "${ZSTD_LIBRARY}")
endif()
endif()
endif()
@@ -2,7 +2,7 @@
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindLibLZMA
Findliblzma
-----------
Find LZMA compression algorithm headers and library.
@@ -13,7 +13,7 @@ Imported Targets
.. versionadded:: 3.14
This module defines :prop_tgt:`IMPORTED` target ``LibLZMA::LibLZMA``, if
This module defines :prop_tgt:`IMPORTED` target ``liblzma::liblzma``, if
liblzma has been found.
Result variables
@@ -21,7 +21,7 @@ Result variables
This module will set the following variables in your project:
``LIBLZMA_FOUND``
``liblzma_FOUND``
True if liblzma headers and library were found.
``LIBLZMA_INCLUDE_DIRS``
Directory where liblzma headers are located.
@@ -70,7 +70,7 @@ endif()
if (LIBLZMA_LIBRARY)
include(CheckLibraryExists)
set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
set(CMAKE_REQUIRED_QUIET ${LibLZMA_FIND_QUIETLY})
set(CMAKE_REQUIRED_QUIET ${liblzma_FIND_QUIETLY})
if(NOT LIBLZMA_LIBRARY_RELEASE AND NOT LIBLZMA_LIBRARY_DEBUG)
set(LIBLZMA_LIBRARY_check ${LIBLZMA_LIBRARY})
elseif(LIBLZMA_LIBRARY_RELEASE)
@@ -86,7 +86,7 @@ if (LIBLZMA_LIBRARY)
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibLZMA REQUIRED_VARS LIBLZMA_LIBRARY
find_package_handle_standard_args(liblzma REQUIRED_VARS LIBLZMA_LIBRARY
LIBLZMA_INCLUDE_DIR
LIBLZMA_HAS_AUTO_DECODER
LIBLZMA_HAS_EASY_ENCODER
@@ -95,31 +95,31 @@ find_package_handle_standard_args(LibLZMA REQUIRED_VARS LIBLZMA_LIBRARY
)
mark_as_advanced( LIBLZMA_INCLUDE_DIR LIBLZMA_LIBRARY )
if (LIBLZMA_FOUND)
if (liblzma_FOUND)
set(LIBLZMA_LIBRARIES ${LIBLZMA_LIBRARY})
set(LIBLZMA_INCLUDE_DIRS ${LIBLZMA_INCLUDE_DIR})
if(NOT TARGET LibLZMA::LibLZMA)
add_library(LibLZMA::LibLZMA UNKNOWN IMPORTED)
set_target_properties(LibLZMA::LibLZMA PROPERTIES
if(NOT TARGET liblzma::liblzma)
add_library(liblzma::liblzma UNKNOWN IMPORTED)
set_target_properties(liblzma::liblzma PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${LIBLZMA_INCLUDE_DIR}
IMPORTED_LINK_INTERFACE_LANGUAGES C)
if(LIBLZMA_LIBRARY_RELEASE)
set_property(TARGET LibLZMA::LibLZMA APPEND PROPERTY
set_property(TARGET liblzma::liblzma APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(LibLZMA::LibLZMA PROPERTIES
set_target_properties(liblzma::liblzma PROPERTIES
IMPORTED_LOCATION_RELEASE "${LIBLZMA_LIBRARY_RELEASE}")
endif()
if(LIBLZMA_LIBRARY_DEBUG)
set_property(TARGET LibLZMA::LibLZMA APPEND PROPERTY
set_property(TARGET liblzma::liblzma APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(LibLZMA::LibLZMA PROPERTIES
set_target_properties(liblzma::liblzma PROPERTIES
IMPORTED_LOCATION_DEBUG "${LIBLZMA_LIBRARY_DEBUG}")
endif()
if(NOT LIBLZMA_LIBRARY_RELEASE AND NOT LIBLZMA_LIBRARY_DEBUG)
set_target_properties(LibLZMA::LibLZMA PROPERTIES
set_target_properties(liblzma::liblzma PROPERTIES
IMPORTED_LOCATION "${LIBLZMA_LIBRARY}")
endif()
endif()
+41 -13
View File
@@ -39,18 +39,46 @@ if (old-jpeg AND JPEG_SUPPORT)
set(OJPEG_SUPPORT TRUE)
endif()
# 8/12-bit jpeg mode
set(JPEG12_INCLUDE_DIR JPEG12_INCLUDE_DIR-NOTFOUND CACHE PATH "Include directory for 12-bit libjpeg")
set(JPEG12_LIBRARY JPEG12_LIBRARY-NOTFOUND CACHE FILEPATH "12-bit libjpeg library")
set(JPEG_DUAL_MODE_8_12 FALSE)
if (JPEG12_INCLUDE_DIR AND JPEG12_LIBRARY)
set(JPEG12_LIBRARIES ${JPEG12_LIBRARY})
set(JPEG12_FOUND TRUE)
else()
set(JPEG12_FOUND FALSE)
if (JPEG_SUPPORT)
# Check for jpeg12_read_scanlines() which has been added in libjpeg-turbo 2.2
# for dual 8/12 bit mode.
include(CheckCSourceCompiles)
include(CMakePushCheckState)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES "${JPEG_INCLUDE_DIRS}")
set(CMAKE_REQUIRED_LIBRARIES "${JPEG_LIBRARIES}")
check_c_source_compiles(
"
#include <stddef.h>
#include <stdio.h>
#include \"jpeglib.h\"
int main()
{
jpeg_read_scanlines(0,0,0);
jpeg12_read_scanlines(0,0,0);
return 0;
}
"
HAVE_JPEGTURBO_DUAL_MODE_8_12)
cmake_pop_check_state()
endif()
option(jpeg12 "enable libjpeg 8/12-bit dual mode (requires separate 12-bit libjpeg build)" ${JPEG12_FOUND})
if (jpeg12 AND JPEG12_FOUND)
set(JPEG_DUAL_MODE_8_12 TRUE)
set(LIBJPEG_12_PATH "${JPEG12_INCLUDE_DIR}/jpeglib.h")
if (NOT HAVE_JPEGTURBO_DUAL_MODE_8_12)
# 12-bit jpeg mode in a dedicated libjpeg12 library
set(JPEG12_INCLUDE_DIR JPEG12_INCLUDE_DIR-NOTFOUND CACHE PATH "Include directory for 12-bit libjpeg")
set(JPEG12_LIBRARY JPEG12_LIBRARY-NOTFOUND CACHE FILEPATH "12-bit libjpeg library")
set(JPEG_DUAL_MODE_8_12 FALSE)
if (JPEG12_INCLUDE_DIR AND JPEG12_LIBRARY)
set(JPEG12_LIBRARIES ${JPEG12_LIBRARY})
set(JPEG12_FOUND TRUE)
else()
set(JPEG12_FOUND FALSE)
endif()
option(jpeg12 "enable libjpeg 8/12-bit dual mode (requires separate 12-bit libjpeg build)" ${JPEG12_FOUND})
if (jpeg12 AND JPEG12_FOUND)
set(JPEG_DUAL_MODE_8_12 TRUE)
set(LIBJPEG_12_PATH "${JPEG12_INCLUDE_DIR}/jpeglib.h")
endif()
endif()
+3 -2
View File
@@ -26,8 +26,9 @@
# liblzma2
set(LZMA_SUPPORT FALSE)
find_package(LibLZMA)
option(lzma "use liblzma (required for LZMA2 compression)" ${LZMA_FOUND})
find_package(liblzma)
option(lzma "use liblzma (required for LZMA2 compression)" ${LIBLZMA_FOUND})
if (lzma AND LIBLZMA_FOUND)
set(LZMA_SUPPORT TRUE)
endif()
+2
View File
@@ -35,6 +35,8 @@ if(strip-chopping)
endif()
endif()
set(TIFF_MAX_DIR_COUNT 1048576 CACHE STRING "Maximum number of TIFF directories that libtiff can browse through")
# Defer loading of strip/tile offsets
option(defer-strile-load "enable deferred strip/tile offset/size loading (also available at runtime with the 'D' flag of TIFFOpen())" OFF)
set(DEFER_STRILE_LOAD ${defer-strile-load})
+7
View File
@@ -29,6 +29,7 @@ set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL COMPONENTS OpenGL)
find_package(GLUT)
set(OPENGL_SUPPORT FALSE)
set(HAVE_OPENGL FALSE)
if(OPENGL_FOUND AND OPENGL_GLU_FOUND AND GLUT_FOUND)
set(HAVE_OPENGL TRUE)
@@ -41,3 +42,9 @@ check_include_file(GL/glut.h HAVE_GL_GLUT_H)
check_include_file(GLUT/glut.h HAVE_GLUT_GLUT_H)
check_include_file(OpenGL/gl.h HAVE_OPENGL_GL_H)
check_include_file(OpenGL/glu.h HAVE_OPENGL_GLU_H)
option(tiff-opengl "use OpenGL (required for tiffgt viewer)" ${HAVE_OPENGL})
if (tiff-opengl AND HAVE_OPENGL)
set(OPENGL_SUPPORT TRUE)
endif()
+6 -4
View File
@@ -29,13 +29,13 @@ function(set_libs_private out_var)
foreach(lib IN LISTS ARGN)
get_filename_component(name "${lib}" NAME)
foreach(prefix IN LISTS CMAKE_FIND_LIBRARY_PREFIXES)
if(name MATCHES "^${prefix}")
if(NOT("${prefix}" STREQUAL "") AND name MATCHES "^${prefix}")
string(REGEX REPLACE "^${prefix}" "" name "${name}")
break()
endif()
endforeach()
foreach(suffix IN LISTS CMAKE_FIND_LIBRARY_SUFFIXES)
if(name MATCHES "${suffix}$")
if(NOT("${suffix}" STREQUAL "") AND name MATCHES "${suffix}$")
string(REGEX REPLACE "${suffix}$" "" name "${name}")
break()
endif()
@@ -63,5 +63,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libtiff-4.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libtiff-4.pc @ONLY)
# Install pkg-config file
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libtiff-4.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
if (tiff-install)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libtiff-4.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
-11
View File
@@ -26,17 +26,6 @@
include(TestBigEndian)
# CPU bit order
set(HOST_FILLORDER FILLORDER_MSB2LSB)
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i.*86.*" OR
CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64.*" OR
# AMD64 on Windows
CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "AMD64" OR
CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64.*")
set(HOST_FILLORDER FILLORDER_LSB2MSB)
endif()
# CPU endianness
test_big_endian(HOST_BIG_ENDIAN)
if(HOST_BIG_ENDIAN)
+22 -6
View File
@@ -22,10 +22,26 @@
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
# Add target tiff_release to update the version information in the root files
# VERSION and RELEASE-DATE.
add_custom_target(tiff_release
COMMAND ${CMAKE_COMMAND}
"-DSOURCE_DIR:PATH=${PROJECT_SOURCE_DIR}"
"-DLIBTIFF_VERSION=${PROJECT_VERSION}"
"-DLIBTIFF_BASIC_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
"-DLIBTIFF_BASIC_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
-P "${CMAKE_CURRENT_LIST_DIR}/ReleaseScript.cmake"
COMMENT "Releasing ${PROJECT_NAME} ${PROJECT_VERSION} ...")
# Version information is taken from configure.ac
# Note: Single command "cmake --build . --target tiff_release"
# does not work correctly, because version information is taken from CMakeCache.txt,
# which is not updated by cmake --build.
# Therefore, force CMake re-configure if configure.ac has changed.
# By the way, release-date and VERSION will not change but only when --targt tiff_release is called.
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/configure.ac
)
add_custom_target(release
COMMAND ${CMAKE_COMMAND}
"-DSOURCE_DIR:PATH=${PROJECT_SOURCE_DIR}"
"-DLIBTIFF_VERSION=${PROJECT_VERSION}"
-P "${CMAKE_CURRENT_LIST_DIR}/ReleaseScript.cmake"
COMMENT "Releasing ${PROJECT_NAME} ${PROJECT_VERSION}")
+13 -3
View File
@@ -22,11 +22,21 @@
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
# Update release date to current date
string(TIMESTAMP LIBTIFF_RELEASE_DATE "%Y%m%d")
# Update version information in all relevant files
message(STATUS "Setting release version to ${LIBTIFF_VERSION}")
message(STATUS "Setting release date to ${LIBTIFF_RELEASE_DATE}")
configure_file("${SOURCE_DIR}/libtiff/tiffvers.h.cmake.in"
"${SOURCE_DIR}/libtiff/tiffvers.h"
@ONLY)
# Only needed here, for manual build of target tiff_release
# because otherwise tiffvers.h is generated when building all targets.
configure_file(${LIBTIFF_BASIC_SOURCE_DIR}/libtiff/tiffvers.h.cmake.in
${LIBTIFF_BASIC_BINARY_DIR}/libtiff/tiffvers.h
@ONLY)
# Write version information and release date to root files.
FILE(WRITE ${LIBTIFF_BASIC_SOURCE_DIR}/VERSION "${LIBTIFF_VERSION}" \n)
FILE(WRITE ${LIBTIFF_BASIC_SOURCE_DIR}/RELEASE-DATE "${LIBTIFF_RELEASE_DATE}" \n)
message(STATUS "Files tiffvers.h, VERSION and RELEASE-DATE updated.")
+93
View File
@@ -0,0 +1,93 @@
# #%L
# OME Files C++ libraries (cmake build infrastructure)
# %%
# Copyright © 2015 Open Microscopy Environment:
# - Massachusetts Institute of Technology
# - National Institutes of Health
# - University of Dundee
# - Board of Regents of the University of Wisconsin-Madison
# - Glencoe Software, Inc.
# %%
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of any organization.
# #L%
find_package(Python3 COMPONENTS Interpreter)
# Sphinx documentation generator
find_program(SPHINX_BUILD sphinx-build)
if (SPHINX_BUILD)
message(STATUS "Looking for sphinx-build - ${SPHINX_BUILD}")
else()
message(STATUS "Looking for sphinx-build - not found")
endif()
set(SPHINX_DEFAULT OFF)
if(SPHINX_BUILD)
set(SPHINX_DEFAULT ON)
endif()
option(sphinx "Enable sphinx manual page and HTML documentation" ${SPHINX_DEFAULT})
option(sphinx-linkcheck "Check sphinx documentation links by default" OFF)
set(BUILD_SPHINX ${sphinx})
set(SPHINX_LIST_DIR ${CMAKE_CURRENT_LIST_DIR})
function(sphinx_manpages srcdir builddir manvar)
execute_process(COMMAND "${Python3_EXECUTABLE}" -B ${SPHINX_LIST_DIR}/list-manpages.py
"${srcdir}" "${builddir}"
RESULT_VARIABLE sphinx_man_fail
OUTPUT_VARIABLE MAN_PAGES)
if (sphinx_man_fail)
message(WARNING "Failed to get generated sphinx manual pages from ${confdir}")
endif()
string(REPLACE "\n" ";" MAN_PAGES "${MAN_PAGES}")
set(${manvar} "${MAN_PAGES}" PARENT_SCOPE)
message(STATUS "Sphinx manual pages: ${MAN_PAGES}")
endfunction(sphinx_manpages)
function(sphinx_manpage_dependencies srcdir depvar)
execute_process(COMMAND "${Python3_EXECUTABLE}" -B ${SPHINX_LIST_DIR}/list-manpage-dependencies.py
"${srcdir}"
RESULT_VARIABLE sphinx_dep_fail
OUTPUT_VARIABLE SPHINX_MAN_DEPENDENCIES)
if (sphinx_dep_fail)
message(WARNING "Failed to get Sphinx dependencies from ${confdir}")
endif()
string(REPLACE "\n" ";" SPHINX_MAN_DEPENDENCIES "${SPHINX_MAN_DEPENDENCIES}")
set(${depvar} "${SPHINX_MAN_DEPENDENCIES}" PARENT_SCOPE)
endfunction(sphinx_manpage_dependencies)
function(sphinx_dependencies srcdir depvar)
file(GLOB_RECURSE CRUDE_SPHINX_DEPENDENCIES "${srcdir}/*.rst")
foreach(file ${CRUDE_SPHINX_DEPENDENCIES})
string(FIND "${file}" "_build" FILE_MATCH)
if(FILE_MATCH EQUAL -1)
list(APPEND SPHINX_DEPENDENCIES "${file}")
endif()
endforeach()
set(${depvar} "${SPHINX_DEPENDENCIES}" PARENT_SCOPE)
endfunction(sphinx_dependencies)
+87
View File
@@ -0,0 +1,87 @@
# Check "local" sphinx links, using files in the build tree and in the
# install tree (other components)
message(STATUS "Checking internal links")
set(failed OFF)
file(STRINGS "${OUTPUT}" output)
file(REMOVE "${OUTPUT}.new")
foreach(line IN LISTS output)
# Parse the filename, link type, link and anchor from each line
string(REGEX MATCH "^.*: \\[.*\\] .*" line_match "${line}")
string(REGEX MATCH "^.*: \\[.*\\] .*#.*" anchor_match "${line}")
if(line_match)
string(REGEX REPLACE "^(.*): \\[(.*)\\] (.*)" "\\1" filename "${line}")
string(REGEX REPLACE "^(.*): \\[(.*)\\] (.*)" "\\2" type "${line}")
if(anchor_match)
string(REGEX REPLACE "^(.*): \\[(.*)\\] (.*)#(.*)" "\\3" link "${line}")
string(REGEX REPLACE "^(.*): \\[(.*)\\] (.*)#(.*)" "\\4" link "${anchor}")
else()
string(REGEX REPLACE "^(.*): \\[(.*)\\] (.*)" "\\3" link "${line}")
unset(anchor)
endif()
# Only check local links
if(type STREQUAL "local")
# Compute path relative to our install path
file(RELATIVE_PATH relpath "/" "/${SPHINX_INSTALL_PATH}/${link}")
# Check sphinx link in the install tree
unset(linkfile)
if(EXISTS "${EXTERNAL_REFERENCE}/${relpath}")
set(linkfile "${EXTERNAL_REFERENCE}/${relpath}")
endif()
# Check sphinx link in the build tree
if(EXISTS "${INTERNAL_REFERENCE}/${link}")
set(linkfile "${INTERNAL_REFERENCE}/${link}")
endif()
# Check doxygen link in the install tree
if(EXISTS "${DOXYGEN_REFERENCE}/${link}")
set(linkfile "${DOXYGEN_REFERENCE}/${link}")
endif()
# Check doxygen link in the build tree
if(DOXYGEN_REFERENCE AND DOXYGEN_INSTALL_PATH)
string(REGEX REPLACE "^${DOXYGEN_INSTALL_PATH}/(.*)" "\\1" doxygen_path "${relpath}")
if(EXISTS "${DOXYGEN_REFERENCE}/${doxygen_path}")
set(linkfile "${DOXYGEN_REFERENCE}/${doxygen_path}")
endif()
endif()
# Check link and any anchor. If the link does not exist, or the
# anchor does not exist, set the link type to broken when
# rewriting the output file with our test results.
if(linkfile)
if(anchor)
file(STRINGS "${linkfile}" anchor_matches REGEX "<a +class=\"anchor\" +id=\"${anchor}\"")
if(anchor_matches)
file(APPEND "${OUTPUT}.new" "${filename}: [${type}] ${link}#${anchor}\n")
else()
set(failed ON)
file(APPEND "${OUTPUT}.new" "${filename}: [broken] ${link}#${anchor}\n")
message(STATUS "Broken link: ${filename}: ${link}#${anchor}")
endif()
else()
file(APPEND "${OUTPUT}.new" "${filename}: [${type}] ${link}\n")
endif()
else()
set(failed ON)
file(APPEND "${OUTPUT}.new" "${filename}: [broken] ${link}\n")
message(STATUS "Broken link: ${filename}: ${link}")
endif()
else()
if(type STREQUAL "broken")
set(failed ON)
message(STATUS "Broken link: ${filename}: ${link}")
endif()
file(APPEND "${OUTPUT}.new" "${filename}: [${type}] ${link}\n")
endif()
else()
file(APPEND "${OUTPUT}.new" "${line}\n")
endif()
endforeach()
file(RENAME "${OUTPUT}.new" "${OUTPUT}")
if(failed)
message(FATAL_ERROR "Broken links detected")
endif()
+27
View File
@@ -0,0 +1,27 @@
if(NOT "@BUILD_SHARED_LIBS@")
# TODO: import dependencies
endif()
function(set_variable_from_rel_or_absolute_path var root rel_or_abs_path)
if(IS_ABSOLUTE "${rel_or_abs_path}")
set(${var} "${rel_or_abs_path}" PARENT_SCOPE)
else()
set(${var} "${root}/${rel_or_abs_path}" PARENT_SCOPE)
endif()
endfunction()
# Tell the user project where to find our headers and libraries
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
get_filename_component(_ROOT "${_DIR}/@PROJECT_ROOT_DIR@" ABSOLUTE)
# Use _ROOT as prefix here for the possibility of relocation after installation.
set_variable_from_rel_or_absolute_path("TIFF_INCLUDE_DIR" "${_ROOT}" "@CMAKE_INSTALL_INCLUDEDIR@")
set(TIFF_INCLUDE_DIRS ${TIFF_INCLUDE_DIR})
set(TIFF_LIBRARIES TIFF::tiff)
if(NOT TARGET TIFF::tiff)
include("${CMAKE_CURRENT_LIST_DIR}/TiffTargets.cmake")
endif()
unset (_ROOT)
unset (_DIR)
+9 -5
View File
@@ -23,13 +23,17 @@
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
# Debug postfix
if(MSVC)
# Debug postfix
set(CMAKE_DEBUG_POSTFIX "d")
# disable deprecation warnings
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
# suppress deprecation warning for MSVC POSIX names
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
# disable deprecation warnings
add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
# suppress deprecation warning for MSVC POSIX names
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
# Don't warn about use of deprecated functions
add_compile_options(/wd4996)
endif()
# Win32 file I/O
+18 -7
View File
@@ -31,13 +31,24 @@ set(ZSTD_USABLE FALSE)
find_package(ZSTD)
if(ZSTD_FOUND)
set(CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES})
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${ZSTD_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${ZSTD_LIBRARIES})
check_symbol_exists(ZSTD_decompressStream "zstd.h" ZSTD_RECENT_ENOUGH)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
if(TARGET zstd::libzstd_shared)
add_library(ZSTD::ZSTD ALIAS zstd::libzstd_shared)
set(ZSTD_HAVE_DECOMPRESS_STREAM ON)
elseif(TARGET zstd::libzstd_static)
add_library(ZSTD::ZSTD ALIAS zstd::libzstd_static)
set(ZSTD_HAVE_DECOMPRESS_STREAM ON)
endif()
if(NOT DEFINED ZSTD_HAVE_DECOMPRESS_STREAM)
set(CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES})
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${ZSTD_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${ZSTD_LIBRARIES})
check_symbol_exists(ZSTD_decompressStream "zstd.h" ZSTD_HAVE_DECOMPRESS_STREAM)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
endif()
set(ZSTD_RECENT_ENOUGH ${ZSTD_HAVE_DECOMPRESS_STREAM})
if (ZSTD_RECENT_ENOUGH)
set(ZSTD_USABLE TRUE)
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env python
# Find manual page dependencies
# argv1 = doc dir containing conf.py
import importlib.util
import os.path
import pathlib
import sys
if __name__ == "__main__":
if len(sys.argv) != 2:
sys.exit("Usage: %s sphinx-srcdir" % (sys.argv[0]))
conf_dir = os.path.abspath(sys.argv[1])
conf_path = os.path.join(conf_dir, 'conf.py')
spec = importlib.util.spec_from_file_location('conf', conf_path)
conf = importlib.util.module_from_spec(spec)
spec.loader.exec_module(conf)
if hasattr(conf, 'man_pages'):
for man in conf.man_pages:
man_path = os.path.join(sys.argv[1], "{}{}".format(man[0], '.rst'))
man_path_posix = pathlib.PureWindowsPath(man_path).as_posix()
print(man_path_posix)
print(pathlib.PureWindowsPath(conf_path).as_posix())
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env python
# Find manual pages to be generated
# argv1 = doc dir containing conf.py
# argv2 = manpage directory to contain generated manpages
import importlib.util
import os.path
import pathlib
import sys
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: {} sphinx-srcdir sphinx-builddir".format(sys.argv[0]), file=sys.stderr)
sys.exit(2)
conf_dir = os.path.abspath(sys.argv[1])
conf_path = os.path.join(conf_dir, 'conf.py')
spec = importlib.util.spec_from_file_location('conf', conf_path)
conf = importlib.util.module_from_spec(spec)
spec.loader.exec_module(conf)
if hasattr(conf, 'man_pages'):
for man in conf.man_pages:
man_path = os.path.join(sys.argv[2], "%s.%s" % (man[1], man[4]))
man_path_posix = pathlib.PureWindowsPath(man_path).as_posix()
print(man_path_posix)
else:
print("No man_pages array in {}".format(conf_path), file=sys.stderr)
sys.exit(3)
+185 -67
View File
@@ -25,7 +25,7 @@ dnl OF THIS SOFTWARE.
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.64)
AC_INIT([LibTIFF Software],[4.4.0],[tiff@lists.maptools.org],[tiff])
AC_INIT([LibTIFF Software],[4.7.0],[tiff@lists.osgeo.org],[tiff])
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_MACRO_DIR(m4)
AC_LANG(C)
@@ -40,12 +40,13 @@ AM_MAINTAINER_MODE
dnl Versioning.
dnl Don't fill the ALPHA_VERSION field, if not applicable.
LIBTIFF_MAJOR_VERSION=4
LIBTIFF_MINOR_VERSION=4
LIBTIFF_MINOR_VERSION=7
LIBTIFF_MICRO_VERSION=0
LIBTIFF_ALPHA_VERSION=
LIBTIFF_VERSION=$LIBTIFF_MAJOR_VERSION.$LIBTIFF_MINOR_VERSION.$LIBTIFF_MICRO_VERSION$LIBTIFF_ALPHA_VERSION
dnl This will be used with the 'make release' target
LIBTIFF_RELEASE_DATE=`date +"%Y%m%d"`
dnl This (LIBTIFF_RELEASE_DATE) is used to set the #define TIFFLIB_VERSION in tiffvers.h.
LIBTIFF_RELEASE_DATE=$(cat ${srcdir}/RELEASE-DATE)
dnl Libtool library revision control info
dnl See the libtool documentation under the heading "Libtool's versioning
@@ -76,9 +77,9 @@ dnl 5. If any interfaces have been added since the last public release, then
dnl increment age.
dnl 6. If any interfaces have been removed since the last public release,
dnl then set age to 0.
LIBTIFF_CURRENT=13
LIBTIFF_CURRENT=7
LIBTIFF_REVISION=0
LIBTIFF_AGE=8
LIBTIFF_AGE=1
LIBTIFF_VERSION_INFO=$LIBTIFF_CURRENT:$LIBTIFF_REVISION:$LIBTIFF_AGE
# This is a special hack for OpenBSD and MirOS systems. The dynamic linker
@@ -121,9 +122,9 @@ AC_PATH_PROG(CMAKE, cmake)
# constrained to compilers using GNU ld on ELF systems or systems
# which provide an adequate emulation thereof.
AC_ARG_ENABLE([ld-version-script],
AS_HELP_STRING([--enable-ld-version-script],
[enable linker version script (default is disabled)]),
[have_ld_version_script=$enableval], [have_ld_version_script=no])
AS_HELP_STRING([--disable-ld-version-script],
[disable linker version script (default is enabled if supported)]),
[have_ld_version_script=$enableval], [have_ld_version_script=yes])
if test "$have_ld_version_script" != no; then
AC_MSG_CHECKING([if LD -Wl,--version-script works])
save_LDFLAGS="$LDFLAGS"
@@ -163,6 +164,13 @@ AC_SUBST(tiff_libs_private)
tiff_requires_private=
AC_SUBST(tiff_requires_private)
AM_CONDITIONAL(BUILD_STATIC, test "$enable_static" = "yes")
dnl Avoid -Werror to interfere with feature detection
SAVED_CFLAGS="$CFLAGS"
CFLAGS=$(echo "$CFLAGS " | sed "s/-Werror //")
dnl We don't need to add math library to all targets
case "${host_os}" in
cygwin* | mingw32* | beos* | darwin*)
@@ -195,11 +203,18 @@ dnl Check if optarg (and presumably related externs) already declared in headers
AC_CHECK_DECLS([optarg])
dnl ---------------------------------------------------------------------------
dnl Deprecated features and backward compatibilty
dnl Deprecated features and backward compatibility
dnl ---------------------------------------------------------------------------
# Disable deprecated features to ensure clean build
CPPFLAGS="-DTIFF_DISABLE_DEPRECATED $CPPFLAGS"
AC_ARG_ENABLE([deprecated],
AS_HELP_STRING([--enable-deprecated],
[enable deprecated features (default is disabled)]),
[enable_deprecated=$enableval], [enable_deprecated=no])
if test "$enable_deprecated" = "yes"; then
# Disable deprecated features to ensure clean build
CPPFLAGS="-DTIFF_DISABLE_DEPRECATED $CPPFLAGS"
fi
dnl ---------------------------------------------------------------------------
dnl Compute sized types for current CPU and compiler options
@@ -245,22 +260,6 @@ AC_CHECK_FUNCS([mmap setmode])
dnl Will use local replacements for unavailable functions
AC_REPLACE_FUNCS(getopt)
dnl ---------------------------------------------------------------------------
dnl Check the native cpu bit order.
dnl ---------------------------------------------------------------------------
AC_MSG_CHECKING([native cpu bit order])
case "$host_cpu" in
i*86*|x86_64*)
HOST_FILLORDER=FILLORDER_LSB2MSB
AC_MSG_RESULT([lsb2msb])
;;
*)
HOST_FILLORDER=FILLORDER_MSB2LSB
AC_MSG_RESULT([msb2lsb])
;;
esac
AC_DEFINE_UNQUOTED(HOST_FILLORDER, $HOST_FILLORDER, [Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB)])
dnl ---------------------------------------------------------------------------
dnl Configure legacy tifconf.h HOST_BIGENDIAN.
dnl ---------------------------------------------------------------------------
@@ -316,6 +315,34 @@ fi
AC_SUBST(LIBTIFF_DOCDIR)
dnl ---------------------------------------------------------------------------
dnl Enable or disable parts of the build
dnl ---------------------------------------------------------------------------
AC_ARG_ENABLE(tools,
AS_HELP_STRING([--disable-tools],
[Disable building of tools]),
[TIFF_TOOLS=$enableval], [TIFF_TOOLS=yes])
AM_CONDITIONAL(TIFF_TOOLS, test "$TIFF_TOOLS" = "yes")
AC_ARG_ENABLE(tests,
AS_HELP_STRING([--disable-tests],
[Disable building of tests]),
[TIFF_TESTS=$enableval], [TIFF_TESTS=yes])
AM_CONDITIONAL(TIFF_TESTS, test "$TIFF_TESTS" = "yes")
AC_ARG_ENABLE(contrib,
AS_HELP_STRING([--disable-contrib],
[Disable building of contrib]),
[TIFF_CONTRIB=$enableval], [TIFF_CONTRIB=yes])
AM_CONDITIONAL(TIFF_CONTRIB, test "$TIFF_CONTRIB" = "yes")
AC_ARG_ENABLE(docs,
AS_HELP_STRING([--disable-docs],
[Disable building of docs]),
[TIFF_DOCS=$enableval], [TIFF_DOCS=yes])
AM_CONDITIONAL(TIFF_DOCS, test "$TIFF_DOCS" = "yes")
dnl ---------------------------------------------------------------------------
dnl Switch on/off internal codecs.
@@ -435,6 +462,7 @@ if test "$HAVE_ZLIB" = "yes" ; then
AC_DEFINE(ZIP_SUPPORT,1,[Support Deflate compression])
LIBS="-lz $LIBS"
tiff_libs_private="-lz ${tiff_libs_private}"
tiff_requires_private="zlib ${tiff_requires_private}"
if test "$HAVE_RPATH" = "yes" -a "x$with_zlib_lib_dir" != "x" ; then
LIBDIR="-R $with_zlib_lib_dir $LIBDIR"
@@ -492,6 +520,7 @@ if test "$HAVE_LIBDEFLATE" = "yes" ; then
AC_DEFINE(LIBDEFLATE_SUPPORT,1,[Support libdeflate enhanced compression])
LIBS="-ldeflate $LIBS"
tiff_libs_private="-ldeflate ${tiff_libs_private}"
tiff_requires_private="libdeflate ${tiff_requires_private}"
if test "$HAVE_RPATH" = "yes" -a "x$with_libdeflate_lib_dir" != "x" ; then
LIBDIR="-R $with_libdeflate_lib_dir $LIBDIR"
@@ -520,6 +549,7 @@ dnl Check for JPEG.
dnl ---------------------------------------------------------------------------
HAVE_JPEG=no
HAVE_JPEGTURBO_DUAL_MODE_8_12=no
AC_ARG_ENABLE(jpeg,
AS_HELP_STRING([--disable-jpeg],
@@ -552,6 +582,9 @@ if test "x$enable_jpeg" != "xno" ; then
fi
if test "$jpeg_lib" = "yes" -a "$jpeg_h" = "yes" ; then
dnl Check for jpeg12_read_scanlines which has been added in libjpeg-turbo 3.0
dnl for dual 8/12 bit mode.
AC_CHECK_LIB(jpeg, jpeg12_read_scanlines, [HAVE_JPEGTURBO_DUAL_MODE_8_12=yes], [HAVE_JPEGTURBO_DUAL_MODE_8_12=no],)
HAVE_JPEG=yes
fi
@@ -561,14 +594,19 @@ if test "$HAVE_JPEG" = "yes" ; then
AC_DEFINE(JPEG_SUPPORT,1,[Support JPEG compression (requires IJG JPEG library)])
LIBS="-ljpeg $LIBS"
tiff_libs_private="-ljpeg ${tiff_libs_private}"
tiff_requires_private="libjpeg ${tiff_requires_private}"
if test "$HAVE_RPATH" = "yes" -a "x$with_jpeg_lib_dir" != "x" ; then
LIBDIR="-R $with_jpeg_lib_dir $LIBDIR"
fi
if test "$HAVE_JPEGTURBO_DUAL_MODE_8_12" = "yes"; then
AC_DEFINE(HAVE_JPEGTURBO_DUAL_MODE_8_12,1,[libjpeg-turbo >= 3.0 dual mode enabled])
fi
fi
AM_CONDITIONAL(HAVE_JPEG, test "$HAVE_JPEG" = 'yes')
AM_CONDITIONAL(HAVE_JPEGTURBO_DUAL_MODE_8_12, test "$HAVE_JPEGTURBO_DUAL_MODE_8_12" = 'yes')
dnl ---------------------------------------------------------------------------
dnl Check for Old JPEG.
@@ -702,6 +740,7 @@ if test "$HAVE_LERC" = "yes" ; then
AC_DEFINE(LERC_SUPPORT,1,[Support lerc compression])
LIBS="-l${lerc_lib_name} $LIBS"
tiff_libs_private="-l${lerc_lib_name} ${tiff_libs_private}"
tiff_requires_private="Lerc ${tiff_requires_private}"
if test "$HAVE_RPATH" = "yes" -a "x$with_lerc_lib_dir" != "x" ; then
LIBDIR="-R $with_lerc_lib_dir $LIBDIR"
@@ -756,6 +795,7 @@ if test "$HAVE_LZMA" = "yes" ; then
AC_DEFINE(LZMA_SUPPORT,1,[Support LZMA2 compression])
LIBS="-llzma $LIBS"
tiff_libs_private="-llzma ${tiff_libs_private}"
tiff_requires_private="liblzma ${tiff_requires_private}"
if test "$HAVE_RPATH" = "yes" -a "x$with_lzma_lib_dir" != "x" ; then
LIBDIR="-R $with_lzma_lib_dir $LIBDIR"
@@ -810,6 +850,7 @@ if test "$HAVE_ZSTD" = "yes" ; then
AC_DEFINE(ZSTD_SUPPORT,1,[Support zstd compression])
LIBS="-lzstd $LIBS"
tiff_libs_private="-lzstd ${tiff_libs_private}"
tiff_requires_private="libzstd ${tiff_requires_private}"
if test "$HAVE_RPATH" = "yes" -a "x$with_zstd_lib_dir" != "x" ; then
LIBDIR="-R $with_zstd_lib_dir $LIBDIR"
@@ -864,6 +905,7 @@ if test "$HAVE_WEBP" = "yes" ; then
AC_DEFINE(WEBP_SUPPORT,1,[Support webp compression])
LIBS="-lwebp $LIBS"
tiff_libs_private="-lwebp ${tiff_libs_private}"
tiff_requires_private="libwebp ${tiff_requires_private}"
if test "$HAVE_RPATH" = "yes" -a "x$with_webp_lib_dir" != "x" ; then
LIBDIR="-R $with_webp_lib_dir $LIBDIR"
@@ -875,35 +917,38 @@ AM_CONDITIONAL(HAVE_WEBP, test "$HAVE_WEBP" = 'yes')
dnl ---------------------------------------------------------------------------
dnl Should 8/12 bit jpeg mode be enabled?
dnl This should not be used starting with libjpeg-turbo >= 3.0 that has
dnl built-in support for dual mode.
dnl ---------------------------------------------------------------------------
HAVE_JPEG12=no
if test "$HAVE_JPEGTURBO_DUAL_MODE_8_12" = "no"; then
HAVE_JPEG12=no
AC_ARG_ENABLE(jpeg12,
AS_HELP_STRING([--enable-jpeg12],
[enable libjpeg 8/12bit dual mode]),,)
AC_ARG_WITH(jpeg12-include-dir,
AS_HELP_STRING([--with-jpeg12-include-dir=DIR],
[location of libjpeg 12bit headers]),,)
AC_ARG_WITH(jpeg12-lib,
AS_HELP_STRING([--with-jpeg12-lib=LIBRARY],
[path to libjpeg 12bit library]),,)
AC_ARG_ENABLE(jpeg12,
AS_HELP_STRING([--enable-jpeg12],
[enable libjpeg 8/12bit dual mode (not to be used with libjpeg-turbo >= 3.0)]),,)
AC_ARG_WITH(jpeg12-include-dir,
AS_HELP_STRING([--with-jpeg12-include-dir=DIR],
[location of libjpeg 12bit headers]),,)
AC_ARG_WITH(jpeg12-lib,
AS_HELP_STRING([--with-jpeg12-lib=LIBRARY],
[path to libjpeg 12bit library]),,)
if test "x$enable_jpeg12" = "xyes" ; then
if test "x$enable_jpeg12" = "xyes" ; then
if test "x$with_jpeg12_lib" != "x" ; then
LIBS="$with_jpeg12_lib $LIBS"
fi
HAVE_JPEG12=yes
if test "x$with_jpeg12_lib" != "x" ; then
LIBS="$with_jpeg12_lib $LIBS"
fi
HAVE_JPEG12=yes
AC_DEFINE(JPEG_DUAL_MODE_8_12,1,[8/12 bit libjpeg dual mode enabled])
if test "x$with_jpeg12_include_dir" != "x" ; then
AC_DEFINE_UNQUOTED(LIBJPEG_12_PATH,"$with_jpeg12_include_dir/jpeglib.h",[12bit libjpeg primary include file with path])
fi
AC_DEFINE(JPEG_DUAL_MODE_8_12,1,[8/12 bit libjpeg dual mode enabled])
if test "x$with_jpeg12_include_dir" != "x" ; then
AC_DEFINE_UNQUOTED(LIBJPEG_12_PATH,"$with_jpeg12_include_dir/jpeglib.h",[12bit libjpeg primary include file with path])
fi
fi
fi
dnl ---------------------------------------------------------------------------
dnl Check for C++.
dnl ---------------------------------------------------------------------------
@@ -927,36 +972,42 @@ dnl ---------------------------------------------------------------------------
HAVE_OPENGL=no
AC_ARG_ENABLE(opengl,
AS_HELP_STRING([--disable-opengl],
[disable OpenGL usage (required by tiffgt, enabled by default)]),,)
AC_PATH_XTRA
if test "x$enable_opengl" != "xno" ; then
dnl AX_CHECK_GL sets GL_CFLAGS & GL_LIBS. Also PTHREAD_LIBS,
dnl PTHREAD_CFLAGS, & PTHREAD_CC as a side-effect
AX_CHECK_GL
AC_PATH_XTRA
dnl AX_CHECK_GLU sets GLU_CFLAGS & GLU_LIBS
AX_CHECK_GLU
dnl AX_CHECK_GL sets GL_CFLAGS & GL_LIBS. Also PTHREAD_LIBS,
dnl PTHREAD_CFLAGS, & PTHREAD_CC as a side-effect
AX_CHECK_GL
dnl AX_CHECK_GLUT sets GLUT_CFLAGS & GLUT_LIBS
AX_CHECK_GLUT
dnl AX_CHECK_GLU sets GLU_CFLAGS & GLU_LIBS
AX_CHECK_GLU
if test "$no_x" != "yes" -a "$no_gl" != "yes" \
-a "$no_glu" != "yes" -a "$no_glut" != "yes" ; then
HAVE_OPENGL=yes
dnl AX_CHECK_GLUT sets GLUT_CFLAGS & GLUT_LIBS
AX_CHECK_GLUT
if test "$no_x" != "yes" -a "$no_gl" != "yes" \
-a "$no_glu" != "yes" -a "$no_glut" != "yes" ; then
HAVE_OPENGL=yes
fi
fi
AM_CONDITIONAL(HAVE_OPENGL, test "$HAVE_OPENGL" = "yes")
dnl ---------------------------------------------------------------------------
dnl Check for Win32 IO: make sure we have windows.h but not cygwin
dnl this must be after the ogl test, since that looks for windows.h and we
dnl test it
dnl ---------------------------------------------------------------------------
AC_ARG_ENABLE(win32-io,
AS_HELP_STRING([--disable-win32-io],
[disable Win32 I/O (Windows only, enabled by default except for Cygwin)]),,)
AC_CHECK_HEADER(windows.h)
win32_io_ok=no
case "${host_os}" in
cygwin*)
@@ -1020,6 +1071,20 @@ if test "$HAVE_STRIPCHOP" = "yes" \
fi
dnl ---------------------------------------------------------------------------
dnl Maximum number of TIFF directories that libtiff can browse through
dnl ---------------------------------------------------------------------------
AC_ARG_WITH(max-dir-count,
AS_HELP_STRING([--with-max-dir-count=SIZE],
[Maximum number of TIFF directories that libtiff can browse through [[default=1048576]]]),,)
if test "x$with_max_dir_count" = "x" -o "x$with_max_dir_count" = "xyes"; then
with_max_dir_count="1048576"
fi
AC_DEFINE_UNQUOTED(TIFF_MAX_DIR_COUNT,$with_max_dir_count,[Maximum number of TIFF directories that libtiff can browse through])
dnl ---------------------------------------------------------------------------
dnl Should we try to defer loading of strip/tile offsets and sizes to
dnl optimize directory scanning?
@@ -1087,8 +1152,50 @@ if test "$CHECK_JPEG_YCBCR_SUBSAMPLING" = "yes" ; then
[Pick up YCbCr subsampling info from the JPEG data stream to support files lacking the tag (default enabled).])
fi
for python in python3.16 python3.15 python3.14 python3.13 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python3.1 python3.0 python3 python; do
AC_CHECK_PROGS(PYTHON_BIN, [$python])
if test "x$PYTHON_BIN" != "x"; then
break
fi
done
AC_ARG_ENABLE(sphinx,
AS_HELP_STRING([--disable-sphinx],
[disable building of the sphinx documentation]),
[BUILD_SPHINX=$enableval],
[BUILD_SPHINX=yes])
AC_PATH_PROG(SPHINX_BUILD, [sphinx-build], [no])
AM_CONDITIONAL([SPHINX], [test "$BUILD_SPHINX" = yes -a "$SPHINX_BUILD" != no -a "x$PYTHON_BIN" != "x"])
if test "x$PYTHON_BIN" != "x"; then
AC_MSG_CHECKING([generated manual pages])
TIFF_MAN1_GEN=$(echo $("$PYTHON_BIN" "${srcdir}/cmake/list-manpages.py" "${srcdir}/doc" man | grep "\.1$"))
TIFF_MAN3_GEN=$(echo $("$PYTHON_BIN" "${srcdir}/cmake/list-manpages.py" "${srcdir}/doc" man | grep "\.3tiff$"))
TIFF_MAN_RULES=$("$PYTHON_BIN" "${srcdir}/cmake/list-manpages.py" "${srcdir}/doc" man | sed -e 's;$;: all-local;')
AC_SUBST([TIFF_MAN1_GEN])
AC_SUBST([TIFF_MAN3_GEN])
AC_SUBST([TIFF_MAN_RULES])
AM_SUBST_NOTMAKE([TIFF_MAN_RULES])
AC_MSG_RESULT([done])
fi
if test -d "${srcdir}/doc/man-prebuilt"; then
AC_MSG_CHECKING([prebuilt manual pages])
TIFF_MAN1_PREBUILT=$(echo $(cd "${srcdir}/doc" && ls -1 man-prebuilt/*.1))
TIFF_MAN3_PREBUILT=$(echo $(cd "${srcdir}/doc" && ls -1 man-prebuilt/*.3tiff))
AC_SUBST([TIFF_MAN1_PREBUILT])
AC_SUBST([TIFF_MAN3_PREBUILT])
AC_MSG_RESULT([done])
fi
dnl ---------------------------------------------------------------------------
CFLAGS="$SAVED_CFLAGS"
AC_SUBST(LIBDIR)
AC_CONFIG_HEADERS([config/config.h libtiff/tif_config.h libtiff/tiffconf.h port/libport_config.h])
@@ -1106,12 +1213,10 @@ AC_CONFIG_FILES([Makefile \
contrib/stream/Makefile \
contrib/tags/Makefile \
contrib/win_dib/Makefile \
html/Makefile \
html/images/Makefile \
html/man/Makefile \
doc/Makefile \
libtiff-4.pc \
libtiff/Makefile \
man/Makefile \
libtiff/tiffvers.h \
port/Makefile \
test/Makefile \
tools/Makefile])
@@ -1124,10 +1229,19 @@ dnl ---------------------------------------------------------------------------
LOC_MSG()
LOC_MSG([Libtiff is now configured for ${host}])
LOC_MSG()
LOC_MSG([ Libtiff build version: ${LIBTIFF_VERSION}])
LOC_MSG([ Libtiff library version: ${LIBTIFF_VERSION_INFO}])
LOC_MSG([ Libtiff release date: ${LIBTIFF_RELEASE_DATE}])
LOC_MSG()
LOC_MSG([ Installation directory: ${prefix}])
LOC_MSG([ Documentation directory: ${LIBTIFF_DOCDIR}])
LOC_MSG([ C compiler: ${CC} ${CFLAGS}])
LOC_MSG([ C++ compiler: ${CXX} ${CXXFLAGS}])
LOC_MSG([ Build tools: ${TIFF_TOOLS}])
LOC_MSG([ Build tests: ${TIFF_TESTS}])
LOC_MSG([ Build contrib: ${TIFF_CONTRIB}])
LOC_MSG([ Build docs: ${TIFF_DOCS}])
LOC_MSG([ Build deprecated features: ${enable_deprecated}])
LOC_MSG([ Enable runtime linker paths: ${HAVE_RPATH}])
LOC_MSG([ Enable linker symbol versioning: ${have_ld_version_script}])
LOC_MSG([ Support Microsoft Document Imaging: ${HAVE_MDI}])
@@ -1147,7 +1261,11 @@ LOC_MSG([ libdeflate support: ${HAVE_LIBDEFLATE}])
LOC_MSG([ Pixar log-format algorithm: ${HAVE_PIXARLOG}])
LOC_MSG([ JPEG support: ${HAVE_JPEG}])
LOC_MSG([ Old JPEG support: ${HAVE_OJPEG}])
LOC_MSG([ JPEG 8/12 bit dual mode: ${HAVE_JPEG12}])
if test "$HAVE_JPEGTURBO_DUAL_MODE_8_12" = "yes"; then
LOC_MSG([ JPEG 8/12 bit dual mode: ${HAVE_JPEGTURBO_DUAL_MODE_8_12} (libjpeg turbo >= 2.2 dual mode)])
else
LOC_MSG([ JPEG 8/12 bit dual mode: ${HAVE_JPEG12}])
fi
LOC_MSG([ ISO JBIG support: ${HAVE_JBIG}])
LOC_MSG([ LERC support: ${HAVE_LERC}])
LOC_MSG([ LZMA2 support: ${HAVE_LZMA}])
+1 -1
View File
@@ -23,7 +23,7 @@
# OF THIS SOFTWARE.
add_executable(addtiffo addtiffo.c tif_overview.c tif_ovrcache.c tif_ovrcache.h)
target_link_libraries(addtiffo tiff port)
target_link_libraries(addtiffo tiff tiff_port)
if(WEBP_SUPPORT AND EMSCRIPTEN)
# Emscripten is pretty finnicky about linker flags.
+2
View File
@@ -29,7 +29,9 @@ EXTRA_DIST = \
CMakeLists.txt \
README
if TIFF_CONTRIB
noinst_PROGRAMS = addtiffo
endif
addtiffo_SOURCES = addtiffo.c tif_overview.c tif_ovrcache.c tif_ovrcache.h
addtiffo_LDADD = $(LIBTIFF)
+51 -56
View File
@@ -59,49 +59,50 @@
* New
*/
#include "tiffio.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tiffio.h"
void TIFFBuildOverviews( TIFF *, int, int *, int, const char *,
int (*)(double,void*), void * );
void TIFFBuildOverviews(TIFF *, int, int *, int, const char *,
int (*)(double, void *), void *);
/************************************************************************/
/* main() */
/************************************************************************/
int main( int argc, char ** argv )
int main(int argc, char **argv)
{
int anOverviews[100]; /* TODO: un-hardwire array length, flexible allocate */
int nOverviewCount = 0;
int bUseSubIFD = 0;
TIFF *hTIFF;
const char *pszResampling = "nearest";
int anOverviews[100]; /* TODO: un-hardwire array length, flexible allocate
*/
int nOverviewCount = 0;
int bUseSubIFD = 0;
TIFF *hTIFF;
const char *pszResampling = "nearest";
/* -------------------------------------------------------------------- */
/* Usage: */
/* -------------------------------------------------------------------- */
if( argc < 2 )
/* -------------------------------------------------------------------- */
/* Usage: */
/* -------------------------------------------------------------------- */
if (argc < 2)
{
printf( "Usage: addtiffo [-r {nearest,average,mode}]\n"
" tiff_filename [resolution_reductions]\n"
"\n"
"Example:\n"
" %% addtiffo abc.tif 2 4 8 16\n" );
return( 1 );
printf("Usage: addtiffo [-r {nearest,average,mode}]\n"
" tiff_filename [resolution_reductions]\n"
"\n"
"Example:\n"
" %% addtiffo abc.tif 2 4 8 16\n");
return (1);
}
while( argv[1][0] == '-' )
while (argv[1][0] == '-')
{
if( strcmp(argv[1],"-subifd") == 0 )
if (strcmp(argv[1], "-subifd") == 0)
{
bUseSubIFD = 1;
argv++;
argc--;
}
else if( strcmp(argv[1],"-r") == 0 )
else if (strcmp(argv[1], "-r") == 0)
{
argv += 2;
argc -= 2;
@@ -109,34 +110,35 @@ int main( int argc, char ** argv )
}
else
{
fprintf( stderr, "Incorrect parameters\n" );
return( 1 );
fprintf(stderr, "Incorrect parameters\n");
return (1);
}
}
/* TODO: resampling mode parameter needs to be encoded in an integer from this point on */
/* TODO: resampling mode parameter needs to be encoded in an integer from
* this point on */
/* -------------------------------------------------------------------- */
/* Collect the user requested reduction factors. */
/* -------------------------------------------------------------------- */
while( nOverviewCount < argc - 2 && nOverviewCount < 100 )
/* -------------------------------------------------------------------- */
/* Collect the user requested reduction factors. */
/* -------------------------------------------------------------------- */
while (nOverviewCount < argc - 2 && nOverviewCount < 100)
{
anOverviews[nOverviewCount] = atoi(argv[nOverviewCount+2]);
if( (anOverviews[nOverviewCount] <= 0) ||
anOverviews[nOverviewCount] = atoi(argv[nOverviewCount + 2]);
if ((anOverviews[nOverviewCount] <= 0) ||
((anOverviews[nOverviewCount] > 1024)))
{
fprintf( stderr, "Incorrect parameters\n" );
return(1);
fprintf(stderr, "Incorrect parameters\n");
return (1);
}
nOverviewCount++;
}
/* -------------------------------------------------------------------- */
/* Default to four overview levels. It would be nicer if it */
/* defaulted based on the size of the source image. */
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* Default to four overview levels. It would be nicer if it */
/* defaulted based on the size of the source image. */
/* -------------------------------------------------------------------- */
/* TODO: make it default based on the size of the source image */
if( nOverviewCount == 0 )
if (nOverviewCount == 0)
{
nOverviewCount = 4;
@@ -146,20 +148,20 @@ int main( int argc, char ** argv )
anOverviews[3] = 16;
}
/* -------------------------------------------------------------------- */
/* Build the overview. */
/* -------------------------------------------------------------------- */
hTIFF = TIFFOpen( argv[1], "r+" );
if( hTIFF == NULL )
/* -------------------------------------------------------------------- */
/* Build the overview. */
/* -------------------------------------------------------------------- */
hTIFF = TIFFOpen(argv[1], "r+");
if (hTIFF == NULL)
{
fprintf( stderr, "TIFFOpen(%s) failed.\n", argv[1] );
return( 1 );
fprintf(stderr, "TIFFOpen(%s) failed.\n", argv[1]);
return (1);
}
TIFFBuildOverviews( hTIFF, nOverviewCount, anOverviews, bUseSubIFD,
pszResampling, NULL, NULL );
TIFFBuildOverviews(hTIFF, nOverviewCount, anOverviews, bUseSubIFD,
pszResampling, NULL, NULL);
TIFFClose( hTIFF );
TIFFClose(hTIFF);
/* -------------------------------------------------------------------- */
/* Optionally test for memory leaks. */
@@ -168,12 +170,5 @@ int main( int argc, char ** argv )
malloc_dump(1);
#endif
return( 0 );
return (0);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
File diff suppressed because it is too large Load Diff
+199 -189
View File
@@ -1,7 +1,7 @@
/******************************************************************************
* Project: TIFF Overview Builder
* Purpose: Library functions to maintain two rows of tiles or two strips
* of data for output overviews as an output cache.
* of data for output overviews as an output cache.
* Author: Frank Warmerdam, warmerdam@pobox.com
*
******************************************************************************
@@ -27,8 +27,8 @@
******************************************************************************
*/
#include "tiffiop.h"
#include "tif_ovrcache.h"
#include "tiffiop.h"
#include <assert.h>
/************************************************************************/
@@ -38,89 +38,95 @@
/* existing TIFF directory. */
/************************************************************************/
TIFFOvrCache *TIFFCreateOvrCache( TIFF *hTIFF, toff_t nDirOffset )
TIFFOvrCache *TIFFCreateOvrCache(TIFF *hTIFF, toff_t nDirOffset)
{
TIFFOvrCache *psCache;
toff_t nBaseDirOffset;
TIFFOvrCache *psCache;
toff_t nBaseDirOffset;
int nRet;
psCache = (TIFFOvrCache *) _TIFFmalloc(sizeof(TIFFOvrCache));
psCache = (TIFFOvrCache *)_TIFFmalloc(sizeof(TIFFOvrCache));
psCache->nDirOffset = nDirOffset;
psCache->hTIFF = hTIFF;
/* -------------------------------------------------------------------- */
/* Get definition of this raster from the TIFF file itself. */
/* -------------------------------------------------------------------- */
nBaseDirOffset = TIFFCurrentDirOffset( psCache->hTIFF );
TIFFSetSubDirectory( hTIFF, nDirOffset );
TIFFGetField( hTIFF, TIFFTAG_IMAGEWIDTH, &(psCache->nXSize) );
TIFFGetField( hTIFF, TIFFTAG_IMAGELENGTH, &(psCache->nYSize) );
TIFFGetField( hTIFF, TIFFTAG_BITSPERSAMPLE, &(psCache->nBitsPerPixel) );
TIFFGetField( hTIFF, TIFFTAG_SAMPLESPERPIXEL, &(psCache->nSamples) );
TIFFGetField( hTIFF, TIFFTAG_PLANARCONFIG, &(psCache->nPlanarConfig) );
/* -------------------------------------------------------------------- */
/* Get definition of this raster from the TIFF file itself. */
/* -------------------------------------------------------------------- */
nBaseDirOffset = TIFFCurrentDirOffset(psCache->hTIFF);
nRet = TIFFSetSubDirectory(hTIFF, nDirOffset);
(void)nRet;
assert(nRet == 1);
if( !TIFFIsTiled( hTIFF ) )
TIFFGetField(hTIFF, TIFFTAG_IMAGEWIDTH, &(psCache->nXSize));
TIFFGetField(hTIFF, TIFFTAG_IMAGELENGTH, &(psCache->nYSize));
TIFFGetField(hTIFF, TIFFTAG_BITSPERSAMPLE, &(psCache->nBitsPerPixel));
TIFFGetField(hTIFF, TIFFTAG_SAMPLESPERPIXEL, &(psCache->nSamples));
TIFFGetField(hTIFF, TIFFTAG_PLANARCONFIG, &(psCache->nPlanarConfig));
if (!TIFFIsTiled(hTIFF))
{
TIFFGetField( hTIFF, TIFFTAG_ROWSPERSTRIP, &(psCache->nBlockYSize) );
TIFFGetField(hTIFF, TIFFTAG_ROWSPERSTRIP, &(psCache->nBlockYSize));
psCache->nBlockXSize = psCache->nXSize;
psCache->nBytesPerBlock = TIFFStripSize(hTIFF);
psCache->bTiled = FALSE;
}
else
{
TIFFGetField( hTIFF, TIFFTAG_TILEWIDTH, &(psCache->nBlockXSize) );
TIFFGetField( hTIFF, TIFFTAG_TILELENGTH, &(psCache->nBlockYSize) );
TIFFGetField(hTIFF, TIFFTAG_TILEWIDTH, &(psCache->nBlockXSize));
TIFFGetField(hTIFF, TIFFTAG_TILELENGTH, &(psCache->nBlockYSize));
psCache->nBytesPerBlock = TIFFTileSize(hTIFF);
psCache->bTiled = TRUE;
}
/* -------------------------------------------------------------------- */
/* Compute some values from this. */
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* Compute some values from this. */
/* -------------------------------------------------------------------- */
psCache->nBlocksPerRow = (psCache->nXSize + psCache->nBlockXSize - 1)
/ psCache->nBlockXSize;
psCache->nBlocksPerColumn = (psCache->nYSize + psCache->nBlockYSize - 1)
/ psCache->nBlockYSize;
psCache->nBlocksPerRow =
(psCache->nXSize + psCache->nBlockXSize - 1) / psCache->nBlockXSize;
psCache->nBlocksPerColumn =
(psCache->nYSize + psCache->nBlockYSize - 1) / psCache->nBlockYSize;
if (psCache->nPlanarConfig == PLANARCONFIG_SEPARATE)
psCache->nBytesPerRow = psCache->nBytesPerBlock
* psCache->nBlocksPerRow * psCache->nSamples;
psCache->nBytesPerRow = psCache->nBytesPerBlock *
psCache->nBlocksPerRow * psCache->nSamples;
else
psCache->nBytesPerRow =
psCache->nBytesPerBlock * psCache->nBlocksPerRow;
/* -------------------------------------------------------------------- */
/* Allocate and initialize the data buffers. */
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* Allocate and initialize the data buffers. */
/* -------------------------------------------------------------------- */
psCache->pabyRow1Blocks =
(unsigned char *) _TIFFmalloc(psCache->nBytesPerRow);
(unsigned char *)_TIFFmalloc(psCache->nBytesPerRow);
psCache->pabyRow2Blocks =
(unsigned char *) _TIFFmalloc(psCache->nBytesPerRow);
(unsigned char *)_TIFFmalloc(psCache->nBytesPerRow);
if ( psCache->pabyRow1Blocks == NULL
|| psCache->pabyRow2Blocks == NULL )
if (psCache->pabyRow1Blocks == NULL || psCache->pabyRow2Blocks == NULL)
{
TIFFErrorExt( hTIFF->tif_clientdata, hTIFF->tif_name,
"Can't allocate memory for overview cache." );
/* TODO: use of TIFFError is inconsistent with use of fprintf in addtiffo.c, sort out */
if (psCache->pabyRow1Blocks) _TIFFfree(psCache->pabyRow1Blocks);
if (psCache->pabyRow2Blocks) _TIFFfree(psCache->pabyRow2Blocks);
_TIFFfree( psCache );
TIFFErrorExt(hTIFF->tif_clientdata, hTIFF->tif_name,
"Can't allocate memory for overview cache.");
/* TODO: use of TIFFError is inconsistent with use of fprintf in
* addtiffo.c, sort out */
if (psCache->pabyRow1Blocks)
_TIFFfree(psCache->pabyRow1Blocks);
if (psCache->pabyRow2Blocks)
_TIFFfree(psCache->pabyRow2Blocks);
_TIFFfree(psCache);
return NULL;
}
_TIFFmemset( psCache->pabyRow1Blocks, 0, psCache->nBytesPerRow );
_TIFFmemset( psCache->pabyRow2Blocks, 0, psCache->nBytesPerRow );
_TIFFmemset(psCache->pabyRow1Blocks, 0, psCache->nBytesPerRow);
_TIFFmemset(psCache->pabyRow2Blocks, 0, psCache->nBytesPerRow);
psCache->nBlockOffset = 0;
TIFFSetSubDirectory( psCache->hTIFF, nBaseDirOffset );
nRet = TIFFSetSubDirectory(psCache->hTIFF, nBaseDirOffset);
(void)nRet;
assert(nRet == 1);
return psCache;
}
@@ -132,130 +138,140 @@ TIFFOvrCache *TIFFCreateOvrCache( TIFF *hTIFF, toff_t nDirOffset )
/* down by one block. */
/************************************************************************/
static void TIFFWriteOvrRow( TIFFOvrCache * psCache )
static void TIFFWriteOvrRow(TIFFOvrCache *psCache)
{
int nRet, iTileX, iTileY = psCache->nBlockOffset;
int nRet, iTileX, iTileY = psCache->nBlockOffset;
unsigned char *pabyData;
toff_t nBaseDirOffset;
uint32_t RowsInStrip;
toff_t nBaseDirOffset;
uint32_t RowsInStrip;
/* -------------------------------------------------------------------- */
/* If the output cache is multi-byte per sample, and the file */
/* being written to is of a different byte order than the current */
/* platform, we will need to byte swap the data. */
/* -------------------------------------------------------------------- */
if( TIFFIsByteSwapped(psCache->hTIFF) )
/* -------------------------------------------------------------------- */
/* If the output cache is multi-byte per sample, and the file */
/* being written to is of a different byte order than the current */
/* platform, we will need to byte swap the data. */
/* -------------------------------------------------------------------- */
if (TIFFIsByteSwapped(psCache->hTIFF))
{
if( psCache->nBitsPerPixel == 16 )
TIFFSwabArrayOfShort( (uint16_t *) psCache->pabyRow1Blocks,
(psCache->nBytesPerBlock * psCache->nSamples) / 2 );
if (psCache->nBitsPerPixel == 16)
TIFFSwabArrayOfShort((uint16_t *)psCache->pabyRow1Blocks,
(psCache->nBytesPerBlock * psCache->nSamples) /
2);
else if( psCache->nBitsPerPixel == 32 )
TIFFSwabArrayOfLong( (uint32_t *) psCache->pabyRow1Blocks,
(psCache->nBytesPerBlock * psCache->nSamples) / 4 );
else if (psCache->nBitsPerPixel == 32)
TIFFSwabArrayOfLong((uint32_t *)psCache->pabyRow1Blocks,
(psCache->nBytesPerBlock * psCache->nSamples) /
4);
else if( psCache->nBitsPerPixel == 64 )
TIFFSwabArrayOfDouble( (double *) psCache->pabyRow1Blocks,
(psCache->nBytesPerBlock * psCache->nSamples) / 8 );
else if (psCache->nBitsPerPixel == 64)
TIFFSwabArrayOfDouble(
(double *)psCache->pabyRow1Blocks,
(psCache->nBytesPerBlock * psCache->nSamples) / 8);
}
/* -------------------------------------------------------------------- */
/* Record original directory position, so we can restore it at */
/* end. */
/* -------------------------------------------------------------------- */
nBaseDirOffset = TIFFCurrentDirOffset( psCache->hTIFF );
nRet = TIFFSetSubDirectory( psCache->hTIFF, psCache->nDirOffset );
(void) nRet;
assert( nRet == 1 );
/* -------------------------------------------------------------------- */
/* Record original directory position, so we can restore it at */
/* end. */
/* -------------------------------------------------------------------- */
nBaseDirOffset = TIFFCurrentDirOffset(psCache->hTIFF);
nRet = TIFFSetSubDirectory(psCache->hTIFF, psCache->nDirOffset);
(void)nRet;
assert(nRet == 1);
/* -------------------------------------------------------------------- */
/* Write blocks to TIFF file. */
/* -------------------------------------------------------------------- */
for( iTileX = 0; iTileX < psCache->nBlocksPerRow; iTileX++ )
{
int nTileID;
/* -------------------------------------------------------------------- */
/* Write blocks to TIFF file. */
/* -------------------------------------------------------------------- */
for (iTileX = 0; iTileX < psCache->nBlocksPerRow; iTileX++)
{
int nTileID;
if (psCache->nPlanarConfig == PLANARCONFIG_SEPARATE)
{
int iSample;
if (psCache->nPlanarConfig == PLANARCONFIG_SEPARATE)
{
int iSample;
for( iSample = 0; iSample < psCache->nSamples; iSample++ )
{
pabyData = TIFFGetOvrBlock( psCache, iTileX, iTileY, iSample );
for (iSample = 0; iSample < psCache->nSamples; iSample++)
{
pabyData = TIFFGetOvrBlock(psCache, iTileX, iTileY, iSample);
if( psCache->bTiled )
{
nTileID = TIFFComputeTile( psCache->hTIFF,
iTileX * psCache->nBlockXSize,
iTileY * psCache->nBlockYSize,
0, (tsample_t) iSample );
TIFFWriteEncodedTile( psCache->hTIFF, nTileID,
pabyData,
TIFFTileSize(psCache->hTIFF) );
}
else
{
nTileID = TIFFComputeStrip( psCache->hTIFF,
iTileY * psCache->nBlockYSize,
(tsample_t) iSample );
RowsInStrip=psCache->nBlockYSize;
if ((iTileY+1)*psCache->nBlockYSize>psCache->nYSize)
RowsInStrip=psCache->nYSize-iTileY*psCache->nBlockYSize;
TIFFWriteEncodedStrip( psCache->hTIFF, nTileID,
pabyData,
TIFFVStripSize(psCache->hTIFF,RowsInStrip) );
}
}
if (psCache->bTiled)
{
nTileID = TIFFComputeTile(
psCache->hTIFF, iTileX * psCache->nBlockXSize,
iTileY * psCache->nBlockYSize, 0, (tsample_t)iSample);
if (TIFFWriteEncodedTile(psCache->hTIFF, nTileID, pabyData,
TIFFTileSize(psCache->hTIFF)) < 0)
{
fprintf(stderr, "TIFFWriteEncodedTile() failed\n");
}
}
else
{
nTileID = TIFFComputeStrip(psCache->hTIFF,
iTileY * psCache->nBlockYSize,
(tsample_t)iSample);
RowsInStrip = psCache->nBlockYSize;
if ((iTileY + 1) * psCache->nBlockYSize > psCache->nYSize)
RowsInStrip =
psCache->nYSize - iTileY * psCache->nBlockYSize;
if (TIFFWriteEncodedStrip(
psCache->hTIFF, nTileID, pabyData,
TIFFVStripSize(psCache->hTIFF, RowsInStrip)) < 0)
{
fprintf(stderr, "TIFFWriteEncodedStrip() failed\n");
}
}
}
}
else
{
pabyData = TIFFGetOvrBlock(psCache, iTileX, iTileY, 0);
}
else
{
pabyData = TIFFGetOvrBlock( psCache, iTileX, iTileY, 0 );
if (psCache->bTiled)
{
nTileID = TIFFComputeTile(psCache->hTIFF,
iTileX * psCache->nBlockXSize,
iTileY * psCache->nBlockYSize, 0, 0);
if (TIFFWriteEncodedTile(psCache->hTIFF, nTileID, pabyData,
TIFFTileSize(psCache->hTIFF)) < 0)
{
fprintf(stderr, "TIFFWriteEncodedTile() failed\n");
}
}
else
{
nTileID = TIFFComputeStrip(psCache->hTIFF,
iTileY * psCache->nBlockYSize, 0);
RowsInStrip = psCache->nBlockYSize;
if ((iTileY + 1) * psCache->nBlockYSize > psCache->nYSize)
RowsInStrip =
psCache->nYSize - iTileY * psCache->nBlockYSize;
if (TIFFWriteEncodedStrip(
psCache->hTIFF, nTileID, pabyData,
TIFFVStripSize(psCache->hTIFF, RowsInStrip)) < 0)
{
fprintf(stderr, "TIFFWriteEncodedStrip() failed\n");
}
}
}
}
if( psCache->bTiled )
{
nTileID = TIFFComputeTile( psCache->hTIFF,
iTileX * psCache->nBlockXSize,
iTileY * psCache->nBlockYSize,
0, 0 );
TIFFWriteEncodedTile( psCache->hTIFF, nTileID,
pabyData,
TIFFTileSize(psCache->hTIFF) );
}
else
{
nTileID = TIFFComputeStrip( psCache->hTIFF,
iTileY * psCache->nBlockYSize,
0 );
RowsInStrip=psCache->nBlockYSize;
if ((iTileY+1)*psCache->nBlockYSize>psCache->nYSize)
RowsInStrip=psCache->nYSize-iTileY*psCache->nBlockYSize;
TIFFWriteEncodedStrip( psCache->hTIFF, nTileID,
pabyData,
TIFFVStripSize(psCache->hTIFF,RowsInStrip) );
}
}
}
/* TODO: add checks on error status return of TIFFWriteEncodedTile and TIFFWriteEncodedStrip */
/* -------------------------------------------------------------------- */
/* Rotate buffers. */
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* Rotate buffers. */
/* -------------------------------------------------------------------- */
pabyData = psCache->pabyRow1Blocks;
psCache->pabyRow1Blocks = psCache->pabyRow2Blocks;
psCache->pabyRow2Blocks = pabyData;
_TIFFmemset( pabyData, 0, psCache->nBytesPerRow );
_TIFFmemset(pabyData, 0, psCache->nBytesPerRow);
psCache->nBlockOffset++;
/* -------------------------------------------------------------------- */
/* Restore access to original directory. */
/* -------------------------------------------------------------------- */
TIFFFlush( psCache->hTIFF );
/* -------------------------------------------------------------------- */
/* Restore access to original directory. */
/* -------------------------------------------------------------------- */
TIFFFlush(psCache->hTIFF);
/* TODO: add checks on error status return of TIFFFlush */
TIFFSetSubDirectory( psCache->hTIFF, nBaseDirOffset );
TIFFSetSubDirectory(psCache->hTIFF, nBaseDirOffset);
/* TODO: add checks on error status return of TIFFSetSubDirectory */
}
@@ -264,30 +280,31 @@ static void TIFFWriteOvrRow( TIFFOvrCache * psCache )
/************************************************************************/
/* TODO: make TIFF_Downsample handle iSample offset, so that we can
* do with a single TIFFGetOvrBlock and no longer need TIFFGetOvrBlock_Subsampled */
unsigned char *TIFFGetOvrBlock( TIFFOvrCache *psCache, int iTileX, int iTileY,
int iSample )
* do with a single TIFFGetOvrBlock and no longer need
* TIFFGetOvrBlock_Subsampled */
unsigned char *TIFFGetOvrBlock(TIFFOvrCache *psCache, int iTileX, int iTileY,
int iSample)
{
long nRowOffset;
long nRowOffset;
if ( iTileY > psCache->nBlockOffset + 1 )
TIFFWriteOvrRow( psCache );
if (iTileY > psCache->nBlockOffset + 1)
TIFFWriteOvrRow(psCache);
assert( iTileX >= 0 && iTileX < psCache->nBlocksPerRow );
assert( iTileY >= 0 && iTileY < psCache->nBlocksPerColumn );
assert( iTileY >= psCache->nBlockOffset
&& iTileY < psCache->nBlockOffset+2 );
assert( iSample >= 0 && iSample < psCache->nSamples );
assert(iTileX >= 0 && iTileX < psCache->nBlocksPerRow);
assert(iTileY >= 0 && iTileY < psCache->nBlocksPerColumn);
assert(iTileY >= psCache->nBlockOffset &&
iTileY < psCache->nBlockOffset + 2);
assert(iSample >= 0 && iSample < psCache->nSamples);
if (psCache->nPlanarConfig == PLANARCONFIG_SEPARATE)
nRowOffset = ((((toff_t) iTileX * psCache->nSamples) + iSample)
* psCache->nBytesPerBlock);
nRowOffset = ((((toff_t)iTileX * psCache->nSamples) + iSample) *
psCache->nBytesPerBlock);
else
nRowOffset = iTileX * psCache->nBytesPerBlock +
(psCache->nBitsPerPixel + 7) / 8 * iSample;
(psCache->nBitsPerPixel + 7) / 8 * iSample;
if ( iTileY == psCache->nBlockOffset )
if (iTileY == psCache->nBlockOffset)
return psCache->pabyRow1Blocks + nRowOffset;
else
return psCache->pabyRow2Blocks + nRowOffset;
@@ -297,24 +314,24 @@ unsigned char *TIFFGetOvrBlock( TIFFOvrCache *psCache, int iTileX, int iTileY,
/* TIFFGetOvrBlock_Subsampled() */
/************************************************************************/
unsigned char *TIFFGetOvrBlock_Subsampled( TIFFOvrCache *psCache,
int iTileX, int iTileY )
unsigned char *TIFFGetOvrBlock_Subsampled(TIFFOvrCache *psCache, int iTileX,
int iTileY)
{
int nRowOffset;
int nRowOffset;
if( iTileY > psCache->nBlockOffset + 1 )
TIFFWriteOvrRow( psCache );
if (iTileY > psCache->nBlockOffset + 1)
TIFFWriteOvrRow(psCache);
assert( iTileX >= 0 && iTileX < psCache->nBlocksPerRow );
assert( iTileY >= 0 && iTileY < psCache->nBlocksPerColumn );
assert( iTileY >= psCache->nBlockOffset
&& iTileY < psCache->nBlockOffset+2 );
assert( psCache->nPlanarConfig != PLANARCONFIG_SEPARATE );
assert(iTileX >= 0 && iTileX < psCache->nBlocksPerRow);
assert(iTileY >= 0 && iTileY < psCache->nBlocksPerColumn);
assert(iTileY >= psCache->nBlockOffset &&
iTileY < psCache->nBlockOffset + 2);
assert(psCache->nPlanarConfig != PLANARCONFIG_SEPARATE);
nRowOffset = iTileX * psCache->nBytesPerBlock;
if( iTileY == psCache->nBlockOffset )
if (iTileY == psCache->nBlockOffset)
return psCache->pabyRow1Blocks + nRowOffset;
else
return psCache->pabyRow2Blocks + nRowOffset;
@@ -324,20 +341,13 @@ unsigned char *TIFFGetOvrBlock_Subsampled( TIFFOvrCache *psCache,
/* TIFFDestroyOvrCache() */
/************************************************************************/
void TIFFDestroyOvrCache( TIFFOvrCache * psCache )
void TIFFDestroyOvrCache(TIFFOvrCache *psCache)
{
while( psCache->nBlockOffset < psCache->nBlocksPerColumn )
TIFFWriteOvrRow( psCache );
while (psCache->nBlockOffset < psCache->nBlocksPerColumn)
TIFFWriteOvrRow(psCache);
_TIFFfree( psCache->pabyRow1Blocks );
_TIFFfree( psCache->pabyRow2Blocks );
_TIFFfree( psCache );
_TIFFfree(psCache->pabyRow1Blocks);
_TIFFfree(psCache->pabyRow2Blocks);
_TIFFfree(psCache);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
+41 -49
View File
@@ -3,11 +3,11 @@
*
* Project: TIFF Overview Builder
* Purpose: Library functions to maintain two rows of tiles or two strips
* of data for output overviews as an output cache.
* of data for output overviews as an output cache.
* Author: Frank Warmerdam, warmerdam@pobox.com
*
* This code could potentially be used by other applications wanting to
* manage a once-through write cache.
* manage a once-through write cache.
*
******************************************************************************
* Copyright (c) 2000, Frank Warmerdam
@@ -38,66 +38,58 @@
#include "tiffio.h"
#if defined(__cplusplus)
extern "C" {
#endif
typedef struct
extern "C"
{
uint32_t nXSize;
uint32_t nYSize;
#endif
uint16_t nBitsPerPixel;
uint16_t nSamples;
uint16_t nPlanarConfig;
uint32_t nBlockXSize;
uint32_t nBlockYSize;
toff_t nBytesPerBlock;
toff_t nBytesPerRow;
typedef struct
{
uint32_t nXSize;
uint32_t nYSize;
int nBlocksPerRow;
int nBlocksPerColumn;
uint16_t nBitsPerPixel;
uint16_t nSamples;
uint16_t nPlanarConfig;
uint32_t nBlockXSize;
uint32_t nBlockYSize;
toff_t nBytesPerBlock;
toff_t nBytesPerRow;
int nBlockOffset; /* what block is the first in papabyBlocks? */
unsigned char *pabyRow1Blocks;
unsigned char *pabyRow2Blocks;
int nBlocksPerRow;
int nBlocksPerColumn;
toff_t nDirOffset;
TIFF *hTIFF;
int bTiled;
} TIFFOvrCache;
int nBlockOffset; /* what block is the first in papabyBlocks? */
unsigned char *pabyRow1Blocks;
unsigned char *pabyRow2Blocks;
TIFFOvrCache *TIFFCreateOvrCache( TIFF *hTIFF, toff_t nDirOffset );
unsigned char *TIFFGetOvrBlock( TIFFOvrCache *psCache, int iTileX, int iTileY,
int iSample );
unsigned char *TIFFGetOvrBlock_Subsampled( TIFFOvrCache *psCache, int iTileX, int iTileY );
void TIFFDestroyOvrCache( TIFFOvrCache * );
toff_t nDirOffset;
TIFF *hTIFF;
int bTiled;
void TIFFBuildOverviews( TIFF *, int, int *, int, const char *,
int (*)(double,void*), void * );
} TIFFOvrCache;
void TIFF_ProcessFullResBlock( TIFF *, int, int, int, int, int, int *, int,
int, TIFFOvrCache **, uint32_t, uint32_t,
unsigned char *, uint32_t, uint32_t,
int, const char * );
TIFFOvrCache *TIFFCreateOvrCache(TIFF *hTIFF, toff_t nDirOffset);
unsigned char *TIFFGetOvrBlock(TIFFOvrCache *psCache, int iTileX,
int iTileY, int iSample);
unsigned char *TIFFGetOvrBlock_Subsampled(TIFFOvrCache *psCache, int iTileX,
int iTileY);
void TIFFDestroyOvrCache(TIFFOvrCache *);
uint32_t TIFF_WriteOverview( TIFF *, uint32_t, uint32_t, int, int, int, int, int,
int, int, int, int, unsigned short *,
unsigned short *, unsigned short *, int,
int, int);
void TIFFBuildOverviews(TIFF *, int, int *, int, const char *,
int (*)(double, void *), void *);
void TIFF_ProcessFullResBlock(TIFF *, int, int, int, int, int, int *, int,
int, TIFFOvrCache **, uint32_t, uint32_t,
unsigned char *, uint32_t, uint32_t, int,
const char *);
uint32_t TIFF_WriteOverview(TIFF *, uint32_t, uint32_t, int, int, int, int,
int, int, int, int, int, unsigned short *,
unsigned short *, unsigned short *, int, int,
int);
#if defined(__cplusplus)
}
#endif
#endif /* ndef TIF_OVRCACHE_H_INCLUDED */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
#endif /* ndef TIF_OVRCACHE_H_INCLUDED */
+4 -4
View File
@@ -23,16 +23,16 @@
# OF THIS SOFTWARE.
add_executable(tiff-bi tiff-bi.c)
target_link_libraries(tiff-bi tiff port)
target_link_libraries(tiff-bi tiff tiff_port)
add_executable(tiff-grayscale tiff-grayscale.c)
target_link_libraries(tiff-grayscale tiff port CMath::CMath)
target_link_libraries(tiff-grayscale tiff tiff_port CMath::CMath)
add_executable(tiff-palette tiff-palette.c)
target_link_libraries(tiff-palette tiff port)
target_link_libraries(tiff-palette tiff tiff_port)
add_executable(tiff-rgb tiff-rgb.c)
target_link_libraries(tiff-rgb tiff port CMath::CMath)
target_link_libraries(tiff-rgb tiff tiff_port CMath::CMath)
if(WEBP_SUPPORT AND EMSCRIPTEN)
# Emscripten is pretty finnicky about linker flags.
+2
View File
@@ -31,7 +31,9 @@ EXTRA_DIST = \
CMakeLists.txt \
README
if TIFF_CONTRIB
noinst_PROGRAMS = tiff-bi tiff-grayscale tiff-palette tiff-rgb
endif
tiff_bi_SOURCES = tiff-bi.c
tiff_bi_LDADD = $(LIBTIFF)
+10 -15
View File
@@ -27,21 +27,23 @@
#include "tiffio.h"
#define WIDTH 512
#define HEIGHT WIDTH
#define WIDTH 512
#define HEIGHT WIDTH
int main(int argc, char **argv)
{
int i;
unsigned char * scan_line;
TIFF * tif;
int i;
unsigned char *scan_line;
TIFF *tif;
if (argc != 2) {
if (argc != 2)
{
fprintf(stderr, "Usage: %s tiff-image\n", argv[0]);
return 0;
}
if ((tif = TIFFOpen(argv[1], "w")) == NULL) {
if ((tif = TIFFOpen(argv[1], "w")) == NULL)
{
fprintf(stderr, "can't open %s as a TIFF file\n", argv[1]);
return 0;
}
@@ -56,7 +58,7 @@ int main(int argc, char **argv)
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE);
scan_line = (unsigned char *) malloc(WIDTH / 8);
scan_line = (unsigned char *)malloc(WIDTH / 8);
for (i = 0; i < (WIDTH / 8) / 2; i++)
scan_line[i] = 0;
@@ -80,10 +82,3 @@ int main(int argc, char **argv)
TIFFClose(tif);
return 0;
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+41 -44
View File
@@ -30,20 +30,20 @@
#include "tiffio.h"
#define WIDTH 512
#define HEIGHT WIDTH
#define WIDTH 512
#define HEIGHT WIDTH
char * programName;
void Usage();
char *programName;
void Usage();
int main(int argc, char **argv)
{
int bits_per_pixel = 8, cmsize, i, j, k,
gray_index, chunk_size = 32, nchunks = 16;
unsigned char * scan_line;
uint16_t * gray;
float refblackwhite[2*1];
TIFF * tif;
int bits_per_pixel = 8, cmsize, i, j, k, gray_index, chunk_size = 32,
nchunks = 16;
unsigned char *scan_line;
uint16_t *gray;
float refblackwhite[2 * 1];
TIFF *tif;
programName = argv[0];
@@ -51,11 +51,12 @@ int main(int argc, char **argv)
Usage();
if (!strcmp(argv[1], "-depth"))
bits_per_pixel = atoi(argv[2]);
bits_per_pixel = atoi(argv[2]);
else
Usage();
Usage();
switch (bits_per_pixel) {
switch (bits_per_pixel)
{
case 8:
nchunks = 16;
chunk_size = 32;
@@ -73,18 +74,19 @@ int main(int argc, char **argv)
}
cmsize = nchunks * nchunks;
gray = (uint16_t *) malloc(cmsize * sizeof(uint16_t));
gray = (uint16_t *)malloc(cmsize * sizeof(uint16_t));
gray[0] = 3000;
for (i = 1; i < cmsize; i++)
gray[i] = (uint16_t) (-log10((double) i / (cmsize - 1)) * 1000);
gray[i] = (uint16_t)(-log10((double)i / (cmsize - 1)) * 1000);
refblackwhite[0] = 0.0;
refblackwhite[1] = (float)((1L<<bits_per_pixel) - 1);
refblackwhite[1] = (float)((1L << bits_per_pixel) - 1);
if ((tif = TIFFOpen(argv[3], "w")) == NULL) {
if ((tif = TIFFOpen(argv[3], "w")) == NULL)
{
fprintf(stderr, "can't open %s as a TIFF file\n", argv[3]);
free(gray);
free(gray);
return 0;
}
@@ -100,26 +102,29 @@ int main(int argc, char **argv)
TIFFSetField(tif, TIFFTAG_TRANSFERFUNCTION, gray);
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE);
scan_line = (unsigned char *) malloc(WIDTH / (8 / bits_per_pixel));
scan_line = (unsigned char *)malloc(WIDTH / (8 / bits_per_pixel));
for (i = 0; i < HEIGHT; i++) {
for (j = 0, k = 0; j < WIDTH;) {
for (i = 0; i < HEIGHT; i++)
{
for (j = 0, k = 0; j < WIDTH;)
{
gray_index = (j / chunk_size) + ((i / chunk_size) * nchunks);
switch (bits_per_pixel) {
case 8:
scan_line[k++] = gray_index;
j++;
break;
case 4:
scan_line[k++] = (gray_index << 4) + gray_index;
j += 2;
break;
case 2:
scan_line[k++] = (gray_index << 6) + (gray_index << 4)
+ (gray_index << 2) + gray_index;
j += 4;
break;
switch (bits_per_pixel)
{
case 8:
scan_line[k++] = gray_index;
j++;
break;
case 4:
scan_line[k++] = (gray_index << 4) + gray_index;
j += 2;
break;
case 2:
scan_line[k++] = (gray_index << 6) + (gray_index << 4) +
(gray_index << 2) + gray_index;
j += 4;
break;
}
}
TIFFWriteScanline(tif, scan_line, i, 0);
@@ -130,16 +135,8 @@ int main(int argc, char **argv)
return 0;
}
void
Usage()
void Usage()
{
fprintf(stderr, "Usage: %s -depth (8 | 4 | 2) tiff-image\n", programName);
exit(0);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+180 -175
View File
@@ -28,20 +28,20 @@
#include "tiffio.h"
#define WIDTH 512
#define HEIGHT WIDTH
#define SCALE(x) ((x) * 257L)
#define WIDTH 512
#define HEIGHT WIDTH
#define SCALE(x) ((x)*257L)
char * programName;
void Usage();
char *programName;
void Usage();
int main(int argc, char **argv)
{
int bits_per_pixel = 8, cmsize, i, j, k,
cmap_index, chunk_size = 32, nchunks = 16;
unsigned char * scan_line;
uint16_t *red, *green, *blue;
TIFF * tif;
int bits_per_pixel = 8, cmsize, i, j, k, cmap_index, chunk_size = 32,
nchunks = 16;
unsigned char *scan_line;
uint16_t *red, *green, *blue;
TIFF *tif;
programName = argv[0];
@@ -49,11 +49,12 @@ int main(int argc, char **argv)
Usage();
if (!strcmp(argv[1], "-depth"))
bits_per_pixel = atoi(argv[2]);
bits_per_pixel = atoi(argv[2]);
else
Usage();
Usage();
switch (bits_per_pixel) {
switch (bits_per_pixel)
{
case 8:
nchunks = 16;
chunk_size = 32;
@@ -66,158 +67,166 @@ int main(int argc, char **argv)
nchunks = 2;
chunk_size = 256;
break;
case 1:
nchunks = 2;
chunk_size = 256;
break;
case 1:
nchunks = 2;
chunk_size = 256;
break;
default:
Usage();
}
if (bits_per_pixel != 1) {
cmsize = nchunks * nchunks;
} else {
cmsize = 2;
if (bits_per_pixel != 1)
{
cmsize = nchunks * nchunks;
}
red = (uint16_t *) malloc(cmsize * sizeof(uint16_t));
green = (uint16_t *) malloc(cmsize * sizeof(uint16_t));
blue = (uint16_t *) malloc(cmsize * sizeof(uint16_t));
else
{
cmsize = 2;
}
red = (uint16_t *)malloc(cmsize * sizeof(uint16_t));
green = (uint16_t *)malloc(cmsize * sizeof(uint16_t));
blue = (uint16_t *)malloc(cmsize * sizeof(uint16_t));
switch (bits_per_pixel) {
case 8:
for (i = 0; i < cmsize; i++) {
if (i < 32)
red[i] = 0;
else if (i < 64)
red[i] = SCALE(36);
else if (i < 96)
red[i] = SCALE(73);
else if (i < 128)
red[i] = SCALE(109);
else if (i < 160)
red[i] = SCALE(146);
else if (i < 192)
red[i] = SCALE(182);
else if (i < 224)
red[i] = SCALE(219);
else if (i < 256)
red[i] = SCALE(255);
switch (bits_per_pixel)
{
case 8:
for (i = 0; i < cmsize; i++)
{
if (i < 32)
red[i] = 0;
else if (i < 64)
red[i] = SCALE(36);
else if (i < 96)
red[i] = SCALE(73);
else if (i < 128)
red[i] = SCALE(109);
else if (i < 160)
red[i] = SCALE(146);
else if (i < 192)
red[i] = SCALE(182);
else if (i < 224)
red[i] = SCALE(219);
else if (i < 256)
red[i] = SCALE(255);
if ((i % 32) < 4)
green[i] = 0;
else if (i < 8)
green[i] = SCALE(36);
else if ((i % 32) < 12)
green[i] = SCALE(73);
else if ((i % 32) < 16)
green[i] = SCALE(109);
else if ((i % 32) < 20)
green[i] = SCALE(146);
else if ((i % 32) < 24)
green[i] = SCALE(182);
else if ((i % 32) < 28)
green[i] = SCALE(219);
else if ((i % 32) < 32)
green[i] = SCALE(255);
if ((i % 32) < 4)
green[i] = 0;
else if (i < 8)
green[i] = SCALE(36);
else if ((i % 32) < 12)
green[i] = SCALE(73);
else if ((i % 32) < 16)
green[i] = SCALE(109);
else if ((i % 32) < 20)
green[i] = SCALE(146);
else if ((i % 32) < 24)
green[i] = SCALE(182);
else if ((i % 32) < 28)
green[i] = SCALE(219);
else if ((i % 32) < 32)
green[i] = SCALE(255);
if ((i % 4) == 0)
blue[i] = SCALE(0);
else if ((i % 4) == 1)
blue[i] = SCALE(85);
else if ((i % 4) == 2)
blue[i] = SCALE(170);
else if ((i % 4) == 3)
blue[i] = SCALE(255);
}
break;
case 4:
red[0] = SCALE(255);
green[0] = 0;
blue[0] = 0;
if ((i % 4) == 0)
blue[i] = SCALE(0);
else if ((i % 4) == 1)
blue[i] = SCALE(85);
else if ((i % 4) == 2)
blue[i] = SCALE(170);
else if ((i % 4) == 3)
blue[i] = SCALE(255);
}
break;
case 4:
red[0] = SCALE(255);
green[0] = 0;
blue[0] = 0;
red[1] = 0;
green[1] = SCALE(255);
blue[1] = 0;
red[1] = 0;
green[1] = SCALE(255);
blue[1] = 0;
red[2] = 0;
green[2] = 0;
blue[2] = SCALE(255);
red[2] = 0;
green[2] = 0;
blue[2] = SCALE(255);
red[3] = SCALE(255);
green[3] = SCALE(255);
blue[3] = SCALE(255);
red[3] = SCALE(255);
green[3] = SCALE(255);
blue[3] = SCALE(255);
red[4] = 0;
green[4] = SCALE(255);
blue[4] = SCALE(255);
red[4] = 0;
green[4] = SCALE(255);
blue[4] = SCALE(255);
red[5] = SCALE(255);
green[5] = 0;
blue[5] = SCALE(255);
red[5] = SCALE(255);
green[5] = 0;
blue[5] = SCALE(255);
red[6] = SCALE(255);
green[6] = SCALE(255);
blue[6] = 0;
red[6] = SCALE(255);
green[6] = SCALE(255);
blue[6] = 0;
red[7] = 0;
green[7] = 0;
blue[7] = 0;
red[7] = 0;
green[7] = 0;
blue[7] = 0;
red[8] = SCALE(176);
green[8] = SCALE(224);
blue[8] = SCALE(230);
red[9] = SCALE(100);
green[9] = SCALE(149);
blue[9] = SCALE(237);
red[10] = SCALE(46);
green[10] = SCALE(139);
blue[10] = SCALE(87);
red[11] = SCALE(160);
green[11] = SCALE(82);
blue[11] = SCALE(45);
red[12] = SCALE(238);
green[12] = SCALE(130);
blue[12] = SCALE(238);
red[13] = SCALE(176);
green[13] = SCALE(48);
blue[13] = SCALE(96);
red[14] = SCALE(50);
green[14] = SCALE(205);
blue[14] = SCALE(50);
red[15] = SCALE(240);
green[15] = SCALE(152);
blue[15] = SCALE(35);
break;
case 2:
red[0] = SCALE(255);
green[0] = 0;
blue[0] = 0;
red[8] = SCALE(176);
green[8] = SCALE(224);
blue[8] = SCALE(230);
red[9] = SCALE(100);
green[9] = SCALE(149);
blue[9] = SCALE(237);
red[10] = SCALE(46);
green[10] = SCALE(139);
blue[10] = SCALE(87);
red[11] = SCALE(160);
green[11] = SCALE(82);
blue[11] = SCALE(45);
red[12] = SCALE(238);
green[12] = SCALE(130);
blue[12] = SCALE(238);
red[13] = SCALE(176);
green[13] = SCALE(48);
blue[13] = SCALE(96);
red[14] = SCALE(50);
green[14] = SCALE(205);
blue[14] = SCALE(50);
red[15] = SCALE(240);
green[15] = SCALE(152);
blue[15] = SCALE(35);
break;
case 2:
red[0] = SCALE(255);
green[0] = 0;
blue[0] = 0;
red[1] = 0;
green[1] = SCALE(255);
blue[1] = 0;
red[1] = 0;
green[1] = SCALE(255);
blue[1] = 0;
red[2] = 0;
green[2] = 0;
blue[2] = SCALE(255);
red[3] = SCALE(255);
green[3] = SCALE(255);
blue[3] = SCALE(255);
break;
case 1:
red[0] = 0;
green[0] = 0;
blue[0] = 0;
red[2] = 0;
green[2] = 0;
blue[2] = SCALE(255);
red[3] = SCALE(255);
green[3] = SCALE(255);
blue[3] = SCALE(255);
break;
case 1:
red[0] = 0;
green[0] = 0;
blue[0] = 0;
red[1] = SCALE(255);
green[1] = SCALE(255);
blue[1] = SCALE(255);
break;
red[1] = SCALE(255);
green[1] = SCALE(255);
blue[1] = SCALE(255);
break;
}
if ((tif = TIFFOpen(argv[3], "w")) == NULL) {
if ((tif = TIFFOpen(argv[3], "w")) == NULL)
{
fprintf(stderr, "can't open %s as a TIFF file\n", argv[3]);
free(red);free(green);free(blue);
free(red);
free(green);
free(blue);
return 0;
}
@@ -232,31 +241,34 @@ int main(int argc, char **argv)
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE);
TIFFSetField(tif, TIFFTAG_COLORMAP, red, green, blue);
scan_line = (unsigned char *) malloc(WIDTH / (8 / bits_per_pixel));
scan_line = (unsigned char *)malloc(WIDTH / (8 / bits_per_pixel));
for (i = 0; i < HEIGHT; i++) {
for (j = 0, k = 0; j < WIDTH;) {
for (i = 0; i < HEIGHT; i++)
{
for (j = 0, k = 0; j < WIDTH;)
{
cmap_index = (j / chunk_size) + ((i / chunk_size) * nchunks);
switch (bits_per_pixel) {
case 8:
scan_line[k++] = cmap_index;
j++;
break;
case 4:
scan_line[k++] = (cmap_index << 4) + cmap_index;
j += 2;
break;
case 2:
scan_line[k++] = (cmap_index << 6) + (cmap_index << 4)
+ (cmap_index << 2) + cmap_index;
j += 4;
break;
case 1:
scan_line[k++] =
((j / chunk_size) == (i / chunk_size)) ? 0x00 : 0xff;
j += 8;
break;
switch (bits_per_pixel)
{
case 8:
scan_line[k++] = cmap_index;
j++;
break;
case 4:
scan_line[k++] = (cmap_index << 4) + cmap_index;
j += 2;
break;
case 2:
scan_line[k++] = (cmap_index << 6) + (cmap_index << 4) +
(cmap_index << 2) + cmap_index;
j += 4;
break;
case 1:
scan_line[k++] =
((j / chunk_size) == (i / chunk_size)) ? 0x00 : 0xff;
j += 8;
break;
}
}
TIFFWriteScanline(tif, scan_line, i, 0);
@@ -267,16 +279,9 @@ int main(int argc, char **argv)
return 0;
}
void
Usage()
void Usage()
{
fprintf(stderr, "Usage: %s -depth (8 | 4 | 2 | 1) tiff-image\n", programName);
fprintf(stderr, "Usage: %s -depth (8 | 4 | 2 | 1) tiff-image\n",
programName);
exit(0);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+118 -101
View File
@@ -29,57 +29,66 @@
#include "tiffio.h"
#define ROUND(x) (uint16_t) ((x) + 0.5)
#define CMSIZE 256
#define WIDTH 525
#define HEIGHT 512
#define TIFF_GAMMA 2.2
#define ROUND(x) (uint16_t)((x) + 0.5)
#define CMSIZE 256
#define WIDTH 525
#define HEIGHT 512
#define TIFF_GAMMA 2.2
void Usage();
char * programName;
void Usage();
char *programName;
int main(int argc, char **argv)
{
char * input_file = NULL;
double image_gamma = TIFF_GAMMA;
int i, j;
TIFF * tif;
unsigned char * scan_line;
uint16_t red[CMSIZE], green[CMSIZE], blue[CMSIZE];
float refblackwhite[2*3];
char *input_file = NULL;
double image_gamma = TIFF_GAMMA;
int i, j;
TIFF *tif;
unsigned char *scan_line;
uint16_t red[CMSIZE], green[CMSIZE], blue[CMSIZE];
float refblackwhite[2 * 3];
programName = argv[0];
switch (argc) {
case 2:
image_gamma = TIFF_GAMMA;
input_file = argv[1];
break;
case 4:
if (!strcmp(argv[1], "-gamma")) {
image_gamma = atof(argv[2]);
input_file = argv[3];
} else
switch (argc)
{
case 2:
image_gamma = TIFF_GAMMA;
input_file = argv[1];
break;
case 4:
if (!strcmp(argv[1], "-gamma"))
{
image_gamma = atof(argv[2]);
input_file = argv[3];
}
else
Usage();
break;
default:
Usage();
break;
default:
Usage();
}
for (i = 0; i < CMSIZE; i++) {
for (i = 0; i < CMSIZE; i++)
{
if (i == 0)
red[i] = green[i] = blue[i] = 0;
else {
else
{
red[i] = ROUND((pow(i / 255.0, 1.0 / image_gamma) * 65535.0));
green[i] = ROUND((pow(i / 255.0, 1.0 / image_gamma) * 65535.0));
blue[i] = ROUND((pow(i / 255.0, 1.0 / image_gamma) * 65535.0));
}
}
refblackwhite[0] = 0.0; refblackwhite[1] = 255.0;
refblackwhite[2] = 0.0; refblackwhite[3] = 255.0;
refblackwhite[4] = 0.0; refblackwhite[5] = 255.0;
refblackwhite[0] = 0.0;
refblackwhite[1] = 255.0;
refblackwhite[2] = 0.0;
refblackwhite[3] = 255.0;
refblackwhite[4] = 0.0;
refblackwhite[5] = 255.0;
if ((tif = TIFFOpen(input_file, "w")) == NULL) {
if ((tif = TIFFOpen(input_file, "w")) == NULL)
{
fprintf(stderr, "can't open %s as a TIFF file\n", input_file);
exit(0);
}
@@ -100,81 +109,97 @@ int main(int argc, char **argv)
TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, refblackwhite);
TIFFSetField(tif, TIFFTAG_TRANSFERFUNCTION, red, green, blue);
scan_line = (unsigned char *) malloc(WIDTH * 3);
scan_line = (unsigned char *)malloc(WIDTH * 3);
for (i = 0; i < 255; i++) {
for (j = 0; j < 75; j++) {
scan_line[j * 3] = 255;
scan_line[(j * 3) + 1] = 255 - i;
scan_line[(j * 3) + 2] = 255 - i;
for (i = 0; i < 255; i++)
{
for (j = 0; j < 75; j++)
{
scan_line[j * 3] = 255;
scan_line[(j * 3) + 1] = 255 - i;
scan_line[(j * 3) + 2] = 255 - i;
}
for (j = 75; j < 150; j++) {
scan_line[j * 3] = 255 - i;
scan_line[(j * 3) + 1] = 255;
scan_line[(j * 3) + 2] = 255 - i;
for (j = 75; j < 150; j++)
{
scan_line[j * 3] = 255 - i;
scan_line[(j * 3) + 1] = 255;
scan_line[(j * 3) + 2] = 255 - i;
}
for (j = 150; j < 225; j++) {
scan_line[j * 3] = 255 - i;
scan_line[(j * 3) + 1] = 255 - i;
scan_line[(j * 3) + 2] = 255;
for (j = 150; j < 225; j++)
{
scan_line[j * 3] = 255 - i;
scan_line[(j * 3) + 1] = 255 - i;
scan_line[(j * 3) + 2] = 255;
}
for (j = 225; j < 300; j++) {
scan_line[j * 3] = (i - 1) / 2;
scan_line[(j * 3) + 1] = (i - 1) / 2;
scan_line[(j * 3) + 2] = (i - 1) / 2;
for (j = 225; j < 300; j++)
{
scan_line[j * 3] = (i - 1) / 2;
scan_line[(j * 3) + 1] = (i - 1) / 2;
scan_line[(j * 3) + 2] = (i - 1) / 2;
}
for (j = 300; j < 375; j++) {
scan_line[j * 3] = 255 - i;
scan_line[(j * 3) + 1] = 255;
scan_line[(j * 3) + 2] = 255;
for (j = 300; j < 375; j++)
{
scan_line[j * 3] = 255 - i;
scan_line[(j * 3) + 1] = 255;
scan_line[(j * 3) + 2] = 255;
}
for (j = 375; j < 450; j++) {
scan_line[j * 3] = 255;
scan_line[(j * 3) + 1] = 255 - i;
scan_line[(j * 3) + 2] = 255;
for (j = 375; j < 450; j++)
{
scan_line[j * 3] = 255;
scan_line[(j * 3) + 1] = 255 - i;
scan_line[(j * 3) + 2] = 255;
}
for (j = 450; j < 525; j++) {
scan_line[j * 3] = 255;
scan_line[(j * 3) + 1] = 255;
scan_line[(j * 3) + 2] = 255 - i;
for (j = 450; j < 525; j++)
{
scan_line[j * 3] = 255;
scan_line[(j * 3) + 1] = 255;
scan_line[(j * 3) + 2] = 255 - i;
}
TIFFWriteScanline(tif, scan_line, i, 0);
}
for (i = 255; i < 512; i++) {
for (j = 0; j < 75; j++) {
scan_line[j * 3] = i;
scan_line[(j * 3) + 1] = 0;
scan_line[(j * 3) + 2] = 0;
for (i = 255; i < 512; i++)
{
for (j = 0; j < 75; j++)
{
scan_line[j * 3] = i;
scan_line[(j * 3) + 1] = 0;
scan_line[(j * 3) + 2] = 0;
}
for (j = 75; j < 150; j++) {
scan_line[j * 3] = 0;
scan_line[(j * 3) + 1] = i;
scan_line[(j * 3) + 2] = 0;
for (j = 75; j < 150; j++)
{
scan_line[j * 3] = 0;
scan_line[(j * 3) + 1] = i;
scan_line[(j * 3) + 2] = 0;
}
for (j = 150; j < 225; j++) {
scan_line[j * 3] = 0;
scan_line[(j * 3) + 1] = 0;
scan_line[(j * 3) + 2] = i;
for (j = 150; j < 225; j++)
{
scan_line[j * 3] = 0;
scan_line[(j * 3) + 1] = 0;
scan_line[(j * 3) + 2] = i;
}
for (j = 225; j < 300; j++) {
scan_line[j * 3] = (i - 1) / 2;
scan_line[(j * 3) + 1] = (i - 1) / 2;
scan_line[(j * 3) + 2] = (i - 1) / 2;
for (j = 225; j < 300; j++)
{
scan_line[j * 3] = (i - 1) / 2;
scan_line[(j * 3) + 1] = (i - 1) / 2;
scan_line[(j * 3) + 2] = (i - 1) / 2;
}
for (j = 300; j < 375; j++) {
scan_line[j * 3] = 0;
scan_line[(j * 3) + 1] = i;
scan_line[(j * 3) + 2] = i;
for (j = 300; j < 375; j++)
{
scan_line[j * 3] = 0;
scan_line[(j * 3) + 1] = i;
scan_line[(j * 3) + 2] = i;
}
for (j = 375; j < 450; j++) {
scan_line[j * 3] = i;
scan_line[(j * 3) + 1] = 0;
scan_line[(j * 3) + 2] = i;
for (j = 375; j < 450; j++)
{
scan_line[j * 3] = i;
scan_line[(j * 3) + 1] = 0;
scan_line[(j * 3) + 2] = i;
}
for (j = 450; j < 525; j++) {
scan_line[j * 3] = i;
scan_line[(j * 3) + 1] = i;
scan_line[(j * 3) + 2] = 0;
for (j = 450; j < 525; j++)
{
scan_line[j * 3] = i;
scan_line[(j * 3) + 1] = i;
scan_line[(j * 3) + 2] = 0;
}
TIFFWriteScanline(tif, scan_line, i, 0);
}
@@ -184,16 +209,8 @@ int main(int argc, char **argv)
exit(0);
}
void
Usage()
void Usage()
{
fprintf(stderr, "Usage: %s -gamma gamma tiff-image\n", programName);
exit(0);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
-7
View File
@@ -1,8 +1 @@
#define PATCHLEVEL 0
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+658 -601
View File
File diff suppressed because it is too large Load Diff
+11 -18
View File
@@ -1,21 +1,14 @@
#define xtifficon_width 32
#define xtifficon_height 32
static char xtifficon_bits[] = {
0xff, 0x00, 0x00, 0xc0, 0xfe, 0x01, 0x7e, 0xc0, 0xfc, 0x03, 0x7e, 0x60,
0xf8, 0x07, 0x06, 0x30, 0xf8, 0x07, 0x1e, 0x18, 0xf0, 0x0f, 0x1e, 0x0c,
0xe0, 0x1f, 0x06, 0x06, 0xc0, 0x3f, 0x06, 0x06, 0xc0, 0x3f, 0x06, 0x03,
0x80, 0x7f, 0x80, 0x01, 0x00, 0xff, 0xc0, 0x00, 0x00, 0xfe, 0x61, 0x00,
0x00, 0xfe, 0x31, 0x7e, 0x7e, 0xfc, 0x33, 0x7e, 0x7e, 0xf8, 0x1b, 0x06,
0x18, 0xf0, 0x0d, 0x1e, 0x18, 0xf0, 0x0e, 0x1e, 0x18, 0x60, 0x1f, 0x06,
0x18, 0xb0, 0x3f, 0x06, 0x18, 0x98, 0x7f, 0x06, 0x18, 0x98, 0x7f, 0x00,
0x00, 0x0c, 0xff, 0x00, 0x00, 0x06, 0xfe, 0x01, 0x00, 0x63, 0xfc, 0x03,
0x80, 0x61, 0xfc, 0x03, 0xc0, 0x60, 0xf8, 0x07, 0xc0, 0x60, 0xf0, 0x0f,
0x60, 0x60, 0xe0, 0x1f, 0x30, 0x60, 0xe0, 0x1f, 0x18, 0x60, 0xc0, 0x3f,
0x0c, 0x60, 0x80, 0x7f, 0x06, 0x00, 0x00, 0xff};
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
0xff, 0x00, 0x00, 0xc0, 0xfe, 0x01, 0x7e, 0xc0, 0xfc, 0x03, 0x7e, 0x60,
0xf8, 0x07, 0x06, 0x30, 0xf8, 0x07, 0x1e, 0x18, 0xf0, 0x0f, 0x1e, 0x0c,
0xe0, 0x1f, 0x06, 0x06, 0xc0, 0x3f, 0x06, 0x06, 0xc0, 0x3f, 0x06, 0x03,
0x80, 0x7f, 0x80, 0x01, 0x00, 0xff, 0xc0, 0x00, 0x00, 0xfe, 0x61, 0x00,
0x00, 0xfe, 0x31, 0x7e, 0x7e, 0xfc, 0x33, 0x7e, 0x7e, 0xf8, 0x1b, 0x06,
0x18, 0xf0, 0x0d, 0x1e, 0x18, 0xf0, 0x0e, 0x1e, 0x18, 0x60, 0x1f, 0x06,
0x18, 0xb0, 0x3f, 0x06, 0x18, 0x98, 0x7f, 0x06, 0x18, 0x98, 0x7f, 0x00,
0x00, 0x0c, 0xff, 0x00, 0x00, 0x06, 0xfe, 0x01, 0x00, 0x63, 0xfc, 0x03,
0x80, 0x61, 0xfc, 0x03, 0xc0, 0x60, 0xf8, 0x07, 0xc0, 0x60, 0xf0, 0x0f,
0x60, 0x60, 0xe0, 0x1f, 0x30, 0x60, 0xe0, 0x1f, 0x18, 0x60, 0xc0, 0x3f,
0x0c, 0x60, 0x80, 0x7f, 0x06, 0x00, 0x00, 0xff};
+1 -1
View File
@@ -23,4 +23,4 @@
# OF THIS SOFTWARE.
add_executable(iptcutil iptcutil.c)
target_link_libraries(iptcutil tiff port)
target_link_libraries(iptcutil tiff tiff_port)
+2
View File
@@ -31,7 +31,9 @@ EXTRA_DIST = \
test.iptc \
test.txt
if TIFF_CONTRIB
noinst_PROGRAMS = iptcutil
endif
iptcutil_SOURCES = iptcutil.c
iptcutil_LDADD = $(LIBTIFF)
File diff suppressed because it is too large Load Diff
+76 -89
View File
@@ -5,11 +5,11 @@
- as if it were a file.
- mfs_ stands for memory file system.
- Author : Mike Johnson - Banctec AB 03/07/96
-
-
--------------------------------------------------------------------------------
*/
/*
/*
Copyright (c) 1996 Mike Johnson
Copyright (c) 1996 BancTec AB
@@ -21,29 +21,28 @@ all copies of the software and related documentation, and (ii) the names of
Mike Johnson and BancTec may not be used in any advertising or
publicity relating to the software.
THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MIKE JOHNSON OR BANCTEC BE LIABLE FOR
ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
OF THIS SOFTWARE.
*/
/*
--------------------------------------------------------------------------------
- Includes
--------------------------------------------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
--------------------------------------------------------------------------------
@@ -51,9 +50,9 @@ OF THIS SOFTWARE.
--------------------------------------------------------------------------------
*/
#define MAX_BUFFS 20
#define FALSE 0
#define TRUE 1
#define MAX_BUFFS 20
#define FALSE 0
#define TRUE 1
/*
--------------------------------------------------------------------------------
@@ -61,31 +60,30 @@ OF THIS SOFTWARE.
--------------------------------------------------------------------------------
*/
static char *buf[MAX_BUFFS]; /* Memory for each open buf */
static long buf_off[MAX_BUFFS]; /* File pointer for each buf */
static long buf_size[MAX_BUFFS]; /* Count of bytes allocated for each buf */
static long fds[MAX_BUFFS]; /* File descriptor status */
static int buf_mode[MAX_BUFFS]; /* Mode of buffer (r, w, a) */
static char *buf[MAX_BUFFS]; /* Memory for each open buf */
static long buf_off[MAX_BUFFS]; /* File pointer for each buf */
static long buf_size[MAX_BUFFS]; /* Count of bytes allocated for each buf */
static long fds[MAX_BUFFS]; /* File descriptor status */
static int buf_mode[MAX_BUFFS]; /* Mode of buffer (r, w, a) */
static int library_init_done = FALSE;
/*
--------------------------------------------------------------------------------
- Function prototypes
--------------------------------------------------------------------------------
*/
int mfs_open (void *ptr, int size, char *mode);
int mfs_lseek (int fd, int offset, int whence);
int mfs_read (int fd, void *buf, int size);
int mfs_write (int fd, void *buf, int size);
int mfs_size (int fd);
int mfs_map (int fd, char **addr, size_t *len);
int mfs_unmap (int fd);
int mfs_close (int fd);
static int extend_mem_file (int fd, int size);
static void mem_init ();
int mfs_open(void *ptr, int size, char *mode);
int mfs_lseek(int fd, int offset, int whence);
int mfs_read(int fd, void *buf, int size);
int mfs_write(int fd, void *buf, int size);
int mfs_size(int fd);
int mfs_map(int fd, char **addr, size_t *len);
int mfs_unmap(int fd);
int mfs_close(int fd);
static int extend_mem_file(int fd, int size);
static void mem_init();
/*
--------------------------------------------------------------------------------
@@ -97,7 +95,7 @@ static void mem_init ();
--------------------------------------------------------------------------------
- Function : mfs_open ()
-
- Arguments : Pointer to allocated buffer, initial size of buffer,
- Arguments : Pointer to allocated buffer, initial size of buffer,
- mode spec (r, w, a)
-
- Returns : File descriptor or -1 if error.
@@ -108,22 +106,22 @@ static void mem_init ();
- back to TIFFClientOpen and used as if it was a disk
- based fd.
- If the call is for mode 'w' then pass (void *)NULL as
- the buffer and zero size and the library will
- the buffer and zero size and the library will
- allocate memory for you.
- If the mode is append then pass (void *)NULL and size
- zero or with a valid address.
-
-
--------------------------------------------------------------------------------
*/
int mfs_open (void *buffer, int size, char *mode)
int mfs_open(void *buffer, int size, char *mode)
{
int ret, i;
void *tmp;
if (library_init_done == FALSE)
{
mem_init ();
mem_init();
library_init_done = TRUE;
}
@@ -140,7 +138,7 @@ int mfs_open (void *buffer, int size, char *mode)
}
}
if (i == MAX_BUFFS) /* No more free descriptors */
if (i == MAX_BUFFS) /* No more free descriptors */
{
ret = -1;
errno = EMFILE;
@@ -171,7 +169,7 @@ int mfs_open (void *buffer, int size, char *mode)
else
{
tmp = malloc (0); /* Get a pointer */
tmp = malloc(0); /* Get a pointer */
if (tmp == (void *)NULL)
{
ret = -1;
@@ -187,9 +185,9 @@ int mfs_open (void *buffer, int size, char *mode)
}
else if (ret >= 0 && *mode == 'a')
{
if (buffer == (void *) NULL) /* Create space for client */
if (buffer == (void *)NULL) /* Create space for client */
{
tmp = malloc (0); /* Get a pointer */
tmp = malloc(0); /* Get a pointer */
if (tmp == (void *)NULL)
{
ret = -1;
@@ -202,14 +200,14 @@ int mfs_open (void *buffer, int size, char *mode)
buf_off[ret] = 0;
}
}
else /* Client has file read in already */
else /* Client has file read in already */
{
buf[ret] = (char *)buffer;
buf_size[ret] = size;
buf_off[ret] = 0;
}
}
else /* Some other invalid combination of parameters */
else /* Some other invalid combination of parameters */
{
ret = -1;
errno = EINVAL;
@@ -235,16 +233,16 @@ int mfs_open (void *buffer, int size, char *mode)
- Description : Does the same as lseek (2) except on a memory based file.
- Note: the memory area will be extended if the caller
- attempts to seek past the current end of file (memory).
-
-
--------------------------------------------------------------------------------
*/
int mfs_lseek (int fd, int offset, int whence)
int mfs_lseek(int fd, int offset, int whence)
{
int ret;
long test_off;
if (fds[fd] == -1) /* Not open */
if (fds[fd] == -1) /* Not open */
{
ret = -1;
errno = EBADF;
@@ -260,7 +258,7 @@ int mfs_lseek (int fd, int offset, int whence)
{
case SEEK_SET:
if (offset > buf_size[fd])
extend_mem_file (fd, offset);
extend_mem_file(fd, offset);
buf_off[fd] = offset;
ret = offset;
break;
@@ -276,7 +274,7 @@ int mfs_lseek (int fd, int offset, int whence)
else
{
if (test_off > buf_size[fd])
extend_mem_file (fd, test_off);
extend_mem_file(fd, test_off);
buf_off[fd] = test_off;
ret = test_off;
}
@@ -293,7 +291,7 @@ int mfs_lseek (int fd, int offset, int whence)
else
{
if (test_off > buf_size[fd])
extend_mem_file (fd, test_off);
extend_mem_file(fd, test_off);
buf_off[fd] = test_off;
ret = test_off;
}
@@ -307,7 +305,7 @@ int mfs_lseek (int fd, int offset, int whence)
}
return (ret);
}
}
/*
--------------------------------------------------------------------------------
@@ -320,11 +318,11 @@ int mfs_lseek (int fd, int offset, int whence)
- Description : Does the same as read (2) except on a memory based file.
- Note: An attempt to read past the end of memory currently
- allocated to the file will return 0 (End Of File)
-
-
--------------------------------------------------------------------------------
*/
int mfs_read (int fd, void *clnt_buf, int size)
int mfs_read(int fd, void *clnt_buf, int size)
{
int ret;
@@ -337,11 +335,11 @@ int mfs_read (int fd, void *clnt_buf, int size)
}
else if (buf_off[fd] + size > buf_size[fd])
{
ret = 0; /* EOF */
ret = 0; /* EOF */
}
else
{
memcpy (clnt_buf, (void *) (buf[fd] + buf_off[fd]), size);
memcpy(clnt_buf, (void *)(buf[fd] + buf_off[fd]), size);
buf_off[fd] = buf_off[fd] + size;
ret = size;
}
@@ -360,11 +358,11 @@ int mfs_read (int fd, void *clnt_buf, int size)
- Description : Does the same as write (2) except on a memory based file.
- Note: the memory area will be extended if the caller
- attempts to write past the current end of file (memory).
-
-
--------------------------------------------------------------------------------
*/
int mfs_write (int fd, void *clnt_buf, int size)
int mfs_write(int fd, void *clnt_buf, int size)
{
int ret;
@@ -380,12 +378,12 @@ int mfs_write (int fd, void *clnt_buf, int size)
/* Write */
if (buf_off[fd] + size > buf_size[fd])
{
extend_mem_file (fd, buf_off[fd] + size);
{
extend_mem_file(fd, buf_off[fd] + size);
buf_size[fd] = (buf_off[fd] + size);
}
memcpy ((buf[fd] + buf_off[fd]), clnt_buf, size);
memcpy((buf[fd] + buf_off[fd]), clnt_buf, size);
buf_off[fd] = buf_off[fd] + size;
ret = size;
@@ -397,10 +395,10 @@ int mfs_write (int fd, void *clnt_buf, int size)
if (buf_off[fd] != buf_size[fd])
buf_off[fd] = buf_size[fd];
extend_mem_file (fd, buf_off[fd] + size);
extend_mem_file(fd, buf_off[fd] + size);
buf_size[fd] += size;
memcpy ((buf[fd] + buf_off[fd]), clnt_buf, size);
memcpy((buf[fd] + buf_off[fd]), clnt_buf, size);
buf_off[fd] = buf_off[fd] + size;
ret = size;
@@ -418,15 +416,15 @@ int mfs_write (int fd, void *clnt_buf, int size)
- Returns : integer file size
-
- Description : This function returns the current size of the file in bytes.
-
-
--------------------------------------------------------------------------------
*/
int mfs_size (int fd)
int mfs_size(int fd)
{
int ret;
if (fds[fd] == -1) /* Not open */
if (fds[fd] == -1) /* Not open */
{
ret = -1;
errno = EBADF;
@@ -449,15 +447,15 @@ int mfs_size (int fd)
- in memory and what size the mapped area is. It is provided
- to satisfy the MapProc function in libtiff. It pretends
- that the file has been mmap (2)ped.
-
-
--------------------------------------------------------------------------------
*/
int mfs_map (int fd, char **addr, size_t *len)
int mfs_map(int fd, char **addr, size_t *len)
{
int ret;
int ret;
if (fds[fd] == -1) /* Not open */
if (fds[fd] == -1) /* Not open */
{
ret = -1;
errno = EBADF;
@@ -482,14 +480,11 @@ int mfs_map (int fd, char **addr, size_t *len)
-
- Description : This function does nothing as the file is always
- in memory.
-
-
--------------------------------------------------------------------------------
*/
int mfs_unmap (int fd)
{
return (0);
}
int mfs_unmap(int fd) { return (0); }
/*
--------------------------------------------------------------------------------
@@ -500,15 +495,15 @@ int mfs_unmap (int fd)
- Returns : close status (succeeded or otherwise)
-
- Description : Close the open memory file. (Make fd available again.)
-
-
--------------------------------------------------------------------------------
*/
int mfs_close (int fd)
int mfs_close(int fd)
{
int ret;
int ret;
if (fds[fd] == -1) /* Not open */
if (fds[fd] == -1) /* Not open */
{
ret = -1;
errno = EBADF;
@@ -531,20 +526,20 @@ int mfs_close (int fd)
- Returns : 0 - All OK, -1 - realloc () failed.
-
- Description : Increase the amount of memory allocated to a file.
-
-
--------------------------------------------------------------------------------
*/
static int extend_mem_file (int fd, int size)
static int extend_mem_file(int fd, int size)
{
void *new_mem;
int ret;
if ((new_mem = realloc (buf[fd], size)) == (void *) NULL)
if ((new_mem = realloc(buf[fd], size)) == (void *)NULL)
ret = -1;
else
{
buf[fd] = (char *) new_mem;
buf[fd] = (char *)new_mem;
ret = 0;
}
@@ -560,11 +555,11 @@ static int extend_mem_file (int fd, int size)
- Returns : void
-
- Description : Initialise the library.
-
-
--------------------------------------------------------------------------------
*/
static void mem_init ()
static void mem_init()
{
int i;
@@ -576,11 +571,3 @@ static void mem_init ()
buf_off[i] = 0;
}
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+88 -74
View File
@@ -28,112 +28,126 @@
#include <tiffio.h>
#include <tiffio.hxx>
/* stolen from tiffiop.h, which is a private header so we can't just include it */
/* stolen from tiffiop.h, which is a private header so we can't just include it
*/
/* safe multiply returns either the multiplied value or 0 if it overflowed */
#define __TIFFSafeMultiply(t,v,m) ((((t)(m) != (t)0) && (((t)(((v)*(m))/(m))) == (t)(v))) ? (t)((v)*(m)) : (t)0)
#define __TIFFSafeMultiply(t, v, m) \
((((t)(m) != (t)0) && (((t)(((v) * (m)) / (m))) == (t)(v))) \
? (t)((v) * (m)) \
: (t)0)
const uint64_t MAX_SIZE = 500000000;
extern "C" void handle_error(const char *unused, const char *unused2, va_list unused3) {
extern "C" void handle_error(const char *unused, const char *unused2,
va_list unused3)
{
return;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
{
#ifndef STANDALONE
TIFFSetErrorHandler(handle_error);
TIFFSetWarningHandler(handle_error);
TIFFSetErrorHandler(handle_error);
TIFFSetWarningHandler(handle_error);
#endif
#if defined(__has_feature)
# if __has_feature(memory_sanitizer)
// libjpeg-turbo has issues with MSAN and SIMD code
// See https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7547
// and https://github.com/libjpeg-turbo/libjpeg-turbo/pull/365
setenv("JSIMD_FORCENONE" ,"1", 1);
# endif
#if __has_feature(memory_sanitizer)
// libjpeg-turbo has issues with MSAN and SIMD code
// See https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7547
// and https://github.com/libjpeg-turbo/libjpeg-turbo/pull/365
setenv("JSIMD_FORCENONE", "1", 1);
#endif
std::istringstream s(std::string(Data,Data+Size));
TIFF* tif = TIFFStreamOpen("MemTIFF", &s);
if (!tif) {
return 0;
}
uint32_t w, h;
uint32_t* raster;
#endif
std::istringstream s(std::string(Data, Data + Size));
TIFF *tif = TIFFStreamOpen("MemTIFF", &s);
if (!tif)
{
return 0;
}
uint32_t w, h;
uint32_t *raster;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
/* don't continue if file size is ludicrous */
if (TIFFTileSize64(tif) > MAX_SIZE) {
TIFFClose(tif);
return 0;
}
uint64_t bufsize = TIFFTileSize64(tif);
/* don't continue if the buffer size greater than the max allowed by the fuzzer */
if (bufsize > MAX_SIZE || bufsize == 0) {
TIFFClose(tif);
return 0;
}
/* another hack to work around an OOM in tif_fax3.c */
uint32_t tilewidth = 0;
uint32_t imagewidth = 0;
TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tilewidth);
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &imagewidth);
tilewidth = __TIFFSafeMultiply(uint32_t, tilewidth, 2);
imagewidth = __TIFFSafeMultiply(uint32_t, imagewidth, 2);
if (tilewidth * 2 > MAX_SIZE || imagewidth * 2 > MAX_SIZE || tilewidth == 0 || imagewidth == 0) {
TIFFClose(tif);
return 0;
}
uint32_t size = __TIFFSafeMultiply(uint32_t, w, h);
if (size > MAX_SIZE || size == 0) {
TIFFClose(tif);
return 0;
}
raster = (uint32_t*) _TIFFmalloc(size * sizeof (uint32_t));
if (raster != NULL) {
TIFFReadRGBAImage(tif, w, h, raster, 0);
_TIFFfree(raster);
}
TIFFClose(tif);
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
/* don't continue if file size is ludicrous */
if (TIFFTileSize64(tif) > MAX_SIZE)
{
TIFFClose(tif);
return 0;
}
uint64_t bufsize = TIFFTileSize64(tif);
/* don't continue if the buffer size greater than the max allowed by the
* fuzzer */
if (bufsize > MAX_SIZE || bufsize == 0)
{
TIFFClose(tif);
return 0;
}
/* another hack to work around an OOM in tif_fax3.c */
uint32_t tilewidth = 0;
uint32_t imagewidth = 0;
TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tilewidth);
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &imagewidth);
tilewidth = __TIFFSafeMultiply(uint32_t, tilewidth, 2);
imagewidth = __TIFFSafeMultiply(uint32_t, imagewidth, 2);
if (tilewidth * 2 > MAX_SIZE || imagewidth * 2 > MAX_SIZE ||
tilewidth == 0 || imagewidth == 0)
{
TIFFClose(tif);
return 0;
}
uint32_t size = __TIFFSafeMultiply(uint32_t, w, h);
if (size > MAX_SIZE || size == 0)
{
TIFFClose(tif);
return 0;
}
raster = (uint32_t *)_TIFFmalloc(size * sizeof(uint32_t));
if (raster != NULL)
{
TIFFReadRGBAImage(tif, w, h, raster, 0);
_TIFFfree(raster);
}
TIFFClose(tif);
return 0;
return 0;
}
#ifdef STANDALONE
template<class T> static void CPL_IGNORE_RET_VAL(T) {}
template <class T> static void CPL_IGNORE_RET_VAL(T) {}
static void Usage(int, char* argv[])
static void Usage(int, char *argv[])
{
fprintf(stderr, "%s [--help] [-repeat N] filename.\n", argv[0]);
exit(1);
}
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{
int nRet = 0;
void* buf = NULL;
void *buf = NULL;
int nLen = 0;
int nLoops = 1;
const char* pszFilename = NULL;
const char *pszFilename = NULL;
for(int i = 1; i < argc; i++ )
for (int i = 1; i < argc; i++)
{
if( i + 1 < argc && strcmp(argv[i], "-repeat") == 0 )
if (i + 1 < argc && strcmp(argv[i], "-repeat") == 0)
{
nLoops = atoi(argv[i+1]);
nLoops = atoi(argv[i + 1]);
i++;
}
else if( strcmp(argv[i], "-dummy") == 0 )
else if (strcmp(argv[i], "-dummy") == 0)
{
uint8_t dummy = ' ';
return LLVMFuzzerTestOneInput(&dummy, 1);
}
else if( strcmp(argv[i], "--help") == 0 )
else if (strcmp(argv[i], "--help") == 0)
{
Usage(argc, argv);
}
else if( argv[i][0] == '-' )
else if (argv[i][0] == '-')
{
fprintf(stderr, "Unrecognized option: %s", argv[i]);
Usage(argc, argv);
@@ -143,13 +157,13 @@ int main(int argc, char* argv[])
pszFilename = argv[i];
}
}
if( pszFilename == nullptr )
if (pszFilename == nullptr)
{
fprintf(stderr, "No filename specified\n");
Usage(argc, argv);
}
FILE* f = fopen(pszFilename, "rb");
if( !f )
FILE *f = fopen(pszFilename, "rb");
if (!f)
{
fprintf(stderr, "%s does not exist.\n", pszFilename);
exit(1);
@@ -158,7 +172,7 @@ int main(int argc, char* argv[])
nLen = (int)ftell(f);
fseek(f, 0, SEEK_SET);
buf = malloc(nLen);
if( !buf )
if (!buf)
{
fprintf(stderr, "malloc failed.\n");
fclose(f);
@@ -166,10 +180,10 @@ int main(int argc, char* argv[])
}
CPL_IGNORE_RET_VAL(fread(buf, nLen, 1, f));
fclose(f);
for( int i = 0; i < nLoops; i++ )
for (int i = 0; i < nLoops; i++)
{
nRet = LLVMFuzzerTestOneInput(static_cast<const uint8_t*>(buf), nLen);
if( nRet != 0 )
nRet = LLVMFuzzerTestOneInput(static_cast<const uint8_t *>(buf), nLen);
if (nRet != 0)
break;
}
free(buf);
+335 -294
View File
@@ -2,23 +2,23 @@
* Copyright (c) 1991-1996 Sam Leffler
* Copyright (c) 1991-1996 Silicon Graphics, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
@@ -34,43 +34,41 @@
* ignore those details. The calling program does, however, need to be
* conscious of the type of the pixel data that it is receiving.
*
* For reasons of efficiency, the callback function actually gets called for
* For reasons of efficiency, the callback function actually gets called for
* "blocks" of pixels rather than for individual pixels. The format of the
* callback arguments is given below.
*
* This code was taken from TIFFReadRGBAImage() in tif_getimage.c of the original
* TIFF distribution, and simplified and generalized to provide this general
* iteration capability. Those routines could certainly be re-implemented in terms
* of a TIFFImageIter if desired.
* This code was taken from TIFFReadRGBAImage() in tif_getimage.c of the
* original TIFF distribution, and simplified and generalized to provide this
* general iteration capability. Those routines could certainly be
* re-implemented in terms of a TIFFImageIter if desired.
*
*/
#include "tiffiop.h"
#include "tif_imageiter.h"
#include "tiffiop.h"
#include <assert.h>
#include <stdio.h>
static int gtTileContig(TIFFImageIter*, void *udata, uint32_t, uint32_t);
static int gtTileSeparate(TIFFImageIter*, void *udata, uint32_t, uint32_t);
static int gtStripContig(TIFFImageIter*, void *udata, uint32_t, uint32_t);
static int gtStripSeparate(TIFFImageIter*, void *udata, uint32_t, uint32_t);
static int gtTileContig(TIFFImageIter *, void *udata, uint32_t, uint32_t);
static int gtTileSeparate(TIFFImageIter *, void *udata, uint32_t, uint32_t);
static int gtStripContig(TIFFImageIter *, void *udata, uint32_t, uint32_t);
static int gtStripSeparate(TIFFImageIter *, void *udata, uint32_t, uint32_t);
static const char photoTag[] = "PhotometricInterpretation";
static const char photoTag[] = "PhotometricInterpretation";
static int
isCCITTCompression(TIFF* tif)
static int isCCITTCompression(TIFF *tif)
{
uint16_t compress;
TIFFGetField(tif, TIFFTAG_COMPRESSION, &compress);
return (compress == COMPRESSION_CCITTFAX3 ||
compress == COMPRESSION_CCITTFAX4 ||
compress == COMPRESSION_CCITTRLE ||
compress == COMPRESSION_CCITTRLEW);
compress == COMPRESSION_CCITTFAX4 ||
compress == COMPRESSION_CCITTRLE ||
compress == COMPRESSION_CCITTRLEW);
}
int
TIFFImageIterBegin(TIFFImageIter* img, TIFF* tif, int stop, char emsg[1024])
int TIFFImageIterBegin(TIFFImageIter *img, TIFF *tif, int stop, char emsg[1024])
{
uint16_t* sampleinfo;
uint16_t *sampleinfo;
uint16_t extrasamples;
uint16_t planarconfig;
int colorchannels;
@@ -80,217 +78,244 @@ TIFFImageIterBegin(TIFFImageIter* img, TIFF* tif, int stop, char emsg[1024])
TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample);
img->alpha = 0;
TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &img->samplesperpixel);
TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
&extrasamples, &sampleinfo);
TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, &extrasamples,
&sampleinfo);
if (extrasamples == 1)
switch (sampleinfo[0]) {
case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */
case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */
img->alpha = sampleinfo[0];
break;
}
switch (sampleinfo[0])
{
case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */
case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */
img->alpha = sampleinfo[0];
break;
}
colorchannels = img->samplesperpixel - extrasamples;
TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig);
if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) {
switch (colorchannels) {
case 1:
if (isCCITTCompression(tif))
img->photometric = PHOTOMETRIC_MINISWHITE;
else
img->photometric = PHOTOMETRIC_MINISBLACK;
break;
case 3:
img->photometric = PHOTOMETRIC_RGB;
break;
default:
sprintf(emsg, "Missing needed %s tag", photoTag);
return (0);
}
if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric))
{
switch (colorchannels)
{
case 1:
if (isCCITTCompression(tif))
img->photometric = PHOTOMETRIC_MINISWHITE;
else
img->photometric = PHOTOMETRIC_MINISBLACK;
break;
case 3:
img->photometric = PHOTOMETRIC_RGB;
break;
default:
sprintf(emsg, "Missing needed %s tag", photoTag);
return (0);
}
}
switch (img->photometric) {
case PHOTOMETRIC_PALETTE:
if (!TIFFGetField(tif, TIFFTAG_COLORMAP,
&img->redcmap, &img->greencmap, &img->bluecmap)) {
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Missing required \"Colormap\" tag");
return (0);
}
/* fall through... */
case PHOTOMETRIC_MINISWHITE:
case PHOTOMETRIC_MINISBLACK:
/* This should work now so skip the check - BSR
if (planarconfig == PLANARCONFIG_CONTIG && img->samplesperpixel != 1) {
sprintf(emsg,
"Sorry, can not handle contiguous data with %s=%d, and %s=%d",
photoTag, img->photometric,
"Samples/pixel", img->samplesperpixel);
return (0);
}
*/
break;
case PHOTOMETRIC_YCBCR:
if (planarconfig != PLANARCONFIG_CONTIG) {
sprintf(emsg, "Sorry, can not handle YCbCr images with %s=%d",
"Planarconfiguration", planarconfig);
return (0);
}
/* It would probably be nice to have a reality check here. */
{ uint16_t compress;
TIFFGetField(tif, TIFFTAG_COMPRESSION, &compress);
if (compress == COMPRESSION_JPEG && planarconfig == PLANARCONFIG_CONTIG) {
/* can rely on libjpeg to convert to RGB */
/* XXX should restore current state on exit */
TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
img->photometric = PHOTOMETRIC_RGB;
}
}
break;
case PHOTOMETRIC_RGB:
if (colorchannels < 3) {
sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
"Color channels", colorchannels);
return (0);
}
break;
case PHOTOMETRIC_SEPARATED: {
uint16_t inkset;
TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset);
if (inkset != INKSET_CMYK) {
sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
"InkSet", inkset);
return (0);
}
if (img->samplesperpixel != 4) {
sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
"Samples/pixel", img->samplesperpixel);
return (0);
}
break;
}
default:
sprintf(emsg, "Sorry, can not handle image with %s=%d",
photoTag, img->photometric);
return (0);
switch (img->photometric)
{
case PHOTOMETRIC_PALETTE:
if (!TIFFGetField(tif, TIFFTAG_COLORMAP, &img->redcmap,
&img->greencmap, &img->bluecmap))
{
TIFFErrorExtR(tif, TIFFFileName(tif),
"Missing required \"Colormap\" tag");
return (0);
}
/* fall through... */
case PHOTOMETRIC_MINISWHITE:
case PHOTOMETRIC_MINISBLACK:
/* This should work now so skip the check - BSR
if (planarconfig == PLANARCONFIG_CONTIG &&
img->samplesperpixel != 1) { sprintf(emsg, "Sorry, can not handle
contiguous data with %s=%d, and %s=%d", photoTag,
img->photometric, "Samples/pixel", img->samplesperpixel); return
(0);
}
*/
break;
case PHOTOMETRIC_YCBCR:
if (planarconfig != PLANARCONFIG_CONTIG)
{
sprintf(emsg, "Sorry, can not handle YCbCr images with %s=%d",
"Planarconfiguration", planarconfig);
return (0);
}
/* It would probably be nice to have a reality check here. */
{
uint16_t compress;
TIFFGetField(tif, TIFFTAG_COMPRESSION, &compress);
if (compress == COMPRESSION_JPEG &&
planarconfig == PLANARCONFIG_CONTIG)
{
/* can rely on libjpeg to convert to RGB */
/* XXX should restore current state on exit */
TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
img->photometric = PHOTOMETRIC_RGB;
}
}
break;
case PHOTOMETRIC_RGB:
if (colorchannels < 3)
{
sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
"Color channels", colorchannels);
return (0);
}
break;
case PHOTOMETRIC_SEPARATED:
{
uint16_t inkset;
TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset);
if (inkset != INKSET_CMYK)
{
sprintf(emsg,
"Sorry, can not handle separated image with %s=%d",
"InkSet", inkset);
return (0);
}
if (img->samplesperpixel != 4)
{
sprintf(emsg,
"Sorry, can not handle separated image with %s=%d",
"Samples/pixel", img->samplesperpixel);
return (0);
}
break;
}
default:
sprintf(emsg, "Sorry, can not handle image with %s=%d", photoTag,
img->photometric);
return (0);
}
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height);
TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation);
switch (img->orientation) {
case ORIENTATION_BOTRIGHT:
case ORIENTATION_RIGHTBOT: /* XXX */
case ORIENTATION_LEFTBOT: /* XXX */
TIFFWarning(TIFFFileName(tif), "using bottom-left orientation");
img->orientation = ORIENTATION_BOTLEFT;
/* fall through... */
case ORIENTATION_BOTLEFT:
break;
case ORIENTATION_TOPRIGHT:
case ORIENTATION_RIGHTTOP: /* XXX */
case ORIENTATION_LEFTTOP: /* XXX */
default:
TIFFWarning(TIFFFileName(tif), "using top-left orientation");
img->orientation = ORIENTATION_TOPLEFT;
/* fall through... */
case ORIENTATION_TOPLEFT:
break;
switch (img->orientation)
{
case ORIENTATION_BOTRIGHT:
case ORIENTATION_RIGHTBOT: /* XXX */
case ORIENTATION_LEFTBOT: /* XXX */
TIFFWarning(TIFFFileName(tif), "using bottom-left orientation");
img->orientation = ORIENTATION_BOTLEFT;
/* fall through... */
case ORIENTATION_BOTLEFT:
break;
case ORIENTATION_TOPRIGHT:
case ORIENTATION_RIGHTTOP: /* XXX */
case ORIENTATION_LEFTTOP: /* XXX */
default:
TIFFWarning(TIFFFileName(tif), "using top-left orientation");
img->orientation = ORIENTATION_TOPLEFT;
/* fall through... */
case ORIENTATION_TOPLEFT:
break;
}
img->isContig =
!(planarconfig == PLANARCONFIG_SEPARATE && colorchannels > 1);
if (img->isContig) {
img->get = TIFFIsTiled(tif) ? gtTileContig : gtStripContig;
} else {
img->get = TIFFIsTiled(tif) ? gtTileSeparate : gtStripSeparate;
!(planarconfig == PLANARCONFIG_SEPARATE && colorchannels > 1);
if (img->isContig)
{
img->get = TIFFIsTiled(tif) ? gtTileContig : gtStripContig;
}
else
{
img->get = TIFFIsTiled(tif) ? gtTileSeparate : gtStripSeparate;
}
return (1);
}
int
TIFFImageIterGet(TIFFImageIter* img, void *udata, uint32_t w, uint32_t h)
int TIFFImageIterGet(TIFFImageIter *img, void *udata, uint32_t w, uint32_t h)
{
if (img->get == NULL) {
TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No \"get\" routine setup");
return (0);
if (img->get == NULL)
{
TIFFErrorExtR(img->tif, TIFFFileName(img->tif),
"No \"get\" routine setup");
return (0);
}
if (img->callback.any == NULL) {
TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif),
"No \"put\" routine setupl; probably can not handle image format");
return (0);
if (img->callback.any == NULL)
{
TIFFErrorExtR(
img->tif, TIFFFileName(img->tif),
"No \"put\" routine setupl; probably can not handle image format");
return (0);
}
return (*img->get)(img, udata, w, h);
}
TIFFImageIterEnd(TIFFImageIter* img)
{
/* Nothing to free... ? */
TIFFImageIterEnd(TIFFImageIter *img)
{ /* Nothing to free... ? */
}
/*
* Read the specified image into an ABGR-format raster.
*/
int
TIFFReadImageIter(TIFF* tif,
uint32_t rwidth, uint32_t rheight, uint8_t* raster, int stop)
int TIFFReadImageIter(TIFF *tif, uint32_t rwidth, uint32_t rheight,
uint8_t *raster, int stop)
{
char emsg[1024];
TIFFImageIter img;
int ok;
if (TIFFImageIterBegin(&img, tif, stop, emsg)) {
/* XXX verify rwidth and rheight against width and height */
ok = TIFFImageIterGet(&img, raster, rwidth, img.height);
TIFFImageIterEnd(&img);
} else {
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), emsg);
ok = 0;
if (TIFFImageIterBegin(&img, tif, stop, emsg))
{
/* XXX verify rwidth and rheight against width and height */
ok = TIFFImageIterGet(&img, raster, rwidth, img.height);
TIFFImageIterEnd(&img);
}
else
{
TIFFErrorExtR(tif, TIFFFileName(tif), emsg);
ok = 0;
}
return (ok);
}
/*
* Get an tile-organized image that has
* PlanarConfiguration contiguous if SamplesPerPixel > 1
* or
* SamplesPerPixel == 1
*/
static int
gtTileContig(TIFFImageIter* img, void *udata, uint32_t w, uint32_t h)
*/
static int gtTileContig(TIFFImageIter *img, void *udata, uint32_t w, uint32_t h)
{
TIFF* tif = img->tif;
TIFF *tif = img->tif;
ImageIterTileContigRoutine callback = img->callback.contig;
uint16_t orientation;
uint32_t col, row;
uint32_t tw, th;
u_char* buf;
u_char *buf;
int32_t fromskew;
uint32_t nrow;
buf = (u_char*) _TIFFmalloc(TIFFTileSize(tif));
if (buf == 0) {
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer");
return (0);
buf = (u_char *)_TIFFmalloc(TIFFTileSize(tif));
if (buf == 0)
{
TIFFErrorExtR(tif, TIFFFileName(tif), "No space for tile buffer");
return (0);
}
TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw);
TIFFGetField(tif, TIFFTAG_TILELENGTH, &th);
orientation = img->orientation;
for (row = 0; row < h; row += th) {
nrow = (row + th > h ? h - row : th);
for (col = 0; col < w; col += tw) {
if (TIFFReadTile(tif, buf, col, row, 0, 0) < 0 && img->stoponerr)
break;
if (col + tw > w) {
/*
* Tile is clipped horizontally. Calculate
* visible portion and skewing factors.
*/
uint32_t npix = w - col;
fromskew = tw - npix;
(*callback)(img, udata, col, row, npix, nrow, fromskew, buf);
} else {
(*callback)(img, udata, col, row, tw, nrow, 0, buf);
}
}
for (row = 0; row < h; row += th)
{
nrow = (row + th > h ? h - row : th);
for (col = 0; col < w; col += tw)
{
if (TIFFReadTile(tif, buf, col, row, 0, 0) < 0 && img->stoponerr)
break;
if (col + tw > w)
{
/*
* Tile is clipped horizontally. Calculate
* visible portion and skewing factors.
*/
uint32_t npix = w - col;
fromskew = tw - npix;
(*callback)(img, udata, col, row, npix, nrow, fromskew, buf);
}
else
{
(*callback)(img, udata, col, row, tw, nrow, 0, buf);
}
}
}
_TIFFfree(buf);
return (1);
@@ -301,63 +326,71 @@ gtTileContig(TIFFImageIter* img, void *udata, uint32_t w, uint32_t h)
* SamplesPerPixel > 1
* PlanarConfiguration separated
* We assume that all such images are RGB.
*/
static int
gtTileSeparate(TIFFImageIter* img, void *udata, uint32_t w, uint32_t h)
*/
static int gtTileSeparate(TIFFImageIter *img, void *udata, uint32_t w,
uint32_t h)
{
TIFF* tif = img->tif;
TIFF *tif = img->tif;
ImageIterTileSeparateRoutine callback = img->callback.separate;
uint16_t orientation;
uint32_t col, row;
uint32_t tw, th;
u_char* buf;
u_char* r;
u_char* g;
u_char* b;
u_char* a;
u_char *buf;
u_char *r;
u_char *g;
u_char *b;
u_char *a;
tsize_t tilesize;
int32_t fromskew;
int alpha = img->alpha;
uint32_t nrow;
tilesize = TIFFTileSize(tif);
buf = (u_char*) _TIFFmalloc(4*tilesize);
if (buf == 0) {
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer");
return (0);
buf = (u_char *)_TIFFmalloc(4 * tilesize);
if (buf == 0)
{
TIFFErrorExtR(tif, TIFFFileName(tif), "No space for tile buffer");
return (0);
}
r = buf;
g = r + tilesize;
b = g + tilesize;
a = b + tilesize;
if (!alpha)
memset(a, 0xff, tilesize);
memset(a, 0xff, tilesize);
TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw);
TIFFGetField(tif, TIFFTAG_TILELENGTH, &th);
orientation = img->orientation;
for (row = 0; row < h; row += th) {
nrow = (row + th > h ? h - row : th);
for (col = 0; col < w; col += tw) {
if (TIFFReadTile(tif, r, col, row,0,0) < 0 && img->stoponerr)
break;
if (TIFFReadTile(tif, g, col, row,0,1) < 0 && img->stoponerr)
break;
if (TIFFReadTile(tif, b, col, row,0,2) < 0 && img->stoponerr)
break;
if (alpha && TIFFReadTile(tif,a,col,row,0,3) < 0 && img->stoponerr)
break;
if (col + tw > w) {
/*
* Tile is clipped horizontally. Calculate
* visible portion and skewing factors.
*/
uint32_t npix = w - col;
fromskew = tw - npix;
(*callback)(img, udata, col, row, npix, nrow, fromskew, r, g, b, a);
} else {
(*callback)(img, udata, col, row, tw, nrow, 0, r, g, b, a);
}
}
for (row = 0; row < h; row += th)
{
nrow = (row + th > h ? h - row : th);
for (col = 0; col < w; col += tw)
{
if (TIFFReadTile(tif, r, col, row, 0, 0) < 0 && img->stoponerr)
break;
if (TIFFReadTile(tif, g, col, row, 0, 1) < 0 && img->stoponerr)
break;
if (TIFFReadTile(tif, b, col, row, 0, 2) < 0 && img->stoponerr)
break;
if (alpha && TIFFReadTile(tif, a, col, row, 0, 3) < 0 &&
img->stoponerr)
break;
if (col + tw > w)
{
/*
* Tile is clipped horizontally. Calculate
* visible portion and skewing factors.
*/
uint32_t npix = w - col;
fromskew = tw - npix;
(*callback)(img, udata, col, row, npix, nrow, fromskew, r, g, b,
a);
}
else
{
(*callback)(img, udata, col, row, tw, nrow, 0, r, g, b, a);
}
}
}
_TIFFfree(buf);
return (1);
@@ -368,35 +401,38 @@ gtTileSeparate(TIFFImageIter* img, void *udata, uint32_t w, uint32_t h)
* PlanarConfiguration contiguous if SamplesPerPixel > 1
* or
* SamplesPerPixel == 1
*/
static int
gtStripContig(TIFFImageIter* img, void *udata, uint32_t w, uint32_t h)
*/
static int gtStripContig(TIFFImageIter *img, void *udata, uint32_t w,
uint32_t h)
{
TIFF* tif = img->tif;
TIFF *tif = img->tif;
ImageIterTileContigRoutine callback = img->callback.contig;
uint16_t orientation;
uint32_t row, nrow;
u_char* buf;
u_char *buf;
uint32_t rowsperstrip;
uint32_t imagewidth = img->width;
tsize_t scanline;
int32_t fromskew;
buf = (u_char*) _TIFFmalloc(TIFFStripSize(tif));
if (buf == 0) {
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for strip buffer");
return (0);
buf = (u_char *)_TIFFmalloc(TIFFStripSize(tif));
if (buf == 0)
{
TIFFErrorExtR(tif, TIFFFileName(tif), "No space for strip buffer");
return (0);
}
orientation = img->orientation;
TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
scanline = TIFFScanlineSize(tif);
fromskew = (w < imagewidth ? imagewidth - w : 0);
for (row = 0; row < h; row += rowsperstrip) {
nrow = (row + rowsperstrip > h ? h - row : rowsperstrip);
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 0),
buf, nrow*scanline) < 0 && img->stoponerr)
break;
(*callback)(img, udata, 0, row, w, nrow, fromskew, buf);
for (row = 0; row < h; row += rowsperstrip)
{
nrow = (row + rowsperstrip > h ? h - row : rowsperstrip);
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 0), buf,
nrow * scanline) < 0 &&
img->stoponerr)
break;
(*callback)(img, udata, 0, row, w, nrow, fromskew, buf);
}
_TIFFfree(buf);
return (1);
@@ -408,10 +444,10 @@ gtStripContig(TIFFImageIter* img, void *udata, uint32_t w, uint32_t h)
* PlanarConfiguration separated
* We assume that all such images are RGB.
*/
static int
gtStripSeparate(TIFFImageIter* img, void *udata, uint32_t w, uint32_t h)
static int gtStripSeparate(TIFFImageIter *img, void *udata, uint32_t w,
uint32_t h)
{
TIFF* tif = img->tif;
TIFF *tif = img->tif;
ImageIterTileSeparateRoutine callback = img->callback.separate;
uint16_t orientation;
u_char *buf;
@@ -425,36 +461,41 @@ gtStripSeparate(TIFFImageIter* img, void *udata, uint32_t w, uint32_t h)
int alpha = img->alpha;
stripsize = TIFFStripSize(tif);
r = buf = (u_char *)_TIFFmalloc(4*stripsize);
if (buf == 0) {
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer");
return (0);
r = buf = (u_char *)_TIFFmalloc(4 * stripsize);
if (buf == 0)
{
TIFFErrorExtR(tif, TIFFFileName(tif), "No space for tile buffer");
return (0);
}
g = r + stripsize;
b = g + stripsize;
a = b + stripsize;
if (!alpha)
memset(a, 0xff, stripsize);
memset(a, 0xff, stripsize);
orientation = img->orientation;
TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
scanline = TIFFScanlineSize(tif);
fromskew = (w < imagewidth ? imagewidth - w : 0);
for (row = 0; row < h; row += rowsperstrip) {
nrow = (row + rowsperstrip > h ? h - row : rowsperstrip);
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 0),
r, nrow*scanline) < 0 && img->stoponerr)
break;
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 1),
g, nrow*scanline) < 0 && img->stoponerr)
break;
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 2),
b, nrow*scanline) < 0 && img->stoponerr)
break;
if (alpha &&
(TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 3),
a, nrow*scanline) < 0 && img->stoponerr))
break;
(*callback)(img, udata, 0, row, w, nrow, fromskew, r, g, b, a);
for (row = 0; row < h; row += rowsperstrip)
{
nrow = (row + rowsperstrip > h ? h - row : rowsperstrip);
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 0), r,
nrow * scanline) < 0 &&
img->stoponerr)
break;
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 1), g,
nrow * scanline) < 0 &&
img->stoponerr)
break;
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 2), b,
nrow * scanline) < 0 &&
img->stoponerr)
break;
if (alpha && (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 3),
a, nrow * scanline) < 0 &&
img->stoponerr))
break;
(*callback)(img, udata, 0, row, w, nrow, fromskew, r, g, b, a);
}
_TIFFfree(buf);
return (1);
@@ -462,18 +503,18 @@ gtStripSeparate(TIFFImageIter* img, void *udata, uint32_t w, uint32_t h)
DECLAREContigCallbackFunc(TestContigCallback)
{
printf("Contig Callback called with x = %d, y = %d, w = %d, h = %d, fromskew = %d\n",
x, y, w, h, fromskew);
printf("Contig Callback called with x = %d, y = %d, w = %d, h = %d, "
"fromskew = %d\n",
x, y, w, h, fromskew);
}
DECLARESepCallbackFunc(TestSepCallback)
{
printf("Sep Callback called with x = %d, y = %d, w = %d, h = %d, fromskew = %d\n",
x, y, w, h, fromskew);
printf("Sep Callback called with x = %d, y = %d, w = %d, h = %d, fromskew "
"= %d\n",
x, y, w, h, fromskew);
}
#ifdef MAIN
main(int argc, char **argv)
{
@@ -489,35 +530,35 @@ main(int argc, char **argv)
unsigned char *ColorMap;
unsigned char *data;
if (argc < 2) {
fprintf(stderr,"usage: %s tiff_file\n",argv[0]);
exit(1);
if (argc < 2)
{
fprintf(stderr, "usage: %s tiff_file\n", argv[0]);
exit(1);
}
tif = (TIFF *)PLIGetImage(argv[1], (void *) &data, &ColorMap,
&nx, &ny, &BitsPerSample, &SamplesPerPixel,
&isColorMapped, &isPliFile);
if (tif != NULL) {
tif = (TIFF *)PLIGetImage(argv[1], (void *)&data, &ColorMap, &nx, &ny,
&BitsPerSample, &SamplesPerPixel, &isColorMapped,
&isPliFile);
if (tif != NULL)
{
if (TIFFImageIterBegin(&img, tif, stop, emsg)) {
/* Here need to set data and callback function! */
if (img.isContig) {
img.callback = TestContigCallback;
} else {
img.callback = TestSepCallback;
}
ok = TIFFImageIterGet(&img, NULL, img.width, img.height);
TIFFImageIterEnd(&img);
} else {
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), emsg);
}
if (TIFFImageIterBegin(&img, tif, stop, emsg))
{
/* Here need to set data and callback function! */
if (img.isContig)
{
img.callback = TestContigCallback;
}
else
{
img.callback = TestSepCallback;
}
ok = TIFFImageIterGet(&img, NULL, img.width, img.height);
TIFFImageIterEnd(&img);
}
else
{
TIFFErrorExtR(tif, TIFFFileName(tif), emsg);
}
}
}
#endif
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+39 -52
View File
@@ -7,58 +7,45 @@ typedef struct _TIFFImageIter TIFFImageIter;
img->samplesperpixel consecutive samples each containing img->bitspersample
bits of data. The array pp is ordered in h consecutive rows of w+fromskew
pixels each. */
typedef void (*ImageIterTileContigRoutine)
(TIFFImageIter*, void *, uint32_t, uint32_t, uint32_t, uint32_t, int32_t,
unsigned char*);
#define DECLAREContigCallbackFunc(name) \
static void name(\
TIFFImageIter* img, \
void* user_data, \
uint32_t x, uint32_t y, \
uint32_t w, uint32_t h, \
int32_t fromskew, \
u_char* pp \
)
typedef void (*ImageIterTileContigRoutine)(TIFFImageIter *, void *, uint32_t,
uint32_t, uint32_t, uint32_t,
int32_t, unsigned char *);
#define DECLAREContigCallbackFunc(name) \
static void name(TIFFImageIter *img, void *user_data, uint32_t x, \
uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, \
u_char *pp)
typedef void (*ImageIterTileSeparateRoutine)
(TIFFImageIter*, void *, uint32_t, uint32_t, uint32_t, uint32_t, int32_t,
unsigned char*, unsigned char*, unsigned char*, unsigned char*);
#define DECLARESepCallbackFunc(name) \
static void name(\
TIFFImageIter* img, \
void* user_data, \
uint32_t x, uint32_t y, \
uint32_t w, uint32_t h,\
int32_t fromskew, \
u_char* r, u_char* g, u_char* b, u_char* a\
)
typedef void (*ImageIterTileSeparateRoutine)(TIFFImageIter *, void *, uint32_t,
uint32_t, uint32_t, uint32_t,
int32_t, unsigned char *,
unsigned char *, unsigned char *,
unsigned char *);
#define DECLARESepCallbackFunc(name) \
static void name(TIFFImageIter *img, void *user_data, uint32_t x, \
uint32_t y, uint32_t w, uint32_t h, int32_t fromskew, \
u_char *r, u_char *g, u_char *b, u_char *a)
struct _TIFFImageIter {
TIFF* tif; /* image handle */
int stoponerr; /* stop on read error */
int isContig; /* data is packed/separate */
int alpha; /* type of alpha data present */
uint32_t width; /* image width */
uint32_t height; /* image height */
uint16_t bitspersample; /* image bits/sample */
uint16_t samplesperpixel; /* image samples/pixel */
uint16_t orientation; /* image orientation */
uint16_t photometric; /* image photometric interp */
uint16_t* redcmap; /* colormap palette */
uint16_t* greencmap;
uint16_t* bluecmap;
/* get image data routine */
int (*get)(TIFFImageIter*, void *udata, uint32_t, uint32_t);
union {
void (*any)(TIFFImageIter*);
ImageIterTileContigRoutine contig;
ImageIterTileSeparateRoutine separate;
} callback; /* fn to exec for each block */
struct _TIFFImageIter
{
TIFF *tif; /* image handle */
int stoponerr; /* stop on read error */
int isContig; /* data is packed/separate */
int alpha; /* type of alpha data present */
uint32_t width; /* image width */
uint32_t height; /* image height */
uint16_t bitspersample; /* image bits/sample */
uint16_t samplesperpixel; /* image samples/pixel */
uint16_t orientation; /* image orientation */
uint16_t photometric; /* image photometric interp */
uint16_t *redcmap; /* colormap palette */
uint16_t *greencmap;
uint16_t *bluecmap;
/* get image data routine */
int (*get)(TIFFImageIter *, void *udata, uint32_t, uint32_t);
union
{
void (*any)(TIFFImageIter *);
ImageIterTileContigRoutine contig;
ImageIterTileSeparateRoutine separate;
} callback; /* fn to exec for each block */
};
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+117 -127
View File
@@ -43,157 +43,152 @@ static char sccsid[] = "@(#)ras2tif.c 1.2 90/03/06";
* real file since seek(2) is used.
*/
#include "tiffio.h"
#include <pixrect/pixrect_hs.h>
#include <stdio.h>
#include <sys/time.h>
#include <pixrect/pixrect_hs.h>
#include "tiffio.h"
typedef int boolean;
#define True (1)
#define False (0)
#define SCALE(x) (((x)*((1L<<16)-1))/255)
#define SCALE(x) (((x) * ((1L << 16) - 1)) / 255)
boolean Verbose = False;
boolean dummyinput = False;
char *pname; /* program name (used for error messages) */
boolean Verbose = False;
boolean dummyinput = False;
char *pname; /* program name (used for error messages) */
void
error(s1, s2)
char *s1,
*s2;
void error(s1, s2) char *s1, *s2;
{
fprintf(stderr, s1, pname, s2);
exit(1);
}
void
usage()
{
error("usage: %s -[vq] [-|rasterfile] TIFFfile\n", NULL);
}
void usage() { error("usage: %s -[vq] [-|rasterfile] TIFFfile\n", NULL); }
main(argc, argv)
int argc;
char *argv[];
main(argc, argv) int argc;
char *argv[];
{
char *inf = NULL;
char *outf = NULL;
FILE *fp;
int depth,
i;
long row;
TIFF *tif;
Pixrect *pix; /* The Sun Pixrect */
colormap_t Colormap; /* The Pixrect Colormap */
u_short red[256],
green[256],
blue[256];
struct tm *ct;
char *inf = NULL;
char *outf = NULL;
FILE *fp;
int depth, i;
long row;
TIFF *tif;
Pixrect *pix; /* The Sun Pixrect */
colormap_t Colormap; /* The Pixrect Colormap */
u_short red[256], green[256], blue[256];
struct tm *ct;
struct timeval tv;
long width,
height;
long rowsperstrip;
int year;
short photometric;
short samplesperpixel;
short bitspersample;
int bpsl;
long width, height;
long rowsperstrip;
int year;
short photometric;
short samplesperpixel;
short bitspersample;
int bpsl;
static char *version = "ras2tif 1.0";
static char *datetime = "1990:01:01 12:00:00";
gettimeofday(&tv, (struct timezone *) NULL);
gettimeofday(&tv, (struct timezone *)NULL);
ct = localtime(&tv.tv_sec);
year=1900 + ct->tm_year;
sprintf(datetime, "%04d:%02d:%02d %02d:%02d:%02d",
year, ct->tm_mon + 1, ct->tm_mday,
ct->tm_hour, ct->tm_min, ct->tm_sec);
year = 1900 + ct->tm_year;
sprintf(datetime, "%04d:%02d:%02d %02d:%02d:%02d", year, ct->tm_mon + 1,
ct->tm_mday, ct->tm_hour, ct->tm_min, ct->tm_sec);
setbuf(stderr, NULL);
pname = argv[0];
while (--argc) {
if ((++argv)[0][0] == '-') {
switch (argv[0][1]) {
case 'v':
Verbose = True;
break;
case 'q':
usage();
break;
case '\0':
if (inf == NULL)
dummyinput = True;
else
usage();
break;
default:
fprintf(stderr, "%s: illegal option -%c.\n", pname,
argv[0][1]);
exit(1);
}
} else if (inf == NULL && !dummyinput) {
inf = argv[0];
} else if (outf == NULL)
outf = argv[0];
else
usage();
while (--argc)
{
if ((++argv)[0][0] == '-')
{
switch (argv[0][1])
{
case 'v':
Verbose = True;
break;
case 'q':
usage();
break;
case '\0':
if (inf == NULL)
dummyinput = True;
else
usage();
break;
default:
fprintf(stderr, "%s: illegal option -%c.\n", pname,
argv[0][1]);
exit(1);
}
}
else if (inf == NULL && !dummyinput)
{
inf = argv[0];
}
else if (outf == NULL)
outf = argv[0];
else
usage();
}
if (outf == NULL)
error("%s: can't write output file to a stream.\n", NULL);
error("%s: can't write output file to a stream.\n", NULL);
if (dummyinput || inf == NULL) {
inf = "Standard Input";
fp = stdin;
} else if ((fp = fopen(inf, "r")) == NULL)
error("%s: %s couldn't be opened.\n", inf);
if (dummyinput || inf == NULL)
{
inf = "Standard Input";
fp = stdin;
}
else if ((fp = fopen(inf, "r")) == NULL)
error("%s: %s couldn't be opened.\n", inf);
if (Verbose)
fprintf(stderr, "Reading rasterfile from %s...", inf);
fprintf(stderr, "Reading rasterfile from %s...", inf);
pix = pr_load(fp, &Colormap);
if (pix == NULL)
error("%s: %s is not a raster file.\n", inf);
error("%s: %s is not a raster file.\n", inf);
if (Verbose)
fprintf(stderr, "done.\n");
fprintf(stderr, "done.\n");
if (Verbose)
fprintf(stderr, "Writing %s...", outf);
fprintf(stderr, "Writing %s...", outf);
tif = TIFFOpen(outf, "w");
if (tif == NULL)
error("%s: error opening TIFF file %s", outf);
error("%s: error opening TIFF file %s", outf);
width = pix->pr_width;
height = pix->pr_height;
depth = pix->pr_depth;
switch (depth) {
case 1:
samplesperpixel = 1;
bitspersample = 1;
photometric = PHOTOMETRIC_MINISBLACK;
break;
case 8:
samplesperpixel = 1;
bitspersample = 8;
photometric = PHOTOMETRIC_PALETTE;
break;
case 24:
samplesperpixel = 3;
bitspersample = 8;
photometric = PHOTOMETRIC_RGB;
break;
case 32:
samplesperpixel = 4;
bitspersample = 8;
photometric = PHOTOMETRIC_RGB;
break;
default:
error("%s: bogus depth: %d\n", depth);
switch (depth)
{
case 1:
samplesperpixel = 1;
bitspersample = 1;
photometric = PHOTOMETRIC_MINISBLACK;
break;
case 8:
samplesperpixel = 1;
bitspersample = 8;
photometric = PHOTOMETRIC_PALETTE;
break;
case 24:
samplesperpixel = 3;
bitspersample = 8;
photometric = PHOTOMETRIC_RGB;
break;
case 32:
samplesperpixel = 4;
bitspersample = 8;
photometric = PHOTOMETRIC_RGB;
break;
default:
error("%s: bogus depth: %d\n", depth);
}
bpsl = ((depth * width + 15) >> 3) & ~1;
@@ -217,38 +212,33 @@ main(argc, argv)
memset(red, 0, sizeof(red));
memset(green, 0, sizeof(green));
memset(blue, 0, sizeof(blue));
if (depth == 8) {
TIFFSetField(tif, TIFFTAG_COLORMAP, red, green, blue);
for (i = 0; i < Colormap.length; i++) {
red[i] = SCALE(Colormap.map[0][i]);
green[i] = SCALE(Colormap.map[1][i]);
blue[i] = SCALE(Colormap.map[2][i]);
}
if (depth == 8)
{
TIFFSetField(tif, TIFFTAG_COLORMAP, red, green, blue);
for (i = 0; i < Colormap.length; i++)
{
red[i] = SCALE(Colormap.map[0][i]);
green[i] = SCALE(Colormap.map[1][i]);
blue[i] = SCALE(Colormap.map[2][i]);
}
}
if (Verbose)
fprintf(stderr, "%dx%dx%d image, ", width, height, depth);
fprintf(stderr, "%dx%dx%d image, ", width, height, depth);
for (row = 0; row < height; row++)
if (TIFFWriteScanline(tif,
(u_char *) mprd_addr(mpr_d(pix), 0, row),
row, 0) < 0) {
fprintf("failed a scanline write (%d)\n", row);
break;
}
if (TIFFWriteScanline(tif, (u_char *)mprd_addr(mpr_d(pix), 0, row), row,
0) < 0)
{
fprintf("failed a scanline write (%d)\n", row);
break;
}
TIFFFlushData(tif);
TIFFClose(tif);
if (Verbose)
fprintf(stderr, "done.\n");
fprintf(stderr, "done.\n");
pr_destroy(pix);
exit(0);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+219 -226
View File
@@ -40,302 +40,295 @@
* file since seek(2) is used.
*/
#include <stdio.h>
#include <pixrect/pixrect_hs.h>
#include "tiffio.h"
#include <pixrect/pixrect_hs.h>
#include <stdio.h>
typedef int boolean;
#define True (1)
#define False (0)
#define CVT(x) (((x) * 255) / ((1L<<16)-1))
#define CVT(x) (((x)*255) / ((1L << 16) - 1))
boolean Verbose = False;
char *pname; /* program name (used for error messages) */
boolean Verbose = False;
char *pname; /* program name (used for error messages) */
void
error(s1, s2)
char *s1,
*s2;
void error(s1, s2) char *s1, *s2;
{
fprintf(stderr, s1, pname, s2);
exit(1);
}
void
usage()
{
error("usage: %s -[vq] TIFFfile [rasterfile]\n", NULL);
}
void usage() { error("usage: %s -[vq] TIFFfile [rasterfile]\n", NULL); }
main(argc, argv)
int argc;
char *argv[];
main(argc, argv) int argc;
char *argv[];
{
char *inf = NULL;
char *outf = NULL;
FILE *fp;
long width,
height;
int depth,
numcolors;
char *inf = NULL;
char *outf = NULL;
FILE *fp;
long width, height;
int depth, numcolors;
register TIFF *tif;
TIFFDirectory *td;
register u_char *inp,
*outp;
register int col,
i;
register u_char *inp, *outp;
register int col, i;
register long row;
u_char *Map = NULL;
u_char *buf;
short bitspersample;
short samplesperpixel;
short photometric;
u_short *redcolormap,
*bluecolormap,
*greencolormap;
u_char *Map = NULL;
u_char *buf;
short bitspersample;
short samplesperpixel;
short photometric;
u_short *redcolormap, *bluecolormap, *greencolormap;
Pixrect *pix; /* The Sun Pixrect */
colormap_t Colormap; /* The Pixrect Colormap */
u_char red[256],
green[256],
blue[256];
Pixrect *pix; /* The Sun Pixrect */
colormap_t Colormap; /* The Pixrect Colormap */
u_char red[256], green[256], blue[256];
setbuf(stderr, NULL);
pname = argv[0];
while (--argc) {
if ((++argv)[0][0] == '-')
switch (argv[0][1]) {
case 'v':
Verbose = True;
break;
case 'q':
usage();
break;
default:
fprintf(stderr, "%s: illegal option -%c.\n", pname,
argv[0][1]);
exit(1);
}
else if (inf == NULL)
inf = argv[0];
else if (outf == NULL)
outf = argv[0];
else
usage();
while (--argc)
{
if ((++argv)[0][0] == '-')
switch (argv[0][1])
{
case 'v':
Verbose = True;
break;
case 'q':
usage();
break;
default:
fprintf(stderr, "%s: illegal option -%c.\n", pname,
argv[0][1]);
exit(1);
}
else if (inf == NULL)
inf = argv[0];
else if (outf == NULL)
outf = argv[0];
else
usage();
}
if (inf == NULL)
error("%s: can't read input file from a stream.\n", NULL);
error("%s: can't read input file from a stream.\n", NULL);
if (Verbose)
fprintf(stderr, "Reading %s...", inf);
fprintf(stderr, "Reading %s...", inf);
tif = TIFFOpen(inf, "r");
if (tif == NULL)
error("%s: error opening TIFF file %s", inf);
error("%s: error opening TIFF file %s", inf);
if (Verbose)
TIFFPrintDirectory(tif, stderr, True, False, False);
TIFFPrintDirectory(tif, stderr, True, False, False);
TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample);
if (bitspersample > 8)
error("%s: can't handle more than 8-bits per sample\n", NULL);
error("%s: can't handle more than 8-bits per sample\n", NULL);
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
switch (samplesperpixel) {
case 1:
if (bitspersample == 1)
depth = 1;
else
depth = 8;
break;
case 3:
case 4:
depth = 24;
break;
default:
error("%s: only handle 1-channel gray scale or 3-channel color\n");
switch (samplesperpixel)
{
case 1:
if (bitspersample == 1)
depth = 1;
else
depth = 8;
break;
case 3:
case 4:
depth = 24;
break;
default:
error("%s: only handle 1-channel gray scale or 3-channel color\n");
}
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
if (Verbose)
fprintf(stderr, "%dx%dx%d image, ", width, height, depth);
fprintf(stderr, "%dx%dx%d image, ", width, height, depth);
if (Verbose)
fprintf(stderr, "%d bits/sample, %d samples/pixel, ",
bitspersample, samplesperpixel);
fprintf(stderr, "%d bits/sample, %d samples/pixel, ", bitspersample,
samplesperpixel);
pix = mem_create(width, height, depth);
if (pix == (Pixrect *) NULL)
error("%s: can't allocate memory for output pixrect...\n", NULL);
if (pix == (Pixrect *)NULL)
error("%s: can't allocate memory for output pixrect...\n", NULL);
numcolors = (1 << bitspersample);
TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric);
if (numcolors == 2) {
if (Verbose)
fprintf(stderr, "monochrome ");
Colormap.type = RMT_NONE;
Colormap.length = 0;
Colormap.map[0] = Colormap.map[1] = Colormap.map[2] = NULL;
} else {
switch (photometric) {
case PHOTOMETRIC_MINISBLACK:
if (Verbose)
fprintf(stderr, "%d graylevels (min=black), ", numcolors);
Map = (u_char *) malloc(numcolors * sizeof(u_char));
for (i = 0; i < numcolors; i++)
Map[i] = (255 * i) / numcolors;
Colormap.type = RMT_EQUAL_RGB;
Colormap.length = numcolors;
Colormap.map[0] = Colormap.map[1] = Colormap.map[2] = Map;
break;
case PHOTOMETRIC_MINISWHITE:
if (Verbose)
fprintf(stderr, "%d graylevels (min=white), ", numcolors);
Map = (u_char *) malloc(numcolors * sizeof(u_char));
for (i = 0; i < numcolors; i++)
Map[i] = 255 - ((255 * i) / numcolors);
Colormap.type = RMT_EQUAL_RGB;
Colormap.length = numcolors;
Colormap.map[0] = Colormap.map[1] = Colormap.map[2] = Map;
break;
case PHOTOMETRIC_RGB:
if (Verbose)
fprintf(stderr, "truecolor ");
Colormap.type = RMT_NONE;
Colormap.length = 0;
Colormap.map[0] = Colormap.map[1] = Colormap.map[2] = NULL;
break;
case PHOTOMETRIC_PALETTE:
if (Verbose)
fprintf(stderr, "colormapped ");
Colormap.type = RMT_EQUAL_RGB;
Colormap.length = numcolors;
memset(red, 0, sizeof(red));
memset(green, 0, sizeof(green));
memset(blue, 0, sizeof(blue));
TIFFGetField(tif, TIFFTAG_COLORMAP,
&redcolormap, &greencolormap, &bluecolormap);
for (i = 0; i < numcolors; i++) {
red[i] = (u_char) CVT(redcolormap[i]);
green[i] = (u_char) CVT(greencolormap[i]);
blue[i] = (u_char) CVT(bluecolormap[i]);
}
Colormap.map[0] = red;
Colormap.map[1] = green;
Colormap.map[2] = blue;
break;
case PHOTOMETRIC_MASK:
error("%s: Don't know how to handle PHOTOMETRIC_MASK\n");
break;
case PHOTOMETRIC_DEPTH:
error("%s: Don't know how to handle PHOTOMETRIC_DEPTH\n");
break;
default:
error("%s: unknown photometric (cmap): %d\n", photometric);
}
if (numcolors == 2)
{
if (Verbose)
fprintf(stderr, "monochrome ");
Colormap.type = RMT_NONE;
Colormap.length = 0;
Colormap.map[0] = Colormap.map[1] = Colormap.map[2] = NULL;
}
else
{
switch (photometric)
{
case PHOTOMETRIC_MINISBLACK:
if (Verbose)
fprintf(stderr, "%d graylevels (min=black), ", numcolors);
Map = (u_char *)malloc(numcolors * sizeof(u_char));
for (i = 0; i < numcolors; i++)
Map[i] = (255 * i) / numcolors;
Colormap.type = RMT_EQUAL_RGB;
Colormap.length = numcolors;
Colormap.map[0] = Colormap.map[1] = Colormap.map[2] = Map;
break;
case PHOTOMETRIC_MINISWHITE:
if (Verbose)
fprintf(stderr, "%d graylevels (min=white), ", numcolors);
Map = (u_char *)malloc(numcolors * sizeof(u_char));
for (i = 0; i < numcolors; i++)
Map[i] = 255 - ((255 * i) / numcolors);
Colormap.type = RMT_EQUAL_RGB;
Colormap.length = numcolors;
Colormap.map[0] = Colormap.map[1] = Colormap.map[2] = Map;
break;
case PHOTOMETRIC_RGB:
if (Verbose)
fprintf(stderr, "truecolor ");
Colormap.type = RMT_NONE;
Colormap.length = 0;
Colormap.map[0] = Colormap.map[1] = Colormap.map[2] = NULL;
break;
case PHOTOMETRIC_PALETTE:
if (Verbose)
fprintf(stderr, "colormapped ");
Colormap.type = RMT_EQUAL_RGB;
Colormap.length = numcolors;
memset(red, 0, sizeof(red));
memset(green, 0, sizeof(green));
memset(blue, 0, sizeof(blue));
TIFFGetField(tif, TIFFTAG_COLORMAP, &redcolormap,
&greencolormap, &bluecolormap);
for (i = 0; i < numcolors; i++)
{
red[i] = (u_char)CVT(redcolormap[i]);
green[i] = (u_char)CVT(greencolormap[i]);
blue[i] = (u_char)CVT(bluecolormap[i]);
}
Colormap.map[0] = red;
Colormap.map[1] = green;
Colormap.map[2] = blue;
break;
case PHOTOMETRIC_MASK:
error("%s: Don't know how to handle PHOTOMETRIC_MASK\n");
break;
case PHOTOMETRIC_DEPTH:
error("%s: Don't know how to handle PHOTOMETRIC_DEPTH\n");
break;
default:
error("%s: unknown photometric (cmap): %d\n", photometric);
}
}
buf = (u_char *) malloc(TIFFScanlineSize(tif));
buf = (u_char *)malloc(TIFFScanlineSize(tif));
if (buf == NULL)
error("%s: can't allocate memory for scanline buffer...\n", NULL);
error("%s: can't allocate memory for scanline buffer...\n", NULL);
for (row = 0; row < height; row++) {
if (TIFFReadScanline(tif, buf, row, 0) < 0)
error("%s: bad data read on line: %d\n", row);
inp = buf;
outp = (u_char *) mprd_addr(mpr_d(pix), 0, row);
switch (photometric) {
case PHOTOMETRIC_RGB:
if (samplesperpixel == 4)
for (col = 0; col < width; col++) {
*outp++ = *inp++; /* Blue */
*outp++ = *inp++; /* Green */
*outp++ = *inp++; /* Red */
inp++; /* skip alpha channel */
}
else
for (col = 0; col < width; col++) {
*outp++ = *inp++; /* Blue */
*outp++ = *inp++; /* Green */
*outp++ = *inp++; /* Red */
}
break;
case PHOTOMETRIC_MINISWHITE:
case PHOTOMETRIC_MINISBLACK:
switch (bitspersample) {
case 1:
for (col = 0; col < ((width + 7) / 8); col++)
*outp++ = *inp++;
break;
case 2:
for (col = 0; col < ((width + 3) / 4); col++) {
*outp++ = (*inp >> 6) & 3;
*outp++ = (*inp >> 4) & 3;
*outp++ = (*inp >> 2) & 3;
*outp++ = *inp++ & 3;
}
break;
case 4:
for (col = 0; col < width / 2; col++) {
*outp++ = *inp >> 4;
*outp++ = *inp++ & 0xf;
}
break;
case 8:
for (col = 0; col < width; col++)
*outp++ = *inp++;
break;
default:
error("%s: bad bits/sample: %d\n", bitspersample);
}
break;
case PHOTOMETRIC_PALETTE:
memcpy(outp, inp, width);
break;
default:
error("%s: unknown photometric (write): %d\n", photometric);
}
for (row = 0; row < height; row++)
{
if (TIFFReadScanline(tif, buf, row, 0) < 0)
error("%s: bad data read on line: %d\n", row);
inp = buf;
outp = (u_char *)mprd_addr(mpr_d(pix), 0, row);
switch (photometric)
{
case PHOTOMETRIC_RGB:
if (samplesperpixel == 4)
for (col = 0; col < width; col++)
{
*outp++ = *inp++; /* Blue */
*outp++ = *inp++; /* Green */
*outp++ = *inp++; /* Red */
inp++; /* skip alpha channel */
}
else
for (col = 0; col < width; col++)
{
*outp++ = *inp++; /* Blue */
*outp++ = *inp++; /* Green */
*outp++ = *inp++; /* Red */
}
break;
case PHOTOMETRIC_MINISWHITE:
case PHOTOMETRIC_MINISBLACK:
switch (bitspersample)
{
case 1:
for (col = 0; col < ((width + 7) / 8); col++)
*outp++ = *inp++;
break;
case 2:
for (col = 0; col < ((width + 3) / 4); col++)
{
*outp++ = (*inp >> 6) & 3;
*outp++ = (*inp >> 4) & 3;
*outp++ = (*inp >> 2) & 3;
*outp++ = *inp++ & 3;
}
break;
case 4:
for (col = 0; col < width / 2; col++)
{
*outp++ = *inp >> 4;
*outp++ = *inp++ & 0xf;
}
break;
case 8:
for (col = 0; col < width; col++)
*outp++ = *inp++;
break;
default:
error("%s: bad bits/sample: %d\n", bitspersample);
}
break;
case PHOTOMETRIC_PALETTE:
memcpy(outp, inp, width);
break;
default:
error("%s: unknown photometric (write): %d\n", photometric);
}
}
free((char *) buf);
free((char *)buf);
if (Verbose)
fprintf(stderr, "done.\n");
fprintf(stderr, "done.\n");
if (outf == NULL || strcmp(outf, "Standard Output") == 0) {
outf = "Standard Output";
fp = stdout;
} else {
if (!(fp = fopen(outf, "w")))
error("%s: %s couldn't be opened for writing.\n", outf);
if (outf == NULL || strcmp(outf, "Standard Output") == 0)
{
outf = "Standard Output";
fp = stdout;
}
else
{
if (!(fp = fopen(outf, "w")))
error("%s: %s couldn't be opened for writing.\n", outf);
}
if (Verbose)
fprintf(stderr, "Writing rasterfile in %s...", outf);
fprintf(stderr, "Writing rasterfile in %s...", outf);
if (pr_dump(pix, fp, &Colormap, RT_BYTE_ENCODED, 0) == PIX_ERR)
error("%s: error writing Sun Rasterfile: %s\n", outf);
error("%s: error writing Sun Rasterfile: %s\n", outf);
if (Verbose)
fprintf(stderr, "done.\n");
fprintf(stderr, "done.\n");
pr_destroy(pix);
if (fp != stdout)
fclose(fp);
fclose(fp);
exit(0);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+146 -170
View File
@@ -2,237 +2,213 @@
#include "tiffstream.h"
const char* TiffStream::m_name = "TiffStream";
const char *TiffStream::m_name = "TiffStream";
TiffStream::TiffStream()
{
m_tif = NULL;
m_inStream = NULL;
m_outStream = NULL;
m_ioStream = NULL;
m_outStream = NULL;
m_ioStream = NULL;
m_streamLength = 0;
m_streamLength = 0;
m_this = reinterpret_cast<thandle_t>(this);
m_this = reinterpret_cast<thandle_t>(this);
};
TiffStream::~TiffStream()
{
if(m_tif != NULL) TIFFClose(m_tif);
if (m_tif != NULL)
TIFFClose(m_tif);
}
TIFF*
TiffStream::makeFileStream(istream* str)
TIFF *TiffStream::makeFileStream(istream *str)
{
m_inStream = str;
m_outStream = NULL;
m_ioStream = NULL;
m_outStream = NULL;
m_ioStream = NULL;
m_streamLength = getSize(m_this);
m_tif = TIFFClientOpen(m_name,
"r",
m_this,
read,
write,
seek,
close,
size,
map,
unmap);
m_tif = TIFFClientOpen(m_name, "r", m_this, read, write, seek, close, size,
map, unmap);
return m_tif;
}
TIFF*
TiffStream::makeFileStream(ostream* str)
TIFF *TiffStream::makeFileStream(ostream *str)
{
m_inStream = NULL;
m_inStream = NULL;
m_outStream = str;
m_ioStream = NULL;
m_streamLength = getSize(m_this);
m_ioStream = NULL;
m_streamLength = getSize(m_this);
m_tif = TIFFClientOpen(m_name,
"w",
m_this,
read,
write,
seek,
close,
size,
map,
unmap);
m_tif = TIFFClientOpen(m_name, "w", m_this, read, write, seek, close, size,
map, unmap);
return m_tif;
}
TIFF*
TiffStream::makeFileStream(iostream* str)
TIFF *TiffStream::makeFileStream(iostream *str)
{
m_inStream = NULL;
m_outStream = NULL;
m_inStream = NULL;
m_outStream = NULL;
m_ioStream = str;
m_streamLength = getSize(m_this);
m_streamLength = getSize(m_this);
m_tif = TIFFClientOpen(m_name,
"r+w",
m_this,
read,
write,
seek,
close,
size,
map,
unmap);
m_tif = TIFFClientOpen(m_name, "r+w", m_this, read, write, seek, close,
size, map, unmap);
return m_tif;
}
tsize_t
TiffStream::read(thandle_t fd, tdata_t buf, tsize_t size)
tsize_t TiffStream::read(thandle_t fd, tdata_t buf, tsize_t size)
{
istream* istr;
TiffStream* ts = reinterpret_cast<TiffStream*>(fd);
if(ts->m_inStream != NULL) {
istr = ts->m_inStream;
} else if(ts->m_ioStream != NULL) {
istr = ts->m_ioStream;
}
istream *istr;
TiffStream *ts = reinterpret_cast<TiffStream *>(fd);
if (ts->m_inStream != NULL)
{
istr = ts->m_inStream;
}
else if (ts->m_ioStream != NULL)
{
istr = ts->m_ioStream;
}
int remain = ts->m_streamLength - ts->tell(fd);
int actual = remain < size ? remain : size;
istr->read(reinterpret_cast<char*>(buf), actual);
int remain = ts->m_streamLength - ts->tell(fd);
int actual = remain < size ? remain : size;
istr->read(reinterpret_cast<char *>(buf), actual);
return istr->gcount();
}
tsize_t
TiffStream::write(thandle_t fd, tdata_t buf, tsize_t size)
tsize_t TiffStream::write(thandle_t fd, tdata_t buf, tsize_t size)
{
TiffStream* ts = reinterpret_cast<TiffStream*>(fd);
ostream* ostr;
if(ts->m_outStream != NULL) {
ostr = ts->m_outStream;
} else if(ts->m_ioStream != NULL) {
ostr = ts->m_ioStream;
}
TiffStream *ts = reinterpret_cast<TiffStream *>(fd);
ostream *ostr;
if (ts->m_outStream != NULL)
{
ostr = ts->m_outStream;
}
else if (ts->m_ioStream != NULL)
{
ostr = ts->m_ioStream;
}
streampos start = ostr->tellp();
ostr->write(reinterpret_cast<const char*>(buf), size);
return ostr->tellp() - start;
streampos start = ostr->tellp();
ostr->write(reinterpret_cast<const char *>(buf), size);
return ostr->tellp() - start;
}
toff_t
TiffStream::seek(thandle_t fd, toff_t offset, int origin)
toff_t TiffStream::seek(thandle_t fd, toff_t offset, int origin)
{
TiffStream* ts = reinterpret_cast<TiffStream*>(fd);
if(ts->seekInt(fd, offset, origin) == true) return offset;
else return -1;
TiffStream *ts = reinterpret_cast<TiffStream *>(fd);
if (ts->seekInt(fd, offset, origin) == true)
return offset;
else
return -1;
}
int
TiffStream::close(thandle_t fd)
int TiffStream::close(thandle_t fd)
{
TiffStream* ts = reinterpret_cast<TiffStream*>(fd);
if(ts->m_inStream != NULL) {
ts->m_inStream = NULL;
return 0;
} else if(ts->m_outStream != NULL) {
ts->m_outStream = NULL;
return 0;
} else if(ts->m_ioStream != NULL) {
ts->m_ioStream = NULL;
return 0;
}
TiffStream *ts = reinterpret_cast<TiffStream *>(fd);
if (ts->m_inStream != NULL)
{
ts->m_inStream = NULL;
return 0;
}
else if (ts->m_outStream != NULL)
{
ts->m_outStream = NULL;
return 0;
}
else if (ts->m_ioStream != NULL)
{
ts->m_ioStream = NULL;
return 0;
}
return -1;
}
toff_t
TiffStream::size(thandle_t fd)
toff_t TiffStream::size(thandle_t fd)
{
TiffStream* ts = reinterpret_cast<TiffStream*>(fd);
TiffStream *ts = reinterpret_cast<TiffStream *>(fd);
return ts->getSize(fd);
}
int
TiffStream::map(thandle_t fd, tdata_t* phase, toff_t* psize)
int TiffStream::map(thandle_t fd, tdata_t *phase, toff_t *psize) { return 0; }
void TiffStream::unmap(thandle_t fd, tdata_t base, tsize_t size) {}
unsigned int TiffStream::getSize(thandle_t fd)
{
if (!isOpen(fd))
return 0;
unsigned int pos = tell(fd);
seekInt(fd, 0, end);
unsigned int size = tell(fd);
seekInt(fd, pos, beg);
return size;
}
unsigned int TiffStream::tell(thandle_t fd)
{
TiffStream *ts = reinterpret_cast<TiffStream *>(fd);
if (ts->m_inStream != NULL)
{
return ts->m_inStream->tellg();
}
else if (ts->m_outStream != NULL)
{
return ts->m_outStream->tellp();
}
else if (ts->m_ioStream != NULL)
{
return ts->m_ioStream->tellg();
}
return 0;
}
void
TiffStream::unmap(thandle_t fd, tdata_t base, tsize_t size)
bool TiffStream::seekInt(thandle_t fd, unsigned int offset, int origin)
{
}
if (!isOpen(fd))
return false;
unsigned int
TiffStream::getSize(thandle_t fd)
{
if(!isOpen(fd)) return 0;
ios::seek_dir org;
switch (origin)
{
case beg:
org = ios::beg;
break;
case cur:
org = ios::cur;
break;
case end:
org = ios::end;
break;
}
unsigned int pos = tell(fd);
seekInt(fd, 0, end);
unsigned int size = tell(fd);
seekInt(fd, pos, beg);
return size;
}
unsigned int
TiffStream::tell(thandle_t fd)
{
TiffStream* ts = reinterpret_cast<TiffStream*>(fd);
if(ts->m_inStream != NULL) {
return ts->m_inStream->tellg();
} else if(ts->m_outStream != NULL) {
return ts->m_outStream->tellp();
} else if(ts->m_ioStream != NULL) {
return ts->m_ioStream->tellg();
}
return 0;
}
bool
TiffStream::seekInt(thandle_t fd, unsigned int offset, int origin)
{
if(!isOpen(fd)) return false;
ios::seek_dir org;
switch(origin) {
case beg:
org = ios::beg;
break;
case cur:
org = ios::cur;
break;
case end:
org = ios::end;
break;
}
TiffStream* ts = reinterpret_cast<TiffStream*>(fd);
if(ts->m_inStream != NULL) {
ts->m_inStream->seekg(offset, org);
return true;
} else if(ts->m_outStream != NULL) {
ts->m_outStream->seekp(offset, org);
return true;
} else if(ts->m_ioStream != NULL) {
ts->m_ioStream->seekg(offset, org);
ts->m_ioStream->seekp(offset, org);
return true;
}
TiffStream *ts = reinterpret_cast<TiffStream *>(fd);
if (ts->m_inStream != NULL)
{
ts->m_inStream->seekg(offset, org);
return true;
}
else if (ts->m_outStream != NULL)
{
ts->m_outStream->seekp(offset, org);
return true;
}
else if (ts->m_ioStream != NULL)
{
ts->m_ioStream->seekg(offset, org);
ts->m_ioStream->seekp(offset, org);
return true;
}
return false;
}
bool
TiffStream::isOpen(thandle_t fd)
bool TiffStream::isOpen(thandle_t fd)
{
TiffStream* ts = reinterpret_cast<TiffStream*>(fd);
return (ts->m_inStream != NULL ||
ts->m_outStream != NULL ||
ts->m_ioStream != NULL);
}/*
* Local Variables:
* mode: c++
* c-basic-offset: 8
* fill-column: 78
* End:
*/
TiffStream *ts = reinterpret_cast<TiffStream *>(fd);
return (ts->m_inStream != NULL || ts->m_outStream != NULL ||
ts->m_ioStream != NULL);
}
+38 -44
View File
@@ -7,64 +7,58 @@
#include "tiffio.h"
class TiffStream {
class TiffStream
{
public:
public:
// ctor/dtor
TiffStream();
~TiffStream();
~TiffStream();
public:
enum SeekDir {
beg,
cur,
end,
public:
enum SeekDir
{
beg,
cur,
end,
};
public:
public:
// factory methods
TIFF* makeFileStream(iostream* str);
TIFF* makeFileStream(istream* str);
TIFF* makeFileStream(ostream* str);
TIFF *makeFileStream(iostream *str);
TIFF *makeFileStream(istream *str);
TIFF *makeFileStream(ostream *str);
public:
public:
// tiff client methods
static tsize_t read(thandle_t fd, tdata_t buf, tsize_t size);
static tsize_t write(thandle_t fd, tdata_t buf, tsize_t size);
static toff_t seek(thandle_t fd, toff_t offset, int origin);
static toff_t size(thandle_t fd);
static int close(thandle_t fd);
static int map(thandle_t fd, tdata_t* phase, toff_t* psize);
static void unmap(thandle_t fd, tdata_t base, tsize_t size);
static tsize_t read(thandle_t fd, tdata_t buf, tsize_t size);
static tsize_t write(thandle_t fd, tdata_t buf, tsize_t size);
static toff_t seek(thandle_t fd, toff_t offset, int origin);
static toff_t size(thandle_t fd);
static int close(thandle_t fd);
static int map(thandle_t fd, tdata_t *phase, toff_t *psize);
static void unmap(thandle_t fd, tdata_t base, tsize_t size);
public:
public:
// query method
TIFF* getTiffHandle() const { return m_tif; }
unsigned int getStreamLength() { return m_streamLength; }
TIFF *getTiffHandle() const { return m_tif; }
unsigned int getStreamLength() { return m_streamLength; }
private:
// internal methods
private:
// internal methods
unsigned int getSize(thandle_t fd);
unsigned int tell(thandle_t fd);
bool seekInt(thandle_t fd, unsigned int offset, int origin);
bool isOpen(thandle_t fd);
unsigned int tell(thandle_t fd);
bool seekInt(thandle_t fd, unsigned int offset, int origin);
bool isOpen(thandle_t fd);
private:
thandle_t m_this;
TIFF* m_tif;
static const char* m_name;
istream* m_inStream;
ostream* m_outStream;
iostream* m_ioStream;
int m_streamLength;
private:
thandle_t m_this;
TIFF *m_tif;
static const char *m_name;
istream *m_inStream;
ostream *m_outStream;
iostream *m_ioStream;
int m_streamLength;
};
#endif // _TIFF_STREAM_H_
/*
* Local Variables:
* mode: c++
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+22 -27
View File
@@ -5,35 +5,30 @@
#include "xtiffio.h"
#include <stdlib.h>
void main(int argc,char *argv[])
void main(int argc, char *argv[])
{
char *fname="newtif.tif";
int flags;
char *fname = "newtif.tif";
int flags;
TIFF *tif=(TIFF*)0; /* TIFF-level descriptor */
TIFF *tif = (TIFF *)0; /* TIFF-level descriptor */
if (argc > 1)
fname = argv[1];
tif = XTIFFOpen(fname, "r");
if (!tif)
goto failure;
/* We want the double array listed */
flags = TIFFPRINT_MYMULTIDOUBLES;
TIFFPrintDirectory(tif, stdout, flags);
XTIFFClose(tif);
exit(0);
if (argc>1) fname=argv[1];
tif=XTIFFOpen(fname,"r");
if (!tif) goto failure;
/* We want the double array listed */
flags = TIFFPRINT_MYMULTIDOUBLES;
TIFFPrintDirectory(tif,stdout,flags);
XTIFFClose(tif);
exit (0);
failure:
printf("failure in listtif\n");
if (tif) XTIFFClose(tif);
exit (-1);
printf("failure in listtif\n");
if (tif)
XTIFFClose(tif);
exit(-1);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+39 -51
View File
@@ -3,9 +3,8 @@
* the XTIFF extended tiff example tags.
*/
#include <stdlib.h>
#include "xtiffio.h"
#include <stdlib.h>
void SetUpTIFFDirectory(TIFF *tif);
void WriteImage(TIFF *tif);
@@ -15,63 +14,52 @@ void WriteImage(TIFF *tif);
void main()
{
TIFF *tif=(TIFF*)0; /* TIFF-level descriptor */
tif=XTIFFOpen("newtif.tif","w");
if (!tif) goto failure;
SetUpTIFFDirectory(tif);
WriteImage(tif);
XTIFFClose(tif);
exit (0);
failure:
printf("failure in maketif\n");
if (tif) XTIFFClose(tif);
exit (-1);
}
TIFF *tif = (TIFF *)0; /* TIFF-level descriptor */
tif = XTIFFOpen("newtif.tif", "w");
if (!tif)
goto failure;
SetUpTIFFDirectory(tif);
WriteImage(tif);
XTIFFClose(tif);
exit(0);
failure:
printf("failure in maketif\n");
if (tif)
XTIFFClose(tif);
exit(-1);
}
void SetUpTIFFDirectory(TIFF *tif)
{
double mymulti[6]={0.0,1.0,2.0, 3.1415926, 5.0,1.0};
uint32_t mysingle=3456;
char *ascii="This file was produced by Steven Spielberg. NOT";
double mymulti[6] = {0.0, 1.0, 2.0, 3.1415926, 5.0, 1.0};
uint32_t mysingle = 3456;
char *ascii = "This file was produced by Steven Spielberg. NOT";
TIFFSetField(tif,TIFFTAG_IMAGEWIDTH,WIDTH);
TIFFSetField(tif,TIFFTAG_IMAGELENGTH,HEIGHT);
TIFFSetField(tif,TIFFTAG_COMPRESSION,COMPRESSION_NONE);
TIFFSetField(tif,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_MINISBLACK);
TIFFSetField(tif,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);
TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE,8);
TIFFSetField(tif,TIFFTAG_ROWSPERSTRIP,20);
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, WIDTH);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, HEIGHT);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 20);
/* Install the extended TIFF tag examples */
TIFFSetField(tif,TIFFTAG_EXAMPLE_MULTI,6,mymulti);
TIFFSetField(tif,TIFFTAG_EXAMPLE_SINGLE,mysingle);
TIFFSetField(tif,TIFFTAG_EXAMPLE_ASCII,ascii);
/* Install the extended TIFF tag examples */
TIFFSetField(tif, TIFFTAG_EXAMPLE_MULTI, 6, mymulti);
TIFFSetField(tif, TIFFTAG_EXAMPLE_SINGLE, mysingle);
TIFFSetField(tif, TIFFTAG_EXAMPLE_ASCII, ascii);
}
void WriteImage(TIFF *tif)
{
int i;
char buffer[WIDTH];
memset(buffer,0,sizeof(buffer));
for (i=0;i<HEIGHT;i++)
if (!TIFFWriteScanline(tif, buffer, i, 0))
TIFFErrorExt(tif->tif_clientdata, "WriteImage","failure in WriteScanline\n");
int i;
char buffer[WIDTH];
memset(buffer, 0, sizeof(buffer));
for (i = 0; i < HEIGHT; i++)
if (!TIFFWriteScanline(tif, buffer, i, 0))
TIFFErrorExtR(tif, "WriteImage", "failure in WriteScanline\n");
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+231 -248
View File
@@ -10,14 +10,14 @@
*
* Author: Niles D. Ritter
*/
#include "xtiffiop.h"
#include <stdio.h>
/* Tiff info structure.
*
* Entry format:
* { TAGNUMBER, ReadCount, WriteCount, DataType, FIELDNUM,
* { TAGNUMBER, ReadCount, WriteCount, DataType, FIELDNUM,
* OkToChange, PassDirCountOnSet, AsciiName }
*
* For ReadCount, WriteCount, -1 = unknown; used for mult-valued
@@ -25,219 +25,216 @@
*/
static const TIFFFieldInfo xtiffFieldInfo[] = {
/* XXX Replace these example tags with your own extended tags */
{ TIFFTAG_EXAMPLE_MULTI, -1,-1, TIFF_DOUBLE, FIELD_EXAMPLE_MULTI,
TRUE, TRUE, "MyMultivaluedTag" },
{ TIFFTAG_EXAMPLE_SINGLE, 1, 1, TIFF_LONG, FIELD_EXAMPLE_SINGLE,
TRUE, FALSE, "MySingleLongTag" },
{ TIFFTAG_EXAMPLE_ASCII, -1,-1, TIFF_ASCII, FIELD_EXAMPLE_ASCII,
TRUE, FALSE, "MyAsciiTag" },
/* XXX Replace these example tags with your own extended tags */
{TIFFTAG_EXAMPLE_MULTI, -1, -1, TIFF_DOUBLE, FIELD_EXAMPLE_MULTI, TRUE,
TRUE, "MyMultivaluedTag"},
{TIFFTAG_EXAMPLE_SINGLE, 1, 1, TIFF_LONG, FIELD_EXAMPLE_SINGLE, TRUE, FALSE,
"MySingleLongTag"},
{TIFFTAG_EXAMPLE_ASCII, -1, -1, TIFF_ASCII, FIELD_EXAMPLE_ASCII, TRUE,
FALSE, "MyAsciiTag"},
};
#define N(a) (sizeof (a) / sizeof (a[0]))
#define N(a) (sizeof(a) / sizeof(a[0]))
static void
_XTIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
static void _XTIFFPrintDirectory(TIFF *tif, FILE *fd, long flags)
{
xtiff *xt = XTIFFDIR(tif);
XTIFFDirectory *xd = &xt->xtif_dir;
int i,num;
xtiff *xt = XTIFFDIR(tif);
XTIFFDirectory *xd = &xt->xtif_dir;
int i, num;
/* call the inherited method */
if (PARENT(xt,printdir))
(PARENT(xt,printdir))(tif,fd,flags);
/* call the inherited method */
if (PARENT(xt, printdir))
(PARENT(xt, printdir))(tif, fd, flags);
/* XXX Add field printing here. Replace the three example
* tags implemented below with your own.
*/
/* XXX Add field printing here. Replace the three example
* tags implemented below with your own.
*/
fprintf(fd,"--My Example Tags--\n");
fprintf(fd, "--My Example Tags--\n");
/* Our first example tag may have a lot of values, so we
* will only print them out if the TIFFPRINT_MYMULTIDOUBLES
* flag is passed into the print method.
*/
if (TIFFFieldSet(tif,FIELD_EXAMPLE_MULTI))
{
fprintf(fd, " My Multi-Valued Doubles:");
if (flags & TIFFPRINT_MYMULTIDOUBLES)
{
double *value = xd->xd_example_multi;
num = xd->xd_num_multi;
fprintf(fd,"(");
for (i=0;i<num;i++) fprintf(fd, " %lg", *value++);
fprintf(fd,")\n");
} else
fprintf(fd, "(present)\n");
}
/* Our first example tag may have a lot of values, so we
* will only print them out if the TIFFPRINT_MYMULTIDOUBLES
* flag is passed into the print method.
*/
if (TIFFFieldSet(tif, FIELD_EXAMPLE_MULTI))
{
fprintf(fd, " My Multi-Valued Doubles:");
if (flags & TIFFPRINT_MYMULTIDOUBLES)
{
double *value = xd->xd_example_multi;
if (TIFFFieldSet(tif,FIELD_EXAMPLE_SINGLE))
{
fprintf(fd, " My Single Long Tag: %lu\n", xd->xd_example_single);
}
num = xd->xd_num_multi;
fprintf(fd, "(");
for (i = 0; i < num; i++)
fprintf(fd, " %lg", *value++);
fprintf(fd, ")\n");
}
else
fprintf(fd, "(present)\n");
}
if (TIFFFieldSet(tif,FIELD_EXAMPLE_ASCII))
{
_TIFFprintAsciiTag(fd,"My ASCII Tag",
xd->xd_example_ascii);
}
if (TIFFFieldSet(tif, FIELD_EXAMPLE_SINGLE))
{
fprintf(fd, " My Single Long Tag: %lu\n", xd->xd_example_single);
}
if (TIFFFieldSet(tif, FIELD_EXAMPLE_ASCII))
{
_TIFFprintAsciiTag(fd, "My ASCII Tag", xd->xd_example_ascii);
}
}
static int
_XTIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
static int _XTIFFVSetField(TIFF *tif, ttag_t tag, va_list ap)
{
xtiff *xt = XTIFFDIR(tif);
XTIFFDirectory* xd = &xt->xtif_dir;
int status = 1;
uint32_t v32=0;
int i=0, v=0;
va_list ap1 = ap;
xtiff *xt = XTIFFDIR(tif);
XTIFFDirectory *xd = &xt->xtif_dir;
int status = 1;
uint32_t v32 = 0;
int i = 0, v = 0;
va_list ap1 = ap;
/* va_start is called by the calling routine */
switch (tag) {
/*
* XXX put your extended tags here; replace the implemented
* example tags with your own.
*/
case TIFFTAG_EXAMPLE_MULTI:
/* multi-valued tags need to store the count as well */
xd->xd_num_multi = (uint16_t) va_arg(ap, int);
_TIFFsetDoubleArray(&xd->xd_example_multi, va_arg(ap, double*),
(long) xd->xd_num_multi);
break;
case TIFFTAG_EXAMPLE_SINGLE:
xd->xd_example_single = va_arg(ap, uint32_t);
break;
case TIFFTAG_EXAMPLE_ASCII:
_TIFFsetString(&xd->xd_example_ascii, va_arg(ap, char*));
break;
default:
/* call the inherited method */
return (PARENT(xt,vsetfield))(tif,tag,ap);
break;
}
if (status) {
/* we have to override the print method here,
* after the compression tags have gotten to it.
* This makes sense because the only time we would
* need the extended print method is if an extended
* tag is set by the reader.
*/
if (!(xt->xtif_flags & XTIFFP_PRINT))
{
PARENT(xt,printdir) = TIFFMEMBER(tif,printdir);
TIFFMEMBER(tif,printdir) = _XTIFFPrintDirectory;
xt->xtif_flags |= XTIFFP_PRINT;
}
TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif, tag)->field_bit);
tif->tif_flags |= TIFF_DIRTYDIRECT;
}
va_end(ap);
return (status);
/* va_start is called by the calling routine */
switch (tag)
{
/*
* XXX put your extended tags here; replace the implemented
* example tags with your own.
*/
case TIFFTAG_EXAMPLE_MULTI:
/* multi-valued tags need to store the count as well */
xd->xd_num_multi = (uint16_t)va_arg(ap, int);
_TIFFsetDoubleArray(&xd->xd_example_multi, va_arg(ap, double *),
(long)xd->xd_num_multi);
break;
case TIFFTAG_EXAMPLE_SINGLE:
xd->xd_example_single = va_arg(ap, uint32_t);
break;
case TIFFTAG_EXAMPLE_ASCII:
_TIFFsetString(&xd->xd_example_ascii, va_arg(ap, char *));
break;
default:
/* call the inherited method */
return (PARENT(xt, vsetfield))(tif, tag, ap);
break;
}
if (status)
{
/* we have to override the print method here,
* after the compression tags have gotten to it.
* This makes sense because the only time we would
* need the extended print method is if an extended
* tag is set by the reader.
*/
if (!(xt->xtif_flags & XTIFFP_PRINT))
{
PARENT(xt, printdir) = TIFFMEMBER(tif, printdir);
TIFFMEMBER(tif, printdir) = _XTIFFPrintDirectory;
xt->xtif_flags |= XTIFFP_PRINT;
}
TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif, tag)->field_bit);
tif->tif_flags |= TIFF_DIRTYDIRECT;
}
va_end(ap);
return (status);
badvalue:
TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%d: Bad value for \"%s\"", v,
_TIFFFieldWithTag(tif, tag)->field_name);
va_end(ap);
return (0);
TIFFErrorExtR(tif, tif->tif_name, "%d: Bad value for \"%s\"", v,
_TIFFFieldWithTag(tif, tag)->field_name);
va_end(ap);
return (0);
badvalue32:
TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%ld: Bad value for \"%s\"", v32,
_TIFFFieldWithTag(tif, tag)->field_name);
va_end(ap);
return (0);
TIFFErrorExtR(tif, tif->tif_name, "%ld: Bad value for \"%s\"", v32,
_TIFFFieldWithTag(tif, tag)->field_name);
va_end(ap);
return (0);
}
static int
_XTIFFVGetField(TIFF* tif, ttag_t tag, va_list ap)
static int _XTIFFVGetField(TIFF *tif, ttag_t tag, va_list ap)
{
xtiff *xt = XTIFFDIR(tif);
XTIFFDirectory* xd = &xt->xtif_dir;
xtiff *xt = XTIFFDIR(tif);
XTIFFDirectory *xd = &xt->xtif_dir;
switch (tag) {
/*
* XXX put your extended tags here; replace the implemented
* example tags with your own.
*/
case TIFFTAG_EXAMPLE_MULTI:
*va_arg(ap, uint16_t*) = xd->xd_num_multi;
*va_arg(ap, double**) = xd->xd_example_multi;
break;
case TIFFTAG_EXAMPLE_ASCII:
*va_arg(ap, char**) = xd->xd_example_ascii;
break;
case TIFFTAG_EXAMPLE_SINGLE:
*va_arg(ap, uint32_t*) = xd->xd_example_single;
break;
default:
/* return inherited method */
return (PARENT(xt,vgetfield))(tif,tag,ap);
break;
}
return (1);
switch (tag)
{
/*
* XXX put your extended tags here; replace the implemented
* example tags with your own.
*/
case TIFFTAG_EXAMPLE_MULTI:
*va_arg(ap, uint16_t *) = xd->xd_num_multi;
*va_arg(ap, double **) = xd->xd_example_multi;
break;
case TIFFTAG_EXAMPLE_ASCII:
*va_arg(ap, char **) = xd->xd_example_ascii;
break;
case TIFFTAG_EXAMPLE_SINGLE:
*va_arg(ap, uint32_t *) = xd->xd_example_single;
break;
default:
/* return inherited method */
return (PARENT(xt, vgetfield))(tif, tag, ap);
break;
}
return (1);
}
#define CleanupField(member) { \
if (xd->member) { \
_TIFFfree(xd->member); \
xd->member = 0; \
} \
}
#define CleanupField(member) \
{ \
if (xd->member) \
{ \
_TIFFfree(xd->member); \
xd->member = 0; \
} \
}
/*
* Release storage associated with a directory.
*/
static void
_XTIFFFreeDirectory(xtiff* xt)
static void _XTIFFFreeDirectory(xtiff *xt)
{
XTIFFDirectory* xd = &xt->xtif_dir;
XTIFFDirectory *xd = &xt->xtif_dir;
/*
* XXX - Purge all Your allocated memory except
* for the xtiff directory itself. This includes
* all fields that require a _TIFFsetXXX call in
* _XTIFFVSetField().
*/
CleanupField(xd_example_multi);
CleanupField(xd_example_ascii);
/*
* XXX - Purge all Your allocated memory except
* for the xtiff directory itself. This includes
* all fields that require a _TIFFsetXXX call in
* _XTIFFVSetField().
*/
CleanupField(xd_example_multi);
CleanupField(xd_example_ascii);
}
#undef CleanupField
static void _XTIFFLocalDefaultDirectory(TIFF *tif)
{
xtiff *xt = XTIFFDIR(tif);
XTIFFDirectory* xd = &xt->xtif_dir;
xtiff *xt = XTIFFDIR(tif);
XTIFFDirectory *xd = &xt->xtif_dir;
/* Install the extended Tag field info */
_TIFFMergeFieldInfo(tif, xtiffFieldInfo, N(xtiffFieldInfo));
/* Install the extended Tag field info */
_TIFFMergeFieldInfo(tif, xtiffFieldInfo, N(xtiffFieldInfo));
/*
* free up any dynamically allocated arrays
* before the new directory is read in.
*/
_XTIFFFreeDirectory(xt);
_TIFFmemset(xt,0,sizeof(xtiff));
/*
* free up any dynamically allocated arrays
* before the new directory is read in.
*/
/* Override the tag access methods */
_XTIFFFreeDirectory(xt);
_TIFFmemset(xt, 0, sizeof(xtiff));
PARENT(xt,vsetfield) = TIFFMEMBER(tif,vsetfield);
TIFFMEMBER(tif,vsetfield) = _XTIFFVSetField;
PARENT(xt,vgetfield) = TIFFMEMBER(tif,vgetfield);
TIFFMEMBER(tif,vgetfield) = _XTIFFVGetField;
/* Override the tag access methods */
/*
* XXX Set up any default values here.
*/
xd->xd_example_single = 234;
PARENT(xt, vsetfield) = TIFFMEMBER(tif, vsetfield);
TIFFMEMBER(tif, vsetfield) = _XTIFFVSetField;
PARENT(xt, vgetfield) = TIFFMEMBER(tif, vgetfield);
TIFFMEMBER(tif, vgetfield) = _XTIFFVGetField;
/*
* XXX Set up any default values here.
*/
xd->xd_example_single = 234;
}
/**********************************************************************
* Nothing below this line should need to be changed.
**********************************************************************/
@@ -250,39 +247,37 @@ static TIFFExtendProc _ParentExtender;
* every time a new TIFF directory is opened.
*/
static void
_XTIFFDefaultDirectory(TIFF *tif)
static void _XTIFFDefaultDirectory(TIFF *tif)
{
xtiff *xt;
/* Allocate Directory Structure if first time, and install it */
if (!(tif->tif_flags & XTIFF_INITIALIZED))
{
xt = _TIFFmalloc(sizeof(xtiff));
if (!xt)
{
/* handle memory allocation failure here ! */
return;
}
_TIFFmemset(xt,0,sizeof(xtiff));
/*
* Install into TIFF structure.
*/
TIFFMEMBER(tif,clientdir) = (tidata_t)xt;
tif->tif_flags |= XTIFF_INITIALIZED; /* don't do this again! */
}
/* set up our own defaults */
_XTIFFLocalDefaultDirectory(tif);
xtiff *xt;
/* Since an XTIFF client module may have overridden
* the default directory method, we call it now to
* allow it to set up the rest of its own methods.
/* Allocate Directory Structure if first time, and install it */
if (!(tif->tif_flags & XTIFF_INITIALIZED))
{
xt = _TIFFmalloc(sizeof(xtiff));
if (!xt)
{
/* handle memory allocation failure here ! */
return;
}
_TIFFmemset(xt, 0, sizeof(xtiff));
/*
* Install into TIFF structure.
*/
TIFFMEMBER(tif, clientdir) = (tidata_t)xt;
tif->tif_flags |= XTIFF_INITIALIZED; /* don't do this again! */
}
if (_ParentExtender)
(*_ParentExtender)(tif);
/* set up our own defaults */
_XTIFFLocalDefaultDirectory(tif);
/* Since an XTIFF client module may have overridden
* the default directory method, we call it now to
* allow it to set up the rest of its own methods.
*/
if (_ParentExtender)
(*_ParentExtender)(tif);
}
/*
@@ -290,61 +285,49 @@ _XTIFFDefaultDirectory(TIFF *tif)
* procedure for the TIFF module.
*/
static
void _XTIFFInitialize(void)
static void _XTIFFInitialize(void)
{
static first_time=1;
if (! first_time) return; /* Been there. Done that. */
first_time = 0;
/* Grab the inherited method and install */
_ParentExtender = TIFFSetTagExtender(_XTIFFDefaultDirectory);
}
static first_time = 1;
if (!first_time)
return; /* Been there. Done that. */
first_time = 0;
/* Grab the inherited method and install */
_ParentExtender = TIFFSetTagExtender(_XTIFFDefaultDirectory);
}
/*
* Public File I/O Routines.
*/
TIFF*
XTIFFOpen(const char* name, const char* mode)
TIFF *XTIFFOpen(const char *name, const char *mode)
{
/* Set up the callback */
_XTIFFInitialize();
/* Open the file; the callback will set everything up
*/
return TIFFOpen(name, mode);
/* Set up the callback */
_XTIFFInitialize();
/* Open the file; the callback will set everything up
*/
return TIFFOpen(name, mode);
}
TIFF*
XTIFFFdOpen(int fd, const char* name, const char* mode)
TIFF *XTIFFFdOpen(int fd, const char *name, const char *mode)
{
/* Set up the callback */
_XTIFFInitialize();
/* Set up the callback */
_XTIFFInitialize();
/* Open the file; the callback will set everything up
*/
return TIFFFdOpen(fd, name, mode);
/* Open the file; the callback will set everything up
*/
return TIFFFdOpen(fd, name, mode);
}
void
XTIFFClose(TIFF *tif)
void XTIFFClose(TIFF *tif)
{
xtiff *xt = XTIFFDIR(tif);
/* call inherited function first */
TIFFClose(tif);
/* Free up extended allocated memory */
_XTIFFFreeDirectory(xt);
_TIFFfree(xt);
xtiff *xt = XTIFFDIR(tif);
/* call inherited function first */
TIFFClose(tif);
/* Free up extended allocated memory */
_XTIFFFreeDirectory(xt);
_TIFFfree(xt);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+12 -19
View File
@@ -14,46 +14,39 @@
#include "tiffio.h"
/*
* XXX Define your private Tag names and values here
/*
* XXX Define your private Tag names and values here
*/
/* These tags are not valid, but are provided for example */
#define TIFFTAG_EXAMPLE_MULTI 61234
#define TIFFTAG_EXAMPLE_SINGLE 61235
#define TIFFTAG_EXAMPLE_ASCII 61236
#define TIFFTAG_EXAMPLE_MULTI 61234
#define TIFFTAG_EXAMPLE_SINGLE 61235
#define TIFFTAG_EXAMPLE_ASCII 61236
/*
/*
* XXX Define Printing method flags. These
* flags may be passed in to TIFFPrintDirectory() to
* indicate that those particular field values should
* be printed out in full, rather than just an indicator
* of whether they are present or not.
*/
#define TIFFPRINT_MYMULTIDOUBLES 0x80000000
#define TIFFPRINT_MYMULTIDOUBLES 0x80000000
/**********************************************************************
* Nothing below this line should need to be changed by the user.
**********************************************************************/
#if defined(__cplusplus)
extern "C" {
extern "C"
{
#endif
extern TIFF* XTIFFOpen(const char* name, const char* mode);
extern TIFF* XTIFFFdOpen(int fd, const char* name, const char* mode);
extern void XTIFFClose(TIFF *tif);
extern TIFF *XTIFFOpen(const char *name, const char *mode);
extern TIFF *XTIFFFdOpen(int fd, const char *name, const char *mode);
extern void XTIFFClose(TIFF *tif);
#if defined(__cplusplus)
}
#endif
#endif /* __xtiffio_h */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+23 -30
View File
@@ -22,20 +22,20 @@
/* XXX - Define number of your extended tags here */
#define NUM_XFIELD 3
#define XFIELD_BASE (FIELD_LAST-NUM_XFIELD)
#define XFIELD_BASE (FIELD_LAST - NUM_XFIELD)
/* XXX - Define your Tag Fields here */
#define FIELD_EXAMPLE_MULTI (XFIELD_BASE+0)
#define FIELD_EXAMPLE_SINGLE (XFIELD_BASE+1)
#define FIELD_EXAMPLE_ASCII (XFIELD_BASE+2)
#define FIELD_EXAMPLE_MULTI (XFIELD_BASE + 0)
#define FIELD_EXAMPLE_SINGLE (XFIELD_BASE + 1)
#define FIELD_EXAMPLE_ASCII (XFIELD_BASE + 2)
/* XXX - Define Private directory tag structure here */
struct XTIFFDirectory {
uint16_t xd_num_multi; /* dir-count for the multi tag */
double* xd_example_multi;
uint32_t xd_example_single;
char* xd_example_ascii;
struct XTIFFDirectory
{
uint16_t xd_num_multi; /* dir-count for the multi tag */
double *xd_example_multi;
uint32_t xd_example_single;
char *xd_example_ascii;
};
typedef struct XTIFFDirectory XTIFFDirectory;
@@ -43,30 +43,23 @@ typedef struct XTIFFDirectory XTIFFDirectory;
* Nothing below this line should need to be changed by the user.
**********************************************************************/
struct xtiff {
TIFF *xtif_tif; /* parent TIFF pointer */
uint32_t xtif_flags;
#define XTIFFP_PRINT 0x00000001
XTIFFDirectory xtif_dir; /* internal rep of current directory */
TIFFVSetMethod xtif_vsetfield; /* inherited tag set routine */
TIFFVGetMethod xtif_vgetfield; /* inherited tag get routine */
TIFFPrintMethod xtif_printdir; /* inherited dir print method */
struct xtiff
{
TIFF *xtif_tif; /* parent TIFF pointer */
uint32_t xtif_flags;
#define XTIFFP_PRINT 0x00000001
XTIFFDirectory xtif_dir; /* internal rep of current directory */
TIFFVSetMethod xtif_vsetfield; /* inherited tag set routine */
TIFFVGetMethod xtif_vgetfield; /* inherited tag get routine */
TIFFPrintMethod xtif_printdir; /* inherited dir print method */
};
typedef struct xtiff xtiff;
#define PARENT(xt, pmember) ((xt)->xtif_##pmember)
#define TIFFMEMBER(tf, pmember) ((tf)->tif_##pmember)
#define XTIFFDIR(tif) ((xtiff *)TIFFMEMBER(tif, clientdir))
#define PARENT(xt,pmember) ((xt)->xtif_ ## pmember)
#define TIFFMEMBER(tf,pmember) ((tf)->tif_ ## pmember)
#define XTIFFDIR(tif) ((xtiff *)TIFFMEMBER(tif,clientdir))
/* Extended TIFF flags */
#define XTIFF_INITIALIZED 0x80000000
#endif /* __xtiffiop_h */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+184 -187
View File
@@ -1,11 +1,11 @@
#include "StdAfx.h"
//#define STRICT
// #define STRICT
#include "diblib.h"
#include <commdlg.h>
#include <stdlib.h> // MAX_ constants
#include <windows.h>
#include <windowsx.h>
#include <commdlg.h>
#include <stdlib.h> // MAX_ constants
#include "diblib.h"
/*--------------------------------------------------------------------
READ TIFF
@@ -31,44 +31,42 @@
#include <assert.h>
#include <stdio.h>
// piggyback some data on top of the RGBA Image
struct TIFFDibImage {
struct TIFFDibImage
{
TIFFRGBAImage tif;
int dibinstalled;
} ;
int dibinstalled;
};
HANDLE LoadTIFFinDIB(LPCTSTR lpFileName);
HANDLE TIFFRGBA2DIB(TIFFDibImage* dib, uint32_t* raster) ;
HANDLE TIFFRGBA2DIB(TIFFDibImage *dib, uint32_t *raster);
static void
MyWarningHandler(const char* module, const char* fmt, va_list ap)
static void MyWarningHandler(const char *module, const char *fmt, va_list ap)
{
// ignore all warnings (unused tags, etc)
return;
}
static void
MyErrorHandler(const char* module, const char* fmt, va_list ap)
static void MyErrorHandler(const char *module, const char *fmt, va_list ap)
{
return;
}
// Turn off the error and warning handlers to check if a valid file.
// Necessary because of the way that the Doc loads images and restart files.
int ChkTIFF ( LPCTSTR lpszPath )
int ChkTIFF(LPCTSTR lpszPath)
{
int rtn = 0;
TIFFErrorHandler eh;
TIFFErrorHandler wh;
TIFFErrorHandler eh;
TIFFErrorHandler wh;
eh = TIFFSetErrorHandler(NULL);
wh = TIFFSetWarningHandler(NULL);
TIFF* tif = TIFFOpen(lpszPath, "r");
if (tif) {
TIFF *tif = TIFFOpen(lpszPath, "r");
if (tif)
{
rtn = 1;
TIFFClose(tif);
}
@@ -79,34 +77,42 @@ int ChkTIFF ( LPCTSTR lpszPath )
return rtn;
}
void DibInstallHack(TIFFDibImage* img) ;
void DibInstallHack(TIFFDibImage *img);
PVOID ReadTIFF ( LPCTSTR lpszPath )
PVOID ReadTIFF(LPCTSTR lpszPath)
{
void* pDIB = 0;
TIFFErrorHandler wh;
void *pDIB = 0;
TIFFErrorHandler wh;
wh = TIFFSetWarningHandler(MyWarningHandler);
if (ChkTIFF(lpszPath)) {
TIFF* tif = TIFFOpen(lpszPath, "r");
if (tif) {
if (ChkTIFF(lpszPath))
{
TIFF *tif = TIFFOpen(lpszPath, "r");
if (tif)
{
char emsg[1024];
if (TIFFRGBAImageOK(tif, emsg)) {
if (TIFFRGBAImageOK(tif, emsg))
{
TIFFDibImage img;
char emsg[1024];
if (TIFFRGBAImageBegin(&img.tif, tif, -1, emsg)) {
if (TIFFRGBAImageBegin(&img.tif, tif, -1, emsg))
{
size_t npixels;
uint32_t* raster;
uint32_t *raster;
DibInstallHack(&img);
npixels = img.tif.width * img.tif.height;
raster = (uint32_t*) _TIFFmalloc(npixels * sizeof (uint32_t));
if (raster != NULL) {
if (TIFFRGBAImageGet(&img.tif, raster, img.tif.width, img.tif.height)) {
raster =
(uint32_t *)_TIFFmalloc(npixels * sizeof(uint32_t));
if (raster != NULL)
{
if (TIFFRGBAImageGet(&img.tif, raster, img.tif.width,
img.tif.height))
{
pDIB = TIFFRGBA2DIB(&img, raster);
}
}
@@ -114,8 +120,9 @@ PVOID ReadTIFF ( LPCTSTR lpszPath )
}
TIFFRGBAImageEnd(&img.tif);
}
else {
TRACE("Unable to open image(%s): %s\n", lpszPath, emsg );
else
{
TRACE("Unable to open image(%s): %s\n", lpszPath, emsg);
}
TIFFClose(tif);
}
@@ -126,12 +133,10 @@ PVOID ReadTIFF ( LPCTSTR lpszPath )
return pDIB;
}
HANDLE TIFFRGBA2DIB(TIFFDibImage* dib, uint32_t* raster)
HANDLE TIFFRGBA2DIB(TIFFDibImage *dib, uint32_t *raster)
{
void* pDIB = 0;
TIFFRGBAImage* img = &dib->tif;
void *pDIB = 0;
TIFFRGBAImage *img = &dib->tif;
uint32_t imageLength;
uint32_t imageWidth;
@@ -140,8 +145,8 @@ HANDLE TIFFRGBA2DIB(TIFFDibImage* dib, uint32_t* raster)
uint32_t RowsPerStrip;
uint16_t PhotometricInterpretation;
BITMAPINFOHEADER bi;
int dwDIBSize ;
BITMAPINFOHEADER bi;
int dwDIBSize;
TIFFGetField(img->tif, TIFFTAG_IMAGEWIDTH, &imageWidth);
TIFFGetField(img->tif, TIFFTAG_IMAGELENGTH, &imageLength);
@@ -150,91 +155,97 @@ HANDLE TIFFRGBA2DIB(TIFFDibImage* dib, uint32_t* raster)
TIFFGetField(img->tif, TIFFTAG_SAMPLESPERPIXEL, &SamplePerPixel);
TIFFGetField(img->tif, TIFFTAG_PHOTOMETRIC, &PhotometricInterpretation);
if ( BitsPerSample == 1 && SamplePerPixel == 1 && dib->dibinstalled ) { // bilevel
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = imageWidth;
bi.biHeight = imageLength;
bi.biPlanes = 1; // always
bi.biBitCount = 1;
bi.biCompression = BI_RGB;
bi.biSizeImage = WIDTHBYTES(bi.biWidth * bi.biBitCount) * bi.biHeight;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0; // must be zero for RGB compression (none)
bi.biClrImportant = 0; // always
if (BitsPerSample == 1 && SamplePerPixel == 1 && dib->dibinstalled)
{ // bilevel
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = imageWidth;
bi.biHeight = imageLength;
bi.biPlanes = 1; // always
bi.biBitCount = 1;
bi.biCompression = BI_RGB;
bi.biSizeImage = WIDTHBYTES(bi.biWidth * bi.biBitCount) * bi.biHeight;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0; // must be zero for RGB compression (none)
bi.biClrImportant = 0; // always
// Get the size of the DIB
dwDIBSize = GetDIBSize( &bi );
dwDIBSize = GetDIBSize(&bi);
// Allocate for the BITMAPINFO structure and the color table.
pDIB = GlobalAllocPtr( GHND, dwDIBSize );
if (pDIB == 0) {
return( NULL );
pDIB = GlobalAllocPtr(GHND, dwDIBSize);
if (pDIB == 0)
{
return (NULL);
}
// Copy the header info
*((BITMAPINFOHEADER*)pDIB) = bi;
*((BITMAPINFOHEADER *)pDIB) = bi;
// Get a pointer to the color table
RGBQUAD *pRgbq = (RGBQUAD *)((LPSTR)pDIB + sizeof(BITMAPINFOHEADER));
RGBQUAD *pRgbq = (RGBQUAD *)((LPSTR)pDIB + sizeof(BITMAPINFOHEADER));
pRgbq[0].rgbRed = 0;
pRgbq[0].rgbBlue = 0;
pRgbq[0].rgbGreen = 0;
pRgbq[0].rgbRed = 0;
pRgbq[0].rgbBlue = 0;
pRgbq[0].rgbGreen = 0;
pRgbq[0].rgbReserved = 0;
pRgbq[1].rgbRed = 255;
pRgbq[1].rgbBlue = 255;
pRgbq[1].rgbGreen = 255;
pRgbq[1].rgbRed = 255;
pRgbq[1].rgbBlue = 255;
pRgbq[1].rgbGreen = 255;
pRgbq[1].rgbReserved = 255;
// Pointers to the bits
//PVOID pbiBits = (LPSTR)pRgbq + bi.biClrUsed * sizeof(RGBQUAD);
// PVOID pbiBits = (LPSTR)pRgbq + bi.biClrUsed * sizeof(RGBQUAD);
//
// In the BITMAPINFOHEADER documentation, it appears that
// there should be no color table for 32 bit images, but
// experience shows that the image is off by 3 words if it
// is not included. So here it is.
PVOID pbiBits = GetDIBImagePtr((BITMAPINFOHEADER*)pDIB); //(LPSTR)pRgbq + 3 * sizeof(RGBQUAD);
PVOID pbiBits = GetDIBImagePtr(
(BITMAPINFOHEADER *)pDIB); //(LPSTR)pRgbq + 3 * sizeof(RGBQUAD);
int sizeWords = bi.biSizeImage/4;
RGBQUAD* rgbDib = (RGBQUAD*)pbiBits;
long* rgbTif = (long*)raster;
int sizeWords = bi.biSizeImage / 4;
RGBQUAD *rgbDib = (RGBQUAD *)pbiBits;
long *rgbTif = (long *)raster;
_TIFFmemcpy(pbiBits, raster, bi.biSizeImage);
}
// For now just always default to the RGB 32 bit form. // save as 32 bit for simplicity
else if ( true /*BitsPerSample == 8 && SamplePerPixel == 3*/ ) { // 24 bit color
// For now just always default to the RGB 32 bit form. // save as 32 bit
// for simplicity
else if (true /*BitsPerSample == 8 && SamplePerPixel == 3*/)
{ // 24 bit color
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = imageWidth;
bi.biHeight = imageLength;
bi.biPlanes = 1; // always
bi.biBitCount = 32;
bi.biCompression = BI_RGB;
bi.biSizeImage = WIDTHBYTES(bi.biWidth * bi.biBitCount) * bi.biHeight;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0; // must be zero for RGB compression (none)
bi.biClrImportant = 0; // always
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = imageWidth;
bi.biHeight = imageLength;
bi.biPlanes = 1; // always
bi.biBitCount = 32;
bi.biCompression = BI_RGB;
bi.biSizeImage = WIDTHBYTES(bi.biWidth * bi.biBitCount) * bi.biHeight;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0; // must be zero for RGB compression (none)
bi.biClrImportant = 0; // always
// Get the size of the DIB
dwDIBSize = GetDIBSize( &bi );
dwDIBSize = GetDIBSize(&bi);
// Allocate for the BITMAPINFO structure and the color table.
pDIB = GlobalAllocPtr( GHND, dwDIBSize );
if (pDIB == 0) {
return( NULL );
pDIB = GlobalAllocPtr(GHND, dwDIBSize);
if (pDIB == 0)
{
return (NULL);
}
// Copy the header info
*((BITMAPINFOHEADER*)pDIB) = bi;
*((BITMAPINFOHEADER *)pDIB) = bi;
// Get a pointer to the color table
RGBQUAD *pRgbq = (RGBQUAD *)((LPSTR)pDIB + sizeof(BITMAPINFOHEADER));
RGBQUAD *pRgbq = (RGBQUAD *)((LPSTR)pDIB + sizeof(BITMAPINFOHEADER));
// Pointers to the bits
//PVOID pbiBits = (LPSTR)pRgbq + bi.biClrUsed * sizeof(RGBQUAD);
// PVOID pbiBits = (LPSTR)pRgbq + bi.biClrUsed * sizeof(RGBQUAD);
//
// In the BITMAPINFOHEADER documentation, it appears that
// there should be no color table for 32 bit images, but
@@ -242,15 +253,15 @@ HANDLE TIFFRGBA2DIB(TIFFDibImage* dib, uint32_t* raster)
// is not included. So here it is.
PVOID pbiBits = (LPSTR)pRgbq + 3 * sizeof(RGBQUAD);
int sizeWords = bi.biSizeImage/4;
RGBQUAD* rgbDib = (RGBQUAD*)pbiBits;
long* rgbTif = (long*)raster;
int sizeWords = bi.biSizeImage / 4;
RGBQUAD *rgbDib = (RGBQUAD *)pbiBits;
long *rgbTif = (long *)raster;
// Swap the byte order while copying
for ( int i = 0 ; i < sizeWords ; ++i )
for (int i = 0; i < sizeWords; ++i)
{
rgbDib[i].rgbRed = TIFFGetR(rgbTif[i]);
rgbDib[i].rgbBlue = TIFFGetB(rgbTif[i]);
rgbDib[i].rgbRed = TIFFGetR(rgbTif[i]);
rgbDib[i].rgbBlue = TIFFGetB(rgbTif[i]);
rgbDib[i].rgbGreen = TIFFGetG(rgbTif[i]);
rgbDib[i].rgbReserved = 0;
}
@@ -259,9 +270,6 @@ HANDLE TIFFRGBA2DIB(TIFFDibImage* dib, uint32_t* raster)
return pDIB;
}
///////////////////////////////////////////////////////////////
//
// Hacked from tif_getimage.c in libtiff in v3.5.7
@@ -269,49 +277,42 @@ HANDLE TIFFRGBA2DIB(TIFFDibImage* dib, uint32_t* raster)
//
typedef unsigned char u_char;
#define DECLAREContigPutFunc(name) \
static void name(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, \
uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, \
u_char *pp)
#define DECLAREContigPutFunc(name) \
static void name(\
TIFFRGBAImage* img, \
uint32_t* cp, \
uint32_t x, uint32_t y, \
uint32_t w, uint32_t h, \
int32_t fromskew, int32_t toskew, \
u_char* pp \
)
#define DECLARESepPutFunc(name) \
static void name(\
TIFFRGBAImage* img,\
uint32_t* cp,\
uint32_t x, uint32_t y, \
uint32_t w, uint32_t h,\
int32_t fromskew, int32_t toskew,\
u_char* r, u_char* g, u_char* b, u_char* a\
)
#define DECLARESepPutFunc(name) \
static void name(TIFFRGBAImage *img, uint32_t *cp, uint32_t x, uint32_t y, \
uint32_t w, uint32_t h, int32_t fromskew, int32_t toskew, \
u_char *r, u_char *g, u_char *b, u_char *a)
DECLAREContigPutFunc(putContig1bitTile);
static int getStripContig1Bit(TIFFRGBAImage* img, uint32_t* uraster, uint32_t w, uint32_t h);
static int getStripContig1Bit(TIFFRGBAImage *img, uint32_t *uraster, uint32_t w,
uint32_t h);
//typdef struct TIFFDibImage {
// TIFFRGBAImage tif;
// dibinstalled;
//} TIFFDibImage ;
// typdef struct TIFFDibImage {
// TIFFRGBAImage tif;
// dibinstalled;
// } TIFFDibImage ;
void DibInstallHack(TIFFDibImage* dib) {
TIFFRGBAImage* img = &dib->tif;
void DibInstallHack(TIFFDibImage *dib)
{
TIFFRGBAImage *img = &dib->tif;
dib->dibinstalled = false;
switch (img->photometric) {
switch (img->photometric)
{
case PHOTOMETRIC_MINISWHITE:
case PHOTOMETRIC_MINISBLACK:
switch (img->bitspersample) {
case 1:
img->put.contig = putContig1bitTile;
img->get = getStripContig1Bit;
dib->dibinstalled = true;
break;
}
break;
switch (img->bitspersample)
{
case 1:
img->put.contig = putContig1bitTile;
img->get = getStripContig1Bit;
dib->dibinstalled = true;
break;
}
break;
}
}
@@ -324,15 +325,16 @@ DECLAREContigPutFunc(putContig1bitTile)
{
int samplesperpixel = img->samplesperpixel;
(void) y;
(void)y;
fromskew *= samplesperpixel;
int wb = WIDTHBYTES(w);
u_char* ucp = (u_char*)cp;
u_char *ucp = (u_char *)cp;
/* Convert 'w' to bytes from pixels (rounded up) */
w = (w+7)/8;
w = (w + 7) / 8;
while (h-- > 0) {
while (h-- > 0)
{
_TIFFmemcpy(ucp, pp, w);
/*
for (x = wb; x-- > 0;) {
@@ -348,32 +350,32 @@ DECLAREContigPutFunc(putContig1bitTile)
/*
* Hacked from the tif_getimage.c file.
*/
static uint32_t
setorientation(TIFFRGBAImage* img, uint32_t h)
static uint32_t setorientation(TIFFRGBAImage *img, uint32_t h)
{
TIFF* tif = img->tif;
TIFF *tif = img->tif;
uint32_t y;
switch (img->orientation) {
case ORIENTATION_BOTRIGHT:
case ORIENTATION_RIGHTBOT: /* XXX */
case ORIENTATION_LEFTBOT: /* XXX */
TIFFWarning(TIFFFileName(tif), "using bottom-left orientation");
img->orientation = ORIENTATION_BOTLEFT;
/* fall through... */
case ORIENTATION_BOTLEFT:
y = 0;
break;
case ORIENTATION_TOPRIGHT:
case ORIENTATION_RIGHTTOP: /* XXX */
case ORIENTATION_LEFTTOP: /* XXX */
default:
TIFFWarning(TIFFFileName(tif), "using top-left orientation");
img->orientation = ORIENTATION_TOPLEFT;
/* fall through... */
case ORIENTATION_TOPLEFT:
y = h-1;
break;
switch (img->orientation)
{
case ORIENTATION_BOTRIGHT:
case ORIENTATION_RIGHTBOT: /* XXX */
case ORIENTATION_LEFTBOT: /* XXX */
TIFFWarning(TIFFFileName(tif), "using bottom-left orientation");
img->orientation = ORIENTATION_BOTLEFT;
/* fall through... */
case ORIENTATION_BOTLEFT:
y = 0;
break;
case ORIENTATION_TOPRIGHT:
case ORIENTATION_RIGHTTOP: /* XXX */
case ORIENTATION_LEFTTOP: /* XXX */
default:
TIFFWarning(TIFFFileName(tif), "using top-left orientation");
img->orientation = ORIENTATION_TOPLEFT;
/* fall through... */
case ORIENTATION_TOPLEFT:
y = h - 1;
break;
}
return (y);
}
@@ -389,61 +391,56 @@ setorientation(TIFFRGBAImage* img, uint32_t h)
* This is set up to allow us to just copy the data to the raster
* for 1-bit bitmaps
*/
static int
getStripContig1Bit(TIFFRGBAImage* img, uint32_t* raster, uint32_t w, uint32_t h)
static int getStripContig1Bit(TIFFRGBAImage *img, uint32_t *raster, uint32_t w,
uint32_t h)
{
TIFF* tif = img->tif;
TIFF *tif = img->tif;
tileContigRoutine put = img->put.contig;
uint16_t orientation;
uint32_t row, y, nrow, rowstoread;
uint32_t pos;
u_char* buf;
u_char *buf;
uint32_t rowsperstrip;
uint32_t imagewidth = img->width;
tsize_t scanline;
int32_t fromskew, toskew;
tstrip_t strip;
tsize_t stripsize;
u_char* braster = (u_char*)raster; // byte wide raster
uint32_t wb = WIDTHBYTES(w);
tsize_t stripsize;
u_char *braster = (u_char *)raster; // byte wide raster
uint32_t wb = WIDTHBYTES(w);
int ret = 1;
buf = (u_char*) _TIFFmalloc(TIFFStripSize(tif));
if (buf == 0) {
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for strip buffer");
buf = (u_char *)_TIFFmalloc(TIFFStripSize(tif));
if (buf == 0)
{
TIFFErrorExtR(tif, TIFFFileName(tif), "No space for strip buffer");
return (0);
}
y = setorientation(img, h);
orientation = img->orientation;
toskew = -(int32_t) (orientation == ORIENTATION_TOPLEFT ? wb+wb : wb-wb);
toskew = -(int32_t)(orientation == ORIENTATION_TOPLEFT ? wb + wb : wb - wb);
TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
scanline = TIFFScanlineSize(tif);
fromskew = (w < imagewidth ? imagewidth - w : 0)/8;
fromskew = (w < imagewidth ? imagewidth - w : 0) / 8;
for (row = 0; row < h; row += nrow)
{
rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
nrow = (row + rowstoread > h ? h - row : rowstoread);
strip = TIFFComputeStrip(tif,row+img->row_offset, 0);
stripsize = ((row + img->row_offset)%rowsperstrip + nrow) * scanline;
if (TIFFReadEncodedStrip(tif, strip, buf, stripsize ) < 0
&& img->stoponerr)
strip = TIFFComputeStrip(tif, row + img->row_offset, 0);
stripsize = ((row + img->row_offset) % rowsperstrip + nrow) * scanline;
if (TIFFReadEncodedStrip(tif, strip, buf, stripsize) < 0 &&
img->stoponerr)
{
ret = 0;
break;
}
pos = ((row + img->row_offset) % rowsperstrip) * scanline;
(*put)(img, (uint32_t*)(braster+y*wb), 0, y, w, nrow, fromskew, toskew, buf + pos);
y += (orientation == ORIENTATION_TOPLEFT ?-(int32_t) nrow : (int32_t) nrow);
(*put)(img, (uint32_t *)(braster + y * wb), 0, y, w, nrow, fromskew,
toskew, buf + pos);
y += (orientation == ORIENTATION_TOPLEFT ? -(int32_t)nrow
: (int32_t)nrow);
}
_TIFFfree(buf);
return (ret);
}
/*
* Local Variables:
* mode: c++
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+234 -256
View File
@@ -1,42 +1,39 @@
/*************************************************************************
*
* Source file for Windows 95/Win32.
* Source file for Windows 95/Win32.
*
* The function LoadTIFFinDIB in this source file let you load
* a TIFF file and build a memory DIB with it and return the
* The function LoadTIFFinDIB in this source file let you load
* a TIFF file and build a memory DIB with it and return the
* HANDLE (HDIB) of the memory block containing the DIB.
*
* Example :
*
* Example :
*
* HDIB hDIB;
* hDIB = LoadTIFFinDIB("sample.tif");
*
*
* To build this source file you must include the TIFF library
* To build this source file you must include the TIFF library
* in your project.
*
* 4/12/95 Philippe Tenenhaus 100423.3705@compuserve.com
*
************************************************************************/
#include "tiffio.h"
#include "tiffio.h"
#define HDIB HANDLE
#define IS_WIN30_DIB(lpbi) ((*(LPDWORD)(lpbi)) == sizeof(BITMAPINFOHEADER))
#define CVT(x) (((x) * 255L) / ((1L<<16)-1))
#define IS_WIN30_DIB(lpbi) ((*(LPDWORD)(lpbi)) == sizeof(BITMAPINFOHEADER))
#define CVT(x) (((x)*255L) / ((1L << 16) - 1))
static HDIB CreateDIB(DWORD dwWidth, DWORD dwHeight, WORD wBitCount);
static LPSTR FindDIBBits(LPSTR lpDIB);
static WORD PaletteSize(LPSTR lpDIB);
static WORD DIBNumColors(LPSTR lpDIB);
static int checkcmap(int n, uint16_t* r, uint16_t* g, uint16_t* b);
static int checkcmap(int n, uint16_t *r, uint16_t *g, uint16_t *b);
/*************************************************************************
*
* HDIB LoadTIFFinDIB(LPSTR lpFileName)
* HDIB LoadTIFFinDIB(LPSTR lpFileName)
*
* Parameter:
*
@@ -56,181 +53,173 @@ static int checkcmap(int n, uint16_t* r, uint16_t* g, uint16_t* b);
*
************************************************************************/
HDIB LoadTIFFinDIB(LPSTR lpFileName)
HDIB LoadTIFFinDIB(LPSTR lpFileName)
{
TIFF *tif;
unsigned long imageLength;
unsigned long imageWidth;
unsigned int BitsPerSample;
TIFF *tif;
unsigned long imageLength;
unsigned long imageWidth;
unsigned int BitsPerSample;
unsigned long LineSize;
unsigned int SamplePerPixel;
unsigned long RowsPerStrip;
int PhotometricInterpretation;
long nrow;
unsigned long row;
char *buf;
LPBITMAPINFOHEADER lpDIB;
HDIB hDIB;
char *lpBits;
HGLOBAL hStrip;
int i,l;
int Align;
unsigned int SamplePerPixel;
unsigned long RowsPerStrip;
int PhotometricInterpretation;
long nrow;
unsigned long row;
char *buf;
LPBITMAPINFOHEADER lpDIB;
HDIB hDIB;
char *lpBits;
HGLOBAL hStrip;
int i, l;
int Align;
tif = TIFFOpen(lpFileName, "r");
if (!tif)
goto TiffOpenError;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &imageWidth);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imageLength);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imageLength);
TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &BitsPerSample);
TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &RowsPerStrip);
TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &RowsPerStrip);
TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &RowsPerStrip);
TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &RowsPerStrip);
TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &PhotometricInterpretation);
LineSize = TIFFScanlineSize(tif); //Number of byte in ine line
SamplePerPixel = (int) (LineSize/imageWidth);
LineSize = TIFFScanlineSize(tif); // Number of byte in ine line
//Align = Number of byte to add at the end of each line of the DIB
SamplePerPixel = (int)(LineSize / imageWidth);
// Align = Number of byte to add at the end of each line of the DIB
Align = 4 - (LineSize % 4);
if (Align == 4) Align = 0;
if (Align == 4)
Align = 0;
//Create a new DIB
hDIB = CreateDIB((DWORD) imageWidth, (DWORD) imageLength, (WORD)
(BitsPerSample*SamplePerPixel));
lpDIB = (LPBITMAPINFOHEADER) GlobalLock(hDIB);
// Create a new DIB
hDIB = CreateDIB((DWORD)imageWidth, (DWORD)imageLength,
(WORD)(BitsPerSample * SamplePerPixel));
lpDIB = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
if (!lpDIB)
goto OutOfDIBMemory;
if (lpDIB)
lpBits = FindDIBBits((LPSTR) lpDIB);
else
lpBits = NULL;
goto OutOfDIBMemory;
//In the tiff file the lines are save from up to down
//In a DIB the lines must be save from down to up
if (lpDIB)
lpBits = FindDIBBits((LPSTR)lpDIB);
else
lpBits = NULL;
// In the tiff file the lines are save from up to down
// In a DIB the lines must be save from down to up
if (lpBits)
{
lpBits = FindDIBBits((LPSTR) lpDIB);
lpBits+=((imageWidth*SamplePerPixel)+Align)*(imageLength-1);
//now lpBits pointe on the bottom line
hStrip = GlobalAlloc(GHND,TIFFStripSize(tif));
buf = GlobalLock(hStrip);
{
lpBits = FindDIBBits((LPSTR)lpDIB);
lpBits += ((imageWidth * SamplePerPixel) + Align) * (imageLength - 1);
// now lpBits pointe on the bottom line
hStrip = GlobalAlloc(GHND, TIFFStripSize(tif));
buf = GlobalLock(hStrip);
if (!buf)
goto OutOfBufMemory;
//PhotometricInterpretation = 2 image is RGB
//PhotometricInterpretation = 3 image have a color palette
goto OutOfBufMemory;
// PhotometricInterpretation = 2 image is RGB
// PhotometricInterpretation = 3 image have a color palette
if (PhotometricInterpretation == 3)
{
uint16_t* red;
uint16_t* green;
uint16_t* blue;
int16_t i;
LPBITMAPINFO lpbmi;
int Palette16Bits;
TIFFGetField(tif, TIFFTAG_COLORMAP, &red, &green, &blue);
uint16_t *red;
uint16_t *green;
uint16_t *blue;
int16_t i;
LPBITMAPINFO lpbmi;
int Palette16Bits;
//Is the palette 16 or 8 bits ?
if (checkcmap(1<<BitsPerSample, red, green, blue) == 16)
Palette16Bits = TRUE;
else
Palette16Bits = FALSE;
lpbmi = (LPBITMAPINFO)lpDIB;
//load the palette in the DIB
for (i = (1<<BitsPerSample)-1; i >= 0; i--)
{
if (Palette16Bits)
{
lpbmi->bmiColors[i].rgbRed =(BYTE) CVT(red[i]);
lpbmi->bmiColors[i].rgbGreen = (BYTE) CVT(green[i]);
lpbmi->bmiColors[i].rgbBlue = (BYTE) CVT(blue[i]);
}
else
{
lpbmi->bmiColors[i].rgbRed = (BYTE) red[i];
lpbmi->bmiColors[i].rgbGreen = (BYTE) green[i];
lpbmi->bmiColors[i].rgbBlue = (BYTE) blue[i];
}
}
}
//read the tiff lines and save them in the DIB
//with RGB mode, we have to change the order of the 3 samples RGB
<=> BGR
for (row = 0; row < imageLength; row += RowsPerStrip)
{
nrow = (row + RowsPerStrip > imageLength ? imageLength - row :
RowsPerStrip);
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 0),
buf, nrow*LineSize)==-1)
{
goto TiffReadError;
}
TIFFGetField(tif, TIFFTAG_COLORMAP, &red, &green, &blue);
// Is the palette 16 or 8 bits ?
if (checkcmap(1 << BitsPerSample, red, green, blue) == 16)
Palette16Bits = TRUE;
else
{
for (l = 0; l < nrow; l++)
{
if (SamplePerPixel == 3)
for (i=0;i< (int) (imageWidth);i++)
{
lpBits[i*SamplePerPixel+0]=buf[l*LineSize+i*Sample
PerPixel+2];
lpBits[i*SamplePerPixel+1]=buf[l*LineSize+i*Sample
PerPixel+1];
lpBits[i*SamplePerPixel+2]=buf[l*LineSize+i*Sample
PerPixel+0];
}
else
memcpy(lpBits, &buf[(int) (l*LineSize)], (int)
imageWidth*SamplePerPixel);
lpBits-=imageWidth*SamplePerPixel+Align;
Palette16Bits = FALSE;
}
}
}
lpbmi = (LPBITMAPINFO)lpDIB;
// load the palette in the DIB
for (i = (1 << BitsPerSample) - 1; i >= 0; i--)
{
if (Palette16Bits)
{
lpbmi->bmiColors[i].rgbRed = (BYTE)CVT(red[i]);
lpbmi->bmiColors[i].rgbGreen = (BYTE)CVT(green[i]);
lpbmi->bmiColors[i].rgbBlue = (BYTE)CVT(blue[i]);
}
else
{
lpbmi->bmiColors[i].rgbRed = (BYTE)red[i];
lpbmi->bmiColors[i].rgbGreen = (BYTE)green[i];
lpbmi->bmiColors[i].rgbBlue = (BYTE)blue[i];
}
}
}
// read the tiff lines and save them in the DIB
// with RGB mode, we have to change the order of the 3 samples RGB
<=> BGR for (row = 0; row < imageLength; row += RowsPerStrip)
{
nrow = (row + RowsPerStrip > imageLength ? imageLength - row
: RowsPerStrip);
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, row, 0), buf,
nrow * LineSize) == -1)
{
goto TiffReadError;
}
else
{
for (l = 0; l < nrow; l++)
{
if (SamplePerPixel == 3)
for (i = 0; i < (int)(imageWidth); i++)
{
lpBits[i * SamplePerPixel + 0] =
buf[l * LineSize + i * Sample PerPixel + 2];
lpBits[i * SamplePerPixel + 1] =
buf[l * LineSize + i * Sample PerPixel + 1];
lpBits[i * SamplePerPixel + 2] =
buf[l * LineSize + i * Sample PerPixel + 0];
}
else
memcpy(lpBits, &buf[(int)(l * LineSize)],
(int)imageWidth * SamplePerPixel);
lpBits -= imageWidth * SamplePerPixel + Align;
}
}
}
GlobalUnlock(hStrip);
GlobalFree(hStrip);
GlobalUnlock(hDIB);
GlobalUnlock(hDIB);
TIFFClose(tif);
}
}
return hDIB;
OutOfBufMemory:
TiffReadError:
GlobalUnlock(hDIB);
GlobalFree(hStrip);
OutOfDIBMemory:
TIFFClose(tif);
TiffOpenError:
return (HANDLE) 0;
OutOfBufMemory:
TiffReadError:
GlobalUnlock(hDIB);
GlobalFree(hStrip);
OutOfDIBMemory:
TIFFClose(tif);
TiffOpenError:
return (HANDLE)0;
}
static int checkcmap(int n, uint16_t* r, uint16_t* g, uint16_t* b)
static int checkcmap(int n, uint16_t *r, uint16_t *g, uint16_t *b)
{
while (n-- > 0)
if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256)
return (16);
return (16);
return (8);
}
/*************************************************************************
* All the following functions were created by microsoft, they are
* parts of the sample project "wincap" given with the SDK Win32.
@@ -247,135 +236,124 @@ static int checkcmap(int n, uint16_t* r, uint16_t* g, uint16_t* b)
HDIB CreateDIB(DWORD dwWidth, DWORD dwHeight, WORD wBitCount)
{
BITMAPINFOHEADER bi; // bitmap header
LPBITMAPINFOHEADER lpbi; // pointer to BITMAPINFOHEADER
DWORD dwLen; // size of memory block
HDIB hDIB;
DWORD dwBytesPerLine; // Number of bytes per scanline
BITMAPINFOHEADER bi; // bitmap header
LPBITMAPINFOHEADER lpbi; // pointer to BITMAPINFOHEADER
DWORD dwLen; // size of memory block
HDIB hDIB;
DWORD dwBytesPerLine; // Number of bytes per scanline
// Make sure bits per pixel is valid
if (wBitCount <= 1)
wBitCount = 1;
else if (wBitCount <= 4)
wBitCount = 4;
else if (wBitCount <= 8)
wBitCount = 8;
else if (wBitCount <= 24)
wBitCount = 24;
else
wBitCount = 4; // set default value to 4 if parameter is bogus
// Make sure bits per pixel is valid
if (wBitCount <= 1)
wBitCount = 1;
else if (wBitCount <= 4)
wBitCount = 4;
else if (wBitCount <= 8)
wBitCount = 8;
else if (wBitCount <= 24)
wBitCount = 24;
else
wBitCount = 4; // set default value to 4 if parameter is bogus
// initialize BITMAPINFOHEADER
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = dwWidth; // fill in width from parameter
bi.biHeight = dwHeight; // fill in height from parameter
bi.biPlanes = 1; // must be 1
bi.biBitCount = wBitCount; // from parameter
bi.biCompression = BI_RGB;
bi.biSizeImage =
(dwWidth * dwHeight * wBitCount) / 8; // 0; // 0's here
mean "default" bi.biXPelsPerMeter = 2834; // 0;
bi.biYPelsPerMeter = 2834; // 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
// initialize BITMAPINFOHEADER
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = dwWidth; // fill in width from parameter
bi.biHeight = dwHeight; // fill in height from parameter
bi.biPlanes = 1; // must be 1
bi.biBitCount = wBitCount; // from parameter
bi.biCompression = BI_RGB;
bi.biSizeImage = (dwWidth*dwHeight*wBitCount)/8; //0; // 0's here
mean "default"
bi.biXPelsPerMeter = 2834; //0;
bi.biYPelsPerMeter = 2834; //0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
// calculate size of memory block required to store the DIB. This
// block should be big enough to hold the BITMAPINFOHEADER, the color
// table, and the bits
// calculate size of memory block required to store the DIB. This
// block should be big enough to hold the BITMAPINFOHEADER, the color
// table, and the bits
dwBytesPerLine = (((wBitCount * dwWidth) + 31) / 32 * 4);
dwLen = bi.biSize + PaletteSize((LPSTR)&bi) + (dwBytesPerLine * dwHeight);
dwBytesPerLine = (((wBitCount * dwWidth) + 31) / 32 * 4);
dwLen = bi.biSize + PaletteSize((LPSTR)&bi) + (dwBytesPerLine * dwHeight);
// alloc memory block to store our bitmap
hDIB = GlobalAlloc(GHND, dwLen);
// alloc memory block to store our bitmap
hDIB = GlobalAlloc(GHND, dwLen);
// major bummer if we couldn't get memory block
if (!hDIB)
{
return NULL;
}
// major bummer if we couldn't get memory block
if (!hDIB)
{
return NULL;
}
// lock memory and get pointer to it
lpbi = (VOID FAR *)GlobalLock(hDIB);
// lock memory and get pointer to it
lpbi = (VOID FAR *)GlobalLock(hDIB);
// use our bitmap info structure to fill in first part of
// our DIB with the BITMAPINFOHEADER
*lpbi = bi;
// use our bitmap info structure to fill in first part of
// our DIB with the BITMAPINFOHEADER
*lpbi = bi;
// Since we don't know what the colortable and bits should contain,
// just leave these blank. Unlock the DIB and return the HDIB.
// Since we don't know what the colortable and bits should contain,
// just leave these blank. Unlock the DIB and return the HDIB.
GlobalUnlock(hDIB);
GlobalUnlock(hDIB);
/* return handle to the DIB */
return hDIB;
/* return handle to the DIB */
return hDIB;
}
LPSTR FAR FindDIBBits(LPSTR lpDIB)
{
return (lpDIB + *(LPDWORD)lpDIB + PaletteSize(lpDIB));
return (lpDIB + *(LPDWORD)lpDIB + PaletteSize(lpDIB));
}
WORD FAR PaletteSize(LPSTR lpDIB)
{
/* calculate the size required by the palette */
if (IS_WIN30_DIB (lpDIB))
return (DIBNumColors(lpDIB) * sizeof(RGBQUAD));
else
return (DIBNumColors(lpDIB) * sizeof(RGBTRIPLE));
/* calculate the size required by the palette */
if (IS_WIN30_DIB(lpDIB))
return (DIBNumColors(lpDIB) * sizeof(RGBQUAD));
else
return (DIBNumColors(lpDIB) * sizeof(RGBTRIPLE));
}
WORD DIBNumColors(LPSTR lpDIB)
{
WORD wBitCount; // DIB bit count
WORD wBitCount; // DIB bit count
/* If this is a Windows-style DIB, the number of colors in the
* color table can be less than the number of bits per pixel
* allows for (i.e. lpbi->biClrUsed can be set to some value).
* If this is the case, return the appropriate value.
*/
/* If this is a Windows-style DIB, the number of colors in the
* color table can be less than the number of bits per pixel
* allows for (i.e. lpbi->biClrUsed can be set to some value).
* If this is the case, return the appropriate value.
*/
if (IS_WIN30_DIB(lpDIB))
{
DWORD dwClrUsed;
if (IS_WIN30_DIB(lpDIB))
{
DWORD dwClrUsed;
dwClrUsed = ((LPBITMAPINFOHEADER)lpDIB)->biClrUsed;
if (dwClrUsed)
return (WORD)dwClrUsed;
}
dwClrUsed = ((LPBITMAPINFOHEADER)lpDIB)->biClrUsed;
if (dwClrUsed)
return (WORD)dwClrUsed;
}
/* Calculate the number of colors in the color table based on
* the number of bits per pixel for the DIB.
*/
if (IS_WIN30_DIB(lpDIB))
wBitCount = ((LPBITMAPINFOHEADER)lpDIB)->biBitCount;
else
wBitCount = ((LPBITMAPCOREHEADER)lpDIB)->bcBitCount;
/* Calculate the number of colors in the color table based on
* the number of bits per pixel for the DIB.
*/
if (IS_WIN30_DIB(lpDIB))
wBitCount = ((LPBITMAPINFOHEADER)lpDIB)->biBitCount;
else
wBitCount = ((LPBITMAPCOREHEADER)lpDIB)->bcBitCount;
/* return number of colors based on bits per pixel */
switch (wBitCount)
{
case 1:
return 2;
/* return number of colors based on bits per pixel */
switch (wBitCount)
{
case 1:
return 2;
case 4:
return 16;
case 4:
return 16;
case 8:
return 256;
case 8:
return 256;
default:
return 0;
}
default:
return 0;
}
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
+146
View File
@@ -0,0 +1,146 @@
# CMake build for libtiff
# Run "cmake" to generate the build files for your platform
#
# Copyright © 2015 Open Microscopy Environment / University of Dundee
# Copyright © 2021-2022 Roger Leigh <rleigh@codelibre.net>
# Written by Roger Leigh <rleigh@codelibre.net>
#
# Permission to use, copy, modify, distribute, and sell this software and
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.
#
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
#
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
cmake_minimum_required(VERSION 3.2.0)
include(Sphinx)
if (BUILD_SPHINX AND SPHINX_BUILD)
# Re-run CMake when the Sphinx configuration is updated
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/conf.py")
message(STATUS "Checking manual page dependencies")
# Create build directory and conf.py
set(sphinx_srcdir "${CMAKE_CURRENT_SOURCE_DIR}")
set(sphinx_builddir "${CMAKE_CURRENT_BINARY_DIR}")
file(MAKE_DIRECTORY "${sphinx_builddir}")
sphinx_manpages("${sphinx_srcdir}" "${sphinx_builddir}/man" MAN_PAGES)
sphinx_manpage_dependencies("${sphinx_srcdir}" MAN_PAGE_DEPENDENCIES)
sphinx_dependencies("${sphinx_srcdir}" SPHINX_DEPENDENCIES)
# Generate and install man pages
unset(man_target)
if(MAN_PAGES)
add_custom_command(OUTPUT ${MAN_PAGES}
COMMAND ${CMAKE_COMMAND} -E make_directory "${sphinx_builddir}/cache"
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/man"
COMMAND ${SPHINX_BUILD}
-D "release=${LIBTIFF_VERSION_FULL}"
-D "version=${tiff_VERSION_MAJOR}.${tiff_VERSION_MINOR}"
-d "${sphinx_builddir}/cache"
-b man
"${sphinx_srcdir}" "${sphinx_builddir}/man"
WORKING_DIRECTORY "${sphinx_srcdir}"
DEPENDS ${MAN_PAGE_DEPENDENCIES})
if(NOT TARGET doc-man)
add_custom_target(doc-man ALL)
endif()
add_custom_target(${PROJECT_NAME}-doc-man DEPENDS ${MAN_PAGES})
add_dependencies(doc-man ${PROJECT_NAME}-doc-man)
set(man_target ${PROJECT_NAME}-doc-man)
foreach (man ${MAN_PAGES})
string(REGEX REPLACE ".*\\.([0-9])[a-z]*\$" "\\1" man_section "${man}")
install(FILES "${man}"
DESTINATION "${CMAKE_INSTALL_MANDIR}/man${man_section}"
COMPONENT "runtime")
endforeach()
endif()
# Generate and install HTML manual
# Depends on man to allow sharing of cache with parallel build.
add_custom_command(OUTPUT "${sphinx_builddir}/html/index.html"
COMMAND ${CMAKE_COMMAND} -E make_directory "${sphinx_builddir}/cache"
COMMAND ${CMAKE_COMMAND} -E make_directory "${sphinx_builddir}/html"
COMMAND ${SPHINX_BUILD}
-D "release=${tiff_VERSION}"
-D "version=${tiff_VERSION_MAJOR}.${tiff_VERSION_MINOR}"
-d "${sphinx_builddir}/cache"
-b html
"${sphinx_srcdir}" "${sphinx_builddir}/html"
WORKING_DIRECTORY "${sphinx_srcdir}"
DEPENDS ${man_target} ${SPHINX_DEPENDENCIES})
if(NOT TARGET doc-html)
add_custom_target(doc-html ALL)
endif()
add_custom_target(${PROJECT_NAME}-doc-html DEPENDS "${sphinx_builddir}/html/index.html")
add_dependencies(doc-html ${PROJECT_NAME}-doc-html)
install(DIRECTORY "${sphinx_builddir}/html"
DESTINATION "${CMAKE_INSTALL_DOCDIR}/manual"
COMPONENT "runtime")
if(sphinx-linkcheck)
set(sphinx_linkcheck_all ALL)
endif()
if(NOT TARGET doc-linkcheck)
add_custom_target(doc-linkcheck)
endif()
add_custom_target(${PROJECT_NAME}-doc-linkcheck ${sphinx_linkcheck_all}
COMMAND ${CMAKE_COMMAND} -E make_directory "${sphinx_builddir}/cache"
COMMAND ${CMAKE_COMMAND} -E make_directory "${sphinx_builddir}/linkcheck"
COMMAND ${SPHINX_BUILD}
-D "release=${tiff_VERSION}"
-D "version=${tiff_VERSION_MAJOR}.${tiff_VERSION_MINOR}"
-c "${sphinx_builddir}"
-d "${sphinx_builddir}/cache"
-b linkcheck
"${sphinx_srcdir}" "${sphinx_builddir}/linkcheck"
COMMENT "Checking remote links in sphinx documentation"
WORKING_DIRECTORY "${sphinx_srcdir}"
DEPENDS ${man_target} ${SPHINX_DEPENDENCIES})
add_dependencies(doc-linkcheck ${PROJECT_NAME}-doc-linkcheck)
if(NOT TARGET doc-locallinkcheck)
add_custom_target(doc-locallinkcheck)
endif()
add_custom_target(${PROJECT_NAME}-doc-locallinkcheck ${sphinx_linkcheck_all}
COMMAND ${CMAKE_COMMAND}
"-DOUTPUT=${sphinx_builddir}/linkcheck/output.txt"
"-DSPHINX_INSTALL_PATH=${PROJECT_NAME}/manual/html"
"-DINTERNAL_REFERENCE=${sphinx_builddir}/html"
"-DEXTERNAL_REFERENCE=${CMAKE_INSTALL_FULL_DATAROOTDIR}/doc"
"-DDOXYGEN_REFERENCE=${PROJECT_BINARY_DIR}/docs/doxygen/api"
"-DDOXYGEN_INSTALL_PATH=${PROJECT_NAME}/api"
-P "${PROJECT_SOURCE_DIR}/cmake/SphinxCheckInternalLinks.cmake"
COMMENT "Checking local links in sphinx documentation"
WORKING_DIRECTORY "${sphinx_srcdir}"
DEPENDS doc-linkcheck)
add_dependencies(doc-locallinkcheck ${PROJECT_NAME}-doc-locallinkcheck)
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/html-prebuilt/")
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/html-prebuilt/"
DESTINATION "${CMAKE_INSTALL_DOCDIR}/manual/html"
COMPONENT "runtime")
else()
message(WARNING "Manual pages and HTML manual will not be generated or installed")
endif()
+288
View File
@@ -0,0 +1,288 @@
#
# Tag Image File Format (TIFF) Software
#
# Copyright (C) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
#
# Permission to use, copy, modify, distribute, and sell this software and
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.
#
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
#
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
# Process this file with automake to produce Makefile.in.
docdir = $(LIBTIFF_DOCDIR)/manual
rst_sources = \
index.rst \
build.rst \
internals.rst \
tools/tiffgt.rst \
tools/tiffdither.rst \
tools/tiff2pdf.rst \
tools/tiff2ps.rst \
tools/ppm2tiff.rst \
tools/raw2tiff.rst \
tools/fax2tiff.rst \
tools/tiffcrop.rst \
tools/tiff2bw.rst \
tools/fax2ps.rst \
tools/thumbnail.rst \
tools/tiffcmp.rst \
tools/tiffdump.rst \
tools/tiff2rgba.rst \
tools/tiffinfo.rst \
tools/rgb2ycbcr.rst \
tools/tiffset.rst \
tools/tiffsplit.rst \
tools/tiffmedian.rst \
tools/pal2rgb.rst \
tools/tiffcp.rst \
project/license.rst \
project/index.rst \
project/acknowledgements.rst \
project/bugs.rst \
project/mailinglist.rst \
project/psc.rst \
addingtags.rst \
specification/index.rst \
specification/bigtiff.rst \
specification/coverage.rst \
specification/technote2.rst \
specification/coverage-bigtiff.rst \
releases/v3.4beta028.rst \
releases/v4.0.9.rst \
releases/v3.9.0.rst \
releases/v4.0.7.rst \
releases/v3.5.7.rst \
releases/v4.0.0.rst \
releases/v3.7.0beta2.rst \
releases/v3.7.1.rst \
releases/index.rst \
releases/v3.8.0.rst \
releases/v4.1.0.rst \
releases/historical.rst \
releases/v3.5.6beta.rst \
releases/v3.6.1.rst \
releases/v4.2.0.rst \
releases/v3.7.0.rst \
releases/v4.0.1.rst \
releases/v3.5.1.rst \
releases/v4.0.10.rst \
releases/v4.0.6.rst \
releases/v4.0.8.rst \
releases/v3.9.1.rst \
releases/v3.4beta029.rst \
releases/v4.3.0.rst \
releases/v3.4beta031.rst \
releases/v3.7.0alpha.rst \
releases/v3.6.0.rst \
releases/v3.4beta036.rst \
releases/v4.0.4beta.rst \
releases/v3.8.1.rst \
releases/v4.4.0.rst \
releases/v3.4beta035.rst \
releases/v3.4beta032.rst \
releases/v3.4beta007.rst \
releases/v3.9.0beta.rst \
releases/v3.8.2.rst \
releases/v3.4beta018.rst \
releases/v3.7.3.rst \
releases/v3.4beta016.rst \
releases/v3.7.4.rst \
releases/v3.5.2.rst \
releases/v4.0.5.rst \
releases/v3.4beta024.rst \
releases/v3.5.5.rst \
releases/v4.0.2.rst \
releases/v3.9.5.rst \
releases/v3.9.2.rst \
releases/v3.4beta033.rst \
releases/v3.4beta034.rst \
releases/v3.9.3.rst \
releases/v3.9.4.rst \
releases/v3.7.0beta.rst \
releases/v3.5.4.rst \
releases/v4.0.3.rst \
releases/v3.5.3.rst \
releases/v4.0.4.rst \
releases/v3.7.2.rst \
releases/v4.5.0.rst \
releases/v4.5.1.rst \
releases/v4.6.0.rst \
releases/v4.7.0.rst \
rfcs/index.rst \
rfcs/rfc1_psc.rst \
rfcs/rfc2_restoring_needed_tools.rst \
functions.rst \
tools.rst \
terms.rst \
contrib.rst \
functions/TIFFRGBAImage.rst \
functions/TIFFGetField.rst \
functions/TIFFSetDirectory.rst \
functions/TIFFWriteRawStrip.rst \
functions/TIFFcolor.rst \
functions/TIFFstrip.rst \
functions/TIFFReadDirectory.rst \
functions/TIFFReadRawTile.rst \
functions/libtiff.rst \
functions/TIFFPrintDirectory.rst \
functions/TIFFsize.rst \
functions/TIFFReadRGBATile.rst \
functions/TIFFswab.rst \
functions/TIFFmemory.rst \
functions/TIFFtile.rst \
functions/TIFFReadEncodedTile.rst \
functions/TIFFWriteDirectory.rst \
functions/TIFFSetField.rst \
functions/TIFFWriteScanline.rst \
functions/TIFFClose.rst \
functions/TIFFFieldName.rst \
functions/TIFFFieldReadCount.rst \
functions/TIFFError.rst \
functions/TIFFOpen.rst \
functions/TIFFOpenOptions.rst \
functions/TIFFcodec.rst \
functions/TIFFFlush.rst \
functions/TIFFDataWidth.rst \
functions/TIFFReadRawStrip.rst \
functions/TIFFReadTile.rst \
functions/TIFFFieldWriteCount.rst \
functions/TIFFbuffer.rst \
functions/TIFFWriteRawTile.rst \
functions/TIFFWarning.rst \
functions/TIFFFieldDataType.rst \
functions/TIFFWriteEncodedStrip.rst \
functions/TIFFFieldPassCount.rst \
functions/TIFFReadRGBAImage.rst \
functions/TIFFReadScanline.rst \
functions/TIFFReadEncodedStrip.rst \
functions/TIFFFieldTag.rst \
functions/TIFFWriteTile.rst \
functions/TIFFReadRGBAStrip.rst \
functions/TIFFquery.rst \
functions/TIFFWriteEncodedTile.rst \
functions/_TIFFauxiliary.rst \
functions/_TIFFRewriteField.rst \
functions/TIFFAccessTagMethods.rst \
functions/TIFFClientInfo.rst \
functions/TIFFCreateDirectory.rst \
functions/TIFFCustomDirectory.rst \
functions/TIFFCustomTagList.rst \
functions/TIFFDeferStrileArrayWriting.rst \
functions/TIFFFieldQuery.rst \
functions/TIFFMergeFieldInfo.rst \
functions/TIFFProcFunctions.rst \
functions/TIFFReadFromUserBuffer.rst \
functions/TIFFSetTagExtender.rst \
functions/TIFFStrileQuery.rst \
libtiff.rst \
multi_page.rst \
images.rst
EXTRA_DIST = \
CMakeLists.txt \
conf.py \
specification/bigtiffpr_images \
images \
$(rst_sources)
if TIFF_DOCS
if SPHINX
doc-html: $(EXTRA_DIST) ../configure.ac
$(SPHINX_BUILD) \
-D "release=$(LIBTIFF_VERSION)" \
-D "version=$(LIBTIFF_MAJOR_VERSION).$(LIBTIFF_MINOR_VERSION)" \
-d "$(builddir)/cache" \
-b html \
"$(srcdir)" "$(builddir)/html"
touch doc-html
doc-man: $(EXTRA_DIST) ../configure.ac
$(SPHINX_BUILD) \
-D "release=$(LIBTIFF_VERSION)" \
-D "version=$(LIBTIFF_MAJOR_VERSION).$(LIBTIFF_MINOR_VERSION)" \
-d "$(builddir)/cache" \
-b man \
"$(srcdir)" "$(builddir)/man"
touch doc-man
man1_MANS = $(TIFF_MAN1_GEN)
man3_MANS = $(TIFF_MAN3_GEN)
@TIFF_MAN_RULES@
all-local: doc-html doc-man
clean-local:
rm -rf html
rm -rf man
rm -rf cache
rm -f doc-html
rm -f doc-man
html_installdir = html
else
# Sphinx not available
doc-html:
echo "HTML documentation generation not configured (sphinx not available)"
exit 1
doc-man:
echo "Manual page documentation generation not configured (sphinx not available)"
exit 1
.PHONY: doc-html doc-man
man1_MANS = $(TIFF_MAN1_PREBUILT)
man3_MANS = $(TIFF_MAN3_PREBUILT)
html_installdir = $(srcdir)/html-prebuilt
endif
install-data-local: all-local
find $(html_installdir) -type d | sed -e 's;^$(html_installdir);;' | while read dir; do \
echo " $(MKDIR_P) '$(DESTDIR)$(docdir)$$dir'"; \
$(MKDIR_P) "$(DESTDIR)$(docdir)$$dir" || exit 1; \
done
find $(html_installdir) -type f | sed -e 's;^$(html_installdir);;' | while read docfile; do \
docsubdir=$$(dirname $$docfile); \
echo "$(INSTALL_DATA) '$(html_installdir)$$docfile' '$(DESTDIR)$(docdir)$$docsubdir'"; \
$(INSTALL_DATA) "$(html_installdir)$$docfile" "$(DESTDIR)$(docdir)$$docsubdir"; \
done
uninstall-local:
echo "rm -r $(DESTDIR)$(docdir)"
rm -r $(DESTDIR)$(docdir)
else
# Documentation generation disabled
doc-html:
echo "HTML documentation generation not configured"
exit 1
doc-man:
echo "Manual page documentation generation not configured"
exit 1
.PHONY: doc-html doc-man
endif
dist-hook: doc-html doc-man
cp -r html $(distdir)/html-prebuilt
cp -r man $(distdir)/man-prebuilt
View File
+316
View File
@@ -0,0 +1,316 @@
Defining New TIFF Tags
======================
Libtiff has built-in knowledge of all the standard TIFF tags, as
well as extensions. The following describes how to add knowledge of
new tags as builtins to libtiff, or how to application specific tags can
be used by applications without modifying libtiff.
.. _TIFFFieldInfo_Definition:
TIFFFieldInfo
-------------
How libtiff manages specific tags is primarily controlled by the
definition for that tag value stored internally as a TIFFFieldInfo structure.
This structure looks like this:
.. highlight:: c
::
typedef struct {
ttag_t field_tag; /* field's tag */
short field_readcount; /* read count / TIFF_VARIABLE / TIFF_VARIABLE2 / TIFF_SPP */
short field_writecount; /* write count / TIFF_VARIABLE / TIFF_VARIABLE2 */
TIFFDataType field_type; /* type of associated data */
unsigned short field_bit; /* bit in fieldsset bit vector */
unsigned char field_oktochange; /* if true, can change while writing */
unsigned char field_passcount; /* if true, pass dir count on set */
char *field_name; /* ASCII name */
} TIFFFieldInfo;
.. c:member:: ttag_t TIFFFieldInfo.field_tag
The tag number. For instance 277 for the
SamplesPerPixel tag. Builtin tags will generally have a ``#define`` in
:file:`tiff.h` for each known tag.
.. c:member:: short TIFFFieldInfo.field_readcount
The number of values which should be read.
The special value :c:macro:`TIFF_VARIABLE` (-1) indicates that a variable number of
values may be read. The special value :c:macro:`TIFFTAG_SPP` (-2) indicates that there
should be one value for each sample as defined by :c:macro:`TIFFTAG_SAMPLESPERPIXEL`.
The special value :c:macro:`TIFF_VARIABLE2` (-3) is similar to :c:macro:`TIFF_VARIABLE`
but the required TIFFGetField() count value must be uint32_t* instead of uint16_t* as
for :c:macro:`TIFF_VARIABLE` (-1).
For ASCII fields with variable length, this field is :c:macro:`TIFF_VARIABLE`.
.. c:member:: short TIFFFieldInfo.field_writecount
The number of values which should be written.
Generally the same as field_readcount. A few built-in exceptions exist, but
I haven't analysed why they differ.
.. c:member:: TIFFDataType TIFFFieldInfo.field_type
Type of the field. One of :c:enumerator:`TIFF_BYTE`, :c:enumerator:`TIFF_ASCII`,
:c:enumerator:`TIFF_SHORT`, :c:enumerator:`TIFF_LONG`,
:c:enumerator:`TIFF_RATIONAL`, :c:enumerator:`TIFF_SBYTE`,
:c:enumerator:`TIFF_UNDEFINED`, :c:enumerator:`TIFF_SSHORT`,
:c:enumerator:`TIFF_SLONG`, :c:enumerator:`TIFF_SRATIONAL`,
:c:enumerator:`TIFF_FLOAT`, :c:enumerator:`TIFF_DOUBLE` or
:c:enumerator:`TIFF_IFD`.
And for BigTIFF :c:enumerator:`TIFF_LONG8`,
:c:enumerator:`TIFF_SLONG8` and :c:enumerator:`TIFF_IFD8`,
which are automatically reverted to 4 byte fields in
ClassicTIFF.
.. c:member:: unsigned short TIFFFieldInfo.field_bit
Built-in tags stored in special fields in the
TIFF structure have assigned field numbers to distinguish them (e.g.
:c:macro:`FIELD_SAMPLESPERPIXEL`). New tags should generally just use
:c:macro:`FIELD_CUSTOM` indicating they are stored in the generic tag list.
.. c:member:: unsigned char TIFFFieldInfo.field_oktochange
TRUE if it is OK to change this tag value
while an image is being written. FALSE for stuff that must be set once
and then left unchanged (like ImageWidth, or PhotometricInterpretation for
instance).
.. c:member:: unsigned char TIFFFieldInfo.field_passcount
If TRUE, then the count value must be passed
in :c:func:`TIFFSetField`, and :c:func:`TIFFGetField`, otherwise the count is not required.
This should generally be TRUE for non-ascii variable count tags unless
the count is implicit (such as with the colormap).
.. c:member:: char * TIFFFieldInfo.field_name
A name for the tag. Normally mixed case (studly caps)
like ``StripByteCounts``, and relatively short.
Within :file:`tif_dirinfo.c` file, the built-in TIFF tags are defined with
:c:struct:`TIFFField` structure that has additional parameters defining the var_arg
interface of :c:func:`TIFFSetField` and :c:func:`TIFFGetField`.
Various functions exist for getting the internal :c:struct:`TIFFFieldInfo`
definitions, including :c:func:`_TIFFFindFieldInfo`, and
:c:func:`_TIFFFindFieldInfoByName`. See
:file:`tif_dirinfo.c` for details.
.. _Tag_Auto_registration:
Default Tag Auto-registration
-----------------------------
In libtiff 3.6.0 a new mechanism was introduced allowing libtiff to
read unrecognised tags automatically. When an unknown tags is encountered,
it is automatically internally defined with a default name and a type
derived from the tag value in the file. Applications only need to predefine
application specific tags if they need to be able to set them in a file, or
if particular calling conventions are desired for :c:func:`TIFFSetField` and
:c:func:`TIFFGetField`.
When tags are autodefined like this the :c:member:`field_readcount` and
:c:member:`field_writecount` values are always :c:macro:`TIFF_VARIABLE2` (-3). The
:c:member:`field_passcount` is always TRUE, and the :c:member:`field_bit` is
:c:macro:`FIELD_CUSTOM`. The field name will be ``Tag %d`` where the ``%d``
is the tag number.
Thus, to read anonymous auto-registered tags use the following:
::
uint32_t count;
void* value; //has to be a pointer to the expected value type.
TIFFGetField(tif, TIFFTAG_UNKNOWN_TO_LIBTIFF, &count, &value);
.. _Define_Application_Tags:
Defining Application Tags
-------------------------
For various reasons, it is common for applications to want to define
their own tags to store information outside the core TIFF specification.
This is done by calling :c:func:`TIFFMergeFieldInfo` with one or more
:c:struct:`TIFFFieldInfo`.
The libgeotiff library provides geospatial information extensions within
a TIFF file. First, an array of :c:struct:`TIFFFieldInfo` is prepared with
information on the new tags:
::
static const TIFFFieldInfo xtiffFieldInfo[] = {
/* XXX Insert Your tags here */
{ TIFFTAG_GEOPIXELSCALE, -1,-1, TIFF_DOUBLE, FIELD_CUSTOM,
TRUE, TRUE, "GeoPixelScale" },
{ TIFFTAG_GEOTRANSMATRIX, -1,-1, TIFF_DOUBLE, FIELD_CUSTOM,
TRUE, TRUE, "GeoTransformationMatrix" },
{ TIFFTAG_GEOTIEPOINTS, -1,-1, TIFF_DOUBLE, FIELD_CUSTOM,
TRUE, TRUE, "GeoTiePoints" },
{ TIFFTAG_GEOKEYDIRECTORY, -1,-1, TIFF_SHORT, FIELD_CUSTOM,
TRUE, TRUE, "GeoKeyDirectory" },
{ TIFFTAG_GEODOUBLEPARAMS, -1,-1, TIFF_DOUBLE, FIELD_CUSTOM,
TRUE, TRUE, "GeoDoubleParams" },
{ TIFFTAG_GEOASCIIPARAMS, -1,-1, TIFF_ASCII, FIELD_CUSTOM,
TRUE, FALSE, "GeoASCIIParams" }
};
In order to define the tags, we call :c:func:`TIFFMergeFieldInfo` on the
desired TIFF handle with the list of :c:struct:`TIFFFieldInfo`.
::
#define N(a) (sizeof (a) / sizeof (a[0]))
/* Install the extended Tag field info */
TIFFMergeFieldInfo(tif, xtiffFieldInfo, N(xtiffFieldInfo));
The tags need to be defined for each TIFF file opened - and when reading
they should be defined before the tags of the file are read, yet a valid
:c:expr:`TIFF *` is needed to merge the tags against. In order to get them
registered at the appropriate part of the setup process, it is necessary
to register our merge function as an extender callback with libtiff.
This is done with :c:func:`TIFFSetTagExtender`. We also keep track of the
previous tag extender (if any) so that we can call it from our extender
allowing a chain of customizations to take effect.
::
static TIFFExtendProc _ParentExtender = NULL;
static
void _XTIFFInitialize(void)
{
static int first_time=1;
if (! first_time) return; /* Been there. Done that. */
first_time = 0;
/* Grab the inherited method and install */
_ParentExtender = TIFFSetTagExtender(_XTIFFDefaultDirectory);
}
The extender callback is looks like this. It merges in our new fields
and then calls the next extender if there is one in effect.
::
static void
_XTIFFDefaultDirectory(TIFF *tif)
{
/* Install the extended Tag field info */
TIFFMergeFieldInfo(tif, xtiffFieldInfo, N(xtiffFieldInfo));
/* Since an XTIFF client module may have overridden
* the default directory method, we call it now to
* allow it to set up the rest of its own methods.
*/
if (_ParentExtender)
(*_ParentExtender)(tif);
}
The above approach ensures that our new definitions are used when reading
or writing any TIFF file. However, since on reading we already have
default definitions for tags, it is usually not critical to pre-define them.
If tag definitions are only required for writing custom tags, you can just
call :c:func:`TIFFMergeFieldInfo` before setting new tags. The whole extender
architecture can then be avoided.
Adding New Builtin Tags
-----------------------
A similar approach is taken to the above. However, the :c:struct:`TIFFFieldInfo`
should be added to the :c:expr:`tiffFieldInfo[]` list in :file:`tif_dirinfo.c`.
Ensure that new tags are added in sorted order by the tag number.
Normally new built-in tags should be defined with :c:macro:`FIELD_CUSTOM`; however, if
it is desirable for the tag value to have it's own field in the :c:struct:`TIFFDirectory`
structure, then you will need to ``#define`` a new :c:macro:`FIELD_` value for it, and
add appropriate handling as follows:
#. Define the tag in :file:`tiff.h`.
#. Add a field to the directory structure in :file:`tif_dir.h`
and define a ``FIELD_*`` bit (also update the definition of
:c:macro:`FIELD_CODEC` to reflect your addition).
#. Add an entry in the :c:struct:`TIFFFieldInfo` array defined at the top of
:file:`tif_dirinfo.c`.
.. note::
Note that you must keep this array sorted by tag
number and that the widest variant entry for a tag should come
first (e.g. :c:macro:`LONG` before :c:macro:`SHORT`).
#. Add entries in :c:func:`_TIFFVSetField` and :c:func:`_TIFFVGetField`
for the new tag.
#. (*optional*) If the value associated with the tag is not a scalar value
(e.g. the array for ``TransferFunction``) and requires
special processing,
then add the appropriate code to :c:func:`TIFFReadDirectory` and
:c:func:`TIFFWriteDirectory`. You're best off finding a similar tag and
cribbing code.
#. Add support to :c:func:`TIFFPrintDirectory` in :file:`tif_print.c`
to print the tag's value.
If you want to maintain portability, beware of making assumptions
about data types. Use the typedefs (:c:type:`uint16_t`, etc. when dealing with
data on disk and ``t*_t`` when stuff is in memory) and be careful about
passing items through printf or similar vararg interfaces.
Adding New Codec-private Tags
-----------------------------
To add tags that are meaningful *only when a particular compression
algorithm is used* follow these steps:
#. Define the tag in :file:`tiff.h`.
#. Allocate storage for the tag values in the private state block of
the codec.
#. Insure the state block is created when the codec is initialized.
#. At :c:func:`TIFFInitfoo` time override the method pointers in the
:c:struct:`TIFF` structure for getting, setting and printing tag values.
For example,
::
sp->vgetparent = tif->tif_vgetfield;
tif->tif_vgetfield = fooVGetField; /* hook for codec tags */
sp->vsetparent = tif->tif_vsetfield;
tif->tif_vsetfield = fooVSetField; /* hook for codec tags */
tif->tif_printdir = fooPrintDir; /* hook for codec tags */
(Actually you may decide not to override the
:c:member:`tif_printdir` method, but rather just specify it).
#. Create a private :c:struct:`TIFFFieldInfo` array for your tags and
merge them into the core tags at initialization time using
:c:func:`_TIFFMergeFieldInfo`; e.g.
::
_TIFFMergeFieldInfo(tif, fooFieldInfo, N(fooFieldInfo));
(where :c:macro:`N` is a macro used liberaly throughout the distributed code).
#. Fill in the get and set routines. Be sure to call the parent method
for tags that you are not handled directly. Also be sure to set the
``FIELD_*`` bits for tags that are to be written to the file. Note that
you can create "pseudo-tags" by defining tags that are processed
exclusively in the get/set routines and never written to file (see
the handling of :c:macro:`TIFFTAG_FAXMODE` in :file:`tif_fax3.c`
for an example of this).
#. Fill in the print routine, if appropriate.
Note that space has been allocated in the ``FIELD_*`` bit space for
codec-private tags. Define your bits as ``FIELD_CODEC+<offset>`` to
keep them away from the core tags. If you need more tags than there
is room for, just increase :c:macro:`FIELD_SETLONGS` at the top of
:file:`tiffiop.h`.
+754
View File
@@ -0,0 +1,754 @@
Building the TIFF Software Distribution
=======================================
.. image:: images/cramps.gif
:width: 159
:alt: cramps
This chapter contains step-by-step instructions on how to configure
and build the TIFF software distribution. The software is most
easily built on a UNIX system, but with a little bit of work it can
easily be built and used on other non-UNIX platforms.
Building on all systems with CMake
----------------------------------
CMake may be used to
generate build files for most common build systems and IDEs, and
supports all UNIX-like systems as well as Windows. See
the `CMake website <http://www.cmake.org/>`_ for further
details. To build the software on you need to first run
:command:`cmake` to configure the build and generate the system-specific
build files. This reads the top-level :file:`CMakeLists.txt` file,
which probes the target system for necessary tools and functions,
checks any options you specified to configure the build, and then
outputs build files configured for your system. If using ``Unix
Makefiles``, once configuration is done, you simply
run :command:`make` (or :command:`gmake`) to build the software and
then :command:`make install` to do the installation. For other build
systems, you do the equivalent steps with the tool for that system.
For example, on any UNIX system:
.. code-block:: shell
$ cd ./tiff-4.0.5
$ cmake
...lots of messages...
$ make
...lots of messages...
$ make test
...lots of messages...
# make install
Building is dependent on a :program:`make` utility and a C
(and optionally a C++) compiler, so you will need these tools.
In general, the software is designed such that the following
targets will always be available:
::
make [all] build stuff
make test run the test suite
make install build and install stuff
make clean remove object files, executables and cruft
Build Trees
^^^^^^^^^^^
There are two schemes for configuring and building the software. If
you intend to build the software for only one target system, you
can configure the software so that it is built in the same
directories as the source code.
.. code-block:: shell
$ gzip -dc tiff-4.0.5.tar.gz | tar -xf -
$ cd ./tiff-4.0.5
$ cmake
$ make
$ make test
$ make install
Otherwise, you can configure a build tree that is parallel to
the source tree hierarchy (or in some completely different place)
but which contains only configured files and files created during
the build procedure.
.. code-block:: shell
$ gzip -dc tiff-4.0.5.tar.gz | tar -xf -
$ mkdir tiff-4.0.5-build
$ cd ./tiff-4.0.5-build
$ cmake ../tiff-4.0.5
$ make
$ make test
$ make install
This second scheme is useful for:
* building multiple targets from a single source tree
* building from a read-only source tree
* sharing the source files via a network, but building on
multiple systems
* keeping the source tree clean
(unlike :program:`autoconf`, :program:`cmake` does not provide
a ``distclean`` target, so out of source builds are
recommended)
Generators
^^^^^^^^^^
The default generator for UNIX is ``Unix Makefiles``, and on Windows is
``NMake Makefiles`` or ``MSBuild`` depending upon the setup.
Run :command:`cmake --help` to list all the
generators available for your platform. For example, to use the Ninja
`build system <https://martine.github.io/ninja/>`_ on UNIX or
Windows:
.. code-block:: shell
cmake -G Ninja
cmake --build .
ctest -V
cmake --build . --target install
Note that :command:`cmake --build .` is a build-system-independent way
of building a target; you can always use the build system directly.
Alternatively, using the MSBuild system on Windows (64-bit Release
build with VS2013):
.. code-block:: shell
cmake -G "Visual Studio 12 2013 Win64"
cmake --build . --config Release
ctest -V -C Release
cmake --build . --config Release --target install
With the above configuration, it's also possible to open the generated
solution file with the Visual Studio IDE as well as building on the
command-line.
Configuration Options
^^^^^^^^^^^^^^^^^^^^^
The configuration process is critical to the proper compilation,
installation, and operation of the
software. The :file:`CMakeLists.txt` script runs a series of tests to
decide whether or not the target system supports required
functionality and, if it does not, whether it can emulate or
workaround the missing functions. After running :command:`cmake`, check
the :file:`CMakeCache.txt` file; this contains all the results of the
checks performed and the options set by the user. If :program:`cmake`
failed to run, check :file:`CMakeFiles/CMakeOutput.log`
and :file:`CMakeFiles/CMakeError.log`; these should record the error
which caused the failure.
A second function of the configure script is to set the default
configuration parameters for the software. Of particular note are the
directories where the software is to be installed. By default the
software is installed in the :file:`/usr/local` hierarchy. To change
this behaviour the appropriate parameters can be specified on the
command line. Run :command:`cmake --help` to get a full list of possible
options, and :command:`cmake -LH` to list all the configurable options for
this software package, or :command:`cmake -LAH` to show all advanced
options in addition. Standard installation related options are shown
below.
.. list-table:: Installation options
:widths: 10 15
:header-rows: 1
* - Option
- Description
* - ``CMAKE_INSTALL_PREFIX``
- Installation root directory. The options below may be used to override
individual installation locations.
* - ``CMAKE_INSTALL_BINDIR``
- user executables [:file:`PREFIX/bin`]
* - ``CMAKE_INSTALL_SBINDIR``
- system admin executables [:file:`PREFIX/sbin`]
* - ``CMAKE_INSTALL_LIBEXECDIR``
- program executables [:file:`PREFIX/libexec`]
* - ``CMAKE_INSTALL_SYSCONFDIR``
- read-only single-machine data [:file:`PREFIX/etc`]
* - ``CMAKE_INSTALL_SHAREDSTATEDIR``
- modifiable architecture-independent data [:file:`PREFIX/com`]
* - ``CMAKE_INSTALL_LOCALSTATEDIR``
- modifiable single-machine data [:file:`PREFIX/var`]
* - ``CMAKE_INSTALL_LIBDIR``
- object code libraries [:file:`PREFIX/lib`]
* - ``CMAKE_INSTALL_INCLUDEDIR``
- C header files [:file:`PREFIX/include`]
* - ``CMAKE_INSTALL_OLDINCLUDEDIR``
- C header files for non-gcc [:file:`/usr/include`]
* - ``CMAKE_INSTALL_DATAROOTDIR``
- read-only architecture-independent data root [:file:`PREFIX/share`]
* - ``CMAKE_INSTALL_DATADIR``
- read-only architecture-independent data [:file:`DATAROOTDIR`]
* - ``CMAKE_INSTALL_LOCALEDIR``
- locale-dependent data [:file:`DATAROOTDIR/locale`]
* - ``CMAKE_INSTALL_MANDIR``
- man documentation [:file:`DATAROOTDIR/man`]
* - ``CMAKE_INSTALL_DOCDIR``
- documentation root [:file:`DATAROOTDIR/doc/tiff`]
Also see the
CMake `documentation <http://www.cmake.org/cmake/help/latest/>`_
for `additional variables <http://www.cmake.org/cmake/help/latest/manual/cmake-variables.7.html>`_
which may be set.
Configuring Optional Packages/Support
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The TIFF software comes with several packages that are installed
only as needed, or only if specifically configured at the time the
configure script is run. Packages can be configured via the
:program:`cmake` commandline parameters.
Static/Shared Objects Support
.............................
``BUILD_SHARED_LIBS[=ON|OFF]``:
Build shared libraries (default is ``ON``)
This option controls whether or not to configure the software
to build a shared and static binaries for the TIFF library. Use of
shared libraries can significantly reduce the disk space needed for
users of the TIFF software. If shared libraries are not used then
the code is statically linked into each application that uses it.
``ld-version-script[=ON|OFF]``
Enable linker version script (default is ``ON``)
Add shared library symbol versioning on ELF-based systems (e.g.
Linux and FreeBSD) which use the GNU linker. This is needed if
several major versions of libtiff might be loaded at once into the
same program.
JPEG Support
............
``jpeg[=ON|OFF]``
Enable IJG JPEG library usage (required for JPEG compression, enabled by default)
``JPEG_INCLUDE_DIR=DIR``:
Location of IJG JPEG library headers
``JPEG_LIBRARY=DIR``
Location of IJG JPEG library binary
The ``JPEG`` package enables support for the handling of
TIFF images with JPEG-encoded data. Support for JPEG-encoded data
requires the Independent JPEG Group (IJG) ``libjpeg``
distribution; this software is available at `<http://www.ijg.org/>`_.
The CMake script automatically tries to search for a working IJG JPEG
installation. If it fails to find library, JPEG support will be
automatically disabled. If you want specify the exact paths to
library binary and headers, use above options for that.
ZIP Support
...........
The ``ZIP`` support enables support for the handling of TIFF
images with deflate-encoded data (enabled by default if
available). Support for deflate-encoded data requires the freely
available ``zlib`` distribution written by Jean-loup Gailly and
Mark Adler; this software is available at `<http://www.zlib.org/>`_.
Building on a UNIX System with Autoconf
---------------------------------------
.. program:: configure
To build the software on a UNIX system you need to first run the
:program:`configure` shell script that is located in the top level of the
source directory. This script probes the target system for
necessary tools and functions and constructs a build environment in
which the software may be compiled. Once configuration is done, you
simply run :command:`make` (or :command:`gmake`) to build the software
and then :command:`make install` to do the installation; for example:
.. code-block:: shell
% cd ./tiff-4.0.5
% ./configure
...lots of messages...
% make
...lots of messages...
% make check
...lots of messages...
# make install
Supplied Makefiles are dependent on a :program:`make` utility and a C
(and optionally a C++ compiler), so you will need these tools.
In general, the software is designed such that the following
should be "make-able" in each directory:
.. list-table:: Make targets
:widths: 10 15
:header-rows: 1
* - Target
- Description
* - :command:`make [all]`
- build everything
* - :command:`make check`
- run the test suite
* - :command:`make install`
- build and install everything
* - :command:`make clean`
- remove object files, executables and cruft
* - :command:`make distclean`
- remove everything that can be recreated
Note that after running :command:`make distclean` the
:program:`configure` script must be run again to create the :file:`Makefile`
and other make-related files.
Build Trees
^^^^^^^^^^^
There are two schemes for configuring and building the software. If
you intend to build the software for only one target system, you
can configure the software so that it is built in the same
directories as the source code.
.. code-block:: shell
% gzip -dc tiff-4.0.5.tar.gz | tar -xf -
% cd ./tiff-4.0.5
% ./configure
% make
% make check
% make install
Otherwise, you can configure a build tree that is parallel to
the source tree hierarchy (or in some completely different place)
but which contains only configured files and files created during
the build procedure.
.. code-block:: shell
% gzip -dc tiff-4.0.5.tar.gz | tar -xf -
% mkdir tiff-4.0.5-build
% cd ./tiff-4.0.5-build
% ../tiff-4.0.5/configure
% make
% make check
% make install
This second scheme is useful for:
* building multiple targets from a single source tree
* building from a read-only source tree
* sharing the source files via a network, but building on
multiple systems
Configuration Options
^^^^^^^^^^^^^^^^^^^^^
The configuration process is critical to the proper compilation,
installation, and operation of the software. The configure script
runs a series of tests to decide whether or not the target system
supports required functionality and, if it does not, whether it can
emulate or workaround the missing functions. This procedure is
fairly complicated and, due to the nonstandard nature of most UNIX
systems, prone to error. The first time that you configure the
software for use you should check the output from the configure
script and look for anything that does not make sense for your
system.
A second function of the configure script is to set the default
configuration parameters for the software. Of particular note are
the directories where the software is to be installed. By default
the software is installed in the :file:`/usr/local` hierarchy. To
change this behaviour the appropriate parameters can be specified
on the command line to configure. Run :command:`./configure --help` to
get a full list of possible options. Standard installation related
options are shown below.
Installation directories:
.. option:: --prefix=PREFIX
install architecture-independent files in *PREFIX* [:file:`/usr/local`]
.. option:: --exec-prefix=EPREFIX
install architecture-dependent files in *EPREFIX* [:file:`PREFIX`]
By default, :command:`make install` will install all the files in
:file:`/usr/local/bin`, :file:`/usr/local/lib` etc. You can specify
an installation prefix other than :file:`/usr/local` using :option:`--prefix`,
for instance ``--prefix=$HOME``. For better control, use the options below.
Fine tuning of the installation directories:
.. option:: --bindir=DIR
user executables [:file:`EPREFIX/bin`]
.. option:: --sbindir=DIR
system admin executables [:file:`EPREFIX/sbin`]
.. option:: --libexecdir=DIR
program executables [:file:`EPREFIX/libexec`]
.. option:: --sysconfdir=DIR
read-only single-machine data [:file:`PREFIX/etc`]
.. option:: --sharedstatedir=DIR
modifiable architecture-independent data [:file:`PREFIX/com`]
.. option:: --localstatedir=DIR
modifiable single-machine data [:file:`PREFIX/var`]
.. option:: --libdir=DIR
object code libraries [:file:`EPREFIX/lib`]
.. option:: --includedir=DIR
C header files [:file:`PREFIX/include`]
.. option:: --oldincludedir=DIR
C header files for non-gcc [:file:`/usr/include`]
.. option:: --datarootdir=DIR
read-only architecture-independent data root [:file:`PREFIX/share`]
.. option:: --datadir=DIR
read-only architecture-independent data [:file:`DATAROOTDIR`]
.. option:: --localedir=DIR
locale-dependent data [:file:`DATAROOTDIR/locale`]
.. option:: --mandir=DIR
man documentation [:file:`DATAROOTDIR/man`]
.. option:: --docdir=DIR
documentation root [:file:`DATAROOTDIR/doc/tiff`]
.. option:: --htmldir=DIR
html documentation [:file:`DOCDIR`]
Program names:
.. option:: --program-prefix=PREFIX
prepend *PREFIX* to installed program names
.. option:: --program-suffix=SUFFIX
append *SUFFIX* to installed program names
.. option:: --program-transform-name=PROGRAM
run :command:`sed` *PROGRAM* on installed program names
Configuring Optional Packages/Support
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The TIFF software comes with several packages that are installed
only as needed, or only if specifically configured at the time the
configure script is run. Packages can be configured via the
:program:`configure` script commandline parameters.
Static/Shared Objects Support
.............................
.. option:: --enable-shared[=PKGS]
Build shared libraries [enabled]
.. option:: --enable-static[=PKGS]
Build static libraries [enabled]
These options control whether or not to configure the software
to build a shared and static binaries for the TIFF library. Use of
shared libraries can significantly reduce the disk space needed for
users of the TIFF software. If shared libraries are not used then
the code is statically linked into each application that uses it.
By default both types of binaries are configured.
.. option:: --enable-rpath
Enable runtime linker paths (``-R`` libtool option)
Add library directories (see other options below) to the TIFF
library run-time linker path.
.. option:: --enable-ld-version-script
Enable linker version script [yes]
Add shared library symbol versioning on ELF-based systems (e.g.
Linux and FreeBSD) which use the GNU linker. This is needed if
several major versions of libtiff might be loaded at once into the
same program.
JPEG Support
............
.. option:: --disable-jpeg
Disable IJG JPEG library usage (required for JPEG compression, enabled by default)
.. option:: --with-jpeg-include-dir=DIR
Location of IJG JPEG library headers
.. option:: --with-jpeg-lib-dir=DIR
Location of IJG JPEG library binary)
The ``JPEG`` package enables support for the handling of
TIFF images with JPEG-encoded data. Support for JPEG-encoded data
requires the Independent JPEG Group (IJG) ``libjpeg``
distribution; this software is available at
`<http://www.ijg.org/>`_. The :program:`configure`
script automatically tries to search for a working IJG JPEG
installation. If it fails to find library, JPEG support will be
automatically disabled. If you want specify the exact paths to
library binary and headers, use above switches for that.
ZIP Support
...........
The ``ZIP`` support enables support for the handling of
TIFF images with deflate-encoded data. Support for deflate-encoded
data requires the freely available ``zlib`` distribution
written by Jean-loup Gailly and Mark Adler; this software is
available at `<http://www.zlib.org/>`_. Support will be
enabled automatically if ``zlib`` is found.
Building the Software on Other Systems
--------------------------------------
This section contains information that might be useful if you are
working on a non-UNIX system that is not directly supported. All
library-related files described below are located in the
:file:`libtiff` directory.
The library requires two files that are generated
*on-the-fly*. The file :file:`tif_fax3sm.c` has the state
tables for the Group 3 and Group 4 decoders. This file is generated
by the :program:`mkg3states` program on a UNIX system; for
example:
.. code-block:: shell
cd libtiff
cc -o mkg3states mkg3states.c
rm -f tif_fax3sm.c
./mkg3states -c const tif_fax3sm.c
The ``-c`` option can be used to control whether or not the
resulting tables are generated with a ``const`` declaration.
The ``-s`` option can be used to specify a C storage class for
the table declarations. The ``-b`` option can be used to force
data values to be explicitly bracketed with ``{}`` (apparently
needed for some MS-Windows compilers); otherwise the structures are
emitted in as compact a format as possible. Consult the source code
for this program if you have questions.
The second file required to build the library, :file:`version.h`,
contains the version information returned by the
:c:func:`TIFFGetVersion` routine. This file is built on most systems
using the :file:`mkversion` program and the contents of the
:file:`VERSION` and :file:`tiff.alpha` files; for example,
.. code-block:: shell
cd libtiff
cc -o mkversion mkversion.c
rm -f version.h
./mkversion -v ../VERSION -a ../dist/tiff.alpha version.h
Otherwise, when building the library on a non-UNIX system be
sure to consult the files :file:`tiffcomp.h` and :file:`tiffconf.h`.
The former contains system compatibility definitions while the
latter is provided so that the software configuration can be
controlled on systems that do not support the make facility for
building the software.
Systems without a 32-bit compiler may not be able to handle some
of the codecs in the library; especially the Group 3 and 4 decoder.
If you encounter problems try disabling support for a particular
codec; consult the :doc:`internals`.
Programs in the tools directory are written to assume an ANSI C
compilation environment. There may be a few POSIX'isms as well. The
code in the :file:`port` directory is provided to emulate routines
that may be missing on some systems. On UNIX systems the
:program:`configure` script automatically figures out which routines
are not present on a system and enables the use of the equivalent
emulation routines from the :file:`port` directory. It may be
necessary to manually do this work on a non-UNIX system.
Testing the software
--------------------
Assuming you have working versions of :doc:`/tools/tiffgt`, you can now use
it to view any of the sample images available for testing, or try
:doc:`/tools/tiffinfo` to display the file metadata. See the
:doc:`images` section on obtaining the test images. Otherwise, you can
do a cursory check of the library with the :doc:`/tools/tiffcp` and
:doc:`/tools/tiffcmp` programs. For example,
.. code-block:: shell
tiffcp -lzw cramps.tif x.tif
tiffcmp cramps.tif x.tif
(:program:`tiffcmp` should be silent if the files compare
correctly).
LibTIFF source files
--------------------
The following files make up the core library:
.. list-table:: Core library source files
:widths: 5 15
:header-rows: 1
* - File
- Description
* - :file:`libtiff/tiff.h`
- TIFF spec definitions
* - :file:`libtiff/tiffconf.h`
- non-UNIX configuration definitions
* - :file:`libtiff/tiffio.h`
- public TIFF library definitions
* - :file:`libtiff/tiffiop.h`
- private TIFF library definitions
* - :file:`libtiff/t4.h`
- CCITT Group 3/4 code tables+definitions
* - :file:`libtiff/tif_dir.h`
- private defs for TIFF directory handling
* - :file:`libtiff/tif_fax3.h`
- CCITT Group 3/4-related definitions
* - :file:`libtiff/tif_predict.h`
- private defs for Predictor tag support
* - :file:`libtiff/tiffvers.h`
- version string
* - :file:`libtiff/uvcode.h`
- LogL/LogLuv codec-specific definitions
* - :file:`libtiff/tif_aux.c`
- auxiliary directory-related functions
* - :file:`libtiff/tif_close.c`
- close an open TIFF file
* - :file:`libtiff/tif_codec.c`
- configuration table of builtin codecs
* - :file:`libtiff/tif_color.c`
- colorspace transforms
* - :file:`libtiff/tif_compress.c`
- compression scheme support
* - :file:`libtiff/tif_dir.c`
- directory tag interface code
* - :file:`libtiff/tif_dirinfo.c`
- directory known tag support code
* - :file:`libtiff/tif_dirread.c`
- directory reading code
* - :file:`libtiff/tif_dirwrite.c`
- directory writing code
* - :file:`libtiff/tif_dumpmode.c`
- "no" compression codec
* - :file:`libtiff/tif_error.c`
- library error handler
* - :file:`libtiff/tif_fax3.c`
- CCITT Group 3 and 4 codec
* - :file:`libtiff/tif_fax3sm.c`
- G3/G4 state tables (generated by mkg3states)
* - :file:`libtiff/tif_flush.c`
- i/o and directory state flushing
* - :file:`libtiff/tif_getimage.c`
- :doc:`/functions/TIFFRGBAImage` support
* - :file:`libtiff/tif_jbig.c`
- JBIG codec
* - :file:`libtiff/tif_jpeg.c`
- JPEG codec (interface to the IJG distribution)
* - :file:`libtiff/tif_jpeg_12.c`
- 12-bit JPEG codec (interface to the IJG distribution)
* - :file:`libtiff/tif_lerc.c`
- LERC codec
* - :file:`libtiff/tif_luv.c`
- SGI LogL/LogLuv codec
* - :file:`libtiff/tif_lzma.c`
- LZMA codec
* - :file:`libtiff/tif_lzw.c`
- LZW codec
* - :file:`libtiff/tif_next.c`
- NeXT 2-bit scheme codec (decoding only)
* - :file:`libtiff/tif_ojpeg.c`
- Old JPEG codec (obsolete, decoding only)
* - :file:`libtiff/tif_open.c`
- open and simply query code
* - :file:`libtiff/tif_packbits.c`
- Packbits codec
* - :file:`libtiff/tif_pixarlog.c`
- Pixar codec
* - :file:`libtiff/tif_predict.c`
- Predictor tag support
* - :file:`libtiff/tif_print.c`
- directory printing support
* - :file:`libtiff/tif_read.c`
- image data reading support
* - :file:`libtiff/tif_strip.c`
- some strip-related code
* - :file:`libtiff/tif_swab.c`
- byte and bit swapping support
* - :file:`libtiff/tif_thunder.c`
- Thunderscan codec (decoding only)
* - :file:`libtiff/tif_tile.c`
- some tile-related code
* - :file:`libtiff/tif_unix.c`
- UNIX-related OS support
* - :file:`libtiff/tif_version.c`
- library version support
* - :file:`libtiff/tif_warning.c`
- library warning handler
* - :file:`libtiff/tif_win32.c`
- Win32 (Windows)-related OS support
* - :file:`libtiff/tif_write.c`
- image data writing support
* - :file:`libtiff/tif_zip.c`
- Deflate codec
* - :file:`libtiff/tif_zstd.c`
- ZSTD codec
* - :file:`libtiff/mkg3states.c`
- program to generate G3/G4 decoder state tables
* - :file:`libtiff/mkspans.c`
- program to generate black-white span tables
+179
View File
@@ -0,0 +1,179 @@
# -*- coding: utf-8 -*-
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# Substitutions from external build system.
srcdir = None
builddir = None
ext_source_branch = None
ext_source_user = None
# -- Project information -----------------------------------------------------
project = 'LibTIFF'
copyright = '1988-2022, LibTIFF contributors'
author = 'LibTIFF contributors'
# The full version, including alpha/beta/rc tags
release = 'UNDEFINED'
version = 'UNDEFINED'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.extlinks'
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
extlinks = {
# GitLab links
'issue' : ('https://gitlab.com/libtiff/libtiff/-/issues/%s', 'issue #%s'),
'merge' : ('https://gitlab.com/libtiff/libtiff/-/merge_requests/%s', 'merge request #%s'),
'commit' : ('https://gitlab.com/libtiff/libtiff/-/commit/%s', 'commit %s'),
'branch' : ('https://gitlab.com/libtiff/libtiff/-/tree/%s', 'branch %s'),
'tag' : ('https://gitlab.com/libtiff/libtiff/-/tags/%s', 'tag %s'),
# Old Bugzilla
'bugzilla' : ('http://bugzilla.maptools.org/show_bug.cgi?id=%s', 'MapTools bugzilla #%s'),
'bugzilla-rs' : ('http://bugzilla.remotesensing.org/show_bug.cgi?id=%s', 'Remote Sensing bugzilla #%s [no longer available]'),
# GDAL
'gdal-trac' : ('http://trac.osgeo.org/gdal/ticket/%s', 'GDAL trac #%s'),
'oss-fuzz' : ('https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=%s', 'OSS-Fuzz #%s'),
# Security
'cve' : ('https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s', 'CVE-%s'),
}
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinxdoc'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_extra_path = []
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('functions/libtiff', 'libtiff', 'introduction to libtiff, a library for reading and writing TIFF files', author, '3tiff'),
('tools/fax2ps', 'fax2ps', 'convert a TIFF facsimile to compressed PostScript™', author, 1),
('tools/fax2tiff', 'fax2tiff', 'create a TIFF Class F fax file from raw fax data', author, 1),
('tools/pal2rgb', 'pal2rgb', 'convert a palette color TIFF image to a full color image', author, 1),
('tools/ppm2tiff', 'ppm2tiff', 'create a TIFF file from PPM, PGM and PBM image files', author, 1),
('tools/raw2tiff', 'raw2tiff', 'create a TIFF file from a raw data file', author, 1),
('tools/rgb2ycbcr', 'rgb2ycbcr', 'convert non-YCbCr TIFF images to a YCbCr TIFF image', author, 1),
('tools/thumbnail', 'thumbnail', 'create a TIFF file with thumbnail images', author, 1),
('tools/tiff2bw', 'tiff2bw', 'convert a color TIFF image to greyscale', author, 1),
('tools/tiff2pdf', 'tiff2pdf', 'convert a TIFF image to a PDF document', author, 1),
('tools/tiff2ps', 'tiff2ps', 'convert TIFF image to PostScript™', author, 1),
('tools/tiff2rgba', 'tiff2rgba', 'convert a TIFF image to RGBA color space', author, 1),
('tools/tiffcmp', 'tiffcmp', 'compare two TIFF files', author, 1),
('tools/tiffcp', 'tiffcp', 'copy (and possibly convert) a TIFF file', author, 1),
('tools/tiffcrop', 'tiffcrop', 'select, copy, crop, convert, extract, and/or process one or more TIFF files', author, 1),
('tools/tiffdither', 'tiffdither', 'convert a greyscale TIFF image to bilevel using dithering', author, 1),
('tools/tiffdump', 'tiffdump', 'print verbatim information about TIFF files', author, 1),
('tools/tiffgt', 'tiffgt', 'display an image stored in a TIFF file (Silicon Graphics version)', author, 1),
('tools/tiffinfo', 'tiffinfo', 'print information about TIFF files', author, 1),
('tools/tiffmedian', 'tiffmedian', 'apply the median cut algorithm to data in a TIFF file', author, 1),
('tools/tiffset', 'tiffset', 'set or unset a field in a TIFF header', author, 1),
('tools/tiffsplit', 'tiffsplit', 'split a multi-image TIFF into single-image TIFF files', author, 1),
('functions/_TIFFauxiliary', '_TIFFauxiliary', 'auxiliary functions', author, '3tiff'),
('functions/_TIFFRewriteField', '_TIFFRewriteField', 'rewrite a field in the directory on disk', author, '3tiff'),
('functions/TIFFAccessTagMethods', 'TIFFAccessTagMethods', 'provides read/write access to the TIFFTagMethods', author, '3tiff'),
('functions/TIFFbuffer', 'TIFFbuffer', 'I/O buffering control routines', author, '3tiff'),
('functions/TIFFClientInfo', 'TIFFClientInfo', 'provides a method to hand over user defined data from one routine to another', author, '3tiff'),
('functions/TIFFClose', 'TIFFClose', 'close a previously opened TIFF file', author, '3tiff'),
('functions/TIFFcodec', 'TIFFcodec', 'codec-related utility routines', author, '3tiff'),
('functions/TIFFcolor', 'TIFFcolor', 'color conversion routines', author, '3tiff'),
('functions/TIFFCreateDirectory', 'TIFFCreateDirectory', 'routines to create a directory and retrieve information about directories', author, '3tiff'),
('functions/TIFFCustomDirectory', 'TIFFCustomDirectory', 'routines to create a custom directory', author, '3tiff'),
('functions/TIFFCustomTagList', 'TIFFCustomTagList', 'returns information about the custom tag list', author, '3tiff'),
('functions/TIFFDataWidth', 'TIFFDataWidth', 'get the size of TIFF data types', author, '3tiff'),
('functions/TIFFDeferStrileArrayWriting', 'TIFFDeferStrileArrayWriting', 'defer strile array writing', author, '3tiff'),
('functions/TIFFError', 'TIFFError', 'library error handling interface', author, '3tiff'),
('functions/TIFFFieldDataType', 'TIFFFieldDataType', 'get TIFF data type from field information', author, '3tiff'),
('functions/TIFFFieldName', 'TIFFFieldName', 'get TIFF field name from field information', author, '3tiff'),
('functions/TIFFFieldPassCount', 'TIFFFieldPassCount', 'get whether to pass a count to TIFFGetField/TIFFSetField', author, '3tiff'),
('functions/TIFFFieldQuery', 'TIFFFieldQuery', 'routines to query TIFF field information', author, '3tiff'),
('functions/TIFFFieldReadCount', 'TIFFFieldReadCount', 'get number of values to be read from field', author, '3tiff'),
('functions/TIFFFieldTag', 'TIFFFieldTag', 'get TIFF field tag value from field information', author, '3tiff'),
('functions/TIFFFieldWriteCount', 'TIFFFieldWriteCount', 'get number of values to be written to field', author, '3tiff'),
('functions/TIFFFlush', 'TIFFFlush', 'flush pending writes to an open TIFF file', author, '3tiff'),
('functions/TIFFGetField', 'TIFFGetField', 'get the value(s) of a tag in an open TIFF file', author, '3tiff'),
('functions/TIFFmemory', 'TIFFmemory', 'memory management-related functions for use with TIFF files', author, '3tiff'),
('functions/TIFFMergeFieldInfo', 'TIFFMergeFieldInfo', 'add application-defined TIFF tags to the list of known libtiff tags', author, '3tiff'),
('functions/TIFFOpen', 'TIFFOpen', 'open a TIFF file for reading or writing', author, '3tiff'),
('functions/TIFFPrintDirectory', 'TIFFPrintDirectory', 'print a description of a TIFF directory', author, '3tiff'),
('functions/TIFFProcFunctions', 'TIFFProcFunctions', 'set TIFF processing functions', author, '3tiff'),
('functions/TIFFquery', 'TIFFquery', 'query routines', author, '3tiff'),
('functions/TIFFReadDirectory', 'TIFFReadDirectory', 'get the contents of the next directory in an open TIFF file', author, '3tiff'),
('functions/TIFFReadEncodedStrip', 'TIFFReadEncodedStrip', 'read and decode a strip of data from an open TIFF file', author, '3tiff'),
('functions/TIFFReadEncodedTile', 'TIFFReadEncodedTile', 'read and decode a tile of data from an open TIFF file', author, '3tiff'),
('functions/TIFFReadFromUserBuffer', 'TIFFReadFromUserBuffer', 'decode data using an user defined buffer', author, '3tiff'),
('functions/TIFFReadRawStrip', 'TIFFReadRawStrip', 'return the undecoded contents of a strip of data from an open TIFF file', author, '3tiff'),
('functions/TIFFReadRawTile', 'TIFFReadRawTile', 'return an undecoded tile of data from an open TIFF file', author, '3tiff'),
('functions/TIFFReadRGBAImage', 'TIFFReadRGBAImage', 'read and decode an image into a fixed-format raster', author, '3tiff'),
('functions/TIFFReadRGBAStrip', 'TIFFReadRGBAStrip', 'read and decode an image strip into a fixed-format raster', author, '3tiff'),
('functions/TIFFReadRGBATile', 'TIFFReadRGBATile', 'read and decode an image tile into a fixed-format raster', author, '3tiff'),
('functions/TIFFReadScanline', 'TIFFReadScanline', 'read and decode a scanline of data from an open TIFF file', author, '3tiff'),
('functions/TIFFReadTile', 'TIFFReadTile', 'read and decode a tile of data from an open TIFF file', author, '3tiff'),
('functions/TIFFRGBAImage', 'TIFFRGBAImage', 'read and decode an image into a raster', author, '3tiff'),
('functions/TIFFSetDirectory', 'TIFFSetDirectory', 'set the current directory for an open TIFF file', author, '3tiff'),
('functions/TIFFSetField', 'TIFFSetField', 'set the value(s) of a tag in a TIFF file open for writing', author, '3tiff'),
('functions/TIFFSetTagExtender', 'TIFFSetTagExtender', 'register the merge function for user defined tags as an extender callback with libtiff', author, '3tiff'),
('functions/TIFFsize', 'TIFFsize', 'return the size of various items associated with an open TIFF file', author, '3tiff'),
('functions/TIFFStrileQuery', 'TIFFStrileQuery', 'get strile byte count and offset', author, '3tiff'),
('functions/TIFFstrip', 'TIFFstrip', 'strip-related utility routines', author, '3tiff'),
('functions/TIFFswab', 'TIFFswab', 'byte- and bit-swapping routines', author, '3tiff'),
('functions/TIFFtile', 'TIFFtile', 'tile-related utility routines', author, '3tiff'),
('functions/TIFFWarning', 'TIFFWarning', 'library warning interface', author, '3tiff'),
('functions/TIFFWriteDirectory', 'TIFFWriteDirectory', 'write the current directory in an open TIFF file', author, '3tiff'),
('functions/TIFFWriteEncodedStrip', 'TIFFWriteEncodedStrip', 'compress and write a strip of data to an open TIFF file', author, '3tiff'),
('functions/TIFFWriteEncodedTile', 'TIFFWriteEncodedTile', 'compress and write a tile of data to an open TIFF file', author, '3tiff'),
('functions/TIFFWriteRawStrip', 'TIFFWriteRawStrip', 'write a strip of raw data to an open TIFF file', author, '3tiff'),
('functions/TIFFWriteRawTile', 'TIFFWriteRawTile', 'write a tile of raw data to an open TIFF file', author, '3tiff'),
('functions/TIFFWriteScanline', 'TIFFWriteScanline', 'write a scanline to an open TIFF file', author, '3tiff'),
('functions/TIFFWriteTile', 'TIFFWriteTile', 'encode and write a tile of data to an open TIFF file', author, '3tiff'),
]
# If true, show URL addresses after external links.
man_show_urls = True
smartquotes = False
+88
View File
@@ -0,0 +1,88 @@
Contributed TIFF Software
=========================
.. image:: images/smallliz.jpg
:width: 108
:alt: smallliz
The :file:`contrib` directory has contributed software that
uses the TIFF library or which is associated with the library
(typically glue and guidance for ports to non-UNIX platforms, or tools that
aren't directly TIFF related).
.. list-table:: Contributed software
:widths: 5 20
:header-rows: 1
* - Location
- Description
* - :file:`contrib/dbs`
- various tools from Dan & Chris Sears, including a simple X-based viewer
* - :file:`contrib/ras`
- two programs by Patrick Naughton for converting
between Sun rasterfile format and TIFF (these
require :file:`libpixrect.a`, as opposed to the one in
tools that doesn't)
* - :file:`contrib/mac-mpw`
:file:`contrib/mac-cw`
- scripts and files from Niles Ritter for building
the library and tools under Macintosh/MPW C and
code warrior.
* - :file:`contrib/acorn`
- scripts and files from Peter Greenham for building
the library and tools on an Acorn RISC OS system.
* - :file:`contrib/win32`
- scripts and files from Scott Wagner for building
the library under Windows NT and Windows 95. (The makefile.vc in the
libtiff/libtiff directory may be sufficient for most users.)
* - :file:`contrib/win_dib`
- two separate implementations of TIFF to DIB code suitable for any Win32
platform. Contributed by Mark James, and Philippe Tenenhaus.
* - :file:`contrib/ojpeg`
- Patch for IJG JPEG library related to support for some Old JPEG in TIFF files.
Contributed by Scott Marovich.
* - :file:`contrib/dosdjgpp`
- scripts and files from Alexander Lehmann for building
the library under MSDOS with the DJGPP v2 compiler.
* - :file:`contrib/tags`
- scripts and files from Niles Ritter for adding private
tag support at runtime, without changing libtiff.
* - :file:`contrib/mfs`
- code from Mike Johnson to read+write images in memory
without modifying the library
* - :file:`contrib/pds`
- various routines from Conrad Poelman; a TIFF image iterator and
code to support "private sub-directories"
* - :file:`contrib/iptcutil`
- A utility by `Bill Radcliffe <billr@corbis.com>`_ to
convert an extracted IPTC Newsphoto caption from a binary blob to
ASCII text, and vice versa. IPTC binary blobs can be extracted from
images via the `ImageMagick <http://www.ImageMagick.org/>`_ convert(1)
utility.
* - :file:`contrib/addtiffo`
- A utility (and supporting subroutine) for building
one or more reduce resolution
overviews to an existing TIFF file. Supplied by
`Frank Warmerdam <http://pobox.com/~warmerdam>`_.
* - :file:`contrib/stream`
- A class (TiffStream) for accessing TIFF files through a C++ stream
interface. Supplied by `Avi Bleiweiss <avi@shutterfly.com>`_.
Questions regarding these packages are usually best directed toward
their authors.
+66
View File
@@ -0,0 +1,66 @@
TIFF Functions Overview
=======================
.. toctree::
:maxdepth: 1
:titlesonly:
functions/libtiff
functions/TIFFAccessTagMethods
functions/TIFFbuffer
functions/TIFFClientInfo
functions/TIFFClose
functions/TIFFcodec
functions/TIFFcolor
functions/TIFFCreateDirectory
functions/TIFFCustomDirectory
functions/TIFFCustomTagList
functions/TIFFDataWidth
functions/TIFFDeferStrileArrayWriting
functions/TIFFError
functions/TIFFFieldDataType
functions/TIFFFieldName
functions/TIFFFieldPassCount
functions/TIFFFieldQuery
functions/TIFFFieldReadCount
functions/TIFFFieldTag
functions/TIFFFieldWriteCount
functions/TIFFFlush
functions/TIFFGetField
functions/TIFFmemory
functions/TIFFMergeFieldInfo
functions/TIFFOpen
functions/TIFFOpenOptions
functions/TIFFPrintDirectory
functions/TIFFProcFunctions
functions/TIFFquery
functions/TIFFReadDirectory
functions/TIFFReadEncodedStrip
functions/TIFFReadEncodedTile
functions/TIFFReadFromUserBuffer
functions/TIFFReadRawStrip
functions/TIFFReadRawTile
functions/TIFFReadRGBAImage
functions/TIFFReadRGBAStrip
functions/TIFFReadRGBATile
functions/TIFFReadScanline
functions/TIFFReadTile
functions/TIFFRGBAImage
functions/TIFFSetDirectory
functions/TIFFSetField
functions/TIFFSetTagExtender
functions/TIFFsize
functions/TIFFStrileQuery
functions/TIFFstrip
functions/TIFFswab
functions/TIFFtile
functions/TIFFWarning
functions/TIFFWriteDirectory
functions/TIFFWriteEncodedStrip
functions/TIFFWriteEncodedTile
functions/TIFFWriteRawStrip
functions/TIFFWriteRawTile
functions/TIFFWriteScanline
functions/TIFFWriteTile
functions/_TIFFauxiliary
functions/_TIFFRewriteField
+30
View File
@@ -0,0 +1,30 @@
TIFFAccessTagMethods
====================
Synopsis
--------
.. highlight:: c
::
#include <tiffio.h>
.. c:function:: TIFFTagMethods *TIFFAccessTagMethods(TIFF* tif)
Description
-----------
This provides read/write access to the TIFFTagMethods within the TIFF
structure to application code without giving access to the private TIFF
structure.
Diagnostics
-----------
None
See also
--------
:doc:`libtiff` (3tiff)
+40
View File
@@ -0,0 +1,40 @@
TIFFClientInfo
==============
Synopsis
--------
.. highlight:: c
::
#include <tiffio.h>
.. c:function:: void *TIFFGetClientInfo(TIFF* tif, const char *name)
.. c:function:: void TIFFSetClientInfo(TIFF* tif, void *data, const char *name)
Description
-----------
.. TODO: Check explanation of clientinfo linked list intention and usage.
The *clientinfo* linked list provides a method to hand over user defined
data from one routine to another via the internal ``tif`` storage of the
``libtiff`` library.
:c:func:`TIFFGetClientInfo` returns a pointer to the data of the named entry
in the clientinfo-list. If the *name* is not found ``NULL`` is returned.
:c:func:`TIFFSetClientInfo` adds or replaces an entry in the clientinfo-list
with the *name* and the pointer to the *data* provided by the caller.
Diagnostics
-----------
None.
See also
--------
:doc:`libtiff` (3tiff),
+51
View File
@@ -0,0 +1,51 @@
TIFFClose
==========
Synopsis
--------
.. highlight:: c
::
#include <tiffio.h>
.. c:function:: void TIFFClose(TIFF* tif)
.. c:function:: void TIFFCleanup(TIFF* tif)
Description
-----------
:c:func:`TIFFClose` closes a file that was previously opened with
:c:func:`TIFFOpen`. Any buffered data are flushed to the file, including
the contents of the current directory (if modified); and all resources
are reclaimed. :c:func:`TIFFClose` calls :c:func:`TIFFCleanup` and then
the associated function to close the file handle.
:c:func:`TIFFCleanup` is an auxiliary function to free the TIFF structure.
The given structure will be completely freed, so you should save opened file
handle and pointer to the close procedure in external variables before
calling :c:func:`TIFFCleanup`, if you will need these ones to close the file.
:c:func:`TIFFCleanup` calls :c:func:`TIFFFlush`, which stores all pending data
in the file.
.. note::
Both functions have no return value.
If you want to check whether the data has been successfully written
to the file, you can call :c:func:`TIFFFlush`, which has a return value,
before :c:func:`TIFFClose`.
Diagnostics
-----------
All error messages are directed to the :c:func:`TIFFErrorExtR` routine.
Likewise, warning messages are directed to the :c:func:`TIFFWarningExtR` routine.
See also
--------
:doc:`libtiff` (3tiff),
:doc:`TIFFOpen` (3tiff),
:doc:`TIFFError` (3tiff)
+83
View File
@@ -0,0 +1,83 @@
TIFFCreateDirectory
===================
Synopsis
--------
.. highlight:: c
::
#include <tiffio.h>
.. c:function:: int TIFFCreateDirectory(TIFF* tif)
.. c:function:: int TIFFFreeDirectory(TIFF* tif)
.. c:function:: int TIFFUnlinkDirectory(TIFF* tif, tdir_t dirn)
Description
-----------
The following routines create or release a directory.
:c:func:`TIFFCreateDirectory` setup for a directory in a open TIFF file.
The newly created directory will not exist on the file till
:c:func:`TIFFWriteDirectory`, :c:func:`TIFFCheckpointDirectory`,
:c:func:`TIFFFlush` or :c:func:`TIFFClose` is called.
:c:func:`TIFFWriteDirectory` also creates a new directory,
frees the ``*tif`` structure and sets up a new one.
:c:func:`TIFFFreeDirectory` releases allocated storage associated with a
directory, especially custom-fields.
However, the main part of the directory is not touched. Routine
:c:func:`TIFFCleanup` calls :c:func:`TIFFFreeDirectory` to release
the directory part of the `tif` structure.
:c:func:`TIFFUnlinkDirectory` unlink the specified directory from the
directory chain.
The parameter *dirn* specifies the subfile/directory
as an integer number, with the first directory numbered one (1).
This is different to :c:func:`TIFFSetDirectory` or :c:func:`TIFFCurrentDirectory` where the first
directory starts with zero (0).
Directory query functions :c:func:`TIFFCurrentDirectory`,
:c:func:`TIFFCurrentDirOffset`, :c:func:`TIFFLastDirectory` and
:c:func:`TIFFNumberOfDirectories` retrieve information about directories
in an open TIFF file. Be aware that until a directory is
not written to file AND read back, the query functions won't retrieve
the correct information!
Notes
-----
Be aware:
- that until a directory is not written to file AND read back, the
query functions won't retrieve the correct information!
- that the newly created directory will not exist on the file till
:c:func:`TIFFWriteDirectory`, :c:func:`TIFFCheckpointDirectory`,
:c:func:`TIFFFlush` or :c:func:`TIFFClose` has been called.
- that :c:func:`TIFFCreateDirectory` and :c:func:`TIFFWriteDirectory`
create a new directory, free the ``*tif`` structure and set up a new one.
- that unlike :c:func:`TIFFWriteDirectory`, :c:func:`TIFFCheckpointDirectory`
does not free up the directory data structures in memory.
After ``libtiff`` version 4.6.0 :c:func:`TIFFCreateDirectory` also releases
the directory part of the `tif` structure by calling :c:func:`TIFFFreeDirectory`,
which should have been called by the user application before creating a new directory.
Diagnostics
-----------
All error messages are directed to the :c:func:`TIFFErrorExtR` routine.
Likewise, warning messages are directed to the :c:func:`TIFFWarningExtR` routine.
See also
--------
:doc:`libtiff` (3tiff),
:doc:`TIFFCustomDirectory` (3tiff),
:doc:`TIFFquery` (3tiff),
:doc:`TIFFSetDirectory` (3tiff),
:doc:`TIFFWriteDirectory` (3tiff)

Some files were not shown because too many files have changed in this diff Show More