diff options
Diffstat (limited to 'tiff/tools')
-rwxr-xr-x[-rw-r--r--] | tiff/tools/CMakeLists.txt | 122 | ||||
-rw-r--r-- | tiff/tools/Makefile.am | 5 | ||||
-rw-r--r-- | tiff/tools/Makefile.in | 18 | ||||
-rw-r--r-- | tiff/tools/Makefile.vc | 51 | ||||
-rw-r--r-- | tiff/tools/fax2ps.c | 72 | ||||
-rw-r--r-- | tiff/tools/fax2tiff.c | 130 | ||||
-rw-r--r-- | tiff/tools/pal2rgb.c | 159 | ||||
-rw-r--r-- | tiff/tools/ppm2tiff.c | 118 | ||||
-rw-r--r-- | tiff/tools/raw2tiff.c | 238 | ||||
-rw-r--r-- | tiff/tools/rgb2ycbcr.c | 110 | ||||
-rw-r--r-- | tiff/tools/thumbnail.c | 218 | ||||
-rw-r--r-- | tiff/tools/tiff2bw.c | 182 | ||||
-rw-r--r-- | tiff/tools/tiff2pdf.c | 874 | ||||
-rw-r--r-- | tiff/tools/tiff2ps.c | 467 | ||||
-rw-r--r-- | tiff/tools/tiff2rgba.c | 155 | ||||
-rw-r--r-- | tiff/tools/tiffcmp.c | 173 | ||||
-rw-r--r-- | tiff/tools/tiffcp.c | 706 | ||||
-rw-r--r-- | tiff/tools/tiffcrop.c | 2192 | ||||
-rw-r--r-- | tiff/tools/tiffdither.c | 92 | ||||
-rw-r--r-- | tiff/tools/tiffdump.c | 268 | ||||
-rw-r--r-- | tiff/tools/tiffgt.c | 32 | ||||
-rw-r--r-- | tiff/tools/tiffinfo.c | 161 | ||||
-rw-r--r-- | tiff/tools/tiffmedian.c | 112 | ||||
-rw-r--r-- | tiff/tools/tiffset.c | 48 | ||||
-rw-r--r-- | tiff/tools/tiffsplit.c | 81 |
25 files changed, 3398 insertions, 3386 deletions
diff --git a/tiff/tools/CMakeLists.txt b/tiff/tools/CMakeLists.txt index ff2a1ddc..66b8e0bb 100644..100755 --- a/tiff/tools/CMakeLists.txt +++ b/tiff/tools/CMakeLists.txt @@ -22,73 +22,88 @@ # LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE # OF THIS SOFTWARE. -extra_dist(Makefile.vc) +add_executable(fax2ps) +target_sources(fax2ps PRIVATE fax2ps.c) +target_link_libraries(fax2ps PRIVATE tiff port) -include_directories(${PROJECT_SOURCE_DIR}/libtiff - ${PROJECT_BINARY_DIR}/libtiff - ${PROJECT_SOURCE_DIR}/port - ${CMAKE_CURRENT_BINARY_DIR}) +add_executable(fax2tiff) +target_sources(fax2tiff PRIVATE fax2tiff.c) +target_link_libraries(fax2tiff PRIVATE tiff port) -add_executable(fax2ps fax2ps.c) -target_link_libraries(fax2ps tiff port) +add_executable(pal2rgb) +target_sources(pal2rgb PRIVATE pal2rgb.c) +target_link_libraries(pal2rgb PRIVATE tiff port) -add_executable(fax2tiff fax2tiff.c) -target_link_libraries(fax2tiff tiff port) +add_executable(ppm2tiff) +target_sources(ppm2tiff PRIVATE ppm2tiff.c) +target_link_libraries(ppm2tiff PRIVATE tiff port) -add_executable(pal2rgb pal2rgb.c) -target_link_libraries(pal2rgb tiff port) +add_executable(raw2tiff) +target_sources(raw2tiff PRIVATE raw2tiff.c) +target_link_libraries(raw2tiff PRIVATE tiff port CMath::CMath) -add_executable(ppm2tiff ppm2tiff.c) -target_link_libraries(ppm2tiff tiff port) +add_executable(rgb2ycbcr) +target_sources(rgb2ycbcr PRIVATE rgb2ycbcr.c) +target_link_libraries(rgb2ycbcr PRIVATE tiff port) -add_executable(raw2tiff raw2tiff.c) -target_link_libraries(raw2tiff tiff port) +add_executable(thumbnail) +target_sources(thumbnail PRIVATE thumbnail.c) +target_link_libraries(thumbnail PRIVATE tiff port CMath::CMath) -add_executable(rgb2ycbcr rgb2ycbcr.c) -target_link_libraries(rgb2ycbcr tiff port) +add_executable(tiff2bw) +target_sources(tiff2bw PRIVATE tiff2bw.c) +target_link_libraries(tiff2bw PRIVATE tiff port) -add_executable(thumbnail thumbnail.c) -target_link_libraries(thumbnail tiff port) +add_executable(tiff2pdf) +target_sources(tiff2pdf PRIVATE tiff2pdf.c) +target_link_libraries(tiff2pdf PRIVATE tiff port) -add_executable(tiff2bw tiff2bw.c) -target_link_libraries(tiff2bw tiff port) +add_executable(tiff2ps) +target_sources(tiff2ps PRIVATE tiff2ps.c) +target_link_libraries(tiff2ps PRIVATE tiff port CMath::CMath) -add_executable(tiff2pdf tiff2pdf.c) -target_link_libraries(tiff2pdf tiff port) +add_executable(tiff2rgba) +target_sources(tiff2rgba PRIVATE tiff2rgba.c) +target_link_libraries(tiff2rgba PRIVATE tiff port) -add_executable(tiff2ps tiff2ps.c) -target_link_libraries(tiff2ps tiff port) +add_executable(tiffcmp) +target_sources(tiffcmp PRIVATE tiffcmp.c) +target_link_libraries(tiffcmp PRIVATE tiff port) -add_executable(tiff2rgba tiff2rgba.c) -target_link_libraries(tiff2rgba tiff port) +add_executable(tiffcp) +target_sources(tiffcp PRIVATE tiffcp.c) +target_link_libraries(tiffcp PRIVATE tiff port) -add_executable(tiffcmp tiffcmp.c) -target_link_libraries(tiffcmp tiff port) +add_executable(tiffcrop) +target_sources(tiffcrop PRIVATE tiffcrop.c) +target_link_libraries(tiffcrop PRIVATE tiff port CMath::CMath) -add_executable(tiffcp tiffcp.c) -target_link_libraries(tiffcp tiff port) +add_executable(tiffdither) +target_sources(tiffdither PRIVATE tiffdither.c) +target_link_libraries(tiffdither PRIVATE tiff port) -add_executable(tiffcrop tiffcrop.c) -target_link_libraries(tiffcrop tiff port) +add_executable(tiffdump) +target_sources(tiffdump PRIVATE tiffdump.c) +target_link_libraries(tiffdump PRIVATE tiff port) -add_executable(tiffdither tiffdither.c) -target_link_libraries(tiffdither tiff port) +add_executable(tiffinfo) +target_sources(tiffinfo PRIVATE tiffinfo.c) +target_link_libraries(tiffinfo PRIVATE tiff port) -add_executable(tiffdump tiffdump.c) -target_link_libraries(tiffdump tiff port) +add_executable(tiffmedian) +target_sources(tiffmedian PRIVATE tiffmedian.c) +target_link_libraries(tiffmedian PRIVATE tiff port) -add_executable(tiffinfo tiffinfo.c) -target_link_libraries(tiffinfo tiff port) +add_executable(tiffset) +target_sources(tiffset PRIVATE tiffset.c) +target_link_libraries(tiffset PRIVATE tiff port) -add_executable(tiffmedian tiffmedian.c) -target_link_libraries(tiffmedian tiff port) - -add_executable(tiffset tiffset.c) -target_link_libraries(tiffset tiff port) - -add_executable(tiffsplit tiffsplit.c) -target_link_libraries(tiffsplit tiff port) +add_executable(tiffsplit) +target_sources(tiffsplit PRIVATE tiffsplit.c) +target_link_libraries(tiffsplit PRIVATE tiff port) +# rgb2ycbcr and thumbnail are intended to *NOT* be installed. They are for +# testing purposes only. install(TARGETS fax2ps fax2tiff pal2rgb @@ -110,15 +125,10 @@ install(TARGETS fax2ps RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") if(HAVE_OPENGL) - if(OPENGL_INCLUDE_DIR) - include_directories(${OPENGL_INCLUDE_DIR}) - endif() - if(GLUT_INCLUDE_DIR) - include_directories(${GLUT_INCLUDE_DIR}) - endif() - - add_executable(tiffgt tiffgt.c) - target_link_libraries(tiffgt tiff port ${GLUT_LIBRARIES} ${OPENGL_LIBRARIES}) + add_executable(tiffgt) + target_sources(tiffgt PRIVATE tiffgt.c) + target_link_libraries(tiffgt PRIVATE tiff port) + target_link_libraries(tiffgt PRIVATE OpenGL::GL GLUT::GLUT) install(TARGETS tiffgt RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") diff --git a/tiff/tools/Makefile.am b/tiff/tools/Makefile.am index 3054bee3..c8142b05 100644 --- a/tiff/tools/Makefile.am +++ b/tiff/tools/Makefile.am @@ -27,8 +27,7 @@ LIBPORT = $(top_builddir)/port/libport.la LIBTIFF = $(top_builddir)/libtiff/libtiff.la EXTRA_DIST = \ - CMakeLists.txt \ - Makefile.vc + CMakeLists.txt bin_PROGRAMS = \ fax2ps \ @@ -128,7 +127,7 @@ tiffgt_SOURCES = tiffgt.c tiffgt_CFLAGS = $(CFLAGS) $(GLUT_CFLAGS) $(AM_CFLAGS) tiffgt_LDADD = $(LIBTIFF) $(LIBPORT) $(X_LIBS) $(GLUT_LIBS) -AM_CPPFLAGS = -I$(top_srcdir)/libtiff +AM_CPPFLAGS = -I$(top_srcdir)/libtiff -I$(top_srcdir)/port echo: (echo $(CFLAGS)) diff --git a/tiff/tools/Makefile.in b/tiff/tools/Makefile.in index 8b1a2460..fc1bff84 100644 --- a/tiff/tools/Makefile.in +++ b/tiff/tools/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2020 Free Software Foundation, Inc. +# Copyright (C) 1994-2018 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -133,8 +133,10 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/libtiff/tif_config.h \ - $(top_builddir)/libtiff/tiffconf.h +CONFIG_HEADER = $(top_builddir)/config.h \ + $(top_builddir)/libtiff/tif_config.h \ + $(top_builddir)/libtiff/tiffconf.h \ + $(top_builddir)/port/libport_config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = @HAVE_OPENGL_TRUE@am__EXEEXT_1 = tiffgt$(EXEEXT) @@ -224,7 +226,7 @@ AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = -DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/libtiff +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) -I$(top_builddir)/libtiff -I$(top_builddir)/port depcomp = $(SHELL) $(top_srcdir)/config/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/fax2ps.Po ./$(DEPDIR)/fax2tiff.Po \ @@ -437,6 +439,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -449,8 +452,7 @@ top_srcdir = @top_srcdir@ LIBPORT = $(top_builddir)/port/libport.la LIBTIFF = $(top_builddir)/libtiff/libtiff.la EXTRA_DIST = \ - CMakeLists.txt \ - Makefile.vc + CMakeLists.txt @HAVE_RPATH_TRUE@AM_LDFLAGS = $(LIBDIR) fax2ps_SOURCES = fax2ps.c @@ -496,7 +498,7 @@ tiffsplit_LDADD = $(LIBTIFF) $(LIBPORT) tiffgt_SOURCES = tiffgt.c tiffgt_CFLAGS = $(CFLAGS) $(GLUT_CFLAGS) $(AM_CFLAGS) tiffgt_LDADD = $(LIBTIFF) $(LIBPORT) $(X_LIBS) $(GLUT_LIBS) -AM_CPPFLAGS = -I$(top_srcdir)/libtiff +AM_CPPFLAGS = -I$(top_srcdir)/libtiff -I$(top_srcdir)/port all: all-am .SUFFIXES: diff --git a/tiff/tools/Makefile.vc b/tiff/tools/Makefile.vc deleted file mode 100644 index 453db43e..00000000 --- a/tiff/tools/Makefile.vc +++ /dev/null @@ -1,51 +0,0 @@ -# -# 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. -# -# Makefile for MS Visual C and Watcom C compilers. -# -# To build: -# C:\libtiff\tools> nmake /f makefile.vc - -!INCLUDE ..\nmake.opt - -TARGETS = tiffinfo.exe tiffdump.exe fax2tiff.exe \ - fax2ps.exe pal2rgb.exe ppm2tiff.exe \ - rgb2ycbcr.exe thumbnail.exe raw2tiff.exe \ - tiff2bw.exe tiff2rgba.exe tiff2pdf.exe tiff2ps.exe \ - tiffcmp.exe tiffcp.exe tiffcrop.exe tiffdither.exe \ - tiffmedian.exe tiffset.exe tiffsplit.exe - -INCL = -I..\libtiff -I..\port -DNEED_LIBPORT -LIBS = $(LIBS) ..\port\libport.lib ..\libtiff\libtiff.lib - -default: $(TARGETS) - -.c.exe: - $(CC) $(CFLAGS) $*.c $(EXTRA_OBJ) $(LIBS) - -tiffgt.exe: - $(CC) $(CFLAGS) tiffgt.c $(EXTRA_OBJ) $(LIBS) - -clean: - -del *.exe - -del *.exe.manifest - -del *.obj diff --git a/tiff/tools/fax2ps.c b/tiff/tools/fax2ps.c index f59f4921..625574c6 100644 --- a/tiff/tools/fax2ps.c +++ b/tiff/tools/fax2ps.c @@ -22,6 +22,7 @@ * OF THIS SOFTWARE. */ #include "tif_config.h" +#include "libport.h" #include <stdlib.h> #include <stdio.h> @@ -41,10 +42,6 @@ # include <io.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffiop.h" #include "tiffio.h" @@ -75,7 +72,7 @@ int maxline = 512; /* max output line of PostScript */ * March 13-15, 1995. */ static void -printruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx) +printruns(unsigned char* buf, uint32_t* runs, uint32_t* erun, uint32_t lastx) { static struct { char white, black; @@ -89,9 +86,9 @@ printruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx) static char* svalue = " !\"#$&'*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abc"; int colormode = 1; /* 0 for white, 1 for black */ - uint32 runlength = 0; + uint32_t runlength = 0; int n = maxline; - uint32 x = 0; + uint32_t x = 0; int l; (void) buf; @@ -129,7 +126,7 @@ printruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx) l++; } while (runlength > 0 && runlength <= 6) { - uint32 bitsleft = 6; + uint32_t bitsleft = 6; int t = 0; while (bitsleft) { if (runlength <= bitsleft) { @@ -201,10 +198,10 @@ emitFont(FILE* fd) } void -printTIF(TIFF* tif, uint16 pageNumber) +printTIF(TIFF* tif, uint16_t pageNumber) { - uint32 w, h; - uint16 unit, compression; + uint32_t w, h; + uint16_t unit, compression; float xres, yres, scale = 1.0; tstrip_t s, ns; time_t creation_time; @@ -278,10 +275,10 @@ printTIF(TIFF* tif, uint16 pageNumber) TIFFGetField(tif, TIFFTAG_PAGENUMBER, &pn, &ptotal) int -findPage(TIFF* tif, uint16 pageNumber) +findPage(TIFF* tif, uint16_t pageNumber) { - uint16 pn = (uint16) -1; - uint16 ptotal = (uint16) -1; + uint16_t pn = (uint16_t) -1; + uint16_t ptotal = (uint16_t) -1; if (GetPageNumber(tif)) { while (pn != (pageNumber-1) && TIFFReadDirectory(tif) && GetPageNumber(tif)) ; @@ -291,10 +288,10 @@ findPage(TIFF* tif, uint16 pageNumber) } void -fax2ps(TIFF* tif, uint16 npages, uint16* pages, char* filename) +fax2ps(TIFF* tif, uint16_t npages, uint16_t* pages, char* filename) { if (npages > 0) { - uint16 pn, ptotal; + uint16_t pn, ptotal; int i; if (!GetPageNumber(tif)) @@ -307,7 +304,7 @@ fax2ps(TIFF* tif, uint16 npages, uint16* pages, char* filename) fprintf(stderr, "%s: No page number %d\n", filename, pages[i]); } } else { - uint16 pageNumber = 0; + uint16_t pageNumber = 0; do printTIF(tif, pageNumber++); while (TIFFReadDirectory(tif)); @@ -333,7 +330,7 @@ main(int argc, char** argv) extern int optind; extern char* optarg; #endif - uint16 *pages = NULL, npages = 0, pageNumber; + uint16_t *pages = NULL, npages = 0, pageNumber; int c, dowarnings = 0; /* if 1, enable library warnings */ TIFF* tif; @@ -349,11 +346,11 @@ main(int argc, char** argv) pageWidth = (float)atof(optarg); break; case 'p': /* print specific page */ - pageNumber = (uint16)atoi(optarg); + pageNumber = (uint16_t)atoi(optarg); if (pages) - pages = (uint16*) realloc(pages, (npages+1)*sizeof(uint16)); + pages = (uint16_t*) realloc(pages, (npages + 1) * sizeof(uint16_t)); else - pages = (uint16*) malloc(sizeof(uint16)); + pages = (uint16_t*) malloc(sizeof(uint16_t)); if( pages == NULL ) { fprintf(stderr, "Out of memory\n"); @@ -375,11 +372,12 @@ main(int argc, char** argv) break; case 'h': usage(EXIT_SUCCESS); + break; case '?': usage(EXIT_FAILURE); } if (npages > 0) - qsort(pages, npages, sizeof(uint16), pcompar); + qsort(pages, npages, sizeof(uint16_t), pcompar); if (!dowarnings) TIFFSetWarningHandler(0); if (optind < argc) { @@ -433,29 +431,27 @@ main(int argc, char** argv) return (EXIT_SUCCESS); } -const char* stuff[] = { -"usage: fax2ps [options] [input.tif ...]", -"where options are:", -" -w suppress warning messages", -" -l chars set maximum output line length for generated PostScript", -" -p page# select page to print (can use multiple times)", -" -x xres set default horizontal resolution of input data (dpi)", -" -y yres set default vertical resolution of input data (lpi)", -" -S scale output to page size", -" -W width set output page width (inches), default is 8.5", -" -H height set output page height (inches), default is 11", -NULL -}; +static const char usage_info[] = +"Convert a TIFF facsimile to compressed PostScript\n\n" +"usage: fax2ps [options] [input.tif ...]\n" +"where options are:\n" +" -w suppress warning messages\n" +" -l chars set maximum output line length for generated PostScript\n" +" -p page# select page to print (can use multiple times)\n" +" -x xres set default horizontal resolution of input data (dpi)\n" +" -y yres set default vertical resolution of input data (lpi)\n" +" -S scale output to page size\n" +" -W width set output page width (inches), default is 8.5\n" +" -H height set output page height (inches), default is 11\n" +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } diff --git a/tiff/tools/fax2tiff.c b/tiff/tools/fax2tiff.c index eecb41e3..59ed02c0 100644 --- a/tiff/tools/fax2tiff.c +++ b/tiff/tools/fax2tiff.c @@ -26,6 +26,7 @@ * Convert a CCITT Group 3 or 4 FAX file to TIFF Group 3 or 4 format. */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> /* should have atof & getopt */ @@ -42,10 +43,6 @@ # include <io.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffiop.h" #ifndef EXIT_SUCCESS @@ -55,17 +52,17 @@ # define EXIT_FAILURE 1 #endif -#define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3) +#define TIFFhowmany8(x) (((x)&0x07)?((uint32_t)(x)>>3)+1:(uint32_t)(x)>>3) TIFF *faxTIFF; char *rowbuf; char *refbuf; -uint32 xsize = 1728; +uint32_t xsize = 1728; int verbose; int stretch; -uint16 badfaxrun; -uint32 badfaxlines; +uint16_t badfaxrun; +uint32_t badfaxlines; int copyFaxFile(TIFF* tifin, TIFF* tifout); static void usage(int code); @@ -91,12 +88,12 @@ main(int argc, char* argv[]) int compression_out = COMPRESSION_CCITTFAX3; int fillorder_in = FILLORDER_LSB2MSB; int fillorder_out = FILLORDER_LSB2MSB; - uint32 group3options_in = 0; /* 1d-encoded */ - uint32 group3options_out = 0; /* 1d-encoded */ - uint32 group4options_in = 0; /* compressed */ - uint32 group4options_out = 0; /* compressed */ - uint32 defrowsperstrip = (uint32) 0; - uint32 rowsperstrip; + uint32_t group3options_in = 0; /* 1d-encoded */ + uint32_t group3options_out = 0; /* 1d-encoded */ + uint32_t group4options_in = 0; /* compressed */ + uint32_t group4options_out = 0; /* compressed */ + uint32_t defrowsperstrip = (uint32_t) 0; + uint32_t rowsperstrip; int photometric_in = PHOTOMETRIC_MINISWHITE; int photometric_out = PHOTOMETRIC_MINISWHITE; int mode = FAXMODE_CLASSF; @@ -151,7 +148,7 @@ main(int argc, char* argv[]) resY = (float) atof(optarg); break; case 'X': /* input width */ - xsize = (uint32) atoi(optarg); + xsize = (uint32_t) atoi(optarg); break; /* output-related options */ @@ -218,6 +215,7 @@ main(int argc, char* argv[]) break; case 'h': usage(EXIT_SUCCESS); + break; case '?': usage(EXIT_FAILURE); /*NOTREACHED*/ @@ -297,7 +295,7 @@ main(int argc, char* argv[]) group3options_out); TIFFSetField(out, TIFFTAG_FAXMODE, mode); rowsperstrip = - (defrowsperstrip)?defrowsperstrip:(uint32)-1L; + (defrowsperstrip)?defrowsperstrip:(uint32_t)-1L; break; /* g4 */ @@ -306,7 +304,7 @@ main(int argc, char* argv[]) group4options_out); TIFFSetField(out, TIFFTAG_FAXMODE, mode); rowsperstrip = - (defrowsperstrip)?defrowsperstrip:(uint32)-1L; + (defrowsperstrip)?defrowsperstrip:(uint32_t)-1L; break; default: @@ -338,9 +336,9 @@ main(int argc, char* argv[]) if (verbose) { fprintf(stderr, "%s:\n", argv[optind]); fprintf(stderr, "%d rows in input\n", rows); - fprintf(stderr, "%ld total bad rows\n", - (long) badfaxlines); - fprintf(stderr, "%d max consecutive bad rows\n", badfaxrun); + fprintf(stderr, "%"PRIu32" total bad rows\n", + badfaxlines); + fprintf(stderr, "%"PRIu16" max consecutive bad rows\n", badfaxrun); } if (compression_out == COMPRESSION_CCITTFAX3 && mode == FAXMODE_CLASSF) { @@ -360,9 +358,9 @@ main(int argc, char* argv[]) int copyFaxFile(TIFF* tifin, TIFF* tifout) { - uint32 row; - uint32 linesize = TIFFhowmany8(xsize); - uint16 badrun; + uint32_t row; + uint32_t linesize = TIFFhowmany8(xsize); + uint16_t badrun; int ok; tifin->tif_rawdatasize = (tmsize_t)TIFFGetFileSize(tifin); @@ -408,15 +406,15 @@ copyFaxFile(TIFF* tifin, TIFF* tifout) tifin->tif_row++; if (TIFFWriteScanline(tifout, rowbuf, row, 0) < 0) { - fprintf(stderr, "%s: Write error at row %ld.\n", - tifout->tif_name, (long) row); + fprintf(stderr, "%s: Write error at row %"PRIu32".\n", + tifout->tif_name, row); break; } row++; if (stretch) { if (TIFFWriteScanline(tifout, rowbuf, row, 0) < 0) { - fprintf(stderr, "%s: Write error at row %ld.\n", - tifout->tif_name, (long) row); + fprintf(stderr, "%s: Write error at row %"PRIu32".\n", + tifout->tif_name, row); break; } row++; @@ -428,51 +426,53 @@ copyFaxFile(TIFF* tifin, TIFF* tifout) return (row); } -const char* stuff[] = { -"usage: fax2tiff [options] input.raw...", -"where options are:", -" -3 input data is G3-encoded [default]", -" -4 input data is G4-encoded", -" -U input data is uncompressed (G3 or G4)", -" -1 input data is 1D-encoded (G3 only) [default]", -" -2 input data is 2D-encoded (G3 only)", -" -P input is not EOL-aligned (G3 only) [default]", -" -A input is EOL-aligned (G3 only)", -" -M input data has MSB2LSB bit order", -" -L input data has LSB2MSB bit order [default]", -" -B input data has min 0 means black", -" -W input data has min 0 means white [default]", -" -R # input data has # resolution (lines/inch) [default is 196]", -" -X # input data has # width [default is 1728]", -"", -" -o out.tif write output to out.tif", -" -7 generate G3-encoded output [default]", -" -8 generate G4-encoded output", -" -u generate uncompressed output (G3 or G4)", -" -5 generate 1D-encoded output (G3 only)", -" -6 generate 2D-encoded output (G3 only) [default]", -" -p generate not EOL-aligned output (G3 only)", -" -a generate EOL-aligned output (G3 only) [default]", -" -c generate \"classic\" TIFF format", -" -f generate TIFF Class F (TIFF/F) format [default]", -" -m output fill order is MSB2LSB", -" -l output fill order is LSB2MSB [default]", -" -r # make each strip have no more than # rows", -" -s stretch image by duplicating scanlines", -" -v print information about conversion work", -" -z generate LZW compressed output", -NULL -}; +static const char usage_info[] = +"Create a TIFF Class F fax file from raw fax data\n\n" +"usage: fax2tiff [options] input.raw...\n" +"where options are:\n" +" -3 input data is G3-encoded [default]\n" +" -4 input data is G4-encoded\n" +" -U input data is uncompressed (G3 or G4)\n" +" -1 input data is 1D-encoded (G3 only) [default]\n" +" -2 input data is 2D-encoded (G3 only)\n" +" -P input is not EOL-aligned (G3 only) [default]\n" +" -A input is EOL-aligned (G3 only)\n" +" -M input data has MSB2LSB bit order\n" +" -L input data has LSB2MSB bit order [default]\n" +" -B input data has min 0 means black\n" +" -W input data has min 0 means white [default]\n" +" -R # input data has # resolution (lines/inch) [default is 196]\n" +" -X # input data has # width [default is 1728]\n" +"\n" +" -o out.tif write output to out.tif\n" +#ifdef CCITT_SUPPORT +" -7 generate G3-encoded output [default]\n" +" -8 generate G4-encoded output\n" +" -u generate uncompressed output (G3 or G4)\n" +" -5 generate 1D-encoded output (G3 only)\n" +" -6 generate 2D-encoded output (G3 only) [default]\n" +" -p generate not EOL-aligned output (G3 only)\n" +" -a generate EOL-aligned output (G3 only) [default]\n" +#endif +" -c generate \"classic\" TIFF format\n" +" -f generate TIFF Class F (TIFF/F) format [default]\n" +" -m output fill order is MSB2LSB\n" +" -l output fill order is LSB2MSB [default]\n" +" -r # make each strip have no more than # rows\n" +" -s stretch image by duplicating scanlines\n" +" -v print information about conversion work\n" +#ifdef LZW_SUPPORT +" -z generate LZW compressed output\n" +#endif +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } diff --git a/tiff/tools/pal2rgb.c b/tiff/tools/pal2rgb.c index bf95cb37..287b31f8 100644 --- a/tiff/tools/pal2rgb.c +++ b/tiff/tools/pal2rgb.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <string.h> @@ -33,10 +34,6 @@ # include <unistd.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffio.h" #ifndef EXIT_SUCCESS @@ -53,7 +50,7 @@ static void usage(int code); static void cpTags(TIFF* in, TIFF* out); static int -checkcmap(int n, uint16* r, uint16* g, uint16* b) +checkcmap(int n, uint16_t* r, uint16_t* g, uint16_t* b) { while (n-- > 0) if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256) @@ -67,8 +64,8 @@ checkcmap(int n, uint16* r, uint16* g, uint16* b) #define CopyField3(tag, v1, v2, v3) \ if (TIFFGetField(in, tag, &v1, &v2, &v3)) TIFFSetField(out, tag, v1, v2, v3) -static uint16 compression = (uint16) -1; -static uint16 predictor = 0; +static uint16_t compression = (uint16_t) -1; +static uint16_t predictor = 0; static int quality = 75; /* JPEG quality */ static int jpegcolormode = JPEGCOLORMODE_RGB; static int processCompressOptions(char*); @@ -76,13 +73,13 @@ static int processCompressOptions(char*); int main(int argc, char* argv[]) { - uint16 bitspersample, shortv; - uint32 imagewidth, imagelength; - uint16 config = PLANARCONFIG_CONTIG; - uint32 rowsperstrip = (uint32) -1; - uint16 photometric = PHOTOMETRIC_RGB; - uint16 *rmap, *gmap, *bmap; - uint32 row; + uint16_t bitspersample, shortv; + uint32_t imagewidth, imagelength; + uint16_t config = PLANARCONFIG_CONTIG; + uint32_t rowsperstrip = (uint32_t) -1; + uint16_t photometric = PHOTOMETRIC_RGB; + uint16_t *rmap, *gmap, *bmap; + uint32_t row; int cmap = -1; TIFF *in, *out; int c; @@ -114,6 +111,7 @@ main(int argc, char* argv[]) break; case 'h': usage(EXIT_SUCCESS); + break; case '?': usage(EXIT_FAILURE); /*NOTREACHED*/ @@ -153,7 +151,7 @@ main(int argc, char* argv[]) cpTags(in, out); TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &imagewidth); TIFFGetField(in, TIFFTAG_IMAGELENGTH, &imagelength); - if (compression != (uint16)-1) + if (compression != (uint16_t)-1) TIFFSetField(out, TIFFTAG_COMPRESSION, compression); else TIFFGetField(in, TIFFTAG_COMPRESSION, &compression); @@ -195,7 +193,7 @@ main(int argc, char* argv[]) } { unsigned char *ibuf, *obuf; register unsigned char* pp; - register uint32 x; + register uint32_t x; tmsize_t tss_in = TIFFScanlineSize(in); tmsize_t tss_out = TIFFScanlineSize(out); if (tss_out / tss_in < 3) { @@ -301,27 +299,27 @@ processCompressOptions(char* opt) if (TIFFGetField(in, tag, &v1, &v2, &v3, &v4)) TIFFSetField(out, tag, v1, v2, v3, v4) static void -cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) +cpTag(TIFF* in, TIFF* out, uint16_t tag, uint16_t count, TIFFDataType type) { switch (type) { case TIFF_SHORT: if (count == 1) { - uint16 shortv; + uint16_t shortv; CopyField(tag, shortv); } else if (count == 2) { - uint16 shortv1, shortv2; + uint16_t shortv1, shortv2; CopyField2(tag, shortv1, shortv2); } else if (count == 4) { - uint16 *tr, *tg, *tb, *ta; + uint16_t *tr, *tg, *tb, *ta; CopyField4(tag, tr, tg, tb, ta); - } else if (count == (uint16) -1) { - uint16 shortv1; - uint16* shortav; + } else if (count == (uint16_t) -1) { + uint16_t shortv1; + uint16_t* shortav; CopyField2(tag, shortv1, shortav); } break; case TIFF_LONG: - { uint32 longv; + { uint32_t longv; CopyField(tag, longv); } break; @@ -329,7 +327,7 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) if (count == 1) { float floatv; CopyField(tag, floatv); - } else if (count == (uint16) -1) { + } else if (count == (uint16_t) -1) { float* floatav; CopyField(tag, floatav); } @@ -343,7 +341,7 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) if (count == 1) { double doublev; CopyField(tag, doublev); - } else if (count == (uint16) -1) { + } else if (count == (uint16_t) -1) { double* doubleav; CopyField(tag, doubleav); } @@ -360,9 +358,9 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) #undef CopyField2 #undef CopyField -static struct cpTag { - uint16 tag; - uint16 count; +static const struct cpTag { + uint16_t tag; + uint16_t count; TIFFDataType type; } tags[] = { { TIFFTAG_IMAGEWIDTH, 1, TIFF_LONG }, @@ -384,49 +382,49 @@ static struct cpTag { { TIFFTAG_XRESOLUTION, 1, TIFF_RATIONAL }, { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL }, { TIFFTAG_PAGENAME, 1, TIFF_ASCII }, - { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL }, - { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL }, - { TIFFTAG_GROUP4OPTIONS, 1, TIFF_LONG }, - { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT }, - { TIFFTAG_PAGENUMBER, 2, TIFF_SHORT }, - { TIFFTAG_SOFTWARE, 1, TIFF_ASCII }, - { TIFFTAG_DATETIME, 1, TIFF_ASCII }, - { TIFFTAG_ARTIST, 1, TIFF_ASCII }, - { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII }, - { TIFFTAG_WHITEPOINT, 2, TIFF_RATIONAL }, - { TIFFTAG_PRIMARYCHROMATICITIES, (uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT }, - { TIFFTAG_BADFAXLINES, 1, TIFF_LONG }, - { TIFFTAG_CLEANFAXDATA, 1, TIFF_SHORT }, - { TIFFTAG_CONSECUTIVEBADFAXLINES, 1, TIFF_LONG }, - { TIFFTAG_INKSET, 1, TIFF_SHORT }, + { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL }, + { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL }, + { TIFFTAG_GROUP4OPTIONS, 1, TIFF_LONG }, + { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT }, + { TIFFTAG_PAGENUMBER, 2, TIFF_SHORT }, + { TIFFTAG_SOFTWARE, 1, TIFF_ASCII }, + { TIFFTAG_DATETIME, 1, TIFF_ASCII }, + { TIFFTAG_ARTIST, 1, TIFF_ASCII }, + { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII }, + { TIFFTAG_WHITEPOINT, 2, TIFF_RATIONAL }, + { TIFFTAG_PRIMARYCHROMATICITIES, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT }, + { TIFFTAG_BADFAXLINES, 1, TIFF_LONG }, + { TIFFTAG_CLEANFAXDATA, 1, TIFF_SHORT }, + { TIFFTAG_CONSECUTIVEBADFAXLINES, 1, TIFF_LONG }, + { TIFFTAG_INKSET, 1, TIFF_SHORT }, /*{ TIFFTAG_INKNAMES, 1, TIFF_ASCII },*/ /* Needs much more complicated logic. See tiffcp */ - { TIFFTAG_DOTRANGE, 2, TIFF_SHORT }, - { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII }, - { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT }, - { TIFFTAG_YCBCRCOEFFICIENTS, (uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT }, - { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT }, - { TIFFTAG_REFERENCEBLACKWHITE, (uint16) -1,TIFF_RATIONAL }, + { TIFFTAG_DOTRANGE, 2, TIFF_SHORT }, + { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII }, + { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT }, + { TIFFTAG_YCBCRCOEFFICIENTS, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT }, + { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT }, + { TIFFTAG_REFERENCEBLACKWHITE, (uint16_t) -1, TIFF_RATIONAL }, }; #define NTAGS (sizeof (tags) / sizeof (tags[0])) static void cpTags(TIFF* in, TIFF* out) { - struct cpTag *p; + const struct cpTag *p; for (p = tags; p < &tags[NTAGS]; p++) { if( p->tag == TIFFTAG_GROUP3OPTIONS ) { - uint16 compression; + uint16_t compression; if( !TIFFGetField(in, TIFFTAG_COMPRESSION, &compression) || compression != COMPRESSION_CCITTFAX3 ) continue; } if( p->tag == TIFFTAG_GROUP4OPTIONS ) { - uint16 compression; + uint16_t compression; if( !TIFFGetField(in, TIFFTAG_COMPRESSION, &compression) || compression != COMPRESSION_CCITTFAX4 ) continue; @@ -436,35 +434,42 @@ cpTags(TIFF* in, TIFF* out) } #undef NTAGS -const char* stuff[] = { -"usage: pal2rgb [options] input.tif output.tif", -"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 8 assume 8-bit colormap values (instead of 16-bit)", -" -C 16 assume 16-bit colormap values", -"", -" -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 const char usage_info[] = +"Convert a palette color TIFF image to a full color image\n\n" +"usage: pal2rgb [options] input.tif output.tif\n" +"where options are:\n" +" -p contig pack samples contiguously (e.g. RGBRGB...)\n" +" -p separate store samples separately (e.g. RRR...GGG...BBB...)\n" +" -r # make each strip have no more than # rows\n" +" -C 8 assume 8-bit colormap values (instead of 16-bit)\n" +" -C 16 assume 16-bit colormap values\n" +"\n" +#ifdef LZW_SUPPORT +" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding\n" +/* " LZW options:\n" */ +" # set predictor value\n" +" For example, -c lzw:2 to get LZW-encoded data with horizontal differencing\n" +#endif +#ifdef ZIP_SUPPORT +" -c zip[:opts] compress output with deflate encoding\n" +/* " Deflate (ZIP) options:\n" */ +" # set predictor value\n" +#endif +#ifdef PACKBITS_SUPPORT +" -c packbits compress output with packbits encoding\n" +#endif +#if defined(LZW_SUPPORT) || defined(ZIP_SUPPORT) || defined(PACKBITS_SUPPORT) +" -c none use no compression algorithm on output\n" +#endif +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } diff --git a/tiff/tools/ppm2tiff.c b/tiff/tools/ppm2tiff.c index c6332439..d0eaee85 100644 --- a/tiff/tools/ppm2tiff.c +++ b/tiff/tools/ppm2tiff.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> @@ -41,16 +42,8 @@ # include <io.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffio.h" -#ifndef HAVE_GETOPT -extern int getopt(int argc, char * const argv[], const char *optstring); -#endif - #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif @@ -61,17 +54,17 @@ extern int getopt(int argc, char * const argv[], const char *optstring); #define streq(a,b) (strcmp(a,b) == 0) #define strneq(a,b,n) (strncmp(a,b,n) == 0) -static uint16 compression = COMPRESSION_PACKBITS; -static uint16 predictor = 0; +static uint16_t compression = COMPRESSION_PACKBITS; +static uint16_t predictor = 0; static int quality = 75; /* JPEG quality */ static int jpegcolormode = JPEGCOLORMODE_RGB; -static uint32 g3opts; +static uint32_t g3opts; static void usage(int code); static int processCompressOptions(char*); static void -pack_none (unsigned char *buf, unsigned int smpls, uint16 bps) +pack_none (unsigned char *buf, unsigned int smpls, uint16_t bps) { (void)buf; (void)smpls; @@ -80,7 +73,7 @@ pack_none (unsigned char *buf, unsigned int smpls, uint16 bps) } static void -pack_swab (unsigned char *buf, unsigned int smpls, uint16 bps) +pack_swab (unsigned char *buf, unsigned int smpls, uint16_t bps) { unsigned int s; unsigned char h; @@ -99,13 +92,13 @@ pack_swab (unsigned char *buf, unsigned int smpls, uint16 bps) } static void -pack_bytes (unsigned char *buf, unsigned int smpls, uint16 bps) +pack_bytes (unsigned char *buf, unsigned int smpls, uint16_t bps) { unsigned int s; unsigned int in; unsigned int out; int bits; - uint16 t; + uint16_t t; in = 0; out = 0; @@ -115,7 +108,7 @@ pack_bytes (unsigned char *buf, unsigned int smpls, uint16 bps) for (s = 0; smpls > s; s++) { t <<= bps; - t |= (uint16) buf [in++]; + t |= (uint16_t) buf [in++]; bits += bps; @@ -129,13 +122,13 @@ pack_bytes (unsigned char *buf, unsigned int smpls, uint16 bps) } static void -pack_words (unsigned char *buf, unsigned int smpls, uint16 bps) +pack_words (unsigned char *buf, unsigned int smpls, uint16_t bps) { unsigned int s; unsigned int in; unsigned int out; int bits; - uint32 t; + uint32_t t; in = 0; out = 0; @@ -145,8 +138,8 @@ pack_words (unsigned char *buf, unsigned int smpls, uint16 bps) for (s = 0; smpls > s; s++) { t <<= bps; - t |= (uint32) buf [in++] << 8; - t |= (uint32) buf [in++] << 0; + t |= (uint32_t) buf [in++] << 8; + t |= (uint32_t) buf [in++] << 0; bits += bps; @@ -173,9 +166,6 @@ BadPPM(char* file) } -#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0)) -#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1) - static tmsize_t multiply_ms(tmsize_t m1, tmsize_t m2) { @@ -187,15 +177,15 @@ multiply_ms(tmsize_t m1, tmsize_t m2) int main(int argc, char* argv[]) { - uint16 photometric = 0; - uint32 rowsperstrip = (uint32) -1; + uint16_t photometric = 0; + uint32_t rowsperstrip = (uint32_t) -1; double resolution = -1; unsigned char *buf = NULL; tmsize_t linebytes = 0; int pbm; - uint16 spp = 1; - uint16 bpp = 8; - void (*pack_func) (unsigned char *buf, unsigned int smpls, uint16 bps); + uint16_t spp = 1; + uint16_t bpp = 8; + void (*pack_func) (unsigned char *buf, unsigned int smpls, uint16_t bps); TIFF *out; FILE *in; unsigned int w, h, prec, row; @@ -225,6 +215,7 @@ main(int argc, char* argv[]) break; case 'h': usage(EXIT_SUCCESS); + break; case '?': usage(EXIT_FAILURE); /*NOTREACHED*/ @@ -349,8 +340,8 @@ main(int argc, char* argv[]) out = TIFFOpen(argv[optind], "w"); if (out == NULL) return (EXIT_FAILURE); - TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32) w); - TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32) h); + TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32_t) w); + TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32_t) h); TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, spp); TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bpp); @@ -379,7 +370,7 @@ main(int argc, char* argv[]) } else { linebytes = multiply_ms(2 * spp, w); } - if (rowsperstrip == (uint32) -1) { + if (rowsperstrip == (uint32_t) -1) { TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, h); } else { TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, @@ -412,8 +403,8 @@ main(int argc, char* argv[]) } for (row = 0; row < h; row++) { if (fread(buf, linebytes, 1, in) != 1) { - fprintf(stderr, "%s: scanline %lu: Read error.\n", - infile, (unsigned long) row); + fprintf(stderr, "%s: scanline %u: Read error.\n", + infile, row); break; } pack_func (buf, w * spp, bpp); @@ -489,38 +480,49 @@ processCompressOptions(char* opt) return (1); } -const char* stuff[] = { -"usage: ppm2tiff [options] input.ppm output.tif", -"where options are:", -" -r # make each strip have no more than # rows", -" -R # set x&y resolution (dpi)", -"", -" -c jpeg[:opts] compress output with JPEG encoding", -" -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 (the default)", -" -c g3[:opts] compress output with CCITT Group 3 encoding", -" -c g4 compress output with CCITT Group 4 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 const char usage_info[] = +"Create a TIFF file from PPM, PGM and PBM image files\n\n" +"usage: ppm2tiff [options] input.ppm output.tif\n" +"where options are:\n" +" -r # make each strip have no more than # rows\n" +" -R # set x&y resolution (dpi)\n" +"\n" +#ifdef JPEG_SUPPORT +" -c jpeg[:opts] compress output with JPEG encoding\n" +/* "JPEG options:\n" */ +" # set compression quality level (0-100, default 75)\n" +" r output color image as RGB rather than YCbCr\n" +#endif +#ifdef LZW_SUPPORT +" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding\n" +/* " LZW options:\n" */ +" # set predictor value\n" +" For example, -c lzw:2 for LZW-encoded data with horizontal differencing\n" +#endif +#ifdef ZIP_SUPPORT +" -c zip[:opts] compress output with deflate encoding\n" +/* " Deflate (ZIP) options:\n" */ +" # set predictor value\n" +#endif +#ifdef PACKBITS_SUPPORT +" -c packbits compress output with packbits encoding (the default)\n" +#endif +#ifdef CCITT_SUPPORT +" -c g3[:opts] compress output with CCITT Group 3 encoding\n" +" -c g4 compress output with CCITT Group 4 encoding\n" +#endif +#if defined(JPEG_SUPPORT) || defined(LZW_SUPPORT) || defined(ZIP_SUPPORT) || defined(PACKBITS_SUPPORT) || defined(CCITT_SUPPORT) +" -c none use no compression algorithm on output\n" +#endif +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } diff --git a/tiff/tools/raw2tiff.c b/tiff/tools/raw2tiff.c index 8bbdc045..dfee715f 100644 --- a/tiff/tools/raw2tiff.c +++ b/tiff/tools/raw2tiff.c @@ -27,6 +27,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> @@ -52,10 +53,6 @@ # include <io.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffiop.h" #include "tiffio.h" @@ -66,10 +63,6 @@ #define EXIT_FAILURE 1 #endif -#ifndef HAVE_GETOPT -extern int getopt(int argc, char * const argv[], const char *optstring); -#endif - #ifndef O_BINARY # define O_BINARY 0 #endif @@ -79,37 +72,37 @@ typedef enum { BAND } InterleavingType; -static uint16 compression = (uint16) -1; +static uint16_t compression = (uint16_t) -1; static int jpegcolormode = JPEGCOLORMODE_RGB; static int quality = 75; /* JPEG quality */ -static uint16 predictor = 0; +static uint16_t predictor = 0; -static void swapBytesInScanline(void *, uint32, TIFFDataType); -static int guessSize(int, TIFFDataType, _TIFF_off_t, uint32, int, - uint32 *, uint32 *); -static double correlation(void *, void *, uint32, TIFFDataType); +static void swapBytesInScanline(void *, uint32_t, TIFFDataType); +static int guessSize(int, TIFFDataType, _TIFF_off_t, uint32_t, int, + uint32_t *, uint32_t *); +static double correlation(void *, void *, uint32_t, TIFFDataType); static void usage(int); static int processCompressOptions(char*); int main(int argc, char* argv[]) { - uint32 width = 0, length = 0, linebytes, bufsize; - uint32 nbands = 1; /* number of bands in input image*/ + uint32_t width = 0, length = 0, linebytes, bufsize; + uint32_t nbands = 1; /* number of bands in input image*/ _TIFF_off_t hdr_size = 0; /* size of the header to skip */ TIFFDataType dtype = TIFF_BYTE; - int16 depth = 1; /* bytes per pixel in input image */ + int16_t depth = 1; /* bytes per pixel in input image */ int swab = 0; /* byte swapping flag */ InterleavingType interleaving = 0; /* interleaving type flag */ - uint32 rowsperstrip = (uint32) -1; - uint16 photometric = PHOTOMETRIC_MINISBLACK; - uint16 config = PLANARCONFIG_CONTIG; - uint16 fillorder = FILLORDER_LSB2MSB; + uint32_t rowsperstrip = (uint32_t) -1; + uint16_t photometric = PHOTOMETRIC_MINISBLACK; + uint16_t config = PLANARCONFIG_CONTIG; + uint16_t fillorder = FILLORDER_LSB2MSB; int fd; char *outfilename = NULL; TIFF *out; - uint32 row, col, band; + uint32_t row, col, band; int c; unsigned char *buf = NULL, *buf1 = NULL; #if !HAVE_DECL_OPTARG @@ -254,7 +247,7 @@ main(int argc, char* argv[]) TIFFSetField(out, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_VOID); break; } - if (compression == (uint16) -1) + if (compression == (uint16_t) -1) compression = COMPRESSION_PACKBITS; TIFFSetField(out, TIFFTAG_COMPRESSION, compression); switch (compression) { @@ -299,16 +292,14 @@ main(int argc, char* argv[]) hdr_size + (length*band+row)*linebytes, SEEK_SET) == (_TIFF_off_t)-1) { fprintf(stderr, - "%s: %s: scanline %lu: seek error.\n", - argv[0], argv[optind], - (unsigned long) row); + "%s: %s: scanline %"PRIu32": seek error.\n", + argv[0], argv[optind], row); break; } if (read(fd, buf, linebytes) < 0) { fprintf(stderr, - "%s: %s: scanline %lu: Read error.\n", - argv[0], argv[optind], - (unsigned long) row); + "%s: %s: scanline %"PRIu32": Read error.\n", + argv[0], argv[optind], row); break; } if (swab) /* Swap bytes if needed */ @@ -322,9 +313,8 @@ main(int argc, char* argv[]) default: if (read(fd, buf1, bufsize) < 0) { fprintf(stderr, - "%s: %s: scanline %lu: Read error.\n", - argv[0], argv[optind], - (unsigned long) row); + "%s: %s: scanline %"PRIu32": Read error.\n", + argv[0], argv[optind], row); break; } if (swab) /* Swap bytes if needed */ @@ -333,8 +323,8 @@ main(int argc, char* argv[]) } if (TIFFWriteScanline(out, buf1, row, 0) < 0) { - fprintf(stderr, "%s: %s: scanline %lu: Write error.\n", - argv[0], outfilename, (unsigned long) row); + fprintf(stderr, "%s: %s: scanline %"PRIu32": Write error.\n", + argv[0], outfilename, row); break; } } @@ -347,17 +337,17 @@ main(int argc, char* argv[]) } static void -swapBytesInScanline(void *buf, uint32 width, TIFFDataType dtype) +swapBytesInScanline(void *buf, uint32_t width, TIFFDataType dtype) { switch (dtype) { case TIFF_SHORT: case TIFF_SSHORT: - TIFFSwabArrayOfShort((uint16*)buf, + TIFFSwabArrayOfShort((uint16_t*)buf, (unsigned long)width); break; case TIFF_LONG: case TIFF_SLONG: - TIFFSwabArrayOfLong((uint32*)buf, + TIFFSwabArrayOfLong((uint32_t*)buf, (unsigned long)width); break; /* case TIFF_FLOAT: */ /* FIXME */ @@ -371,14 +361,14 @@ swapBytesInScanline(void *buf, uint32 width, TIFFDataType dtype) } static int -guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands, - int swab, uint32 *width, uint32 *length) +guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32_t nbands, + int swab, uint32_t *width, uint32_t *length) { const float longt = 40.0; /* maximum possible height/width ratio */ char *buf1, *buf2; _TIFF_stat_s filestat; - uint32 w, h, scanlinesize, imagesize; - uint32 depth = TIFFDataWidth(dtype); + uint32_t w, h, scanlinesize, imagesize; + uint32_t depth = TIFFDataWidth(dtype); double cor_coef = 0, tmp; if (_TIFF_fstat_f(fd, &filestat) == -1) { @@ -398,8 +388,8 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands, *length = imagesize / *width; - fprintf(stderr, "Height is guessed as %lu.\n", - (unsigned long)*length); + fprintf(stderr, "Height is guessed as %"PRIu32".\n", + *length); return 1; } else if (*width == 0 && *length != 0) { @@ -407,14 +397,14 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands, *width = imagesize / *length; - fprintf(stderr, "Width is guessed as %lu.\n", - (unsigned long)*width); + fprintf(stderr, "Width is guessed as %"PRIu32".\n", + *width); return 1; } else if (*width == 0 && *length == 0) { unsigned int fail = 0; fprintf(stderr, "Image width and height are not specified.\n"); - w = (uint32) sqrt(imagesize / longt); + w = (uint32_t) sqrt(imagesize / longt); if( w == 0 ) { fprintf(stderr, "Too small image size.\n"); @@ -480,8 +470,8 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands, } fprintf(stderr, - "Width is guessed as %lu, height is guessed as %lu.\n", - (unsigned long)*width, (unsigned long)*length); + "Width is guessed as %"PRIu32", height is guessed as %"PRIu32".\n", + *width, *length); return 1; } else { @@ -496,10 +486,10 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands, /* Calculate correlation coefficient between two numeric vectors */ static double -correlation(void *buf1, void *buf2, uint32 n_elem, TIFFDataType dtype) +correlation(void *buf1, void *buf2, uint32_t n_elem, TIFFDataType dtype) { double X, Y, M1 = 0.0, M2 = 0.0, D1 = 0.0, D2 = 0.0, K = 0.0; - uint32 i; + uint32_t i; switch (dtype) { case TIFF_BYTE: @@ -523,8 +513,8 @@ correlation(void *buf1, void *buf2, uint32 n_elem, TIFFDataType dtype) break; case TIFF_SHORT: for (i = 0; i < n_elem; i++) { - X = ((uint16 *)buf1)[i]; - Y = ((uint16 *)buf2)[i]; + X = ((uint16_t *)buf1)[i]; + Y = ((uint16_t *)buf2)[i]; M1 += X, M2 += Y; D1 += X * X, D2 += Y * Y; K += X * Y; @@ -532,8 +522,8 @@ correlation(void *buf1, void *buf2, uint32 n_elem, TIFFDataType dtype) break; case TIFF_SSHORT: for (i = 0; i < n_elem; i++) { - X = ((int16 *)buf1)[i]; - Y = ((int16 *)buf2)[i]; + X = ((int16_t *)buf1)[i]; + Y = ((int16_t *)buf2)[i]; M1 += X, M2 += Y; D1 += X * X, D2 += Y * Y; K += X * Y; @@ -541,8 +531,8 @@ correlation(void *buf1, void *buf2, uint32 n_elem, TIFFDataType dtype) break; case TIFF_LONG: for (i = 0; i < n_elem; i++) { - X = ((uint32 *)buf1)[i]; - Y = ((uint32 *)buf2)[i]; + X = ((uint32_t *)buf1)[i]; + Y = ((uint32_t *)buf2)[i]; M1 += X, M2 += Y; D1 += X * X, D2 += Y * Y; K += X * Y; @@ -550,8 +540,8 @@ correlation(void *buf1, void *buf2, uint32 n_elem, TIFFDataType dtype) break; case TIFF_SLONG: for (i = 0; i < n_elem; i++) { - X = ((int32 *)buf1)[i]; - Y = ((int32 *)buf2)[i]; + X = ((int32_t *)buf1)[i]; + Y = ((int32_t *)buf2)[i]; M1 += X, M2 += Y; D1 += X * X, D2 += Y * Y; K += X * Y; @@ -624,75 +614,83 @@ processCompressOptions(char* opt) return (1); } -static const char* stuff[] = { -"raw2tiff --- tool for converting raw byte sequences in TIFF images", -"usage: raw2tiff [options] input.raw output.tif", -"where options are:", -" -L input data has LSB2MSB bit order (default)", -" -M input data has MSB2LSB bit order", -" -r # make each strip have no more than # rows", -" -H # size of input image file header in bytes (0 by default)", -" -w # width of input image in pixels", -" -l # length of input image in lines", -" -b # number of bands in input image (1 by default)", -"", -" -d data_type type of samples in input image", -"where data_type may be:", -" byte 8-bit unsigned integer (default)", -" short 16-bit unsigned integer", -" long 32-bit unsigned integer", -" sbyte 8-bit signed integer", -" sshort 16-bit signed integer", -" slong 32-bit signed integer", -" float 32-bit IEEE floating point", -" double 64-bit IEEE floating point", -"", -" -p photo photometric interpretation (color space) of the input image", -"where photo may be:", -" miniswhite white color represented with 0 value", -" minisblack black color represented with 0 value (default)", -" rgb image has RGB color model", -" cmyk image has CMYK (separated) color model", -" ycbcr image has YCbCr color model", -" cielab image has CIE L*a*b color model", -" icclab image has ICC L*a*b color model", -" itulab image has ITU L*a*b color model", -"", -" -s swap bytes fetched from input file", -"", -" -i config type of samples interleaving in input image", -"where config may be:", -" pixel pixel interleaved data (default)", -" band band interleaved data", -"", -" -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", -" -o out.tif write output to out.tif", -" -h this help message", -NULL -}; +static const char usage_info[] = +"Create a TIFF file from raw data\n\n" +"usage: raw2tiff [options] input.raw output.tif\n" +"where options are:\n" +" -L input data has LSB2MSB bit order (default)\n" +" -M input data has MSB2LSB bit order\n" +" -r # make each strip have no more than # rows\n" +" -H # size of input image file header in bytes (0 by default)\n" +" -w # width of input image in pixels\n" +" -l # length of input image in lines\n" +" -b # number of bands in input image (1 by default)\n" +"\n" +" -d data_type type of samples in input image\n" +"where data_type may be:\n" +" byte 8-bit unsigned integer (default)\n" +" short 16-bit unsigned integer\n" +" long 32-bit unsigned integer\n" +" sbyte 8-bit signed integer\n" +" sshort 16-bit signed integer\n" +" slong 32-bit signed integer\n" +" float 32-bit IEEE floating point\n" +" double 64-bit IEEE floating point\n" +"\n" +" -p photo photometric interpretation (color space) of the input image\n" +"where photo may be:\n" +" miniswhite white color represented with 0 value\n" +" minisblack black color represented with 0 value (default)\n" +" rgb image has RGB color model\n" +" cmyk image has CMYK (separated) color model\n" +" ycbcr image has YCbCr color model\n" +" cielab image has CIE L*a*b color model\n" +" icclab image has ICC L*a*b color model\n" +" itulab image has ITU L*a*b color model\n" +"\n" +" -s swap bytes fetched from input file\n" +"\n" +" -i config type of samples interleaving in input image\n" +"where config may be:\n" +" pixel pixel interleaved data (default)\n" +" band band interleaved data\n" +"\n" +#ifdef LZW_SUPPORT +" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding\n" +/* " LZW options:\n" */ +" # set predictor value\n" +" For example, -c lzw:2 for LZW-encoded data with horizontal differencing\n" +#endif +#ifdef ZIP_SUPPORT +" -c zip[:opts] compress output with deflate encoding\n" +/* " Deflate (ZIP) options:\n" */ +" # set predictor value\n" +#endif +#ifdef JPEG_SUPPORT +" -c jpeg[:opts] compress output with JPEG encoding\n" +/* " JPEG options:\n" */ +" # set compression quality level (0-100, default 75)\n" +" r output color image as RGB rather than YCbCr\n" +" For example, -c jpeg:r:50 for JPEG-encoded RGB data with 50% comp. quality\n" +#endif +#ifdef PACKBITS_SUPPORT +" -c packbits compress output with packbits encoding\n" +#endif +#if defined(LZW_SUPPORT) || defined(ZIP_SUPPORT) || defined(JPEG_SUPPORT) || defined(PACKBITS_SUPPORT) +" -c none use no compression algorithm on output\n" +#endif +"\n" +" -o out.tif write output to out.tif\n" +" -h this help message\n" +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } diff --git a/tiff/tools/rgb2ycbcr.c b/tiff/tools/rgb2ycbcr.c index 482cc5b4..d2a93c2d 100644 --- a/tiff/tools/rgb2ycbcr.c +++ b/tiff/tools/rgb2ycbcr.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <string.h> @@ -32,10 +33,6 @@ # include <unistd.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffiop.h" #include "tiffio.h" @@ -53,17 +50,17 @@ #ifndef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) #endif -#define roundup(x, y) (howmany(x,y)*((uint32)(y))) +#define roundup(x, y) (howmany(x,y)*((uint32_t)(y))) #define LumaRed ycbcrCoeffs[0] #define LumaGreen ycbcrCoeffs[1] #define LumaBlue ycbcrCoeffs[2] -uint16 compression = COMPRESSION_PACKBITS; -uint32 rowsperstrip = (uint32) -1; +uint16_t compression = COMPRESSION_PACKBITS; +uint32_t rowsperstrip = (uint32_t) -1; -uint16 horizSubSampling = 2; /* YCbCr horizontal subsampling */ -uint16 vertSubSampling = 2; /* YCbCr vertical subsampling */ +uint16_t horizSubSampling = 2; /* YCbCr horizontal subsampling */ +uint16_t vertSubSampling = 2; /* YCbCr vertical subsampling */ float ycbcrCoeffs[3] = { .299F, .587F, .114F }; /* default coding range is CCIR Rec 601-1 with no headroom/footroom */ float refBlackWhite[6] = { 0.F, 255.F, 128.F, 255.F, 128.F, 255.F }; @@ -182,17 +179,17 @@ setupLumaTables(void) } static void -cvtClump(unsigned char* op, uint32* raster, uint32 ch, uint32 cw, uint32 w) +cvtClump(unsigned char* op, uint32_t* raster, uint32_t ch, uint32_t cw, uint32_t w) { float Y, Cb = 0, Cr = 0; - uint32 j, k; + uint32_t j, k; /* * Convert ch-by-cw block of RGB * to YCbCr and sample accordingly. */ for (k = 0; k < ch; k++) { for (j = 0; j < cw; j++) { - uint32 RGB = (raster - k*w)[j]; + uint32_t RGB = (raster - k * w)[j]; Y = lumaRed[TIFFGetR(RGB)] + lumaGreen[TIFFGetG(RGB)] + lumaBlue[TIFFGetB(RGB)]; @@ -224,11 +221,11 @@ cvtClump(unsigned char* op, uint32* raster, uint32 ch, uint32 cw, uint32 w) * sample to generate the output data. */ static void -cvtStrip(unsigned char* op, uint32* raster, uint32 nrows, uint32 width) +cvtStrip(unsigned char* op, uint32_t* raster, uint32_t nrows, uint32_t width) { - uint32 x; + uint32_t x; int clumpSize = vertSubSampling * horizSubSampling + 2; - uint32 *tp; + uint32_t *tp; for (; nrows >= vertSubSampling; nrows -= vertSubSampling) { tp = raster; @@ -257,23 +254,23 @@ cvtStrip(unsigned char* op, uint32* raster, uint32 nrows, uint32 width) } static int -cvtRaster(TIFF* tif, uint32* raster, uint32 width, uint32 height) +cvtRaster(TIFF* tif, uint32_t* raster, uint32_t width, uint32_t height) { - uint32 y; + uint32_t y; tstrip_t strip = 0; tsize_t cc, acc; unsigned char* buf; - uint32 rwidth = roundup(width, horizSubSampling); - uint32 rheight = roundup(height, vertSubSampling); - uint32 nrows = (rowsperstrip > rheight ? rheight : rowsperstrip); - uint32 rnrows = roundup(nrows,vertSubSampling); + uint32_t rwidth = roundup(width, horizSubSampling); + uint32_t rheight = roundup(height, vertSubSampling); + uint32_t nrows = (rowsperstrip > rheight ? rheight : rowsperstrip); + uint32_t rnrows = roundup(nrows, vertSubSampling); cc = rnrows*rwidth + 2*((rnrows*rwidth) / (horizSubSampling*vertSubSampling)); buf = (unsigned char*)_TIFFmalloc(cc); // FIXME unchecked malloc - for (y = height; (int32) y > 0; y -= nrows) { - uint32 nr = (y > nrows ? nrows : y); + for (y = height; (int32_t) y > 0; y -= nrows) { + uint32_t nr = (y > nrows ? nrows : y); cvtStrip(buf, raster + (y-1)*width, nr, width); nr = roundup(nr, vertSubSampling); acc = nr*rwidth + @@ -290,12 +287,12 @@ cvtRaster(TIFF* tif, uint32* raster, uint32 width, uint32 height) static int tiffcvt(TIFF* in, TIFF* out) { - uint32 width, height; /* image width & height */ - uint32* raster; /* retrieve RGBA image */ - uint16 shortv; + uint32_t width, height; /* image width & height */ + uint32_t* raster; /* retrieve RGBA image */ + uint16_t shortv; float floatv; char *stringv; - uint32 longv; + uint32_t longv; int result; size_t pixel_count; @@ -307,18 +304,18 @@ tiffcvt(TIFF* in, TIFF* out) if (!width || !height || pixel_count / width != height) { TIFFError(TIFFFileName(in), "Malformed input file; " - "can't allocate buffer for raster of %lux%lu size", - (unsigned long)width, (unsigned long)height); + "can't allocate buffer for raster of %"PRIu32"x%"PRIu32" size", + width, height); return 0; } - raster = (uint32*)_TIFFCheckMalloc(in, pixel_count, sizeof(uint32), - "raster buffer"); + raster = (uint32_t*)_TIFFCheckMalloc(in, pixel_count, sizeof(uint32_t), + "raster buffer"); if (raster == 0) { TIFFError(TIFFFileName(in), - "Failed to allocate buffer (%lu elements of %lu each)", - (unsigned long)pixel_count, - (unsigned long)sizeof(uint32)); + "Failed to allocate buffer (%"TIFF_SIZE_FORMAT" elements of %"TIFF_SIZE_FORMAT" each)", + pixel_count, + sizeof(uint32_t)); return (0); } @@ -364,19 +361,34 @@ tiffcvt(TIFF* in, TIFF* out) return result; } -const char* stuff[] = { - "usage: rgb2ycbcr [-c comp] [-r rows] [-h N] [-v N] input... output\n", - "where comp is one of the following compression algorithms:\n", - " jpeg\t\tJPEG encoding\n", - " lzw\t\tLempel-Ziv & Welch encoding\n", - " zip\t\tdeflate encoding\n", - " packbits\tPackBits encoding (default)\n", - " none\t\tno compression\n", - "and the other options are:\n", - " -r\trows/strip\n", - " -h\thorizontal sampling factor (1,2,4)\n", - " -v\tvertical sampling factor (1,2,4)\n", - NULL +const char* usage_info[] = { +/* Help information format modified for the sake of consistency with the other tiff tools */ +/* "usage: rgb2ycbcr [-c comp] [-r rows] [-h N] [-v N] input... output\n", */ +/* "where comp is one of the following compression algorithms:\n", */ +"Convert RGB color, greyscale, or bi-level TIFF images to YCbCr images\n\n" +"usage: rgb2ycbcr [options] input output", +"where options are:", +#ifdef JPEG_SUPPORT +" -c jpeg JPEG encoding", +#endif +#ifdef ZIP_SUPPORT +" -c zip Zip/Deflate encoding", +#endif +#ifdef LZW_SUPPORT +" -c lzw Lempel-Ziv & Welch encoding", +#endif +#ifdef PACKBITS_SUPPORT +" -c packbits PackBits encoding (default)", +#endif +#if defined(JPEG_SUPPORT) || defined(LZW_SUPPORT) || defined(ZIP_SUPPORT) || defined(PACKBITS_SUPPORT) +" -c none no compression", +#endif +"", +/* "and the other options are:\n", */ +" -r rows/strip", +" -h horizontal sampling factor (1,2,4)", +" -v vertical sampling factor (1,2,4)", +NULL }; static void @@ -386,8 +398,8 @@ usage(int code) FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + for (i = 0; usage_info[i] != NULL; i++) + fprintf(out, "%s\n", usage_info[i]); exit(code); } diff --git a/tiff/tools/thumbnail.c b/tiff/tools/thumbnail.c index edb69983..274705d3 100644 --- a/tiff/tools/thumbnail.c +++ b/tiff/tools/thumbnail.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> @@ -33,10 +34,6 @@ # include <unistd.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffio.h" #ifndef EXIT_SUCCESS @@ -46,14 +43,10 @@ #define EXIT_FAILURE 1 #endif -#ifndef HAVE_GETOPT -extern int getopt(int argc, char * const argv[], const char *optstring); -#endif - #define streq(a,b) (strcmp(a,b) == 0) #ifndef TIFFhowmany8 -# define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3) +# define TIFFhowmany8(x) (((x)&0x07)?((uint32_t)(x)>>3)+1:(uint32_t)(x)>>3) #endif typedef enum { @@ -66,10 +59,10 @@ typedef enum { LINEAR } Contrast; -static uint32 tnw = 216; /* thumbnail width */ -static uint32 tnh = 274; /* thumbnail height */ +static uint32_t tnw = 216; /* thumbnail width */ +static uint32_t tnh = 274; /* thumbnail height */ static Contrast contrast = LINEAR; /* current contrast */ -static uint8* thumbnail; +static uint8_t* thumbnail; static int cpIFD(TIFF*, TIFF*); static int generateThumbnail(TIFF*, TIFF*); @@ -114,7 +107,7 @@ main(int argc, char* argv[]) if( in == NULL ) return 2; - thumbnail = (uint8*) _TIFFmalloc(tnw * tnh); + thumbnail = (uint8_t*) _TIFFmalloc(tnw * tnh); if (!thumbnail) { TIFFError(TIFFFileName(in), "Can't allocate space for thumbnail buffer."); @@ -148,37 +141,37 @@ bad: if (TIFFGetField(in, tag, &v1, &v2, &v3, &v4)) TIFFSetField(out, tag, v1, v2, v3, v4) static void -cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) +cpTag(TIFF* in, TIFF* out, uint16_t tag, uint16_t count, TIFFDataType type) { switch (type) { case TIFF_SHORT: if (count == 1) { - uint16 shortv; + uint16_t shortv; CopyField(tag, shortv); } else if (count == 2) { - uint16 shortv1, shortv2; + uint16_t shortv1, shortv2; CopyField2(tag, shortv1, shortv2); } else if (count == 4) { - uint16 *tr, *tg, *tb, *ta; + uint16_t *tr, *tg, *tb, *ta; CopyField4(tag, tr, tg, tb, ta); - } else if (count == (uint16) -1) { - uint16 shortv1; - uint16* shortav; + } else if (count == (uint16_t) -1) { + uint16_t shortv1; + uint16_t* shortav; CopyField2(tag, shortv1, shortav); } break; case TIFF_LONG: - { uint32 longv; + { uint32_t longv; CopyField(tag, longv); } break; case TIFF_LONG8: - { uint64 longv8; + { uint64_t longv8; CopyField(tag, longv8); } break; case TIFF_SLONG8: - { int64 longv8; + { int64_t longv8; CopyField(tag, longv8); } break; @@ -186,7 +179,7 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) if (count == 1) { float floatv; CopyField(tag, floatv); - } else if (count == (uint16) -1) { + } else if (count == (uint16_t) -1) { float* floatav; CopyField(tag, floatav); } @@ -200,7 +193,7 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) if (count == 1) { double doublev; CopyField(tag, doublev); - } else if (count == (uint16) -1) { + } else if (count == (uint16_t) -1) { double* doubleav; CopyField(tag, doubleav); } @@ -221,9 +214,9 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) #undef CopyField2 #undef CopyField -static struct cpTag { - uint16 tag; - uint16 count; +static const struct cpTag { + uint16_t tag; + uint16_t count; TIFFDataType type; } tags[] = { { TIFFTAG_IMAGEWIDTH, 1, TIFF_LONG }, @@ -248,38 +241,38 @@ static struct cpTag { { TIFFTAG_XRESOLUTION, 1, TIFF_RATIONAL }, { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL }, { TIFFTAG_PAGENAME, 1, TIFF_ASCII }, - { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL }, - { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL }, - { TIFFTAG_GROUP4OPTIONS, 1, TIFF_LONG }, - { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT }, - { TIFFTAG_PAGENUMBER, 2, TIFF_SHORT }, - { TIFFTAG_SOFTWARE, 1, TIFF_ASCII }, - { TIFFTAG_DATETIME, 1, TIFF_ASCII }, - { TIFFTAG_ARTIST, 1, TIFF_ASCII }, - { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII }, - { TIFFTAG_WHITEPOINT, 2, TIFF_RATIONAL }, - { TIFFTAG_PRIMARYCHROMATICITIES, (uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT }, - { TIFFTAG_BADFAXLINES, 1, TIFF_LONG }, - { TIFFTAG_CLEANFAXDATA, 1, TIFF_SHORT }, - { TIFFTAG_CONSECUTIVEBADFAXLINES, 1, TIFF_LONG }, - { TIFFTAG_INKSET, 1, TIFF_SHORT }, + { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL }, + { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL }, + { TIFFTAG_GROUP4OPTIONS, 1, TIFF_LONG }, + { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT }, + { TIFFTAG_PAGENUMBER, 2, TIFF_SHORT }, + { TIFFTAG_SOFTWARE, 1, TIFF_ASCII }, + { TIFFTAG_DATETIME, 1, TIFF_ASCII }, + { TIFFTAG_ARTIST, 1, TIFF_ASCII }, + { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII }, + { TIFFTAG_WHITEPOINT, 2, TIFF_RATIONAL }, + { TIFFTAG_PRIMARYCHROMATICITIES, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT }, + { TIFFTAG_BADFAXLINES, 1, TIFF_LONG }, + { TIFFTAG_CLEANFAXDATA, 1, TIFF_SHORT }, + { TIFFTAG_CONSECUTIVEBADFAXLINES, 1, TIFF_LONG }, + { TIFFTAG_INKSET, 1, TIFF_SHORT }, /*{ TIFFTAG_INKNAMES, 1, TIFF_ASCII },*/ /* Needs much more complicated logic. See tiffcp */ - { TIFFTAG_DOTRANGE, 2, TIFF_SHORT }, - { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII }, - { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT }, - { TIFFTAG_YCBCRCOEFFICIENTS, (uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT }, - { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT }, - { TIFFTAG_REFERENCEBLACKWHITE, (uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_EXTRASAMPLES, (uint16) -1, TIFF_SHORT }, + { TIFFTAG_DOTRANGE, 2, TIFF_SHORT }, + { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII }, + { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT }, + { TIFFTAG_YCBCRCOEFFICIENTS, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT }, + { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT }, + { TIFFTAG_REFERENCEBLACKWHITE, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_EXTRASAMPLES, (uint16_t) -1, TIFF_SHORT }, }; #define NTAGS (sizeof (tags) / sizeof (tags[0])) static void cpTags(TIFF* in, TIFF* out) { - struct cpTag *p; + const struct cpTag *p; for (p = tags; p < &tags[NTAGS]; p++) { /* Horrible: but TIFFGetField() expects 2 arguments to be passed */ @@ -287,14 +280,14 @@ cpTags(TIFF* in, TIFF* out) /* isn't used */ if( p->tag == TIFFTAG_GROUP3OPTIONS ) { - uint16 compression; + uint16_t compression; if( !TIFFGetField(in, TIFFTAG_COMPRESSION, &compression) || compression != COMPRESSION_CCITTFAX3 ) continue; } if( p->tag == TIFFTAG_GROUP4OPTIONS ) { - uint16 compression; + uint16_t compression; if( !TIFFGetField(in, TIFFTAG_COMPRESSION, &compression) || compression != COMPRESSION_CCITTFAX4 ) continue; @@ -312,11 +305,11 @@ cpStrips(TIFF* in, TIFF* out) if (buf) { tstrip_t s, ns = TIFFNumberOfStrips(in); - uint64 *bytecounts; + uint64_t *bytecounts; TIFFGetField(in, TIFFTAG_STRIPBYTECOUNTS, &bytecounts); for (s = 0; s < ns; s++) { - if (bytecounts[s] > (uint64) bufsize) { + if (bytecounts[s] > (uint64_t) bufsize) { buf = (unsigned char *)_TIFFrealloc(buf, (tmsize_t)bytecounts[s]); if (!buf) goto bad; @@ -346,11 +339,11 @@ cpTiles(TIFF* in, TIFF* out) if (buf) { ttile_t t, nt = TIFFNumberOfTiles(in); - uint64 *bytecounts; + uint64_t *bytecounts; TIFFGetField(in, TIFFTAG_TILEBYTECOUNTS, &bytecounts); for (t = 0; t < nt; t++) { - if (bytecounts[t] > (uint64) bufsize) { + if (bytecounts[t] > (uint64_t) bufsize) { buf = (unsigned char *)_TIFFrealloc(buf, (tmsize_t)bytecounts[t]); if (!buf) goto bad; @@ -386,16 +379,16 @@ cpIFD(TIFF* in, TIFF* out) return (1); } -static uint16 photometric; /* current photometric of raster */ -static uint16 filterWidth; /* filter width in pixels */ -static uint32 stepSrcWidth; /* src image stepping width */ -static uint32 stepDstWidth; /* dest stepping width */ -static uint8* src0; /* horizontal bit stepping (start) */ -static uint8* src1; /* horizontal bit stepping (middle) */ -static uint8* src2; /* horizontal bit stepping (end) */ -static uint32* rowoff; /* row offset for stepping */ -static uint8 cmap[256]; /* colormap indexes */ -static uint8 bits[256]; /* count of bits set */ +static uint16_t photometric; /* current photometric of raster */ +static uint16_t filterWidth; /* filter width in pixels */ +static uint32_t stepSrcWidth; /* src image stepping width */ +static uint32_t stepDstWidth; /* dest stepping width */ +static uint8_t* src0; /* horizontal bit stepping (start) */ +static uint8_t* src1; /* horizontal bit stepping (middle) */ +static uint8_t* src2; /* horizontal bit stepping (end) */ +static uint32_t* rowoff; /* row offset for stepping */ +static uint8_t cmap[256]; /* colormap indexes */ +static uint8_t bits[256]; /* count of bits set */ static void setupBitsTables() @@ -423,10 +416,10 @@ static int clamp(float v, int low, int high) #endif static void -expFill(float pct[], uint32 p, uint32 n) +expFill(float pct[], uint32_t p, uint32_t n) { - uint32 i; - uint32 c = (p * n) / 100; + uint32_t i; + uint32_t c = (p * n) / 100; for (i = 1; i < c; i++) pct[i] = (float) (1-exp(i/((double)(n-1)))/ M_E); for (; i < n; i++) @@ -437,7 +430,7 @@ static void setupCmap() { float pct[256]; /* known to be large enough */ - uint32 i; + uint32_t i; pct[0] = 1; /* force white */ switch (contrast) { case EXP50: expFill(pct, 50, 256); break; @@ -466,10 +459,10 @@ setupCmap() static void initScale() { - src0 = (uint8*) _TIFFmalloc(sizeof (uint8) * tnw); - src1 = (uint8*) _TIFFmalloc(sizeof (uint8) * tnw); - src2 = (uint8*) _TIFFmalloc(sizeof (uint8) * tnw); - rowoff = (uint32*) _TIFFmalloc(sizeof (uint32) * tnw); + src0 = (uint8_t*) _TIFFmalloc(sizeof (uint8_t) * tnw); + src1 = (uint8_t*) _TIFFmalloc(sizeof (uint8_t) * tnw); + src2 = (uint8_t*) _TIFFmalloc(sizeof (uint8_t) * tnw); + rowoff = (uint32_t*) _TIFFmalloc(sizeof (uint32_t) * tnw); filterWidth = 0; stepDstWidth = stepSrcWidth = 0; setupBitsTables(); @@ -480,18 +473,18 @@ initScale() * according to the widths of the src and dst images. */ static void -setupStepTables(uint32 sw) +setupStepTables(uint32_t sw) { if (stepSrcWidth != sw || stepDstWidth != tnw) { int step = sw; int limit = tnw; int err = 0; - uint32 sx = 0; - uint32 x; + uint32_t sx = 0; + uint32_t x; int fw; - uint8 b; + uint8_t b; for (x = 0; x < tnw; x++) { - uint32 sx0 = sx; + uint32_t sx0 = sx; err += step; while (err >= limit) { err -= limit; @@ -514,19 +507,19 @@ setupStepTables(uint32 sw) } static void -setrow(uint8* row, uint32 nrows, const uint8* rows[]) +setrow(uint8_t* row, uint32_t nrows, const uint8_t* rows[]) { - uint32 x; - uint32 area = nrows * filterWidth; + uint32_t x; + uint32_t area = nrows * filterWidth; for (x = 0; x < tnw; x++) { - uint32 mask0 = src0[x]; - uint32 fw = src1[x]; - uint32 mask1 = src1[x]; - uint32 off = rowoff[x]; - uint32 acc = 0; - uint32 y, i; + uint32_t mask0 = src0[x]; + uint32_t fw = src1[x]; + uint32_t mask1 = src1[x]; + uint32_t off = rowoff[x]; + uint32_t acc = 0; + uint32_t y, i; for (y = 0; y < nrows; y++) { - const uint8* src = rows[y] + off; + const uint8_t* src = rows[y] + off; acc += bits[*src++ & mask0]; switch (fw) { default: @@ -556,18 +549,18 @@ setrow(uint8* row, uint32 nrows, const uint8* rows[]) * with a user-selectable contrast curve. */ static void -setImage1(const uint8* br, uint32 rw, uint32 rh) +setImage1(const uint8_t* br, uint32_t rw, uint32_t rh) { int step = rh; int limit = tnh; int err = 0; int bpr = TIFFhowmany8(rw); int sy = 0; - uint8* row = thumbnail; - uint32 dy; + uint8_t* row = thumbnail; + uint32_t dy; for (dy = 0; dy < tnh; dy++) { - const uint8* rows[256]; - uint32 nrows = 1; + const uint8_t* rows[256]; + uint32_t nrows = 1; fprintf(stderr, "bpr=%d, sy=%d, bpr*sy=%d\n", bpr, sy, bpr*sy); rows[0] = br + bpr*sy; err += step; @@ -589,9 +582,9 @@ setImage1(const uint8* br, uint32 rw, uint32 rh) } static void -setImage(const uint8* br, uint32 rw, uint32 rh) +setImage(const uint8_t* br, uint32_t rw, uint32_t rh) { - filterWidth = (uint16) ceil((double) rw / (double) tnw); + filterWidth = (uint16_t) ceil((double) rw / (double) tnw); setupStepTables(rw); setImage1(br, rw, rh); } @@ -601,8 +594,8 @@ generateThumbnail(TIFF* in, TIFF* out) { unsigned char* raster; unsigned char* rp; - uint32 sw, sh, rps; - uint16 bps, spp; + uint32_t sw, sh, rps; + uint16_t bps, spp; tsize_t rowsize, rastersize; tstrip_t s, ns = TIFFNumberOfStrips(in); toff_t diroff[1]; @@ -639,25 +632,26 @@ generateThumbnail(TIFF* in, TIFF* out) _TIFFfree(raster); TIFFSetField(out, TIFFTAG_SUBFILETYPE, FILETYPE_REDUCEDIMAGE); - TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32) tnw); - TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32) tnh); - TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, (uint16) 8); - TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, (uint16) 1); + TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32_t) tnw); + TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32_t) tnh); + TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, (uint16_t) 8); + TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, (uint16_t) 1); TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS); TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); - cpTag(in, out, TIFFTAG_SOFTWARE, (uint16) -1, TIFF_ASCII); - cpTag(in, out, TIFFTAG_IMAGEDESCRIPTION, (uint16) -1, TIFF_ASCII); - cpTag(in, out, TIFFTAG_DATETIME, (uint16) -1, TIFF_ASCII); - cpTag(in, out, TIFFTAG_HOSTCOMPUTER, (uint16) -1, TIFF_ASCII); + cpTag(in, out, TIFFTAG_SOFTWARE, (uint16_t) -1, TIFF_ASCII); + cpTag(in, out, TIFFTAG_IMAGEDESCRIPTION, (uint16_t) -1, TIFF_ASCII); + cpTag(in, out, TIFFTAG_DATETIME, (uint16_t) -1, TIFF_ASCII); + cpTag(in, out, TIFFTAG_HOSTCOMPUTER, (uint16_t) -1, TIFF_ASCII); diroff[0] = 0UL; TIFFSetField(out, TIFFTAG_SUBIFD, 1, diroff); return (TIFFWriteEncodedStrip(out, 0, thumbnail, tnw*tnh) != -1 && TIFFWriteDirectory(out) != -1); } -const char* stuff[] = { +const char* usage_info[] = { +"Create a TIFF file with thumbnail images\n\n" "usage: thumbnail [options] input.tif output.tif", "where options are:", " -h # specify thumbnail image height (default is 274)", @@ -680,8 +674,8 @@ usage(int code) FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + for (i = 0; usage_info[i] != NULL; i++) + fprintf(out, "%s\n", usage_info[i]); exit(code); } diff --git a/tiff/tools/tiff2bw.c b/tiff/tools/tiff2bw.c index 654bd324..75811e6a 100644 --- a/tiff/tools/tiff2bw.c +++ b/tiff/tools/tiff2bw.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> @@ -33,10 +34,6 @@ # include <unistd.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffio.h" #include "tiffiop.h" @@ -57,7 +54,7 @@ static void usage(int code); static int processCompressOptions(char*); static void -compresscontig(unsigned char* out, unsigned char* rgb, uint32 n) +compresscontig(unsigned char* out, unsigned char* rgb, uint32_t n) { register int v, red = RED, green = GREEN, blue = BLUE; @@ -71,9 +68,9 @@ compresscontig(unsigned char* out, unsigned char* rgb, uint32 n) static void compresssep(unsigned char* out, - unsigned char* r, unsigned char* g, unsigned char* b, uint32 n) + unsigned char* r, unsigned char* g, unsigned char* b, uint32_t n) { - register uint32 red = RED, green = GREEN, blue = BLUE; + register uint32_t red = RED, green = GREEN, blue = BLUE; while (n-- > 0) *out++ = (unsigned char) @@ -81,7 +78,7 @@ compresssep(unsigned char* out, } static int -checkcmap(TIFF* tif, int n, uint16* r, uint16* g, uint16* b) +checkcmap(TIFF* tif, int n, uint16_t* r, uint16_t* g, uint16_t* b) { while (n-- > 0) if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256) @@ -91,7 +88,7 @@ checkcmap(TIFF* tif, int n, uint16* r, uint16* g, uint16* b) } static void -compresspalette(unsigned char* out, unsigned char* data, uint32 n, uint16* rmap, uint16* gmap, uint16* bmap) +compresspalette(unsigned char* out, unsigned char* data, uint32_t n, uint16_t* rmap, uint16_t* gmap, uint16_t* bmap) { register int v, red = RED, green = GREEN, blue = BLUE; @@ -104,8 +101,8 @@ compresspalette(unsigned char* out, unsigned char* data, uint32 n, uint16* rmap, } } -static uint16 compression = (uint16) -1; -static uint16 predictor = 0; +static uint16_t compression = (uint16_t) -1; +static uint16_t predictor = 0; static int jpegcolormode = JPEGCOLORMODE_RGB; static int quality = 75; /* JPEG quality */ @@ -114,18 +111,18 @@ static void cpTags(TIFF* in, TIFF* out); int main(int argc, char* argv[]) { - uint32 rowsperstrip = (uint32) -1; + uint32_t rowsperstrip = (uint32_t) -1; TIFF *in, *out; - uint32 w, h; - uint16 samplesperpixel; - uint16 bitspersample; - uint16 config; - uint16 photometric; - uint16* red; - uint16* green; - uint16* blue; + uint32_t w, h; + uint16_t samplesperpixel; + uint16_t bitspersample; + uint16_t config; + uint16_t photometric; + uint16_t* red; + uint16_t* green; + uint16_t* blue; tsize_t rowsize; - register uint32 row; + register uint32_t row; register tsample_t s; unsigned char *inbuf, *outbuf; char thing[1024]; @@ -160,9 +157,12 @@ main(int argc, char* argv[]) break; case 'h': usage(EXIT_SUCCESS); + /*NOTREACHED*/ + break; case '?': usage(EXIT_FAILURE); /*NOTREACHED*/ + break; } if (argc - optind < 2) usage(EXIT_FAILURE); @@ -209,7 +209,7 @@ main(int argc, char* argv[]) TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 1); TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); cpTags(in, out); - if (compression != (uint16) -1) { + if (compression != (uint16_t) -1) { TIFFSetField(out, TIFFTAG_COMPRESSION, compression); switch (compression) { case COMPRESSION_JPEG: @@ -376,27 +376,27 @@ processCompressOptions(char* opt) if (TIFFGetField(in, tag, &v1, &v2, &v3, &v4)) TIFFSetField(out, tag, v1, v2, v3, v4) static void -cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) +cpTag(TIFF* in, TIFF* out, uint16_t tag, uint16_t count, TIFFDataType type) { switch (type) { case TIFF_SHORT: if (count == 1) { - uint16 shortv; + uint16_t shortv; CopyField(tag, shortv); } else if (count == 2) { - uint16 shortv1, shortv2; + uint16_t shortv1, shortv2; CopyField2(tag, shortv1, shortv2); } else if (count == 4) { - uint16 *tr, *tg, *tb, *ta; + uint16_t *tr, *tg, *tb, *ta; CopyField4(tag, tr, tg, tb, ta); - } else if (count == (uint16) -1) { - uint16 shortv1; - uint16* shortav; + } else if (count == (uint16_t) -1) { + uint16_t shortv1; + uint16_t* shortav; CopyField2(tag, shortv1, shortav); } break; case TIFF_LONG: - { uint32 longv; + { uint32_t longv; CopyField(tag, longv); } break; @@ -404,7 +404,7 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) if (count == 1) { float floatv; CopyField(tag, floatv); - } else if (count == (uint16) -1) { + } else if (count == (uint16_t) -1) { float* floatav; CopyField(tag, floatav); } @@ -418,7 +418,7 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) if (count == 1) { double doublev; CopyField(tag, doublev); - } else if (count == (uint16) -1) { + } else if (count == (uint16_t) -1) { double* doubleav; CopyField(tag, doubleav); } @@ -435,9 +435,9 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) #undef CopyField2 #undef CopyField -static struct cpTag { - uint16 tag; - uint16 count; +static const struct cpTag { + uint16_t tag; + uint16_t count; TIFFDataType type; } tags[] = { { TIFFTAG_SUBFILETYPE, 1, TIFF_LONG }, @@ -449,49 +449,49 @@ static struct cpTag { { TIFFTAG_MINSAMPLEVALUE, 1, TIFF_SHORT }, { TIFFTAG_MAXSAMPLEVALUE, 1, TIFF_SHORT }, { TIFFTAG_XRESOLUTION, 1, TIFF_RATIONAL }, - { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL }, - { TIFFTAG_PAGENAME, 1, TIFF_ASCII }, - { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL }, - { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL }, - { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT }, - { TIFFTAG_SOFTWARE, 1, TIFF_ASCII }, - { TIFFTAG_DATETIME, 1, TIFF_ASCII }, - { TIFFTAG_ARTIST, 1, TIFF_ASCII }, - { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII }, - { TIFFTAG_WHITEPOINT, 2, TIFF_RATIONAL }, - { TIFFTAG_PRIMARYCHROMATICITIES,(uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT }, - { TIFFTAG_INKSET, 1, TIFF_SHORT }, - { TIFFTAG_DOTRANGE, 2, TIFF_SHORT }, - { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII }, - { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT }, - { TIFFTAG_YCBCRCOEFFICIENTS, (uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT }, - { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT }, - { TIFFTAG_REFERENCEBLACKWHITE, (uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_EXTRASAMPLES, (uint16) -1, TIFF_SHORT }, - { TIFFTAG_SMINSAMPLEVALUE, 1, TIFF_DOUBLE }, - { TIFFTAG_SMAXSAMPLEVALUE, 1, TIFF_DOUBLE }, - { TIFFTAG_STONITS, 1, TIFF_DOUBLE }, + { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL }, + { TIFFTAG_PAGENAME, 1, TIFF_ASCII }, + { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL }, + { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL }, + { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT }, + { TIFFTAG_SOFTWARE, 1, TIFF_ASCII }, + { TIFFTAG_DATETIME, 1, TIFF_ASCII }, + { TIFFTAG_ARTIST, 1, TIFF_ASCII }, + { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII }, + { TIFFTAG_WHITEPOINT, 2, TIFF_RATIONAL }, + { TIFFTAG_PRIMARYCHROMATICITIES,(uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT }, + { TIFFTAG_INKSET, 1, TIFF_SHORT }, + { TIFFTAG_DOTRANGE, 2, TIFF_SHORT }, + { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII }, + { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT }, + { TIFFTAG_YCBCRCOEFFICIENTS, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT }, + { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT }, + { TIFFTAG_REFERENCEBLACKWHITE, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_EXTRASAMPLES, (uint16_t) -1, TIFF_SHORT }, + { TIFFTAG_SMINSAMPLEVALUE, 1, TIFF_DOUBLE }, + { TIFFTAG_SMAXSAMPLEVALUE, 1, TIFF_DOUBLE }, + { TIFFTAG_STONITS, 1, TIFF_DOUBLE }, }; #define NTAGS (sizeof (tags) / sizeof (tags[0])) static void cpTags(TIFF* in, TIFF* out) { - struct cpTag *p; + const struct cpTag *p; for (p = tags; p < &tags[NTAGS]; p++) { if( p->tag == TIFFTAG_GROUP3OPTIONS ) { - uint16 compression; + uint16_t compression; if( !TIFFGetField(in, TIFFTAG_COMPRESSION, &compression) || compression != COMPRESSION_CCITTFAX3 ) continue; } if( p->tag == TIFFTAG_GROUP4OPTIONS ) { - uint16 compression; + uint16_t compression; if( !TIFFGetField(in, TIFFTAG_COMPRESSION, &compression) || compression != COMPRESSION_CCITTFAX4 ) continue; @@ -501,37 +501,47 @@ cpTags(TIFF* in, TIFF* out) } #undef NTAGS -const char* stuff[] = { -"usage: tiff2bw [options] input.tif output.tif", -"where options are:", -" -R % use #% from red channel", -" -G % use #% from green channel", -" -B % use #% from blue channel", -"", -" -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 g3[:opts] compress output with CCITT Group 3 encoding", -" -c g4 compress output with CCITT Group 4 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 const char usage_info[] = +"Convert a color TIFF image to greyscale\n\n" +"usage: tiff2bw [options] input.tif output.tif\n" +"where options are:\n" +" -R % use #% from red channel\n" +" -G % use #% from green channel\n" +" -B % use #% from blue channel\n" +"\n" +" -r # make each strip have no more than # rows\n" +"\n" +#ifdef LZW_SUPPORT +" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding\n" +/* " LZW options:\n" */ +" # set predictor value\n" +" For example, -c lzw:2 for LZW-encoded data with horizontal differencing\n" +#endif +#ifdef ZIP_SUPPORT +" -c zip[:opts] compress output with deflate encoding\n" +/* " Deflate (ZIP) options:\n" */ +" # set predictor value\n" +#endif +#ifdef PACKBITS_SUPPORT +" -c packbits compress output with packbits encoding\n" +#endif +#ifdef CCITT_SUPPORT +" -c g3[:opts] compress output with CCITT Group 3 encoding\n" +" -c g4 compress output with CCITT Group 4 encoding\n" +#endif +#if defined(LZW_SUPPORT) || defined(ZIP_SUPPORT) || defined(PACKBITS_SUPPORT) || defined(CCITT_SUPPORT) +" -c none use no compression algorithm on output\n" +#endif +"\n" +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } diff --git a/tiff/tools/tiff2pdf.c b/tiff/tools/tiff2pdf.c index acaef0d6..63751f11 100644 --- a/tiff/tools/tiff2pdf.c +++ b/tiff/tools/tiff2pdf.c @@ -24,8 +24,6 @@ * OF THIS SOFTWARE. */ -#include "tif_config.h" - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -46,16 +44,10 @@ # include <io.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffiop.h" #include "tiffio.h" - -#ifndef HAVE_GETOPT -extern int getopt(int argc, char * const argv[], const char *optstring); -#endif +#include "tif_config.h" +#include "libport.h" #ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 @@ -128,9 +120,9 @@ typedef enum{ /* This struct defines a logical page of a TIFF. */ typedef struct { tdir_t page_directory; - uint32 page_number; + uint32_t page_number; ttile_t page_tilecount; - uint32 page_extra; + uint32_t page_extra; } T2P_PAGE; /* This struct defines a PDF rectangle's coordinates. */ @@ -150,12 +142,12 @@ typedef struct { /* This struct defines information about the tiles on a PDF page. */ typedef struct { ttile_t tiles_tilecount; - uint32 tiles_tilewidth; - uint32 tiles_tilelength; - uint32 tiles_tilecountx; - uint32 tiles_tilecounty; - uint32 tiles_edgetilewidth; - uint32 tiles_edgetilelength; + uint32_t tiles_tilewidth; + uint32_t tiles_tilelength; + uint32_t tiles_tilecountx; + uint32_t tiles_tilecounty; + uint32_t tiles_edgetilewidth; + uint32_t tiles_edgetilelength; T2P_TILE* tiles_tiles; } T2P_TILES; @@ -165,24 +157,24 @@ typedef struct { T2P_PAGE* tiff_pages; T2P_TILES* tiff_tiles; tdir_t tiff_pagecount; - uint16 tiff_compression; - uint16 tiff_photometric; - uint16 tiff_fillorder; - uint16 tiff_bitspersample; - uint16 tiff_samplesperpixel; - uint16 tiff_planar; - uint32 tiff_width; - uint32 tiff_length; + uint16_t tiff_compression; + uint16_t tiff_photometric; + uint16_t tiff_fillorder; + uint16_t tiff_bitspersample; + uint16_t tiff_samplesperpixel; + uint16_t tiff_planar; + uint32_t tiff_width; + uint32_t tiff_length; float tiff_xres; float tiff_yres; - uint16 tiff_orientation; + uint16_t tiff_orientation; toff_t tiff_dataoffset; tsize_t tiff_datasize; tsize_t tiff_maxdatasize; - uint16 tiff_resunit; - uint16 pdf_centimeters; - uint16 pdf_overrideres; - uint16 pdf_overridepagesize; + uint16_t tiff_resunit; + uint16_t pdf_centimeters; + uint16_t pdf_overrideres; + uint16_t pdf_overridepagesize; float pdf_defaultxres; float pdf_defaultyres; float pdf_xres; @@ -196,14 +188,14 @@ typedef struct { int pdf_image_fillpage; /* 0 (default: no scaling, 1:scale imagesize to pagesize */ T2P_BOX pdf_mediabox; T2P_BOX pdf_imagebox; - uint16 pdf_majorversion; - uint16 pdf_minorversion; - uint32 pdf_catalog; - uint32 pdf_pages; - uint32 pdf_info; - uint32 pdf_palettecs; - uint16 pdf_fitwindow; - uint32 pdf_startxref; + uint16_t pdf_majorversion; + uint16_t pdf_minorversion; + uint32_t pdf_catalog; + uint32_t pdf_pages; + uint32_t pdf_info; + uint32_t pdf_palettecs; + uint16_t pdf_fitwindow; + uint32_t pdf_startxref; #define TIFF2PDF_FILEID_SIZE 33 char pdf_fileid[TIFF2PDF_FILEID_SIZE]; #define TIFF2PDF_DATETIME_SIZE 17 @@ -224,35 +216,35 @@ typedef struct { char pdf_keywords[TIFF2PDF_KEYWORDS_SIZE]; int pdf_keywords_set; t2p_cs_t pdf_colorspace; - uint16 pdf_colorspace_invert; - uint16 pdf_switchdecode; - uint16 pdf_palettesize; + uint16_t pdf_colorspace_invert; + uint16_t pdf_switchdecode; + uint16_t pdf_palettesize; unsigned char* pdf_palette; int pdf_labrange[4]; t2p_compress_t pdf_defaultcompression; - uint16 pdf_defaultcompressionquality; + uint16_t pdf_defaultcompressionquality; t2p_compress_t pdf_compression; - uint16 pdf_compressionquality; /* for deflate : 100 * zipquality + predictor */ - uint16 pdf_nopassthrough; + uint16_t pdf_compressionquality; /* for deflate : 100 * zipquality + predictor */ + uint16_t pdf_nopassthrough; t2p_transcode_t pdf_transcode; t2p_sample_t pdf_sample; - uint32* pdf_xrefoffsets; - uint32 pdf_xrefcount; + uint32_t* pdf_xrefoffsets; + uint32_t pdf_xrefcount; tdir_t pdf_page; #ifdef OJPEG_SUPPORT tdata_t pdf_ojpegdata; - uint32 pdf_ojpegdatalength; - uint32 pdf_ojpegiflength; + uint32_t pdf_ojpegdatalength; + uint32_t pdf_ojpegiflength; #endif float tiff_whitechromaticities[2]; float tiff_primarychromaticities[6]; float tiff_referenceblackwhite[2]; - uint16* tiff_transferfunction[3]; + uint16_t* tiff_transferfunction[3]; int pdf_image_interpolate; /* 0 (default) : do not interpolate, 1 : interpolate */ - uint16 tiff_transferfunctioncount; - uint32 pdf_icccs; - uint32 tiff_iccprofilelength; + uint16_t tiff_transferfunctioncount; + uint32_t pdf_icccs; + uint32_t tiff_iccprofilelength; tdata_t tiff_iccprofile; /* fields for custom read/write procedures */ @@ -263,7 +255,7 @@ typedef struct { /* These functions are called by main. */ -static void tiff2pdf_usage(int); +static void usage_info(int); int tiff2pdf_match_paper_size(float*, float*, char*); /* These functions are used to generate a PDF from a TIFF. */ @@ -296,25 +288,25 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P*, TIFF*, TIFF*, ttile_t); int t2p_process_ojpeg_tables(T2P*, TIFF*); #endif #ifdef JPEG_SUPPORT -int t2p_process_jpeg_strip(unsigned char*, tsize_t*, unsigned char*, tsize_t, tsize_t*, tstrip_t, uint32); +int t2p_process_jpeg_strip(unsigned char*, tsize_t*, unsigned char*, tsize_t, tsize_t*, tstrip_t, uint32_t); #endif -void t2p_tile_collapse_left(tdata_t, tsize_t, uint32, uint32, uint32); +void t2p_tile_collapse_left(tdata_t, tsize_t, uint32_t, uint32_t, uint32_t); void t2p_write_advance_directory(T2P*, TIFF*); tsize_t t2p_sample_planar_separate_to_contig(T2P*, unsigned char*, unsigned char*, tsize_t); tsize_t t2p_sample_realize_palette(T2P*, unsigned char*); -tsize_t t2p_sample_abgr_to_rgb(tdata_t, uint32); -tsize_t t2p_sample_rgba_to_rgb(tdata_t, uint32); -tsize_t t2p_sample_rgbaa_to_rgb(tdata_t, uint32); -tsize_t t2p_sample_lab_signed_to_unsigned(tdata_t, uint32); +tsize_t t2p_sample_abgr_to_rgb(tdata_t, uint32_t); +tsize_t t2p_sample_rgba_to_rgb(tdata_t, uint32_t); +tsize_t t2p_sample_rgbaa_to_rgb(tdata_t, uint32_t); +tsize_t t2p_sample_lab_signed_to_unsigned(tdata_t, uint32_t); tsize_t t2p_write_pdf_header(T2P*, TIFF*); -tsize_t t2p_write_pdf_obj_start(uint32, TIFF*); +tsize_t t2p_write_pdf_obj_start(uint32_t, TIFF*); tsize_t t2p_write_pdf_obj_end(TIFF*); tsize_t t2p_write_pdf_name(const unsigned char*, TIFF*); tsize_t t2p_write_pdf_string(const char*, TIFF*); tsize_t t2p_write_pdf_stream(tdata_t, tsize_t, TIFF*); tsize_t t2p_write_pdf_stream_start(TIFF*); tsize_t t2p_write_pdf_stream_end(TIFF*); -tsize_t t2p_write_pdf_stream_dict(tsize_t, uint32, TIFF*); +tsize_t t2p_write_pdf_stream_dict(tsize_t, uint32_t, TIFF*); tsize_t t2p_write_pdf_stream_dict_start(TIFF*); tsize_t t2p_write_pdf_stream_dict_end(TIFF*); tsize_t t2p_write_pdf_stream_length(tsize_t, TIFF*); @@ -323,16 +315,16 @@ tsize_t t2p_write_pdf_info(T2P*, TIFF*, TIFF*); void t2p_pdf_currenttime(T2P*); void t2p_pdf_tifftime(T2P*, TIFF*); tsize_t t2p_write_pdf_pages(T2P*, TIFF*); -tsize_t t2p_write_pdf_page(uint32, T2P*, TIFF*); +tsize_t t2p_write_pdf_page(uint32_t, T2P*, TIFF*); void t2p_compose_pdf_page(T2P*); -void t2p_compose_pdf_page_orient(T2P_BOX*, uint16); -void t2p_compose_pdf_page_orient_flip(T2P_BOX*, uint16); +void t2p_compose_pdf_page_orient(T2P_BOX*, uint16_t); +void t2p_compose_pdf_page_orient_flip(T2P_BOX*, uint16_t); tsize_t t2p_write_pdf_page_content(T2P*, TIFF*); tsize_t t2p_write_pdf_xobject_stream_dict(ttile_t, T2P*, TIFF*); tsize_t t2p_write_pdf_xobject_cs(T2P*, TIFF*); tsize_t t2p_write_pdf_transfer(T2P*, TIFF*); -tsize_t t2p_write_pdf_transfer_dict(T2P*, TIFF*, uint16); -tsize_t t2p_write_pdf_transfer_stream(T2P*, TIFF*, uint16); +tsize_t t2p_write_pdf_transfer_dict(T2P*, TIFF*, uint16_t); +tsize_t t2p_write_pdf_transfer_stream(T2P*, TIFF*, uint16_t); tsize_t t2p_write_pdf_xobject_calcs(T2P*, TIFF*); tsize_t t2p_write_pdf_xobject_icccs(T2P*, TIFF*); tsize_t t2p_write_pdf_xobject_icccs_dict(T2P*, TIFF*); @@ -390,7 +382,7 @@ t2pWriteFile(TIFF *tif, tdata_t data, tmsize_t size) return -1; } -static uint64 +static uint64_t t2pSeekFile(TIFF *tif, toff_t offset, int whence) { thandle_t client = TIFFClientdata(tif); @@ -419,8 +411,8 @@ t2p_writeproc(thandle_t handle, tdata_t data, tmsize_t size) return size; } -static uint64 -t2p_seekproc(thandle_t handle, uint64 offset, int whence) +static uint64_t +t2p_seekproc(thandle_t handle, uint64_t offset, int whence) { T2P *t2p = (T2P*) handle; if (t2p->outputdisable <= 0 && t2p->outputfile) @@ -435,7 +427,7 @@ t2p_closeproc(thandle_t handle) return fclose(t2p->outputfile); } -static uint64 +static uint64_t t2p_sizeproc(thandle_t handle) { (void) handle; @@ -456,10 +448,10 @@ t2p_unmapproc(thandle_t handle, void *data, toff_t offset) } #if defined(OJPEG_SUPPORT) || defined(JPEG_SUPPORT) -static uint64 -checkAdd64(uint64 summand1, uint64 summand2, T2P* t2p) +static uint64_t +checkAdd64(uint64_t summand1, uint64_t summand2, T2P* t2p) { - uint64 bytes = summand1 + summand2; + uint64_t bytes = summand1 + summand2; if (bytes < summand1) { TIFFError(TIFF2PDF_MODULE, "Integer overflow"); @@ -471,10 +463,10 @@ checkAdd64(uint64 summand1, uint64 summand2, T2P* t2p) } #endif /* defined(OJPEG_SUPPORT) || defined(JPEG_SUPPORT) */ -static uint64 -checkMultiply64(uint64 first, uint64 second, T2P* t2p) +static uint64_t +checkMultiply64(uint64_t first, uint64_t second, T2P* t2p) { - uint64 bytes = first * second; + uint64_t bytes = first * second; if (second && bytes / second != first) { TIFFError(TIFF2PDF_MODULE, "Integer overflow"); @@ -557,8 +549,12 @@ checkMultiply64(uint64 first, uint64 second, T2P* t2p) options: -o: output to file name +#ifdef JPEG_SUPPORT -j: compress with JPEG (requires libjpeg configured with libtiff) - -z: compress with Zip/Deflate (requires zlib configured with libtiff) +#endif +#ifdef ZIP_SUPPORT +printf (-z: compress with Zip/Deflate (requires zlib configured with libtiff)); +#endif -q: compression quality -n: no compressed data passthrough -d: do not compress (decompress) @@ -755,10 +751,10 @@ int main(int argc, char** argv){ t2p->pdf_image_interpolate = 1; break; case 'h': - tiff2pdf_usage(EXIT_SUCCESS); + usage_info(EXIT_SUCCESS); goto success; case '?': - tiff2pdf_usage(EXIT_FAILURE); + usage_info(EXIT_FAILURE); goto fail; } } @@ -776,14 +772,14 @@ int main(int argc, char** argv){ } } else { TIFFError(TIFF2PDF_MODULE, "No input file specified"); - tiff2pdf_usage(EXIT_FAILURE); + usage_info(EXIT_FAILURE); goto fail; } if(argc > optind) { TIFFError(TIFF2PDF_MODULE, "No support for multiple input files"); - tiff2pdf_usage(EXIT_FAILURE); + usage_info(EXIT_FAILURE); goto fail; } @@ -845,48 +841,47 @@ success: } -static void tiff2pdf_usage(int code) { - static const char* lines[]={ - "usage: tiff2pdf [options] input.tiff", - "options:", - " -o: output to file name", +static void usage_info(int code) { + static const char lines[]= + "Convert a TIFF image to a PDF document\n\n" + "usage: tiff2pdf [options] input.tiff\n" + "where options are:\n" + " -o: output to file name\n" #ifdef JPEG_SUPPORT - " -j: compress with JPEG", + " -j: compress with JPEG\n" #endif #ifdef ZIP_SUPPORT - " -z: compress with Zip/Deflate", + " -z: compress with Zip/Deflate\n" #endif - " -q: compression quality", - " -n: no compressed data passthrough", - " -d: do not compress (decompress)", - " -i: invert colors", - " -u: set distance unit, 'i' for inch, 'm' for centimeter", - " -x: set x resolution default in dots per unit", - " -y: set y resolution default in dots per unit", - " -w: width in units", - " -l: length in units", - " -r: 'd' for resolution default, 'o' for resolution override", - " -p: paper size, eg \"letter\", \"legal\", \"A4\"", - " -F: make the tiff fill the PDF page", - " -f: set PDF \"Fit Window\" user preference", - " -e: date, overrides image or current date/time default, YYYYMMDDHHMMSS", - " -c: sets document creator, overrides image software default", - " -a: sets document author, overrides image artist default", - " -t: sets document title, overrides image document name default", - " -s: sets document subject, overrides image image description default", - " -k: sets document keywords", - " -b: set PDF \"Interpolate\" user preference", - " -m: set memory allocation limit (in MiB). set to 0 to disable limit", - " -h: usage", - NULL - }; - int i=0; +#if defined(JPEG_SUPPORT) || defined(ZIP_SUPPORT) + " -q: compression quality\n" + " -n: no compressed data passthrough\n" + " -d: do not compress (decompress)\n" +#endif + " -i: invert colors\n" + " -u: set distance unit, 'i' for inch, 'm' for centimeter\n" + " -x: set x resolution default in dots per unit\n" + " -y: set y resolution default in dots per unit\n" + " -w: width in units\n" + " -l: length in units\n" + " -r: 'd' for resolution default, 'o' for resolution override\n" + " -p: paper size, eg \"letter\", \"legal\", \"A4\"\n" + " -F: make the tiff fill the PDF page\n" + " -f: set PDF \"Fit Window\" user preference\n" + " -e: date, overrides image or current date/time default, YYYYMMDDHHMMSS\n" + " -c: sets document creator, overrides image software default\n" + " -a: sets document author, overrides image artist default\n" + " -t: sets document title, overrides image document name default\n" + " -s: sets document subject, overrides image image description default\n" + " -k: sets document keywords\n" + " -b: set PDF \"Interpolate\" user preference\n" + " -m: set memory allocation limit (in MiB). set to 0 to disable limit\n" + " -h: usage\n" + ; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i=0;lines[i]!=NULL;i++){ - fprintf(out, "%s\n", lines[i]); - } + fprintf(out, "%s", lines); return; } @@ -961,8 +956,8 @@ T2P* t2p_init() if(t2p==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for t2p_init", - (unsigned long) sizeof(T2P)); + "Can't allocate %"TIFF_SIZE_FORMAT" bytes of memory for t2p_init", + sizeof(T2P)); return( (T2P*) NULL ); } _TIFFmemset(t2p, 0x00, sizeof(T2P)); @@ -1021,6 +1016,7 @@ void t2p_free(T2P* t2p) */ void t2p_validate(T2P* t2p){ + (void) t2p; #ifdef JPEG_SUPPORT if(t2p->pdf_defaultcompression==T2P_COMPRESS_JPEG){ @@ -1032,7 +1028,7 @@ void t2p_validate(T2P* t2p){ #endif #ifdef ZIP_SUPPORT if(t2p->pdf_defaultcompression==T2P_COMPRESS_ZIP){ - uint16 m=t2p->pdf_defaultcompressionquality%100; + uint16_t m= t2p->pdf_defaultcompressionquality % 100; if(t2p->pdf_defaultcompressionquality/100 > 9 || (m>1 && m<10) || m>15){ t2p->pdf_defaultcompressionquality=0; @@ -1042,14 +1038,13 @@ void t2p_validate(T2P* t2p){ t2p->pdf_defaultcompressionquality*=100; TIFFError( TIFF2PDF_MODULE, - "PNG Group predictor differencing not implemented, assuming compression quality %u", + "PNG Group predictor differencing not implemented, assuming compression quality %"PRIu16, t2p->pdf_defaultcompressionquality); } t2p->pdf_defaultcompressionquality%=100; if(t2p->pdf_minorversion<2){t2p->pdf_minorversion=2;} } #endif - (void)0; return; } @@ -1066,11 +1061,11 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ tdir_t directorycount=0; tdir_t i=0; - uint16 pagen=0; - uint16 paged=0; - uint16 xuint16=0; - uint16 tiff_transferfunctioncount=0; - uint16* tiff_transferfunction[3]; + uint16_t pagen=0; + uint16_t paged=0; + uint16_t xuint16=0; + uint16_t tiff_transferfunctioncount=0; + uint16_t* tiff_transferfunction[3]; directorycount=TIFFNumberOfDirectories(input); if(directorycount > TIFF_DIR_MAX) { @@ -1085,8 +1080,8 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ if(t2p->tiff_pages==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate " TIFF_SIZE_FORMAT " bytes of memory for tiff_pages array, %s", - (TIFF_SIZE_T) directorycount * sizeof(T2P_PAGE), + "Can't allocate %"TIFF_SIZE_FORMAT" bytes of memory for tiff_pages array, %s", + sizeof(T2P_PAGE) * directorycount, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1096,20 +1091,20 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ if(t2p->tiff_tiles==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate " TIFF_SIZE_FORMAT " bytes of memory for tiff_tiles array, %s", - (TIFF_SIZE_T) directorycount * sizeof(T2P_TILES), + "Can't allocate %"TIFF_SIZE_FORMAT" bytes of memory for tiff_tiles array, %s", + sizeof(T2P_TILES) * directorycount, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return; } _TIFFmemset( t2p->tiff_tiles, 0x00, directorycount * sizeof(T2P_TILES)); for(i=0;i<directorycount;i++){ - uint32 subfiletype = 0; + uint32_t subfiletype = 0; if(!TIFFSetDirectory(input, i)){ TIFFError( TIFF2PDF_MODULE, - "Can't set directory %u of input file %s", + "Can't set directory %"PRIu16" of input file %s", i, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -1183,8 +1178,8 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ &(tiff_transferfunction[1]), &(tiff_transferfunction[2]))) { - if((tiff_transferfunction[1] != (uint16*) NULL) && - (tiff_transferfunction[2] != (uint16*) NULL) + if((tiff_transferfunction[1] != (uint16_t*) NULL) && + (tiff_transferfunction[2] != (uint16_t*) NULL) ) { tiff_transferfunctioncount=3; } else { @@ -1198,7 +1193,7 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ if (tiff_transferfunctioncount != t2p->tiff_transferfunctioncount){ TIFFError( TIFF2PDF_MODULE, - "Different transfer function on page %d", + "Different transfer function on page %"PRIu16, i); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1269,8 +1264,8 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ if( t2p->tiff_tiles[i].tiles_tiles == NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate " TIFF_SIZE_FORMAT " bytes of memory for t2p_read_tiff_init, %s", - (TIFF_SIZE_T) t2p->tiff_tiles[i].tiles_tilecount * sizeof(T2P_TILE), + "Can't allocate %"TIFF_SIZE_FORMAT" bytes of memory for t2p_read_tiff_init, %s", + sizeof(T2P_TILE) * t2p->tiff_tiles[i].tiles_tilecount, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1290,9 +1285,9 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ int t2p_cmp_t2p_page(const void* e1, const void* e2){ int d; - d = (int32)(((T2P_PAGE*)e1)->page_number) - (int32)(((T2P_PAGE*)e2)->page_number); + d = (int32_t)(((T2P_PAGE*)e1)->page_number) - (int32_t)(((T2P_PAGE*)e2)->page_number); if(d == 0){ - d = (int32)(((T2P_PAGE*)e1)->page_directory) - (int32)(((T2P_PAGE*)e2)->page_directory); + d = (int32_t)(((T2P_PAGE*)e1)->page_directory) - (int32_t)(((T2P_PAGE*)e2)->page_directory); } return d; } @@ -1312,12 +1307,12 @@ int t2p_cmp_t2p_page(const void* e1, const void* e2){ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ int i=0; - uint16* r = NULL; - uint16* g = NULL; - uint16* b = NULL; - uint16* a = NULL; - uint16 xuint16; - uint16* xuint16p; + uint16_t* r = NULL; + uint16_t* g = NULL; + uint16_t* b = NULL; + uint16_t* a = NULL; + uint16_t xuint16; + uint16_t* xuint16p; float* xfloatp; t2p->pdf_transcode = T2P_TRANSCODE_ENCODE; @@ -1359,7 +1354,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ if( TIFFIsCODECConfigured(t2p->tiff_compression) == 0){ TIFFError( TIFF2PDF_MODULE, - "No support for %s with compression type %u: not configured", + "No support for %s with compression type %"PRIu16": not configured", TIFFFileName(input), t2p->tiff_compression ); @@ -1385,7 +1380,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ default: TIFFError( TIFF2PDF_MODULE, - "No support for %s with %u bits per sample", + "No support for %s with %"PRIu16" bits per sample", TIFFFileName(input), t2p->tiff_bitspersample); t2p->t2p_error = T2P_ERR_ERROR; @@ -1396,7 +1391,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ if(t2p->tiff_samplesperpixel>4){ TIFFError( TIFF2PDF_MODULE, - "No support for %s with %u samples per pixel", + "No support for %s with %"PRIu16" samples per pixel", TIFFFileName(input), t2p->tiff_samplesperpixel); t2p->t2p_error = T2P_ERR_ERROR; @@ -1419,7 +1414,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ default: TIFFError( TIFF2PDF_MODULE, - "No support for %s with sample format %u", + "No support for %s with sample format %"PRIu16, TIFFFileName(input), xuint16); t2p->t2p_error = T2P_ERR_ERROR; @@ -1476,7 +1471,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ { TIFFError( TIFF2PDF_MODULE, - "No support for BitsPerSample=%d for RGBA", + "No support for BitsPerSample=%"PRIu16" for RGBA", t2p->tiff_bitspersample); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1489,7 +1484,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ { TIFFError( TIFF2PDF_MODULE, - "No support for BitsPerSample=%d for RGBA", + "No support for BitsPerSample=%"PRIu16" for RGBA", t2p->tiff_bitspersample); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1513,7 +1508,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ } else { TIFFError( TIFF2PDF_MODULE, - "No support for RGB image %s with %u samples per pixel", + "No support for RGB image %s with %"PRIu16" samples per pixel", TIFFFileName(input), t2p->tiff_samplesperpixel); t2p->t2p_error = T2P_ERR_ERROR; @@ -1522,7 +1517,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ } else { TIFFError( TIFF2PDF_MODULE, - "No support for RGB image %s with %u samples per pixel", + "No support for RGB image %s with %"PRIu16" samples per pixel", TIFFFileName(input), t2p->tiff_samplesperpixel); t2p->t2p_error = T2P_ERR_ERROR; @@ -1564,7 +1559,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ if(t2p->pdf_palette==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_read_tiff_image, %s", + "Can't allocate %"PRIu16" bytes of memory for t2p_read_tiff_image, %s", t2p->pdf_palettesize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -1598,7 +1593,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ } else { TIFFError( TIFF2PDF_MODULE, - "No support for %s because it has %u samples per pixel", + "No support for %s because it has %"PRIu16" samples per pixel", TIFFFileName(input), t2p->tiff_samplesperpixel); t2p->t2p_error = T2P_ERR_ERROR; @@ -1640,7 +1635,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ if(t2p->pdf_palette==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_read_tiff_image, %s", + "Can't allocate %"PRIu16" bytes of memory for t2p_read_tiff_image, %s", t2p->pdf_palettesize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -1672,7 +1667,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ if( t2p->tiff_samplesperpixel != 3){ TIFFError( TIFF2PDF_MODULE, - "Unsupported samplesperpixel = %d for CIELAB", + "Unsupported samplesperpixel = %"PRIu16" for CIELAB", t2p->tiff_samplesperpixel); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1680,7 +1675,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ if( t2p->tiff_bitspersample != 8){ TIFFError( TIFF2PDF_MODULE, - "Invalid bitspersample = %d for CIELAB", + "Invalid bitspersample = %"PRIu16" for CIELAB", t2p->tiff_bitspersample); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1703,7 +1698,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ if( t2p->tiff_samplesperpixel != 3){ TIFFError( TIFF2PDF_MODULE, - "Unsupported samplesperpixel = %d for ITULAB", + "Unsupported samplesperpixel = %"PRIu16" for ITULAB", t2p->tiff_samplesperpixel); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1711,7 +1706,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ if( t2p->tiff_bitspersample != 8){ TIFFError( TIFF2PDF_MODULE, - "Invalid bitspersample = %d for ITULAB", + "Invalid bitspersample = %"PRIu16" for ITULAB", t2p->tiff_bitspersample); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1734,7 +1729,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ default: TIFFError( TIFF2PDF_MODULE, - "No support for %s with photometric interpretation %u", + "No support for %s with photometric interpretation %"PRIu16, TIFFFileName(input), t2p->tiff_photometric); t2p->t2p_error = T2P_ERR_ERROR; @@ -1756,7 +1751,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ if(t2p->tiff_bitspersample!=8){ TIFFError( TIFF2PDF_MODULE, - "No support for %s with separated planar configuration and %u bits per sample", + "No support for %s with separated planar configuration and %"PRIu16" bits per sample", TIFFFileName(input), t2p->tiff_bitspersample); t2p->t2p_error = T2P_ERR_ERROR; @@ -1766,7 +1761,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ default: TIFFError( TIFF2PDF_MODULE, - "No support for %s with planar configuration %u", + "No support for %s with planar configuration %"PRIu16, TIFFFileName(input), t2p->tiff_planar); t2p->t2p_error = T2P_ERR_ERROR; @@ -1778,7 +1773,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ &(t2p->tiff_orientation)); if(t2p->tiff_orientation>8){ TIFFWarning(TIFF2PDF_MODULE, - "Image %s has orientation %u, assuming 0", + "Image %s has orientation %"PRIu16", assuming 0", TIFFFileName(input), t2p->tiff_orientation); t2p->tiff_orientation=0; } @@ -1824,7 +1819,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ if(t2p->tiff_compression== COMPRESSION_ADOBE_DEFLATE || t2p->tiff_compression==COMPRESSION_DEFLATE){ if(TIFFIsTiled(input) || (TIFFNumberOfStrips(input)==1) ){ - uint16 predictor; + uint16_t predictor; t2p->pdf_transcode = T2P_TRANSCODE_RAW; t2p->pdf_compression=T2P_COMPRESS_ZIP; TIFFGetField(input, TIFFTAG_PREDICTOR, &predictor); @@ -1899,8 +1894,8 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ &(t2p->tiff_transferfunction[0]), &(t2p->tiff_transferfunction[1]), &(t2p->tiff_transferfunction[2]))) { - if((t2p->tiff_transferfunction[1] != (uint16*) NULL) && - (t2p->tiff_transferfunction[2] != (uint16*) NULL) + if((t2p->tiff_transferfunction[1] != (uint16_t*) NULL) && + (t2p->tiff_transferfunction[2] != (uint16_t*) NULL) ) { t2p->tiff_transferfunctioncount=3; } else { @@ -1960,41 +1955,44 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ return; } -/* +/** + * checks for overflow + */ +static void t2p_set_tiff_datasize(T2P* t2p, uint64_t k) { + if (k != (uint64_t)(tmsize_t)k || (tmsize_t)k < 0) { + TIFFError(TIFF2PDF_MODULE, "Integer overflow"); + t2p->t2p_error = T2P_ERR_ERROR; + return; + } + t2p->tiff_datasize = (tmsize_t)k; +} + +/** This function returns the necessary size of a data buffer to contain the raw or uncompressed image data from the input TIFF for a page. */ - void t2p_read_tiff_size(T2P* t2p, TIFF* input){ - uint64* sbc=NULL; -#if defined(JPEG_SUPPORT) || defined (OJPEG_SUPPORT) + uint64_t* sbc=NULL; +#if defined(JPEG_SUPPORT) || defined(OJPEG_SUPPORT) unsigned char* jpt=NULL; tstrip_t i=0; tstrip_t stripcount=0; #endif - uint64 k = 0; + uint64_t k = 0; if(t2p->pdf_transcode == T2P_TRANSCODE_RAW){ -#ifdef CCITT_SUPPORT - if(t2p->pdf_compression == T2P_COMPRESS_G4 ){ - TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc); - if (sbc[0] != (uint64)(tmsize_t)sbc[0]) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - } - t2p->tiff_datasize=(tmsize_t)sbc[0]; - return; - } +#if defined(CCITT_SUPPORT) || defined(ZIP_SUPPORT) +#if defined(CCITT_SUPPORT) && defined(ZIP_SUPPORT) + if(t2p->pdf_compression == T2P_COMPRESS_G4 || t2p->pdf_compression == T2P_COMPRESS_ZIP) +#elif defined(CCITT_SUPPORT) + if(t2p->pdf_compression == T2P_COMPRESS_G4) +#else + if(t2p->pdf_compression == T2P_COMPRESS_ZIP) #endif -#ifdef ZIP_SUPPORT - if(t2p->pdf_compression == T2P_COMPRESS_ZIP){ + { TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc); - if (sbc[0] != (uint64)(tmsize_t)sbc[0]) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - } - t2p->tiff_datasize=(tmsize_t)sbc[0]; + t2p_set_tiff_datasize(t2p, sbc[0]); return; } #endif @@ -2014,7 +2012,7 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){ if(TIFFGetField(input, TIFFTAG_JPEGIFOFFSET, &(t2p->tiff_dataoffset))){ if(t2p->tiff_dataoffset != 0){ if(TIFFGetField(input, TIFFTAG_JPEGIFBYTECOUNT, &(t2p->tiff_datasize))!=0){ - if((uint64)t2p->tiff_datasize < k) { + if((uint64_t)t2p->tiff_datasize < k) { TIFFWarning(TIFF2PDF_MODULE, "Input file %s has short JPEG interchange file byte count", TIFFFileName(input)); @@ -2023,11 +2021,7 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){ k = checkAdd64(k, 6, t2p); k = checkAdd64(k, stripcount, t2p); k = checkAdd64(k, stripcount, t2p); - t2p->tiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - } + t2p_set_tiff_datasize(t2p, k); return; } return; @@ -2043,17 +2037,13 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){ k = checkAdd64(k, stripcount, t2p); k = checkAdd64(k, stripcount, t2p); k = checkAdd64(k, 2048, t2p); - t2p->tiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - } + t2p_set_tiff_datasize(t2p, k); return; } #endif #ifdef JPEG_SUPPORT if(t2p->tiff_compression == COMPRESSION_JPEG) { - uint32 count = 0; + uint32_t count = 0; if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0 ){ if(count > 4){ k += count; @@ -2077,11 +2067,7 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){ } k = checkAdd64(k, 2, t2p); /* use EOI of last strip */ k = checkAdd64(k, 6, t2p); /* for DRI marker of first strip */ - t2p->tiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - } + t2p_set_tiff_datasize(t2p, k); return; } #endif @@ -2104,11 +2090,7 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){ t2p->t2p_error = T2P_ERR_ERROR; } - t2p->tiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - } + t2p_set_tiff_datasize(t2p, k); return; } @@ -2120,12 +2102,12 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){ void t2p_read_tiff_size_tile(T2P* t2p, TIFF* input, ttile_t tile){ - uint64* tbc = NULL; - uint16 edge=0; + uint64_t* tbc = NULL; + uint16_t edge=0; #ifdef JPEG_SUPPORT unsigned char* jpt; #endif - uint64 k; + uint64_t k; edge |= t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile); edge |= t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile); @@ -2152,7 +2134,7 @@ void t2p_read_tiff_size_tile(T2P* t2p, TIFF* input, ttile_t tile){ #endif #ifdef JPEG_SUPPORT if(t2p->tiff_compression==COMPRESSION_JPEG) { - uint32 count = 0; + uint32_t count = 0; if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt)!=0){ if(count > 4){ k = checkAdd64(k, count, t2p); @@ -2161,11 +2143,7 @@ void t2p_read_tiff_size_tile(T2P* t2p, TIFF* input, ttile_t tile){ } } #endif - t2p->tiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - } + t2p_set_tiff_datasize(t2p, k); return; } } @@ -2178,11 +2156,7 @@ void t2p_read_tiff_size_tile(T2P* t2p, TIFF* input, ttile_t tile){ t2p->t2p_error = T2P_ERR_ERROR; } - t2p->tiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - } + t2p_set_tiff_datasize(t2p, k); return; } @@ -2263,18 +2237,18 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ tsize_t sepstripsize=0; #ifdef OJPEG_SUPPORT toff_t inputoffset=0; - uint16 h_samp=1; - uint16 v_samp=1; - uint16 ri=1; - uint32 rows=0; + uint16_t h_samp=1; + uint16_t v_samp=1; + uint16_t ri=1; + uint32_t rows=0; #endif /* ifdef OJPEG_SUPPORT */ #ifdef JPEG_SUPPORT unsigned char* jpt; float* xfloatp; - uint64* sbc; + uint64_t* sbc; unsigned char* stripbuffer; tsize_t striplength=0; - uint32 max_striplength=0; + uint32_t max_striplength=0; #endif /* ifdef JPEG_SUPPORT */ /* Fail if prior error (in particular, can't trust tiff_datasize) */ @@ -2288,9 +2262,9 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ _TIFFmalloc(t2p->tiff_datasize); if (buffer == NULL) { TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for " + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for " "t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2323,8 +2297,8 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ _TIFFmalloc(t2p->tiff_datasize); if(buffer == NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for t2p_readwrite_pdf_image, %s", + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2355,8 +2329,8 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ _TIFFmalloc(t2p->tiff_datasize); if(buffer == NULL) { TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for t2p_readwrite_pdf_image, %s", + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2431,8 +2405,8 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for t2p_readwrite_pdf_image, %s", + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2482,13 +2456,13 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ #endif /* ifdef OJPEG_SUPPORT */ #ifdef JPEG_SUPPORT if(t2p->tiff_compression == COMPRESSION_JPEG) { - uint32 count = 0; + uint32_t count = 0; buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for t2p_readwrite_pdf_image, %s", + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2509,7 +2483,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ _TIFFmalloc(max_striplength); if(stripbuffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %"PRId32" bytes of memory for t2p_readwrite_pdf_image, %s", max_striplength, TIFFFileName(input)); _TIFFfree(buffer); @@ -2557,8 +2531,8 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for t2p_readwrite_pdf_image, %s", + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2574,7 +2548,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ TIFFmin(stripsize, t2p->tiff_datasize - bufferoffset)); if(read==-1){ TIFFError(TIFF2PDF_MODULE, - "Error on decoding strip %u of %s", + "Error on decoding strip %"PRIu32" of %s", i, TIFFFileName(input)); _TIFFfree(buffer); @@ -2595,8 +2569,8 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for t2p_readwrite_pdf_image, %s", + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2605,8 +2579,8 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ samplebuffer = (unsigned char*) _TIFFmalloc(stripsize); if(samplebuffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for t2p_readwrite_pdf_image, %s", + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; _TIFFfree(buffer); @@ -2622,7 +2596,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ TIFFmin(sepstripsize, stripsize - samplebufferoffset)); if(read==-1){ TIFFError(TIFF2PDF_MODULE, - "Error on decoding strip %u of %s", + "Error on decoding strip %"PRIu32" of %s", i + j*stripcount, TIFFFileName(input)); _TIFFfree(buffer); @@ -2645,8 +2619,8 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for t2p_readwrite_pdf_image, %s", + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2662,7 +2636,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ TIFFmin(stripsize, t2p->tiff_datasize - bufferoffset)); if(read==-1){ TIFFError(TIFF2PDF_MODULE, - "Error on decoding strip %u of %s", + "Error on decoding strip %"PRIu32" of %s", i, TIFFFileName(input)); _TIFFfree(samplebuffer); @@ -2680,8 +2654,8 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ t2p->tiff_datasize * t2p->tiff_samplesperpixel); if(samplebuffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for t2p_readwrite_pdf_image, %s", + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; _TIFFfree(buffer); @@ -2711,8 +2685,8 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ t2p->tiff_width*t2p->tiff_length*4); if(samplebuffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for t2p_readwrite_pdf_image, %s", + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; _TIFFfree(buffer); @@ -2724,7 +2698,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ input, t2p->tiff_width, t2p->tiff_length, - (uint32*)buffer, + (uint32_t*)buffer, ORIENTATION_TOPLEFT, 0)){ TIFFError(TIFF2PDF_MODULE, @@ -2770,7 +2744,7 @@ dataready: #ifdef JPEG_SUPPORT case T2P_COMPRESS_JPEG: if(t2p->tiff_photometric==PHOTOMETRIC_YCBCR) { - uint16 hor = 0, ver = 0; + uint16_t hor = 0, ver = 0; if (TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &hor, &ver) !=0 ) { if(hor != 0 && ver != 0){ TIFFSetField(output, TIFFTAG_YCBCRSUBSAMPLING, hor, ver); @@ -2872,14 +2846,14 @@ dataready: tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_t tile){ - uint16 edge=0; + uint16_t edge=0; tsize_t written=0; unsigned char* buffer=NULL; tsize_t bufferoffset=0; unsigned char* samplebuffer=NULL; tsize_t samplebufferoffset=0; tsize_t read=0; - uint16 i=0; + uint16_t i=0; ttile_t tilecount=0; /* tsize_t tilesize=0; */ ttile_t septilecount=0; @@ -2887,7 +2861,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ #ifdef JPEG_SUPPORT unsigned char* jpt; float* xfloatp; - uint32 xuint32=0; + uint32_t xuint32=0; #endif /* Fail if prior error (in particular, can't trust tiff_datasize) */ @@ -2908,9 +2882,9 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ buffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory " + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory " "for t2p_readwrite_pdf_image_tile, %s", - (unsigned long) t2p->tiff_datasize, + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2936,9 +2910,9 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ buffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory " + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory " "for t2p_readwrite_pdf_image_tile, %s", - (unsigned long) t2p->tiff_datasize, + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2973,9 +2947,9 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ buffer=(unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory " + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory " "for t2p_readwrite_pdf_image, %s", - (unsigned long) t2p->tiff_datasize, + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -3017,13 +2991,13 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ #ifdef JPEG_SUPPORT if(t2p->tiff_compression == COMPRESSION_JPEG){ unsigned char table_end[2]; - uint32 count = 0; + uint32_t count = 0; buffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate " TIFF_SIZE_FORMAT " bytes of memory " + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory " "for t2p_readwrite_pdf_image_tile, %s", - (TIFF_SIZE_T) t2p->tiff_datasize, + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -3070,9 +3044,9 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory for " + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory for " "t2p_readwrite_pdf_image_tile, %s", - (unsigned long) t2p->tiff_datasize, + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -3086,7 +3060,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ t2p->tiff_datasize); if(read==-1){ TIFFError(TIFF2PDF_MODULE, - "Error on decoding tile %u of %s", + "Error on decoding tile %"PRIu32" of %s", tile, TIFFFileName(input)); _TIFFfree(buffer); @@ -3104,9 +3078,9 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory " + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory " "for t2p_readwrite_pdf_image_tile, %s", - (unsigned long) t2p->tiff_datasize, + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -3115,9 +3089,9 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ samplebuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(samplebuffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory " + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory " "for t2p_readwrite_pdf_image_tile, %s", - (unsigned long) t2p->tiff_datasize, + t2p->tiff_datasize, TIFFFileName(input)); _TIFFfree(buffer); t2p->t2p_error = T2P_ERR_ERROR; @@ -3133,7 +3107,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ septilesize); if(read==-1){ TIFFError(TIFF2PDF_MODULE, - "Error on decoding tile %u of %s", + "Error on decoding tile %"PRIu32" of %s", tile + i*tilecount, TIFFFileName(input)); _TIFFfree(samplebuffer); @@ -3156,9 +3130,9 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %lu bytes of memory " + "Can't allocate %"TIFF_SSIZE_FORMAT" bytes of memory " "for t2p_readwrite_pdf_image_tile, %s", - (unsigned long) t2p->tiff_datasize, + t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -3171,7 +3145,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ t2p->tiff_datasize); if(read==-1){ TIFFError(TIFF2PDF_MODULE, - "Error on decoding tile %u of %s", + "Error on decoding tile %"PRIu32" of %s", tile, TIFFFileName(input)); _TIFFfree(buffer); @@ -3212,7 +3186,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ } if(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile) != 0){ - if ((uint64)t2p->tiff_datasize < (uint64)TIFFTileRowSize(input) * (uint64)t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength) { + if ((uint64_t)t2p->tiff_datasize < (uint64_t)TIFFTileRowSize(input) * (uint64_t)t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength) { /* we don't know how to handle PLANARCONFIG_CONTIG, PHOTOMETRIC_YCBCR with 3 samples per pixel */ TIFFWarning( TIFF2PDF_MODULE, @@ -3277,7 +3251,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ #ifdef JPEG_SUPPORT case T2P_COMPRESS_JPEG: if (t2p->tiff_photometric==PHOTOMETRIC_YCBCR) { - uint16 hor = 0, ver = 0; + uint16_t hor = 0, ver = 0; if (TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &hor, &ver)!=0) { if (hor != 0 && ver != 0) { TIFFSetField(output, TIFFTAG_YCBCRSUBSAMPLING, hor, ver); @@ -3331,8 +3305,8 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ if (TIFFStripSize(output) > t2p->tiff_datasize) { TIFFError(TIFF2PDF_MODULE, - "Size mismatch input %ld, output %ld", - t2p->tiff_datasize, TIFFStripSize(output)); + "Size mismatch input %" PRId64 ", output %" PRId64, + (int64_t) t2p->tiff_datasize, (int64_t) TIFFStripSize(output)); _TIFFfree(buffer); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -3360,26 +3334,26 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ #ifdef OJPEG_SUPPORT int t2p_process_ojpeg_tables(T2P* t2p, TIFF* input){ - uint16 proc=0; + uint16_t proc=0; void* q; - uint32 q_length=0; + uint32_t q_length=0; void* dc; - uint32 dc_length=0; + uint32_t dc_length=0; void* ac; - uint32 ac_length=0; - uint16* lp; - uint16* pt; - uint16 h_samp=1; - uint16 v_samp=1; + uint32_t ac_length=0; + uint16_t* lp; + uint16_t* pt; + uint16_t h_samp=1; + uint16_t v_samp=1; unsigned char* ojpegdata; - uint16 table_count; - uint32 offset_table; - uint32 offset_ms_l; - uint32 code_count; - uint32 i=0; - uint32 dest=0; - uint16 ri=0; - uint32 rows=0; + uint16_t table_count; + uint32_t offset_table; + uint32_t offset_ms_l; + uint32_t code_count; + uint32_t i=0; + uint32_t dest=0; + uint16_t ri=0; + uint32_t rows=0; if(!TIFFGetField(input, TIFFTAG_JPEGPROC, &proc)){ TIFFError(TIFF2PDF_MODULE, @@ -3452,7 +3426,7 @@ int t2p_process_ojpeg_tables(T2P* t2p, TIFF* input){ if(t2p->pdf_ojpegdata == NULL){ TIFFError(TIFF2PDF_MODULE, "Can't allocate %u bytes of memory for t2p_process_ojpeg_tables, %s", - 2048, + 2048u, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -3605,21 +3579,21 @@ int t2p_process_ojpeg_tables(T2P* t2p, TIFF* input){ #ifdef JPEG_SUPPORT int t2p_process_jpeg_strip( - unsigned char* strip, - tsize_t* striplength, - unsigned char* buffer, - tsize_t buffersize, - tsize_t* bufferoffset, - tstrip_t no, - uint32 height){ + unsigned char* strip, + tsize_t* striplength, + unsigned char* buffer, + tsize_t buffersize, + tsize_t* bufferoffset, + tstrip_t no, + uint32_t height){ tsize_t i=0; while (i < *striplength) { tsize_t datalen; - uint16 ri; - uint16 v_samp; - uint16 h_samp; + uint16_t ri; + uint16_t v_samp; + uint16_t h_samp; int j; int ncomp; @@ -3667,7 +3641,7 @@ int t2p_process_jpeg_strip( if( *bufferoffset + 11 + 3*(ncomp-1) >= buffersize ) return(0); for(j=0;j<ncomp;j++){ - uint16 samp = buffer[*bufferoffset+11+(3*j)]; + uint16_t samp = buffer[*bufferoffset + 11 + (3 * j)]; if( (samp>>4) > h_samp) h_samp = (samp>>4); if( (samp & 0x0f) > v_samp) @@ -3675,12 +3649,12 @@ int t2p_process_jpeg_strip( } v_samp*=8; h_samp*=8; - ri=((( ((uint16)(buffer[*bufferoffset+5])<<8) | - (uint16)(buffer[*bufferoffset+6]) )+v_samp-1)/ - v_samp); - ri*=((( ((uint16)(buffer[*bufferoffset+7])<<8) | - (uint16)(buffer[*bufferoffset+8]) )+h_samp-1)/ - h_samp); + ri=(((((uint16_t)(buffer[*bufferoffset + 5]) << 8) | + (uint16_t)(buffer[*bufferoffset + 6]) ) + v_samp - 1) / + v_samp); + ri*=(((((uint16_t)(buffer[*bufferoffset + 7]) << 8) | + (uint16_t)(buffer[*bufferoffset + 8]) ) + h_samp - 1) / + h_samp); buffer[*bufferoffset+5]= (unsigned char) ((height>>8) & 0xff); buffer[*bufferoffset+6]= @@ -3739,13 +3713,13 @@ int t2p_process_jpeg_strip( tilelength buffer of samples. */ void t2p_tile_collapse_left( - tdata_t buffer, - tsize_t scanwidth, - uint32 tilewidth, - uint32 edgetilewidth, - uint32 tilelength){ + tdata_t buffer, + tsize_t scanwidth, + uint32_t tilewidth, + uint32_t edgetilewidth, + uint32_t tilelength){ - uint32 i; + uint32_t i; tsize_t edgescanwidth=0; edgescanwidth = (scanwidth * edgetilewidth + (tilewidth - 1))/ tilewidth; @@ -3804,12 +3778,12 @@ tsize_t t2p_sample_planar_separate_to_contig( tsize_t t2p_sample_realize_palette(T2P* t2p, unsigned char* buffer){ - uint32 sample_count=0; - uint16 component_count=0; - uint32 palette_offset=0; - uint32 sample_offset=0; - uint32 i=0; - uint32 j=0; + uint32_t sample_count=0; + uint16_t component_count=0; + uint32_t palette_offset=0; + uint32_t sample_offset=0; + uint32_t i=0; + uint32_t j=0; size_t data_size; sample_count=t2p->tiff_width*t2p->tiff_length; component_count=t2p->tiff_samplesperpixel; @@ -3844,13 +3818,13 @@ tsize_t t2p_sample_realize_palette(T2P* t2p, unsigned char* buffer){ into RGB interleaved data, discarding A. */ -tsize_t t2p_sample_abgr_to_rgb(tdata_t data, uint32 samplecount) +tsize_t t2p_sample_abgr_to_rgb(tdata_t data, uint32_t samplecount) { - uint32 i=0; - uint32 sample=0; + uint32_t i=0; + uint32_t sample=0; for(i=0;i<samplecount;i++){ - sample=((uint32*)data)[i]; + sample=((uint32_t*)data)[i]; ((char*)data)[i*3]= (char) (sample & 0xff); ((char*)data)[i*3+1]= (char) ((sample>>8) & 0xff); ((char*)data)[i*3+2]= (char) ((sample>>16) & 0xff); @@ -3865,18 +3839,18 @@ tsize_t t2p_sample_abgr_to_rgb(tdata_t data, uint32 samplecount) */ tsize_t -t2p_sample_rgbaa_to_rgb(tdata_t data, uint32 samplecount) +t2p_sample_rgbaa_to_rgb(tdata_t data, uint32_t samplecount) { - uint32 i; + uint32_t i; /* For the 3 first samples, there is overlap between source and * destination, so use memmove(). * See http://bugzilla.maptools.org/show_bug.cgi?id=2577 */ for(i = 0; i < 3 && i < samplecount; i++) - memmove((uint8*)data + i * 3, (uint8*)data + i * 4, 3); + memmove((uint8_t*)data + i * 3, (uint8_t*)data + i * 4, 3); for(; i < samplecount; i++) - memcpy((uint8*)data + i * 3, (uint8*)data + i * 4, 3); + memcpy((uint8_t*)data + i * 3, (uint8_t*)data + i * 4, 3); return(i * 3); } @@ -3887,18 +3861,18 @@ t2p_sample_rgbaa_to_rgb(tdata_t data, uint32 samplecount) */ tsize_t -t2p_sample_rgba_to_rgb(tdata_t data, uint32 samplecount) +t2p_sample_rgba_to_rgb(tdata_t data, uint32_t samplecount) { - uint32 i = 0; - uint32 sample = 0; - uint8 alpha = 0; + uint32_t i = 0; + uint32_t sample = 0; + uint8_t alpha = 0; for (i = 0; i < samplecount; i++) { - sample=((uint32*)data)[i]; - alpha=(uint8)((255 - ((sample >> 24) & 0xff))); - ((uint8 *)data)[i * 3] = (uint8) ((sample >> 16) & 0xff) + alpha; - ((uint8 *)data)[i * 3 + 1] = (uint8) ((sample >> 8) & 0xff) + alpha; - ((uint8 *)data)[i * 3 + 2] = (uint8) (sample & 0xff) + alpha; + sample=((uint32_t*)data)[i]; + alpha=(uint8_t)((255 - ((sample >> 24) & 0xff))); + ((uint8_t *)data)[i * 3] = (uint8_t) ((sample >> 16) & 0xff) + alpha; + ((uint8_t *)data)[i * 3 + 1] = (uint8_t) ((sample >> 8) & 0xff) + alpha; + ((uint8_t *)data)[i * 3 + 2] = (uint8_t) (sample & 0xff) + alpha; } return (i * 3); @@ -3909,9 +3883,9 @@ t2p_sample_rgba_to_rgb(tdata_t data, uint32 samplecount) to unsigned. */ -tsize_t t2p_sample_lab_signed_to_unsigned(tdata_t buffer, uint32 samplecount){ +tsize_t t2p_sample_lab_signed_to_unsigned(tdata_t buffer, uint32_t samplecount){ - uint32 i=0; + uint32_t i=0; for(i=0;i<samplecount;i++){ if( (((unsigned char*)buffer)[(i*3)+1] & 0x80) !=0){ @@ -3941,9 +3915,9 @@ tsize_t t2p_write_pdf_header(T2P* t2p, TIFF* output){ char buffer[16]; int buflen=0; - buflen = snprintf(buffer, sizeof(buffer), "%%PDF-%u.%u ", - t2p->pdf_majorversion&0xff, - t2p->pdf_minorversion&0xff); + buflen = snprintf(buffer, sizeof(buffer), "%%PDF-%"PRIu16".%"PRIu16" ", + (uint16_t) (t2p->pdf_majorversion&0xff), + (uint16_t) (t2p->pdf_minorversion&0xff)); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t)"\n%\342\343\317\323\n", 7); @@ -3955,13 +3929,13 @@ tsize_t t2p_write_pdf_header(T2P* t2p, TIFF* output){ This function writes the beginning of a PDF object to output. */ -tsize_t t2p_write_pdf_obj_start(uint32 number, TIFF* output){ +tsize_t t2p_write_pdf_obj_start(uint32_t number, TIFF* output){ tsize_t written=0; char buffer[32]; int buflen=0; - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)number); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, number); check_snprintf_ret((T2P*)NULL, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen ); written += t2pWriteFile(output, (tdata_t) " 0 obj\n", 7); @@ -3989,9 +3963,9 @@ tsize_t t2p_write_pdf_obj_end(TIFF* output){ tsize_t t2p_write_pdf_name(const unsigned char* name, TIFF* output){ tsize_t written=0; - uint32 i=0; + uint32_t i=0; char buffer[64]; - uint16 nextchar=0; + uint16_t nextchar=0; size_t namelen=0; namelen = strlen((char *)name); @@ -4087,7 +4061,7 @@ tsize_t t2p_write_pdf_name(const unsigned char* name, TIFF* output){ tsize_t t2p_write_pdf_string(const char* pdfstr, TIFF* output) { tsize_t written = 0; - uint32 i = 0; + uint32_t i = 0; char buffer[64]; size_t len = 0; @@ -4177,7 +4151,7 @@ tsize_t t2p_write_pdf_stream_end(TIFF* output){ This function writes a stream dictionary for a PDF stream to output. */ -tsize_t t2p_write_pdf_stream_dict(tsize_t len, uint32 number, TIFF* output){ +tsize_t t2p_write_pdf_stream_dict(tsize_t len, uint32_t number, TIFF* output){ tsize_t written=0; char buffer[32]; @@ -4187,7 +4161,7 @@ tsize_t t2p_write_pdf_stream_dict(tsize_t len, uint32 number, TIFF* output){ if(len!=0){ written += t2p_write_pdf_stream_length(len, output); } else { - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)number); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, number); check_snprintf_ret((T2P*)NULL, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6); @@ -4232,7 +4206,7 @@ tsize_t t2p_write_pdf_stream_length(tsize_t len, TIFF* output){ char buffer[32]; int buflen=0; - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)len); + buflen=snprintf(buffer, sizeof(buffer), "%"TIFF_SSIZE_FORMAT, len); check_snprintf_ret((T2P*)NULL, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "\n", 1); @@ -4253,7 +4227,7 @@ tsize_t t2p_write_pdf_catalog(T2P* t2p, TIFF* output) written += t2pWriteFile(output, (tdata_t)"<< \n/Type /Catalog \n/Pages ", 27); - buflen = snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_pages); + buflen = snprintf(buffer, sizeof(buffer), "%"PRIu32, t2p->pdf_pages); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, TIFFmin((size_t)buflen, sizeof(buffer) - 1)); @@ -4442,7 +4416,7 @@ tsize_t t2p_write_pdf_pages(T2P* t2p, TIFF* output) } } written += t2pWriteFile(output, (tdata_t) "] \n/Count ", 10); - buflen=snprintf(buffer, sizeof(buffer), "%d", t2p->tiff_pagecount); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu16, t2p->tiff_pagecount); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " \n>> \n", 6); @@ -4454,7 +4428,7 @@ tsize_t t2p_write_pdf_pages(T2P* t2p, TIFF* output) This function writes a PDF Page structure to output. */ -tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){ +tsize_t t2p_write_pdf_page(uint32_t object, T2P* t2p, TIFF* output){ unsigned int i=0; tsize_t written=0; @@ -4462,7 +4436,7 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){ int buflen=0; written += t2pWriteFile(output, (tdata_t) "<<\n/Type /Page \n/Parent ", 24); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_pages); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, t2p->pdf_pages); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6); @@ -4484,7 +4458,7 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){ written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "] \n", 3); written += t2pWriteFile(output, (tdata_t) "/Contents ", 10); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)(object + 1)); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, object + 1u); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6); @@ -4493,16 +4467,16 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){ written += t2pWriteFile(output, (tdata_t) "/XObject <<\n", 12); for(i=0;i<t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount;i++){ written += t2pWriteFile(output, (tdata_t) "/Im", 3); - buflen = snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_page+1); + buflen = snprintf(buffer, sizeof(buffer), "%"PRIu16, (uint16_t)(t2p->pdf_page+1u)); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "_", 1); - buflen = snprintf(buffer, sizeof(buffer), "%u", i+1); + buflen = snprintf(buffer, sizeof(buffer), "%u", i+1u); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " ", 1); - buflen = snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)(object+3+(2*i)+t2p->tiff_pages[t2p->pdf_page].page_extra)); + buflen = snprintf(buffer, sizeof(buffer), "%"PRIu32, + object+3u+(2u*i)+t2p->tiff_pages[t2p->pdf_page].page_extra); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); @@ -4514,12 +4488,12 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){ } else { written += t2pWriteFile(output, (tdata_t) "/XObject <<\n", 12); written += t2pWriteFile(output, (tdata_t) "/Im", 3); - buflen = snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_page+1); + buflen = snprintf(buffer, sizeof(buffer), "%"PRIu16, (uint16_t)(t2p->pdf_page+1u)); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " ", 1); - buflen = snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)(object+3+(2*i)+t2p->tiff_pages[t2p->pdf_page].page_extra)); + buflen = snprintf(buffer, sizeof(buffer), "%"PRIu32, + object+3u+(2u*i)+t2p->tiff_pages[t2p->pdf_page].page_extra); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); @@ -4528,8 +4502,8 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){ if(t2p->tiff_transferfunctioncount != 0) { written += t2pWriteFile(output, (tdata_t) "/ExtGState <<", 13); t2pWriteFile(output, (tdata_t) "/GS1 ", 5); - buflen = snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)(object + 3)); + buflen = snprintf(buffer, sizeof(buffer), "%"PRIu32, + object + 3u); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); @@ -4557,14 +4531,14 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){ void t2p_compose_pdf_page(T2P* t2p){ - uint32 i=0; - uint32 i2=0; + uint32_t i=0; + uint32_t i2=0; T2P_TILE* tiles=NULL; T2P_BOX* boxp=NULL; - uint32 tilecountx=0; - uint32 tilecounty=0; - uint32 tilewidth=0; - uint32 tilelength=0; + uint32_t tilecountx=0; + uint32_t tilecounty=0; + uint32_t tilewidth=0; + uint32_t tilelength=0; int istiled=0; float f=0; float width_ratio=0; @@ -4763,7 +4737,7 @@ void t2p_compose_pdf_page(T2P* t2p){ return; } -void t2p_compose_pdf_page_orient(T2P_BOX* boxp, uint16 orientation){ +void t2p_compose_pdf_page_orient(T2P_BOX* boxp, uint16_t orientation){ float m1[9]; float f=0.0; @@ -4838,7 +4812,7 @@ void t2p_compose_pdf_page_orient(T2P_BOX* boxp, uint16 orientation){ return; } -void t2p_compose_pdf_page_orient_flip(T2P_BOX* boxp, uint16 orientation){ +void t2p_compose_pdf_page_orient_flip(T2P_BOX* boxp, uint16_t orientation){ float m1[9]; float f=0.0; @@ -4912,7 +4886,7 @@ tsize_t t2p_write_pdf_page_content_stream(T2P* t2p, TIFF* output){ for(i=0;i<t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount; i++){ box=t2p->tiff_tiles[t2p->pdf_page].tiles_tiles[i].tile_box; buflen=snprintf(buffer, sizeof(buffer), - "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d_%ld Do Q\n", + "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%"PRIu16"_%"PRIu32" Do Q\n", t2p->tiff_transferfunctioncount?"/GS1 gs ":"", box.mat[0], box.mat[1], @@ -4920,15 +4894,15 @@ tsize_t t2p_write_pdf_page_content_stream(T2P* t2p, TIFF* output){ box.mat[4], box.mat[6], box.mat[7], - t2p->pdf_page + 1, - (long)(i + 1)); + (uint16_t)(t2p->pdf_page + 1u), + i + 1u); check_snprintf_ret(t2p, buflen, buffer); written += t2p_write_pdf_stream(buffer, buflen, output); } } else { box=t2p->pdf_imagebox; buflen=snprintf(buffer, sizeof(buffer), - "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d Do Q\n", + "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%"PRIu16" Do Q\n", t2p->tiff_transferfunctioncount?"/GS1 gs ":"", box.mat[0], box.mat[1], @@ -4936,7 +4910,7 @@ tsize_t t2p_write_pdf_page_content_stream(T2P* t2p, TIFF* output){ box.mat[4], box.mat[6], box.mat[7], - t2p->pdf_page+1); + (uint16_t)(t2p->pdf_page+1u)); check_snprintf_ret(t2p, buflen, buffer); written += t2p_write_pdf_stream(buffer, buflen, output); } @@ -4960,45 +4934,45 @@ tsize_t t2p_write_pdf_xobject_stream_dict(ttile_t tile, written += t2pWriteFile(output, (tdata_t) "/Type /XObject \n/Subtype /Image \n/Name /Im", 42); - buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_page+1); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu16, (uint16_t)(t2p->pdf_page+1u)); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); if(tile != 0){ written += t2pWriteFile(output, (tdata_t) "_", 1); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)tile); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, tile); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } written += t2pWriteFile(output, (tdata_t) "\n/Width ", 8); if(tile==0){ - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->tiff_width); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, t2p->tiff_width); } else { if(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)!=0){ - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth); } else { - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth); } } check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "\n/Height ", 9); if(tile==0){ - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->tiff_length); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, t2p->tiff_length); } else { if(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)!=0){ - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength); } else { - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength); } } check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "\n/BitsPerComponent ", 19); - buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->tiff_bitspersample); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu16, t2p->tiff_bitspersample); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "\n/ColorSpace ", 13); @@ -5053,11 +5027,11 @@ tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){ t2p->pdf_colorspace ^= T2P_CS_PALETTE; written += t2p_write_pdf_xobject_cs(t2p, output); t2p->pdf_colorspace |= T2P_CS_PALETTE; - buflen=snprintf(buffer, sizeof(buffer), "%u", (0x0001 << t2p->tiff_bitspersample)-1 ); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, (uint32_t)(0x1u << t2p->tiff_bitspersample)-1u ); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " ", 1); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_palettecs ); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, t2p->pdf_palettecs ); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ]\n", 7); @@ -5116,25 +5090,25 @@ tsize_t t2p_write_pdf_transfer(T2P* t2p, TIFF* output){ written += t2pWriteFile(output, (tdata_t) "<< /Type /ExtGState \n/TR ", 25); if(t2p->tiff_transferfunctioncount == 1){ - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)(t2p->pdf_xrefcount + 1)); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->pdf_xrefcount + 1u); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); } else { written += t2pWriteFile(output, (tdata_t) "[ ", 2); - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)(t2p->pdf_xrefcount + 1)); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->pdf_xrefcount + 1u); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)(t2p->pdf_xrefcount + 2)); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->pdf_xrefcount + 2u); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)(t2p->pdf_xrefcount + 3)); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->pdf_xrefcount + 3u); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); @@ -5146,7 +5120,7 @@ tsize_t t2p_write_pdf_transfer(T2P* t2p, TIFF* output){ return(written); } -tsize_t t2p_write_pdf_transfer_dict(T2P* t2p, TIFF* output, uint16 i){ +tsize_t t2p_write_pdf_transfer_dict(T2P* t2p, TIFF* output, uint16_t i){ tsize_t written=0; char buffer[32]; @@ -5156,7 +5130,7 @@ tsize_t t2p_write_pdf_transfer_dict(T2P* t2p, TIFF* output, uint16 i){ written += t2pWriteFile(output, (tdata_t) "/FunctionType 0 \n", 17); written += t2pWriteFile(output, (tdata_t) "/Domain [0.0 1.0] \n", 19); written += t2pWriteFile(output, (tdata_t) "/Range [0.0 1.0] \n", 18); - buflen=snprintf(buffer, sizeof(buffer), "/Size [%u] \n", (1<<t2p->tiff_bitspersample)); + buflen=snprintf(buffer, sizeof(buffer), "/Size [%"PRIu16"] \n", (uint16_t)(1u<<t2p->tiff_bitspersample)); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "/BitsPerSample 16 \n", 19); @@ -5165,7 +5139,7 @@ tsize_t t2p_write_pdf_transfer_dict(T2P* t2p, TIFF* output, uint16 i){ return(written); } -tsize_t t2p_write_pdf_transfer_stream(T2P* t2p, TIFF* output, uint16 i){ +tsize_t t2p_write_pdf_transfer_stream(T2P* t2p, TIFF* output, uint16_t i){ tsize_t written=0; @@ -5283,7 +5257,7 @@ tsize_t t2p_write_pdf_xobject_icccs(T2P* t2p, TIFF* output){ int buflen=0; written += t2pWriteFile(output, (tdata_t) "[/ICCBased ", 11); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_icccs); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, t2p->pdf_icccs); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R] \n", 7); @@ -5298,7 +5272,7 @@ tsize_t t2p_write_pdf_xobject_icccs_dict(T2P* t2p, TIFF* output){ int buflen=0; written += t2pWriteFile(output, (tdata_t) "/N ", 3); - buflen=snprintf(buffer, sizeof(buffer), "%u \n", t2p->tiff_samplesperpixel); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu16" \n", t2p->tiff_samplesperpixel); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "/Alternate ", 11); @@ -5379,39 +5353,39 @@ tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t tile, T2P* t2p, TIFF* output written += t2pWriteFile(output, (tdata_t) "<< /K -1 ", 9); if(tile==0){ written += t2pWriteFile(output, (tdata_t) "/Columns ", 9); - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)t2p->tiff_width); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->tiff_width); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " /Rows ", 7); - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)t2p->tiff_length); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->tiff_length); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } else { if(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)==0){ written += t2pWriteFile(output, (tdata_t) "/Columns ", 9); - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } else { written += t2pWriteFile(output, (tdata_t) "/Columns ", 9); - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } if(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)==0){ written += t2pWriteFile(output, (tdata_t) " /Rows ", 7); - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } else { written += t2pWriteFile(output, (tdata_t) " /Rows ", 7); - buflen=snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } @@ -5438,20 +5412,20 @@ tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t tile, T2P* t2p, TIFF* output if(t2p->pdf_compressionquality%100){ written += t2pWriteFile(output, (tdata_t) "/DecodeParms ", 13); written += t2pWriteFile(output, (tdata_t) "<< /Predictor ", 14); - buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_compressionquality%100); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu16, (uint16_t)(t2p->pdf_compressionquality % 100u)); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " /Columns ", 10); - buflen = snprintf(buffer, sizeof(buffer), "%lu", - (unsigned long)t2p->tiff_width); + buflen = snprintf(buffer, sizeof(buffer), "%"PRIu32, + t2p->tiff_width); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " /Colors ", 9); - buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->tiff_samplesperpixel); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu16, t2p->tiff_samplesperpixel); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " /BitsPerComponent ", 19); - buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->tiff_bitspersample); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu16, t2p->tiff_bitspersample); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) ">>\n", 3); @@ -5474,10 +5448,10 @@ tsize_t t2p_write_pdf_xreftable(T2P* t2p, TIFF* output){ tsize_t written=0; char buffer[64]; int buflen=0; - uint32 i=0; + uint32_t i=0; written += t2pWriteFile(output, (tdata_t) "xref\n0 ", 7); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)(t2p->pdf_xrefcount + 1)); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, t2p->pdf_xrefcount + 1u); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " \n0000000000 65535 f \n", 22); @@ -5506,15 +5480,15 @@ tsize_t t2p_write_pdf_trailer(T2P* t2p, TIFF* output) snprintf(t2p->pdf_fileid + i, 9, "%.8X", rand()); written += t2pWriteFile(output, (tdata_t) "trailer\n<<\n/Size ", 17); - buflen = snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)(t2p->pdf_xrefcount+1)); + buflen = snprintf(buffer, sizeof(buffer), "%"PRIu32, t2p->pdf_xrefcount+1u); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "\n/Root ", 7); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_catalog); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, t2p->pdf_catalog); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R \n/Info ", 12); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_info); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, t2p->pdf_info); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R \n/ID[<", 11); @@ -5524,7 +5498,7 @@ tsize_t t2p_write_pdf_trailer(T2P* t2p, TIFF* output) written += t2pWriteFile(output, (tdata_t) t2p->pdf_fileid, sizeof(t2p->pdf_fileid) - 1); written += t2pWriteFile(output, (tdata_t) ">]\n>>\nstartxref\n", 16); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_startxref); + buflen=snprintf(buffer, sizeof(buffer), "%"PRIu32, t2p->pdf_startxref); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "\n%%EOF\n", 7); @@ -5577,16 +5551,16 @@ tsize_t t2p_write_pdf(T2P* t2p, TIFF* input, TIFF* output){ tsize_t written=0; ttile_t i2=0; tsize_t streamlen=0; - uint16 i=0; + uint16_t i=0; t2p_read_tiff_init(t2p, input); if(t2p->t2p_error!=T2P_ERR_OK){return(0);} - t2p->pdf_xrefoffsets= (uint32*) _TIFFmalloc(TIFFSafeMultiply(tmsize_t,t2p->pdf_xrefcount,sizeof(uint32)) ); + t2p->pdf_xrefoffsets= (uint32_t*) _TIFFmalloc(TIFFSafeMultiply(tmsize_t, t2p->pdf_xrefcount, sizeof(uint32_t)) ); if(t2p->pdf_xrefoffsets==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_write_pdf", - (unsigned int) (t2p->pdf_xrefcount * sizeof(uint32)) ); + "Can't allocate %"TIFF_SIZE_FORMAT" bytes of memory for t2p_write_pdf", + sizeof(uint32_t) * t2p->pdf_xrefcount); t2p->t2p_error = T2P_ERR_ERROR; return(written); } @@ -5694,8 +5668,8 @@ tsize_t t2p_write_pdf(T2P* t2p, TIFF* input, TIFF* output){ t2p_read_tiff_size_tile(t2p, input, i2); if (t2p->tiff_maxdatasize && (t2p->tiff_datasize > t2p->tiff_maxdatasize)) { TIFFError(TIFF2PDF_MODULE, - "Allocation of " TIFF_UINT64_FORMAT " bytes is forbidden. Limit is " TIFF_UINT64_FORMAT ". Use -m option to change limit", - (uint64)t2p->tiff_datasize, (uint64)t2p->tiff_maxdatasize); + "Allocation of %" PRIu64 " bytes is forbidden. Limit is %" PRIu64 ". Use -m option to change limit", + (uint64_t)t2p->tiff_datasize, (uint64_t)t2p->tiff_maxdatasize); t2p->t2p_error = T2P_ERR_ERROR; return (0); } @@ -5724,8 +5698,8 @@ tsize_t t2p_write_pdf(T2P* t2p, TIFF* input, TIFF* output){ t2p_read_tiff_size(t2p, input); if (t2p->tiff_maxdatasize && (t2p->tiff_datasize > t2p->tiff_maxdatasize)) { TIFFError(TIFF2PDF_MODULE, - "Allocation of " TIFF_UINT64_FORMAT " bytes is forbidden. Limit is " TIFF_UINT64_FORMAT ". Use -m option to change limit", - (uint64)t2p->tiff_datasize, (uint64)t2p->tiff_maxdatasize); + "Allocation of %" PRIu64 " bytes is forbidden. Limit is %" PRIu64 ". Use -m option to change limit", + (uint64_t)t2p->tiff_datasize, (uint64_t)t2p->tiff_maxdatasize); t2p->t2p_error = T2P_ERR_ERROR; return (0); } diff --git a/tiff/tools/tiff2ps.c b/tiff/tools/tiff2ps.c index 4ed5eba2..a598ede7 100644 --- a/tiff/tools/tiff2ps.c +++ b/tiff/tools/tiff2ps.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> /* for atof */ @@ -34,10 +35,6 @@ # include <unistd.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffio.h" #ifndef EXIT_SUCCESS @@ -64,7 +61,7 @@ * warning messages for incompatible command line options. * Add new command line options to specify PageOrientation * Document Structuring Comment for landscape or portrait - * and code to determine the values from ouput width and height + * and code to determine the values from output width and height * if not specified on the command line. * Add new command line option to specify document creator * as an alterntive to the string "tiff2ps" following model @@ -85,7 +82,7 @@ * * Identified incompatible options and returned errors, eg * -i for imagemask operator is only available for Level2 or - * Level3 Postscript in the current implmentation since there + * Level3 Postscript in the current implementation since there * is a difference in the way the operands are called for Level1 * and there is no function to provide the Level1 version. * -H was not handled properly if -h and/or -w were specified. @@ -96,7 +93,7 @@ * Conversion of TIFF to Postscript with optional rotations * of 90, 180, 270, or auto degrees counterclockwise * Conversion of TIFF to Postscript with entire image scaled - * to maximum of values spedified with -h or -w while + * to maximum of values specified with -h or -w while * maintaining aspect ratio. Same rotations apply. * Conversion of TIFF to Postscript with clipping of output * viewport to height specified with -H, producing multiple @@ -173,9 +170,6 @@ #define EXP_ASCII85ENCODER -/* - * NB: this code assumes uint32 works with printf's %l[ud]. - */ #ifndef TRUE #define TRUE 1 #define FALSE 0 @@ -206,7 +200,7 @@ char *title = NULL; /* optional document title string */ char *creator = NULL; /* optional document creator string */ char pageOrientation[12]; /* set optional PageOrientation DSC to Landscape or Portrait */ int useImagemask = FALSE; /* Use imagemask instead of image operator */ -uint16 res_unit = 0; /* Resolution units: 2 - inches, 3 - cm */ +uint16_t res_unit = 0; /* Resolution units: 2 - inches, 3 - cm */ /* * ASCII85 Encoding Support. @@ -216,14 +210,14 @@ int ascii85count; int ascii85breaklen; int TIFF2PS(FILE*, TIFF*, double, double, double, double, int); -void PSpage(FILE*, TIFF*, uint32, uint32); -void PSColorContigPreamble(FILE*, uint32, uint32, int); -void PSColorSeparatePreamble(FILE*, uint32, uint32, int); -void PSDataColorContig(FILE*, TIFF*, uint32, uint32, int); -void PSDataColorSeparate(FILE*, TIFF*, uint32, uint32, int); -void PSDataPalette(FILE*, TIFF*, uint32, uint32); -void PSDataBW(FILE*, TIFF*, uint32, uint32); -void PSRawDataBW(FILE*, TIFF*, uint32, uint32); +void PSpage(FILE*, TIFF*, uint32_t, uint32_t); +void PSColorContigPreamble(FILE*, uint32_t, uint32_t, int); +void PSColorSeparatePreamble(FILE*, uint32_t, uint32_t, int); +void PSDataColorContig(FILE*, TIFF*, uint32_t, uint32_t, int); +void PSDataColorSeparate(FILE*, TIFF*, uint32_t, uint32_t, int); +void PSDataPalette(FILE*, TIFF*, uint32_t, uint32_t); +void PSDataBW(FILE*, TIFF*, uint32_t, uint32_t); +void PSRawDataBW(FILE*, TIFF*, uint32_t, uint32_t); void Ascii85Init(void); void Ascii85Put(unsigned char code, FILE* fd); void Ascii85Flush(FILE* fd); @@ -242,7 +236,7 @@ int exportMaskedImage(FILE *, double, double, double, double, int, int, double, double, double, int, int); #if defined( EXP_ASCII85ENCODER) -tsize_t Ascii85EncodeBlock( uint8 * ascii85_p, unsigned f_eod, const uint8 * raw_p, tsize_t raw_l ); +tsize_t Ascii85EncodeBlock(uint8_t * ascii85_p, unsigned f_eod, const uint8_t * raw_p, tsize_t raw_l ); #endif static void usage(int); @@ -253,8 +247,8 @@ static void usage(int); static void* limitMalloc(tmsize_t s) { if (maxMalloc && (s > maxMalloc)) { - fprintf(stderr, "MemoryLimitError: allocation of " TIFF_UINT64_FORMAT " bytes is forbidden. Limit is " TIFF_UINT64_FORMAT ".\n", - (uint64)s, (uint64)maxMalloc); + fprintf(stderr, "MemoryLimitError: allocation of %" TIFF_SSIZE_FORMAT " bytes is forbidden. Limit is %" TIFF_SSIZE_FORMAT ".\n", + s, maxMalloc); fprintf(stderr, " use -M option to change limit.\n"); return NULL; } @@ -270,7 +264,7 @@ main(int argc, char* argv[]) double leftmargin = 0; double pageWidth = 0; double pageHeight = 0; - uint32 diroff = 0; + uint32_t diroff = 0; #if !HAVE_DECL_OPTARG extern char *optarg; extern int optind; @@ -336,7 +330,7 @@ main(int argc, char* argv[]) case '6': case '7': case '8': - case '9': diroff = (uint32) strtoul(optarg, NULL, 0); + case '9': diroff = (uint32_t) strtoul(optarg, NULL, 0); break; default: TIFFError ("-o", "Offset must be a numeric value."); exit (EXIT_FAILURE); @@ -438,7 +432,7 @@ main(int argc, char* argv[]) { if ((level2 == FALSE) && (level3 == FALSE)) { - TIFFError ("-m "," imagemask operator requres Postscript Level2 or Level3"); + TIFFError ("-m "," imagemask operator requires Postscript Level2 or Level3"); exit (EXIT_FAILURE); } } @@ -522,12 +516,12 @@ main(int argc, char* argv[]) return (EXIT_SUCCESS); } -static uint16 samplesperpixel; -static uint16 bitspersample; -static uint16 planarconfiguration; -static uint16 photometric; -static uint16 compression; -static uint16 extrasamples; +static uint16_t samplesperpixel; +static uint16_t bitspersample; +static uint16_t planarconfiguration; +static uint16_t photometric; +static uint16_t compression; +static uint16_t extrasamples; static int alpha; static int @@ -552,7 +546,7 @@ checkImage(TIFF* tif) case PHOTOMETRIC_RGB: if (alpha && bitspersample != 8) { TIFFError(filename, - "Can not handle %d-bit/sample RGB image with alpha", + "Can not handle %"PRIu16"-bit/sample RGB image with alpha", bitspersample); return (0); } @@ -583,7 +577,7 @@ checkImage(TIFF* tif) /* fall through... */ default: TIFFError(filename, - "Can not handle image with PhotometricInterpretation=%d", + "Can not handle image with PhotometricInterpretation=%"PRIu16, photometric); return (0); } @@ -593,7 +587,7 @@ checkImage(TIFF* tif) case 16: break; default: - TIFFError(filename, "Can not handle %d-bit/sample image", + TIFFError(filename, "Can not handle %"PRIu16"-bit/sample image", bitspersample); return (0); } @@ -605,7 +599,7 @@ checkImage(TIFF* tif) #define PS_UNIT_SIZE 72.0F #define PSUNITS(npix,res) ((npix) * (PS_UNIT_SIZE / (res))) -static char RGBcolorimage[] = "\ +static const char RGBcolorimage[] = "\ /bwproc {\n\ rgbproc\n\ dup length 3 idiv string 0 3 0\n\ @@ -635,10 +629,10 @@ static char RGBcolorimage[] = "\ * It is claimed to be part of some future revision of the EPS spec. */ static void -PhotoshopBanner(FILE* fd, uint32 w, uint32 h, int bs, int nc, char* startline) +PhotoshopBanner(FILE* fd, uint32_t w, uint32_t h, int bs, int nc, const char* startline) { - fprintf(fd, "%%ImageData: %ld %ld %d %d 0 %d 2 \"", - (long) w, (long) h, bitspersample, nc, bs); + fprintf(fd, "%%ImageData: %"PRIu32" %"PRIu32" %"PRIu16" %d 0 %d 2 \"", + w, h, bitspersample, nc, bs); fprintf(fd, startline, nc); fprintf(fd, "\"\n"); } @@ -651,7 +645,7 @@ PhotoshopBanner(FILE* fd, uint32 w, uint32 h, int bs, int nc, char* startline) * pprh : image height in PS units (72 dpi) */ static void -setupPageState(TIFF* tif, uint32* pw, uint32* ph, double* pprw, double* pprh) +setupPageState(TIFF* tif, uint32_t* pw, uint32_t* ph, double* pprw, double* pprh) { float xres = 0.0F, yres = 0.0F; @@ -702,7 +696,7 @@ setupPageState(TIFF* tif, uint32* pw, uint32* ph, double* pprw, double* pprh) static int isCCITTCompression(TIFF* tif) { - uint16 compress; + uint16_t compress; TIFFGetField(tif, TIFFTAG_COMPRESSION, &compress); return (compress == COMPRESSION_CCITTFAX3 || compress == COMPRESSION_CCITTFAX4 || @@ -712,8 +706,8 @@ isCCITTCompression(TIFF* tif) static tsize_t tf_bytesperrow; static tsize_t ps_bytesperrow; -static uint32 tf_rowsperstrip; -static uint32 tf_numberstrips; +static uint32_t tf_rowsperstrip; +static uint32_t tf_numberstrips; static char *hex = "0123456789abcdef"; /* @@ -1130,7 +1124,7 @@ int psPageSize (FILE * fd, int rotation, double pgwidth, double pgheight, fprintf (fd, "%%%%PageOrientation: %s\n", pageOrientation); else fprintf (fd, "%%%%PageOrientation: %s\n", (new_width > new_height) ? "Landscape" : "Portrait"); - fprintf (fd, "%%%%PageBoundingBox: 0 0 %ld %ld\n", (long)new_width, (long)new_height); + fprintf (fd, "%%%%PageBoundingBox: 0 0 %"PRId32" %"PRId32"\n", (int32_t)new_width, (int32_t)new_height); fprintf (fd, "1 dict begin /PageSize [ %f %f ] def currentdict end setpagedevice\n", new_width, new_height); } @@ -1142,7 +1136,7 @@ int psPageSize (FILE * fd, int rotation, double pgwidth, double pgheight, fprintf (fd, "%%%%PageOrientation: %s\n", pageOrientation); else fprintf (fd, "%%%%PageOrientation: %s\n", (pswidth > psheight) ? "Landscape" : "Portrait"); - fprintf (fd, "%%%%PageBoundingBox: 0 0 %ld %ld\n", (long)pswidth, (long)psheight); + fprintf (fd, "%%%%PageBoundingBox: 0 0 %"PRId32" %"PRId32"\n", (int32_t)pswidth, (int32_t)psheight); fprintf(fd, "1 dict begin /PageSize [ %f %f ] def currentdict end setpagedevice\n", pswidth, psheight); } @@ -1152,7 +1146,7 @@ int psPageSize (FILE * fd, int rotation, double pgwidth, double pgheight, fprintf (fd, "%%%%PageOrientation: %s\n", pageOrientation); else fprintf (fd, "%%%%PageOrientation: %s\n", (reqwidth > reqheight) ? "Landscape" : "Portrait"); - fprintf (fd, "%%%%PageBoundingBox: 0 0 %ld %ld\n", (long)reqwidth, (long)reqheight); + fprintf (fd, "%%%%PageBoundingBox: 0 0 %"PRId32" %"PRId32"\n", (int32_t)reqwidth, (int32_t)reqheight); fprintf(fd, "1 dict begin /PageSize [ %f %f ] def currentdict end setpagedevice\n", reqwidth, reqheight); } @@ -1174,7 +1168,7 @@ int psPageSize (FILE * fd, int rotation, double pgwidth, double pgheight, fprintf (fd, "%%%%PageOrientation: %s\n", pageOrientation); else fprintf (fd, "%%%%PageOrientation: %s\n", (new_width > new_height) ? "Landscape" : "Portrait"); - fprintf (fd, "%%%%PageBoundingBox: 0 0 %ld %ld\n", (long)new_width, (long)new_height); + fprintf (fd, "%%%%PageBoundingBox: 0 0 %"PRId32" %"PRId32"\n", (int32_t)new_width, (int32_t)new_height); fprintf (fd, "1 dict begin /PageSize [ %f %f ] def currentdict end setpagedevice\n", new_width, new_height); } @@ -1186,7 +1180,7 @@ int psPageSize (FILE * fd, int rotation, double pgwidth, double pgheight, fprintf (fd, "%%%%PageOrientation: %s\n", pageOrientation); else fprintf (fd, "%%%%PageOrientation: %s\n", (psheight > pswidth) ? "Landscape" : "Portrait"); - fprintf (fd, "%%%%PageBoundingBox: 0 0 %ld %ld\n", (long)psheight, (long)pswidth); + fprintf (fd, "%%%%PageBoundingBox: 0 0 %"PRId32" %"PRId32"\n", (int32_t)psheight, (int32_t)pswidth); fprintf(fd, "1 dict begin /PageSize [ %f %f ] def currentdict end setpagedevice\n", psheight, pswidth); } @@ -1196,7 +1190,7 @@ int psPageSize (FILE * fd, int rotation, double pgwidth, double pgheight, fprintf (fd, "%%%%PageOrientation: %s\n", pageOrientation); else fprintf (fd, "%%%%PageOrientation: %s\n", (reqwidth > reqheight) ? "Landscape" : "Portrait"); - fprintf (fd, "%%%%PageBoundingBox: 0 0 %ld %ld\n", (long)reqwidth, (long)reqheight); + fprintf (fd, "%%%%PageBoundingBox: 0 0 %"PRId32" %"PRId32"\n", (int32_t)reqwidth, (int32_t)reqheight); fprintf(fd, "1 dict begin /PageSize [ %f %f ] def currentdict end setpagedevice\n", reqwidth, reqheight); } @@ -1312,19 +1306,19 @@ int psStart(FILE *fd, int npages, int auto_rotate, int *rotation, double *scale, if (((maxsource == pswidth) && (maxtarget != reqwidth)) || ((maxsource == psheight) && (maxtarget != reqheight))) - { /* optimal orientaion does not match input orientation */ + { /* optimal orientation does not match input orientation */ *rotation = 90; xscale = (reqwidth - left_offset)/psheight; yscale = (reqheight - bottom_offset)/pswidth; } - else /* optimal orientaion matches input orientation */ + else /* optimal orientation matches input orientation */ { xscale = (reqwidth - left_offset)/pswidth; yscale = (reqheight - bottom_offset)/psheight; } *scale = (xscale < yscale) ? xscale : yscale; - /* Do not scale image beyound original size */ + /* Do not scale image beyond original size */ if (*scale > 1.0) *scale = 1.0; @@ -1515,15 +1509,15 @@ int get_viewport (double pgwidth, double pgheight, double pswidth, double psheig int TIFF2PS(FILE* fd, TIFF* tif, double pgwidth, double pgheight, double lm, double bm, int center) { - uint32 pixwidth = 0, pixheight = 0; /* Image width and height in pixels */ + uint32_t pixwidth = 0, pixheight = 0; /* Image width and height in pixels */ double ox = 0.0, oy = 0.0; /* Offset from current Postscript origin */ double pswidth, psheight; /* Original raw image width and height in points */ double view_width, view_height; /* Viewport width and height in points */ double scale = 1.0; double left_offset = lm * PS_UNIT_SIZE; double bottom_offset = bm * PS_UNIT_SIZE; - uint32 subfiletype; - uint16* sampleinfo; + uint32_t subfiletype; + uint16_t* sampleinfo; static int npages = 0; if (!TIFFGetField(tif, TIFFTAG_XPOSITION, &ox)) @@ -1594,7 +1588,7 @@ int TIFF2PS(FILE* fd, TIFF* tif, double pgwidth, double pgheight, double lm, dou { if (pgwidth != 0 || pgheight != 0) { - /* User did not specify a maxium page height or width using -H or -W flag + /* User did not specify a maximum page height or width using -H or -W flag * but did use -h or -w flag to scale to a specific size page. */ npages++; @@ -1653,7 +1647,7 @@ int TIFF2PS(FILE* fd, TIFF* tif, double pgwidth, double pgheight, double lm, dou return(npages); } -static char DuplexPreamble[] = "\ +static const char DuplexPreamble[] = "\ %%BeginFeature: *Duplex True\n\ systemdict begin\n\ /languagelevel where { pop languagelevel } { 1 } ifelse\n\ @@ -1664,7 +1658,7 @@ end\n\ %%EndFeature\n\ "; -static char TumblePreamble[] = "\ +static const char TumblePreamble[] = "\ %%BeginFeature: *Tumble True\n\ systemdict begin\n\ /languagelevel where { pop languagelevel } { 1 } ifelse\n\ @@ -1675,7 +1669,7 @@ end\n\ %%EndFeature\n\ "; -static char AvoidDeadZonePreamble[] = "\ +static const char AvoidDeadZonePreamble[] = "\ gsave newpath clippath pathbbox grestore\n\ 4 2 roll 2 copy translate\n\ exch 3 1 roll sub 3 1 roll sub exch\n\ @@ -1699,9 +1693,9 @@ PSHead(FILE *fd, double pagewidth, double pageheight, double xoff, double yoff) /* NB: should use PageBoundingBox for each page instead of BoundingBox * * PageBoundingBox DSC added in PSPageSize function, R Nolde 09-01-2010 */ - fprintf(fd, "%%%%Origin: %ld %ld\n", (long) xoff, (long) yoff); - fprintf(fd, "%%%%BoundingBox: 0 0 %ld %ld\n", - (long) ceil(pagewidth), (long) ceil(pageheight)); + fprintf(fd, "%%%%Origin: %"PRId32" %"PRId32"\n", (int32_t) xoff, (int32_t) yoff); + fprintf(fd, "%%%%BoundingBox: 0 0 %"PRId32" %"PRId32"\n", + (int32_t) ceil(pagewidth), (int32_t) ceil(pageheight)); fprintf(fd, "%%%%LanguageLevel: %d\n", (level3 ? 3 : (level2 ? 2 : 1))); if (generateEPSF == TRUE) @@ -1732,7 +1726,7 @@ PSTail(FILE *fd, int npages) } static int -checkcmap(TIFF* tif, int n, uint16* r, uint16* g, uint16* b) +checkcmap(TIFF* tif, int n, uint16_t* r, uint16_t* g, uint16_t* b) { (void) tif; while (n-- > 0) @@ -1745,7 +1739,7 @@ checkcmap(TIFF* tif, int n, uint16* r, uint16* g, uint16* b) static void PS_Lvl2colorspace(FILE* fd, TIFF* tif) { - uint16 *rmap, *gmap, *bmap; + uint16_t *rmap, *gmap, *bmap; int i, num_colors; const char * colorspace_p; @@ -1765,7 +1759,7 @@ PS_Lvl2colorspace(FILE* fd, TIFF* tif) /* * Set up PostScript Level 2 colorspace according to - * section 4.8 in the PostScript refenence manual. + * section 4.8 in the PostScript reference manual. */ fputs("% PostScript Level 2 only.\n", fd); if (photometric != PHOTOMETRIC_PALETTE) { @@ -1811,7 +1805,7 @@ PS_Lvl2colorspace(FILE* fd, TIFF* tif) Ascii85Put((unsigned char)bmap[i], fd); } else { fputs((i % 8) ? " " : "\n ", fd); - fprintf(fd, "%02x%02x%02x", + fprintf(fd, "%02"PRIx16"%02"PRIx16"%02"PRIx16"", rmap[i], gmap[i], bmap[i]); } } @@ -1823,21 +1817,21 @@ PS_Lvl2colorspace(FILE* fd, TIFF* tif) } static int -PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) +PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32_t w, uint32_t h) { int use_rawdata; - uint32 tile_width, tile_height; - uint16 predictor, minsamplevalue, maxsamplevalue; - uint32 repeat_count; + uint32_t tile_width, tile_height; + uint16_t predictor, minsamplevalue, maxsamplevalue; + uint32_t repeat_count; char im_h[64], im_x[64], im_y[64]; - char * imageOp = "image"; + const char * imageOp = "image"; if ( useImagemask && (bitspersample == 1) ) imageOp = "imagemask"; (void)strcpy(im_x, "0"); - (void)snprintf(im_y, sizeof(im_y), "%lu", (long) h); - (void)snprintf(im_h, sizeof(im_h), "%lu", (long) h); + (void)snprintf(im_y, sizeof(im_y), "%"PRIu32, h); + (void)snprintf(im_h, sizeof(im_h), "%"PRIu32, h); tile_width = w; tile_height = h; if (TIFFIsTiled(tif)) { @@ -1858,7 +1852,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) } if (tile_height < h) { fputs("/im_y 0 def\n", fd); - (void)snprintf(im_y, sizeof(im_y), "%lu im_y sub", (unsigned long) h); + (void)snprintf(im_y, sizeof(im_y), "%"PRIu32" im_y sub", h); } } else { repeat_count = tf_numberstrips; @@ -1867,10 +1861,9 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) tile_height = h; if (repeat_count > 1) { fputs("/im_y 0 def\n", fd); - fprintf(fd, "/im_h %lu def\n", - (unsigned long) tile_height); + fprintf(fd, "/im_h %"PRIu32" def\n", tile_height); (void)strcpy(im_h, "im_h"); - (void)snprintf(im_y, sizeof(im_y), "%lu im_y sub", (unsigned long) h); + (void)snprintf(im_y, sizeof(im_y), "%"PRIu32" im_y sub", h); } } @@ -1880,7 +1873,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) fputs("{ % exec\n", fd); if (repeat_count > 1) - fprintf(fd, "%u { %% repeat\n", repeat_count); + fprintf(fd, "%"PRIu32" { %% repeat\n", repeat_count); /* * Output filter options and image dictionary. @@ -1890,7 +1883,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) fd); fputs(" <<\n", fd); fputs(" /ImageType 1\n", fd); - fprintf(fd, " /Width %lu\n", (unsigned long) tile_width); + fprintf(fd, " /Width %"PRIu32"\n", tile_width); /* * Workaround for some software that may crash when last strip * of image contains fewer number of scanlines than specified @@ -1902,15 +1895,15 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) * one-stripped image). */ if (TIFFIsTiled(tif) || tf_numberstrips == 1) - fprintf(fd, " /Height %lu\n", (unsigned long) tile_height); + fprintf(fd, " /Height %"PRIu32"\n", tile_height); else fprintf(fd, " /Height im_h\n"); if (planarconfiguration == PLANARCONFIG_SEPARATE && samplesperpixel > 1) fputs(" /MultipleDataSources true\n", fd); - fprintf(fd, " /ImageMatrix [ %lu 0 0 %ld %s %s ]\n", - (unsigned long) w, - (long)h, im_x, im_y); - fprintf(fd, " /BitsPerComponent %d\n", bitspersample); + fprintf(fd, " /ImageMatrix [ %"PRIu32" 0 0 %"PRId32" %s %s ]\n", + w, - (int32_t)h, im_x, im_y); + fprintf(fd, " /BitsPerComponent %"PRIu16"\n", bitspersample); fprintf(fd, " /Interpolate %s\n", interpolate ? "true" : "false"); switch (samplesperpixel - extrasamples) { @@ -1927,7 +1920,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) case COMPRESSION_CCITTFAX4: /* * Manage inverting with /Blackis1 flag - * since there migth be uncompressed parts + * since there might be uncompressed parts */ fputs(" /Decode [0 1]\n", fd); break; @@ -1944,7 +1937,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) &minsamplevalue); TIFFGetFieldDefaulted(tif, TIFFTAG_MAXSAMPLEVALUE, &maxsamplevalue); - fprintf(fd, " /Decode [%u %u]\n", + fprintf(fd, " /Decode [%"PRIu16" %"PRIu16"]\n", minsamplevalue, maxsamplevalue); break; default: @@ -1996,7 +1989,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) case COMPRESSION_CCITTFAX4: /* 4: CCITT Group 4 fax encoding */ fputs("\n\t<<\n", fd); if (compression == COMPRESSION_CCITTFAX3) { - uint32 g3_options; + uint32_t g3_options; fputs("\t /EndOfLine true\n", fd); fputs("\t /EndOfBlock false\n", fd); @@ -2011,7 +2004,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) fputs("\t /EncodedByteAlign true\n", fd); } if (compression == COMPRESSION_CCITTFAX4) { - uint32 g4_options; + uint32_t g4_options; fputs("\t /K -1\n", fd); TIFFGetFieldDefaulted(tif, TIFFTAG_GROUP4OPTIONS, @@ -2020,8 +2013,8 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) fputs("\t /Uncompressed true\n", fd); } if (!(tile_width == w && w == 1728U)) - fprintf(fd, "\t /Columns %lu\n", - (unsigned long) tile_width); + fprintf(fd, "\t /Columns %"PRIu32"\n", + tile_width); fprintf(fd, "\t /Rows %s\n", im_h); if (compression == COMPRESSION_CCITTRLE || compression == COMPRESSION_CCITTRLEW) { @@ -2036,11 +2029,11 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) TIFFGetFieldDefaulted(tif, TIFFTAG_PREDICTOR, &predictor); if (predictor == 2) { fputs("\n\t<<\n", fd); - fprintf(fd, "\t /Predictor %u\n", predictor); - fprintf(fd, "\t /Columns %lu\n", - (unsigned long) tile_width); - fprintf(fd, "\t /Colors %u\n", samplesperpixel); - fprintf(fd, "\t /BitsPerComponent %u\n", + fprintf(fd, "\t /Predictor %"PRIu16"\n", predictor); + fprintf(fd, "\t /Columns %"PRIu32"\n", + tile_width); + fprintf(fd, "\t /Colors %"PRIu16"\n", samplesperpixel); + fprintf(fd, "\t /BitsPerComponent %"PRIu16"\n", bitspersample); fputs("\t>>", fd); } @@ -2053,11 +2046,11 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) if (predictor > 1) { fprintf(fd, "\t %% PostScript Level 3 only."); fputs("\n\t<<\n", fd); - fprintf(fd, "\t /Predictor %u\n", predictor); - fprintf(fd, "\t /Columns %lu\n", - (unsigned long) tile_width); - fprintf(fd, "\t /Colors %u\n", samplesperpixel); - fprintf(fd, "\t /BitsPerComponent %u\n", + fprintf(fd, "\t /Predictor %"PRIu16"\n", predictor); + fprintf(fd, "\t /Columns %"PRIu32"\n", + tile_width); + fprintf(fd, "\t /Colors %"PRIu16"\n", samplesperpixel); + fprintf(fd, "\t /BitsPerComponent %"PRIu16"\n", bitspersample); fputs("\t>>", fd); } @@ -2101,7 +2094,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) } if (planarconfiguration == PLANARCONFIG_SEPARATE && samplesperpixel > 1) { - uint16 i; + uint16_t i; /* * NOTE: This code does not work yet... @@ -2116,28 +2109,28 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) fputs(" im_stream status { im_stream flushfile } if\n", fd); if (repeat_count > 1) { if (tile_width < w) { - fprintf(fd, " /im_x im_x %lu add def\n", - (unsigned long) tile_width); + fprintf(fd, " /im_x im_x %"PRIu32" add def\n", + tile_width); if (tile_height < h) { - fprintf(fd, " im_x %lu ge {\n", - (unsigned long) w); + fprintf(fd, " im_x %"PRIu32" ge {\n", + w); fputs(" /im_x 0 def\n", fd); - fprintf(fd, " /im_y im_y %lu add def\n", - (unsigned long) tile_height); + fprintf(fd, " /im_y im_y %"PRIu32" add def\n", + tile_height); fputs(" } if\n", fd); } } if (tile_height < h) { if (tile_width >= w) { - fprintf(fd, " /im_y im_y %lu add def\n", - (unsigned long) tile_height); + fprintf(fd, " /im_y im_y %"PRIu32" add def\n", + tile_height); if (!TIFFIsTiled(tif)) { - fprintf(fd, " /im_h %lu im_y sub", - (unsigned long) h); - fprintf(fd, " dup %lu gt { pop", - (unsigned long) tile_height); - fprintf(fd, " %lu } if def\n", - (unsigned long) tile_height); + fprintf(fd, " /im_h %"PRIu32" im_y sub", + h); + fprintf(fd, " dup %"PRIu32" gt { pop", + tile_height); + fprintf(fd, " %"PRIu32" } if def\n", + tile_height); } } } @@ -2174,18 +2167,18 @@ PS_FlipBytes(unsigned char* buf, tsize_t count) #define MAXLINE 36 int -PS_Lvl2page(FILE* fd, TIFF* tif, uint32 w, uint32 h) +PS_Lvl2page(FILE* fd, TIFF* tif, uint32_t w, uint32_t h) { - uint16 fillorder; + uint16_t fillorder; int use_rawdata, tiled_image, breaklen = MAXLINE; - uint32 chunk_no, num_chunks; - uint64 *bc; + uint32_t chunk_no, num_chunks; + uint64_t *bc; unsigned char *buf_data, *cp; tsize_t chunk_size, byte_count; #if defined( EXP_ASCII85ENCODER ) tsize_t ascii85_l; /* Length, in bytes, of ascii85_p[] data */ - uint8 * ascii85_p = 0; /* Holds ASCII85 encoded data */ + uint8_t * ascii85_p = 0; /* Holds ASCII85 encoded data */ #endif PS_Lvl2colorspace(fd, tif); @@ -2219,8 +2212,8 @@ PS_Lvl2page(FILE* fd, TIFF* tif, uint32 w, uint32 h) } buf_data = (unsigned char *)limitMalloc(chunk_size); if (!buf_data) { - TIFFError(filename, "Can't alloc %lu bytes for %s.", - (unsigned long) chunk_size, tiled_image ? "tiles" : "strips"); + TIFFError(filename, "Can't alloc %"TIFF_SSIZE_FORMAT" bytes for %s.", + chunk_size, tiled_image ? "tiles" : "strips"); return(FALSE); } @@ -2272,7 +2265,7 @@ PS_Lvl2page(FILE* fd, TIFF* tif, uint32 w, uint32 h) chunk_size); } if (byte_count < 0) { - TIFFError(filename, "Can't read %s %d.", + TIFFError(filename, "Can't read %s %"PRIu32".", tiled_image ? "tile" : "strip", chunk_no); if (ascii85) Ascii85Put('\0', fd); @@ -2363,7 +2356,7 @@ PS_Lvl2page(FILE* fd, TIFF* tif, uint32 w, uint32 h) } void -PSpage(FILE* fd, TIFF* tif, uint32 w, uint32 h) +PSpage(FILE* fd, TIFF* tif, uint32_t w, uint32_t h) { char * imageOp = "image"; @@ -2397,12 +2390,12 @@ PSpage(FILE* fd, TIFF* tif, uint32 w, uint32 h) case PHOTOMETRIC_PALETTE: fprintf(fd, "%s", RGBcolorimage); PhotoshopBanner(fd, w, h, 1, 3, "false 3 colorimage"); - fprintf(fd, "/scanLine %ld string def\n", - (long) ps_bytesperrow * 3L); - fprintf(fd, "%lu %lu 8\n", - (unsigned long) w, (unsigned long) h); - fprintf(fd, "[%lu 0 0 -%lu 0 %lu]\n", - (unsigned long) w, (unsigned long) h, (unsigned long) h); + fprintf(fd, "/scanLine %"TIFF_SSIZE_FORMAT" string def\n", + ps_bytesperrow * 3); + fprintf(fd, "%"PRIu32" %"PRIu32" 8\n", + w, h); + fprintf(fd, "[%"PRIu32" 0 0 -%"PRIu32" 0 %"PRIu32"]\n", + w, h, h); fprintf(fd, "{currentfile scanLine readhexstring pop} bind\n"); fprintf(fd, "false 3 colorimage\n"); PSDataPalette(fd, tif, w, h); @@ -2410,12 +2403,12 @@ PSpage(FILE* fd, TIFF* tif, uint32 w, uint32 h) case PHOTOMETRIC_MINISBLACK: case PHOTOMETRIC_MINISWHITE: PhotoshopBanner(fd, w, h, 1, 1, imageOp); - fprintf(fd, "/scanLine %ld string def\n", - (long) ps_bytesperrow); - fprintf(fd, "%lu %lu %d\n", - (unsigned long) w, (unsigned long) h, bitspersample); - fprintf(fd, "[%lu 0 0 -%lu 0 %lu]\n", - (unsigned long) w, (unsigned long) h, (unsigned long) h); + fprintf(fd, "/scanLine %"TIFF_SSIZE_FORMAT" string def\n", + ps_bytesperrow); + fprintf(fd, "%"PRIu32" %"PRIu32" %"PRIu16"\n", + w, h, bitspersample); + fprintf(fd, "[%"PRIu32" 0 0 -%"PRIu32" 0 %"PRIu32"]\n", + w, h, h); fprintf(fd, "{currentfile scanLine readhexstring pop} bind\n"); fprintf(fd, "%s\n", imageOp); @@ -2426,32 +2419,32 @@ PSpage(FILE* fd, TIFF* tif, uint32 w, uint32 h) } void -PSColorContigPreamble(FILE* fd, uint32 w, uint32 h, int nc) +PSColorContigPreamble(FILE* fd, uint32_t w, uint32_t h, int nc) { ps_bytesperrow = nc * (tf_bytesperrow / samplesperpixel); PhotoshopBanner(fd, w, h, 1, nc, "false %d colorimage"); - fprintf(fd, "/line %ld string def\n", (long) ps_bytesperrow); - fprintf(fd, "%lu %lu %d\n", - (unsigned long) w, (unsigned long) h, bitspersample); - fprintf(fd, "[%lu 0 0 -%lu 0 %lu]\n", - (unsigned long) w, (unsigned long) h, (unsigned long) h); + fprintf(fd, "/line %"TIFF_SSIZE_FORMAT" string def\n", ps_bytesperrow); + fprintf(fd, "%"PRIu32" %"PRIu32" %"PRIu16"\n", + w, h, bitspersample); + fprintf(fd, "[%"PRIu32" 0 0 -%"PRIu32" 0 %"PRIu32"]\n", + w, h, h); fprintf(fd, "{currentfile line readhexstring pop} bind\n"); fprintf(fd, "false %d colorimage\n", nc); } void -PSColorSeparatePreamble(FILE* fd, uint32 w, uint32 h, int nc) +PSColorSeparatePreamble(FILE* fd, uint32_t w, uint32_t h, int nc) { int i; PhotoshopBanner(fd, w, h, ps_bytesperrow, nc, "true %d colorimage"); for (i = 0; i < nc; i++) - fprintf(fd, "/line%d %ld string def\n", - i, (long) ps_bytesperrow); - fprintf(fd, "%lu %lu %d\n", - (unsigned long) w, (unsigned long) h, bitspersample); - fprintf(fd, "[%lu 0 0 -%lu 0 %lu] \n", - (unsigned long) w, (unsigned long) h, (unsigned long) h); + fprintf(fd, "/line%d %"TIFF_SSIZE_FORMAT" string def\n", + i, ps_bytesperrow); + fprintf(fd, "%"PRIu32" %"PRIu32" %"PRIu16"\n", + w, h, bitspersample); + fprintf(fd, "[%"PRIu32" 0 0 -%"PRIu32" 0 %"PRIu32"] \n", + w, h, h); for (i = 0; i < nc; i++) fprintf(fd, "{currentfile line%d readhexstring pop}bind\n", i); fprintf(fd, "true %d colorimage\n", nc); @@ -2462,12 +2455,18 @@ PSColorSeparatePreamble(FILE* fd, uint32 w, uint32 h, int nc) putc('\n', fd); \ (len) = MAXLINE-(howmany); \ } -#define PUTHEX(c,fd) putc(hex[((c)>>4)&0xf],fd); putc(hex[(c)&0xf],fd) + +static inline void +puthex(unsigned int c, FILE *fd) +{ + putc(hex[((c)>>4)&0xf],fd); + putc(hex[(c)&0xf],fd); +} void -PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc) +PSDataColorContig(FILE* fd, TIFF* tif, uint32_t w, uint32_t h, int nc) { - uint32 row; + uint32_t row; int breaklen = MAXLINE, es = samplesperpixel - nc; tsize_t cc; unsigned char *tf_buf; @@ -2476,7 +2475,7 @@ PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc) (void) w; if( es < 0 ) { - TIFFError(filename, "Inconsistent value of es: %d (samplesperpixel=%u, nc=%d)", es, samplesperpixel, nc); + TIFFError(filename, "Inconsistent value of es: %d (samplesperpixel=%"PRIu16", nc=%d)", es, samplesperpixel, nc); return; } tf_buf = (unsigned char *) limitMalloc(tf_bytesperrow); @@ -2509,12 +2508,11 @@ PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc) * where Cback = 1. */ adjust = 255 - cp[nc]; - switch (nc) { - case 4: c = *cp++ + adjust; PUTHEX(c,fd); - case 3: c = *cp++ + adjust; PUTHEX(c,fd); - case 2: c = *cp++ + adjust; PUTHEX(c,fd); - case 1: c = *cp++ + adjust; PUTHEX(c,fd); - } + for (int i = 0; i < nc; ++i) + { + c = *cp++ + adjust; + puthex(c,fd); + } cp += es; } } else { @@ -2523,12 +2521,11 @@ PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc) */ for (cc = 0; (cc + nc) <= tf_bytesperrow; cc += samplesperpixel) { DOBREAK(breaklen, nc, fd); - switch (nc) { - case 4: c = *cp++; PUTHEX(c,fd); - case 3: c = *cp++; PUTHEX(c,fd); - case 2: c = *cp++; PUTHEX(c,fd); - case 1: c = *cp++; PUTHEX(c,fd); - } + for (int i = 0; i < nc; ++i) + { + c = *cp++; + puthex(c,fd); + } cp += es; } } @@ -2537,9 +2534,9 @@ PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc) } void -PSDataColorSeparate(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc) +PSDataColorSeparate(FILE* fd, TIFF* tif, uint32_t w, uint32_t h, int nc) { - uint32 row; + uint32_t row; int breaklen = MAXLINE; tsize_t cc; tsample_t s, maxs; @@ -2556,25 +2553,26 @@ PSDataColorSeparate(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc) for (row = 0; row < h; row++) { for (s = 0; s < maxs; s++) { if (TIFFReadScanline(tif, tf_buf, row, s) < 0) - break; + goto end_loop; for (cp = tf_buf, cc = 0; cc < tf_bytesperrow; cc++) { DOBREAK(breaklen, 1, fd); c = *cp++; - PUTHEX(c,fd); + puthex(c,fd); } } } +end_loop: _TIFFfree((char *) tf_buf); } #define PUTRGBHEX(c,fd) \ - PUTHEX(rmap[c],fd); PUTHEX(gmap[c],fd); PUTHEX(bmap[c],fd) + puthex(rmap[c],fd); puthex(gmap[c],fd); puthex(bmap[c],fd) void -PSDataPalette(FILE* fd, TIFF* tif, uint32 w, uint32 h) +PSDataPalette(FILE* fd, TIFF* tif, uint32_t w, uint32_t h) { - uint16 *rmap, *gmap, *bmap; - uint32 row; + uint16_t *rmap, *gmap, *bmap; + uint32_t row; int breaklen = MAXLINE, nc; tsize_t cc; unsigned char *tf_buf; @@ -2589,7 +2587,7 @@ PSDataPalette(FILE* fd, TIFF* tif, uint32 w, uint32 h) case 8: case 4: case 2: case 1: break; default: - TIFFError(filename, "Depth %d not supported", bitspersample); + TIFFError(filename, "Depth %"PRIu16" not supported", bitspersample); return; } nc = 3 * (8 / bitspersample); @@ -2610,7 +2608,7 @@ PSDataPalette(FILE* fd, TIFF* tif, uint32 w, uint32 h) } for (row = 0; row < h; row++) { if (TIFFReadScanline(tif, tf_buf, row, 0) < 0) - break; + goto end_loop; for (cp = tf_buf, cc = 0; cc < tf_bytesperrow; cc++) { DOBREAK(breaklen, nc, fd); switch (bitspersample) { @@ -2640,11 +2638,12 @@ PSDataPalette(FILE* fd, TIFF* tif, uint32 w, uint32 h) } } } +end_loop: _TIFFfree((char *) tf_buf); } void -PSDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h) +PSDataBW(FILE* fd, TIFF* tif, uint32_t w, uint32_t h) { int breaklen = MAXLINE; unsigned char* tf_buf; @@ -2654,7 +2653,7 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h) #if defined( EXP_ASCII85ENCODER ) tsize_t ascii85_l; /* Length, in bytes, of ascii85_p[] data */ - uint8 *ascii85_p = 0; /* Holds ASCII85 encoded data */ + uint8_t *ascii85_p = 0; /* Holds ASCII85 encoded data */ #endif (void) w; (void) h; @@ -2744,14 +2743,14 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h) * where Cback = 1. */ adjust = 255 - cp[1]; - c = *cp++ + adjust; PUTHEX(c,fd); + c = *cp++ + adjust; puthex(c,fd); cp++, cc--; } } else { while (cc-- > 0) { c = *cp++; DOBREAK(breaklen, 1, fd); - PUTHEX(c, fd); + puthex(c, fd); } } } @@ -2774,20 +2773,20 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h) } void -PSRawDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h) +PSRawDataBW(FILE* fd, TIFF* tif, uint32_t w, uint32_t h) { - uint64 *bc; - uint32 bufsize; + uint64_t *bc; + uint32_t bufsize; int breaklen = MAXLINE; tmsize_t cc; - uint16 fillorder; + uint16_t fillorder; unsigned char *tf_buf; unsigned char *cp, c; tstrip_t s; #if defined( EXP_ASCII85ENCODER ) tsize_t ascii85_l; /* Length, in bytes, of ascii85_p[] data */ - uint8 * ascii85_p = 0; /* Holds ASCII85 encoded data */ + uint8_t * ascii85_p = 0; /* Holds ASCII85 encoded data */ #endif (void) w; (void) h; @@ -2798,11 +2797,11 @@ PSRawDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h) * Find largest strip: */ - bufsize = (uint32) bc[0]; + bufsize = (uint32_t) bc[0]; for ( s = 0; ++s < tf_numberstrips; ) { if ( bc[s] > bufsize ) - bufsize = (uint32) bc[s]; + bufsize = (uint32_t) bc[s]; } tf_buf = (unsigned char*) limitMalloc(bufsize); @@ -2845,7 +2844,7 @@ PSRawDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h) for (cp = tf_buf; cc > 0; cc--) { DOBREAK(breaklen, 1, fd); c = *cp++; - PUTHEX(c, fd); + puthex(c, fd); } fputs(">\n", fd); breaklen = MAXLINE; @@ -2882,12 +2881,12 @@ static char* Ascii85Encode(unsigned char* raw) { static char encoded[6]; - uint32 word; + uint32_t word; word = (((raw[0]<<8)+raw[1])<<16) + (raw[2]<<8) + raw[3]; if (word != 0L) { - uint32 q; - uint16 w1; + uint32_t q; + uint16_t w1; q = word / (85L*85*85*85); /* actually only a byte */ encoded[0] = (char) (q + '!'); @@ -2898,7 +2897,7 @@ Ascii85Encode(unsigned char* raw) word -= q * (85L*85*85); q = word / (85*85); encoded[2] = (char) (q + '!'); - w1 = (uint16) (word - q*(85L*85)); + w1 = (uint16_t) (word - q * (85L * 85)); encoded[3] = (char) ((w1 / 85) + '!'); encoded[4] = (char) ((w1 % 85) + '!'); encoded[5] = '\0'; @@ -2984,13 +2983,13 @@ Ascii85Flush(FILE* fd) * *****************************************************************************/ -tsize_t Ascii85EncodeBlock( uint8 * ascii85_p, unsigned f_eod, const uint8 * raw_p, tsize_t raw_l ) +tsize_t Ascii85EncodeBlock(uint8_t * ascii85_p, unsigned f_eod, const uint8_t * raw_p, tsize_t raw_l ) { char ascii85[5]; /* Encoded 5 tuple */ tsize_t ascii85_l; /* Number of bytes written to ascii85_p[] */ int rc; /* Return code */ - uint32 val32; /* Unencoded 4 tuple */ + uint32_t val32; /* Unencoded 4 tuple */ ascii85_l = 0; /* Nothing written yet */ @@ -3000,10 +2999,10 @@ tsize_t Ascii85EncodeBlock( uint8 * ascii85_p, unsigned f_eod, const uint8 * raw for ( ; raw_l > 3; raw_l -= 4 ) { - val32 = (uint32)*(++raw_p) << 24; - val32 += (uint32)*(++raw_p) << 16; - val32 += (uint32)*(++raw_p) << 8; - val32 += (uint32)*(++raw_p); + val32 = (uint32_t)*(++raw_p) << 24; + val32 += (uint32_t)*(++raw_p) << 16; + val32 += (uint32_t)*(++raw_p) << 8; + val32 += (uint32_t)*(++raw_p); if ( val32 == 0 ) /* Special case */ { @@ -3048,7 +3047,7 @@ tsize_t Ascii85EncodeBlock( uint8 * ascii85_p, unsigned f_eod, const uint8 * raw tsize_t len; /* Output this many bytes */ len = raw_l + 1; - val32 = (uint32)*++raw_p << 24; /* Prime the pump */ + val32 = (uint32_t)*++raw_p << 24; /* Prime the pump */ if ( --raw_l > 0 ) val32 += *(++raw_p) << 16; if ( --raw_l > 0 ) val32 += *(++raw_p) << 8; @@ -3087,52 +3086,50 @@ tsize_t Ascii85EncodeBlock( uint8 * ascii85_p, unsigned f_eod, const uint8 * raw #endif /* EXP_ASCII85ENCODER */ -const char* stuff[] = { -"usage: tiff2ps [options] input.tif ...", -"where options are:", -" -1 generate PostScript Level 1 (default)", -" -2 generate PostScript Level 2", -" -3 generate PostScript Level 3", -" -8 disable use of ASCII85 encoding with PostScript Level 2/3", -" -a convert all directories in file (default is first), Not EPS", -" -b # set the bottom margin to # inches", -" -c center image (-b and -l still add to this)", -" -C name set postscript document creator name", -" -d # set initial directory to # counting from zero", -" -D enable duplex printing (two pages per sheet of paper)", -" -e generate Encapsulated PostScript (EPS) (implies -z)", -" -h # set printed page height to # inches (no default)", -" -w # set printed page width to # inches (no default)", -" -H # split image if height is more than # inches", -" -W # split image if width is more than # inches", -" -L # overLap split images by # inches", -" -i # enable/disable (Nz/0) pixel interpolation (default: enable)", -" -l # set the left margin to # inches", -" -m use \"imagemask\" operator instead of \"image\"", -" -M size set the memory allocation limit in MiB. 0 to disable limit", -" -o # convert directory at file offset # bytes", -" -O file write PostScript to file instead of standard output", -" -p generate regular (non-encapsulated) PostScript", -" -P L or P set optional PageOrientation DSC comment to Landscape or Portrait", -" -r # or auto rotate by 90, 180, 270 degrees or auto", -" -s generate PostScript for a single image", -" -t name set postscript document title. Otherwise the filename is used", -" -T print pages for top edge binding", -" -x override resolution units as centimeters", -" -y override resolution units as inches", -" -z enable printing in the deadzone (only for PostScript Level 2/3)", -NULL -}; +static const char usage_info[] = +"Convert a TIFF image to PostScript\n\n" +"usage: tiff2ps [options] input.tif ...\n" +"where options are:\n" +" -1 generate PostScript Level 1 (default)\n" +" -2 generate PostScript Level 2\n" +" -3 generate PostScript Level 3\n" +" -8 disable use of ASCII85 encoding with PostScript Level 2/3\n" +" -a convert all directories in file (default is first), Not EPS\n" +" -b # set the bottom margin to # inches\n" +" -c center image (-b and -l still add to this)\n" +" -C name set postscript document creator name\n" +" -d # set initial directory to # counting from zero\n" +" -D enable duplex printing (two pages per sheet of paper)\n" +" -e generate Encapsulated PostScript (EPS) (implies -z)\n" +" -h # set printed page height to # inches (no default)\n" +" -w # set printed page width to # inches (no default)\n" +" -H # split image if height is more than # inches\n" +" -W # split image if width is more than # inches\n" +" -L # overLap split images by # inches\n" +" -i # enable/disable (Nz/0) pixel interpolation (default: enable)\n" +" -l # set the left margin to # inches\n" +" -m use \"imagemask\" operator instead of \"image\"\n" +" -M size set the memory allocation limit in MiB. 0 to disable limit\n" +" -o # convert directory at file offset # bytes\n" +" -O file write PostScript to file instead of standard output\n" +" -p generate regular (non-encapsulated) PostScript\n" +" -P L or P set optional PageOrientation DSC comment to Landscape or Portrait\n" +" -r # or auto rotate by 90, 180, 270 degrees or auto\n" +" -s generate PostScript for a single image\n" +" -t name set postscript document title. Otherwise the filename is used\n" +" -T print pages for top edge binding\n" +" -x override resolution units as centimeters\n" +" -y override resolution units as inches\n" +" -z enable printing in the deadzone (only for PostScript Level 2/3)\n" +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } diff --git a/tiff/tools/tiff2rgba.c b/tiff/tools/tiff2rgba.c index 764395f6..7077f946 100644 --- a/tiff/tools/tiff2rgba.c +++ b/tiff/tools/tiff2rgba.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <string.h> @@ -32,10 +33,6 @@ # include <unistd.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffiop.h" #include "tiffio.h" @@ -53,13 +50,13 @@ #ifndef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) #endif -#define roundup(x, y) (howmany(x,y)*((uint32)(y))) +#define roundup(x, y) (howmany(x,y)*((uint32_t)(y))) -uint16 compression = COMPRESSION_PACKBITS; -uint32 rowsperstrip = (uint32) -1; -int process_by_block = 0; /* default is whole image at once */ -int no_alpha = 0; -int bigtiff_output = 0; +static uint16_t compression = COMPRESSION_PACKBITS; +static uint32_t rowsperstrip = (uint32_t) -1; +static int process_by_block = 0; /* default is whole image at once */ +static int no_alpha = 0; +static int bigtiff_output = 0; #define DEFAULT_MAX_MALLOC (256 * 1024 * 1024) /* malloc size limit (in bytes) * disabled when set to 0 */ @@ -122,9 +119,11 @@ main(int argc, char* argv[]) case 'h': usage(EXIT_SUCCESS); /*NOTREACHED*/ + break; case '?': usage(EXIT_FAILURE); /*NOTREACHED*/ + break; } if (argc - optind < 2) @@ -156,13 +155,13 @@ static int cvt_by_tile( TIFF *in, TIFF *out ) { - uint32* raster; /* retrieve RGBA image */ - uint32 width, height; /* image width & height */ - uint32 tile_width, tile_height; - uint32 row, col; - uint32 *wrk_line; + uint32_t* raster; /* retrieve RGBA image */ + uint32_t width, height; /* image width & height */ + uint32_t tile_width, tile_height; + uint32_t row, col; + uint32_t *wrk_line; int ok = 1; - uint32 rastersize, wrk_linesize; + uint32_t rastersize, wrk_linesize; TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width); TIFFGetField(in, TIFFTAG_IMAGELENGTH, &height); @@ -179,13 +178,13 @@ cvt_by_tile( TIFF *in, TIFF *out ) /* * Allocate tile buffer */ - rastersize = tile_width * tile_height * sizeof (uint32); - if (tile_width != (rastersize / tile_height) / sizeof( uint32)) + rastersize = tile_width * tile_height * sizeof (uint32_t); + if (tile_width != (rastersize / tile_height) / sizeof( uint32_t)) { TIFFError(TIFFFileName(in), "Integer overflow when calculating raster buffer"); exit(EXIT_FAILURE); } - raster = (uint32*)_TIFFmalloc(rastersize); + raster = (uint32_t*)_TIFFmalloc(rastersize); if (raster == 0) { TIFFError(TIFFFileName(in), "No space for raster buffer"); return (0); @@ -195,13 +194,13 @@ cvt_by_tile( TIFF *in, TIFF *out ) * Allocate a scanline buffer for swapping during the vertical * mirroring pass. */ - wrk_linesize = tile_width * sizeof (uint32); - if (tile_width != wrk_linesize / sizeof (uint32)) + wrk_linesize = tile_width * sizeof (uint32_t); + if (tile_width != wrk_linesize / sizeof (uint32_t)) { TIFFError(TIFFFileName(in), "Integer overflow when calculating wrk_line buffer"); exit(EXIT_FAILURE); } - wrk_line = (uint32*)_TIFFmalloc(wrk_linesize); + wrk_line = (uint32_t*)_TIFFmalloc(wrk_linesize); if (!wrk_line) { TIFFError(TIFFFileName(in), "No space for raster scanline buffer"); ok = 0; @@ -214,7 +213,7 @@ cvt_by_tile( TIFF *in, TIFF *out ) { for( col = 0; ok && col < width; col += tile_width ) { - uint32 i_row; + uint32_t i_row; /* Read the tile into an RGBA array */ if (!TIFFReadRGBATile(in, col, row, raster)) { @@ -237,7 +236,7 @@ cvt_by_tile( TIFF *in, TIFF *out ) */ for( i_row = 0; i_row < tile_height / 2; i_row++ ) { - uint32 *top_line, *bottom_line; + uint32_t *top_line, *bottom_line; top_line = raster + tile_width * i_row; bottom_line = raster + tile_width * (tile_height-i_row-1); @@ -272,12 +271,12 @@ static int cvt_by_strip( TIFF *in, TIFF *out ) { - uint32* raster; /* retrieve RGBA image */ - uint32 width, height; /* image width & height */ - uint32 row; - uint32 *wrk_line; + uint32_t* raster; /* retrieve RGBA image */ + uint32_t width, height; /* image width & height */ + uint32_t row; + uint32_t *wrk_line; int ok = 1; - uint32 rastersize, wrk_linesize; + uint32_t rastersize, wrk_linesize; TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width); TIFFGetField(in, TIFFTAG_IMAGELENGTH, &height); @@ -292,13 +291,13 @@ cvt_by_strip( TIFF *in, TIFF *out ) /* * Allocate strip buffer */ - rastersize = width * rowsperstrip * sizeof (uint32); - if (width != (rastersize / rowsperstrip) / sizeof( uint32)) + rastersize = width * rowsperstrip * sizeof (uint32_t); + if (width != (rastersize / rowsperstrip) / sizeof( uint32_t)) { TIFFError(TIFFFileName(in), "Integer overflow when calculating raster buffer"); exit(EXIT_FAILURE); } - raster = (uint32*)_TIFFmalloc(rastersize); + raster = (uint32_t*)_TIFFmalloc(rastersize); if (raster == 0) { TIFFError(TIFFFileName(in), "No space for raster buffer"); return (0); @@ -308,13 +307,13 @@ cvt_by_strip( TIFF *in, TIFF *out ) * Allocate a scanline buffer for swapping during the vertical * mirroring pass. */ - wrk_linesize = width * sizeof (uint32); - if (width != wrk_linesize / sizeof (uint32)) + wrk_linesize = width * sizeof (uint32_t); + if (width != wrk_linesize / sizeof (uint32_t)) { TIFFError(TIFFFileName(in), "Integer overflow when calculating wrk_line buffer"); exit(EXIT_FAILURE); } - wrk_line = (uint32*)_TIFFmalloc(wrk_linesize); + wrk_line = (uint32_t*)_TIFFmalloc(wrk_linesize); if (!wrk_line) { TIFFError(TIFFFileName(in), "No space for raster scanline buffer"); ok = 0; @@ -356,7 +355,7 @@ cvt_by_strip( TIFF *in, TIFF *out ) for( i_row = 0; i_row < rows_to_write / 2; i_row++ ) { - uint32 *top_line, *bottom_line; + uint32_t *top_line, *bottom_line; top_line = raster + width * i_row; bottom_line = raster + width * (rows_to_write-i_row-1); @@ -396,9 +395,9 @@ static int cvt_whole_image( TIFF *in, TIFF *out ) { - uint32* raster; /* retrieve RGBA image */ - uint32 width, height; /* image width & height */ - uint32 row; + uint32_t* raster; /* retrieve RGBA image */ + uint32_t width, height; /* image width & height */ + uint32_t row; size_t pixel_count; TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width); @@ -408,24 +407,24 @@ cvt_whole_image( TIFF *in, TIFF *out ) /* XXX: Check the integer overflow. */ if (!width || !height || pixel_count / width != height) { TIFFError(TIFFFileName(in), - "Malformed input file; can't allocate buffer for raster of %lux%lu size", - (unsigned long)width, (unsigned long)height); + "Malformed input file; can't allocate buffer for raster of %"PRIu32"x%"PRIu32" size", + width, height); return 0; } - if (maxMalloc != 0 && (tmsize_t)pixel_count * (tmsize_t)sizeof(uint32) > maxMalloc) { + if (maxMalloc != 0 && (tmsize_t)pixel_count * (tmsize_t)sizeof(uint32_t) > maxMalloc) { TIFFError(TIFFFileName(in), - "Raster size " TIFF_UINT64_FORMAT " over memory limit (" TIFF_UINT64_FORMAT "), try -b option.", - (uint64)pixel_count * sizeof(uint32), (uint64)maxMalloc); + "Raster size %"TIFF_SIZE_FORMAT" over memory limit (%" TIFF_SSIZE_FORMAT "), try -b option.", + pixel_count * sizeof(uint32_t), maxMalloc); return 0; } rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip); TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip); - raster = (uint32*)_TIFFCheckMalloc(in, pixel_count, sizeof(uint32), "raster buffer"); + raster = (uint32_t*)_TIFFCheckMalloc(in, pixel_count, sizeof(uint32_t), "raster buffer"); if (raster == 0) { - TIFFError(TIFFFileName(in), "Failed to allocate buffer (%lu elements of %lu each)", - (unsigned long)pixel_count, (unsigned long)sizeof(uint32)); + TIFFError(TIFFFileName(in), "Failed to allocate buffer (%"TIFF_SIZE_FORMAT" elements of %"TIFF_SIZE_FORMAT" each)", + pixel_count, sizeof(uint32_t)); return (0); } @@ -505,12 +504,12 @@ cvt_whole_image( TIFF *in, TIFF *out ) static int tiffcvt(TIFF* in, TIFF* out) { - uint32 width, height; /* image width & height */ - uint16 shortv; + uint32_t width, height; /* image width & height */ + uint16_t shortv; float floatv; char *stringv; - uint32 longv; - uint16 v[1]; + uint32_t longv; + uint16_t v[1]; TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width); TIFFGetField(in, TIFFTAG_IMAGELENGTH, &height); @@ -546,8 +545,8 @@ tiffcvt(TIFF* in, TIFF* out) if (maxMalloc != 0 && TIFFStripSize(in) > maxMalloc) { TIFFError(TIFFFileName(in), - "Strip Size " TIFF_UINT64_FORMAT " over memory limit (" TIFF_UINT64_FORMAT ")", - (uint64)TIFFStripSize(in), (uint64)maxMalloc); + "Strip Size %" TIFF_SSIZE_FORMAT " over memory limit (%" TIFF_SSIZE_FORMAT ")", + TIFFStripSize(in), maxMalloc); return 0; } if( process_by_block && TIFFIsTiled( in ) ) @@ -558,32 +557,44 @@ tiffcvt(TIFF* in, TIFF* out) return( cvt_whole_image( in, out ) ); } -static const char* stuff[] = { - "usage: tiff2rgba [-c comp] [-r rows] [-b] [-n] [-8] [-M size] input... output", - "where comp is one of the following compression algorithms:", - " jpeg\t\tJPEG encoding", - " zip\t\tZip/Deflate encoding", - " lzw\t\tLempel-Ziv & Welch encoding", - " packbits\tPackBits encoding", - " none\t\tno compression", - "and the other options are:", - " -r\trows/strip", - " -b (progress by block rather than as a whole image)", - " -n don't emit alpha component.", - " -8 write BigTIFF file instead of ClassicTIFF", - " -M set the memory allocation limit in MiB. 0 to disable limit", - NULL -}; +static const char usage_info[] = +/* Help information format modified for the sake of consistency with the other tiff tools */ +/* "usage: tiff2rgba [-c comp] [-r rows] [-b] [-n] [-8] [-M size] input... output" */ +/* "where comp is one of the following compression algorithms:" */ +"Convert a TIFF image to RGBA color space\n\n" +"usage: tiff2rgba [options] input output\n" +"where options are:\n" +#ifdef JPEG_SUPPORT +" -c jpeg JPEG encoding\n" +#endif +#ifdef ZIP_SUPPORT +" -c zip Zip/Deflate encoding\n" +#endif +#ifdef LZW_SUPPORT +" -c lzw Lempel-Ziv & Welch encoding\n" +#endif +#ifdef PACKBITS_SUPPORT +" -c packbits PackBits encoding\n" +#endif +#if defined(JPEG_SUPPORT) || defined(ZIP_SUPPORT) || defined(LZW_SUPPORT) || defined(PACKBITS_SUPPORT) +" -c none no compression\n" +#endif +"\n" +/* "and the other options are:\n" */ +" -r rows/strip\n" +" -b (progress by block rather than as a whole image)\n" +" -n don't emit alpha component.\n" +" -8 write BigTIFF file instead of ClassicTIFF\n" +" -M set the memory allocation limit in MiB. 0 to disable limit\n" +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } diff --git a/tiff/tools/tiffcmp.c b/tiff/tools/tiffcmp.c index 041d6a2d..2a35fe60 100644 --- a/tiff/tools/tiffcmp.c +++ b/tiff/tools/tiffcmp.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> @@ -33,10 +34,6 @@ # include <unistd.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffio.h" #ifndef EXIT_SUCCESS @@ -46,27 +43,23 @@ #define EXIT_FAILURE 1 #endif -#ifndef HAVE_GETOPT -extern int getopt(int argc, char * const argv[], const char *optstring); -#endif - static int stopondiff = 1; static int stoponfirsttag = 1; -static uint16 bitspersample = 1; -static uint16 samplesperpixel = 1; -static uint16 sampleformat = SAMPLEFORMAT_UINT; -static uint32 imagewidth; -static uint32 imagelength; +static uint16_t bitspersample = 1; +static uint16_t samplesperpixel = 1; +static uint16_t sampleformat = SAMPLEFORMAT_UINT; +static uint32_t imagewidth; +static uint32_t imagelength; static void usage(int code); static int tiffcmp(TIFF*, TIFF*); static int cmptags(TIFF*, TIFF*); -static int ContigCompare(int, uint32, unsigned char*, unsigned char*, tsize_t); -static int SeparateCompare(int, int, uint32, unsigned char*, unsigned char*); -static void PrintIntDiff(uint32, int, uint32, uint32, uint32); -static void PrintFloatDiff(uint32, int, uint32, double, double); +static int ContigCompare(int, uint32_t, unsigned char*, unsigned char*, tsize_t); +static int SeparateCompare(int, int, uint32_t, unsigned char*, unsigned char*); +static void PrintIntDiff(uint32_t, int, uint32_t, uint32_t, uint32_t); +static void PrintFloatDiff(uint32_t, int, uint32_t, double, double); -static void leof(const char*, uint32, int); +static void leof(const char*, uint32_t, int); /* * exit with status : @@ -97,9 +90,11 @@ main(int argc, char* argv[]) break; case 'h': usage(EXIT_SUCCESS); + break; case '?': usage(2); /*NOTREACHED*/ + break; } if (argc - optind < 2) usage(2); @@ -130,24 +125,22 @@ main(int argc, char* argv[]) return (0); } -static const char* stuff[] = { -"usage: tiffcmp [options] file1 file2", -"where options are:", -" -l list each byte of image data that differs between the files", -" -z # list specified number of bytes that differs between the files", -" -t ignore any differences in directory tags", -NULL -}; +static const char usage_info[] = +"Compare the tags and data in two TIFF files\n\n" +"usage: tiffcmp [options] file1 file2\n" +"where options are:\n" +" -l list each byte of image data that differs between the files\n" +" -z # list specified number of bytes that differs between the files\n" +" -t ignore any differences in directory tags\n" +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } @@ -166,9 +159,9 @@ static int CheckStringTag(TIFF*, TIFF*, int, char*); static int tiffcmp(TIFF* tif1, TIFF* tif2) { - uint16 config1, config2; + uint16_t config1, config2; tsize_t size1; - uint32 row; + uint32_t row; tsample_t s; unsigned char *buf1, *buf2; @@ -274,7 +267,7 @@ bad1: static int cmptags(TIFF* tif1, TIFF* tif2) { - uint16 compression1, compression2; + uint16_t compression1, compression2; CmpLongField(TIFFTAG_SUBFILETYPE, "SubFileType"); CmpLongField(TIFFTAG_IMAGEWIDTH, "ImageWidth"); CmpLongField(TIFFTAG_IMAGELENGTH, "ImageLength"); @@ -313,13 +306,13 @@ cmptags(TIFF* tif1, TIFF* tif2) CmpShortField(TIFFTAG_GRAYRESPONSEUNIT, "GrayResponseUnit"); CmpShortField(TIFFTAG_COLORRESPONSEUNIT, "ColorResponseUnit"); #ifdef notdef - { uint16 *graycurve; + { uint16_t *graycurve; CmpField(TIFFTAG_GRAYRESPONSECURVE, graycurve); } - { uint16 *red, *green, *blue; + { uint16_t *red, *green, *blue; CmpField3(TIFFTAG_COLORRESPONSECURVE, red, green, blue); } - { uint16 *red, *green, *blue; + { uint16_t *red, *green, *blue; CmpField3(TIFFTAG_COLORMAP, red, green, blue); } #endif @@ -339,11 +332,10 @@ cmptags(TIFF* tif1, TIFF* tif2) } static int -ContigCompare(int sample, uint32 row, - unsigned char* p1, unsigned char* p2, tsize_t size) +ContigCompare(int sample, uint32_t row, + unsigned char* p1, unsigned char* p2, tsize_t size) { - uint32 pix; - int ppb = 8 / bitspersample; + uint32_t pix; int samples_to_test; if (memcmp(p1, p2, size) == 0) @@ -355,9 +347,10 @@ ContigCompare(int sample, uint32 row, case 1: case 2: case 4: case 8: { unsigned char *pix1 = p1, *pix2 = p2; + unsigned bits = 0; - for (pix = 0; pix < imagewidth; pix += ppb) { - int s; + for (pix = 0; pix < imagewidth; pix++) { + int s; for(s = 0; s < samples_to_test; s++) { if (*pix1 != *pix2) { @@ -367,15 +360,17 @@ ContigCompare(int sample, uint32 row, PrintIntDiff(row, sample, pix, *pix1, *pix2); } - pix1++; - pix2++; + bits += bitspersample; + pix1 += (bits / 8); + pix2 += (bits / 8); + bits &= 7; } } break; } case 16: { - uint16 *pix1 = (uint16 *)p1, *pix2 = (uint16 *)p2; + uint16_t *pix1 = (uint16_t *)p1, *pix2 = (uint16_t *)p2; for (pix = 0; pix < imagewidth; pix++) { int s; @@ -393,7 +388,7 @@ ContigCompare(int sample, uint32 row, case 32: if (sampleformat == SAMPLEFORMAT_UINT || sampleformat == SAMPLEFORMAT_INT) { - uint32 *pix1 = (uint32 *)p1, *pix2 = (uint32 *)p2; + uint32_t *pix1 = (uint32_t *)p1, *pix2 = (uint32_t *)p2; for (pix = 0; pix < imagewidth; pix++) { int s; @@ -425,13 +420,13 @@ ContigCompare(int sample, uint32 row, } } } else { - fprintf(stderr, "Sample format %d is not supported.\n", + fprintf(stderr, "Sample format %"PRIu16" is not supported.\n", sampleformat); return -1; } break; default: - fprintf(stderr, "Bit depth %d is not supported.\n", bitspersample); + fprintf(stderr, "Bit depth %"PRIu16" is not supported.\n", bitspersample); return -1; } @@ -439,7 +434,7 @@ ContigCompare(int sample, uint32 row, } static void -PrintIntDiff(uint32 row, int sample, uint32 pix, uint32 w1, uint32 w2) +PrintIntDiff(uint32_t row, int sample, uint32_t pix, uint32_t w1, uint32_t w2) { if (sample < 0) sample = 0; @@ -448,22 +443,22 @@ PrintIntDiff(uint32 row, int sample, uint32 pix, uint32 w1, uint32 w2) case 2: case 4: { - int32 mask1, mask2, s; + int32_t mask1, mask2, s; /* mask1 should have the n lowest bits set, where n == bitspersample */ - mask1 = ((int32)1 << bitspersample) - 1; + mask1 = ((int32_t)1 << bitspersample) - 1; s = (8 - bitspersample); mask2 = mask1 << s; for (; mask2 && pix < imagewidth; mask2 >>= bitspersample, s -= bitspersample, pix++) { if ((w1 & mask2) ^ (w2 & mask2)) { printf( - "Scanline %lu, pixel %lu, sample %d: %01x %01x\n", - (unsigned long) row, - (unsigned long) pix, + "Scanline %"PRIu32", pixel %"PRIu32", sample %d: %01"PRIx32" %01"PRIx32"\n", + row, + pix, sample, - (unsigned int)((w1 >> s) & mask1), - (unsigned int)((w2 >> s) & mask1)); + (w1 >> s) & mask1, + (w2 >> s) & mask1); if (--stopondiff == 0) exit(1); } @@ -471,23 +466,23 @@ PrintIntDiff(uint32 row, int sample, uint32 pix, uint32 w1, uint32 w2) break; } case 8: - printf("Scanline %lu, pixel %lu, sample %d: %02x %02x\n", - (unsigned long) row, (unsigned long) pix, sample, - (unsigned int) w1, (unsigned int) w2); + printf("Scanline %"PRIu32", pixel %"PRIu32", sample %d: %02"PRIx32" %02"PRIx32"\n", + row, pix, sample, + w1, w2); if (--stopondiff == 0) exit(1); break; case 16: - printf("Scanline %lu, pixel %lu, sample %d: %04x %04x\n", - (unsigned long) row, (unsigned long) pix, sample, - (unsigned int) w1, (unsigned int) w2); + printf("Scanline %"PRIu32", pixel %"PRIu32", sample %d: %04"PRIx32" %04"PRIx32"\n", + row, pix, sample, + w1, w2); if (--stopondiff == 0) exit(1); break; case 32: - printf("Scanline %lu, pixel %lu, sample %d: %08x %08x\n", - (unsigned long) row, (unsigned long) pix, sample, - (unsigned int) w1, (unsigned int) w2); + printf("Scanline %"PRIu32", pixel %"PRIu32", sample %d: %08"PRIx32" %08"PRIx32"\n", + row, pix, sample, + w1, w2); if (--stopondiff == 0) exit(1); break; @@ -497,14 +492,14 @@ PrintIntDiff(uint32 row, int sample, uint32 pix, uint32 w1, uint32 w2) } static void -PrintFloatDiff(uint32 row, int sample, uint32 pix, double w1, double w2) +PrintFloatDiff(uint32_t row, int sample, uint32_t pix, double w1, double w2) { if (sample < 0) sample = 0; switch (bitspersample) { case 32: - printf("Scanline %lu, pixel %lu, sample %d: %g %g\n", - (long) row, (long) pix, sample, w1, w2); + printf("Scanline %"PRIu32", pixel %"PRIu32", sample %d: %g %g\n", + row, pix, sample, w1, w2); if (--stopondiff == 0) exit(1); break; @@ -514,17 +509,17 @@ PrintFloatDiff(uint32 row, int sample, uint32 pix, double w1, double w2) } static int -SeparateCompare(int reversed, int sample, uint32 row, - unsigned char* cp1, unsigned char* p2) +SeparateCompare(int reversed, int sample, uint32_t row, + unsigned char* cp1, unsigned char* p2) { - uint32 npixels = imagewidth; + uint32_t npixels = imagewidth; int pixel; cp1 += sample; for (pixel = 0; npixels-- > 0; pixel++, cp1 += samplesperpixel, p2++) { if (*cp1 != *p2) { - printf("Scanline %lu, pixel %lu, sample %ld: ", - (long) row, (long) pixel, (long) sample); + printf("Scanline %"PRIu32", pixel %"PRIu32", sample %d: ", + row, pixel, sample); if (reversed) printf("%02x %02x\n", *p2, *cp1); else @@ -567,14 +562,14 @@ checkTag(TIFF* tif1, TIFF* tif2, int tag, char* name, void* p1, void* p2) static int CheckShortTag(TIFF* tif1, TIFF* tif2, int tag, char* name) { - uint16 v1, v2; - CHECK(v1 == v2, "%s: %u %u\n"); + uint16_t v1, v2; + CHECK(v1 == v2, "%s: %"PRIu16" %"PRIu16"\n"); } static int CheckShort2Tag(TIFF* tif1, TIFF* tif2, int tag, char* name) { - uint16 v11, v12, v21, v22; + uint16_t v11, v12, v21, v22; if (TIFFGetField(tif1, tag, &v11, &v12)) { if (!TIFFGetField(tif2, tag, &v21, &v22)) { @@ -584,7 +579,7 @@ CheckShort2Tag(TIFF* tif1, TIFF* tif2, int tag, char* name) } if (v11 == v21 && v12 == v22) return (1); - printf("%s: <%u,%u> <%u,%u>\n", name, v11, v12, v21, v22); + printf("%s: <%"PRIu16",%"PRIu16"> <%"PRIu16",%"PRIu16">\n", name, v11, v12, v21, v22); } else if (TIFFGetField(tif2, tag, &v21, &v22)) printf("%s tag appears only in %s\n", name, TIFFFileName(tif2)); else @@ -595,8 +590,8 @@ CheckShort2Tag(TIFF* tif1, TIFF* tif2, int tag, char* name) static int CheckShortArrayTag(TIFF* tif1, TIFF* tif2, int tag, char* name) { - uint16 n1, *a1; - uint16 n2, *a2; + uint16_t n1, *a1; + uint16_t n2, *a2; if (TIFFGetField(tif1, tag, &n1, &a1)) { if (!TIFFGetField(tif2, tag, &n2, &a2)) { @@ -606,21 +601,21 @@ CheckShortArrayTag(TIFF* tif1, TIFF* tif2, int tag, char* name) } if (n1 == n2) { char* sep; - uint16 i; + uint16_t i; - if (memcmp(a1, a2, n1 * sizeof(uint16)) == 0) + if (memcmp(a1, a2, n1 * sizeof(uint16_t)) == 0) return (1); - printf("%s: value mismatch, <%u:", name, n1); + printf("%s: value mismatch, <%"PRIu16":", name, n1); sep = ""; for (i = 0; i < n1; i++) - printf("%s%u", sep, a1[i]), sep = ","; - printf("> and <%u: ", n2); + printf("%s%"PRIu16, sep, a1[i]), sep = ","; + printf("> and <%"PRIu16": ", n2); sep = ""; for (i = 0; i < n2; i++) - printf("%s%u", sep, a2[i]), sep = ","; + printf("%s%"PRIu16, sep, a2[i]), sep = ","; printf(">\n"); } else - printf("%s: %u items in %s, %u items in %s", name, + printf("%s: %"PRIu16" items in %s, %"PRIu16" items in %s", name, n1, TIFFFileName(tif1), n2, TIFFFileName(tif2) ); @@ -634,8 +629,8 @@ CheckShortArrayTag(TIFF* tif1, TIFF* tif2, int tag, char* name) static int CheckLongTag(TIFF* tif1, TIFF* tif2, int tag, char* name) { - uint32 v1, v2; - CHECK(v1 == v2, "%s: %u %u\n"); + uint32_t v1, v2; + CHECK(v1 == v2, "%s: %"PRIu32" %"PRIu32"\n"); } static int @@ -653,10 +648,10 @@ CheckStringTag(TIFF* tif1, TIFF* tif2, int tag, char* name) } static void -leof(const char* name, uint32 row, int s) +leof(const char* name, uint32_t row, int s) { - printf("%s: EOF at scanline %lu", name, (unsigned long)row); + printf("%s: EOF at scanline %"PRIu32, name, row); if (s >= 0) printf(", sample %d", s); printf("\n"); diff --git a/tiff/tools/tiffcp.c b/tiff/tools/tiffcp.c index e56b1c10..1f889516 100644 --- a/tiff/tools/tiffcp.c +++ b/tiff/tools/tiffcp.c @@ -37,6 +37,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> @@ -58,14 +59,6 @@ #define EXIT_FAILURE 1 #endif -#ifndef HAVE_GETOPT -extern int getopt(int argc, char * const argv[], const char *optstring); -#endif - -#if defined(VMS) -# define unlink delete -#endif - #define streq(a,b) (strcmp(a,b) == 0) #define strneq(a,b,n) (strncmp(a,b,n) == 0) @@ -79,23 +72,24 @@ extern int getopt(int argc, char * const argv[], const char *optstring); static tmsize_t maxMalloc = DEFAULT_MAX_MALLOC; static int outtiled = -1; -static uint32 tilewidth; -static uint32 tilelength; +static uint32_t tilewidth; +static uint32_t tilelength; -static uint16 config; -static uint16 compression; -static uint16 predictor; +static uint16_t config; +static uint16_t compression; +static double max_z_error = 0.0; +static uint16_t predictor; static int preset; -static uint16 fillorder; -static uint16 orientation; -static uint32 rowsperstrip; -static uint32 g3opts; +static uint16_t fillorder; +static uint16_t orientation; +static uint32_t rowsperstrip; +static uint32_t g3opts; static int ignore = FALSE; /* if true, ignore read errors */ -static uint32 defg3opts = (uint32) -1; +static uint32_t defg3opts = (uint32_t) -1; static int quality = 75; /* JPEG quality */ static int jpegcolormode = JPEGCOLORMODE_RGB; -static uint16 defcompression = (uint16) -1; -static uint16 defpredictor = (uint16) -1; +static uint16_t defcompression = (uint16_t) -1; +static uint16_t defpredictor = (uint16_t) -1; static int defpreset = -1; static int subcodec = -1; @@ -114,8 +108,8 @@ static int pageInSeq = 0; static void* limitMalloc(tmsize_t s) { if (maxMalloc && (s > maxMalloc)) { - fprintf(stderr, "MemoryLimitError: allocation of " TIFF_UINT64_FORMAT " bytes is forbidden. Limit is " TIFF_UINT64_FORMAT ".\n", - (uint64)s, (uint64)maxMalloc); + fprintf(stderr, "MemoryLimitError: allocation of %" TIFF_SSIZE_FORMAT " bytes is forbidden. Limit is %" TIFF_SSIZE_FORMAT ".\n", + s, maxMalloc); fprintf(stderr, " use -m option to change limit.\n"); return NULL; } @@ -146,8 +140,8 @@ static int nextSrcImage (TIFF *tif, char **imageSpec) } } if (TIFFSetDirectory (tif, nextImage)) return 1; - fprintf (stderr, "%s%c%d not found!\n", - TIFFFileName(tif), comma, (int) nextImage); + fprintf (stderr, "%s%c%"PRIu16" not found!\n", + TIFFFileName(tif), comma, nextImage); } return 0; } @@ -185,12 +179,12 @@ static TIFF* openSrcImage (char **imageSpec) int main(int argc, char* argv[]) { - uint16 defconfig = (uint16) -1; - uint16 deffillorder = 0; - uint32 deftilewidth = (uint32) -1; - uint32 deftilelength = (uint32) -1; - uint32 defrowsperstrip = (uint32) 0; - uint64 diroff = 0; + uint16_t defconfig = (uint16_t) -1; + uint16_t deffillorder = 0; + uint32_t deftilewidth = (uint32_t) -1; + uint32_t deftilelength = (uint32_t) -1; + uint32_t defrowsperstrip = (uint32_t) 0; + uint64_t diroff = 0; TIFF* in; TIFF* out; char mode[10]; @@ -218,7 +212,7 @@ main(int argc, char* argv[]) exit (EXIT_FAILURE); } { - uint16 samples = (uint16) -1; + uint16_t samples = (uint16_t) -1; char **biasFn = &optarg; bias = openSrcImage (biasFn); if (!bias) exit (EXIT_FAILURE); @@ -300,9 +294,11 @@ main(int argc, char* argv[]) case 'h': usage(EXIT_SUCCESS); /*NOTREACHED*/ + break; case '?': usage(EXIT_FAILURE); /*NOTREACHED*/ + break; } if (argc - optind < 2) usage(EXIT_FAILURE); @@ -320,7 +316,7 @@ main(int argc, char* argv[]) } if (diroff != 0 && !TIFFSetSubDirectory(in, diroff)) { TIFFError(TIFFFileName(in), - "Error, setting subdirectory at " TIFF_UINT64_FORMAT, diroff); + "Error, setting subdirectory at %" PRIu64, diroff); (void) TIFFClose(in); (void) TIFFClose(out); return (EXIT_FAILURE); @@ -371,10 +367,28 @@ processZIPOptions(char* cp) } static void +processLERCOptions(char* cp) +{ + if ( (cp = strchr(cp, ':')) ) { + do { + cp++; + if (isdigit((int)*cp)) + max_z_error = atof(cp); + else if (*cp == 's') + subcodec = atoi(++cp); + else if (*cp == 'p') + defpreset = atoi(++cp); + else + usage(EXIT_FAILURE); + } while( (cp = strchr(cp, ':')) ); + } +} + +static void processG3Options(char* cp) { if( (cp = strchr(cp, ':')) ) { - if (defg3opts == (uint32) -1) + if (defg3opts == (uint32_t) -1) defg3opts = 0; do { cp++; @@ -425,6 +439,9 @@ processCompressOptions(char* opt) } else if (strneq(opt, "zip", 3)) { processZIPOptions(opt); defcompression = COMPRESSION_ADOBE_DEFLATE; + } else if (strneq(opt, "lerc", 4)) { + processLERCOptions(opt); + defcompression = COMPRESSION_LERC; } else if (strneq(opt, "lzma", 4)) { processZIPOptions(opt); defcompression = COMPRESSION_LZMA; @@ -443,83 +460,121 @@ processCompressOptions(char* opt) return (1); } -static const char* stuff[] = { -"usage: tiffcp [options] input... output", -"where options are:", -" -a append to output instead of overwriting", -" -o offset set initial directory offset", -" -p contig pack samples contiguously (e.g. RGBRGB...)", -" -p separate store samples separately (e.g. RRR...GGG...BBB...)", -" -s write output in strips", -" -t write output in tiles", -" -x force the merged tiff pages in sequence", -" -8 write BigTIFF instead of default ClassicTIFF", -" -B write big-endian instead of native byte order", -" -L write little-endian instead of native byte order", -" -M disable use of memory-mapped files", -" -C disable strip chopping", -" -i ignore read errors", -" -b file[,#] bias (dark) monochrome image to be subtracted from all others", -" -,=% use % rather than , to separate image #'s (per Note below)", -" -m size set maximum memory allocation size (MiB). 0 to disable limit.", -"", -" -r # make each strip have no more than # rows", -" -w # set output tile width (pixels)", -" -l # set output tile length (pixels)", -"", -" -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 lzma[:opts] compress output with LZMA2 encoding", -" -c zstd[:opts] compress output with ZSTD encoding", -" -c webp[:opts] compress output with WEBP encoding", -" -c jpeg[:opts] compress output with JPEG encoding", -" -c jbig compress output with ISO JBIG encoding", -" -c packbits compress output with packbits encoding", -" -c g3[:opts] compress output with CCITT Group 3 encoding", -" -c g4 compress output with CCITT Group 4 encoding", -" -c sgilog compress output with SGILOG encoding", -" -c none use no compression algorithm on output", -"", -"Group 3 options:", -" 1d use default CCITT Group 3 1D-encoding", -" 2d use optional CCITT Group 3 2D-encoding", -" fill byte-align EOL codes", -"For example, -c g3:2d:fill to get G3-2D-encoded data with byte-aligned EOLs", -"", -"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, Deflate (ZIP), LZMA2, ZSTD and WEBP options:", -" # set predictor value", -" p# set compression level (preset)", -#if LIBDEFLATE_SUPPORT -" s# set subcodec (0=zlib, 1=libdeflate) (only for Deflate/ZIP)", +static const char usage_info[] = +"Copy, convert, or combine TIFF files\n\n" +"usage: tiffcp [options] input... output\n" +"where options are:\n" +" -a append to output instead of overwriting\n" +" -o offset set initial directory offset\n" +" -p contig pack samples contiguously (e.g. RGBRGB...)\n" +" -p separate store samples separately (e.g. RRR...GGG...BBB...)\n" +" -s write output in strips\n" +" -t write output in tiles\n" +" -x force the merged tiff pages in sequence\n" +" -8 write BigTIFF instead of default ClassicTIFF\n" +" -B write big-endian instead of native byte order\n" +" -L write little-endian instead of native byte order\n" +" -M disable use of memory-mapped files\n" +" -C disable strip chopping\n" +" -i ignore read errors\n" +" -b file[,#] bias (dark) monochrome image to be subtracted from all others\n" +" -,=% use % rather than , to separate image #'s (per Note below)\n" +" -m size set maximum memory allocation size (MiB). 0 to disable limit.\n" +"\n" +" -r # make each strip have no more than # rows\n" +" -w # set output tile width (pixels)\n" +" -l # set output tile length (pixels)\n" +"\n" +" -f lsb2msb force lsb-to-msb FillOrder for output\n" +" -f msb2lsb force msb-to-lsb FillOrder for output\n" +"\n" +#ifdef LZW_SUPPORT +" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding\n" +/* " LZW options:" */ +" # set predictor value\n" +" For example, -c lzw:2 for LZW-encoded data with horizontal differencing\n" #endif -"For example, -c lzw:2 to get LZW-encoded data with horizontal differencing,", -"-c zip:3:p9 for Deflate encoding with maximum compression level and floating", -"point predictor.", -"", -"Note that input filenames may be of the form filename,x,y,z", -"where x, y, and z specify image numbers in the filename to copy.", -"example: tiffcp -c none -b esp.tif,1 esp.tif,0 test.tif", -" subtract 2nd image in esp.tif from 1st yielding uncompressed result test.tif", -NULL -}; +#ifdef ZIP_SUPPORT +" -c zip[:opts] compress output with deflate encoding\n" +/* " Deflate (ZIP) options:", */ +" # set predictor value\n" +" p# set compression level (preset)\n" +" For example, -c zip:3:p9 for maximum compression level and floating\n" +" point predictor.\n" +#endif +#if defined(ZIP_SUPPORT) && defined(LIBDEFLATE_SUPPORT) +" s# set subcodec: 0=zlib, 1=libdeflate (default 1)\n" +/* " (only for Deflate/ZIP)", */ +#endif +#ifdef LERC_SUPPORT +" -c lerc[:opts] compress output with LERC encoding\n" +/* " LERC options:", */ +" # set max_z_error value\n" +" s# set subcodec: 0=none, 1=deflate, 2=zstd (default 0)\n" +" p# set compression level (preset)\n" +" For example, -c lerc:0.5:s2:p22 for max_z_error 0.5,\n" +" zstd additional copression with maximum compression level.\n" +#endif +#ifdef LZMA_SUPPORT +" -c lzma[:opts] compress output with LZMA2 encoding\n" +/* " LZMA options:", */ +" # set predictor value\n" +" p# set compression level (preset)\n" +#endif +#ifdef ZSTD_SUPPORT +" -c zstd[:opts] compress output with ZSTD encoding\n" +/* " ZSTD options:", */ +" # set predictor value\n" +" p# set compression level (preset)\n" +#endif +#ifdef WEBP_SUPPORT +" -c webp[:opts] compress output with WEBP encoding\n" +/* " WEBP options:", */ +" # set predictor value\n" +" p# set compression level (preset)\n" +#endif +#ifdef JPEG_SUPPORT +" -c jpeg[:opts] compress output with JPEG encoding\n" +/* " JPEG options:", */ +" # set compression quality level (0-100, default 75)\n" +" r output color image as RGB rather than YCbCr\n" +" For example, -c jpeg:r:50 for JPEG-encoded RGB with 50% comp. quality\n" +#endif +#ifdef JBIG_SUPPORT +" -c jbig compress output with ISO JBIG encoding\n" +#endif +#ifdef PACKBITS_SUPPORT +" -c packbits compress output with packbits encoding\n" +#endif +#ifdef CCITT_SUPPORT +" -c g3[:opts] compress output with CCITT Group 3 encoding\n" +/* " CCITT Group 3 options:", */ +" 1d use default CCITT Group 3 1D-encoding\n" +" 2d use optional CCITT Group 3 2D-encoding\n" +" fill byte-align EOL codes\n" +" For example, -c g3:2d:fill for G3-2D-encoded data with byte-aligned EOLs\n" +" -c g4 compress output with CCITT Group 4 encoding\n" +#endif +#ifdef LOGLUV_SUPPORT +" -c sgilog compress output with SGILOG encoding\n" +#endif +#if defined(LZW_SUPPORT) || defined(ZIP_SUPPORT) || defined(LZMA_SUPPORT) || defined(ZSTD_SUPPORT) || defined(WEBP_SUPPORT) || defined(JPEG_SUPPORT) || defined(JBIG_SUPPORT) || defined(PACKBITS_SUPPORT) || defined(CCITT_SUPPORT) || defined(LOGLUV_SUPPORT) || defined(LERC_SUPPORT) +" -c none use no compression algorithm on output\n" +#endif +"\n" +"Note that input filenames may be of the form filename,x,y,z\n" +"where x, y, and z specify image numbers in the filename to copy.\n" +"example: tiffcp -b esp.tif,1 esp.tif,0 test.tif\n" +" subtract 2nd image in esp.tif from 1st yielding result test.tif\n" +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } @@ -533,27 +588,27 @@ usage(int code) if (TIFFGetField(in, tag, &v1, &v2, &v3, &v4)) TIFFSetField(out, tag, v1, v2, v3, v4) static void -cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) +cpTag(TIFF* in, TIFF* out, uint16_t tag, uint16_t count, TIFFDataType type) { switch (type) { case TIFF_SHORT: if (count == 1) { - uint16 shortv; + uint16_t shortv; CopyField(tag, shortv); } else if (count == 2) { - uint16 shortv1, shortv2; + uint16_t shortv1, shortv2; CopyField2(tag, shortv1, shortv2); } else if (count == 4) { - uint16 *tr, *tg, *tb, *ta; + uint16_t *tr, *tg, *tb, *ta; CopyField4(tag, tr, tg, tb, ta); - } else if (count == (uint16) -1) { - uint16 shortv1; - uint16* shortav; + } else if (count == (uint16_t) -1) { + uint16_t shortv1; + uint16_t* shortav; CopyField2(tag, shortv1, shortav); } break; case TIFF_LONG: - { uint32 longv; + { uint32_t longv; CopyField(tag, longv); } break; @@ -561,7 +616,7 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) if (count == 1) { float floatv; CopyField(tag, floatv); - } else if (count == (uint16) -1) { + } else if (count == (uint16_t) -1) { float* floatav; CopyField(tag, floatav); } @@ -575,21 +630,21 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) if (count == 1) { double doublev; CopyField(tag, doublev); - } else if (count == (uint16) -1) { + } else if (count == (uint16_t) -1) { double* doubleav; CopyField(tag, doubleav); } break; default: TIFFError(TIFFFileName(in), - "Data type %d is not supported, tag %d skipped.", + "Data type %"PRIu16" is not supported, tag %d skipped.", tag, type); } } -static struct cpTag { - uint16 tag; - uint16 count; +static const struct cpTag { + uint16_t tag; + uint16_t count; TIFFDataType type; } tags[] = { { TIFFTAG_SUBFILETYPE, 1, TIFF_LONG }, @@ -600,56 +655,56 @@ static struct cpTag { { TIFFTAG_MODEL, 1, TIFF_ASCII }, { TIFFTAG_MINSAMPLEVALUE, 1, TIFF_SHORT }, { TIFFTAG_MAXSAMPLEVALUE, 1, TIFF_SHORT }, - { TIFFTAG_XRESOLUTION, 1, TIFF_RATIONAL }, - { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL }, - { TIFFTAG_PAGENAME, 1, TIFF_ASCII }, - { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL }, - { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL }, - { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT }, - { TIFFTAG_SOFTWARE, 1, TIFF_ASCII }, - { TIFFTAG_DATETIME, 1, TIFF_ASCII }, - { TIFFTAG_ARTIST, 1, TIFF_ASCII }, - { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII }, - { TIFFTAG_WHITEPOINT, (uint16) -1, TIFF_RATIONAL }, - { TIFFTAG_PRIMARYCHROMATICITIES,(uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT }, - { TIFFTAG_INKSET, 1, TIFF_SHORT }, - { TIFFTAG_DOTRANGE, 2, TIFF_SHORT }, - { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII }, - { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT }, - { TIFFTAG_YCBCRCOEFFICIENTS, (uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT }, - { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT }, - { TIFFTAG_REFERENCEBLACKWHITE, (uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_EXTRASAMPLES, (uint16) -1, TIFF_SHORT }, - { TIFFTAG_SMINSAMPLEVALUE, 1, TIFF_DOUBLE }, - { TIFFTAG_SMAXSAMPLEVALUE, 1, TIFF_DOUBLE }, - { TIFFTAG_STONITS, 1, TIFF_DOUBLE }, + { TIFFTAG_XRESOLUTION, 1, TIFF_RATIONAL }, + { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL }, + { TIFFTAG_PAGENAME, 1, TIFF_ASCII }, + { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL }, + { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL }, + { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT }, + { TIFFTAG_SOFTWARE, 1, TIFF_ASCII }, + { TIFFTAG_DATETIME, 1, TIFF_ASCII }, + { TIFFTAG_ARTIST, 1, TIFF_ASCII }, + { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII }, + { TIFFTAG_WHITEPOINT, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_PRIMARYCHROMATICITIES,(uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT }, + { TIFFTAG_INKSET, 1, TIFF_SHORT }, + { TIFFTAG_DOTRANGE, 2, TIFF_SHORT }, + { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII }, + { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT }, + { TIFFTAG_YCBCRCOEFFICIENTS, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT }, + { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT }, + { TIFFTAG_REFERENCEBLACKWHITE, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_EXTRASAMPLES, (uint16_t) -1, TIFF_SHORT }, + { TIFFTAG_SMINSAMPLEVALUE, 1, TIFF_DOUBLE }, + { TIFFTAG_SMAXSAMPLEVALUE, 1, TIFF_DOUBLE }, + { TIFFTAG_STONITS, 1, TIFF_DOUBLE }, }; #define NTAGS (sizeof (tags) / sizeof (tags[0])) #define CopyTag(tag, count, type) cpTag(in, out, tag, count, type) typedef int (*copyFunc) - (TIFF* in, TIFF* out, uint32 l, uint32 w, uint16 samplesperpixel); -static copyFunc pickCopyFunc(TIFF*, TIFF*, uint16, uint16); + (TIFF* in, TIFF* out, uint32_t l, uint32_t w, uint16_t samplesperpixel); +static copyFunc pickCopyFunc(TIFF*, TIFF*, uint16_t, uint16_t); /* PODD */ static int tiffcp(TIFF* in, TIFF* out) { - uint16 bitspersample = 1, samplesperpixel = 1; - uint16 input_compression, input_photometric = PHOTOMETRIC_MINISBLACK; + uint16_t bitspersample = 1, samplesperpixel = 1; + uint16_t input_compression, input_photometric = PHOTOMETRIC_MINISBLACK; copyFunc cf; - uint32 width, length; - struct cpTag* p; + uint32_t width, length; + const struct cpTag* p; CopyField(TIFFTAG_IMAGEWIDTH, width); CopyField(TIFFTAG_IMAGELENGTH, length); CopyField(TIFFTAG_BITSPERSAMPLE, bitspersample); CopyField(TIFFTAG_SAMPLESPERPIXEL, samplesperpixel); - if (compression != (uint16)-1) + if (compression != (uint16_t)-1) TIFFSetField(out, TIFFTAG_COMPRESSION, compression); else CopyField(TIFFTAG_COMPRESSION, compression); @@ -660,7 +715,7 @@ tiffcp(TIFF* in, TIFF* out) TIFFSetField(in, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB); } else if (input_photometric == PHOTOMETRIC_YCBCR) { /* Otherwise, can't handle subsampled input */ - uint16 subsamplinghor,subsamplingver; + uint16_t subsamplinghor,subsamplingver; TIFFGetFieldDefaulted(in, TIFFTAG_YCBCRSUBSAMPLING, &subsamplinghor, &subsamplingver); @@ -732,9 +787,9 @@ tiffcp(TIFF* in, TIFF* out) * input image or, if nothing is defined, use the * library default. */ - if (tilewidth == (uint32) -1) + if (tilewidth == (uint32_t) -1) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tilewidth); - if (tilelength == (uint32) -1) + if (tilelength == (uint32_t) -1) TIFFGetField(in, TIFFTAG_TILELENGTH, &tilelength); TIFFDefaultTileSize(out, &tilewidth, &tilelength); TIFFSetField(out, TIFFTAG_TILEWIDTH, tilewidth); @@ -745,20 +800,20 @@ tiffcp(TIFF* in, TIFF* out) * value from the input image or, if nothing is defined, * use the library default. */ - if (rowsperstrip == (uint32) 0) { + if (rowsperstrip == (uint32_t) 0) { if (!TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &rowsperstrip)) { rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip); } - if (rowsperstrip > length && rowsperstrip != (uint32)-1) + if (rowsperstrip > length && rowsperstrip != (uint32_t)-1) rowsperstrip = length; } - else if (rowsperstrip == (uint32) -1) + else if (rowsperstrip == (uint32_t) -1) rowsperstrip = length; TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip); } - if (config != (uint16) -1) + if (config != (uint16_t) -1) TIFFSetField(out, TIFFTAG_PLANARCONFIG, config); else CopyField(TIFFTAG_PLANARCONFIG, config); @@ -777,12 +832,45 @@ tiffcp(TIFF* in, TIFF* out) CopyTag(TIFFTAG_FAXSUBADDRESS, 1, TIFF_ASCII); CopyTag(TIFFTAG_FAXDCS, 1, TIFF_ASCII); break; + case COMPRESSION_LERC: + if( max_z_error > 0 ) + { + if( TIFFSetField(out, TIFFTAG_LERC_MAXZERROR, max_z_error) != 1 ) + { + return FALSE; + } + } + if( subcodec != -1 ) + { + if( TIFFSetField(out, TIFFTAG_LERC_ADD_COMPRESSION, subcodec) != 1 ) + { + return FALSE; + } + } + if( preset != -1 ) + { + switch (subcodec) { + case LERC_ADD_COMPRESSION_DEFLATE: + if( TIFFSetField(out, TIFFTAG_ZIPQUALITY, preset) != 1 ) + { + return FALSE; + } + break; + case LERC_ADD_COMPRESSION_ZSTD: + if( TIFFSetField( out, TIFFTAG_ZSTD_LEVEL, preset ) != 1 ) + { + return FALSE; + } + break; + } + } + break; case COMPRESSION_LZW: case COMPRESSION_ADOBE_DEFLATE: case COMPRESSION_DEFLATE: case COMPRESSION_LZMA: case COMPRESSION_ZSTD: - if (predictor != (uint16)-1) + if (predictor != (uint16_t)-1) TIFFSetField(out, TIFFTAG_PREDICTOR, predictor); else CopyField(TIFFTAG_PREDICTOR, predictor); @@ -819,7 +907,7 @@ tiffcp(TIFF* in, TIFF* out) case COMPRESSION_CCITTFAX3: case COMPRESSION_CCITTFAX4: if (compression == COMPRESSION_CCITTFAX3) { - if (g3opts != (uint32) -1) + if (g3opts != (uint32_t) -1) TIFFSetField(out, TIFFTAG_GROUP3OPTIONS, g3opts); else @@ -835,13 +923,13 @@ tiffcp(TIFF* in, TIFF* out) break; } { - uint32 len32; + uint32_t len32; void** data; if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &len32, &data)) TIFFSetField(out, TIFFTAG_ICCPROFILE, len32, data); } { - uint16 ninks; + uint16_t ninks; const char* inknames; if (TIFFGetField(in, TIFFTAG_NUMBEROFINKS, &ninks)) { TIFFSetField(out, TIFFTAG_NUMBEROFINKS, ninks); @@ -890,17 +978,17 @@ tiffcp(TIFF* in, TIFF* out) */ #define DECLAREcpFunc(x) \ static int x(TIFF* in, TIFF* out, \ - uint32 imagelength, uint32 imagewidth, tsample_t spp) + uint32_t imagelength, uint32_t imagewidth, tsample_t spp) #define DECLAREreadFunc(x) \ static int x(TIFF* in, \ - uint8* buf, uint32 imagelength, uint32 imagewidth, tsample_t spp) -typedef int (*readFunc)(TIFF*, uint8*, uint32, uint32, tsample_t); + uint8_t* buf, uint32_t imagelength, uint32_t imagewidth, tsample_t spp) +typedef int (*readFunc)(TIFF*, uint8_t*, uint32_t, uint32_t, tsample_t); #define DECLAREwriteFunc(x) \ static int x(TIFF* out, \ - uint8* buf, uint32 imagelength, uint32 imagewidth, tsample_t spp) -typedef int (*writeFunc)(TIFF*, uint8*, uint32, uint32, tsample_t); + uint8_t* buf, uint32_t imagelength, uint32_t imagewidth, tsample_t spp) +typedef int (*writeFunc)(TIFF*, uint8_t*, uint32_t, uint32_t, tsample_t); /* * Contig -> contig by scanline for rows/strip change. @@ -909,7 +997,7 @@ DECLAREcpFunc(cpContig2ContigByRow) { tsize_t scanlinesize = TIFFScanlineSize(in); tdata_t buf; - uint32 row; + uint32_t row; buf = limitMalloc(scanlinesize); if (!buf) @@ -919,14 +1007,14 @@ DECLAREcpFunc(cpContig2ContigByRow) for (row = 0; row < imagelength; row++) { if (TIFFReadScanline(in, buf, row, 0) < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read scanline %lu", - (unsigned long) row); + "Error, can't read scanline %"PRIu32, + row); goto bad; } if (TIFFWriteScanline(out, buf, row, 0) < 0) { TIFFError(TIFFFileName(out), - "Error, can't write scanline %lu", - (unsigned long) row); + "Error, can't write scanline %"PRIu32, + row); goto bad; } } @@ -938,13 +1026,13 @@ bad: } -typedef void biasFn (void *image, void *bias, uint32 pixels); +typedef void biasFn (void *image, void *bias, uint32_t pixels); #define subtract(bits) \ -static void subtract##bits (void *i, void *b, uint32 pixels)\ +static void subtract##bits (void *i, void *b, uint32_t pixels)\ {\ - uint##bits *image = i;\ - uint##bits *bias = b;\ + uint##bits##_t *image = i;\ + uint##bits##_t *bias = b;\ while (pixels--) {\ *image = *image > *bias ? *image-*bias : 0;\ image++, bias++; \ @@ -974,39 +1062,39 @@ DECLAREcpFunc(cpBiasedContig2Contig) tsize_t biasSize = TIFFScanlineSize(bias); tsize_t bufSize = TIFFScanlineSize(in); tdata_t buf, biasBuf; - uint32 biasWidth = 0, biasLength = 0; + uint32_t biasWidth = 0, biasLength = 0; TIFFGetField(bias, TIFFTAG_IMAGEWIDTH, &biasWidth); TIFFGetField(bias, TIFFTAG_IMAGELENGTH, &biasLength); if (biasSize == bufSize && imagelength == biasLength && imagewidth == biasWidth) { - uint16 sampleBits = 0; + uint16_t sampleBits = 0; biasFn *subtractLine; TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &sampleBits); subtractLine = lineSubtractFn (sampleBits); if (subtractLine) { - uint32 row; + uint32_t row; buf = limitMalloc(bufSize); biasBuf = limitMalloc(bufSize); for (row = 0; row < imagelength; row++) { if (TIFFReadScanline(in, buf, row, 0) < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read scanline %lu", - (unsigned long) row); + "Error, can't read scanline %"PRIu32, + row); goto bad; } if (TIFFReadScanline(bias, biasBuf, row, 0) < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read biased scanline %lu", - (unsigned long) row); + "Error, can't read biased scanline %"PRIu32, + row); goto bad; } subtractLine (buf, biasBuf, imagewidth); if (TIFFWriteScanline(out, buf, row, 0) < 0) { TIFFError(TIFFFileName(out), - "Error, can't write scanline %lu", - (unsigned long) row); + "Error, can't write scanline %"PRIu32, + row); goto bad; } } @@ -1022,19 +1110,19 @@ bad: return 0; } else { TIFFError(TIFFFileName(in), - "No support for biasing %d bit pixels\n", + "No support for biasing %"PRIu16" bit pixels\n", sampleBits); return 0; } } TIFFError(TIFFFileName(in), - "Bias image %s,%d\nis not the same size as %s,%d\n", + "Bias image %s,%"PRIu16"\nis not the same size as %s,%"PRIu16"\n", TIFFFileName(bias), TIFFCurrentDirectory(bias), TIFFFileName(in), TIFFCurrentDirectory(in)); return 0; } else { TIFFError(TIFFFileName(in), - "Can't bias %s,%d as it has >1 Sample/Pixel\n", + "Can't bias %s,%"PRIu16" as it has >1 Sample/Pixel\n", TIFFFileName(in), TIFFCurrentDirectory(in)); return 0; } @@ -1053,7 +1141,7 @@ DECLAREcpFunc(cpDecodedStrips) (void) imagewidth; (void) spp; if (buf) { tstrip_t s, ns = TIFFNumberOfStrips(in); - uint32 row = 0; + uint32_t row = 0; _TIFFmemset(buf, 0, stripsize); for (s = 0; s < ns && row < imagelength; s++) { tsize_t cc = (row + rowsperstrip > imagelength) ? @@ -1061,14 +1149,14 @@ DECLAREcpFunc(cpDecodedStrips) if (TIFFReadEncodedStrip(in, s, buf, cc) < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read strip %lu", - (unsigned long) s); + "Error, can't read strip %"PRIu32, + s); goto bad; } if (TIFFWriteEncodedStrip(out, s, buf, cc) < 0) { TIFFError(TIFFFileName(out), - "Error, can't write strip %lu", - (unsigned long) s); + "Error, can't write strip %"PRIu32, + s); goto bad; } row += rowsperstrip; @@ -1077,8 +1165,8 @@ DECLAREcpFunc(cpDecodedStrips) return 1; } else { TIFFError(TIFFFileName(in), - "Error, can't allocate memory buffer of size %lu " - "to read strips", (unsigned long) stripsize); + "Error, can't allocate memory buffer of size %"TIFF_SSIZE_FORMAT + " to read strips", stripsize); return 0; } @@ -1094,7 +1182,7 @@ DECLAREcpFunc(cpSeparate2SeparateByRow) { tsize_t scanlinesize = TIFFScanlineSize(in); tdata_t buf; - uint32 row; + uint32_t row; tsample_t s; (void) imagewidth; @@ -1106,14 +1194,14 @@ DECLAREcpFunc(cpSeparate2SeparateByRow) for (row = 0; row < imagelength; row++) { if (TIFFReadScanline(in, buf, row, s) < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read scanline %lu", - (unsigned long) row); + "Error, can't read scanline %"PRIu32, + row); goto bad; } if (TIFFWriteScanline(out, buf, row, s) < 0) { TIFFError(TIFFFileName(out), - "Error, can't write scanline %lu", - (unsigned long) row); + "Error, can't write scanline %"PRIu32, + row); goto bad; } } @@ -1134,11 +1222,11 @@ DECLAREcpFunc(cpContig2SeparateByRow) tsize_t scanlinesizeout = TIFFScanlineSize(out); tdata_t inbuf; tdata_t outbuf; - register uint8 *inp, *outp; - register uint32 n; - uint32 row; + register uint8_t *inp, *outp; + register uint32_t n; + uint32_t row; tsample_t s; - uint16 bps = 0; + uint16_t bps = 0; (void) TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bps); if( bps != 8 ) @@ -1161,20 +1249,20 @@ DECLAREcpFunc(cpContig2SeparateByRow) if (TIFFReadScanline(in, inbuf, row, 0) < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read scanline %lu", - (unsigned long) row); + "Error, can't read scanline %"PRIu32, + row); goto bad; } - inp = ((uint8*)inbuf) + s; - outp = (uint8*)outbuf; + inp = ((uint8_t*)inbuf) + s; + outp = (uint8_t*)outbuf; for (n = imagewidth; n-- > 0;) { *outp++ = *inp; inp += spp; } if (TIFFWriteScanline(out, outbuf, row, s) < 0) { TIFFError(TIFFFileName(out), - "Error, can't write scanline %lu", - (unsigned long) row); + "Error, can't write scanline %"PRIu32, + row); goto bad; } } @@ -1197,11 +1285,11 @@ DECLAREcpFunc(cpSeparate2ContigByRow) tsize_t scanlinesizeout = TIFFScanlineSize(out); tdata_t inbuf; tdata_t outbuf; - register uint8 *inp, *outp; - register uint32 n; - uint32 row; + register uint8_t *inp, *outp; + register uint32_t n; + uint32_t row; tsample_t s; - uint16 bps = 0; + uint16_t bps = 0; (void) TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bps); if( bps != 8 ) @@ -1224,12 +1312,12 @@ DECLAREcpFunc(cpSeparate2ContigByRow) if (TIFFReadScanline(in, inbuf, row, s) < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read scanline %lu", - (unsigned long) row); + "Error, can't read scanline %"PRIu32, + row); goto bad; } - inp = (uint8*)inbuf; - outp = ((uint8*)outbuf) + s; + inp = (uint8_t*)inbuf; + outp = ((uint8_t*)outbuf) + s; for (n = imagewidth; n-- > 0;) { *outp = *inp++; outp += spp; @@ -1237,8 +1325,8 @@ DECLAREcpFunc(cpSeparate2ContigByRow) } if (TIFFWriteScanline(out, outbuf, row, 0) < 0) { TIFFError(TIFFFileName(out), - "Error, can't write scanline %lu", - (unsigned long) row); + "Error, can't write scanline %"PRIu32, + row); goto bad; } } @@ -1252,11 +1340,11 @@ bad: } static void -cpStripToTile(uint8* out, uint8* in, - uint32 rows, uint32 cols, int outskew, int64 inskew) +cpStripToTile(uint8_t* out, uint8_t* in, + uint32_t rows, uint32_t cols, int outskew, int64_t inskew) { while (rows-- > 0) { - uint32 j = cols; + uint32_t j = cols; while (j-- > 0) *out++ = *in++; out += outskew; @@ -1265,12 +1353,12 @@ cpStripToTile(uint8* out, uint8* in, } static void -cpContigBufToSeparateBuf(uint8* out, uint8* in, - uint32 rows, uint32 cols, int outskew, int inskew, tsample_t spp, - int bytes_per_sample ) +cpContigBufToSeparateBuf(uint8_t* out, uint8_t* in, + uint32_t rows, uint32_t cols, int outskew, int inskew, tsample_t spp, + int bytes_per_sample ) { while (rows-- > 0) { - uint32 j = cols; + uint32_t j = cols; while (j-- > 0) { int n = bytes_per_sample; @@ -1286,12 +1374,12 @@ cpContigBufToSeparateBuf(uint8* out, uint8* in, } static void -cpSeparateBufToContigBuf(uint8* out, uint8* in, - uint32 rows, uint32 cols, int outskew, int inskew, tsample_t spp, - int bytes_per_sample) +cpSeparateBufToContigBuf(uint8_t* out, uint8_t* in, + uint32_t rows, uint32_t cols, int outskew, int inskew, tsample_t spp, + int bytes_per_sample) { while (rows-- > 0) { - uint32 j = cols; + uint32_t j = cols; while (j-- > 0) { int n = bytes_per_sample; @@ -1307,7 +1395,7 @@ cpSeparateBufToContigBuf(uint8* out, uint8* in, static int cpImage(TIFF* in, TIFF* out, readFunc fin, writeFunc fout, - uint32 imagelength, uint32 imagewidth, tsample_t spp) + uint32_t imagelength, uint32_t imagewidth, tsample_t spp) { int status = 0; tdata_t buf = NULL; @@ -1321,9 +1409,9 @@ cpImage(TIFF* in, TIFF* out, readFunc fin, writeFunc fout, && bytes / (tsize_t)imagelength == scanlinesize) { buf = limitMalloc(bytes); if (buf) { - if ((*fin)(in, (uint8*)buf, imagelength, - imagewidth, spp)) { - status = (*fout)(out, (uint8*)buf, + if ((*fin)(in, (uint8_t*)buf, imagelength, + imagewidth, spp)) { + status = (*fout)(out, (uint8_t*)buf, imagelength, imagewidth, spp); } _TIFFfree(buf); @@ -1341,16 +1429,16 @@ cpImage(TIFF* in, TIFF* out, readFunc fin, writeFunc fout, DECLAREreadFunc(readContigStripsIntoBuffer) { tsize_t scanlinesize = TIFFScanlineSize(in); - uint8* bufp = buf; - uint32 row; + uint8_t* bufp = buf; + uint32_t row; (void) imagewidth; (void) spp; for (row = 0; row < imagelength; row++) { if (TIFFReadScanline(in, (tdata_t) bufp, row, 0) < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read scanline %lu", - (unsigned long) row); + "Error, can't read scanline %"PRIu32, + row); return 0; } bufp += scanlinesize; @@ -1373,21 +1461,21 @@ DECLAREreadFunc(readSeparateStripsIntoBuffer) _TIFFmemset(scanline, 0, scanlinesize); (void) imagewidth; if (scanline) { - uint8* bufp = (uint8*) buf; - uint32 row; + uint8_t* bufp = (uint8_t*) buf; + uint32_t row; tsample_t s; for (row = 0; row < imagelength; row++) { /* merge channels */ for (s = 0; s < spp; s++) { - uint8* bp = bufp + s; + uint8_t* bp = bufp + s; tsize_t n = scanlinesize; - uint8* sbuf = scanline; + uint8_t* sbuf = scanline; if (TIFFReadScanline(in, scanline, row, s) < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read scanline %lu", - (unsigned long) row); + "Error, can't read scanline %"PRIu32, + row); status = 0; goto done; } @@ -1408,12 +1496,12 @@ DECLAREreadFunc(readContigTilesIntoBuffer) int status = 1; tsize_t tilesize = TIFFTileSize(in); tdata_t tilebuf; - uint32 imagew = TIFFScanlineSize(in); - uint32 tilew = TIFFTileRowSize(in); - int64 iskew = (int64)imagew - (int64)tilew; - uint8* bufp = (uint8*) buf; - uint32 tw, tl; - uint32 row; + uint32_t imagew = TIFFScanlineSize(in); + uint32_t tilew = TIFFTileRowSize(in); + int64_t iskew = (int64_t)imagew - (int64_t)tilew; + uint8_t* bufp = (uint8_t*) buf; + uint32_t tw, tl; + uint32_t row; (void) spp; tilebuf = limitMalloc(tilesize); @@ -1424,23 +1512,22 @@ DECLAREreadFunc(readContigTilesIntoBuffer) (void) TIFFGetField(in, TIFFTAG_TILELENGTH, &tl); for (row = 0; row < imagelength; row += tl) { - uint32 nrow = (row+tl > imagelength) ? imagelength-row : tl; - uint32 colb = 0; - uint32 col; + uint32_t nrow = (row + tl > imagelength) ? imagelength - row : tl; + uint32_t colb = 0; + uint32_t col; for (col = 0; col < imagewidth && colb < imagew; col += tw) { if (TIFFReadTile(in, tilebuf, col, row, 0, 0) < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read tile at %lu %lu", - (unsigned long) col, - (unsigned long) row); + "Error, can't read tile at %"PRIu32" %"PRIu32, + col, row); status = 0; goto done; } if (colb > iskew) { - uint32 width = imagew - colb; - uint32 oskew = tilew - width; + uint32_t width = imagew - colb; + uint32_t oskew = tilew - width; cpStripToTile(bufp + colb, tilebuf, nrow, width, oskew + iskew, oskew ); @@ -1460,15 +1547,15 @@ done: DECLAREreadFunc(readSeparateTilesIntoBuffer) { int status = 1; - uint32 imagew = TIFFRasterScanlineSize(in); - uint32 tilew = TIFFTileRowSize(in); + uint32_t imagew = TIFFRasterScanlineSize(in); + uint32_t tilew = TIFFTileRowSize(in); int iskew; tsize_t tilesize = TIFFTileSize(in); tdata_t tilebuf; - uint8* bufp = (uint8*) buf; - uint32 tw, tl; - uint32 row; - uint16 bps = 0, bytes_per_sample; + uint8_t* bufp = (uint8_t*) buf; + uint32_t tw, tl; + uint32_t row; + uint16_t bps = 0, bytes_per_sample; if (tilew && spp > (INT_MAX / tilew)) { @@ -1498,9 +1585,9 @@ DECLAREreadFunc(readSeparateTilesIntoBuffer) bytes_per_sample = bps/8; for (row = 0; row < imagelength; row += tl) { - uint32 nrow = (row+tl > imagelength) ? imagelength-row : tl; - uint32 colb = 0; - uint32 col; + uint32_t nrow = (row + tl > imagelength) ? imagelength - row : tl; + uint32_t colb = 0; + uint32_t col; for (col = 0; col < imagewidth; col += tw) { tsample_t s; @@ -1509,11 +1596,9 @@ DECLAREreadFunc(readSeparateTilesIntoBuffer) if (TIFFReadTile(in, tilebuf, col, row, 0, s) < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read tile at %lu %lu, " - "sample %lu", - (unsigned long) col, - (unsigned long) row, - (unsigned long) s); + "Error, can't read tile at %"PRIu32" %"PRIu32", " + "sample %"PRIu16, + col, row, s); status = 0; goto done; } @@ -1522,7 +1607,7 @@ DECLAREreadFunc(readSeparateTilesIntoBuffer) * visible portion and skewing factors. */ if (colb + tilew*spp > imagew) { - uint32 width = imagew - colb; + uint32_t width = imagew - colb; int oskew = tilew*spp - width; cpSeparateBufToContigBuf( bufp+colb+s*bytes_per_sample, @@ -1549,18 +1634,18 @@ done: DECLAREwriteFunc(writeBufferToContigStrips) { - uint32 row, rowsperstrip; + uint32_t row, rowsperstrip; tstrip_t strip = 0; (void) imagewidth; (void) spp; (void) TIFFGetFieldDefaulted(out, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); for (row = 0; row < imagelength; row += rowsperstrip) { - uint32 nrows = (row+rowsperstrip > imagelength) ? + uint32_t nrows = (row + rowsperstrip > imagelength) ? imagelength-row : rowsperstrip; tsize_t stripsize = TIFFVStripSize(out, nrows); if (TIFFWriteEncodedStrip(out, strip++, buf, stripsize) < 0) { TIFFError(TIFFFileName(out), - "Error, can't write strip %u", strip - 1); + "Error, can't write strip %"PRIu32, strip - 1u); return 0; } buf += stripsize; @@ -1570,8 +1655,8 @@ DECLAREwriteFunc(writeBufferToContigStrips) DECLAREwriteFunc(writeBufferToSeparateStrips) { - uint32 rowsize = imagewidth * spp; - uint32 rowsperstrip; + uint32_t rowsize = imagewidth * spp; + uint32_t rowsperstrip; tsize_t stripsize = TIFFStripSize(out); tdata_t obuf; tstrip_t strip = 0; @@ -1583,19 +1668,19 @@ DECLAREwriteFunc(writeBufferToSeparateStrips) _TIFFmemset(obuf, 0, stripsize); (void) TIFFGetFieldDefaulted(out, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); for (s = 0; s < spp; s++) { - uint32 row; + uint32_t row; for (row = 0; row < imagelength; row += rowsperstrip) { - uint32 nrows = (row+rowsperstrip > imagelength) ? + uint32_t nrows = (row + rowsperstrip > imagelength) ? imagelength-row : rowsperstrip; tsize_t stripsize = TIFFVStripSize(out, nrows); cpContigBufToSeparateBuf( - obuf, (uint8*) buf + row*rowsize + s, + obuf, (uint8_t*) buf + row * rowsize + s, nrows, imagewidth, 0, 0, spp, 1); if (TIFFWriteEncodedStrip(out, strip++, obuf, stripsize) < 0) { TIFFError(TIFFFileName(out), - "Error, can't write strip %u", - strip - 1); + "Error, can't write strip %"PRIu32, + strip - 1u); _TIFFfree(obuf); return 0; } @@ -1608,14 +1693,14 @@ DECLAREwriteFunc(writeBufferToSeparateStrips) DECLAREwriteFunc(writeBufferToContigTiles) { - uint32 imagew = TIFFScanlineSize(out); - uint32 tilew = TIFFTileRowSize(out); + uint32_t imagew = TIFFScanlineSize(out); + uint32_t tilew = TIFFTileRowSize(out); int iskew = imagew - tilew; tsize_t tilesize = TIFFTileSize(out); tdata_t obuf; - uint8* bufp = (uint8*) buf; - uint32 tl, tw; - uint32 row; + uint8_t* bufp = (uint8_t*) buf; + uint32_t tl, tw; + uint32_t row; (void) spp; @@ -1626,9 +1711,9 @@ DECLAREwriteFunc(writeBufferToContigTiles) (void) TIFFGetField(out, TIFFTAG_TILELENGTH, &tl); (void) TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw); for (row = 0; row < imagelength; row += tilelength) { - uint32 nrow = (row+tl > imagelength) ? imagelength-row : tl; - uint32 colb = 0; - uint32 col; + uint32_t nrow = (row + tl > imagelength) ? imagelength - row : tl; + uint32_t colb = 0; + uint32_t col; for (col = 0; col < imagewidth && colb < imagew; col += tw) { /* @@ -1636,7 +1721,7 @@ DECLAREwriteFunc(writeBufferToContigTiles) * visible portion and skewing factors. */ if (colb + tilew > imagew) { - uint32 width = imagew - colb; + uint32_t width = imagew - colb; int oskew = tilew - width; cpStripToTile(obuf, bufp + colb, nrow, width, oskew, oskew + iskew); @@ -1645,9 +1730,8 @@ DECLAREwriteFunc(writeBufferToContigTiles) 0, iskew); if (TIFFWriteTile(out, obuf, col, row, 0, 0) < 0) { TIFFError(TIFFFileName(out), - "Error, can't write tile at %lu %lu", - (unsigned long) col, - (unsigned long) row); + "Error, can't write tile at %"PRIu32" %"PRIu32, + col, row); _TIFFfree(obuf); return 0; } @@ -1661,16 +1745,16 @@ DECLAREwriteFunc(writeBufferToContigTiles) DECLAREwriteFunc(writeBufferToSeparateTiles) { - uint32 imagew = TIFFScanlineSize(out); + uint32_t imagew = TIFFScanlineSize(out); tsize_t tilew = TIFFTileRowSize(out); - uint32 iimagew = TIFFRasterScanlineSize(out); + uint32_t iimagew = TIFFRasterScanlineSize(out); int iskew = iimagew - tilew*spp; tsize_t tilesize = TIFFTileSize(out); tdata_t obuf; - uint8* bufp = (uint8*) buf; - uint32 tl, tw; - uint32 row; - uint16 bps = 0, bytes_per_sample; + uint8_t* bufp = (uint8_t*) buf; + uint32_t tl, tw; + uint32_t row; + uint16_t bps = 0, bytes_per_sample; obuf = limitMalloc(TIFFTileSize(out)); if (obuf == NULL) @@ -1694,9 +1778,9 @@ DECLAREwriteFunc(writeBufferToSeparateTiles) bytes_per_sample = bps/8; for (row = 0; row < imagelength; row += tl) { - uint32 nrow = (row+tl > imagelength) ? imagelength-row : tl; - uint32 colb = 0; - uint32 col; + uint32_t nrow = (row + tl > imagelength) ? imagelength - row : tl; + uint32_t colb = 0; + uint32_t col; for (col = 0; col < imagewidth; col += tw) { tsample_t s; @@ -1706,7 +1790,7 @@ DECLAREwriteFunc(writeBufferToSeparateTiles) * visible portion and skewing factors. */ if (colb + tilew > imagew) { - uint32 width = (imagew - colb); + uint32_t width = (imagew - colb); int oskew = tilew - width; cpContigBufToSeparateBuf(obuf, @@ -1722,11 +1806,9 @@ DECLAREwriteFunc(writeBufferToSeparateTiles) bytes_per_sample); if (TIFFWriteTile(out, obuf, col, row, 0, s) < 0) { TIFFError(TIFFFileName(out), - "Error, can't write tile at %lu %lu " - "sample %lu", - (unsigned long) col, - (unsigned long) row, - (unsigned long) s); + "Error, can't write tile at %"PRIu32" %"PRIu32 + " sample %"PRIu16, + col, row, s); _TIFFfree(obuf); return 0; } @@ -1875,10 +1957,10 @@ DECLAREcpFunc(cpSeparateTiles2SeparateStrips) * Select the appropriate copy function to use. */ static copyFunc -pickCopyFunc(TIFF* in, TIFF* out, uint16 bitspersample, uint16 samplesperpixel) +pickCopyFunc(TIFF* in, TIFF* out, uint16_t bitspersample, uint16_t samplesperpixel) { - uint16 shortv; - uint32 w, l, tw, tl; + uint16_t shortv; + uint32_t w, l, tw, tl; int bychunk; (void) TIFFGetFieldDefaulted(in, TIFFTAG_PLANARCONFIG, &shortv); @@ -1891,7 +1973,7 @@ pickCopyFunc(TIFF* in, TIFF* out, uint16 bitspersample, uint16 samplesperpixel) TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &w); TIFFGetField(in, TIFFTAG_IMAGELENGTH, &l); if (!(TIFFIsTiled(out) || TIFFIsTiled(in))) { - uint32 irps = (uint32) -1L; + uint32_t irps = (uint32_t) -1L; TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &irps); /* if biased, force decoded copying to allow image subtraction */ bychunk = !bias && (rowsperstrip == irps); diff --git a/tiff/tools/tiffcrop.c b/tiff/tools/tiffcrop.c index d20b585a..b85c2ce7 100644 --- a/tiff/tools/tiffcrop.c +++ b/tiff/tools/tiffcrop.c @@ -102,17 +102,19 @@ * includes annotations for image parameters and scanline info. Level * selects which functions dump data, with higher numbers selecting * lower level, scanline level routines. Debug reports a limited set - * of messages to monitor progess without enabling dump logs. + * of messages to monitor progress without enabling dump logs. */ static char tiffcrop_version_id[] = "2.4"; static char tiffcrop_rev_date[] = "12-13-2010"; #include "tif_config.h" +#include "libport.h" #include "tiffiop.h" #include <stdio.h> #include <stdlib.h> +#include <stdint.h> #include <string.h> #include <math.h> #include <ctype.h> @@ -124,10 +126,6 @@ static char tiffcrop_rev_date[] = "12-13-2010"; # include <unistd.h> #endif -#ifdef HAVE_STDINT_H -# include <stdint.h> -#endif - #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif @@ -135,32 +133,18 @@ static char tiffcrop_rev_date[] = "12-13-2010"; #define EXIT_FAILURE 1 #endif -#ifndef HAVE_GETOPT -extern int getopt(int argc, char * const argv[], const char *optstring); -#endif - -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffio.h" -#if defined(VMS) -# define unlink delete -#endif - #ifndef PATH_MAX #define PATH_MAX 1024 #endif -#define TIFF_UINT32_MAX 0xFFFFFFFFU - #define TRUE 1 #define FALSE 0 #ifndef TIFFhowmany -#define TIFFhowmany(x, y) ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y))) -#define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3) +#define TIFFhowmany(x, y) ((((uint32_t)(x))+(((uint32_t)(y))-1))/((uint32_t)(y))) +#define TIFFhowmany8(x) (((x)&0x07)?((uint32_t)(x)>>3)+1:(uint32_t)(x)>>3) #endif /* @@ -221,16 +205,16 @@ extern int getopt(int argc, char * const argv[], const char *optstring); /* Offsets into buffer for margins and fixed width and length segments */ struct offset { - uint32 tmargin; - uint32 lmargin; - uint32 bmargin; - uint32 rmargin; - uint32 crop_width; - uint32 crop_length; - uint32 startx; - uint32 endx; - uint32 starty; - uint32 endy; + uint32_t tmargin; + uint32_t lmargin; + uint32_t bmargin; + uint32_t rmargin; + uint32_t crop_width; + uint32_t crop_length; + uint32_t startx; + uint32_t endx; + uint32_t starty; + uint32_t endy; }; /* Description of a zone within the image. Position 1 of 3 zones would be @@ -240,7 +224,7 @@ struct offset { */ struct buffinfo { - uint32 size; /* size of this buffer */ + uint32_t size; /* size of this buffer */ unsigned char *buffer; /* address of the allocated buffer */ }; @@ -250,13 +234,13 @@ struct zone { }; struct pageseg { - uint32 x1; /* index of left edge */ - uint32 x2; /* index of right edge */ - uint32 y1; /* index of top edge */ - uint32 y2; /* index of bottom edge */ + uint32_t x1; /* index of left edge */ + uint32_t x2; /* index of right edge */ + uint32_t y1; /* index of top edge */ + uint32_t y2; /* index of bottom edge */ int position; /* ordinal of segment to be extracted */ int total; /* total equal sized divisions of crop area */ - uint32 buffsize; /* size of buffer needed to hold the cropped zone */ + uint32_t buffsize; /* size of buffer needed to hold the cropped zone */ }; struct coordpairs { @@ -267,13 +251,13 @@ struct coordpairs { }; struct region { - uint32 x1; /* pixel offset of left edge */ - uint32 x2; /* pixel offset of right edge */ - uint32 y1; /* pixel offset of top edge */ - uint32 y2; /* picel offset of bottom edge */ - uint32 width; /* width in pixels */ - uint32 length; /* length in pixels */ - uint32 buffsize; /* size of buffer needed to hold the cropped region */ + uint32_t x1; /* pixel offset of left edge */ + uint32_t x2; /* pixel offset of right edge */ + uint32_t y1; /* pixel offset of top edge */ + uint32_t y2; /* picel offset of bottom edge */ + uint32_t width; /* width in pixels */ + uint32_t length; /* length in pixels */ + uint32_t buffsize; /* size of buffer needed to hold the cropped region */ unsigned char *buffptr; /* address of start of the region */ }; @@ -287,27 +271,27 @@ struct crop_mask { double margins[4]; /* Top, left, bottom, right margins */ float xres; /* Horizontal resolution read from image*/ float yres; /* Vertical resolution read from image */ - uint32 combined_width; /* Width of combined cropped zones */ - uint32 combined_length; /* Length of combined cropped zones */ - uint32 bufftotal; /* Size of buffer needed to hold all the cropped region */ - uint16 img_mode; /* Composite or separate images created from zones or regions */ - uint16 exp_mode; /* Export input images or selections to one or more files */ - uint16 crop_mode; /* Crop options to be applied */ - uint16 res_unit; /* Resolution unit for margins and selections */ - uint16 edge_ref; /* Reference edge for sections extraction and combination */ - uint16 rotation; /* Clockwise rotation of the extracted region or image */ - uint16 mirror; /* Mirror extracted region or image horizontally or vertically */ - uint16 invert; /* Invert the color map of image or region */ - uint16 photometric; /* Status of photometric interpretation for inverted image */ - uint16 selections; /* Number of regions or zones selected */ - uint16 regions; /* Number of regions delimited by corner coordinates */ + uint32_t combined_width; /* Width of combined cropped zones */ + uint32_t combined_length; /* Length of combined cropped zones */ + uint32_t bufftotal; /* Size of buffer needed to hold all the cropped region */ + uint16_t img_mode; /* Composite or separate images created from zones or regions */ + uint16_t exp_mode; /* Export input images or selections to one or more files */ + uint16_t crop_mode; /* Crop options to be applied */ + uint16_t res_unit; /* Resolution unit for margins and selections */ + uint16_t edge_ref; /* Reference edge for sections extraction and combination */ + uint16_t rotation; /* Clockwise rotation of the extracted region or image */ + uint16_t mirror; /* Mirror extracted region or image horizontally or vertically */ + uint16_t invert; /* Invert the color map of image or region */ + uint16_t photometric; /* Status of photometric interpretation for inverted image */ + uint16_t selections; /* Number of regions or zones selected */ + uint16_t regions; /* Number of regions delimited by corner coordinates */ struct region regionlist[MAX_REGIONS]; /* Regions within page or master crop region */ - uint16 zones; /* Number of zones delimited by Ordinal:Total requested */ + uint16_t zones; /* Number of zones delimited by Ordinal:Total requested */ struct zone zonelist[MAX_REGIONS]; /* Zones indices to define a region */ struct coordpairs corners[MAX_REGIONS]; /* Coordinates of upper left and lower right corner */ }; -#define MAX_PAPERNAMES 49 +#define MAX_PAPERNAMES (sizeof(PaperTable)/sizeof(PaperTable[0])) /* was 49 */ #define MAX_PAPERNAME_LENGTH 15 #define DEFAULT_RESUNIT RESUNIT_INCH #define DEFAULT_PAGE_HEIGHT 14.0 @@ -340,7 +324,7 @@ struct paperdef { /* European page sizes corrected from update sent by * thomas . jarosch @ intra2net . com on 5/7/2010 * Paper Size Width Length Aspect Ratio */ -const struct paperdef PaperTable[MAX_PAPERNAMES] = { +static const struct paperdef PaperTable[/*MAX_PAPERNAMES*/] = { {"default", 8.500, 14.000, 0.607}, {"pa4", 8.264, 11.000, 0.751}, {"letter", 8.500, 11.000, 0.773}, @@ -396,16 +380,16 @@ const struct paperdef PaperTable[MAX_PAPERNAMES] = { struct image_data { float xres; float yres; - uint32 width; - uint32 length; - uint16 res_unit; - uint16 bps; - uint16 spp; - uint16 planar; - uint16 photometric; - uint16 orientation; - uint16 compression; - uint16 adjustments; + uint32_t width; + uint32_t length; + uint16_t res_unit; + uint16_t bps; + uint16_t spp; + uint16_t planar; + uint16_t photometric; + uint16_t orientation; + uint16_t compression; + uint16_t adjustments; }; /* Structure to define the output image modifiers */ @@ -417,8 +401,8 @@ struct pagedef { double vmargin; /* margins to subtract from height of sections */ double hres; /* horizontal resolution for output */ double vres; /* vertical resolution for output */ - uint32 mode; /* bitmask of modifiers to page format */ - uint16 res_unit; /* resolution unit for output image */ + uint32_t mode; /* bitmask of modifiers to page format */ + uint16_t res_unit; /* resolution unit for output image */ unsigned int rows; /* number of section rows */ unsigned int cols; /* number of section cols */ unsigned int orient; /* portrait, landscape, seascape, auto */ @@ -437,36 +421,36 @@ struct dump_opts { /* globals */ static int outtiled = -1; -static uint32 tilewidth = 0; -static uint32 tilelength = 0; - -static uint16 config = 0; -static uint16 compression = 0; -static uint16 predictor = 0; -static uint16 fillorder = 0; -static uint32 rowsperstrip = 0; -static uint32 g3opts = 0; +static uint32_t tilewidth = 0; +static uint32_t tilelength = 0; + +static uint16_t config = 0; +static uint16_t compression = 0; +static uint16_t predictor = 0; +static uint16_t fillorder = 0; +static uint32_t rowsperstrip = 0; +static uint32_t g3opts = 0; static int ignore = FALSE; /* if true, ignore read errors */ -static uint32 defg3opts = (uint32) -1; +static uint32_t defg3opts = (uint32_t) -1; static int quality = 100; /* JPEG quality */ /* static int jpegcolormode = -1; was JPEGCOLORMODE_RGB; */ static int jpegcolormode = JPEGCOLORMODE_RGB; -static uint16 defcompression = (uint16) -1; -static uint16 defpredictor = (uint16) -1; +static uint16_t defcompression = (uint16_t) -1; +static uint16_t defpredictor = (uint16_t) -1; static int pageNum = 0; static int little_endian = 1; /* Functions adapted from tiffcp with additions or significant modifications */ -static int readContigStripsIntoBuffer (TIFF*, uint8*); -static int readSeparateStripsIntoBuffer (TIFF*, uint8*, uint32, uint32, tsample_t, struct dump_opts *); -static int readContigTilesIntoBuffer (TIFF*, uint8*, uint32, uint32, uint32, uint32, tsample_t, uint16); -static int readSeparateTilesIntoBuffer (TIFF*, uint8*, uint32, uint32, uint32, uint32, tsample_t, uint16); -static int writeBufferToContigStrips (TIFF*, uint8*, uint32); -static int writeBufferToContigTiles (TIFF*, uint8*, uint32, uint32, tsample_t, struct dump_opts *); -static int writeBufferToSeparateStrips (TIFF*, uint8*, uint32, uint32, tsample_t, struct dump_opts *); -static int writeBufferToSeparateTiles (TIFF*, uint8*, uint32, uint32, tsample_t, struct dump_opts *); -static int extractContigSamplesToBuffer (uint8 *, uint8 *, uint32, uint32, tsample_t, - uint16, uint16, struct dump_opts *); +static int readContigStripsIntoBuffer (TIFF*, uint8_t*); +static int readSeparateStripsIntoBuffer (TIFF*, uint8_t*, uint32_t, uint32_t, tsample_t, struct dump_opts *); +static int readContigTilesIntoBuffer (TIFF*, uint8_t*, uint32_t, uint32_t, uint32_t, uint32_t, tsample_t, uint16_t); +static int readSeparateTilesIntoBuffer (TIFF*, uint8_t*, uint32_t, uint32_t, uint32_t, uint32_t, tsample_t, uint16_t); +static int writeBufferToContigStrips (TIFF*, uint8_t*, uint32_t); +static int writeBufferToContigTiles (TIFF*, uint8_t*, uint32_t, uint32_t, tsample_t, struct dump_opts *); +static int writeBufferToSeparateStrips (TIFF*, uint8_t*, uint32_t, uint32_t, tsample_t, struct dump_opts *); +static int writeBufferToSeparateTiles (TIFF*, uint8_t*, uint32_t, uint32_t, tsample_t, struct dump_opts *); +static int extractContigSamplesToBuffer (uint8_t *, uint8_t *, uint32_t, uint32_t, tsample_t, + uint16_t, uint16_t, struct dump_opts *); static int processCompressOptions(char*); static void usage(int code); @@ -477,10 +461,10 @@ static void initPageSetup (struct pagedef *, struct pageseg *, struct buffinfo [ static void initDumpOptions(struct dump_opts *); /* Command line and file naming functions */ -void process_command_opts (int, char *[], char *, char *, uint32 *, - uint16 *, uint16 *, uint32 *, uint32 *, uint32 *, - struct crop_mask *, struct pagedef *, - struct dump_opts *, +void process_command_opts (int, char *[], char *, char *, uint32_t *, + uint16_t *, uint16_t *, uint32_t *, uint32_t *, uint32_t *, + struct crop_mask *, struct pagedef *, + struct dump_opts *, unsigned int *, unsigned int *); static int update_output_file (TIFF **, char *, int, char *, unsigned int *); @@ -502,12 +486,12 @@ static int writeSelections(TIFF *, TIFF **, struct crop_mask *, struct image_da char *, char *, unsigned int*, unsigned int); /* Section functions */ -static int createImageSection(uint32, unsigned char **); +static int createImageSection(uint32_t, unsigned char **); static int extractImageSection(struct image_data *, struct pageseg *, unsigned char *, unsigned char *); static int writeSingleSection(TIFF *, TIFF *, struct image_data *, - struct dump_opts *, uint32, uint32, - double, double, unsigned char *); + struct dump_opts *, uint32_t, uint32_t, + double, double, unsigned char *); static int writeImageSections(TIFF *, TIFF *, struct image_data *, struct pagedef *, struct pageseg *, struct dump_opts *, unsigned char *, @@ -517,108 +501,108 @@ static int createCroppedImage(struct image_data *, struct crop_mask *, unsigned char **, unsigned char **); static int writeCroppedImage(TIFF *, TIFF *, struct image_data *image, struct dump_opts * dump, - uint32, uint32, unsigned char *, int, int); + uint32_t, uint32_t, unsigned char *, int, int); /* Image manipulation functions */ -static int rotateContigSamples8bits(uint16, uint16, uint16, uint32, - uint32, uint32, uint8 *, uint8 *); -static int rotateContigSamples16bits(uint16, uint16, uint16, uint32, - uint32, uint32, uint8 *, uint8 *); -static int rotateContigSamples24bits(uint16, uint16, uint16, uint32, - uint32, uint32, uint8 *, uint8 *); -static int rotateContigSamples32bits(uint16, uint16, uint16, uint32, - uint32, uint32, uint8 *, uint8 *); -static int rotateImage(uint16, struct image_data *, uint32 *, uint32 *, - unsigned char **); -static int mirrorImage(uint16, uint16, uint16, uint32, uint32, - unsigned char *); -static int invertImage(uint16, uint16, uint16, uint32, uint32, - unsigned char *); +static int rotateContigSamples8bits(uint16_t, uint16_t, uint16_t, uint32_t, + uint32_t, uint32_t, uint8_t *, uint8_t *); +static int rotateContigSamples16bits(uint16_t, uint16_t, uint16_t, uint32_t, + uint32_t, uint32_t, uint8_t *, uint8_t *); +static int rotateContigSamples24bits(uint16_t, uint16_t, uint16_t, uint32_t, + uint32_t, uint32_t, uint8_t *, uint8_t *); +static int rotateContigSamples32bits(uint16_t, uint16_t, uint16_t, uint32_t, + uint32_t, uint32_t, uint8_t *, uint8_t *); +static int rotateImage(uint16_t, struct image_data *, uint32_t *, uint32_t *, + unsigned char **); +static int mirrorImage(uint16_t, uint16_t, uint16_t, uint32_t, uint32_t, + unsigned char *); +static int invertImage(uint16_t, uint16_t, uint16_t, uint32_t, uint32_t, + unsigned char *); /* Functions to reverse the sequence of samples in a scanline */ -static int reverseSamples8bits (uint16, uint16, uint32, uint8 *, uint8 *); -static int reverseSamples16bits (uint16, uint16, uint32, uint8 *, uint8 *); -static int reverseSamples24bits (uint16, uint16, uint32, uint8 *, uint8 *); -static int reverseSamples32bits (uint16, uint16, uint32, uint8 *, uint8 *); -static int reverseSamplesBytes (uint16, uint16, uint32, uint8 *, uint8 *); +static int reverseSamples8bits (uint16_t, uint16_t, uint32_t, uint8_t *, uint8_t *); +static int reverseSamples16bits (uint16_t, uint16_t, uint32_t, uint8_t *, uint8_t *); +static int reverseSamples24bits (uint16_t, uint16_t, uint32_t, uint8_t *, uint8_t *); +static int reverseSamples32bits (uint16_t, uint16_t, uint32_t, uint8_t *, uint8_t *); +static int reverseSamplesBytes (uint16_t, uint16_t, uint32_t, uint8_t *, uint8_t *); /* Functions for manipulating individual samples in an image */ static int extractSeparateRegion(struct image_data *, struct crop_mask *, unsigned char *, unsigned char *, int); static int extractCompositeRegions(struct image_data *, struct crop_mask *, unsigned char *, unsigned char *); -static int extractContigSamples8bits (uint8 *, uint8 *, uint32, - tsample_t, uint16, uint16, - tsample_t, uint32, uint32); -static int extractContigSamples16bits (uint8 *, uint8 *, uint32, - tsample_t, uint16, uint16, - tsample_t, uint32, uint32); -static int extractContigSamples24bits (uint8 *, uint8 *, uint32, - tsample_t, uint16, uint16, - tsample_t, uint32, uint32); -static int extractContigSamples32bits (uint8 *, uint8 *, uint32, - tsample_t, uint16, uint16, - tsample_t, uint32, uint32); -static int extractContigSamplesBytes (uint8 *, uint8 *, uint32, - tsample_t, uint16, uint16, - tsample_t, uint32, uint32); -static int extractContigSamplesShifted8bits (uint8 *, uint8 *, uint32, - tsample_t, uint16, uint16, - tsample_t, uint32, uint32, +static int extractContigSamples8bits (uint8_t *, uint8_t *, uint32_t, + tsample_t, uint16_t, uint16_t, + tsample_t, uint32_t, uint32_t); +static int extractContigSamples16bits (uint8_t *, uint8_t *, uint32_t, + tsample_t, uint16_t, uint16_t, + tsample_t, uint32_t, uint32_t); +static int extractContigSamples24bits (uint8_t *, uint8_t *, uint32_t, + tsample_t, uint16_t, uint16_t, + tsample_t, uint32_t, uint32_t); +static int extractContigSamples32bits (uint8_t *, uint8_t *, uint32_t, + tsample_t, uint16_t, uint16_t, + tsample_t, uint32_t, uint32_t); +static int extractContigSamplesBytes (uint8_t *, uint8_t *, uint32_t, + tsample_t, uint16_t, uint16_t, + tsample_t, uint32_t, uint32_t); +static int extractContigSamplesShifted8bits (uint8_t *, uint8_t *, uint32_t, + tsample_t, uint16_t, uint16_t, + tsample_t, uint32_t, uint32_t, int); -static int extractContigSamplesShifted16bits (uint8 *, uint8 *, uint32, - tsample_t, uint16, uint16, - tsample_t, uint32, uint32, +static int extractContigSamplesShifted16bits (uint8_t *, uint8_t *, uint32_t, + tsample_t, uint16_t, uint16_t, + tsample_t, uint32_t, uint32_t, int); -static int extractContigSamplesShifted24bits (uint8 *, uint8 *, uint32, - tsample_t, uint16, uint16, - tsample_t, uint32, uint32, +static int extractContigSamplesShifted24bits (uint8_t *, uint8_t *, uint32_t, + tsample_t, uint16_t, uint16_t, + tsample_t, uint32_t, uint32_t, int); -static int extractContigSamplesShifted32bits (uint8 *, uint8 *, uint32, - tsample_t, uint16, uint16, - tsample_t, uint32, uint32, +static int extractContigSamplesShifted32bits (uint8_t *, uint8_t *, uint32_t, + tsample_t, uint16_t, uint16_t, + tsample_t, uint32_t, uint32_t, int); -static int extractContigSamplesToTileBuffer(uint8 *, uint8 *, uint32, uint32, - uint32, uint32, tsample_t, uint16, - uint16, uint16, struct dump_opts *); +static int extractContigSamplesToTileBuffer(uint8_t *, uint8_t *, uint32_t, uint32_t, + uint32_t, uint32_t, tsample_t, uint16_t, + uint16_t, uint16_t, struct dump_opts *); /* Functions to combine separate planes into interleaved planes */ -static int combineSeparateSamples8bits (uint8 *[], uint8 *, uint32, uint32, - uint16, uint16, FILE *, int, int); -static int combineSeparateSamples16bits (uint8 *[], uint8 *, uint32, uint32, - uint16, uint16, FILE *, int, int); -static int combineSeparateSamples24bits (uint8 *[], uint8 *, uint32, uint32, - uint16, uint16, FILE *, int, int); -static int combineSeparateSamples32bits (uint8 *[], uint8 *, uint32, uint32, - uint16, uint16, FILE *, int, int); +static int combineSeparateSamples8bits (uint8_t *[], uint8_t *, uint32_t, uint32_t, + uint16_t, uint16_t, FILE *, int, int); +static int combineSeparateSamples16bits (uint8_t *[], uint8_t *, uint32_t, uint32_t, + uint16_t, uint16_t, FILE *, int, int); +static int combineSeparateSamples24bits (uint8_t *[], uint8_t *, uint32_t, uint32_t, + uint16_t, uint16_t, FILE *, int, int); +static int combineSeparateSamples32bits (uint8_t *[], uint8_t *, uint32_t, uint32_t, + uint16_t, uint16_t, FILE *, int, int); static int combineSeparateSamplesBytes (unsigned char *[], unsigned char *, - uint32, uint32, tsample_t, uint16, + uint32_t, uint32_t, tsample_t, uint16_t, FILE *, int, int); -static int combineSeparateTileSamples8bits (uint8 *[], uint8 *, uint32, uint32, - uint32, uint32, uint16, uint16, +static int combineSeparateTileSamples8bits (uint8_t *[], uint8_t *, uint32_t, uint32_t, + uint32_t, uint32_t, uint16_t, uint16_t, FILE *, int, int); -static int combineSeparateTileSamples16bits (uint8 *[], uint8 *, uint32, uint32, - uint32, uint32, uint16, uint16, +static int combineSeparateTileSamples16bits (uint8_t *[], uint8_t *, uint32_t, uint32_t, + uint32_t, uint32_t, uint16_t, uint16_t, FILE *, int, int); -static int combineSeparateTileSamples24bits (uint8 *[], uint8 *, uint32, uint32, - uint32, uint32, uint16, uint16, +static int combineSeparateTileSamples24bits (uint8_t *[], uint8_t *, uint32_t, uint32_t, + uint32_t, uint32_t, uint16_t, uint16_t, FILE *, int, int); -static int combineSeparateTileSamples32bits (uint8 *[], uint8 *, uint32, uint32, - uint32, uint32, uint16, uint16, +static int combineSeparateTileSamples32bits (uint8_t *[], uint8_t *, uint32_t, uint32_t, + uint32_t, uint32_t, uint16_t, uint16_t, FILE *, int, int); static int combineSeparateTileSamplesBytes (unsigned char *[], unsigned char *, - uint32, uint32, uint32, uint32, - tsample_t, uint16, FILE *, int, int); + uint32_t, uint32_t, uint32_t, uint32_t, + tsample_t, uint16_t, FILE *, int, int); /* Dump functions for debugging */ static void dump_info (FILE *, int, char *, char *, ...); -static int dump_data (FILE *, int, char *, unsigned char *, uint32); +static int dump_data (FILE *, int, char *, unsigned char *, uint32_t); static int dump_byte (FILE *, int, char *, unsigned char); -static int dump_short (FILE *, int, char *, uint16); -static int dump_long (FILE *, int, char *, uint32); -static int dump_wide (FILE *, int, char *, uint64); -static int dump_buffer (FILE *, int, uint32, uint32, uint32, unsigned char *); +static int dump_short (FILE *, int, char *, uint16_t); +static int dump_long (FILE *, int, char *, uint32_t); +static int dump_wide (FILE *, int, char *, uint64_t); +static int dump_buffer (FILE *, int, uint32_t, uint32_t, uint32_t, unsigned char *); /* End function declarations */ /* Functions derived in whole or in part from tiffcp */ @@ -636,8 +620,8 @@ static tmsize_t maxMalloc = DEFAULT_MAX_MALLOC; static void* limitMalloc(tmsize_t s) { if (maxMalloc && (s > maxMalloc)) { - fprintf(stderr, "MemoryLimitError: allocation of " TIFF_UINT64_FORMAT " bytes is forbidden. Limit is " TIFF_UINT64_FORMAT ".\n", - (uint64)s, (uint64)maxMalloc); + fprintf(stderr, "MemoryLimitError: allocation of %" PRIu64 " bytes is forbidden. Limit is %" PRIu64 ".\n", + (uint64_t)s, (uint64_t)maxMalloc); fprintf(stderr, " use -k option to change limit.\n"); return NULL; } return _TIFFmalloc(s); @@ -645,165 +629,176 @@ static void* limitMalloc(tmsize_t s) -static const char* usage_info[] = { -"usage: tiffcrop [options] source1 ... sourceN destination", -"where options are:", -" -h Print this syntax listing", -" -v Print tiffcrop version identifier and last revision date", -" ", -" -a Append to output instead of overwriting", -" -d offset Set initial directory offset, counting first image as one, not zero", -" -p contig Pack samples contiguously (e.g. RGBRGB...)", -" -p separate Store samples separately (e.g. RRR...GGG...BBB...)", -" -s Write output in strips", -" -t Write output in tiles", -" -i Ignore read errors", -" -k size set the memory allocation limit in MiB. 0 to disable limit", -" ", -" -r # Make each strip have no more than # rows", -" -w # Set output tile width (pixels)", -" -l # Set output tile length (pixels)", -" ", -" -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 g3[:opts] Compress output with CCITT Group 3 encoding", -" -c g4 Compress output with CCITT Group 4 encoding", -" -c none Use no compression algorithm on output", -" ", -"Group 3 options:", -" 1d Use default CCITT Group 3 1D-encoding", -" 2d Use optional CCITT Group 3 2D-encoding", -" fill Byte-align EOL codes", -"For example, -c g3:2d:fill to get G3-2D-encoded data with byte-aligned EOLs", -" ", -"JPEG options:", -" # Set compression quality level (0-100, default 100)", -" raw Output color image as raw YCbCr", -" rgb Output color image as RGB", -"For example, -c jpeg:rgb: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", -" ", -"Page and selection options:", -" -N odd|even|#,#-#,#|last sequences and ranges of images within file to process", -" The words odd or even may be used to specify all odd or even numbered images.", -" The word last may be used in place of a number in the sequence to indicate.", -" The final image in the file without knowing how many images there are.", -" Numbers are counted from one even though TIFF IFDs are counted from zero.", -" ", -" -E t|l|r|b edge to use as origin for width and length of crop region", -" -U units [in, cm, px ] inches, centimeters or pixels", -" ", -" -m #,#,#,# margins from edges for selection: top, left, bottom, right separated by commas", -" -X # horizontal dimension of region to extract expressed in current units", -" -Y # vertical dimension of region to extract expressed in current units", -" -Z #:#,#:# zones of the image designated as position X of Y,", -" eg 1:3 would be first of three equal portions measured from reference edge", -" -z x1,y1,x2,y2:...:xN,yN,xN+1,yN+1", -" regions of the image designated by upper left and lower right coordinates", -"", -"Export grouping options:", -" -e c|d|i|m|s export mode for images and selections from input images.", -" When exporting a composite image from multiple zones or regions", -" (combined and image modes), the selections must have equal sizes", -" for the axis perpendicular to the edge specified with -E.", -" c|combined All images and selections are written to a single file (default).", -" with multiple selections from one image combined into a single image.", -" d|divided All images and selections are written to a single file", -" with each selection from one image written to a new image.", -" i|image Each input image is written to a new file (numeric filename sequence)", -" with multiple selections from the image combined into one image.", -" m|multiple Each input image is written to a new file (numeric filename sequence)", -" with each selection from the image written to a new image.", -" s|separated Individual selections from each image are written to separate files.", -"", -"Output options:", -" -H # Set horizontal resolution of output images to #", -" -V # Set vertical resolution of output images to #", -" -J # Set horizontal margin of output page to # expressed in current units", -" when sectioning image into columns x rows using the -S cols:rows option", -" -K # Set verticalal margin of output page to # expressed in current units", -" when sectioning image into columns x rows using the -S cols:rows option", -" ", -" -O orient orientation for output image, portrait, landscape, auto", -" -P page page size for output image segments, eg letter, legal, tabloid, etc", -" use #.#x#.# to specify a custom page size in the currently defined units", -" where #.# represents the width and length", -" -S cols:rows Divide the image into equal sized segments using cols across and rows down.", -" ", -" -F hor|vert|both", -" flip (mirror) image or region horizontally, vertically, or both", -" -R # [90,180,or 270] degrees clockwise rotation of image or extracted region", -" -I [black|white|data|both]", -" invert color space, eg dark to light for bilevel and grayscale images", -" If argument is white or black, set the PHOTOMETRIC_INTERPRETATION ", -" tag to MinIsBlack or MinIsWhite without altering the image data", -" If the argument is data or both, the image data are modified:", -" both inverts the data and the PHOTOMETRIC_INTERPRETATION tag,", -" data inverts the data but not the PHOTOMETRIC_INTERPRETATION tag", -" ", -"-D opt1:value1,opt2:value2,opt3:value3:opt4:value4", -" Debug/dump program progress and/or data to non-TIFF files.", -" Options include the following and must be joined as a comma", -" separate list. The use of this option is generally limited to", -" program debugging and development of future options.", -" ", -" debug:N Display limited program progress indicators where larger N", -" increase the level of detail. Note: Tiffcrop may be compiled with", -" -DDEVELMODE to enable additional very low level debug reporting.", -"", -" Format:txt|raw Format any logged data as ASCII text or raw binary ", -" values. ASCII text dumps include strings of ones and zeroes", -" representing the binary values in the image data plus identifying headers.", -" ", -" level:N Specify the level of detail presented in the dump files.", -" This can vary from dumps of the entire input or output image data to dumps", -" of data processed by specific functions. Current range of levels is 1 to 3.", -" ", -" input:full-path-to-directory/input-dumpname", -" ", -" output:full-path-to-directory/output-dumpnaem", -" ", -" When dump files are being written, each image will be written to a separate", -" file with the name built by adding a numeric sequence value to the dumpname", -" and an extension of .txt for ASCII dumps or .bin for binary dumps.", -" ", -" The four debug/dump options are independent, though it makes little sense to", -" specify a dump file without specifying a detail level.", -" ", -NULL -}; +static const char usage_info[] = +"Copy, crop, convert, extract, and/or process TIFF files\n\n" +"usage: tiffcrop [options] source1 ... sourceN destination\n" +"where options are:\n" +" -h Print this syntax listing\n" +" -v Print tiffcrop version identifier and last revision date\n" +" \n" +" -a Append to output instead of overwriting\n" +" -d offset Set initial directory offset, counting first image as one, not zero\n" +" -p contig Pack samples contiguously (e.g. RGBRGB...)\n" +" -p separate Store samples separately (e.g. RRR...GGG...BBB...)\n" +" -s Write output in strips\n" +" -t Write output in tiles\n" +" -i Ignore read errors\n" +" -k size set the memory allocation limit in MiB. 0 to disable limit\n" +" \n" +" -r # Make each strip have no more than # rows\n" +" -w # Set output tile width (pixels)\n" +" -l # Set output tile length (pixels)\n" +" \n" +" -f lsb2msb Force lsb-to-msb FillOrder for output\n" +" -f msb2lsb Force msb-to-lsb FillOrder for output\n" +"\n" +#ifdef LZW_SUPPORT +" -c lzw[:opts] Compress output with Lempel-Ziv & Welch encoding\n" +/* " LZW options:\n" */ +" # Set predictor value\n" +" For example, -c lzw:2 for LZW-encoded data with horizontal differencing\n" +#endif +#ifdef ZIP_SUPPORT +" -c zip[:opts] Compress output with deflate encoding\n" +/* " Deflate (ZIP) options:\n" */ +" # Set predictor value\n" +#endif +#ifdef JPEG_SUPPORT +" -c jpeg[:opts] Compress output with JPEG encoding\n" +/* " JPEG options:\n" */ +" # Set compression quality level (0-100, default 100)\n" +" raw Output color image as raw YCbCr (default)\n" +" rgb Output color image as RGB\n" +" For example, -c jpeg:rgb:50 for JPEG-encoded RGB with 50% comp. quality\n" +#endif +#ifdef PACKBITS_SUPPORT +" -c packbits Compress output with packbits encoding\n" +#endif +#ifdef CCITT_SUPPORT +" -c g3[:opts] Compress output with CCITT Group 3 encoding\n" +/* " CCITT Group 3 options:\n" */ +" 1d Use default CCITT Group 3 1D-encoding\n" +" 2d Use optional CCITT Group 3 2D-encoding\n" +" fill Byte-align EOL codes\n" +" For example, -c g3:2d:fill for G3-2D-encoded data with byte-aligned EOLs\n" +" -c g4 Compress output with CCITT Group 4 encoding\n" +#endif +#if defined(LZW_SUPPORT) || defined(ZIP_SUPPORT) || defined(JPEG_SUPPORT) || defined(PACKBITS_SUPPORT) || defined(CCITT_SUPPORT) +" -c none Use no compression algorithm on output\n" +#endif +"\n" +"Page and selection options:\n" +" -N odd|even|#,#-#,#|last sequences and ranges of images within file to process\n" +" The words odd or even may be used to specify all odd or even numbered images.\n" +" The word last may be used in place of a number in the sequence to indicate.\n" +" The final image in the file without knowing how many images there are.\n" +" Numbers are counted from one even though TIFF IFDs are counted from zero.\n" +"\n" +" -E t|l|r|b edge to use as origin for width and length of crop region\n" +" -U units [in, cm, px ] inches, centimeters or pixels\n" +" \n" +" -m #,#,#,# margins from edges for selection: top, left, bottom, right separated by commas\n" +" -X # horizontal dimension of region to extract expressed in current units\n" +" -Y # vertical dimension of region to extract expressed in current units\n" +" -Z #:#,#:# zones of the image designated as position X of Y,\n" +" eg 1:3 would be first of three equal portions measured from reference edge\n" +" -z x1,y1,x2,y2:...:xN,yN,xN+1,yN+1\n" +" regions of the image designated by upper left and lower right coordinates\n" +"\n" +"Export grouping options:\n" +" -e c|d|i|m|s export mode for images and selections from input images.\n" +" When exporting a composite image from multiple zones or regions\n" +" (combined and image modes), the selections must have equal sizes\n" +" for the axis perpendicular to the edge specified with -E.\n" +" c|combined All images and selections are written to a single file (default).\n" +" with multiple selections from one image combined into a single image.\n" +" d|divided All images and selections are written to a single file\n" +" with each selection from one image written to a new image.\n" +" i|image Each input image is written to a new file (numeric filename sequence)\n" +" with multiple selections from the image combined into one image.\n" +" m|multiple Each input image is written to a new file (numeric filename sequence)\n" +" with each selection from the image written to a new image.\n" +" s|separated Individual selections from each image are written to separate files.\n" +"\n" +"Output options:\n" +" -H # Set horizontal resolution of output images to #\n" +" -V # Set vertical resolution of output images to #\n" +" -J # Set horizontal margin of output page to # expressed in current units\n" +" when sectioning image into columns x rows using the -S cols:rows option\n" +" -K # Set verticalal margin of output page to # expressed in current units\n" +" when sectioning image into columns x rows using the -S cols:rows option\n" +" \n" +" -O orient orientation for output image, portrait, landscape, auto\n" +" -P page page size for output image segments, eg letter, legal, tabloid, etc\n" +" use #.#x#.# to specify a custom page size in the currently defined units\n" +" where #.# represents the width and length\n" +" -S cols:rows Divide the image into equal sized segments using cols across and rows down.\n" +"\n" +" -F hor|vert|both\n" +" flip (mirror) image or region horizontally, vertically, or both\n" +" -R # [90,180,or 270] degrees clockwise rotation of image or extracted region\n" +" -I [black|white|data|both]\n" +" invert color space, eg dark to light for bilevel and grayscale images\n" +" If argument is white or black, set the PHOTOMETRIC_INTERPRETATION \n" +" tag to MinIsBlack or MinIsWhite without altering the image data\n" +" If the argument is data or both, the image data are modified:\n" +" both inverts the data and the PHOTOMETRIC_INTERPRETATION tag,\n" +" data inverts the data but not the PHOTOMETRIC_INTERPRETATION tag\n" +"\n" +"-D opt1:value1,opt2:value2,opt3:value3:opt4:value4\n" +" Debug/dump program progress and/or data to non-TIFF files.\n" +" Options include the following and must be joined as a comma\n" +" separate list. The use of this option is generally limited to\n" +" program debugging and development of future options.\n" +"\n" +" debug:N Display limited program progress indicators where larger N\n" +" increase the level of detail. Note: Tiffcrop may be compiled with\n" +" -DDEVELMODE to enable additional very low level debug reporting.\n" +"\n" +" Format:txt|raw Format any logged data as ASCII text or raw binary \n" +" values. ASCII text dumps include strings of ones and zeroes\n" +" representing the binary values in the image data plus identifying headers.\n" +"\n" +" level:N Specify the level of detail presented in the dump files.\n" +" This can vary from dumps of the entire input or output image data to dumps\n" +" of data processed by specific functions. Current range of levels is 1 to 3.\n" +"\n" +" input:full-path-to-directory/input-dumpname\n" +"\n" +" output:full-path-to-directory/output-dumpnaem\n" +"\n" +" When dump files are being written, each image will be written to a separate\n" +" file with the name built by adding a numeric sequence value to the dumpname\n" +" and an extension of .txt for ASCII dumps or .bin for binary dumps.\n" +"\n" +" The four debug/dump options are independent, though it makes little sense to\n" +" specify a dump file without specifying a detail level.\n" +"\n" +; /* This function could be modified to pass starting sample offset * and number of samples as args to select fewer than spp * from input image. These would then be passed to individual * extractContigSampleXX routines. */ -static int readContigTilesIntoBuffer (TIFF* in, uint8* buf, - uint32 imagelength, - uint32 imagewidth, - uint32 tw, uint32 tl, - tsample_t spp, uint16 bps) +static int readContigTilesIntoBuffer (TIFF* in, uint8_t* buf, + uint32_t imagelength, + uint32_t imagewidth, + uint32_t tw, uint32_t tl, + tsample_t spp, uint16_t bps) { int status = 1; tsample_t sample = 0; tsample_t count = spp; - uint32 row, col, trow; - uint32 nrow, ncol; - uint32 dst_rowsize, shift_width; - uint32 bytes_per_sample, bytes_per_pixel; - uint32 trailing_bits, prev_trailing_bits; - uint32 tile_rowsize = TIFFTileRowSize(in); - uint32 src_offset, dst_offset; - uint32 row_offset, col_offset; - uint8 *bufp = (uint8*) buf; + uint32_t row, col, trow; + uint32_t nrow, ncol; + uint32_t dst_rowsize, shift_width; + uint32_t bytes_per_sample, bytes_per_pixel; + uint32_t trailing_bits, prev_trailing_bits; + uint32_t tile_rowsize = TIFFTileRowSize(in); + uint32_t src_offset, dst_offset; + uint32_t row_offset, col_offset; + uint8_t *bufp = (uint8_t*) buf; unsigned char *src = NULL; unsigned char *dst = NULL; tsize_t tbytes = 0, tile_buffsize = 0; @@ -834,7 +829,7 @@ static int readContigTilesIntoBuffer (TIFF* in, uint8* buf, { #ifdef DEBUG2 TIFFError("readContigTilesIntoBuffer", - "Tilesize %lu is too small, using alternate calculation %u", + "Tilesize %"PRId64" is too small, using alternate calculation %"PRIu64, tilesize, tl * tile_rowsize); #endif tile_buffsize = tl * tile_rowsize; @@ -868,9 +863,8 @@ static int readContigTilesIntoBuffer (TIFF* in, uint8* buf, if (tbytes < tilesize && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read tile at row %lu col %lu, Read %lu bytes of %lu", - (unsigned long) col, (unsigned long) row, (unsigned long)tbytes, - (unsigned long)tilesize); + "Error, can't read tile at row %"PRIu32" col %"PRIu32", Read %"TIFF_SSIZE_FORMAT" bytes of %"TIFF_SSIZE_FORMAT, + col, row, tbytes, tilesize); status = 0; _TIFFfree(tilebuf); return status; @@ -919,8 +913,8 @@ static int readContigTilesIntoBuffer (TIFF* in, uint8* buf, spp, bps, count, 0, ncol)) { TIFFError("readContigTilesIntoBuffer", - "Unable to extract row %d from tile %lu", - row, (unsigned long)TIFFCurrentTile(in)); + "Unable to extract row %"PRIu32" from tile %"PRIu32, + row, TIFFCurrentTile(in)); return 1; } break; @@ -933,8 +927,8 @@ static int readContigTilesIntoBuffer (TIFF* in, uint8* buf, prev_trailing_bits)) { TIFFError("readContigTilesIntoBuffer", - "Unable to extract row %d from tile %lu", - row, (unsigned long)TIFFCurrentTile(in)); + "Unable to extract row %"PRIu32" from tile %"PRIu32, + row, TIFFCurrentTile(in)); return 1; } break; @@ -947,8 +941,8 @@ static int readContigTilesIntoBuffer (TIFF* in, uint8* buf, prev_trailing_bits)) { TIFFError("readContigTilesIntoBuffer", - "Unable to extract row %d from tile %lu", - row, (unsigned long)TIFFCurrentTile(in)); + "Unable to extract row %"PRIu32" from tile %"PRIu32, + row, TIFFCurrentTile(in)); return 1; } break; @@ -959,8 +953,8 @@ static int readContigTilesIntoBuffer (TIFF* in, uint8* buf, prev_trailing_bits)) { TIFFError("readContigTilesIntoBuffer", - "Unable to extract row %d from tile %lu", - row, (unsigned long)TIFFCurrentTile(in)); + "Unable to extract row %"PRIu32" from tile %"PRIu32, + row, TIFFCurrentTile(in)); return 1; } break; @@ -973,12 +967,12 @@ static int readContigTilesIntoBuffer (TIFF* in, uint8* buf, prev_trailing_bits)) { TIFFError("readContigTilesIntoBuffer", - "Unable to extract row %d from tile %lu", - row, (unsigned long)TIFFCurrentTile(in)); + "Unable to extract row %"PRIu32" from tile %"PRIu32, + row, TIFFCurrentTile(in)); return 1; } break; - default: TIFFError("readContigTilesIntoBuffer", "Unsupported bit depth %d", bps); + default: TIFFError("readContigTilesIntoBuffer", "Unsupported bit depth %"PRIu16, bps); return 1; } } @@ -993,20 +987,20 @@ static int readContigTilesIntoBuffer (TIFF* in, uint8* buf, return status; } -static int readSeparateTilesIntoBuffer (TIFF* in, uint8 *obuf, - uint32 imagelength, uint32 imagewidth, - uint32 tw, uint32 tl, - uint16 spp, uint16 bps) +static int readSeparateTilesIntoBuffer (TIFF* in, uint8_t *obuf, + uint32_t imagelength, uint32_t imagewidth, + uint32_t tw, uint32_t tl, + uint16_t spp, uint16_t bps) { int i, status = 1, sample; int shift_width, bytes_per_pixel; - uint16 bytes_per_sample; - uint32 row, col; /* Current row and col of image */ - uint32 nrow, ncol; /* Number of rows and cols in current tile */ - uint32 row_offset, col_offset; /* Output buffer offsets */ + uint16_t bytes_per_sample; + uint32_t row, col; /* Current row and col of image */ + uint32_t nrow, ncol; /* Number of rows and cols in current tile */ + uint32_t row_offset, col_offset; /* Output buffer offsets */ tsize_t tbytes = 0, tilesize = TIFFTileSize(in); tsample_t s; - uint8* bufp = (uint8*)obuf; + uint8_t* bufp = (uint8_t*)obuf; unsigned char *srcbuffs[MAX_SAMPLES]; unsigned char *tbuff = NULL; @@ -1040,10 +1034,9 @@ static int readSeparateTilesIntoBuffer (TIFF* in, uint8 *obuf, if (tbytes < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read tile for row %lu col %lu, " - "sample %lu", - (unsigned long) col, (unsigned long) row, - (unsigned long) s); + "Error, can't read tile for row %"PRIu32" col %"PRIu32", " + "sample %"PRIu16, + col, row, s); status = 0; for (sample = 0; (sample < spp) && (sample < MAX_SAMPLES); sample++) { @@ -1122,7 +1115,7 @@ static int readSeparateTilesIntoBuffer (TIFF* in, uint8 *obuf, break; } break; - default: TIFFError ("readSeparateTilesIntoBuffer", "Unsupported bit depth: %d", bps); + default: TIFFError ("readSeparateTilesIntoBuffer", "Unsupported bit depth: %"PRIu16, bps); status = 0; break; } @@ -1140,9 +1133,9 @@ static int readSeparateTilesIntoBuffer (TIFF* in, uint8 *obuf, return status; } -static int writeBufferToContigStrips(TIFF* out, uint8* buf, uint32 imagelength) +static int writeBufferToContigStrips(TIFF* out, uint8_t* buf, uint32_t imagelength) { - uint32 row, nrows, rowsperstrip; + uint32_t row, nrows, rowsperstrip; tstrip_t strip = 0; tsize_t stripsize; @@ -1154,7 +1147,7 @@ static int writeBufferToContigStrips(TIFF* out, uint8* buf, uint32 imagelength) stripsize = TIFFVStripSize(out, nrows); if (TIFFWriteEncodedStrip(out, strip++, buf, stripsize) < 0) { - TIFFError(TIFFFileName(out), "Error, can't write strip %u", strip - 1); + TIFFError(TIFFFileName(out), "Error, can't write strip %"PRIu32, strip - 1); return 1; } buf += stripsize; @@ -1172,14 +1165,14 @@ static int writeBufferToContigStrips(TIFF* out, uint8* buf, uint32 imagelength) * before any strips or tiles of a different plane are stored. */ static int -writeBufferToSeparateStrips (TIFF* out, uint8* buf, - uint32 length, uint32 width, uint16 spp, - struct dump_opts *dump) +writeBufferToSeparateStrips (TIFF* out, uint8_t* buf, + uint32_t length, uint32_t width, uint16_t spp, + struct dump_opts *dump) { - uint8 *src; - uint16 bps; - uint32 row, nrows, rowsize, rowsperstrip; - uint32 bytes_per_sample; + uint8_t *src; + uint16_t bps; + uint32_t row, nrows, rowsize, rowsperstrip; + uint32_t bytes_per_sample; tsample_t s; tstrip_t strip = 0; tsize_t stripsize = TIFFStripSize(out); @@ -1191,20 +1184,20 @@ writeBufferToSeparateStrips (TIFF* out, uint8* buf, (void) TIFFGetFieldDefaulted(out, TIFFTAG_BITSPERSAMPLE, &bps); bytes_per_sample = (bps + 7) / 8; if( width == 0 || - (uint32)bps * (uint32)spp > TIFF_UINT32_MAX / width || - bps * spp * width > TIFF_UINT32_MAX - 7U ) + (uint32_t)bps * (uint32_t)spp > UINT32_MAX / width || + bps * spp * width > UINT32_MAX - 7U ) { TIFFError(TIFFFileName(out), - "Error, uint32 overflow when computing (bps * spp * width) + 7"); + "Error, uint32_t overflow when computing (bps * spp * width) + 7"); return 1; } rowsize = ((bps * spp * width) + 7U) / 8; /* source has interleaved samples */ if( bytes_per_sample == 0 || - rowsperstrip > TIFF_UINT32_MAX / bytes_per_sample || - rowsperstrip * bytes_per_sample > TIFF_UINT32_MAX / (width + 1) ) + rowsperstrip > UINT32_MAX / bytes_per_sample || + rowsperstrip * bytes_per_sample > UINT32_MAX / (width + 1) ) { TIFFError(TIFFFileName(out), - "Error, uint32 overflow when computing rowsperstrip * " + "Error, uint32_t overflow when computing rowsperstrip * " "bytes_per_sample * (width + 1)"); return 1; } @@ -1239,7 +1232,7 @@ writeBufferToSeparateStrips (TIFF* out, uint8* buf, if (TIFFWriteEncodedStrip(out, strip++, obuf, stripsize) < 0) { - TIFFError(TIFFFileName(out), "Error, can't write strip %u", strip - 1); + TIFFError(TIFFFileName(out), "Error, can't write strip %"PRIu32, strip - 1); _TIFFfree(obuf); return 1; } @@ -1253,16 +1246,16 @@ writeBufferToSeparateStrips (TIFF* out, uint8* buf, /* Extract all planes from contiguous buffer into a single tile buffer * to be written out as a tile. */ -static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength, - uint32 imagewidth, tsample_t spp, - struct dump_opts* dump) +static int writeBufferToContigTiles (TIFF* out, uint8_t* buf, uint32_t imagelength, + uint32_t imagewidth, tsample_t spp, + struct dump_opts* dump) { - uint16 bps; - uint32 tl, tw; - uint32 row, col, nrow, ncol; - uint32 src_rowsize, col_offset; - uint32 tile_rowsize = TIFFTileRowSize(out); - uint8* bufp = (uint8*) buf; + uint16_t bps; + uint32_t tl, tw; + uint32_t row, col, nrow, ncol; + uint32_t src_rowsize, col_offset; + uint32_t tile_rowsize = TIFFTileRowSize(out); + uint8_t* bufp = (uint8_t*) buf; tsize_t tile_buffsize = 0; tsize_t tilesize = TIFFTileSize(out); unsigned char *tilebuf = NULL; @@ -1283,7 +1276,7 @@ static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength, { #ifdef DEBUG2 TIFFError("writeBufferToContigTiles", - "Tilesize %lu is too small, using alternate calculation %u", + "Tilesize %"PRId64" is too small, using alternate calculation %"PRIu32, tilesize, tl * tile_rowsize); #endif tile_buffsize = tl * tile_rowsize; @@ -1295,11 +1288,11 @@ static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength, } if( imagewidth == 0 || - (uint32)bps * (uint32)spp > TIFF_UINT32_MAX / imagewidth || - bps * spp * imagewidth > TIFF_UINT32_MAX - 7U ) + (uint32_t)bps * (uint32_t)spp > UINT32_MAX / imagewidth || + bps * spp * imagewidth > UINT32_MAX - 7U ) { TIFFError(TIFFFileName(out), - "Error, uint32 overflow when computing (imagewidth * bps * spp) + 7"); + "Error, uint32_t overflow when computing (imagewidth * bps * spp) + 7"); return 1; } src_rowsize = ((imagewidth * spp * bps) + 7U) / 8; @@ -1324,8 +1317,8 @@ static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength, tw, 0, spp, spp, bps, dump) > 0) { TIFFError("writeBufferToContigTiles", - "Unable to extract data to tile for row %lu, col %lu", - (unsigned long) row, (unsigned long)col); + "Unable to extract data to tile for row %"PRIu32", col %"PRIu32, + row, col); _TIFFfree(tilebuf); return 1; } @@ -1333,8 +1326,8 @@ static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength, if (TIFFWriteTile(out, tilebuf, col, row, 0, 0) < 0) { TIFFError("writeBufferToContigTiles", - "Cannot write tile at %lu %lu", - (unsigned long) col, (unsigned long) row); + "Cannot write tile at %"PRIu32" %"PRIu32, + col, row); _TIFFfree(tilebuf); return 1; } @@ -1348,17 +1341,17 @@ static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength, /* Extract each plane from contiguous buffer into a single tile buffer * to be written out as a tile. */ -static int writeBufferToSeparateTiles (TIFF* out, uint8* buf, uint32 imagelength, - uint32 imagewidth, tsample_t spp, +static int writeBufferToSeparateTiles (TIFF* out, uint8_t* buf, uint32_t imagelength, + uint32_t imagewidth, tsample_t spp, struct dump_opts * dump) { tdata_t obuf = limitMalloc(TIFFTileSize(out)); - uint32 tl, tw; - uint32 row, col, nrow, ncol; - uint32 src_rowsize, col_offset; - uint16 bps; + uint32_t tl, tw; + uint32_t row, col, nrow, ncol; + uint32_t src_rowsize, col_offset; + uint16_t bps; tsample_t s; - uint8* bufp = (uint8*) buf; + uint8_t* bufp = (uint8_t*) buf; if (obuf == NULL) return 1; @@ -1366,14 +1359,17 @@ static int writeBufferToSeparateTiles (TIFF* out, uint8* buf, uint32 imagelength if( !TIFFGetField(out, TIFFTAG_TILELENGTH, &tl) || !TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw) || !TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps) ) + { + _TIFFfree(obuf); return 1; + } if( imagewidth == 0 || - (uint32)bps * (uint32)spp > TIFF_UINT32_MAX / imagewidth || - bps * spp * imagewidth > TIFF_UINT32_MAX - 7 ) + (uint32_t)bps * (uint32_t)spp > UINT32_MAX / imagewidth || + bps * spp * imagewidth > UINT32_MAX - 7 ) { TIFFError(TIFFFileName(out), - "Error, uint32 overflow when computing (imagewidth * bps * spp) + 7"); + "Error, uint32_t overflow when computing (imagewidth * bps * spp) + 7"); _TIFFfree(obuf); return 1; } @@ -1399,8 +1395,8 @@ static int writeBufferToSeparateTiles (TIFF* out, uint8* buf, uint32 imagelength tw, s, 1, spp, bps, dump) > 0) { TIFFError("writeBufferToSeparateTiles", - "Unable to extract data to tile for row %lu, col %lu sample %d", - (unsigned long) row, (unsigned long)col, (int)s); + "Unable to extract data to tile for row %"PRIu32", col %"PRIu32" sample %"PRIu16, + row, col, s); _TIFFfree(obuf); return 1; } @@ -1408,9 +1404,8 @@ static int writeBufferToSeparateTiles (TIFF* out, uint8* buf, uint32 imagelength if (TIFFWriteTile(out, obuf, col, row, 0, s) < 0) { TIFFError("writeBufferToseparateTiles", - "Cannot write tile at %lu %lu sample %lu", - (unsigned long) col, (unsigned long) row, - (unsigned long) s); + "Cannot write tile at %"PRIu32" %"PRIu32" sample %"PRIu16, + col, row, s); _TIFFfree(obuf); return 1; } @@ -1426,7 +1421,7 @@ static void processG3Options(char* cp) { if( (cp = strchr(cp, ':')) ) { - if (defg3opts == (uint32) -1) + if (defg3opts == (uint32_t) -1) defg3opts = 0; do { cp++; @@ -1504,15 +1499,13 @@ processCompressOptions(char* opt) static void usage(int code) - { - int i; - FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; +{ + FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; - fprintf(out, "\n%s\n", TIFFGetVersion()); - for (i = 0; usage_info[i] != NULL; i++) - fprintf(out, "%s\n", usage_info[i]); - exit(code); - } + fprintf(out, "\n%s\n\n", TIFFGetVersion()); + fprintf(out, "%s", usage_info); + exit(code); +} #define CopyField(tag, v) \ if (TIFFGetField(in, tag, &v)) TIFFSetField(out, tag, v) @@ -1524,27 +1517,27 @@ usage(int code) if (TIFFGetField(in, tag, &v1, &v2, &v3, &v4)) TIFFSetField(out, tag, v1, v2, v3, v4) static void -cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) +cpTag(TIFF* in, TIFF* out, uint16_t tag, uint16_t count, TIFFDataType type) { switch (type) { case TIFF_SHORT: if (count == 1) { - uint16 shortv; + uint16_t shortv; CopyField(tag, shortv); } else if (count == 2) { - uint16 shortv1, shortv2; + uint16_t shortv1, shortv2; CopyField2(tag, shortv1, shortv2); } else if (count == 4) { - uint16 *tr, *tg, *tb, *ta; + uint16_t *tr, *tg, *tb, *ta; CopyField4(tag, tr, tg, tb, ta); - } else if (count == (uint16) -1) { - uint16 shortv1; - uint16* shortav; + } else if (count == (uint16_t) -1) { + uint16_t shortv1; + uint16_t* shortav; CopyField2(tag, shortv1, shortav); } break; case TIFF_LONG: - { uint32 longv; + { uint32_t longv; CopyField(tag, longv); } break; @@ -1552,7 +1545,7 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) if (count == 1) { float floatv; CopyField(tag, floatv); - } else if (count == (uint16) -1) { + } else if (count == (uint16_t) -1) { float* floatav; CopyField(tag, floatav); } @@ -1566,21 +1559,21 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type) if (count == 1) { double doublev; CopyField(tag, doublev); - } else if (count == (uint16) -1) { + } else if (count == (uint16_t) -1) { double* doubleav; CopyField(tag, doubleav); } break; default: TIFFError(TIFFFileName(in), - "Data type %d is not supported, tag %d skipped", + "Data type %"PRIu16" is not supported, tag %d skipped", tag, type); } } -static struct cpTag { - uint16 tag; - uint16 count; +static const struct cpTag { + uint16_t tag; + uint16_t count; TIFFDataType type; } tags[] = { { TIFFTAG_SUBFILETYPE, 1, TIFF_LONG }, @@ -1591,41 +1584,41 @@ static struct cpTag { { TIFFTAG_MODEL, 1, TIFF_ASCII }, { TIFFTAG_MINSAMPLEVALUE, 1, TIFF_SHORT }, { TIFFTAG_MAXSAMPLEVALUE, 1, TIFF_SHORT }, - { TIFFTAG_XRESOLUTION, 1, TIFF_RATIONAL }, - { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL }, - { TIFFTAG_PAGENAME, 1, TIFF_ASCII }, - { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL }, - { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL }, - { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT }, - { TIFFTAG_SOFTWARE, 1, TIFF_ASCII }, - { TIFFTAG_DATETIME, 1, TIFF_ASCII }, - { TIFFTAG_ARTIST, 1, TIFF_ASCII }, - { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII }, - { TIFFTAG_WHITEPOINT, (uint16) -1, TIFF_RATIONAL }, - { TIFFTAG_PRIMARYCHROMATICITIES,(uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT }, - { TIFFTAG_INKSET, 1, TIFF_SHORT }, - { TIFFTAG_DOTRANGE, 2, TIFF_SHORT }, - { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII }, - { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT }, - { TIFFTAG_YCBCRCOEFFICIENTS, (uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT }, - { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT }, - { TIFFTAG_REFERENCEBLACKWHITE, (uint16) -1,TIFF_RATIONAL }, - { TIFFTAG_EXTRASAMPLES, (uint16) -1, TIFF_SHORT }, - { TIFFTAG_SMINSAMPLEVALUE, 1, TIFF_DOUBLE }, - { TIFFTAG_SMAXSAMPLEVALUE, 1, TIFF_DOUBLE }, - { TIFFTAG_STONITS, 1, TIFF_DOUBLE }, + { TIFFTAG_XRESOLUTION, 1, TIFF_RATIONAL }, + { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL }, + { TIFFTAG_PAGENAME, 1, TIFF_ASCII }, + { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL }, + { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL }, + { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT }, + { TIFFTAG_SOFTWARE, 1, TIFF_ASCII }, + { TIFFTAG_DATETIME, 1, TIFF_ASCII }, + { TIFFTAG_ARTIST, 1, TIFF_ASCII }, + { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII }, + { TIFFTAG_WHITEPOINT, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_PRIMARYCHROMATICITIES,(uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT }, + { TIFFTAG_INKSET, 1, TIFF_SHORT }, + { TIFFTAG_DOTRANGE, 2, TIFF_SHORT }, + { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII }, + { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT }, + { TIFFTAG_YCBCRCOEFFICIENTS, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT }, + { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT }, + { TIFFTAG_REFERENCEBLACKWHITE, (uint16_t) -1, TIFF_RATIONAL }, + { TIFFTAG_EXTRASAMPLES, (uint16_t) -1, TIFF_SHORT }, + { TIFFTAG_SMINSAMPLEVALUE, 1, TIFF_DOUBLE }, + { TIFFTAG_SMAXSAMPLEVALUE, 1, TIFF_DOUBLE }, + { TIFFTAG_STONITS, 1, TIFF_DOUBLE }, }; #define NTAGS (sizeof (tags) / sizeof (tags[0])) #define CopyTag(tag, count, type) cpTag(in, out, tag, count, type) /* Functions written by Richard Nolde, with exceptions noted. */ -void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32 *dirnum, - uint16 *defconfig, uint16 *deffillorder, uint32 *deftilewidth, - uint32 *deftilelength, uint32 *defrowsperstrip, - struct crop_mask *crop_data, struct pagedef *page, +void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32_t *dirnum, + uint16_t *defconfig, uint16_t *deffillorder, uint32_t *deftilewidth, + uint32_t *deftilelength, uint32_t *defrowsperstrip, + struct crop_mask *crop_data, struct pagedef *page, struct dump_opts *dump, unsigned int *imagelist, unsigned int *image_count ) { @@ -1750,7 +1743,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32 &crop_data->corners[i].X1, &crop_data->corners[i].Y1, &crop_data->corners[i].X2, &crop_data->corners[i].Y2) != 4) { - TIFFError ("Unable to parse coordinates for region", "%d %s", i, optarg); + TIFFError ("Unable to parse coordinates for region", "%u %s", i, optarg); TIFFError ("For valid options type", "tiffcrop -h"); exit (EXIT_FAILURE); } @@ -1925,11 +1918,11 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32 TIFFError ("For valid options type", "tiffcrop -h"); exit (EXIT_FAILURE); break; - case 'J': /* horizontal margin for sectioned ouput pages */ + case 'J': /* horizontal margin for sectioned output pages */ page->hmargin = atof(optarg); page->mode |= PAGE_MODE_MARGINS; break; - case 'K': /* vertical margin for sectioned ouput pages*/ + case 'K': /* vertical margin for sectioned output pages*/ page->vmargin = atof(optarg); page->mode |= PAGE_MODE_MARGINS; break; @@ -2036,11 +2029,11 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32 crop_data->crop_mode |= CROP_ROTATE; switch (strtoul(optarg, NULL, 0)) { - case 90: crop_data->rotation = (uint16)90; + case 90: crop_data->rotation = (uint16_t)90; break; - case 180: crop_data->rotation = (uint16)180; + case 180: crop_data->rotation = (uint16_t)180; break; - case 270: crop_data->rotation = (uint16)270; + case 270: crop_data->rotation = (uint16_t)270; break; default: TIFFError ("Rotation must be 90, 180, or 270 degrees clockwise", "%s", optarg); TIFFError ("For valid options type", "tiffcrop -h"); @@ -2211,12 +2204,12 @@ main(int argc, char* argv[]) #if !HAVE_DECL_OPTARG extern int optind; #endif - uint16 defconfig = (uint16) -1; - uint16 deffillorder = 0; - uint32 deftilewidth = (uint32) 0; - uint32 deftilelength = (uint32) 0; - uint32 defrowsperstrip = (uint32) 0; - uint32 dirnum = 0; + uint16_t defconfig = (uint16_t) -1; + uint16_t deffillorder = 0; + uint32_t deftilewidth = (uint32_t) 0; + uint32_t deftilelength = (uint32_t) 0; + uint32_t defrowsperstrip = (uint32_t) 0; + uint32_t dirnum = 0; TIFF *in = NULL; TIFF *out = NULL; @@ -2306,8 +2299,8 @@ main(int argc, char* argv[]) if (dirnum > (total_images)) { TIFFError (TIFFFileName(in), - "Invalid image number %d, File contains only %d images", - (int)dirnum + 1, total_images); + "Invalid image number %"PRIu32", File contains only %"PRIu32" images", + dirnum + 1u, total_images); if (out != NULL) (void) TIFFClose(out); return (1); @@ -2315,7 +2308,7 @@ main(int argc, char* argv[]) if (dirnum != 0 && !TIFFSetDirectory(in, (tdir_t)dirnum)) { - TIFFError(TIFFFileName(in),"Error, setting subdirectory at %d", dirnum); + TIFFError(TIFFFileName(in),"Error, setting subdirectory at %"PRIu32, dirnum); if (out != NULL) (void) TIFFClose(out); return (1); @@ -2353,7 +2346,7 @@ main(int argc, char* argv[]) TIFFError ("Unable to open dump file for writing", "%s", temp_filename); exit (EXIT_FAILURE); } - dump_info(dump.infile, dump.format, "Reading image","%d from %s", + dump_info(dump.infile, dump.format, "Reading image","%u from %s", dump_images, TIFFFileName(in)); } length = strlen(dump.outfilename); @@ -2372,7 +2365,7 @@ main(int argc, char* argv[]) TIFFError ("Unable to open dump file for writing", "%s", temp_filename); exit (EXIT_FAILURE); } - dump_info(dump.outfile, dump.format, "Writing image","%d from %s", + dump_info(dump.outfile, dump.format, "Writing image","%u from %s", dump_images, TIFFFileName(in)); } } @@ -2516,10 +2509,10 @@ main(int argc, char* argv[]) /* Debugging functions */ -static int dump_data (FILE *dumpfile, int format, char *dump_tag, unsigned char *data, uint32 count) +static int dump_data (FILE *dumpfile, int format, char *dump_tag, unsigned char *data, uint32_t count) { int j, k; - uint32 i; + uint32_t i; char dump_array[10]; unsigned char bitset; @@ -2591,7 +2584,7 @@ static int dump_byte (FILE *dumpfile, int format, char *dump_tag, unsigned char return (0); } -static int dump_short (FILE *dumpfile, int format, char *dump_tag, uint16 data) +static int dump_short (FILE *dumpfile, int format, char *dump_tag, uint16_t data) { int j, k; char dump_array[20]; @@ -2628,7 +2621,7 @@ static int dump_short (FILE *dumpfile, int format, char *dump_tag, uint16 data) return (0); } -static int dump_long (FILE *dumpfile, int format, char *dump_tag, uint32 data) +static int dump_long (FILE *dumpfile, int format, char *dump_tag, uint32_t data) { int j, k; char dump_array[40]; @@ -2645,7 +2638,7 @@ static int dump_long (FILE *dumpfile, int format, char *dump_tag, uint32 data) fprintf (dumpfile," %s ", dump_tag); for (j = 0, k = 31; k >= 0; j++, k--) { - bitset = data & (((uint32)1 << k)) ? 1 : 0; + bitset = data & (((uint32_t)1 << k)) ? 1 : 0; sprintf(&dump_array[j], (bitset) ? "1" : "0"); if ((k % 8) == 0) sprintf(&dump_array[++j], " "); @@ -2664,7 +2657,7 @@ static int dump_long (FILE *dumpfile, int format, char *dump_tag, uint32 data) return (0); } -static int dump_wide (FILE *dumpfile, int format, char *dump_tag, uint64 data) +static int dump_wide (FILE *dumpfile, int format, char *dump_tag, uint64_t data) { int j, k; char dump_array[80]; @@ -2681,7 +2674,7 @@ static int dump_wide (FILE *dumpfile, int format, char *dump_tag, uint64 data) fprintf (dumpfile," %s ", dump_tag); for (j = 0, k = 63; k >= 0; j++, k--) { - bitset = data & (((uint64)1 << k)) ? 1 : 0; + bitset = data & (((uint64_t)1 << k)) ? 1 : 0; sprintf(&dump_array[j], (bitset) ? "1" : "0"); if ((k % 8) == 0) sprintf(&dump_array[++j], " "); @@ -2714,11 +2707,11 @@ static void dump_info(FILE *dumpfile, int format, char *prefix, char *msg, ...) } } -static int dump_buffer (FILE* dumpfile, int format, uint32 rows, uint32 width, - uint32 row, unsigned char *buff) +static int dump_buffer (FILE* dumpfile, int format, uint32_t rows, uint32_t width, + uint32_t row, unsigned char *buff) { int j, k; - uint32 i; + uint32_t i; unsigned char * dump_ptr; if (dumpfile == NULL) @@ -2732,8 +2725,8 @@ static int dump_buffer (FILE* dumpfile, int format, uint32 rows, uint32 width, dump_ptr = buff + (i * width); if (format == DUMP_TEXT) dump_info (dumpfile, format, "", - "Row %4d, %d bytes at offset %d", - row + i + 1, width, row * width); + "Row %4"PRIu32", %"PRIu32" bytes at offset %"PRIu32, + row + i + 1u, width, row * width); for (j = 0, k = width; k >= 10; j += 10, k -= 10, dump_ptr += 10) dump_data (dumpfile, format, "", dump_ptr, 10); @@ -2750,15 +2743,15 @@ static int dump_buffer (FILE* dumpfile, int format, uint32 rows, uint32 width, */ static int -extractContigSamplesBytes (uint8 *in, uint8 *out, uint32 cols, - tsample_t sample, uint16 spp, uint16 bps, - tsample_t count, uint32 start, uint32 end) +extractContigSamplesBytes (uint8_t *in, uint8_t *out, uint32_t cols, + tsample_t sample, uint16_t spp, uint16_t bps, + tsample_t count, uint32_t start, uint32_t end) { int i, bytes_per_sample, sindex; - uint32 col, dst_rowsize, bit_offset; - uint32 src_byte /*, src_bit */; - uint8 *src = in; - uint8 *dst = out; + uint32_t col, dst_rowsize, bit_offset; + uint32_t src_byte /*, src_bit */; + uint8_t *src = in; + uint8_t *dst = out; if ((src == NULL) || (dst == NULL)) { @@ -2769,13 +2762,13 @@ extractContigSamplesBytes (uint8 *in, uint8 *out, uint32 cols, if ((start > end) || (start > cols)) { TIFFError ("extractContigSamplesBytes", - "Invalid start column value %d ignored", start); + "Invalid start column value %"PRIu32" ignored", start); start = 0; } if ((end == 0) || (end > cols)) { TIFFError ("extractContigSamplesBytes", - "Invalid end column value %d ignored", end); + "Invalid end column value %"PRIu32" ignored", end); end = cols; } @@ -2816,16 +2809,16 @@ extractContigSamplesBytes (uint8 *in, uint8 *out, uint32 cols, } /* end extractContigSamplesBytes */ static int -extractContigSamples8bits (uint8 *in, uint8 *out, uint32 cols, - tsample_t sample, uint16 spp, uint16 bps, - tsample_t count, uint32 start, uint32 end) +extractContigSamples8bits (uint8_t *in, uint8_t *out, uint32_t cols, + tsample_t sample, uint16_t spp, uint16_t bps, + tsample_t count, uint32_t start, uint32_t end) { int ready_bits = 0, sindex = 0; - uint32 col, src_byte, src_bit, bit_offset; - uint8 maskbits = 0, matchbits = 0; - uint8 buff1 = 0, buff2 = 0; - uint8 *src = in; - uint8 *dst = out; + uint32_t col, src_byte, src_bit, bit_offset; + uint8_t maskbits = 0, matchbits = 0; + uint8_t buff1 = 0, buff2 = 0; + uint8_t *src = in; + uint8_t *dst = out; if ((src == NULL) || (dst == NULL)) { @@ -2836,18 +2829,18 @@ extractContigSamples8bits (uint8 *in, uint8 *out, uint32 cols, if ((start > end) || (start > cols)) { TIFFError ("extractContigSamples8bits", - "Invalid start column value %d ignored", start); + "Invalid start column value %"PRIu32" ignored", start); start = 0; } if ((end == 0) || (end > cols)) { TIFFError ("extractContigSamples8bits", - "Invalid end column value %d ignored", end); + "Invalid end column value %"PRIu32" ignored", end); end = cols; } ready_bits = 0; - maskbits = (uint8)-1 >> ( 8 - bps); + maskbits = (uint8_t)-1 >> (8 - bps); buff1 = buff2 = 0; for (col = start; col < end; col++) { /* Compute src byte(s) and bits within byte(s) */ @@ -2893,17 +2886,17 @@ extractContigSamples8bits (uint8 *in, uint8 *out, uint32 cols, } /* end extractContigSamples8bits */ static int -extractContigSamples16bits (uint8 *in, uint8 *out, uint32 cols, - tsample_t sample, uint16 spp, uint16 bps, - tsample_t count, uint32 start, uint32 end) +extractContigSamples16bits (uint8_t *in, uint8_t *out, uint32_t cols, + tsample_t sample, uint16_t spp, uint16_t bps, + tsample_t count, uint32_t start, uint32_t end) { int ready_bits = 0, sindex = 0; - uint32 col, src_byte, src_bit, bit_offset; - uint16 maskbits = 0, matchbits = 0; - uint16 buff1 = 0, buff2 = 0; - uint8 bytebuff = 0; - uint8 *src = in; - uint8 *dst = out; + uint32_t col, src_byte, src_bit, bit_offset; + uint16_t maskbits = 0, matchbits = 0; + uint16_t buff1 = 0, buff2 = 0; + uint8_t bytebuff = 0; + uint8_t *src = in; + uint8_t *dst = out; if ((src == NULL) || (dst == NULL)) { @@ -2914,18 +2907,18 @@ extractContigSamples16bits (uint8 *in, uint8 *out, uint32 cols, if ((start > end) || (start > cols)) { TIFFError ("extractContigSamples16bits", - "Invalid start column value %d ignored", start); + "Invalid start column value %"PRIu32" ignored", start); start = 0; } if ((end == 0) || (end > cols)) { TIFFError ("extractContigSamples16bits", - "Invalid end column value %d ignored", end); + "Invalid end column value %"PRIu32" ignored", end); end = cols; } ready_bits = 0; - maskbits = (uint16)-1 >> (16 - bps); + maskbits = (uint16_t)-1 >> (16 - bps); for (col = start; col < end; col++) { /* Compute src byte(s) and bits within byte(s) */ @@ -2982,17 +2975,17 @@ extractContigSamples16bits (uint8 *in, uint8 *out, uint32 cols, static int -extractContigSamples24bits (uint8 *in, uint8 *out, uint32 cols, - tsample_t sample, uint16 spp, uint16 bps, - tsample_t count, uint32 start, uint32 end) +extractContigSamples24bits (uint8_t *in, uint8_t *out, uint32_t cols, + tsample_t sample, uint16_t spp, uint16_t bps, + tsample_t count, uint32_t start, uint32_t end) { int ready_bits = 0, sindex = 0; - uint32 col, src_byte, src_bit, bit_offset; - uint32 maskbits = 0, matchbits = 0; - uint32 buff1 = 0, buff2 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0; - uint8 *src = in; - uint8 *dst = out; + uint32_t col, src_byte, src_bit, bit_offset; + uint32_t maskbits = 0, matchbits = 0; + uint32_t buff1 = 0, buff2 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0; + uint8_t *src = in; + uint8_t *dst = out; if ((in == NULL) || (out == NULL)) { @@ -3003,18 +2996,18 @@ extractContigSamples24bits (uint8 *in, uint8 *out, uint32 cols, if ((start > end) || (start > cols)) { TIFFError ("extractContigSamples24bits", - "Invalid start column value %d ignored", start); + "Invalid start column value %"PRIu32" ignored", start); start = 0; } if ((end == 0) || (end > cols)) { TIFFError ("extractContigSamples24bits", - "Invalid end column value %d ignored", end); + "Invalid end column value %"PRIu32" ignored", end); end = cols; } ready_bits = 0; - maskbits = (uint32)-1 >> ( 32 - bps); + maskbits = (uint32_t)-1 >> (32 - bps); for (col = start; col < end; col++) { /* Compute src byte(s) and bits within byte(s) */ @@ -3091,18 +3084,18 @@ extractContigSamples24bits (uint8 *in, uint8 *out, uint32 cols, } /* end extractContigSamples24bits */ static int -extractContigSamples32bits (uint8 *in, uint8 *out, uint32 cols, - tsample_t sample, uint16 spp, uint16 bps, - tsample_t count, uint32 start, uint32 end) +extractContigSamples32bits (uint8_t *in, uint8_t *out, uint32_t cols, + tsample_t sample, uint16_t spp, uint16_t bps, + tsample_t count, uint32_t start, uint32_t end) { int ready_bits = 0, sindex = 0 /*, shift_width = 0 */; - uint32 col, src_byte, src_bit, bit_offset; - uint32 longbuff1 = 0, longbuff2 = 0; - uint64 maskbits = 0, matchbits = 0; - uint64 buff1 = 0, buff2 = 0, buff3 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; - uint8 *src = in; - uint8 *dst = out; + uint32_t col, src_byte, src_bit, bit_offset; + uint32_t longbuff1 = 0, longbuff2 = 0; + uint64_t maskbits = 0, matchbits = 0; + uint64_t buff1 = 0, buff2 = 0, buff3 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; + uint8_t *src = in; + uint8_t *dst = out; if ((in == NULL) || (out == NULL)) { @@ -3114,19 +3107,19 @@ extractContigSamples32bits (uint8 *in, uint8 *out, uint32 cols, if ((start > end) || (start > cols)) { TIFFError ("extractContigSamples32bits", - "Invalid start column value %d ignored", start); + "Invalid start column value %"PRIu32" ignored", start); start = 0; } if ((end == 0) || (end > cols)) { TIFFError ("extractContigSamples32bits", - "Invalid end column value %d ignored", end); + "Invalid end column value %"PRIu32" ignored", end); end = cols; } /* shift_width = ((bps + 7) / 8) + 1; */ ready_bits = 0; - maskbits = (uint64)-1 >> ( 64 - bps); + maskbits = (uint64_t)-1 >> (64 - bps); for (col = start; col < end; col++) { /* Compute src byte(s) and bits within byte(s) */ @@ -3157,7 +3150,7 @@ extractContigSamples32bits (uint8 *in, uint8 *out, uint32 cols, longbuff2 = longbuff1; } - buff3 = ((uint64)longbuff1 << 32) | longbuff2; + buff3 = ((uint64_t)longbuff1 << 32) | longbuff2; buff1 = (buff3 & matchbits) << (src_bit); /* If we have a full buffer's worth, write it out */ @@ -3196,17 +3189,17 @@ extractContigSamples32bits (uint8 *in, uint8 *out, uint32 cols, } /* end extractContigSamples32bits */ static int -extractContigSamplesShifted8bits (uint8 *in, uint8 *out, uint32 cols, - tsample_t sample, uint16 spp, uint16 bps, - tsample_t count, uint32 start, uint32 end, - int shift) +extractContigSamplesShifted8bits (uint8_t *in, uint8_t *out, uint32_t cols, + tsample_t sample, uint16_t spp, uint16_t bps, + tsample_t count, uint32_t start, uint32_t end, + int shift) { int ready_bits = 0, sindex = 0; - uint32 col, src_byte, src_bit, bit_offset; - uint8 maskbits = 0, matchbits = 0; - uint8 buff1 = 0, buff2 = 0; - uint8 *src = in; - uint8 *dst = out; + uint32_t col, src_byte, src_bit, bit_offset; + uint8_t maskbits = 0, matchbits = 0; + uint8_t buff1 = 0, buff2 = 0; + uint8_t *src = in; + uint8_t *dst = out; if ((src == NULL) || (dst == NULL)) { @@ -3217,18 +3210,18 @@ extractContigSamplesShifted8bits (uint8 *in, uint8 *out, uint32 cols, if ((start > end) || (start > cols)) { TIFFError ("extractContigSamplesShifted8bits", - "Invalid start column value %d ignored", start); + "Invalid start column value %"PRIu32" ignored", start); start = 0; } if ((end == 0) || (end > cols)) { TIFFError ("extractContigSamplesShifted8bits", - "Invalid end column value %d ignored", end); + "Invalid end column value %"PRIu32" ignored", end); end = cols; } ready_bits = shift; - maskbits = (uint8)-1 >> ( 8 - bps); + maskbits = (uint8_t)-1 >> (8 - bps); buff1 = buff2 = 0; for (col = start; col < end; col++) { /* Compute src byte(s) and bits within byte(s) */ @@ -3250,7 +3243,7 @@ extractContigSamplesShifted8bits (uint8 *in, uint8 *out, uint32 cols, matchbits = maskbits << (8 - src_bit - bps); buff1 = ((*src) & matchbits) << (src_bit); if ((col == start) && (sindex == sample)) - buff2 = *src & ((uint8)-1) << (shift); + buff2 = *src & ((uint8_t)-1) << (shift); /* If we have a full buffer's worth, write it out */ if (ready_bits >= 8) @@ -3276,18 +3269,18 @@ extractContigSamplesShifted8bits (uint8 *in, uint8 *out, uint32 cols, } /* end extractContigSamplesShifted8bits */ static int -extractContigSamplesShifted16bits (uint8 *in, uint8 *out, uint32 cols, - tsample_t sample, uint16 spp, uint16 bps, - tsample_t count, uint32 start, uint32 end, - int shift) +extractContigSamplesShifted16bits (uint8_t *in, uint8_t *out, uint32_t cols, + tsample_t sample, uint16_t spp, uint16_t bps, + tsample_t count, uint32_t start, uint32_t end, + int shift) { int ready_bits = 0, sindex = 0; - uint32 col, src_byte, src_bit, bit_offset; - uint16 maskbits = 0, matchbits = 0; - uint16 buff1 = 0, buff2 = 0; - uint8 bytebuff = 0; - uint8 *src = in; - uint8 *dst = out; + uint32_t col, src_byte, src_bit, bit_offset; + uint16_t maskbits = 0, matchbits = 0; + uint16_t buff1 = 0, buff2 = 0; + uint8_t bytebuff = 0; + uint8_t *src = in; + uint8_t *dst = out; if ((src == NULL) || (dst == NULL)) { @@ -3298,18 +3291,18 @@ extractContigSamplesShifted16bits (uint8 *in, uint8 *out, uint32 cols, if ((start > end) || (start > cols)) { TIFFError ("extractContigSamplesShifted16bits", - "Invalid start column value %d ignored", start); + "Invalid start column value %"PRIu32" ignored", start); start = 0; } if ((end == 0) || (end > cols)) { TIFFError ("extractContigSamplesShifted16bits", - "Invalid end column value %d ignored", end); + "Invalid end column value %"PRIu32" ignored", end); end = cols; } ready_bits = shift; - maskbits = (uint16)-1 >> (16 - bps); + maskbits = (uint16_t)-1 >> (16 - bps); for (col = start; col < end; col++) { /* Compute src byte(s) and bits within byte(s) */ bit_offset = col * bps * spp; @@ -3334,7 +3327,7 @@ extractContigSamplesShifted16bits (uint8 *in, uint8 *out, uint32 cols, buff1 = (src[1] << 8) | src[0]; if ((col == start) && (sindex == sample)) - buff2 = buff1 & ((uint16)-1) << (8 - shift); + buff2 = buff1 & ((uint16_t)-1) << (8 - shift); buff1 = (buff1 & matchbits) << (src_bit); @@ -3366,18 +3359,18 @@ extractContigSamplesShifted16bits (uint8 *in, uint8 *out, uint32 cols, static int -extractContigSamplesShifted24bits (uint8 *in, uint8 *out, uint32 cols, - tsample_t sample, uint16 spp, uint16 bps, - tsample_t count, uint32 start, uint32 end, - int shift) +extractContigSamplesShifted24bits (uint8_t *in, uint8_t *out, uint32_t cols, + tsample_t sample, uint16_t spp, uint16_t bps, + tsample_t count, uint32_t start, uint32_t end, + int shift) { int ready_bits = 0, sindex = 0; - uint32 col, src_byte, src_bit, bit_offset; - uint32 maskbits = 0, matchbits = 0; - uint32 buff1 = 0, buff2 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0; - uint8 *src = in; - uint8 *dst = out; + uint32_t col, src_byte, src_bit, bit_offset; + uint32_t maskbits = 0, matchbits = 0; + uint32_t buff1 = 0, buff2 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0; + uint8_t *src = in; + uint8_t *dst = out; if ((in == NULL) || (out == NULL)) { @@ -3388,18 +3381,18 @@ extractContigSamplesShifted24bits (uint8 *in, uint8 *out, uint32 cols, if ((start > end) || (start > cols)) { TIFFError ("extractContigSamplesShifted24bits", - "Invalid start column value %d ignored", start); + "Invalid start column value %"PRIu32" ignored", start); start = 0; } if ((end == 0) || (end > cols)) { TIFFError ("extractContigSamplesShifted24bits", - "Invalid end column value %d ignored", end); + "Invalid end column value %"PRIu32" ignored", end); end = cols; } ready_bits = shift; - maskbits = (uint32)-1 >> ( 32 - bps); + maskbits = (uint32_t)-1 >> (32 - bps); for (col = start; col < end; col++) { /* Compute src byte(s) and bits within byte(s) */ @@ -3425,7 +3418,7 @@ extractContigSamplesShifted24bits (uint8 *in, uint8 *out, uint32 cols, buff1 = (src[3] << 24) | (src[2] << 16) | (src[1] << 8) | src[0]; if ((col == start) && (sindex == sample)) - buff2 = buff1 & ((uint32)-1) << (16 - shift); + buff2 = buff1 & ((uint32_t)-1) << (16 - shift); buff1 = (buff1 & matchbits) << (src_bit); @@ -3464,19 +3457,19 @@ extractContigSamplesShifted24bits (uint8 *in, uint8 *out, uint32 cols, } /* end extractContigSamplesShifted24bits */ static int -extractContigSamplesShifted32bits (uint8 *in, uint8 *out, uint32 cols, - tsample_t sample, uint16 spp, uint16 bps, - tsample_t count, uint32 start, uint32 end, - int shift) +extractContigSamplesShifted32bits (uint8_t *in, uint8_t *out, uint32_t cols, + tsample_t sample, uint16_t spp, uint16_t bps, + tsample_t count, uint32_t start, uint32_t end, + int shift) { int ready_bits = 0, sindex = 0 /*, shift_width = 0 */; - uint32 col, src_byte, src_bit, bit_offset; - uint32 longbuff1 = 0, longbuff2 = 0; - uint64 maskbits = 0, matchbits = 0; - uint64 buff1 = 0, buff2 = 0, buff3 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; - uint8 *src = in; - uint8 *dst = out; + uint32_t col, src_byte, src_bit, bit_offset; + uint32_t longbuff1 = 0, longbuff2 = 0; + uint64_t maskbits = 0, matchbits = 0; + uint64_t buff1 = 0, buff2 = 0, buff3 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; + uint8_t *src = in; + uint8_t *dst = out; if ((in == NULL) || (out == NULL)) { @@ -3488,19 +3481,19 @@ extractContigSamplesShifted32bits (uint8 *in, uint8 *out, uint32 cols, if ((start > end) || (start > cols)) { TIFFError ("extractContigSamplesShifted32bits", - "Invalid start column value %d ignored", start); + "Invalid start column value %"PRIu32" ignored", start); start = 0; } if ((end == 0) || (end > cols)) { TIFFError ("extractContigSamplesShifted32bits", - "Invalid end column value %d ignored", end); + "Invalid end column value %"PRIu32" ignored", end); end = cols; } /* shift_width = ((bps + 7) / 8) + 1; */ ready_bits = shift; - maskbits = (uint64)-1 >> ( 64 - bps); + maskbits = (uint64_t)-1 >> (64 - bps); for (col = start; col < end; col++) { /* Compute src byte(s) and bits within byte(s) */ @@ -3531,9 +3524,9 @@ extractContigSamplesShifted32bits (uint8 *in, uint8 *out, uint32 cols, longbuff2 = longbuff1; } - buff3 = ((uint64)longbuff1 << 32) | longbuff2; + buff3 = ((uint64_t)longbuff1 << 32) | longbuff2; if ((col == start) && (sindex == sample)) - buff2 = buff3 & ((uint64)-1) << (32 - shift); + buff2 = buff3 & ((uint64_t)-1) << (32 - shift); buff1 = (buff3 & matchbits) << (src_bit); @@ -3572,15 +3565,15 @@ extractContigSamplesShifted32bits (uint8 *in, uint8 *out, uint32 cols, } /* end extractContigSamplesShifted32bits */ static int -extractContigSamplesToBuffer(uint8 *out, uint8 *in, uint32 rows, uint32 cols, - tsample_t sample, uint16 spp, uint16 bps, +extractContigSamplesToBuffer(uint8_t *out, uint8_t *in, uint32_t rows, uint32_t cols, + tsample_t sample, uint16_t spp, uint16_t bps, struct dump_opts *dump) { int shift_width, bytes_per_sample, bytes_per_pixel; - uint32 src_rowsize, src_offset, row, first_col = 0; - uint32 dst_rowsize, dst_offset; + uint32_t src_rowsize, src_offset, row, first_col = 0; + uint32_t dst_rowsize, dst_offset; tsample_t count = 1; - uint8 *src, *dst; + uint8_t *src, *dst; bytes_per_sample = (bps + 7) / 8; bytes_per_pixel = ((bps * spp) + 7) / 8; @@ -3599,7 +3592,7 @@ extractContigSamplesToBuffer(uint8 *out, uint8 *in, uint32 rows, uint32 cols, if ((dump->outfile != NULL) && (dump->level == 4)) { dump_info (dump->outfile, dump->format, "extractContigSamplesToBuffer", - "Sample %d, %d rows", sample + 1, rows + 1); + "Sample %"PRIu32", %"PRIu32" rows", sample + 1u, rows + 1u); } for (row = 0; row < rows; row++) { @@ -3637,7 +3630,7 @@ extractContigSamplesToBuffer(uint8 *out, uint8 *in, uint32 rows, uint32 cols, spp, bps, count, first_col, cols)) return (1); break; - default: TIFFError ("extractContigSamplesToBuffer", "Unsupported bit depth: %d", bps); + default: TIFFError ("extractContigSamplesToBuffer", "Unsupported bit depth: %"PRIu16, bps); return (1); } if ((dump->outfile != NULL) && (dump->level == 4)) @@ -3648,14 +3641,14 @@ extractContigSamplesToBuffer(uint8 *out, uint8 *in, uint32 rows, uint32 cols, } /* end extractContigSamplesToBuffer */ static int -extractContigSamplesToTileBuffer(uint8 *out, uint8 *in, uint32 rows, uint32 cols, - uint32 imagewidth, uint32 tilewidth, tsample_t sample, - uint16 count, uint16 spp, uint16 bps, struct dump_opts *dump) +extractContigSamplesToTileBuffer(uint8_t *out, uint8_t *in, uint32_t rows, uint32_t cols, + uint32_t imagewidth, uint32_t tilewidth, tsample_t sample, + uint16_t count, uint16_t spp, uint16_t bps, struct dump_opts *dump) { int shift_width, bytes_per_sample, bytes_per_pixel; - uint32 src_rowsize, src_offset, row; - uint32 dst_rowsize, dst_offset; - uint8 *src, *dst; + uint32_t src_rowsize, src_offset, row; + uint32_t dst_rowsize, dst_offset; + uint8_t *src, *dst; bytes_per_sample = (bps + 7) / 8; bytes_per_pixel = ((bps * spp) + 7) / 8; @@ -3672,7 +3665,7 @@ extractContigSamplesToTileBuffer(uint8 *out, uint8 *in, uint32 rows, uint32 cols if ((dump->outfile != NULL) && (dump->level == 4)) { dump_info (dump->outfile, dump->format, "extractContigSamplesToTileBuffer", - "Sample %d, %d rows", sample + 1, rows + 1); + "Sample %"PRIu32", %"PRIu32" rows", sample + 1u, rows + 1u); } src_rowsize = ((bps * spp * imagewidth) + 7) / 8; @@ -3714,7 +3707,7 @@ extractContigSamplesToTileBuffer(uint8 *out, uint8 *in, uint32 rows, uint32 cols spp, bps, count, 0, cols)) return (1); break; - default: TIFFError ("extractContigSamplesToTileBuffer", "Unsupported bit depth: %d", bps); + default: TIFFError ("extractContigSamplesToTileBuffer", "Unsupported bit depth: %"PRIu16, bps); return (1); } if ((dump->outfile != NULL) && (dump->level == 4)) @@ -3724,14 +3717,14 @@ extractContigSamplesToTileBuffer(uint8 *out, uint8 *in, uint32 rows, uint32 cols return (0); } /* end extractContigSamplesToTileBuffer */ -static int readContigStripsIntoBuffer (TIFF* in, uint8* buf) +static int readContigStripsIntoBuffer (TIFF* in, uint8_t* buf) { - uint8* bufp = buf; - int32 bytes_read = 0; - uint32 strip, nstrips = TIFFNumberOfStrips(in); - uint32 stripsize = TIFFStripSize(in); - uint32 rows = 0; - uint32 rps = TIFFGetFieldDefaulted(in, TIFFTAG_ROWSPERSTRIP, &rps); + uint8_t* bufp = buf; + int32_t bytes_read = 0; + uint32_t strip, nstrips = TIFFNumberOfStrips(in); + uint32_t stripsize = TIFFStripSize(in); + uint32_t rows = 0; + uint32_t rps = TIFFGetFieldDefaulted(in, TIFFTAG_ROWSPERSTRIP, &rps); tsize_t scanline_size = TIFFScanlineSize(in); if (scanline_size == 0) { @@ -3742,14 +3735,13 @@ static int readContigStripsIntoBuffer (TIFF* in, uint8* buf) for (strip = 0; strip < nstrips; strip++) { bytes_read = TIFFReadEncodedStrip (in, strip, bufp, -1); rows = bytes_read / scanline_size; - if ((strip < (nstrips - 1)) && (bytes_read != (int32)stripsize)) - TIFFError("", "Strip %d: read %lu bytes, strip size %lu", - (int)strip + 1, (unsigned long) bytes_read, - (unsigned long)stripsize); + if ((strip < (nstrips - 1)) && (bytes_read != (int32_t)stripsize)) + TIFFError("", "Strip %"PRIu32": read %"PRId32" bytes, strip size %"PRIu32, + strip + 1, bytes_read, stripsize); if (bytes_read < 0 && !ignore) { - TIFFError("", "Error reading strip %lu after %lu rows", - (unsigned long) strip, (unsigned long)rows); + TIFFError("", "Error reading strip %"PRIu32" after %"PRIu32" rows", + strip, rows); return 0; } bufp += stripsize; @@ -3760,11 +3752,11 @@ static int readContigStripsIntoBuffer (TIFF* in, uint8* buf) static int combineSeparateSamplesBytes (unsigned char *srcbuffs[], unsigned char *out, - uint32 cols, uint32 rows, uint16 spp, uint16 bps, + uint32_t cols, uint32_t rows, uint16_t spp, uint16_t bps, FILE *dumpfile, int format, int level) { int i, bytes_per_sample; - uint32 row, col, col_offset, src_rowsize, dst_rowsize, row_offset; + uint32_t row, col, col_offset, src_rowsize, dst_rowsize, row_offset; unsigned char *src; unsigned char *dst; tsample_t s; @@ -3787,7 +3779,7 @@ combineSeparateSamplesBytes (unsigned char *srcbuffs[], unsigned char *out, { for (s = 0; s < spp; s++) { - dump_info (dumpfile, format, "combineSeparateSamplesBytes","Input data, Sample %d", s); + dump_info (dumpfile, format, "combineSeparateSamplesBytes","Input data, Sample %"PRIu16, s); dump_buffer(dumpfile, format, 1, cols, row, srcbuffs[s] + (row * src_rowsize)); } } @@ -3817,17 +3809,17 @@ combineSeparateSamplesBytes (unsigned char *srcbuffs[], unsigned char *out, } /* end combineSeparateSamplesBytes */ static int -combineSeparateSamples8bits (uint8 *in[], uint8 *out, uint32 cols, - uint32 rows, uint16 spp, uint16 bps, - FILE *dumpfile, int format, int level) +combineSeparateSamples8bits (uint8_t *in[], uint8_t *out, uint32_t cols, + uint32_t rows, uint16_t spp, uint16_t bps, + FILE *dumpfile, int format, int level) { int ready_bits = 0; /* int bytes_per_sample = 0; */ - uint32 src_rowsize, dst_rowsize, src_offset; - uint32 bit_offset; - uint32 row, col, src_byte = 0, src_bit = 0; - uint8 maskbits = 0, matchbits = 0; - uint8 buff1 = 0, buff2 = 0; + uint32_t src_rowsize, dst_rowsize, src_offset; + uint32_t bit_offset; + uint32_t row, col, src_byte = 0, src_bit = 0; + uint8_t maskbits = 0, matchbits = 0; + uint8_t buff1 = 0, buff2 = 0; tsample_t s; unsigned char *src = in[0]; unsigned char *dst = out; @@ -3842,7 +3834,7 @@ combineSeparateSamples8bits (uint8 *in[], uint8 *out, uint32 cols, /* bytes_per_sample = (bps + 7) / 8; */ src_rowsize = ((bps * cols) + 7) / 8; dst_rowsize = ((bps * cols * spp) + 7) / 8; - maskbits = (uint8)-1 >> ( 8 - bps); + maskbits = (uint8_t)-1 >> (8 - bps); for (row = 0; row < rows; row++) { @@ -3882,8 +3874,8 @@ combineSeparateSamples8bits (uint8 *in[], uint8 *out, uint32 cols, if ((dumpfile != NULL) && (level == 3)) { dump_info (dumpfile, format, "", - "Row %3d, Col %3d, Samples %d, Src byte offset %3d bit offset %2d Dst offset %3d", - row + 1, col + 1, s, src_byte, src_bit, dst - out); + "Row %3"PRIu32", Col %3"PRIu32", Samples %"PRIu16", Src byte offset %3"PRIu32" bit offset %2"PRIu32" Dst offset %3td", + row + 1u, col + 1u, s, src_byte, src_bit, dst - out); dump_byte (dumpfile, format, "Match bits", matchbits); dump_byte (dumpfile, format, "Src bits", *src); dump_byte (dumpfile, format, "Buff1 bits", buff1); @@ -3900,8 +3892,8 @@ combineSeparateSamples8bits (uint8 *in[], uint8 *out, uint32 cols, if ((dumpfile != NULL) && (level == 3)) { dump_info (dumpfile, format, "", - "Row %3d, Col %3d, Src byte offset %3d bit offset %2d Dst offset %3d", - row + 1, col + 1, src_byte, src_bit, dst - out); + "Row %3"PRIu32", Col %3"PRIu32", Src byte offset %3"PRIu32" bit offset %2"PRIu32" Dst offset %3td", + row + 1u, col + 1u, src_byte, src_bit, dst - out); dump_byte (dumpfile, format, "Final bits", buff1); } } @@ -3917,17 +3909,17 @@ combineSeparateSamples8bits (uint8 *in[], uint8 *out, uint32 cols, } /* end combineSeparateSamples8bits */ static int -combineSeparateSamples16bits (uint8 *in[], uint8 *out, uint32 cols, - uint32 rows, uint16 spp, uint16 bps, - FILE *dumpfile, int format, int level) +combineSeparateSamples16bits (uint8_t *in[], uint8_t *out, uint32_t cols, + uint32_t rows, uint16_t spp, uint16_t bps, + FILE *dumpfile, int format, int level) { int ready_bits = 0 /*, bytes_per_sample = 0 */; - uint32 src_rowsize, dst_rowsize; - uint32 bit_offset, src_offset; - uint32 row, col, src_byte = 0, src_bit = 0; - uint16 maskbits = 0, matchbits = 0; - uint16 buff1 = 0, buff2 = 0; - uint8 bytebuff = 0; + uint32_t src_rowsize, dst_rowsize; + uint32_t bit_offset, src_offset; + uint32_t row, col, src_byte = 0, src_bit = 0; + uint16_t maskbits = 0, matchbits = 0; + uint16_t buff1 = 0, buff2 = 0; + uint8_t bytebuff = 0; tsample_t s; unsigned char *src = in[0]; unsigned char *dst = out; @@ -3942,7 +3934,7 @@ combineSeparateSamples16bits (uint8 *in[], uint8 *out, uint32 cols, /* bytes_per_sample = (bps + 7) / 8; */ src_rowsize = ((bps * cols) + 7) / 8; dst_rowsize = ((bps * cols * spp) + 7) / 8; - maskbits = (uint16)-1 >> (16 - bps); + maskbits = (uint16_t)-1 >> (16 - bps); for (row = 0; row < rows; row++) { @@ -3989,8 +3981,8 @@ combineSeparateSamples16bits (uint8 *in[], uint8 *out, uint32 cols, if ((dumpfile != NULL) && (level == 3)) { dump_info (dumpfile, format, "", - "Row %3d, Col %3d, Samples %d, Src byte offset %3d bit offset %2d Dst offset %3d", - row + 1, col + 1, s, src_byte, src_bit, dst - out); + "Row %3"PRIu32", Col %3"PRIu32", Samples %"PRIu16", Src byte offset %3"PRIu32" bit offset %2"PRIu32" Dst offset %3td", + row + 1u, col + 1u, s, src_byte, src_bit, dst - out); dump_short (dumpfile, format, "Match bits", matchbits); dump_data (dumpfile, format, "Src bits", src, 2); @@ -4027,17 +4019,17 @@ combineSeparateSamples16bits (uint8 *in[], uint8 *out, uint32 cols, } /* end combineSeparateSamples16bits */ static int -combineSeparateSamples24bits (uint8 *in[], uint8 *out, uint32 cols, - uint32 rows, uint16 spp, uint16 bps, - FILE *dumpfile, int format, int level) +combineSeparateSamples24bits (uint8_t *in[], uint8_t *out, uint32_t cols, + uint32_t rows, uint16_t spp, uint16_t bps, + FILE *dumpfile, int format, int level) { int ready_bits = 0 /*, bytes_per_sample = 0 */; - uint32 src_rowsize, dst_rowsize; - uint32 bit_offset, src_offset; - uint32 row, col, src_byte = 0, src_bit = 0; - uint32 maskbits = 0, matchbits = 0; - uint32 buff1 = 0, buff2 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0; + uint32_t src_rowsize, dst_rowsize; + uint32_t bit_offset, src_offset; + uint32_t row, col, src_byte = 0, src_bit = 0; + uint32_t maskbits = 0, matchbits = 0; + uint32_t buff1 = 0, buff2 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0; tsample_t s; unsigned char *src = in[0]; unsigned char *dst = out; @@ -4052,7 +4044,7 @@ combineSeparateSamples24bits (uint8 *in[], uint8 *out, uint32 cols, /* bytes_per_sample = (bps + 7) / 8; */ src_rowsize = ((bps * cols) + 7) / 8; dst_rowsize = ((bps * cols * spp) + 7) / 8; - maskbits = (uint32)-1 >> ( 32 - bps); + maskbits = (uint32_t)-1 >> (32 - bps); for (row = 0; row < rows; row++) { @@ -4072,9 +4064,9 @@ combineSeparateSamples24bits (uint8 *in[], uint8 *out, uint32 cols, { src = in[s] + src_offset + src_byte; if (little_endian) - buff1 = ((uint32)src[0] << 24) | ((uint32)src[1] << 16) | ((uint32)src[2] << 8) | (uint32)src[3]; + buff1 = ((uint32_t)src[0] << 24) | ((uint32_t)src[1] << 16) | ((uint32_t)src[2] << 8) | (uint32_t)src[3]; else - buff1 = ((uint32)src[3] << 24) | ((uint32)src[2] << 16) | ((uint32)src[1] << 8) | (uint32)src[0]; + buff1 = ((uint32_t)src[3] << 24) | ((uint32_t)src[2] << 16) | ((uint32_t)src[1] << 8) | (uint32_t)src[0]; buff1 = (buff1 & matchbits) << (src_bit); /* If we have a full buffer's worth, write it out */ @@ -4101,8 +4093,8 @@ combineSeparateSamples24bits (uint8 *in[], uint8 *out, uint32 cols, if ((dumpfile != NULL) && (level == 3)) { dump_info (dumpfile, format, "", - "Row %3d, Col %3d, Samples %d, Src byte offset %3d bit offset %2d Dst offset %3d", - row + 1, col + 1, s, src_byte, src_bit, dst - out); + "Row %3"PRIu32", Col %3"PRIu32", Samples %"PRIu16", Src byte offset %3"PRIu32" bit offset %2"PRIu32" Dst offset %3td", + row + 1u, col + 1u, s, src_byte, src_bit, dst - out); dump_long (dumpfile, format, "Match bits ", matchbits); dump_data (dumpfile, format, "Src bits ", src, 4); dump_long (dumpfile, format, "Buff1 bits ", buff1); @@ -4151,18 +4143,18 @@ combineSeparateSamples24bits (uint8 *in[], uint8 *out, uint32 cols, } /* end combineSeparateSamples24bits */ static int -combineSeparateSamples32bits (uint8 *in[], uint8 *out, uint32 cols, - uint32 rows, uint16 spp, uint16 bps, - FILE *dumpfile, int format, int level) +combineSeparateSamples32bits (uint8_t *in[], uint8_t *out, uint32_t cols, + uint32_t rows, uint16_t spp, uint16_t bps, + FILE *dumpfile, int format, int level) { int ready_bits = 0 /*, bytes_per_sample = 0, shift_width = 0 */; - uint32 src_rowsize, dst_rowsize, bit_offset, src_offset; - uint32 src_byte = 0, src_bit = 0; - uint32 row, col; - uint32 longbuff1 = 0, longbuff2 = 0; - uint64 maskbits = 0, matchbits = 0; - uint64 buff1 = 0, buff2 = 0, buff3 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; + uint32_t src_rowsize, dst_rowsize, bit_offset, src_offset; + uint32_t src_byte = 0, src_bit = 0; + uint32_t row, col; + uint32_t longbuff1 = 0, longbuff2 = 0; + uint64_t maskbits = 0, matchbits = 0; + uint64_t buff1 = 0, buff2 = 0, buff3 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; tsample_t s; unsigned char *src = in[0]; unsigned char *dst = out; @@ -4177,7 +4169,7 @@ combineSeparateSamples32bits (uint8 *in[], uint8 *out, uint32 cols, /* bytes_per_sample = (bps + 7) / 8; */ src_rowsize = ((bps * cols) + 7) / 8; dst_rowsize = ((bps * cols * spp) + 7) / 8; - maskbits = (uint64)-1 >> ( 64 - bps); + maskbits = (uint64_t)-1 >> (64 - bps); /* shift_width = ((bps + 7) / 8) + 1; */ for (row = 0; row < rows; row++) @@ -4207,7 +4199,7 @@ combineSeparateSamples32bits (uint8 *in[], uint8 *out, uint32 cols, longbuff1 = (src[3] << 24) | (src[2] << 16) | (src[1] << 8) | src[0]; longbuff2 = longbuff1; } - buff3 = ((uint64)longbuff1 << 32) | longbuff2; + buff3 = ((uint64_t)longbuff1 << 32) | longbuff2; buff1 = (buff3 & matchbits) << (src_bit); /* If we have a full buffer's worth, write it out */ @@ -4238,8 +4230,8 @@ combineSeparateSamples32bits (uint8 *in[], uint8 *out, uint32 cols, if ((dumpfile != NULL) && (level == 3)) { dump_info (dumpfile, format, "", - "Row %3d, Col %3d, Sample %d, Src byte offset %3d bit offset %2d Dst offset %3d", - row + 1, col + 1, s, src_byte, src_bit, dst - out); + "Row %3"PRIu32", Col %3"PRIu32", Sample %"PRIu16", Src byte offset %3"PRIu32" bit offset %2"PRIu32" Dst offset %3td", + row + 1u, col + 1u, s, src_byte, src_bit, dst - out); dump_wide (dumpfile, format, "Match bits ", matchbits); dump_data (dumpfile, format, "Src bits ", src, 8); dump_wide (dumpfile, format, "Buff1 bits ", buff1); @@ -4283,12 +4275,12 @@ combineSeparateSamples32bits (uint8 *in[], uint8 *out, uint32 cols, static int combineSeparateTileSamplesBytes (unsigned char *srcbuffs[], unsigned char *out, - uint32 cols, uint32 rows, uint32 imagewidth, - uint32 tw, uint16 spp, uint16 bps, + uint32_t cols, uint32_t rows, uint32_t imagewidth, + uint32_t tw, uint16_t spp, uint16_t bps, FILE *dumpfile, int format, int level) { int i, bytes_per_sample; - uint32 row, col, col_offset, src_rowsize, dst_rowsize, src_offset; + uint32_t row, col, col_offset, src_rowsize, dst_rowsize, src_offset; unsigned char *src; unsigned char *dst; tsample_t s; @@ -4310,7 +4302,7 @@ combineSeparateTileSamplesBytes (unsigned char *srcbuffs[], unsigned char *out, { for (s = 0; s < spp; s++) { - dump_info (dumpfile, format, "combineSeparateTileSamplesBytes","Input data, Sample %d", s); + dump_info (dumpfile, format, "combineSeparateTileSamplesBytes","Input data, Sample %"PRIu16, s); dump_buffer(dumpfile, format, 1, cols, row, srcbuffs[s] + (row * src_rowsize)); } } @@ -4343,17 +4335,17 @@ combineSeparateTileSamplesBytes (unsigned char *srcbuffs[], unsigned char *out, } /* end combineSeparateTileSamplesBytes */ static int -combineSeparateTileSamples8bits (uint8 *in[], uint8 *out, uint32 cols, - uint32 rows, uint32 imagewidth, - uint32 tw, uint16 spp, uint16 bps, - FILE *dumpfile, int format, int level) +combineSeparateTileSamples8bits (uint8_t *in[], uint8_t *out, uint32_t cols, + uint32_t rows, uint32_t imagewidth, + uint32_t tw, uint16_t spp, uint16_t bps, + FILE *dumpfile, int format, int level) { int ready_bits = 0; - uint32 src_rowsize, dst_rowsize, src_offset; - uint32 bit_offset; - uint32 row, col, src_byte = 0, src_bit = 0; - uint8 maskbits = 0, matchbits = 0; - uint8 buff1 = 0, buff2 = 0; + uint32_t src_rowsize, dst_rowsize, src_offset; + uint32_t bit_offset; + uint32_t row, col, src_byte = 0, src_bit = 0; + uint8_t maskbits = 0, matchbits = 0; + uint8_t buff1 = 0, buff2 = 0; tsample_t s; unsigned char *src = in[0]; unsigned char *dst = out; @@ -4367,7 +4359,7 @@ combineSeparateTileSamples8bits (uint8 *in[], uint8 *out, uint32 cols, src_rowsize = ((bps * tw) + 7) / 8; dst_rowsize = ((imagewidth * bps * spp) + 7) / 8; - maskbits = (uint8)-1 >> ( 8 - bps); + maskbits = (uint8_t)-1 >> (8 - bps); for (row = 0; row < rows; row++) { @@ -4407,8 +4399,8 @@ combineSeparateTileSamples8bits (uint8 *in[], uint8 *out, uint32 cols, if ((dumpfile != NULL) && (level == 3)) { dump_info (dumpfile, format, "", - "Row %3d, Col %3d, Samples %d, Src byte offset %3d bit offset %2d Dst offset %3d", - row + 1, col + 1, s, src_byte, src_bit, dst - out); + "Row %3"PRIu32", Col %3"PRIu32", Samples %"PRIu16", Src byte offset %3"PRIu32" bit offset %2"PRIu32" Dst offset %3td", + row + 1u, col + 1u, s, src_byte, src_bit, dst - out); dump_byte (dumpfile, format, "Match bits", matchbits); dump_byte (dumpfile, format, "Src bits", *src); dump_byte (dumpfile, format, "Buff1 bits", buff1); @@ -4442,18 +4434,18 @@ combineSeparateTileSamples8bits (uint8 *in[], uint8 *out, uint32 cols, } /* end combineSeparateTileSamples8bits */ static int -combineSeparateTileSamples16bits (uint8 *in[], uint8 *out, uint32 cols, - uint32 rows, uint32 imagewidth, - uint32 tw, uint16 spp, uint16 bps, - FILE *dumpfile, int format, int level) +combineSeparateTileSamples16bits (uint8_t *in[], uint8_t *out, uint32_t cols, + uint32_t rows, uint32_t imagewidth, + uint32_t tw, uint16_t spp, uint16_t bps, + FILE *dumpfile, int format, int level) { int ready_bits = 0; - uint32 src_rowsize, dst_rowsize; - uint32 bit_offset, src_offset; - uint32 row, col, src_byte = 0, src_bit = 0; - uint16 maskbits = 0, matchbits = 0; - uint16 buff1 = 0, buff2 = 0; - uint8 bytebuff = 0; + uint32_t src_rowsize, dst_rowsize; + uint32_t bit_offset, src_offset; + uint32_t row, col, src_byte = 0, src_bit = 0; + uint16_t maskbits = 0, matchbits = 0; + uint16_t buff1 = 0, buff2 = 0; + uint8_t bytebuff = 0; tsample_t s; unsigned char *src = in[0]; unsigned char *dst = out; @@ -4467,7 +4459,7 @@ combineSeparateTileSamples16bits (uint8 *in[], uint8 *out, uint32 cols, src_rowsize = ((bps * tw) + 7) / 8; dst_rowsize = ((imagewidth * bps * spp) + 7) / 8; - maskbits = (uint16)-1 >> (16 - bps); + maskbits = (uint16_t)-1 >> (16 - bps); for (row = 0; row < rows; row++) { @@ -4513,8 +4505,8 @@ combineSeparateTileSamples16bits (uint8 *in[], uint8 *out, uint32 cols, if ((dumpfile != NULL) && (level == 3)) { dump_info (dumpfile, format, "", - "Row %3d, Col %3d, Samples %d, Src byte offset %3d bit offset %2d Dst offset %3d", - row + 1, col + 1, s, src_byte, src_bit, dst - out); + "Row %3"PRIu32", Col %3"PRIu32", Samples %"PRIu16", Src byte offset %3"PRIu32" bit offset %2"PRIu32" Dst offset %3td", + row + 1u, col + 1u, s, src_byte, src_bit, dst - out); dump_short (dumpfile, format, "Match bits", matchbits); dump_data (dumpfile, format, "Src bits", src, 2); @@ -4551,18 +4543,18 @@ combineSeparateTileSamples16bits (uint8 *in[], uint8 *out, uint32 cols, } /* end combineSeparateTileSamples16bits */ static int -combineSeparateTileSamples24bits (uint8 *in[], uint8 *out, uint32 cols, - uint32 rows, uint32 imagewidth, - uint32 tw, uint16 spp, uint16 bps, - FILE *dumpfile, int format, int level) +combineSeparateTileSamples24bits (uint8_t *in[], uint8_t *out, uint32_t cols, + uint32_t rows, uint32_t imagewidth, + uint32_t tw, uint16_t spp, uint16_t bps, + FILE *dumpfile, int format, int level) { int ready_bits = 0; - uint32 src_rowsize, dst_rowsize; - uint32 bit_offset, src_offset; - uint32 row, col, src_byte = 0, src_bit = 0; - uint32 maskbits = 0, matchbits = 0; - uint32 buff1 = 0, buff2 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0; + uint32_t src_rowsize, dst_rowsize; + uint32_t bit_offset, src_offset; + uint32_t row, col, src_byte = 0, src_bit = 0; + uint32_t maskbits = 0, matchbits = 0; + uint32_t buff1 = 0, buff2 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0; tsample_t s; unsigned char *src = in[0]; unsigned char *dst = out; @@ -4576,7 +4568,7 @@ combineSeparateTileSamples24bits (uint8 *in[], uint8 *out, uint32 cols, src_rowsize = ((bps * tw) + 7) / 8; dst_rowsize = ((imagewidth * bps * spp) + 7) / 8; - maskbits = (uint32)-1 >> ( 32 - bps); + maskbits = (uint32_t)-1 >> (32 - bps); for (row = 0; row < rows; row++) { @@ -4625,8 +4617,8 @@ combineSeparateTileSamples24bits (uint8 *in[], uint8 *out, uint32 cols, if ((dumpfile != NULL) && (level == 3)) { dump_info (dumpfile, format, "", - "Row %3d, Col %3d, Samples %d, Src byte offset %3d bit offset %2d Dst offset %3d", - row + 1, col + 1, s, src_byte, src_bit, dst - out); + "Row %3"PRIu32", Col %3"PRIu32", Samples %"PRIu16", Src byte offset %3"PRIu32" bit offset %2"PRIu32" Dst offset %3td", + row + 1u, col + 1u, s, src_byte, src_bit, dst - out); dump_long (dumpfile, format, "Match bits ", matchbits); dump_data (dumpfile, format, "Src bits ", src, 4); dump_long (dumpfile, format, "Buff1 bits ", buff1); @@ -4675,19 +4667,19 @@ combineSeparateTileSamples24bits (uint8 *in[], uint8 *out, uint32 cols, } /* end combineSeparateTileSamples24bits */ static int -combineSeparateTileSamples32bits (uint8 *in[], uint8 *out, uint32 cols, - uint32 rows, uint32 imagewidth, - uint32 tw, uint16 spp, uint16 bps, - FILE *dumpfile, int format, int level) +combineSeparateTileSamples32bits (uint8_t *in[], uint8_t *out, uint32_t cols, + uint32_t rows, uint32_t imagewidth, + uint32_t tw, uint16_t spp, uint16_t bps, + FILE *dumpfile, int format, int level) { int ready_bits = 0 /*, shift_width = 0 */; - uint32 src_rowsize, dst_rowsize, bit_offset, src_offset; - uint32 src_byte = 0, src_bit = 0; - uint32 row, col; - uint32 longbuff1 = 0, longbuff2 = 0; - uint64 maskbits = 0, matchbits = 0; - uint64 buff1 = 0, buff2 = 0, buff3 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; + uint32_t src_rowsize, dst_rowsize, bit_offset, src_offset; + uint32_t src_byte = 0, src_bit = 0; + uint32_t row, col; + uint32_t longbuff1 = 0, longbuff2 = 0; + uint64_t maskbits = 0, matchbits = 0; + uint64_t buff1 = 0, buff2 = 0, buff3 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; tsample_t s; unsigned char *src = in[0]; unsigned char *dst = out; @@ -4701,7 +4693,7 @@ combineSeparateTileSamples32bits (uint8 *in[], uint8 *out, uint32 cols, src_rowsize = ((bps * tw) + 7) / 8; dst_rowsize = ((imagewidth * bps * spp) + 7) / 8; - maskbits = (uint64)-1 >> ( 64 - bps); + maskbits = (uint64_t)-1 >> (64 - bps); /* shift_width = ((bps + 7) / 8) + 1; */ for (row = 0; row < rows; row++) @@ -4732,7 +4724,7 @@ combineSeparateTileSamples32bits (uint8 *in[], uint8 *out, uint32 cols, longbuff2 = longbuff1; } - buff3 = ((uint64)longbuff1 << 32) | longbuff2; + buff3 = ((uint64_t)longbuff1 << 32) | longbuff2; buff1 = (buff3 & matchbits) << (src_bit); /* If we have a full buffer's worth, write it out */ @@ -4763,8 +4755,8 @@ combineSeparateTileSamples32bits (uint8 *in[], uint8 *out, uint32 cols, if ((dumpfile != NULL) && (level == 3)) { dump_info (dumpfile, format, "", - "Row %3d, Col %3d, Sample %d, Src byte offset %3d bit offset %2d Dst offset %3d", - row + 1, col + 1, s, src_byte, src_bit, dst - out); + "Row %3"PRIu32", Col %3"PRIu32", Sample %"PRIu16", Src byte offset %3"PRIu32" bit offset %2"PRIu32" Dst offset %3td", + row + 1u, col + 1u, s, src_byte, src_bit, dst - out); dump_wide (dumpfile, format, "Match bits ", matchbits); dump_data (dumpfile, format, "Src bits ", src, 8); dump_wide (dumpfile, format, "Buff1 bits ", buff1); @@ -4807,18 +4799,18 @@ combineSeparateTileSamples32bits (uint8 *in[], uint8 *out, uint32 cols, } /* end combineSeparateTileSamples32bits */ -static int readSeparateStripsIntoBuffer (TIFF *in, uint8 *obuf, uint32 length, - uint32 width, uint16 spp, +static int readSeparateStripsIntoBuffer (TIFF *in, uint8_t *obuf, uint32_t length, + uint32_t width, uint16_t spp, struct dump_opts *dump) { int i, bytes_per_sample, bytes_per_pixel, shift_width, result = 1; - uint32 j; - int32 bytes_read = 0; - uint16 bps = 0, planar; - uint32 nstrips; - uint32 strips_per_sample; - uint32 src_rowsize, dst_rowsize, rows_processed, rps; - uint32 rows_this_strip = 0; + uint32_t j; + int32_t bytes_read = 0; + uint16_t bps = 0, planar; + uint32_t nstrips; + uint32_t strips_per_sample; + uint32_t src_rowsize, dst_rowsize, rows_processed, rps; + uint32_t rows_this_strip = 0; tsample_t s; tstrip_t strip; tsize_t scanlinesize = TIFFScanlineSize(in); @@ -4854,10 +4846,10 @@ static int readSeparateStripsIntoBuffer (TIFF *in, uint8 *obuf, uint32 length, if ((dump->infile != NULL) && (dump->level == 3)) { dump_info (dump->infile, dump->format, "", - "Image width %d, length %d, Scanline size, %4d bytes", + "Image width %"PRIu32", length %"PRIu32", Scanline size, %4"PRId64" bytes", width, length, scanlinesize); dump_info (dump->infile, dump->format, "", - "Bits per sample %d, Samples per pixel %d, Shift width %d", + "Bits per sample %"PRIu16", Samples per pixel %"PRIu16", Shift width %d", bps, spp, shift_width); } @@ -4883,7 +4875,7 @@ static int readSeparateStripsIntoBuffer (TIFF *in, uint8 *obuf, uint32 length, if (!buff) { TIFFError ("readSeparateStripsIntoBuffer", - "Unable to allocate strip read buffer for sample %d", s); + "Unable to allocate strip read buffer for sample %"PRIu16, s); for (i = 0; i < s; i++) _TIFFfree (srcbuffs[i]); return 0; @@ -4906,13 +4898,13 @@ static int readSeparateStripsIntoBuffer (TIFF *in, uint8 *obuf, uint32 length, if (bytes_read < 0 && !ignore) { TIFFError(TIFFFileName(in), - "Error, can't read strip %lu for sample %d", - (unsigned long) strip, s + 1); + "Error, can't read strip %"PRIu32" for sample %"PRIu32, + strip, s + 1u); result = 0; break; } #ifdef DEVELMODE - TIFFError("", "Strip %2d, read %5d bytes for %4d scanlines, shift width %d", + TIFFError("", "Strip %2"PRIu32", read %5"PRId32" bytes for %4"PRIu32" scanlines, shift width %d", strip, bytes_read, rows_this_strip, shift_width); #endif } @@ -4970,7 +4962,7 @@ static int readSeparateStripsIntoBuffer (TIFF *in, uint8 *obuf, uint32 length, break; } break; - default: TIFFError ("readSeparateStripsIntoBuffer", "Unsupported bit depth: %d", bps); + default: TIFFError ("readSeparateStripsIntoBuffer", "Unsupported bit depth: %"PRIu16, bps); result = 0; break; } @@ -5002,7 +4994,7 @@ static int get_page_geometry (char *name, struct pagedef *page) { char *ptr; - int n; + unsigned int n; for (ptr = name; *ptr; ptr++) *ptr = (char)tolower((int)*ptr); @@ -5044,11 +5036,11 @@ initPageSetup (struct pagedef *page, struct pageseg *pagelist, for (i = 0; i < MAX_SECTIONS; i++) { - pagelist[i].x1 = (uint32)0; - pagelist[i].x2 = (uint32)0; - pagelist[i].y1 = (uint32)0; - pagelist[i].y2 = (uint32)0; - pagelist[i].buffsize = (uint32)0; + pagelist[i].x1 = (uint32_t)0; + pagelist[i].x2 = (uint32_t)0; + pagelist[i].y1 = (uint32_t)0; + pagelist[i].y2 = (uint32_t)0; + pagelist[i].buffsize = (uint32_t)0; pagelist[i].position = 0; pagelist[i].total = 0; } @@ -5089,15 +5081,15 @@ initCropMasks (struct crop_mask *cps) cps->length = 0; for (i = 0; i < 4; i++) cps->margins[i] = 0.0; - cps->bufftotal = (uint32)0; - cps->combined_width = (uint32)0; - cps->combined_length = (uint32)0; - cps->rotation = (uint16)0; + cps->bufftotal = (uint32_t)0; + cps->combined_width = (uint32_t)0; + cps->combined_length = (uint32_t)0; + cps->rotation = (uint16_t)0; cps->photometric = INVERT_DATA_AND_TAG; - cps->mirror = (uint16)0; - cps->invert = (uint16)0; - cps->zones = (uint32)0; - cps->regions = (uint32)0; + cps->mirror = (uint16_t)0; + cps->invert = (uint16_t)0; + cps->zones = (uint32_t)0; + cps->regions = (uint32_t)0; for (i = 0; i < MAX_REGIONS; i++) { cps->corners[i].X1 = 0.0; @@ -5140,12 +5132,12 @@ computeInputPixelOffsets(struct crop_mask *crop, struct image_data *image, float xres, yres; /* Values for these offsets are in pixels from start of image, not bytes, * and are indexed from zero to width - 1 or length - 1 */ - uint32 tmargin, bmargin, lmargin, rmargin; - uint32 startx, endx; /* offsets of first and last columns to extract */ - uint32 starty, endy; /* offsets of first and last row to extract */ - uint32 width, length, crop_width, crop_length; - uint32 i, max_width, max_length, zwidth, zlength, buffsize; - uint32 x1, x2, y1, y2; + uint32_t tmargin, bmargin, lmargin, rmargin; + uint32_t startx, endx; /* offsets of first and last columns to extract */ + uint32_t starty, endy; /* offsets of first and last row to extract */ + uint32_t width, length, crop_width, crop_length; + uint32_t i, max_width, max_length, zwidth, zlength, buffsize; + uint32_t x1, x2, y1, y2; if (image->res_unit != RESUNIT_INCH && image->res_unit != RESUNIT_CENTIMETER) { @@ -5190,38 +5182,38 @@ computeInputPixelOffsets(struct crop_mask *crop, struct image_data *image, { if ((crop->res_unit == RESUNIT_INCH) || (crop->res_unit == RESUNIT_CENTIMETER)) { - x1 = (uint32) (crop->corners[i].X1 * scale * xres); - x2 = (uint32) (crop->corners[i].X2 * scale * xres); - y1 = (uint32) (crop->corners[i].Y1 * scale * yres); - y2 = (uint32) (crop->corners[i].Y2 * scale * yres); + x1 = (uint32_t) (crop->corners[i].X1 * scale * xres); + x2 = (uint32_t) (crop->corners[i].X2 * scale * xres); + y1 = (uint32_t) (crop->corners[i].Y1 * scale * yres); + y2 = (uint32_t) (crop->corners[i].Y2 * scale * yres); } else { - x1 = (uint32) (crop->corners[i].X1); - x2 = (uint32) (crop->corners[i].X2); - y1 = (uint32) (crop->corners[i].Y1); - y2 = (uint32) (crop->corners[i].Y2); + x1 = (uint32_t) (crop->corners[i].X1); + x2 = (uint32_t) (crop->corners[i].X2); + y1 = (uint32_t) (crop->corners[i].Y1); + y2 = (uint32_t) (crop->corners[i].Y2); } if (x1 < 1) crop->regionlist[i].x1 = 0; else - crop->regionlist[i].x1 = (uint32) (x1 - 1); + crop->regionlist[i].x1 = (uint32_t) (x1 - 1); if (x2 > image->width - 1) crop->regionlist[i].x2 = image->width - 1; else - crop->regionlist[i].x2 = (uint32) (x2 - 1); + crop->regionlist[i].x2 = (uint32_t) (x2 - 1); zwidth = crop->regionlist[i].x2 - crop->regionlist[i].x1 + 1; if (y1 < 1) crop->regionlist[i].y1 = 0; else - crop->regionlist[i].y1 = (uint32) (y1 - 1); + crop->regionlist[i].y1 = (uint32_t) (y1 - 1); if (y2 > image->length - 1) crop->regionlist[i].y2 = image->length - 1; else - crop->regionlist[i].y2 = (uint32) (y2 - 1); + crop->regionlist[i].y2 = (uint32_t) (y2 - 1); zlength = crop->regionlist[i].y2 - crop->regionlist[i].y1 + 1; @@ -5230,7 +5222,7 @@ computeInputPixelOffsets(struct crop_mask *crop, struct image_data *image, if (zlength > max_length) max_length = zlength; - buffsize = (uint32) + buffsize = (uint32_t) (((zwidth * image->bps * image->spp + 7 ) / 8) * (zlength + 1)); crop->regionlist[i].buffsize = buffsize; @@ -5263,64 +5255,64 @@ computeInputPixelOffsets(struct crop_mask *crop, struct image_data *image, { if (crop->res_unit != RESUNIT_INCH && crop->res_unit != RESUNIT_CENTIMETER) { /* User has specified pixels as reference unit */ - tmargin = (uint32)(crop->margins[0]); - lmargin = (uint32)(crop->margins[1]); - bmargin = (uint32)(crop->margins[2]); - rmargin = (uint32)(crop->margins[3]); + tmargin = (uint32_t)(crop->margins[0]); + lmargin = (uint32_t)(crop->margins[1]); + bmargin = (uint32_t)(crop->margins[2]); + rmargin = (uint32_t)(crop->margins[3]); } else { /* inches or centimeters specified */ - tmargin = (uint32)(crop->margins[0] * scale * yres); - lmargin = (uint32)(crop->margins[1] * scale * xres); - bmargin = (uint32)(crop->margins[2] * scale * yres); - rmargin = (uint32)(crop->margins[3] * scale * xres); + tmargin = (uint32_t)(crop->margins[0] * scale * yres); + lmargin = (uint32_t)(crop->margins[1] * scale * xres); + bmargin = (uint32_t)(crop->margins[2] * scale * yres); + rmargin = (uint32_t)(crop->margins[3] * scale * xres); } if ((lmargin + rmargin) > image->width) { TIFFError("computeInputPixelOffsets", "Combined left and right margins exceed image width"); - lmargin = (uint32) 0; - rmargin = (uint32) 0; + lmargin = (uint32_t) 0; + rmargin = (uint32_t) 0; return (-1); } if ((tmargin + bmargin) > image->length) { TIFFError("computeInputPixelOffsets", "Combined top and bottom margins exceed image length"); - tmargin = (uint32) 0; - bmargin = (uint32) 0; + tmargin = (uint32_t) 0; + bmargin = (uint32_t) 0; return (-1); } } else { /* no margins requested */ - tmargin = (uint32) 0; - lmargin = (uint32) 0; - bmargin = (uint32) 0; - rmargin = (uint32) 0; + tmargin = (uint32_t) 0; + lmargin = (uint32_t) 0; + bmargin = (uint32_t) 0; + rmargin = (uint32_t) 0; } /* Width, height, and margins are expressed as pixel offsets into image */ if (crop->res_unit != RESUNIT_INCH && crop->res_unit != RESUNIT_CENTIMETER) { if (crop->crop_mode & CROP_WIDTH) - width = (uint32)crop->width; + width = (uint32_t)crop->width; else width = image->width - lmargin - rmargin; if (crop->crop_mode & CROP_LENGTH) - length = (uint32)crop->length; + length = (uint32_t)crop->length; else length = image->length - tmargin - bmargin; } else { if (crop->crop_mode & CROP_WIDTH) - width = (uint32)(crop->width * scale * image->xres); + width = (uint32_t)(crop->width * scale * image->xres); else width = image->width - lmargin - rmargin; if (crop->crop_mode & CROP_LENGTH) - length = (uint32)(crop->length * scale * image->yres); + length = (uint32_t)(crop->length * scale * image->yres); else length = image->length - tmargin - bmargin; } @@ -5424,15 +5416,15 @@ getCropOffsets(struct image_data *image, struct crop_mask *crop, struct dump_opt { struct offset offsets; int i; - int32 test; - uint32 seg, total, need_buff = 0; - uint32 buffsize; - uint32 zwidth, zlength; + int32_t test; + uint32_t seg, total, need_buff = 0; + uint32_t buffsize; + uint32_t zwidth, zlength; memset(&offsets, '\0', sizeof(struct offset)); crop->bufftotal = 0; - crop->combined_width = (uint32)0; - crop->combined_length = (uint32)0; + crop->combined_width = (uint32_t)0; + crop->combined_length = (uint32_t)0; crop->selections = 0; /* Compute pixel offsets if margins or fixed width or length specified */ @@ -5469,9 +5461,9 @@ getCropOffsets(struct image_data *image, struct crop_mask *crop, struct dump_opt if (dump->outfile != NULL) { - dump_info (dump->outfile, dump->format, "", "Margins: Top: %d Left: %d Bottom: %d Right: %d", + dump_info (dump->outfile, dump->format, "", "Margins: Top: %"PRIu32" Left: %"PRIu32" Bottom: %"PRIu32" Right: %"PRIu32, offsets.tmargin, offsets.lmargin, offsets.bmargin, offsets.rmargin); - dump_info (dump->outfile, dump->format, "", "Crop region within margins: Adjusted Width: %6d Length: %6d", + dump_info (dump->outfile, dump->format, "", "Crop region within margins: Adjusted Width: %6"PRIu32" Length: %6"PRIu32, offsets.crop_width, offsets.crop_length); } @@ -5511,14 +5503,14 @@ getCropOffsets(struct image_data *image, struct crop_mask *crop, struct dump_opt crop->regionlist[i].y2 = offsets.endy; crop->regionlist[i].x1 = offsets.startx + - (uint32)(offsets.crop_width * 1.0 * (seg - 1) / total); - test = (int32)offsets.startx + - (int32)(offsets.crop_width * 1.0 * seg / total); + (uint32_t)(offsets.crop_width * 1.0 * (seg - 1) / total); + test = (int32_t)offsets.startx + + (int32_t)(offsets.crop_width * 1.0 * seg / total); if (test < 1 ) crop->regionlist[i].x2 = 0; else { - if (test > (int32)(image->width - 1)) + if (test > (int32_t)(image->width - 1)) crop->regionlist[i].x2 = image->width - 1; else crop->regionlist[i].x2 = test - 1; @@ -5526,18 +5518,18 @@ getCropOffsets(struct image_data *image, struct crop_mask *crop, struct dump_opt zwidth = crop->regionlist[i].x2 - crop->regionlist[i].x1 + 1; /* This is passed to extractCropZone or extractCompositeZones */ - crop->combined_length = (uint32)zlength; + crop->combined_length = (uint32_t)zlength; if (crop->exp_mode == COMPOSITE_IMAGES) - crop->combined_width += (uint32)zwidth; + crop->combined_width += (uint32_t)zwidth; else - crop->combined_width = (uint32)zwidth; + crop->combined_width = (uint32_t)zwidth; break; case EDGE_BOTTOM: /* width from left, zones from bottom to top */ zwidth = offsets.crop_width; crop->regionlist[i].x1 = offsets.startx; crop->regionlist[i].x2 = offsets.endx; - test = offsets.endy - (uint32)(offsets.crop_length * 1.0 * seg / total); + test = offsets.endy - (uint32_t)(offsets.crop_length * 1.0 * seg / total); if (test < 1 ) crop->regionlist[i].y1 = 0; else @@ -5548,7 +5540,7 @@ getCropOffsets(struct image_data *image, struct crop_mask *crop, struct dump_opt crop->regionlist[i].y2 = 0; else { - if (test > (int32)(image->length - 1)) + if (test > (int32_t)(image->length - 1)) crop->regionlist[i].y2 = image->length - 1; else crop->regionlist[i].y2 = test; @@ -5557,10 +5549,10 @@ getCropOffsets(struct image_data *image, struct crop_mask *crop, struct dump_opt /* This is passed to extractCropZone or extractCompositeZones */ if (crop->exp_mode == COMPOSITE_IMAGES) - crop->combined_length += (uint32)zlength; + crop->combined_length += (uint32_t)zlength; else - crop->combined_length = (uint32)zlength; - crop->combined_width = (uint32)zwidth; + crop->combined_length = (uint32_t)zlength; + crop->combined_width = (uint32_t)zwidth; break; case EDGE_RIGHT: /* zones from right to left, length from top */ zlength = offsets.crop_length; @@ -5568,14 +5560,14 @@ getCropOffsets(struct image_data *image, struct crop_mask *crop, struct dump_opt crop->regionlist[i].y2 = offsets.endy; crop->regionlist[i].x1 = offsets.startx + - (uint32)(offsets.crop_width * (total - seg) * 1.0 / total); + (uint32_t)(offsets.crop_width * (total - seg) * 1.0 / total); test = offsets.startx + (offsets.crop_width * (total - seg + 1) * 1.0 / total); if (test < 1 ) crop->regionlist[i].x2 = 0; else { - if (test > (int32)(image->width - 1)) + if (test > (int32_t)(image->width - 1)) crop->regionlist[i].x2 = image->width - 1; else crop->regionlist[i].x2 = test - 1; @@ -5583,11 +5575,11 @@ getCropOffsets(struct image_data *image, struct crop_mask *crop, struct dump_opt zwidth = crop->regionlist[i].x2 - crop->regionlist[i].x1 + 1; /* This is passed to extractCropZone or extractCompositeZones */ - crop->combined_length = (uint32)zlength; + crop->combined_length = (uint32_t)zlength; if (crop->exp_mode == COMPOSITE_IMAGES) - crop->combined_width += (uint32)zwidth; + crop->combined_width += (uint32_t)zwidth; else - crop->combined_width = (uint32)zwidth; + crop->combined_width = (uint32_t)zwidth; break; case EDGE_TOP: /* width from left, zones from top to bottom */ default: @@ -5595,13 +5587,13 @@ getCropOffsets(struct image_data *image, struct crop_mask *crop, struct dump_opt crop->regionlist[i].x1 = offsets.startx; crop->regionlist[i].x2 = offsets.endx; - crop->regionlist[i].y1 = offsets.starty + (uint32)(offsets.crop_length * 1.0 * (seg - 1) / total); - test = offsets.starty + (uint32)(offsets.crop_length * 1.0 * seg / total); + crop->regionlist[i].y1 = offsets.starty + (uint32_t)(offsets.crop_length * 1.0 * (seg - 1) / total); + test = offsets.starty + (uint32_t)(offsets.crop_length * 1.0 * seg / total); if (test < 1 ) crop->regionlist[i].y2 = 0; else { - if (test > (int32)(image->length - 1)) + if (test > (int32_t)(image->length - 1)) crop->regionlist[i].y2 = image->length - 1; else crop->regionlist[i].y2 = test - 1; @@ -5610,26 +5602,26 @@ getCropOffsets(struct image_data *image, struct crop_mask *crop, struct dump_opt /* This is passed to extractCropZone or extractCompositeZones */ if (crop->exp_mode == COMPOSITE_IMAGES) - crop->combined_length += (uint32)zlength; + crop->combined_length += (uint32_t)zlength; else - crop->combined_length = (uint32)zlength; - crop->combined_width = (uint32)zwidth; + crop->combined_length = (uint32_t)zlength; + crop->combined_width = (uint32_t)zwidth; break; } /* end switch statement */ - buffsize = (uint32) + buffsize = (uint32_t) ((((zwidth * image->bps * image->spp) + 7 ) / 8) * (zlength + 1)); - crop->regionlist[i].width = (uint32) zwidth; - crop->regionlist[i].length = (uint32) zlength; + crop->regionlist[i].width = (uint32_t) zwidth; + crop->regionlist[i].length = (uint32_t) zlength; crop->regionlist[i].buffsize = buffsize; crop->bufftotal += buffsize; if (dump->outfile != NULL) - dump_info (dump->outfile, dump->format, "", "Zone %d, width: %4d, length: %4d, x1: %4d x2: %4d y1: %4d y2: %4d", - i + 1, (uint32)zwidth, (uint32)zlength, - crop->regionlist[i].x1, crop->regionlist[i].x2, - crop->regionlist[i].y1, crop->regionlist[i].y2); + dump_info (dump->outfile, dump->format, "", "Zone %d, width: %4"PRIu32", length: %4"PRIu32", x1: %4"PRIu32" x2: %4"PRIu32" y1: %4"PRIu32" y2: %4"PRIu32, + i + 1, zwidth, zlength, + crop->regionlist[i].x1, crop->regionlist[i].x2, + crop->regionlist[i].y1, crop->regionlist[i].y2); } return (0); @@ -5643,13 +5635,13 @@ computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image, { double scale; double pwidth, plength; /* Output page width and length in user units*/ - uint32 iwidth, ilength; /* Input image width and length in pixels*/ - uint32 owidth, olength; /* Output image width and length in pixels*/ - uint32 orows, ocols; /* rows and cols for output */ - uint32 hmargin, vmargin; /* Horizontal and vertical margins */ - uint32 x1, x2, y1, y2, line_bytes; + uint32_t iwidth, ilength; /* Input image width and length in pixels*/ + uint32_t owidth, olength; /* Output image width and length in pixels*/ + uint32_t orows, ocols; /* rows and cols for output */ + uint32_t hmargin, vmargin; /* Horizontal and vertical margins */ + uint32_t x1, x2, y1, y2, line_bytes; /* unsigned int orientation; */ - uint32 i, j, k; + uint32_t i, j, k; scale = 1.0; if (page->res_unit == RESUNIT_NONE) @@ -5710,7 +5702,7 @@ computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image, "Hmargin: %3.2f, Vmargin: %3.2f", page->name, page->vres, page->hres, page->hmargin, page->vmargin); - TIFFError("", "Res_unit: %d, Scale: %3.2f, Page width: %3.2f, length: %3.2f", + TIFFError("", "Res_unit: %"PRIu16", Scale: %3.2f, Page width: %3.2f, length: %3.2f", page->res_unit, scale, pwidth, plength); } @@ -5719,27 +5711,27 @@ computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image, { if (page->res_unit == RESUNIT_INCH || page->res_unit == RESUNIT_CENTIMETER) { /* inches or centimeters specified */ - hmargin = (uint32)(page->hmargin * scale * page->hres * ((image->bps + 7)/ 8)); - vmargin = (uint32)(page->vmargin * scale * page->vres * ((image->bps + 7)/ 8)); + hmargin = (uint32_t)(page->hmargin * scale * page->hres * ((image->bps + 7) / 8)); + vmargin = (uint32_t)(page->vmargin * scale * page->vres * ((image->bps + 7) / 8)); } else { /* Otherwise user has specified pixels as reference unit */ - hmargin = (uint32)(page->hmargin * scale * ((image->bps + 7)/ 8)); - vmargin = (uint32)(page->vmargin * scale * ((image->bps + 7)/ 8)); + hmargin = (uint32_t)(page->hmargin * scale * ((image->bps + 7) / 8)); + vmargin = (uint32_t)(page->vmargin * scale * ((image->bps + 7) / 8)); } if ((hmargin * 2.0) > (pwidth * page->hres)) { TIFFError("computeOutputPixelOffsets", "Combined left and right margins exceed page width"); - hmargin = (uint32) 0; + hmargin = (uint32_t) 0; return (-1); } if ((vmargin * 2.0) > (plength * page->vres)) { TIFFError("computeOutputPixelOffsets", "Combined top and bottom margins exceed page length"); - vmargin = (uint32) 0; + vmargin = (uint32_t) 0; return (-1); } } @@ -5763,13 +5755,13 @@ computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image, { if (page->mode & PAGE_MODE_PAPERSIZE ) { - owidth = (uint32)((pwidth * page->hres) - (hmargin * 2)); - olength = (uint32)((plength * page->vres) - (vmargin * 2)); + owidth = (uint32_t)((pwidth * page->hres) - (hmargin * 2)); + olength = (uint32_t)((plength * page->vres) - (vmargin * 2)); } else { - owidth = (uint32)(iwidth - (hmargin * 2 * page->hres)); - olength = (uint32)(ilength - (vmargin * 2 * page->vres)); + owidth = (uint32_t)(iwidth - (hmargin * 2 * page->hres)); + olength = (uint32_t)(ilength - (vmargin * 2 * page->vres)); } } @@ -5844,14 +5836,14 @@ computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image, /* build the list of offsets for each output section */ for (k = 0, i = 0 && k <= MAX_SECTIONS; i < orows; i++) { - y1 = (uint32)(olength * i); - y2 = (uint32)(olength * (i + 1) - 1); + y1 = (uint32_t)(olength * i); + y2 = (uint32_t)(olength * (i + 1) - 1); if (y2 >= ilength) y2 = ilength - 1; for (j = 0; j < ocols; j++, k++) { - x1 = (uint32)(owidth * j); - x2 = (uint32)(owidth * (j + 1) - 1); + x1 = (uint32_t)(owidth * j); + x2 = (uint32_t)(owidth * (j + 1) - 1); if (x2 >= iwidth) x2 = iwidth - 1; sections[k].x1 = x1; @@ -5869,29 +5861,29 @@ computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image, static int loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned char **read_ptr) { - uint32 i; + uint32_t i; float xres = 0.0, yres = 0.0; - uint32 nstrips = 0, ntiles = 0; - uint16 planar = 0; - uint16 bps = 0, spp = 0, res_unit = 0; - uint16 orientation = 0; - uint16 input_compression = 0, input_photometric = 0; - uint16 subsampling_horiz, subsampling_vert; - uint32 width = 0, length = 0; - uint32 stsize = 0, tlsize = 0, buffsize = 0, scanlinesize = 0; - uint32 tw = 0, tl = 0; /* Tile width and length */ - uint32 tile_rowsize = 0; + uint32_t nstrips = 0, ntiles = 0; + uint16_t planar = 0; + uint16_t bps = 0, spp = 0, res_unit = 0; + uint16_t orientation = 0; + uint16_t input_compression = 0, input_photometric = 0; + uint16_t subsampling_horiz, subsampling_vert; + uint32_t width = 0, length = 0; + uint32_t stsize = 0, tlsize = 0, buffsize = 0, scanlinesize = 0; + uint32_t tw = 0, tl = 0; /* Tile width and length */ + uint32_t tile_rowsize = 0; unsigned char *read_buff = NULL; unsigned char *new_buff = NULL; int readunit = 0; - static uint32 prev_readsize = 0; + static uint32_t prev_readsize = 0; TIFFGetFieldDefaulted(in, TIFFTAG_BITSPERSAMPLE, &bps); TIFFGetFieldDefaulted(in, TIFFTAG_SAMPLESPERPIXEL, &spp); TIFFGetFieldDefaulted(in, TIFFTAG_PLANARCONFIG, &planar); TIFFGetFieldDefaulted(in, TIFFTAG_ORIENTATION, &orientation); if (! TIFFGetFieldDefaulted(in, TIFFTAG_PHOTOMETRIC, &input_photometric)) - TIFFError("loadImage","Image lacks Photometric interpreation tag"); + TIFFError("loadImage","Image lacks Photometric interpretation tag"); if (! TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width)) TIFFError("loadimage","Image lacks image width tag"); if(! TIFFGetField(in, TIFFTAG_IMAGELENGTH, &length)) @@ -6066,7 +6058,7 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c if ((bps == 0) || (spp == 0)) { - TIFFError("loadImage", "Invalid samples per pixel (%d) or bits per sample (%d)", + TIFFError("loadImage", "Invalid samples per pixel (%"PRIu16") or bits per sample (%"PRIu16")", spp, bps); return (-1); } @@ -6092,7 +6084,7 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c exit(EXIT_FAILURE); } - if (buffsize < (uint32)(ntiles * tl * tile_rowsize)) + if (buffsize < (uint32_t)(ntiles * tl * tile_rowsize)) { buffsize = ntiles * tl * tile_rowsize; if (ntiles != (buffsize / tl / tile_rowsize)) @@ -6103,19 +6095,19 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c #ifdef DEBUG2 TIFFError("loadImage", - "Tilesize %u is too small, using ntiles * tilelength * tilerowsize %lu", - tlsize, (unsigned long)buffsize); + "Tilesize %"PRIu32" is too small, using ntiles * tilelength * tilerowsize %"PRIu32, + tlsize, buffsize); #endif } if (dump->infile != NULL) dump_info (dump->infile, dump->format, "", - "Tilesize: %u, Number of Tiles: %u, Tile row size: %u", + "Tilesize: %"PRIu32", Number of Tiles: %"PRIu32", Tile row size: %"PRIu32, tlsize, ntiles, tile_rowsize); } else { - uint32 buffsize_check; + uint32_t buffsize_check; readunit = STRIP; TIFFGetFieldDefaulted(in, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); stsize = TIFFStripSize(in); @@ -6138,19 +6130,19 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c TIFFError("loadImage", "Integer overflow detected."); exit(EXIT_FAILURE); } - if (buffsize < (uint32) (((length * width * spp * bps) + 7) / 8)) + if (buffsize < (uint32_t) (((length * width * spp * bps) + 7) / 8)) { buffsize = ((length * width * spp * bps) + 7) / 8; #ifdef DEBUG2 TIFFError("loadImage", - "Stripsize %u is too small, using imagelength * width * spp * bps / 8 = %lu", + "Stripsize %"PRIu32" is too small, using imagelength * width * spp * bps / 8 = %"PRIu32, stsize, (unsigned long)buffsize); #endif } if (dump->infile != NULL) dump_info (dump->infile, dump->format, "", - "Stripsize: %u, Number of Strips: %u, Rows per Strip: %u, Scanline size: %u", + "Stripsize: %"PRIu32", Number of Strips: %"PRIu32", Rows per Strip: %"PRIu32", Scanline size: %"PRIu32, stsize, nstrips, rowsperstrip, scanlinesize); } @@ -6169,7 +6161,7 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c if (subsampling_horiz != 1 || subsampling_vert != 1) { TIFFError("loadImage", - "Can't copy/convert subsampled image with subsampling %d horiz %d vert", + "Can't copy/convert subsampled image with subsampling %"PRIu16" horiz %"PRIu16" vert", subsampling_horiz, subsampling_vert); return (-1); } @@ -6269,10 +6261,10 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c if ((dump->infile != NULL) && (dump->level == 2)) { dump_info (dump->infile, dump->format, "loadImage", - "Image width %d, length %d, Raw image data, %4d bytes", + "Image width %"PRIu32", length %"PRIu32", Raw image data, %4"PRIu32" bytes", width, length, buffsize); dump_info (dump->infile, dump->format, "", - "Bits per sample %d, Samples per pixel %d", bps, spp); + "Bits per sample %"PRIu16", Samples per pixel %"PRIu16, bps, spp); for (i = 0; i < length; i++) dump_buffer(dump->infile, dump->format, 1, scanlinesize, @@ -6283,7 +6275,7 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c static int correct_orientation(struct image_data *image, unsigned char **work_buff_ptr) { - uint16 mirror, rotation; + uint16_t mirror, rotation; unsigned char *work_buff; work_buff = *work_buff_ptr; @@ -6295,7 +6287,7 @@ static int correct_orientation(struct image_data *image, unsigned char **work_b if ((image->adjustments & MIRROR_HORIZ) || (image->adjustments & MIRROR_VERT)) { - mirror = (uint16)(image->adjustments & MIRROR_BOTH); + mirror = (uint16_t)(image->adjustments & MIRROR_BOTH); if (mirrorImage(image->spp, image->bps, mirror, image->width, image->length, work_buff)) { @@ -6307,17 +6299,17 @@ static int correct_orientation(struct image_data *image, unsigned char **work_b if (image->adjustments & ROTATE_ANY) { if (image->adjustments & ROTATECW_90) - rotation = (uint16) 90; + rotation = (uint16_t) 90; else if (image->adjustments & ROTATECW_180) - rotation = (uint16) 180; + rotation = (uint16_t) 180; else if (image->adjustments & ROTATECW_270) - rotation = (uint16) 270; + rotation = (uint16_t) 270; else { - TIFFError ("correct_orientation", "Invalid rotation value: %d", - image->adjustments & ROTATE_ANY); + TIFFError ("correct_orientation", "Invalid rotation value: %"PRIu16, + (uint16_t) (image->adjustments & ROTATE_ANY)); return (-1); } @@ -6339,13 +6331,13 @@ extractCompositeRegions(struct image_data *image, struct crop_mask *crop, unsigned char *read_buff, unsigned char *crop_buff) { int shift_width, bytes_per_sample, bytes_per_pixel; - uint32 i, trailing_bits, prev_trailing_bits; - uint32 row, first_row, last_row, first_col, last_col; - uint32 src_rowsize, dst_rowsize, src_offset, dst_offset; - uint32 crop_width, crop_length, img_width /*, img_length */; - uint32 prev_length, prev_width, composite_width; - uint16 bps, spp; - uint8 *src, *dst; + uint32_t i, trailing_bits, prev_trailing_bits; + uint32_t row, first_row, last_row, first_col, last_col; + uint32_t src_rowsize, dst_rowsize, src_offset, dst_offset; + uint32_t crop_width, crop_length, img_width /*, img_length */; + uint32_t prev_length, prev_width, composite_width; + uint16_t bps, spp; + uint8_t *src, *dst; tsample_t count, sample = 0; /* Update to extract one or more samples */ img_width = image->width; @@ -6422,7 +6414,7 @@ extractCompositeRegions(struct image_data *image, struct crop_mask *crop, last_col + 1)) { TIFFError("extractCompositeRegions", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6434,7 +6426,7 @@ extractCompositeRegions(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractCompositeRegions", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6446,7 +6438,7 @@ extractCompositeRegions(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractCompositeRegions", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6456,7 +6448,7 @@ extractCompositeRegions(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractCompositeRegions", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6468,11 +6460,11 @@ extractCompositeRegions(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractCompositeRegions", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; - default: TIFFError("extractCompositeRegions", "Unsupported bit depth %d", bps); + default: TIFFError("extractCompositeRegions", "Unsupported bit depth %"PRIu16, bps); return (1); } } @@ -6504,7 +6496,7 @@ extractCompositeRegions(struct image_data *image, struct crop_mask *crop, first_col, last_col + 1)) { TIFFError("extractCompositeRegions", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6516,7 +6508,7 @@ extractCompositeRegions(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractCompositeRegions", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6528,7 +6520,7 @@ extractCompositeRegions(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractCompositeRegions", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6538,7 +6530,7 @@ extractCompositeRegions(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractCompositeRegions", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6550,11 +6542,11 @@ extractCompositeRegions(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractCompositeRegions", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; - default: TIFFError("extractCompositeRegions", "Unsupported bit depth %d", bps); + default: TIFFError("extractCompositeRegions", "Unsupported bit depth %"PRIu16, bps); return (1); } } @@ -6588,13 +6580,13 @@ extractSeparateRegion(struct image_data *image, struct crop_mask *crop, int region) { int shift_width, prev_trailing_bits = 0; - uint32 bytes_per_sample, bytes_per_pixel; - uint32 src_rowsize, dst_rowsize; - uint32 row, first_row, last_row, first_col, last_col; - uint32 src_offset, dst_offset; - uint32 crop_width, crop_length, img_width /*, img_length */; - uint16 bps, spp; - uint8 *src, *dst; + uint32_t bytes_per_sample, bytes_per_pixel; + uint32_t src_rowsize, dst_rowsize; + uint32_t row, first_row, last_row, first_col, last_col; + uint32_t src_offset, dst_offset; + uint32_t crop_width, crop_length, img_width /*, img_length */; + uint16_t bps, spp; + uint8_t *src, *dst; tsample_t count, sample = 0; /* Update to extract more or more samples */ img_width = image->width; @@ -6647,7 +6639,7 @@ extractSeparateRegion(struct image_data *image, struct crop_mask *crop, last_col + 1)) { TIFFError("extractSeparateRegion", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6659,7 +6651,7 @@ extractSeparateRegion(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractSeparateRegion", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6671,7 +6663,7 @@ extractSeparateRegion(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractSeparateRegion", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6681,7 +6673,7 @@ extractSeparateRegion(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractSeparateRegion", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; @@ -6693,11 +6685,11 @@ extractSeparateRegion(struct image_data *image, struct crop_mask *crop, prev_trailing_bits)) { TIFFError("extractSeparateRegion", - "Unable to extract row %d", row); + "Unable to extract row %"PRIu32, row); return (1); } break; - default: TIFFError("extractSeparateRegion", "Unsupported bit depth %d", bps); + default: TIFFError("extractSeparateRegion", "Unsupported bit depth %"PRIu16, bps); return (1); } } @@ -6714,19 +6706,19 @@ extractImageSection(struct image_data *image, struct pageseg *section, /* unsigned char *src, *dst; */ #endif - uint32 img_width, img_rowsize; + uint32_t img_width, img_rowsize; #ifdef DEVELMODE - uint32 img_length; + uint32_t img_length; #endif - uint32 j, shift1, shift2, trailing_bits; - uint32 row, first_row, last_row, first_col, last_col; - uint32 src_offset, dst_offset, row_offset, col_offset; - uint32 offset1, offset2, full_bytes; - uint32 sect_width; + uint32_t j, shift1, shift2, trailing_bits; + uint32_t row, first_row, last_row, first_col, last_col; + uint32_t src_offset, dst_offset, row_offset, col_offset; + uint32_t offset1, offset2, full_bytes; + uint32_t sect_width; #ifdef DEVELMODE - uint32 sect_length; + uint32_t sect_length; #endif - uint16 bps, spp; + uint16_t bps, spp; #ifdef DEVELMODE int k; @@ -6774,11 +6766,11 @@ extractImageSection(struct image_data *image, struct pageseg *section, trailing_bits = (sect_width * bps) % 8; #ifdef DEVELMODE - TIFFError ("", "First row: %d, last row: %d, First col: %d, last col: %d\n", + TIFFError ("", "First row: %"PRIu32", last row: %"PRIu32", First col: %"PRIu32", last col: %"PRIu32"\n", first_row, last_row, first_col, last_col); - TIFFError ("", "Image width: %d, Image length: %d, bps: %d, spp: %d\n", + TIFFError ("", "Image width: %"PRIu32", Image length: %"PRIu32", bps: %"PRIu16", spp: %"PRIu16"\n", img_width, img_length, bps, spp); - TIFFError ("", "Sect width: %d, Sect length: %d, full bytes: %d trailing bits %d\n", + TIFFError ("", "Sect width: %"PRIu32", Sect length: %"PRIu32", full bytes: %"PRIu32" trailing bits %"PRIu32"\n", sect_width, sect_length, full_bytes, trailing_bits); #endif @@ -6792,7 +6784,7 @@ extractImageSection(struct image_data *image, struct pageseg *section, src_offset = row_offset + col_offset; #ifdef DEVELMODE - TIFFError ("", "Src offset: %8d, Dst offset: %8d", src_offset, dst_offset); + TIFFError ("", "Src offset: %8"PRIu32", Dst offset: %8"PRIu32, src_offset, dst_offset); #endif _TIFFmemcpy (sect_buff + dst_offset, src_buff + src_offset, full_bytes); dst_offset += full_bytes; @@ -6823,7 +6815,7 @@ extractImageSection(struct image_data *image, struct pageseg *section, sprintf(&bitarray[j], (bitset) ? "1" : "0"); } bitarray[18] = '\0'; - TIFFError ("", "Row: %3d Offset1: %d, Shift1: %d, Offset2: %d, Shift2: %d\n", + TIFFError ("", "Row: %3d Offset1: %"PRIu32", Shift1: %"PRIu32", Offset2: %"PRIu32", Shift2: %"PRIu32"\n", row, offset1, shift1, offset2, shift2); #endif @@ -6833,7 +6825,7 @@ extractImageSection(struct image_data *image, struct pageseg *section, _TIFFmemcpy (sect_buff + dst_offset, src_buff + offset1, full_bytes); #ifdef DEVELMODE - TIFFError ("", " Aligned data src offset1: %8d, Dst offset: %8d\n", offset1, dst_offset); + TIFFError ("", " Aligned data src offset1: %8"PRIu32", Dst offset: %8"PRIu32"\n", offset1, dst_offset); sprintf(&bitarray[18], "\n"); sprintf(&bitarray[19], "\t"); for (j = 20, k = 7; j < 28; j++, k--) @@ -6851,7 +6843,7 @@ extractImageSection(struct image_data *image, struct pageseg *section, bytebuff2 = src_buff[offset2] & ((unsigned char)255 << (7 - shift2)); sect_buff[dst_offset] = bytebuff2; #ifdef DEVELMODE - TIFFError ("", " Trailing bits src offset: %8d, Dst offset: %8d\n", + TIFFError ("", " Trailing bits src offset: %8"PRIu32", Dst offset: %8"PRIu32"\n", offset2, dst_offset); for (j = 30, k = 7; j < 38; j++, k--) { @@ -6867,7 +6859,7 @@ extractImageSection(struct image_data *image, struct pageseg *section, else /* each destination byte will have to be built from two source bytes*/ { #ifdef DEVELMODE - TIFFError ("", " Unalligned data src offset: %8d, Dst offset: %8d\n", offset1 , dst_offset); + TIFFError ("", " Unalligned data src offset: %8"PRIu32", Dst offset: %8"PRIu32"\n", offset1 , dst_offset); #endif for (j = 0; j <= full_bytes; j++) { @@ -6891,7 +6883,7 @@ extractImageSection(struct image_data *image, struct pageseg *section, if (trailing_bits != 0) { #ifdef DEVELMODE - TIFFError ("", " Trailing bits src offset: %8d, Dst offset: %8d\n", offset1 + full_bytes, dst_offset); + TIFFError ("", " Trailing bits src offset: %8"PRIu32", Dst offset: %8"PRIu32"\n", offset1 + full_bytes, dst_offset); #endif if (shift2 > shift1) { @@ -7051,7 +7043,7 @@ writeImageSections(TIFF *in, TIFF *out, struct image_data *image, unsigned char **sect_buff_ptr) { double hres, vres; - uint32 i, k, width, length, sectsize; + uint32_t i, k, width, length, sectsize; unsigned char *sect_buff = *sect_buff_ptr; hres = page->hres; @@ -7061,7 +7053,7 @@ writeImageSections(TIFF *in, TIFF *out, struct image_data *image, if ((k < 1) || (k > MAX_SECTIONS)) { TIFFError("writeImageSections", - "%d Rows and Columns exceed maximum sections\nIncrease resolution or reduce sections", k); + "%"PRIu32" Rows and Columns exceed maximum sections\nIncrease resolution or reduce sections", k); return (-1); } @@ -7069,7 +7061,7 @@ writeImageSections(TIFF *in, TIFF *out, struct image_data *image, { width = sections[i].x2 - sections[i].x1 + 1; length = sections[i].y2 - sections[i].y1 + 1; - sectsize = (uint32) + sectsize = (uint32_t) ceil((width * image->bps + 7) / (double)8) * image->spp * length; /* allocate a buffer if we don't have one already */ if (createImageSection(sectsize, sect_buff_ptr)) @@ -7104,14 +7096,14 @@ writeImageSections(TIFF *in, TIFF *out, struct image_data *image, */ static int writeSingleSection(TIFF *in, TIFF *out, struct image_data *image, - struct dump_opts *dump, uint32 width, uint32 length, + struct dump_opts *dump, uint32_t width, uint32_t length, double hres, double vres, unsigned char *sect_buff) { - uint16 bps, spp; - uint16 input_compression, input_photometric; - uint16 input_planar; - struct cpTag* p; + uint16_t bps, spp; + uint16_t input_compression, input_photometric; + uint16_t input_planar; + const struct cpTag* p; /* Calling this seems to reset the compression mode on the TIFF *in file. TIFFGetField(in, TIFFTAG_JPEGCOLORMODE, &input_jpeg_colormode); @@ -7135,8 +7127,8 @@ writeSingleSection(TIFF *in, TIFF *out, struct image_data *image, * if the user has specified a command line option for * a compression option. Should be passed around in one * of the parameters instead of as a global. If no user - * option specified it will still be (uint16) -1. */ - if (compression != (uint16)-1) + * option specified it will still be (uint16_t) -1. */ + if (compression != (uint16_t)-1) TIFFSetField(out, TIFFTAG_COMPRESSION, compression); else { /* OJPEG is no longer supported for writing so upgrade to JPEG */ @@ -7220,9 +7212,9 @@ writeSingleSection(TIFF *in, TIFF *out, struct image_data *image, * input image or, if nothing is defined, use the * library default. */ - if (tilewidth == (uint32) 0) + if (tilewidth == (uint32_t) 0) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tilewidth); - if (tilelength == (uint32) 0) + if (tilelength == (uint32_t) 0) TIFFGetField(in, TIFFTAG_TILELENGTH, &tilelength); if (tilewidth == 0 || tilelength == 0) @@ -7236,7 +7228,7 @@ writeSingleSection(TIFF *in, TIFF *out, struct image_data *image, * value from the input image or, if nothing is defined, * use the library default. */ - if (rowsperstrip == (uint32) 0) + if (rowsperstrip == (uint32_t) 0) { if (!TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &rowsperstrip)) rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip); @@ -7247,13 +7239,13 @@ writeSingleSection(TIFF *in, TIFF *out, struct image_data *image, } } else - if (rowsperstrip == (uint32) -1) + if (rowsperstrip == (uint32_t) -1) rowsperstrip = length; TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip); } TIFFGetFieldDefaulted(in, TIFFTAG_PLANARCONFIG, &input_planar); - if (config != (uint16) -1) + if (config != (uint16_t) -1) TIFFSetField(out, TIFFTAG_PLANARCONFIG, config); else CopyField(TIFFTAG_PLANARCONFIG, config); @@ -7282,7 +7274,7 @@ writeSingleSection(TIFF *in, TIFF *out, struct image_data *image, case COMPRESSION_LZW: case COMPRESSION_ADOBE_DEFLATE: case COMPRESSION_DEFLATE: - if (predictor != (uint16)-1) + if (predictor != (uint16_t)-1) TIFFSetField(out, TIFFTAG_PREDICTOR, predictor); else CopyField(TIFFTAG_PREDICTOR, predictor); @@ -7290,7 +7282,7 @@ writeSingleSection(TIFF *in, TIFF *out, struct image_data *image, case COMPRESSION_CCITTFAX3: case COMPRESSION_CCITTFAX4: if (compression == COMPRESSION_CCITTFAX3) { - if (g3opts != (uint32) -1) + if (g3opts != (uint32_t) -1) TIFFSetField(out, TIFFTAG_GROUP3OPTIONS, g3opts); else CopyField(TIFFTAG_GROUP3OPTIONS, g3opts); @@ -7305,12 +7297,12 @@ writeSingleSection(TIFF *in, TIFF *out, struct image_data *image, CopyTag(TIFFTAG_FAXSUBADDRESS, 1, TIFF_ASCII); break; } - { uint32 len32; + { uint32_t len32; void** data; if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &len32, &data)) TIFFSetField(out, TIFFTAG_ICCPROFILE, len32, data); } - { uint16 ninks; + { uint16_t ninks; const char* inknames; if (TIFFGetField(in, TIFFTAG_NUMBEROFINKS, &ninks)) { TIFFSetField(out, TIFFTAG_NUMBEROFINKS, ninks); @@ -7374,11 +7366,11 @@ writeSingleSection(TIFF *in, TIFF *out, struct image_data *image, /* Create a buffer to write one section at a time */ static int -createImageSection(uint32 sectsize, unsigned char **sect_buff_ptr) +createImageSection(uint32_t sectsize, unsigned char **sect_buff_ptr) { unsigned char *sect_buff = NULL; unsigned char *new_buff = NULL; - static uint32 prev_sectsize = 0; + static uint32_t prev_sectsize = 0; sect_buff = *sect_buff_ptr; @@ -7423,7 +7415,7 @@ processCropSelections(struct image_data *image, struct crop_mask *crop, unsigned char **read_buff_ptr, struct buffinfo seg_buffs[]) { int i; - uint32 width, length, total_width, total_length; + uint32_t width, length, total_width, total_length; tsize_t cropsize; unsigned char *crop_buff = NULL; unsigned char *read_buff = NULL; @@ -7523,7 +7515,7 @@ processCropSelections(struct image_data *image, struct crop_mask *crop, &crop->combined_length, &crop_buff)) { TIFFError("processCropSelections", - "Failed to rotate composite regions by %d degrees", crop->rotation); + "Failed to rotate composite regions by %"PRIu32" degrees", crop->rotation); return (-1); } seg_buffs[0].buffer = crop_buff; @@ -7629,7 +7621,7 @@ processCropSelections(struct image_data *image, struct crop_mask *crop, &crop->regionlist[i].length, &crop_buff)) { TIFFError("processCropSelections", - "Failed to rotate crop region by %d degrees", crop->rotation); + "Failed to rotate crop region by %"PRIu16" degrees", crop->rotation); return (-1); } total_width += crop->regionlist[i].width; @@ -7647,7 +7639,7 @@ processCropSelections(struct image_data *image, struct crop_mask *crop, /* Copy the crop section of the data from the current image into a buffer * and adjust the IFD values to reflect the new size. If no cropping is - * required, use the origial read buffer as the crop buffer. + * required, use the original read buffer as the crop buffer. * * There is quite a bit of redundancy between this routine and the more * specialized processCropSelections, but this provides @@ -7757,7 +7749,7 @@ createCroppedImage(struct image_data *image, struct crop_mask *crop, &crop->combined_length, crop_buff_ptr)) { TIFFError("createCroppedImage", - "Failed to rotate image or cropped selection by %d degrees", crop->rotation); + "Failed to rotate image or cropped selection by %"PRIu16" degrees", crop->rotation); return (-1); } } @@ -7781,14 +7773,14 @@ createCroppedImage(struct image_data *image, struct crop_mask *crop, * then passed in as an argument. */ static int -writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, - struct dump_opts *dump, uint32 width, uint32 length, +writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, + struct dump_opts *dump, uint32_t width, uint32_t length, unsigned char *crop_buff, int pagenum, int total_pages) { - uint16 bps, spp; - uint16 input_compression, input_photometric; - uint16 input_planar; - struct cpTag* p; + uint16_t bps, spp; + uint16_t input_compression, input_photometric; + uint16_t input_planar; + const struct cpTag* p; input_compression = image->compression; input_photometric = image->photometric; @@ -7806,7 +7798,7 @@ writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, ((input_compression == COMPRESSION_JPEG) ? "New Jpeg" : "Non Jpeg")); #endif - if (compression != (uint16)-1) + if (compression != (uint16_t)-1) TIFFSetField(out, TIFFTAG_COMPRESSION, compression); else { @@ -7895,9 +7887,9 @@ writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, * input image or, if nothing is defined, use the * library default. */ - if (tilewidth == (uint32) 0) + if (tilewidth == (uint32_t) 0) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tilewidth); - if (tilelength == (uint32) 0) + if (tilelength == (uint32_t) 0) TIFFGetField(in, TIFFTAG_TILELENGTH, &tilelength); if (tilewidth == 0 || tilelength == 0) @@ -7910,7 +7902,7 @@ writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, * value from the input image or, if nothing is defined, * use the library default. */ - if (rowsperstrip == (uint32) 0) + if (rowsperstrip == (uint32_t) 0) { if (!TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &rowsperstrip)) rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip); @@ -7921,13 +7913,13 @@ writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, } } else - if (rowsperstrip == (uint32) -1) + if (rowsperstrip == (uint32_t) -1) rowsperstrip = length; TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip); } TIFFGetFieldDefaulted(in, TIFFTAG_PLANARCONFIG, &input_planar); - if (config != (uint16) -1) + if (config != (uint16_t) -1) TIFFSetField(out, TIFFTAG_PLANARCONFIG, config); else CopyField(TIFFTAG_PLANARCONFIG, config); @@ -7953,7 +7945,7 @@ writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, case COMPRESSION_LZW: case COMPRESSION_ADOBE_DEFLATE: case COMPRESSION_DEFLATE: - if (predictor != (uint16)-1) + if (predictor != (uint16_t)-1) TIFFSetField(out, TIFFTAG_PREDICTOR, predictor); else CopyField(TIFFTAG_PREDICTOR, predictor); @@ -7967,7 +7959,7 @@ writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, return (-1); } if (compression == COMPRESSION_CCITTFAX3) { - if (g3opts != (uint32) -1) + if (g3opts != (uint32_t) -1) TIFFSetField(out, TIFFTAG_GROUP3OPTIONS, g3opts); else CopyField(TIFFTAG_GROUP3OPTIONS, g3opts); @@ -7985,12 +7977,12 @@ writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, break; default: break; } - { uint32 len32; + { uint32_t len32; void** data; if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &len32, &data)) TIFFSetField(out, TIFFTAG_ICCPROFILE, len32, data); } - { uint16 ninks; + { uint16_t ninks; const char* inknames; if (TIFFGetField(in, TIFFTAG_NUMBEROFINKS, &ninks)) { TIFFSetField(out, TIFFTAG_NUMBEROFINKS, ninks); @@ -8057,15 +8049,15 @@ writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, } /* end writeCroppedImage */ static int -rotateContigSamples8bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, - uint32 length, uint32 col, uint8 *src, uint8 *dst) +rotateContigSamples8bits(uint16_t rotation, uint16_t spp, uint16_t bps, uint32_t width, + uint32_t length, uint32_t col, uint8_t *src, uint8_t *dst) { int ready_bits = 0; - uint32 src_byte = 0, src_bit = 0; - uint32 row, rowsize = 0, bit_offset = 0; - uint8 matchbits = 0, maskbits = 0; - uint8 buff1 = 0, buff2 = 0; - uint8 *next; + uint32_t src_byte = 0, src_bit = 0; + uint32_t row, rowsize = 0, bit_offset = 0; + uint8_t matchbits = 0, maskbits = 0; + uint8_t buff1 = 0, buff2 = 0; + uint8_t *next; tsample_t sample; if ((src == NULL) || (dst == NULL)) @@ -8076,7 +8068,7 @@ rotateContigSamples8bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, rowsize = ((bps * spp * width) + 7) / 8; ready_bits = 0; - maskbits = (uint8)-1 >> ( 8 - bps); + maskbits = (uint8_t)-1 >> (8 - bps); buff1 = buff2 = 0; for (row = 0; row < length ; row++) @@ -8101,7 +8093,7 @@ rotateContigSamples8bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, break; case 270: next = src + src_byte + (row * rowsize); break; - default: TIFFError("rotateContigSamples8bits", "Invalid rotation %d", rotation); + default: TIFFError("rotateContigSamples8bits", "Invalid rotation %"PRIu16, rotation); return (1); } matchbits = maskbits << (8 - src_bit - bps); @@ -8133,16 +8125,16 @@ rotateContigSamples8bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, static int -rotateContigSamples16bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, - uint32 length, uint32 col, uint8 *src, uint8 *dst) +rotateContigSamples16bits(uint16_t rotation, uint16_t spp, uint16_t bps, uint32_t width, + uint32_t length, uint32_t col, uint8_t *src, uint8_t *dst) { int ready_bits = 0; - uint32 row, rowsize, bit_offset; - uint32 src_byte = 0, src_bit = 0; - uint16 matchbits = 0, maskbits = 0; - uint16 buff1 = 0, buff2 = 0; - uint8 bytebuff = 0; - uint8 *next; + uint32_t row, rowsize, bit_offset; + uint32_t src_byte = 0, src_bit = 0; + uint16_t matchbits = 0, maskbits = 0; + uint16_t buff1 = 0, buff2 = 0; + uint8_t bytebuff = 0; + uint8_t *next; tsample_t sample; if ((src == NULL) || (dst == NULL)) @@ -8153,7 +8145,7 @@ rotateContigSamples16bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, rowsize = ((bps * spp * width) + 7) / 8; ready_bits = 0; - maskbits = (uint16)-1 >> (16 - bps); + maskbits = (uint16_t)-1 >> (16 - bps); buff1 = buff2 = 0; for (row = 0; row < length; row++) { @@ -8177,7 +8169,7 @@ rotateContigSamples16bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, break; case 270: next = src + src_byte + (row * rowsize); break; - default: TIFFError("rotateContigSamples8bits", "Invalid rotation %d", rotation); + default: TIFFError("rotateContigSamples8bits", "Invalid rotation %"PRIu16, rotation); return (1); } matchbits = maskbits << (16 - src_bit - bps); @@ -8216,16 +8208,16 @@ rotateContigSamples16bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, } /* end rotateContigSamples16bits */ static int -rotateContigSamples24bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, - uint32 length, uint32 col, uint8 *src, uint8 *dst) +rotateContigSamples24bits(uint16_t rotation, uint16_t spp, uint16_t bps, uint32_t width, + uint32_t length, uint32_t col, uint8_t *src, uint8_t *dst) { int ready_bits = 0; - uint32 row, rowsize, bit_offset; - uint32 src_byte = 0, src_bit = 0; - uint32 matchbits = 0, maskbits = 0; - uint32 buff1 = 0, buff2 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0; - uint8 *next; + uint32_t row, rowsize, bit_offset; + uint32_t src_byte = 0, src_bit = 0; + uint32_t matchbits = 0, maskbits = 0; + uint32_t buff1 = 0, buff2 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0; + uint8_t *next; tsample_t sample; @@ -8237,7 +8229,7 @@ rotateContigSamples24bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, rowsize = ((bps * spp * width) + 7) / 8; ready_bits = 0; - maskbits = (uint32)-1 >> (32 - bps); + maskbits = (uint32_t)-1 >> (32 - bps); buff1 = buff2 = 0; for (row = 0; row < length; row++) { @@ -8261,7 +8253,7 @@ rotateContigSamples24bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, break; case 270: next = src + src_byte + (row * rowsize); break; - default: TIFFError("rotateContigSamples8bits", "Invalid rotation %d", rotation); + default: TIFFError("rotateContigSamples8bits", "Invalid rotation %"PRIu16, rotation); return (1); } matchbits = maskbits << (32 - src_bit - bps); @@ -8307,18 +8299,18 @@ rotateContigSamples24bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, } /* end rotateContigSamples24bits */ static int -rotateContigSamples32bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, - uint32 length, uint32 col, uint8 *src, uint8 *dst) +rotateContigSamples32bits(uint16_t rotation, uint16_t spp, uint16_t bps, uint32_t width, + uint32_t length, uint32_t col, uint8_t *src, uint8_t *dst) { int ready_bits = 0 /*, shift_width = 0 */; /* int bytes_per_sample, bytes_per_pixel; */ - uint32 row, rowsize, bit_offset; - uint32 src_byte, src_bit; - uint32 longbuff1 = 0, longbuff2 = 0; - uint64 maskbits = 0, matchbits = 0; - uint64 buff1 = 0, buff2 = 0, buff3 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; - uint8 *next; + uint32_t row, rowsize, bit_offset; + uint32_t src_byte, src_bit; + uint32_t longbuff1 = 0, longbuff2 = 0; + uint64_t maskbits = 0, matchbits = 0; + uint64_t buff1 = 0, buff2 = 0, buff3 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; + uint8_t *next; tsample_t sample; @@ -8337,7 +8329,7 @@ rotateContigSamples32bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, rowsize = ((bps * spp * width) + 7) / 8; ready_bits = 0; - maskbits = (uint64)-1 >> (64 - bps); + maskbits = (uint64_t)-1 >> (64 - bps); buff1 = buff2 = 0; for (row = 0; row < length; row++) { @@ -8361,7 +8353,7 @@ rotateContigSamples32bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, break; case 270: next = src + src_byte + (row * rowsize); break; - default: TIFFError("rotateContigSamples8bits", "Invalid rotation %d", rotation); + default: TIFFError("rotateContigSamples8bits", "Invalid rotation %"PRIu16, rotation); return (1); } matchbits = maskbits << (64 - src_bit - bps); @@ -8376,7 +8368,7 @@ rotateContigSamples32bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, longbuff2 = longbuff1; } - buff3 = ((uint64)longbuff1 << 32) | longbuff2; + buff3 = ((uint64_t)longbuff1 << 32) | longbuff2; buff1 = (buff3 & matchbits) << (src_bit); if (ready_bits < 32) @@ -8416,18 +8408,18 @@ rotateContigSamples32bits(uint16 rotation, uint16 spp, uint16 bps, uint32 width, /* Rotate an image by a multiple of 90 degrees clockwise */ static int -rotateImage(uint16 rotation, struct image_data *image, uint32 *img_width, - uint32 *img_length, unsigned char **ibuff_ptr) +rotateImage(uint16_t rotation, struct image_data *image, uint32_t *img_width, + uint32_t *img_length, unsigned char **ibuff_ptr) { int shift_width; - uint32 bytes_per_pixel, bytes_per_sample; - uint32 row, rowsize, src_offset, dst_offset; - uint32 i, col, width, length; - uint32 colsize, buffsize, col_offset, pix_offset; + uint32_t bytes_per_pixel, bytes_per_sample; + uint32_t row, rowsize, src_offset, dst_offset; + uint32_t i, col, width, length; + uint32_t colsize, buffsize, col_offset, pix_offset; unsigned char *ibuff; unsigned char *src; unsigned char *dst; - uint16 spp, bps; + uint16_t spp, bps; float res_temp; unsigned char *rbuff = NULL; @@ -8457,7 +8449,7 @@ rotateImage(uint16 rotation, struct image_data *image, uint32 *img_width, case 90: case 180: case 270: break; - default: TIFFError("rotateImage", "Invalid rotation angle %d", rotation); + default: TIFFError("rotateImage", "Invalid rotation angle %"PRIu16, rotation); return (-1); } @@ -8527,7 +8519,7 @@ rotateImage(uint16 rotation, struct image_data *image, uint32 *img_width, return (-1); } break; - default: TIFFError("rotateImage","Unsupported bit depth %d", bps); + default: TIFFError("rotateImage","Unsupported bit depth %"PRIu16, bps); _TIFFfree(rbuff); return (-1); } @@ -8596,7 +8588,7 @@ rotateImage(uint16 rotation, struct image_data *image, uint32 *img_width, return (-1); } break; - default: TIFFError("rotateImage","Unsupported bit depth %d", bps); + default: TIFFError("rotateImage","Unsupported bit depth %"PRIu16, bps); _TIFFfree(rbuff); return (-1); } @@ -8673,7 +8665,7 @@ rotateImage(uint16 rotation, struct image_data *image, uint32 *img_width, return (-1); } break; - default: TIFFError("rotateImage","Unsupported bit depth %d", bps); + default: TIFFError("rotateImage","Unsupported bit depth %"PRIu16, bps); _TIFFfree(rbuff); return (-1); } @@ -8698,15 +8690,15 @@ rotateImage(uint16 rotation, struct image_data *image, uint32 *img_width, } /* end rotateImage */ static int -reverseSamples8bits (uint16 spp, uint16 bps, uint32 width, - uint8 *ibuff, uint8 *obuff) +reverseSamples8bits (uint16_t spp, uint16_t bps, uint32_t width, + uint8_t *ibuff, uint8_t *obuff) { int ready_bits = 0; - uint32 col; - uint32 src_byte, src_bit; - uint32 bit_offset = 0; - uint8 match_bits = 0, mask_bits = 0; - uint8 buff1 = 0, buff2 = 0; + uint32_t col; + uint32_t src_byte, src_bit; + uint32_t bit_offset = 0; + uint8_t match_bits = 0, mask_bits = 0; + uint8_t buff1 = 0, buff2 = 0; unsigned char *src; unsigned char *dst; tsample_t sample; @@ -8718,7 +8710,7 @@ reverseSamples8bits (uint16 spp, uint16 bps, uint32 width, } ready_bits = 0; - mask_bits = (uint8)-1 >> ( 8 - bps); + mask_bits = (uint8_t)-1 >> (8 - bps); dst = obuff; for (col = width; col > 0; col--) { @@ -8763,16 +8755,16 @@ reverseSamples8bits (uint16 spp, uint16 bps, uint32 width, static int -reverseSamples16bits (uint16 spp, uint16 bps, uint32 width, - uint8 *ibuff, uint8 *obuff) +reverseSamples16bits (uint16_t spp, uint16_t bps, uint32_t width, + uint8_t *ibuff, uint8_t *obuff) { int ready_bits = 0; - uint32 col; - uint32 src_byte = 0, high_bit = 0; - uint32 bit_offset = 0; - uint16 match_bits = 0, mask_bits = 0; - uint16 buff1 = 0, buff2 = 0; - uint8 bytebuff = 0; + uint32_t col; + uint32_t src_byte = 0, high_bit = 0; + uint32_t bit_offset = 0; + uint16_t match_bits = 0, mask_bits = 0; + uint16_t buff1 = 0, buff2 = 0; + uint8_t bytebuff = 0; unsigned char *src; unsigned char *dst; tsample_t sample; @@ -8784,7 +8776,7 @@ reverseSamples16bits (uint16 spp, uint16 bps, uint32 width, } ready_bits = 0; - mask_bits = (uint16)-1 >> (16 - bps); + mask_bits = (uint16_t)-1 >> (16 - bps); dst = obuff; for (col = width; col > 0; col--) { @@ -8838,16 +8830,16 @@ reverseSamples16bits (uint16 spp, uint16 bps, uint32 width, } /* end reverseSamples16bits */ static int -reverseSamples24bits (uint16 spp, uint16 bps, uint32 width, - uint8 *ibuff, uint8 *obuff) +reverseSamples24bits (uint16_t spp, uint16_t bps, uint32_t width, + uint8_t *ibuff, uint8_t *obuff) { int ready_bits = 0; - uint32 col; - uint32 src_byte = 0, high_bit = 0; - uint32 bit_offset = 0; - uint32 match_bits = 0, mask_bits = 0; - uint32 buff1 = 0, buff2 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0; + uint32_t col; + uint32_t src_byte = 0, high_bit = 0; + uint32_t bit_offset = 0; + uint32_t match_bits = 0, mask_bits = 0; + uint32_t buff1 = 0, buff2 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0; unsigned char *src; unsigned char *dst; tsample_t sample; @@ -8859,7 +8851,7 @@ reverseSamples24bits (uint16 spp, uint16 bps, uint32 width, } ready_bits = 0; - mask_bits = (uint32)-1 >> (32 - bps); + mask_bits = (uint32_t)-1 >> (32 - bps); dst = obuff; for (col = width; col > 0; col--) { @@ -8922,18 +8914,18 @@ reverseSamples24bits (uint16 spp, uint16 bps, uint32 width, static int -reverseSamples32bits (uint16 spp, uint16 bps, uint32 width, - uint8 *ibuff, uint8 *obuff) +reverseSamples32bits (uint16_t spp, uint16_t bps, uint32_t width, + uint8_t *ibuff, uint8_t *obuff) { int ready_bits = 0 /*, shift_width = 0 */; /* int bytes_per_sample, bytes_per_pixel; */ - uint32 bit_offset; - uint32 src_byte = 0, high_bit = 0; - uint32 col; - uint32 longbuff1 = 0, longbuff2 = 0; - uint64 mask_bits = 0, match_bits = 0; - uint64 buff1 = 0, buff2 = 0, buff3 = 0; - uint8 bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; + uint32_t bit_offset; + uint32_t src_byte = 0, high_bit = 0; + uint32_t col; + uint32_t longbuff1 = 0, longbuff2 = 0; + uint64_t mask_bits = 0, match_bits = 0; + uint64_t buff1 = 0, buff2 = 0, buff3 = 0; + uint8_t bytebuff1 = 0, bytebuff2 = 0, bytebuff3 = 0, bytebuff4 = 0; unsigned char *src; unsigned char *dst; tsample_t sample; @@ -8945,7 +8937,7 @@ reverseSamples32bits (uint16 spp, uint16 bps, uint32 width, } ready_bits = 0; - mask_bits = (uint64)-1 >> (64 - bps); + mask_bits = (uint64_t)-1 >> (64 - bps); dst = obuff; /* bytes_per_sample = (bps + 7) / 8; */ @@ -8984,7 +8976,7 @@ reverseSamples32bits (uint16 spp, uint16 bps, uint32 width, longbuff1 = (src[3] << 24) | (src[2] << 16) | (src[1] << 8) | src[0]; longbuff2 = longbuff1; } - buff3 = ((uint64)longbuff1 << 32) | longbuff2; + buff3 = ((uint64_t)longbuff1 << 32) | longbuff2; buff1 = (buff3 & match_bits) << (high_bit); if (ready_bits < 32) @@ -9022,12 +9014,12 @@ reverseSamples32bits (uint16 spp, uint16 bps, uint32 width, } /* end reverseSamples32bits */ static int -reverseSamplesBytes (uint16 spp, uint16 bps, uint32 width, - uint8 *src, uint8 *dst) +reverseSamplesBytes (uint16_t spp, uint16_t bps, uint32_t width, + uint8_t *src, uint8_t *dst) { int i; - uint32 col, bytes_per_pixel, col_offset; - uint8 bytebuff1; + uint32_t col, bytes_per_pixel, col_offset; + uint8_t bytebuff1; unsigned char swapbuff[32]; if ((src == NULL) || (dst == NULL)) @@ -9067,7 +9059,7 @@ reverseSamplesBytes (uint16 spp, uint16 bps, uint32 width, dst -= spp; } break; - default: TIFFError("reverseSamplesBytes","Unsupported bit depth %d", bps); + default: TIFFError("reverseSamplesBytes","Unsupported bit depth %"PRIu16, bps); return (1); } return (0); @@ -9076,11 +9068,11 @@ reverseSamplesBytes (uint16 spp, uint16 bps, uint32 width, /* Mirror an image horizontally or vertically */ static int -mirrorImage(uint16 spp, uint16 bps, uint16 mirror, uint32 width, uint32 length, unsigned char *ibuff) +mirrorImage(uint16_t spp, uint16_t bps, uint16_t mirror, uint32_t width, uint32_t length, unsigned char *ibuff) { int shift_width; - uint32 bytes_per_pixel, bytes_per_sample; - uint32 row, rowsize, row_offset; + uint32_t bytes_per_pixel, bytes_per_sample; + uint32_t row, rowsize, row_offset; unsigned char *line_buff = NULL; unsigned char *src; unsigned char *dst; @@ -9170,7 +9162,7 @@ mirrorImage(uint16 spp, uint16 bps, uint16 mirror, uint32 width, uint32 length, } _TIFFmemcpy (src, line_buff, rowsize); break; - default: TIFFError("mirrorImage","Unsupported bit depth %d", bps); + default: TIFFError("mirrorImage","Unsupported bit depth %"PRIu16, bps); _TIFFfree(line_buff); return (-1); } @@ -9180,7 +9172,7 @@ mirrorImage(uint16 spp, uint16 bps, uint16 mirror, uint32 width, uint32 length, } break; - default: TIFFError ("mirrorImage", "Invalid mirror axis %d", mirror); + default: TIFFError ("mirrorImage", "Invalid mirror axis %"PRIu16, mirror); return (-1); break; } @@ -9190,12 +9182,12 @@ mirrorImage(uint16 spp, uint16 bps, uint16 mirror, uint32 width, uint32 length, /* Invert the light and dark values for a bilevel or grayscale image */ static int -invertImage(uint16 photometric, uint16 spp, uint16 bps, uint32 width, uint32 length, unsigned char *work_buff) +invertImage(uint16_t photometric, uint16_t spp, uint16_t bps, uint32_t width, uint32_t length, unsigned char *work_buff) { - uint32 row, col; + uint32_t row, col; unsigned char *src; - uint16 *src_uint16; - uint32 *src_uint32; + uint16_t *src_uint16; + uint32_t *src_uint32; if (spp != 1) { @@ -9218,7 +9210,7 @@ invertImage(uint16 photometric, uint16 spp, uint16 bps, uint32 width, uint32 len switch (bps) { - case 32: src_uint32 = (uint32 *)src; + case 32: src_uint32 = (uint32_t *)src; for (row = 0; row < length; row++) for (col = 0; col < width; col++) { @@ -9226,7 +9218,7 @@ invertImage(uint16 photometric, uint16 spp, uint16 bps, uint32 width, uint32 len src_uint32++; } break; - case 16: src_uint16 = (uint16 *)src; + case 16: src_uint16 = (uint16_t *)src; for (row = 0; row < length; row++) for (col = 0; col < width; col++) { @@ -9244,7 +9236,7 @@ invertImage(uint16 photometric, uint16 spp, uint16 bps, uint32 width, uint32 len src++; } break; - default: TIFFError("invertImage", "Unsupported bit depth %d", bps); + default: TIFFError("invertImage", "Unsupported bit depth %"PRIu16, bps); return (-1); } diff --git a/tiff/tools/tiffdither.c b/tiff/tools/tiffdither.c index a9d1b7c5..062fd608 100644 --- a/tiff/tools/tiffdither.c +++ b/tiff/tools/tiffdither.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> @@ -32,10 +33,6 @@ # include <unistd.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffio.h" #include "tiffiop.h" @@ -52,8 +49,8 @@ #define CopyField(tag, v) \ if (TIFFGetField(in, tag, &v)) TIFFSetField(out, tag, v) -uint32 imagewidth; -uint32 imagelength; +uint32_t imagewidth; +uint32_t imagelength; int threshold = 128; static void usage(int code); @@ -69,8 +66,8 @@ fsdither(TIFF* in, TIFF* out) short *thisline, *nextline, *tmpptr; register unsigned char *outptr; register short *thisptr, *nextptr; - register uint32 i, j; - uint32 imax, jmax; + register uint32_t i, j; + uint32_t imax, jmax; int lastline, lastpixel; int bit; tsize_t outlinesize; @@ -156,9 +153,9 @@ fsdither(TIFF* in, TIFF* out) return errcode; } -static uint16 compression = COMPRESSION_PACKBITS; -static uint16 predictor = 0; -static uint32 group3options = 0; +static uint16_t compression = COMPRESSION_PACKBITS; +static uint16_t predictor = 0; +static uint32_t group3options = 0; static void processG3Options(char* cp) @@ -209,11 +206,11 @@ int main(int argc, char* argv[]) { TIFF *in, *out; - uint16 samplesperpixel, bitspersample = 1, shortv; + uint16_t samplesperpixel, bitspersample = 1, shortv; float floatv; char thing[1024]; - uint32 rowsperstrip = (uint32) -1; - uint16 fillorder = 0; + uint32_t rowsperstrip = (uint32_t) -1; + uint16_t fillorder = 0; int c; #if !HAVE_DECL_OPTARG extern int optind; @@ -246,9 +243,12 @@ main(int argc, char* argv[]) break; case 'h': usage(EXIT_SUCCESS); + /*NOTREACHED*/ + break; case '?': usage(EXIT_FAILURE); /*NOTREACHED*/ + break; } if (argc - optind < 2) usage(EXIT_FAILURE); @@ -305,41 +305,49 @@ main(int argc, char* argv[]) return (EXIT_SUCCESS); } -static const char* stuff[] = { -"usage: tiffdither [options] input.tif output.tif", -"where options are:", -" -r # make each strip have no more than # rows", -" -t # set the threshold value for dithering (default 128)", -" -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 packbits compress output with packbits encoding", -" -c g3[:opts] compress output with CCITT Group 3 encoding", -" -c g4 compress output with CCITT Group 4 encoding", -" -c none use no compression algorithm on output", -"", -"Group 3 options:", -" 1d use default CCITT Group 3 1D-encoding", -" 2d use optional CCITT Group 3 2D-encoding", -" fill byte-align EOL codes", -"For example, -c g3:2d:fill to get G3-2D-encoded data with byte-aligned EOLs", -"", -"LZW and deflate options:", -" # set predictor value", -"For example, -c lzw:2 to get LZW-encoded data with horizontal differencing", -NULL -}; +static const char usage_info[] = +"Convert a greyscale image to bilevel using dithering\n\n" +"usage: tiffdither [options] input.tif output.tif\n" +"where options are:\n" +" -r # make each strip have no more than # rows\n" +" -t # set the threshold value for dithering (default 128)\n" +" -f lsb2msb force lsb-to-msb FillOrder for output\n" +" -f msb2lsb force msb-to-lsb FillOrder for output\n" +"\n" +#ifdef LZW_SUPPORT +" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding\n" +" # set predictor value\n" +" For example, -c lzw:2 for LZW-encoded data with horizontal differencing\n" +#endif +#ifdef ZIP_SUPPORT +" -c zip[:opts] compress output with deflate encoding\n" +" # set predictor value\n" +#endif +#ifdef PACKBITS_SUPPORT +" -c packbits compress output with packbits encoding\n" +#endif +#ifdef CCITT_SUPPORT +" -c g3[:opts] compress output with CCITT Group 3 encoding\n" +" Group 3 options:\n" +" 1d use default CCITT Group 3 1D-encoding\n" +" 2d use optional CCITT Group 3 2D-encoding\n" +" fill byte-align EOL codes\n" +" For example, -c g3:2d:fill for G3-2D-encoded data with byte-aligned EOLs\n" +" -c g4 compress output with CCITT Group 4 encoding\n" +#endif +#if defined(LZW_SUPPORT) || defined(ZIP_SUPPORT) || defined(PACKBITS_SUPPORT) || defined(CCITT_SUPPORT) +" -c none use no compression algorithm on output\n" +#endif +"\n" +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } diff --git a/tiff/tools/tiffdump.c b/tiff/tools/tiffdump.c index 00be9dd4..500fffb6 100644 --- a/tiff/tools/tiffdump.c +++ b/tiff/tools/tiffdump.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> @@ -46,14 +47,6 @@ # include <io.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - -#ifndef HAVE_GETOPT -extern int getopt(int argc, char * const argv[], const char *optstring); -#endif - #include "tiffio.h" #ifndef EXIT_SUCCESS @@ -73,35 +66,35 @@ static union TIFFHeaderBig big; TIFFHeaderCommon common; } hdr; -char* appname; -char* curfile; -int swabflag; -int bigendian; -int bigtiff; -uint32 maxitems = 24; /* maximum indirect data items to print */ - -const char* bytefmt = "%s%#02x"; /* BYTE */ -const char* sbytefmt = "%s%d"; /* SBYTE */ -const char* shortfmt = "%s%u"; /* SHORT */ -const char* sshortfmt = "%s%d"; /* SSHORT */ -const char* longfmt = "%s%lu"; /* LONG */ -const char* slongfmt = "%s%ld"; /* SLONG */ -const char* ifdfmt = "%s%#04lx"; /* IFD offset */ -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) -const char* long8fmt = "%s%I64u"; /* LONG8 */ -const char* slong8fmt = "%s%I64d"; /* SLONG8 */ -const char* ifd8fmt = "%s%#08I64x"; /* IFD offset8*/ -#else -const char* long8fmt = "%s%llu"; /* LONG8 */ -const char* slong8fmt = "%s%lld"; /* SLONG8 */ -const char* ifd8fmt = "%s%#08llx"; /* IFD offset8*/ -#endif -const char* rationalfmt = "%s%g"; /* RATIONAL */ -const char* srationalfmt = "%s%g"; /* SRATIONAL */ -const char* floatfmt = "%s%g"; /* FLOAT */ -const char* doublefmt = "%s%g"; /* DOUBLE */ - -static void dump(int, uint64); +static char* appname; +static char* curfile; +static int swabflag; +static int bigendian; +static int bigtiff; +static uint32_t maxitems = 24; /* maximum indirect data items to print */ + +static const char bytefmt[] = "%s%#02" PRIx8; /* BYTE */ +static const char sbytefmt[] = "%s%" PRId8; /* SBYTE */ +static const char shortfmtd[] = "%s%" PRIu16; /* SHORT */ +static const char shortfmth[] = "%s%#" PRIx16; +static const char sshortfmtd[] = "%s%" PRId16; /* SSHORT */ +static const char sshortfmth[] = "%s%#" PRIx16; +static const char longfmtd[] = "%s%" PRIu32; /* LONG */ +static const char longfmth[] = "%s%#" PRIx32; +static const char slongfmtd[] = "%s%" PRId32; /* SLONG */ +static const char slongfmth[] = "%s%#" PRIx32; +static const char ifdfmt[] = "%s%#04" PRIx32; /* IFD offset */ +static const char long8fmt[] = "%s%" PRIu64; /* LONG8 */ +static const char slong8fmt[] = "%s%" PRId64; /* SLONG8 */ +static const char ifd8fmt[] = "%s%#08" PRIx64; /* IFD offset8 */ +static const char rationalfmt[] = "%s%g"; /* RATIONAL */ +static const char srationalfmt[] = "%s%g"; /* SRATIONAL */ +static const char floatfmt[] = "%s%g"; /* FLOAT */ +static const char doublefmt[] = "%s%g"; /* DOUBLE */ + +unsigned int hex_mode; + +static void dump(int, uint64_t); #if !HAVE_DECL_OPTARG extern int optind; @@ -111,6 +104,7 @@ extern char* optarg; void usage() { + fprintf(stderr, "\nDisplay directory information from TIFF files\n\n"); fprintf(stderr, "usage: %s [-h] [-o offset] [-m maxitems] file.tif ...\n", appname); exit(EXIT_FAILURE); } @@ -121,20 +115,18 @@ main(int argc, char* argv[]) int one = 1, fd; int multiplefiles = (argc > 1); int c; - uint64 diroff = 0; + uint64_t diroff = 0; + hex_mode=0; bigendian = (*(char *)&one == 0); appname = argv[0]; while ((c = getopt(argc, argv, "m:o:h")) != -1) { switch (c) { - case 'h': /* print values in hex */ - shortfmt = "%s%#x"; - sshortfmt = "%s%#x"; - longfmt = "%s%#lx"; - slongfmt = "%s%#lx"; + case 'h': /* print values in hex */ + hex_mode=1; break; case 'o': - diroff = (uint64) strtoul(optarg, NULL, 0); + diroff = (uint64_t) strtoul(optarg, NULL, 0); break; case 'm': maxitems = strtoul(optarg, NULL, 0); @@ -164,16 +156,16 @@ main(int argc, char* argv[]) #define ord(e) ((int)e) -static uint64 ReadDirectory(int, unsigned, uint64); +static uint64_t ReadDirectory(int, unsigned, uint64_t); static void ReadError(char*); static void Error(const char*, ...); static void Fatal(const char*, ...); static void -dump(int fd, uint64 diroff) +dump(int fd, uint64_t diroff) { unsigned i, j; - uint64* visited_diroff = NULL; + uint64_t* visited_diroff = NULL; unsigned int count_visited_dir = 0; _TIFF_lseek_f(fd, (_TIFF_off_t) 0, 0); @@ -246,7 +238,7 @@ dump(int fd, uint64 diroff) { size_t alloc_size; alloc_size=TIFFSafeMultiply(tmsize_t,(count_visited_dir + 1), - sizeof(uint64)); + sizeof(uint64_t)); if (alloc_size == 0) { if (visited_diroff) @@ -255,7 +247,7 @@ dump(int fd, uint64 diroff) } else { - visited_diroff = (uint64*) realloc(visited_diroff,alloc_size); + visited_diroff = (uint64_t*) realloc(visited_diroff, alloc_size); } } if( !visited_diroff ) @@ -293,24 +285,24 @@ static const int datawidth[] = { 8, /* 18 = TIFF_IFD8 */ }; #define NWIDTHS (sizeof (datawidth) / sizeof (datawidth[0])) -static void PrintTag(FILE*, uint16); -static void PrintType(FILE*, uint16); -static void PrintData(FILE*, uint16, uint32, unsigned char*); +static void PrintTag(FILE*, uint16_t); +static void PrintType(FILE*, uint16_t); +static void PrintData(FILE*, uint16_t, uint32_t, unsigned char*); /* * Read the next TIFF directory from a file * and convert it to the internal format. * We read directories sequentially. */ -static uint64 -ReadDirectory(int fd, unsigned int ix, uint64 off) +static uint64_t +ReadDirectory(int fd, unsigned int ix, uint64_t off) { - uint16 dircount; - uint32 direntrysize; + uint16_t dircount; + uint32_t direntrysize; void* dirmem = NULL; - uint64 nextdiroff = 0; - uint32 n; - uint8* dp; + uint64_t nextdiroff = 0; + uint32_t n; + uint8_t* dp; if (off == 0) /* no more directories */ goto done; @@ -319,7 +311,7 @@ ReadDirectory(int fd, unsigned int ix, uint64 off) goto done; } if (!bigtiff) { - if (read(fd, (char*) &dircount, sizeof (uint16)) != sizeof (uint16)) { + if (read(fd, (char*) &dircount, sizeof (uint16_t)) != sizeof (uint16_t)) { ReadError("directory count"); goto done; } @@ -327,8 +319,8 @@ ReadDirectory(int fd, unsigned int ix, uint64 off) TIFFSwabShort(&dircount); direntrysize = 12; } else { - uint64 dircount64 = 0; - if (read(fd, (char*) &dircount64, sizeof (uint64)) != sizeof (uint64)) { + uint64_t dircount64 = 0; + if (read(fd, (char*) &dircount64, sizeof (uint64_t)) != sizeof (uint64_t)) { ReadError("directory count"); goto done; } @@ -338,7 +330,7 @@ ReadDirectory(int fd, unsigned int ix, uint64 off) Error("Sanity check on directory count failed"); goto done; } - dircount = (uint16)dircount64; + dircount = (uint16_t)dircount64; direntrysize = 20; } dirmem = _TIFFmalloc(TIFFSafeMultiply(tmsize_t,dircount,direntrysize)); @@ -350,57 +342,45 @@ ReadDirectory(int fd, unsigned int ix, uint64 off) if (n != dircount*direntrysize) { n /= direntrysize; Error( -#if defined(__WIN32__) && defined(_MSC_VER) - "Could only read %lu of %u entries in directory at offset %#I64x", - (unsigned long)n, dircount, (unsigned __int64) off); -#else - "Could only read %lu of %u entries in directory at offset %#llx", - (unsigned long)n, dircount, (unsigned long long) off); -#endif + "Could only read %" PRIu32 " of %" PRIu16 " entries in directory at offset %#" PRIu64, + n, dircount, off); dircount = n; nextdiroff = 0; } else { if (!bigtiff) { - uint32 nextdiroff32; - if (read(fd, (char*) &nextdiroff32, sizeof (uint32)) != sizeof (uint32)) + uint32_t nextdiroff32; + if (read(fd, (char*) &nextdiroff32, sizeof (uint32_t)) != sizeof (uint32_t)) nextdiroff32 = 0; if (swabflag) TIFFSwabLong(&nextdiroff32); nextdiroff = nextdiroff32; } else { - if (read(fd, (char*) &nextdiroff, sizeof (uint64)) != sizeof (uint64)) + if (read(fd, (char*) &nextdiroff, sizeof (uint64_t)) != sizeof (uint64_t)) nextdiroff = 0; if (swabflag) TIFFSwabLong8(&nextdiroff); } } -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - printf("Directory %u: offset %I64u (%#I64x) next %I64u (%#I64x)\n", ix, - (unsigned __int64)off, (unsigned __int64)off, - (unsigned __int64)nextdiroff, (unsigned __int64)nextdiroff); -#else - printf("Directory %u: offset %llu (%#llx) next %llu (%#llx)\n", ix, - (unsigned long long)off, (unsigned long long)off, - (unsigned long long)nextdiroff, (unsigned long long)nextdiroff); -#endif - for (dp = (uint8*)dirmem, n = dircount; n > 0; n--) { - uint16 tag; - uint16 type; - uint16 typewidth; - uint64 count; - uint64 datasize; + printf("Directory %u: offset %" PRIu64 " (%#" PRIx64 ") next %" PRIu64 " (%#" PRIx64 ")\n", + ix, off, off, nextdiroff, nextdiroff); + for (dp = (uint8_t*)dirmem, n = dircount; n > 0; n--) { + uint16_t tag; + uint16_t type; + uint16_t typewidth; + uint64_t count; + uint64_t datasize; int datafits; void* datamem; - uint64 dataoffset; + uint64_t dataoffset; int datatruncated; int datasizeoverflow; - tag = *(uint16*)dp; + tag = *(uint16_t*)dp; if (swabflag) TIFFSwabShort(&tag); - dp += sizeof(uint16); - type = *(uint16*)dp; - dp += sizeof(uint16); + dp += sizeof(uint16_t); + type = *(uint16_t*)dp; + dp += sizeof(uint16_t); if (swabflag) TIFFSwabShort(&type); PrintTag(stdout, tag); @@ -409,25 +389,21 @@ ReadDirectory(int fd, unsigned int ix, uint64 off) putchar(' '); if (!bigtiff) { - uint32 count32; - count32 = *(uint32*)dp; + uint32_t count32; + count32 = *(uint32_t*)dp; if (swabflag) TIFFSwabLong(&count32); - dp += sizeof(uint32); + dp += sizeof(uint32_t); count = count32; } else { - memcpy(&count, dp, sizeof(uint64)); + memcpy(&count, dp, sizeof(uint64_t)); if (swabflag) TIFFSwabLong8(&count); - dp += sizeof(uint64); + dp += sizeof(uint64_t); } -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - printf("%I64u<", (unsigned __int64)count); -#else - printf("%llu<", (unsigned long long)count); -#endif + printf("%" PRIu64 "<", count); if (type >= NWIDTHS) typewidth = 0; else @@ -442,15 +418,15 @@ ReadDirectory(int fd, unsigned int ix, uint64 off) { if (datasizeoverflow || datasize>4) { - uint32 dataoffset32; + uint32_t dataoffset32; datafits = 0; datamem = NULL; - dataoffset32 = *(uint32*)dp; + dataoffset32 = *(uint32_t*)dp; if (swabflag) TIFFSwabLong(&dataoffset32); dataoffset = dataoffset32; } - dp += sizeof(uint32); + dp += sizeof(uint32_t); } else { @@ -458,11 +434,11 @@ ReadDirectory(int fd, unsigned int ix, uint64 off) { datafits = 0; datamem = NULL; - memcpy(&dataoffset, dp, sizeof(uint64)); + memcpy(&dataoffset, dp, sizeof(uint64_t)); if (swabflag) TIFFSwabLong8(&dataoffset); } - dp += sizeof(uint64); + dp += sizeof(uint64_t); } if (datasizeoverflow || datasize>0x10000) { @@ -488,7 +464,7 @@ ReadDirectory(int fd, unsigned int ix, uint64 off) _TIFFfree(datamem); datamem = NULL; } - else if (read(fd, datamem, (size_t)datasize) != (TIFF_SSIZE_T)datasize) + else if (read(fd, datamem, (size_t)datasize) != (tmsize_t)datasize) { Error( "Read error accessing tag %u value", tag); @@ -511,27 +487,27 @@ ReadDirectory(int fd, unsigned int ix, uint64 off) break; case TIFF_SHORT: case TIFF_SSHORT: - TIFFSwabArrayOfShort((uint16*)datamem,(tmsize_t)count); + TIFFSwabArrayOfShort((uint16_t*)datamem, (tmsize_t)count); break; case TIFF_LONG: case TIFF_SLONG: case TIFF_FLOAT: case TIFF_IFD: - TIFFSwabArrayOfLong((uint32*)datamem,(tmsize_t)count); + TIFFSwabArrayOfLong((uint32_t*)datamem, (tmsize_t)count); break; case TIFF_RATIONAL: case TIFF_SRATIONAL: - TIFFSwabArrayOfLong((uint32*)datamem,(tmsize_t)count*2); + TIFFSwabArrayOfLong((uint32_t*)datamem, (tmsize_t)count * 2); break; case TIFF_DOUBLE: case TIFF_LONG8: case TIFF_SLONG8: case TIFF_IFD8: - TIFFSwabArrayOfLong8((uint64*)datamem,(tmsize_t)count); + TIFFSwabArrayOfLong8((uint64_t*)datamem, (tmsize_t)count); break; } } - PrintData(stdout,type,(uint32)count,datamem); + PrintData(stdout, type, (uint32_t)count, datamem); if (datatruncated) printf(" ..."); if (!datafits) @@ -549,7 +525,7 @@ done: } static const struct tagname { - uint16 tag; + uint16_t tag; const char* name; } tagnames[] = { { TIFFTAG_SUBFILETYPE, "SubFileType" }, @@ -647,7 +623,7 @@ static const struct tagname { #define NTAGS (sizeof (tagnames) / sizeof (tagnames[0])) static void -PrintTag(FILE* fd, uint16 tag) +PrintTag(FILE* fd, uint16_t tag) { const struct tagname *tp; @@ -660,7 +636,7 @@ PrintTag(FILE* fd, uint16 tag) } static void -PrintType(FILE* fd, uint16 type) +PrintType(FILE* fd, uint16_t type) { static const char *typenames[] = { "0", @@ -695,7 +671,7 @@ PrintType(FILE* fd, uint16 type) #include <ctype.h> static void -PrintASCII(FILE* fd, uint32 cc, const unsigned char* cp) +PrintASCII(FILE* fd, uint32_t cc, const unsigned char* cp) { for (; cc > 0; cc--, cp++) { const char* tp; @@ -717,7 +693,7 @@ PrintASCII(FILE* fd, uint32 cc, const unsigned char* cp) } static void -PrintData(FILE* fd, uint16 type, uint32 count, unsigned char* data) +PrintData(FILE* fd, uint16_t type, uint32_t count, unsigned char* data) { char* sep = ""; @@ -738,36 +714,36 @@ PrintData(FILE* fd, uint16 type, uint32 count, unsigned char* data) PrintASCII(fd, count, data); break; case TIFF_SHORT: { - uint16 *wp = (uint16*)data; + uint16_t *wp = (uint16_t*)data; while (count-- > 0) - fprintf(fd, shortfmt, sep, *wp++), sep = " "; + fprintf(fd, hex_mode ? shortfmth : shortfmtd, sep, *wp++), sep = " "; break; } case TIFF_SSHORT: { - int16 *wp = (int16*)data; + int16_t *wp = (int16_t*)data; while (count-- > 0) - fprintf(fd, sshortfmt, sep, *wp++), sep = " "; + fprintf(fd, hex_mode ? sshortfmth : sshortfmtd, sep, *wp++), sep = " "; break; } case TIFF_LONG: { - uint32 *lp = (uint32*)data; + uint32_t *lp = (uint32_t*)data; while (count-- > 0) { - fprintf(fd, longfmt, sep, (unsigned long) *lp++); + fprintf(fd, hex_mode ? longfmth : longfmtd, sep, *lp++); sep = " "; } break; } case TIFF_SLONG: { - int32 *lp = (int32*)data; + int32_t *lp = (int32_t*)data; while (count-- > 0) - fprintf(fd, slongfmt, sep, (long) *lp++), sep = " "; + fprintf(fd, hex_mode ? slongfmth : slongfmtd, sep, *lp++), sep = " "; break; } case TIFF_LONG8: { - uint64 *llp = (uint64*)data; + uint64_t *llp = (uint64_t*)data; while (count-- > 0) { - uint64 val; - memcpy(&val, llp, sizeof(uint64)); + uint64_t val; + memcpy(&val, llp, sizeof(uint64_t)); llp ++; fprintf(fd, long8fmt, sep, val); sep = " "; @@ -775,10 +751,10 @@ PrintData(FILE* fd, uint16 type, uint32 count, unsigned char* data) break; } case TIFF_SLONG8: { - int64 *llp = (int64*)data; + int64_t *llp = (int64_t*)data; while (count-- > 0) { - int64 val; - memcpy(&val, llp, sizeof(int64)); + int64_t val; + memcpy(&val, llp, sizeof(int64_t)); llp ++; fprintf(fd, slong8fmt, sep, val); sep = " "; @@ -786,12 +762,11 @@ PrintData(FILE* fd, uint16 type, uint32 count, unsigned char* data) break; } case TIFF_RATIONAL: { - uint32 *lp = (uint32*)data; + uint32_t *lp = (uint32_t*)data; while (count-- > 0) { if (lp[1] == 0) - fprintf(fd, "%sNan (%lu/%lu)", sep, - (unsigned long) lp[0], - (unsigned long) lp[1]); + fprintf(fd, "%sNan (%"PRIu32"/%"PRIu32")", sep, + lp[0], lp[1]); else fprintf(fd, rationalfmt, sep, (double)lp[0] / (double)lp[1]); @@ -801,11 +776,11 @@ PrintData(FILE* fd, uint16 type, uint32 count, unsigned char* data) break; } case TIFF_SRATIONAL: { - int32 *lp = (int32*)data; + int32_t *lp = (int32_t*)data; while (count-- > 0) { if (lp[1] == 0) - fprintf(fd, "%sNan (%ld/%ld)", sep, - (long) lp[0], (long) lp[1]); + fprintf(fd, "%sNan (%"PRId32"/%"PRId32")", sep, + lp[0], lp[1]); else fprintf(fd, srationalfmt, sep, (double)lp[0] / (double)lp[1]); @@ -827,21 +802,18 @@ PrintData(FILE* fd, uint16 type, uint32 count, unsigned char* data) break; } case TIFF_IFD: { - uint32 *lp = (uint32*)data; + uint32_t *lp = (uint32_t*)data; while (count-- > 0) { - fprintf(fd, ifdfmt, sep, (unsigned long) *lp++); + fprintf(fd, ifdfmt, sep, *lp++); sep = " "; } break; } case TIFF_IFD8: { - uint64 *llp = (uint64*)data; + uint64_t *llp = (uint64_t*)data; while (count-- > 0) { -#if defined(__WIN32__) && defined(_MSC_VER) - fprintf(fd, ifd8fmt, sep, (unsigned __int64) *llp++); -#else - fprintf(fd, ifd8fmt, sep, (unsigned long long) *llp++); -#endif + fprintf(fd, ifd8fmt, sep, *llp++); + sep = " "; sep = " "; } break; diff --git a/tiff/tools/tiffgt.c b/tiff/tools/tiffgt.c index f3cca8c9..f9e1e087 100644 --- a/tiff/tools/tiffgt.c +++ b/tiff/tools/tiffgt.c @@ -24,6 +24,8 @@ */ #include "tif_config.h" +#include "libport.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -55,20 +57,16 @@ #define EXIT_FAILURE 1 #endif -#ifndef HAVE_GETOPT -extern int getopt(int argc, char * const argv[], const char *optstring); -#endif - -static uint32 width = 0, height = 0; /* window width & height */ -static uint32* raster = NULL; /* displayable image */ +static uint32_t width = 0, height = 0; /* window width & height */ +static uint32_t* raster = NULL; /* displayable image */ static TIFFRGBAImage img; static int order0 = 0, order; -static uint16 photo0 = (uint16) -1, photo; +static uint16_t photo0 = (uint16_t) -1, photo; static int stoponerr = 0; /* stop on read error */ static int verbose = 0; #define TITLE_LENGTH 1024 static char title[TITLE_LENGTH]; /* window title line */ -static uint32 xmax, ymax; +static uint32_t xmax, ymax; static char** filelist = NULL; static int fileindex; static int filenum; @@ -81,7 +79,7 @@ static int prevImage(void); static int nextImage(void); static void setWindowSize(void); static void usage(int); -static uint16 photoArg(const char*); +static uint16_t photoArg(const char*); static void raster_draw(void); static void raster_reshape(int, int); static void raster_keys(unsigned char, int, int); @@ -105,7 +103,7 @@ main(int argc, char* argv[]) { int c; int dirnum = -1; - uint32 diroff = 0; + uint32_t diroff = 0; oerror = TIFFSetErrorHandler(NULL); owarning = TIFFSetWarningHandler(NULL); @@ -223,11 +221,11 @@ cleanup_and_exit(int code) static int initImage(void) { - uint32 w, h; + uint32_t w, h; if (order) TIFFSetField(tif, TIFFTAG_FILLORDER, order); - if (photo != (uint16) -1) + if (photo != (uint16_t) -1) TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photo); if (!TIFFRGBAImageBegin(&img, tif, stoponerr, title)) { TIFFError(filelist[fileindex], "%s", title); @@ -251,12 +249,12 @@ initImage(void) } if (w != width || h != height) { - uint32 rastersize = + uint32_t rastersize = _TIFFMultiply32(tif, img.width, img.height, "allocating raster buffer"); if (raster != NULL) _TIFFfree(raster), raster = NULL; - raster = (uint32*) _TIFFCheckMalloc(tif, rastersize, sizeof (uint32), - "allocating raster buffer"); + raster = (uint32_t*) _TIFFCheckMalloc(tif, rastersize, sizeof (uint32_t), + "allocating raster buffer"); if (raster == NULL) { width = height = 0; TIFFError(filelist[fileindex], "No space for raster buffer"); @@ -461,7 +459,7 @@ usage(int code) exit(code); } -static uint16 +static uint16_t photoArg(const char* arg) { if (strcmp(arg, "miniswhite") == 0) @@ -485,7 +483,7 @@ photoArg(const char* arg) else if (strcmp(arg, "logluv") == 0) return (PHOTOMETRIC_LOGLUV); else - return ((uint16) -1); + return ((uint16_t) -1); } /* vim: set ts=8 sts=8 sw=8 noet: */ diff --git a/tiff/tools/tiffinfo.c b/tiff/tools/tiffinfo.c index 2271c9d1..6921a0c5 100644 --- a/tiff/tools/tiffinfo.c +++ b/tiff/tools/tiffinfo.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> @@ -36,10 +37,6 @@ # include <unistd.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffiop.h" #ifndef EXIT_SUCCESS @@ -58,7 +55,7 @@ static int readdata = 0; /* read data in file */ static int stoponerr = 1; /* stop on first read error */ static void usage(int); -static void tiffinfo(TIFF*, uint16, long, int); +static void tiffinfo(TIFF*, uint16_t, long, int); static void PrivateErrorHandler(const char* module, const char* fmt, va_list ap) @@ -72,14 +69,14 @@ int main(int argc, char* argv[]) { int dirnum = -1, multiplefiles, c; - uint16 order = 0; + uint16_t order = 0; TIFF* tif; #if !HAVE_DECL_OPTARG extern int optind; extern char* optarg; #endif long flags = 0; - uint64 diroff = 0; + uint64_t diroff = 0; int chopstrips = 0; /* disable strip chopping */ while ((c = getopt(argc, argv, "f:o:cdDSjilmrsvwz0123456789h")) != -1) @@ -131,10 +128,12 @@ main(int argc, char* argv[]) break; case 'h': usage(EXIT_SUCCESS); - /*NOTREACHED*/ + /*NOTREACHED*/ + break; case '?': usage(EXIT_FAILURE); /*NOTREACHED*/ + break; } if (optind >= argc) usage(EXIT_FAILURE); @@ -172,43 +171,41 @@ main(int argc, char* argv[]) return (status); } -static const char* stuff[] = { -"usage: tiffinfo [options] input...", -"where options are:", -" -D read data", -" -i ignore read errors", -" -c display data for grey/color response curve or colormap", -" -d display raw/decoded image data", -" -f lsb2msb force lsb-to-msb FillOrder for input", -" -f msb2lsb force msb-to-lsb FillOrder for input", -" -j show JPEG tables", -" -o offset set initial directory offset", -" -r read/display raw image data instead of decoded data", -" -s display strip offsets and byte counts", -" -w display raw data in words rather than bytes", -" -z enable strip chopping", -" -# set initial directory (first directory is # 0)", -NULL -}; +static const char usage_info[] = +"Display information about TIFF files\n\n" +"usage: tiffinfo [options] input...\n" +"where options are:\n" +" -D read data\n" +" -i ignore read errors\n" +" -c display data for grey/color response curve or colormap\n" +" -d display raw/decoded image data\n" +" -f lsb2msb force lsb-to-msb FillOrder for input\n" +" -f msb2lsb force msb-to-lsb FillOrder for input\n" +" -j show JPEG tables\n" +" -o offset set initial directory offset\n" +" -r read/display raw image data instead of decoded data\n" +" -s display strip offsets and byte counts\n" +" -w display raw data in words rather than bytes\n" +" -z enable strip chopping\n" +" -# set initial directory (first directory is # 0)\n" +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } static void -ShowStrip(tstrip_t strip, unsigned char* pp, uint32 nrow, tsize_t scanline) +ShowStrip(tstrip_t strip, unsigned char* pp, uint32_t nrow, tsize_t scanline) { register tsize_t cc; - printf("Strip %lu:\n", (unsigned long) strip); + printf("Strip %"PRIu32":\n", strip); while (nrow-- > 0) { for (cc = 0; cc < scanline; cc++) { printf(" %02x", *pp++); @@ -227,13 +224,13 @@ TIFFReadContigStripData(TIFF* tif) buf = (unsigned char *)_TIFFmalloc(TIFFStripSize(tif)); if (buf) { - uint32 row, h=0; - uint32 rowsperstrip = (uint32)-1; + uint32_t row, h=0; + uint32_t rowsperstrip = (uint32_t)-1; TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h); TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); for (row = 0; row < h; row += rowsperstrip) { - uint32 nrow = (row+rowsperstrip > h ? + uint32_t nrow = (row + rowsperstrip > h ? h-row : rowsperstrip); tstrip_t strip = TIFFComputeStrip(tif, row, 0); if (TIFFReadEncodedStrip(tif, strip, buf, nrow*scanline) < 0) { @@ -254,8 +251,8 @@ TIFFReadSeparateStripData(TIFF* tif) buf = (unsigned char *)_TIFFmalloc(TIFFStripSize(tif)); if (buf) { - uint32 row, h=0; - uint32 rowsperstrip = (uint32)-1; + uint32_t row, h=0; + uint32_t rowsperstrip = (uint32_t)-1; tsample_t s, samplesperpixel=0; TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h); @@ -263,7 +260,7 @@ TIFFReadSeparateStripData(TIFF* tif) TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); for (row = 0; row < h; row += rowsperstrip) { for (s = 0; s < samplesperpixel; s++) { - uint32 nrow = (row+rowsperstrip > h ? + uint32_t nrow = (row + rowsperstrip > h ? h-row : rowsperstrip); tstrip_t strip = TIFFComputeStrip(tif, row, s); if (TIFFReadEncodedStrip(tif, strip, buf, nrow*scanline) < 0) { @@ -278,17 +275,17 @@ TIFFReadSeparateStripData(TIFF* tif) } static void -ShowTile(uint32 row, uint32 col, tsample_t sample, - unsigned char* pp, uint32 nrow, tsize_t rowsize) +ShowTile(uint32_t row, uint32_t col, tsample_t sample, + unsigned char* pp, uint32_t nrow, tsize_t rowsize) { - uint32 cc; + uint32_t cc; - printf("Tile (%lu,%lu", (unsigned long) row, (unsigned long) col); + printf("Tile (%" PRIu32 ",%" PRIu32 "", row, col); if (sample != (tsample_t) -1) - printf(",%u", sample); + printf(",%" PRIu16, sample); printf("):\n"); while (nrow-- > 0) { - for (cc = 0; cc < (uint32) rowsize; cc++) { + for (cc = 0; cc < (uint32_t) rowsize; cc++) { printf(" %02x", *pp++); if (((cc+1) % 24) == 0) putchar('\n'); @@ -306,8 +303,8 @@ TIFFReadContigTileData(TIFF* tif) buf = (unsigned char *)_TIFFmalloc(tilesize); if (buf) { - uint32 tw=0, th=0, w=0, h=0; - uint32 row, col; + uint32_t tw=0, th=0, w=0, h=0; + uint32_t row, col; TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w); TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h); @@ -341,8 +338,8 @@ TIFFReadSeparateTileData(TIFF* tif) buf = (unsigned char *)_TIFFmalloc(tilesize); if (buf) { - uint32 tw=0, th=0, w=0, h=0; - uint32 row, col; + uint32_t tw=0, th=0, w=0, h=0; + uint32_t row, col; tsample_t s, samplesperpixel=0; TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w); @@ -374,7 +371,7 @@ TIFFReadSeparateTileData(TIFF* tif) void TIFFReadData(TIFF* tif) { - uint16 config = PLANARCONFIG_CONTIG; + uint16_t config = PLANARCONFIG_CONTIG; TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &config); if (TIFFIsTiled(tif)) { @@ -391,9 +388,9 @@ TIFFReadData(TIFF* tif) } static void -ShowRawBytes(unsigned char* pp, uint32 n) +ShowRawBytes(unsigned char* pp, uint32_t n) { - uint32 i; + uint32_t i; for (i = 0; i < n; i++) { printf(" %02x", *pp++); @@ -404,12 +401,12 @@ ShowRawBytes(unsigned char* pp, uint32 n) } static void -ShowRawWords(uint16* pp, uint32 n) +ShowRawWords(uint16_t* pp, uint32_t n) { - uint32 i; + uint32_t i; for (i = 0; i < n; i++) { - printf(" %04x", *pp++); + printf(" %04" PRIx16, *pp++); if (((i+1) % 15) == 0) printf("\n "); } @@ -421,42 +418,42 @@ TIFFReadRawDataStriped(TIFF* tif, int bitrev) { tstrip_t nstrips = TIFFNumberOfStrips(tif); const char* what = "Strip"; - uint64* stripbc=NULL; + uint64_t* stripbc=NULL; TIFFGetField(tif, TIFFTAG_STRIPBYTECOUNTS, &stripbc); if (stripbc != NULL && nstrips > 0) { - uint32 bufsize = (uint32) stripbc[0]; + uint32_t bufsize = (uint32_t) stripbc[0]; tdata_t buf = _TIFFmalloc(bufsize); tstrip_t s; for (s = 0; s < nstrips; s++) { if (stripbc[s] > bufsize) { buf = _TIFFrealloc(buf, (tmsize_t)stripbc[s]); - bufsize = (uint32) stripbc[s]; + bufsize = (uint32_t) stripbc[s]; } if (buf == NULL) { fprintf(stderr, - "Cannot allocate buffer to read strip %lu\n", - (unsigned long) s); + "Cannot allocate buffer to read strip %"PRIu32"\n", + s); break; } if (TIFFReadRawStrip(tif, s, buf, (tmsize_t) stripbc[s]) < 0) { - fprintf(stderr, "Error reading strip %lu\n", - (unsigned long) s); + fprintf(stderr, "Error reading strip %"PRIu32"\n", + s); if (stoponerr) break; } else if (showdata) { if (bitrev) { TIFFReverseBits(buf, (tmsize_t)stripbc[s]); - printf("%s %lu: (bit reversed)\n ", - what, (unsigned long) s); + printf("%s %"PRIu32": (bit reversed)\n ", + what, s); } else - printf("%s %lu:\n ", what, - (unsigned long) s); + printf("%s %"PRIu32":\n ", what, + s); if (showwords) - ShowRawWords((uint16*) buf, (uint32) stripbc[s]>>1); + ShowRawWords((uint16_t*) buf, (uint32_t) stripbc[s] >> 1); else - ShowRawBytes((unsigned char*) buf, (uint32) stripbc[s]); + ShowRawBytes((unsigned char*) buf, (uint32_t) stripbc[s]); } } if (buf != NULL) @@ -468,14 +465,14 @@ static void TIFFReadRawDataTiled(TIFF* tif, int bitrev) { const char* what = "Tile"; - uint32 ntiles = TIFFNumberOfTiles(tif); - uint64 *tilebc; + uint32_t ntiles = TIFFNumberOfTiles(tif); + uint64_t *tilebc; TIFFGetField(tif, TIFFTAG_TILEBYTECOUNTS, &tilebc); if (tilebc != NULL && ntiles > 0) { - uint64 bufsize = 0; + uint64_t bufsize = 0; tdata_t buf = NULL; - uint32 t; + uint32_t t; for (t = 0; t < ntiles; t++) { if (buf == NULL || tilebc[t] > bufsize) { @@ -484,28 +481,28 @@ TIFFReadRawDataTiled(TIFF* tif, int bitrev) } if (buf == NULL) { fprintf(stderr, - "Cannot allocate buffer to read tile %lu\n", - (unsigned long) t); + "Cannot allocate buffer to read tile %"PRIu32"\n", + t); break; } if (TIFFReadRawTile(tif, t, buf, (tmsize_t)tilebc[t]) < 0) { - fprintf(stderr, "Error reading tile %lu\n", - (unsigned long) t); + fprintf(stderr, "Error reading tile %"PRIu32"\n", + t); if (stoponerr) break; } else if (showdata) { if (bitrev) { TIFFReverseBits(buf, (tmsize_t)tilebc[t]); - printf("%s %lu: (bit reversed)\n ", - what, (unsigned long) t); + printf("%s %"PRIu32": (bit reversed)\n ", + what, t); } else { - printf("%s %lu:\n ", what, - (unsigned long) t); + printf("%s %"PRIu32":\n ", what, + t); } if (showwords) { - ShowRawWords((uint16*) buf, (uint32)(tilebc[t]>>1)); + ShowRawWords((uint16_t*) buf, (uint32_t)(tilebc[t] >> 1)); } else { - ShowRawBytes((unsigned char*) buf, (uint32) tilebc[t]); + ShowRawBytes((unsigned char*) buf, (uint32_t) tilebc[t]); } } } @@ -525,14 +522,14 @@ TIFFReadRawData(TIFF* tif, int bitrev) } static void -tiffinfo(TIFF* tif, uint16 order, long flags, int is_image) +tiffinfo(TIFF* tif, uint16_t order, long flags, int is_image) { TIFFPrintDirectory(tif, stdout, flags); if (!readdata || !is_image) return; if (rawdata) { if (order) { - uint16 o; + uint16_t o; TIFFGetFieldDefaulted(tif, TIFFTAG_FILLORDER, &o); TIFFReadRawData(tif, o != order); diff --git a/tiff/tools/tiffmedian.c b/tiff/tools/tiffmedian.c index 6654cd6f..93a1741c 100644 --- a/tiff/tools/tiffmedian.c +++ b/tiff/tools/tiffmedian.c @@ -39,6 +39,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> @@ -48,10 +49,6 @@ # include <unistd.h> #endif -#ifdef NEED_LIBPORT -# include "libport.h" -#endif - #include "tiffio.h" #ifndef EXIT_SUCCESS @@ -82,7 +79,7 @@ typedef struct colorbox { int rmin, rmax; int gmin, gmax; int bmin, bmax; - uint32 total; + uint32_t total; } Colorbox; typedef struct { @@ -90,20 +87,20 @@ typedef struct { int entries[MAX_CMAP_SIZE][2]; } C_cell; -uint16 rm[MAX_CMAP_SIZE], gm[MAX_CMAP_SIZE], bm[MAX_CMAP_SIZE]; -int num_colors; -uint32 histogram[B_LEN][B_LEN][B_LEN]; -Colorbox *freeboxes; -Colorbox *usedboxes; -C_cell **ColorCells; -TIFF *in, *out; -uint32 rowsperstrip = (uint32) -1; -uint16 compression = (uint16) -1; -uint16 bitspersample = 1; -uint16 samplesperpixel; -uint32 imagewidth; -uint32 imagelength; -uint16 predictor = 0; +static uint16_t rm[MAX_CMAP_SIZE], gm[MAX_CMAP_SIZE], bm[MAX_CMAP_SIZE]; +static int num_colors; +static uint32_t histogram[B_LEN][B_LEN][B_LEN]; +static Colorbox *freeboxes; +static Colorbox *usedboxes; +static C_cell **ColorCells; +static TIFF *in, *out; +static uint32_t rowsperstrip = (uint32_t) -1; +static uint16_t compression = (uint16_t) -1; +static uint16_t bitspersample = 1; +static uint16_t samplesperpixel; +static uint32_t imagewidth; +static uint32_t imagelength; +static uint16_t predictor = 0; static void get_histogram(TIFF*, Colorbox*); static void splitbox(Colorbox*); @@ -123,10 +120,10 @@ int main(int argc, char* argv[]) { int i, dither = 0; - uint16 shortv, config, photometric; + uint16_t shortv, config, photometric; Colorbox *box_list, *ptr; float floatv; - uint32 longv; + uint32_t longv; int c; #if !HAVE_DECL_OPTARG extern int optind; @@ -158,9 +155,11 @@ main(int argc, char* argv[]) case 'h': usage(EXIT_SUCCESS); /*NOTREACHED*/ + break; case '?': usage(EXIT_FAILURE); /*NOTREACHED*/ + break; } if (argc - optind != 2) usage(EXIT_FAILURE); @@ -260,7 +259,7 @@ main(int argc, char* argv[]) CopyField(TIFFTAG_SUBFILETYPE, longv); CopyField(TIFFTAG_IMAGEWIDTH, longv); TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, (short)COLOR_DEPTH); - if (compression != (uint16)-1) { + if (compression != (uint16_t)-1) { TIFFSetField(out, TIFFTAG_COMPRESSION, compression); switch (compression) { case COMPRESSION_LZW: @@ -325,32 +324,41 @@ processCompressOptions(char* opt) return (1); } -char* stuff[] = { -"usage: tiffmedian [options] input.tif output.tif", -"where options are:", -" -r # make each strip have no more than # rows", -" -C # create a colormap with # entries", -" -f use Floyd-Steinberg dithering", -" -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 const char usage_info[] = +"Apply the median cut algorithm to an RGB TIFF file\n\n" +"usage: tiffmedian [options] input.tif output.tif\n" +"where options are:\n" +" -r # make each strip have no more than # rows\n" +" -C # create a colormap with # entries\n" +" -f use Floyd-Steinberg dithering\n" +"\n" +#ifdef LZW_SUPPORT +" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding\n" +/* " LZW options:" */ +" # set predictor value\n" +" For example, -c lzw:2 to get LZW-encoded data with horizontal differencing\n" +#endif +#ifdef ZIP_SUPPORT +" -c zip[:opts] compress output with deflate encoding\n" +/* " Deflate (ZIP) options:" */ +" # set predictor value\n" +#endif +#ifdef PACKBITS_SUPPORT +" -c packbits compress output with packbits encoding\n" +#endif +#if defined(LZW_SUPPORT) || defined(ZIP_SUPPORT) || defined(PACKBITS_SUPPORT) +" -c none use no compression algorithm on output\n" +#endif +"\n" +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; stuff[i] != NULL; i++) - fprintf(out, "%s\n", stuff[i]); + fprintf(out, "%s", usage_info); exit(code); } @@ -359,7 +367,7 @@ get_histogram(TIFF* in, Colorbox* box) { register unsigned char *inptr; register int red, green, blue; - register uint32 j, i; + register uint32_t j, i; unsigned char *inputline; inputline = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(in)); @@ -371,7 +379,7 @@ get_histogram(TIFF* in, Colorbox* box) box->rmax = box->gmax = box->bmax = -1; box->total = imagewidth * imagelength; - { register uint32 *ptr = &histogram[0][0][0]; + { register uint32_t *ptr = &histogram[0][0][0]; for (i = B_LEN*B_LEN*B_LEN; i-- > 0;) *ptr++ = 0; } @@ -411,7 +419,7 @@ static Colorbox * largest_box(void) { register Colorbox *p, *b; - register uint32 size; + register uint32_t size; b = NULL; size = 0; @@ -425,13 +433,13 @@ largest_box(void) static void splitbox(Colorbox* ptr) { - uint32 hist2[B_LEN]; + uint32_t hist2[B_LEN]; int first=0, last=0; register Colorbox *new; - register uint32 *iptr, *histp; + register uint32_t *iptr, *histp; register int i, j; register int ir,ig,ib; - register uint32 sum, sum1, sum2; + register uint32_t sum, sum1, sum2; enum { RED, GREEN, BLUE } axis; /* @@ -547,7 +555,7 @@ splitbox(Colorbox* ptr) static void shrinkbox(Colorbox* box) { - register uint32 *histp; + register uint32_t *histp; register int ir, ig, ib; if (box->rmax > box->rmin) { @@ -720,7 +728,7 @@ create_colorcell(int red, int green, int blue) static void map_colortable(void) { - register uint32 *histp = &histogram[0][0][0]; + register uint32_t *histp = &histogram[0][0][0]; register C_cell *cell; register int j, tmp, d2, dist; int ir, ig, ib, i; @@ -769,7 +777,7 @@ quant(TIFF* in, TIFF* out) { unsigned char *outline, *inputline; register unsigned char *outptr, *inptr; - register uint32 i, j; + register uint32_t i, j; register int red, green, blue; inputline = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(in)); @@ -824,8 +832,8 @@ quant_fsdither(TIFF* in, TIFF* out) short *thisline, *nextline; register unsigned char *outptr; register short *thisptr, *nextptr; - register uint32 i, j; - uint32 imax, jmax; + register uint32_t i, j; + uint32_t imax, jmax; int lastline, lastpixel; imax = imagelength - 1; diff --git a/tiff/tools/tiffset.c b/tiff/tools/tiffset.c index 75cf45c0..8c9e23c5 100644 --- a/tiff/tools/tiffset.c +++ b/tiff/tools/tiffset.c @@ -46,27 +46,25 @@ #define EXIT_FAILURE 1 #endif -static const char* usageMsg[] = { -"usage: tiffset [options] filename", -"where options are:", -" -s <tagname> [count] <value>... set the tag value", -" -u <tagname> to unset the tag", -" -d <dirno> set the directory", -" -sd <diroff> set the subdirectory", -" -sf <tagname> <filename> read the tag value from file (for ASCII tags only)", -" -h this help screen", -NULL -}; +static const char usageMsg[] = +"Set the value of a TIFF header to a specified value\n\n" +"usage: tiffset [options] filename\n" +"where options are:\n" +" -s <tagname> [count] <value>... set the tag value\n" +" -u <tagname> to unset the tag\n" +" -d <dirno> set the directory\n" +" -sd <diroff> set the subdirectory\n" +" -sf <tagname> <filename> read the tag value from file (for ASCII tags only)\n" +" -h this help screen\n" +; static void usage(int code) { - int i; FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr; fprintf(out, "%s\n\n", TIFFGetVersion()); - for (i = 0; usageMsg[i]; i++) - fprintf(out, "%s\n", usageMsg[i]); + fprintf(out, "%s", usageMsg); exit(code); } @@ -221,37 +219,37 @@ main(int argc, char* argv[]) switch (TIFFFieldDataType(fip)) { case TIFF_BYTE: for (i = 0; i < wc; i++) - ((uint8 *)array)[i] = atoi(argv[arg_index+i]); + ((uint8_t *)array)[i] = atoi(argv[arg_index + i]); break; case TIFF_SHORT: for (i = 0; i < wc; i++) - ((uint16 *)array)[i] = atoi(argv[arg_index+i]); + ((uint16_t *)array)[i] = atoi(argv[arg_index + i]); break; case TIFF_SBYTE: for (i = 0; i < wc; i++) - ((int8 *)array)[i] = atoi(argv[arg_index+i]); + ((int8_t *)array)[i] = atoi(argv[arg_index + i]); break; case TIFF_SSHORT: for (i = 0; i < wc; i++) - ((int16 *)array)[i] = atoi(argv[arg_index+i]); + ((int16_t *)array)[i] = atoi(argv[arg_index + i]); break; case TIFF_LONG: for (i = 0; i < wc; i++) - ((uint32 *)array)[i] = atol(argv[arg_index+i]); + ((uint32_t *)array)[i] = atol(argv[arg_index + i]); break; case TIFF_SLONG: case TIFF_IFD: for (i = 0; i < wc; i++) - ((int32 *)array)[i] = atol(argv[arg_index+i]); + ((int32_t *)array)[i] = atol(argv[arg_index + i]); break; case TIFF_LONG8: for (i = 0; i < wc; i++) - ((uint64 *)array)[i] = strtoll(argv[arg_index+i], (char **)NULL, 10); + ((uint64_t *)array)[i] = strtoll(argv[arg_index + i], (char **)NULL, 10); break; case TIFF_SLONG8: case TIFF_IFD8: for (i = 0; i < wc; i++) - ((int64 *)array)[i] = strtoll(argv[arg_index+i], (char **)NULL, 10); + ((int64_t *)array)[i] = strtoll(argv[arg_index + i], (char **)NULL, 10); break; case TIFF_DOUBLE: for (i = 0; i < wc; i++) @@ -276,10 +274,10 @@ main(int argc, char* argv[]) || TIFFFieldTag(fip) == TIFFTAG_DOTRANGE) { if (TIFFFieldDataType(fip) == TIFF_BYTE) { ret = TIFFSetField(tiff, TIFFFieldTag(fip), - ((uint8 *)array)[0], ((uint8 *)array)[1]); + ((uint8_t *)array)[0], ((uint8_t *)array)[1]); } else if (TIFFFieldDataType(fip) == TIFF_SHORT) { ret = TIFFSetField(tiff, TIFFFieldTag(fip), - ((uint16 *)array)[0], ((uint16 *)array)[1]); + ((uint16_t *)array)[0], ((uint16_t *)array)[1]); } } else { ret = TIFFSetField(tiff, TIFFFieldTag(fip), @@ -367,7 +365,7 @@ main(int argc, char* argv[]) fclose( fp ); if(TIFFFieldPassCount( fip )) { - ret = TIFFSetField( tiff, TIFFFieldTag(fip), (uint16)len, text ); + ret = TIFFSetField(tiff, TIFFFieldTag(fip), (uint16_t)len, text ); } else { ret = TIFFSetField( tiff, TIFFFieldTag(fip), text ); } diff --git a/tiff/tools/tiffsplit.c b/tiff/tools/tiffsplit.c index 43b6fdc1..296d6bf9 100644 --- a/tiff/tools/tiffsplit.c +++ b/tiff/tools/tiffsplit.c @@ -23,6 +23,7 @@ */ #include "tif_config.h" +#include "libport.h" #include <stdio.h> #include <stdlib.h> @@ -37,10 +38,6 @@ #define EXIT_FAILURE 1 #endif -#ifndef HAVE_GETOPT -extern int getopt(int argc, char * const argv[], const char *optstring); -#endif - #define CopyField(tag, v) \ if (TIFFGetField(in, tag, &v)) TIFFSetField(out, tag, v) #define CopyField2(tag, v1, v2) \ @@ -64,40 +61,46 @@ main(int argc, char* argv[]) { TIFF *in, *out; - if (argc < 2) { - fprintf(stderr, "%s\n\n", TIFFGetVersion()); - fprintf(stderr, "usage: tiffsplit input.tif [prefix]\n"); + if (argc < 2 || argc > 3) { + fprintf(stderr, "%s\n\n", TIFFGetVersion()); + fprintf(stderr, "Split a multi-image TIFF into single-image TIFF files\n\n"); + fprintf(stderr, "usage: tiffsplit input.tif [prefix]\n"); return (EXIT_FAILURE); } if (argc > 2) { strncpy(fname, argv[2], sizeof(fname)); fname[sizeof(fname) - 1] = '\0'; } + in = TIFFOpen(argv[1], "r"); - if (in != NULL) { - do { - size_t path_len; - char *path; - - newfilename(); + if (in == NULL) { + return EXIT_FAILURE; + } - path_len = strlen(fname) + sizeof(TIFF_SUFFIX); - path = (char *) _TIFFmalloc(path_len); - strncpy(path, fname, path_len); - path[path_len - 1] = '\0'; - strncat(path, TIFF_SUFFIX, path_len - strlen(path) - 1); - out = TIFFOpen(path, TIFFIsBigEndian(in)?"wb":"wl"); - _TIFFfree(path); + do { + size_t path_len; + char *path; - if (out == NULL) - return (EXIT_FAILURE); - if (!tiffcp(in, out)) - return (EXIT_FAILURE); - TIFFClose(out); - } while (TIFFReadDirectory(in)); - (void) TIFFClose(in); - } - return (EXIT_SUCCESS); + newfilename(); + + path_len = strlen(fname) + sizeof(TIFF_SUFFIX); + path = (char *) _TIFFmalloc(path_len); + strncpy(path, fname, path_len); + path[path_len - 1] = '\0'; + strncat(path, TIFF_SUFFIX, path_len - strlen(path) - 1); + out = TIFFOpen(path, TIFFIsBigEndian(in)?"wb":"wl"); + _TIFFfree(path); + + if (out == NULL) + return (EXIT_FAILURE); + if (!tiffcp(in, out)) + return (EXIT_FAILURE); + TIFFClose(out); + } while (TIFFReadDirectory(in)); + + (void) TIFFClose(in); + + return (EXIT_SUCCESS); } static void @@ -162,11 +165,11 @@ newfilename(void) static int tiffcp(TIFF* in, TIFF* out) { - uint16 bitspersample, samplesperpixel, compression, shortv, *shortav; - uint32 w, l; + uint16_t bitspersample, samplesperpixel, compression, shortv, *shortav; + uint32_t w, l; float floatv; char *stringv; - uint32 longv; + uint32_t longv; CopyField(TIFFTAG_SUBFILETYPE, longv); CopyField(TIFFTAG_TILEWIDTH, w); @@ -177,7 +180,7 @@ tiffcp(TIFF* in, TIFF* out) CopyField(TIFFTAG_SAMPLESPERPIXEL, samplesperpixel); CopyField(TIFFTAG_COMPRESSION, compression); if (compression == COMPRESSION_JPEG) { - uint32 count = 0; + uint32_t count = 0; void *table = NULL; if (TIFFGetField(in, TIFFTAG_JPEGTABLES, &count, &table) && count > 0 && table) { @@ -204,10 +207,10 @@ tiffcp(TIFF* in, TIFF* out) CopyField(TIFFTAG_TILEDEPTH, longv); CopyField(TIFFTAG_SAMPLEFORMAT, shortv); CopyField2(TIFFTAG_EXTRASAMPLES, shortv, shortav); - { uint16 *red, *green, *blue; + { uint16_t *red, *green, *blue; CopyField3(TIFFTAG_COLORMAP, red, green, blue); } - { uint16 shortv2; + { uint16_t shortv2; CopyField2(TIFFTAG_PAGENUMBER, shortv, shortv2); } CopyField(TIFFTAG_ARTIST, stringv); @@ -240,7 +243,7 @@ cpStrips(TIFF* in, TIFF* out) if (buf) { tstrip_t s, ns = TIFFNumberOfStrips(in); - uint64 *bytecounts; + uint64_t *bytecounts; if (!TIFFGetField(in, TIFFTAG_STRIPBYTECOUNTS, &bytecounts)) { fprintf(stderr, "tiffsplit: strip byte counts are missing\n"); @@ -248,7 +251,7 @@ cpStrips(TIFF* in, TIFF* out) return (0); } for (s = 0; s < ns; s++) { - if (bytecounts[s] > (uint64)bufsize) { + if (bytecounts[s] > (uint64_t)bufsize) { buf = (unsigned char *)_TIFFrealloc(buf, (tmsize_t)bytecounts[s]); if (!buf) return (0); @@ -274,7 +277,7 @@ cpTiles(TIFF* in, TIFF* out) if (buf) { ttile_t t, nt = TIFFNumberOfTiles(in); - uint64 *bytecounts; + uint64_t *bytecounts; if (!TIFFGetField(in, TIFFTAG_TILEBYTECOUNTS, &bytecounts)) { fprintf(stderr, "tiffsplit: tile byte counts are missing\n"); @@ -282,7 +285,7 @@ cpTiles(TIFF* in, TIFF* out) return (0); } for (t = 0; t < nt; t++) { - if (bytecounts[t] > (uint64) bufsize) { + if (bytecounts[t] > (uint64_t) bufsize) { buf = (unsigned char *)_TIFFrealloc(buf, (tmsize_t)bytecounts[t]); if (!buf) return (0); |