diff options
author | Sam James <sam@gentoo.org> | 2022-09-21 14:18:08 +0100 |
---|---|---|
committer | Sam James <sam@gentoo.org> | 2022-10-02 04:31:25 +0100 |
commit | a529111f77ff46f4836fe7312e70953bc16587cf (patch) | |
tree | 9dc3924cb1a6ef3ef853b7bb45f735365e0b4e6d /tiff/tools/raw2tiff.c | |
parent | Import Ghostscript 9.56.1 (diff) | |
download | ghostscript-gpl-patches-ghostscript-10.tar.gz ghostscript-gpl-patches-ghostscript-10.tar.bz2 ghostscript-gpl-patches-ghostscript-10.zip |
Import Ghostscript 10.0ghostscript-10.0ghostscript-10
Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'tiff/tools/raw2tiff.c')
-rw-r--r-- | tiff/tools/raw2tiff.c | 238 |
1 files changed, 118 insertions, 120 deletions
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); } |