diff options
author | Bob Friesenhahn <bfriesen@simple.dallas.tx.us> | 2010-06-11 22:25:36 +0000 |
---|---|---|
committer | Bob Friesenhahn <bfriesen@simple.dallas.tx.us> | 2010-06-11 22:25:36 +0000 |
commit | d30823e3829de75a5eb4f6d4729c3a5c51ca2dd3 (patch) | |
tree | de057a01d0002c3b8f2e4b9a63ed4766d9472be9 | |
parent | a6ea66c2afa6c9d0ac600f03c7ad1c44436a5608 (diff) | |
download | libtiff-git-d30823e3829de75a5eb4f6d4729c3a5c51ca2dd3.tar.gz |
* tools/tiffcrop.c: Applied patch from Richard Nolde: Corrected
European page size dimensions. Added an option to allow the user
to specify a custom page size on the command line. Fix the case
where a page size specified with a fractional part was being
coerced to an integer by retyping the variables that define the
paper size.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | man/tiffcrop.1 | 1140 | ||||
-rw-r--r-- | tools/tiffcrop.c | 202 |
3 files changed, 746 insertions, 603 deletions
@@ -1,5 +1,12 @@ 2010-06-11 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> + * tools/tiffcrop.c: Applied patch from Richard Nolde: Corrected + European page size dimensions. Added an option to allow the user + to specify a custom page size on the command line. Fix the case + where a page size specified with a fractional part was being + coerced to an integer by retyping the variables that define the + paper size. + * html/index.html: Update for the 3.9.3 release. * tools/tiffcp.c (tiffcp): Applied Tom Lane's patch to reject diff --git a/man/tiffcrop.1 b/man/tiffcrop.1 index 5b8e4e52..f01b17d9 100644 --- a/man/tiffcrop.1 +++ b/man/tiffcrop.1 @@ -1,569 +1,571 @@ -.\" $Id: tiffcrop.1,v 1.5 2009-09-24 21:57:11 bfriesen Exp $
-.\" tiffcrop -- a port of tiffcp.c extended to include extended processing of images
-.\"
-.\" Original code:
-.\"
-.\" Copyright (c) 1988-1997 Sam Leffler
-.\" Copyright (c) 1991-1997 Silicon Graphics, Inc.
-.\"
-.\" Permission to use, copy, modify, distribute, and sell this software and
-.\" its documentation for any purpose is hereby granted without fee, provided
-.\" 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.
-.\"
-.\" Additional code Copyright (c) 2006-2009 Richard Nolde
-.\" Lasted Updated 9/2009
-.\" .if n .po 0
-.TH "TIFFCROP" "1" "December, 2008" "libtiff" ""
-.SH "NAME"
-tiffcrop \- select, copy, crop, convert, extract, and/or process one or more
-.SM TIFF
-files.
-.SH "SYNOPSIS"
-.B tiffcrop
-[
-.I options
-]
-.I "src1.tif ... srcN.tif dst.tif"
-.SH "DESCRIPTION"
-.I Tiffcrop
-processes one or more files created according
-to the Tag Image File Format, Revision 6.0, specification
-into one or more
-.SM TIFF
-file(s).
-.I Tiffcrop
-is most often used to extract portions of an image for processing
-with bar code recognizer or OCR software when that software cannot
-restrict the region of interest to a specific portion of the image
-or to improve efficiency when the regions of interest must be rotated.
-It can also be used to subdivide all or part of a processed image into
-smaller sections and export individual images or sections of images
-as separate files or separate images within one or more files derived
-from the original input image or images.
-.PP
-The available functions can be grouped broadly into three classes:
-.IP
-Those that select individual images or sections of images from the input files.
-The options \-N for sequences or lists of individual images in the input files,
-\-Z for zones, \-z for regions, \-X and \-Y for fixed sized selections,
-\-m for margins, \-U for units, and \-E for edge reference provide a variety of
-ways to specify portions of the input image.
-.IP
-Those that allow the individual images or selections to be exported to one or
-more output files in different groupings and control the organization of the
-data in the output images. The options \-P for page size grouping, \-S for
-subdivision into columns and rows and \-e for export mode options that produce
-one or more files from each input image. The options \-r, \-s, \-t, \-w control
-strip and tile format and sizes while \-B \-L \-c \-f modify the endian addressing
-scheme, the compression options, and the bit fill sequence of images as they
-are written.
-.IP
-Those that perform some action on each image that is selected from the input file.
-The options include \-R for rotate, \-I for inversion of the photometric
-interpretation and/or data values, and \-F to flip (mirror) the image horizontally
-or vertically.
-.PP
-
-Functions are applied to the input image(s) in the following order:
-cropping, fixed area extraction, zone and region extraction,
-inversion, mirroring, rotation.
-.PP
-Functions are applied to the output image(s) in the following order:
-export mode options for grouping zones, regions, or images into
-one or more files,
-.I or
-row and column divisions with output margins,
-.I or
-page size divisions with page orientation options.
-.PP
-Finally, strip, tile, byte order, output resolution, and compression options are
-applied to all output images.
-.PP
-The output file(s) may be organized and compressed using a different
-algorithm from the input files.
-By default,
-.I tiffcrop
-will copy all the understood tags in a
-.SM TIFF
-directory of an input file to the associated directory in the output file.
-Options can be used to force the resultant image to be written as strips
-or tiles of data, respectively.
-.PP
-.I Tiffcrop
-can be used to reorganize the storage characteristics of data
-in a file, and to reorganize, extract, rotate, and otherwise
-process the image data as specified at the same time whereas
-tiffcp does not alter the image data within the file.
-.PP
-Using the options for selecting individual input images and the
-options for exporting images and/or segments defined as zones or
-regions of each input image,
-.I tiffcrop
-can perform the functions of tiffcp and tiffsplit in a single pass
-while applying multiple operations to individual selections or images.
-.PP
-.SH "OPTIONS"
-.TP
-.B \-h
-Display the syntax summary for tiffcrop.
-.TP
-.B \-v
-Report the current version and last modification date for tiffcrop.
-.TP
-.B \-N odd|even|#,#\-#,#|last
-Specify one or more series or range(s) of images within each file to process.
-The words
-.B odd
-or
-.B even
-may be used to specify all odd or even numbered images counting from one.
-Note that internally, TIFF images are numbered from zero rather than one
-but since this convention is not obvious to most users, tiffcrop used 1
-to specifiy the first image in a multipage file. The word
-.B 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.
-Ranges of images may be specified with a dash and multiple sets
-can be indicated by joining them in a comma\-separated list. eg. use
-.B \-N 1,5\-7,last
-to process the 1st, 5th through 7th, and final image in the file.
-.TP
-.B \-E top|bottom|left|right
-Specify the top, bottom, left, or right edge as the reference from
-which to calcuate the width and length of crop regions or sequence
-of postions for zones. When used with the \-e option for exporting
-zones or regions, the reference edge determines how composite images
-are arranged. Using \-E left or right causes successive zones or
-regions to be merged horizontally whereas using \-E top or bottom
-causes successive zones or regions to be arranged vertically. This
-option has no effect on export layout when multiple zones or regions
-are not being exported to composite images. Edges may be abbreviated
-to the first letter.
-.TP
-.B \-e combined|divided|image|multiple|separate
-Specify the export mode for images and selections from input images.
-The final filename on the command line is considered to be the
-destination file or filename stem for automatically generated
-sequences of files. Modes may be abbreviated to the first letter.
-.IP
-combined All images and selections are written to a single file with
-multiple selections from one image combined into a single image (default)
-.IP
-divided All images and selections are written to a single file
-with each selection from one image written to a new image
-.IP
-image Each input image is written to a new file (numeric filename sequence)
-with multiple selections from the image combined into one image
-.IP
-multiple Each input image is written to a new file (numeric filename sequence)
-with each selection from the image written to a new image
-.IP
-separate Individual selections from each image are written to separate files
-.TP
-.B \-U in|cm|px
-Specify the type of units to apply to dimensions for margins and
-crop regions for input and output images. Inches or centimeters
-are converted to pixels using the resolution unit specified in the
-TIFF file (which defaults to inches if not specified in the IFD).
-.TP
-.B \-m #,#,#,#
-Specify margins to be removed from the input image. The order must
-be top, left, bottom, right with only commas separating the elements
-of the list. Margins are scaled according to the current units and
-removed before any other extractions are computed..
-.TP
-.B \-X #
-Set the horizontal (X\-axis) dimension of a region to extract relative to
-the specified origin reference. If the origin is the top or bottom
-edge, the X axis value will be assumed to start at the left edge.
-.TP
-.B \-Y #
-Set the vertical (Y\-axis) dimension of a region to extract relative to
-the specified origin reference. If the origin is the left or right
-edge, the Y axis value will be assumed to start at the top.
-.TP
-.B \-Z #:#,#:#
-Specify zones of the image designated as position X of Y equal sized portions
-measured from the reference edge, eg 1:3 would be first third of the
-image starting from the reference edge minus any margins specified
-for the confining edges. Multiple zones can be specified as a comma
-separated list but they must reference the same edge. To extract the
-top quarter and the bottom third of an image you would use
-.B \-Z 1:4,3:3.
-.TP
-.B \-z x1,y1,x2,y2: ... :xN,yN,xN+1,yN+1
-Specify a series of coordinates to define regions for processing and exporting.
-The coordinates represent the top left and lower right corners of each region
-in the current units, eg inch, cm, or pixels. Pixels are counted from one to
-width or height and inches or cm are calculated from image resolution data.
-
-Each colon delimited series of four values represents the horizontal and vertical
-offsets from the top and left edges of the image, regardless of the edge specified
-with the \-E option. The first and third values represent the horizontal offsets of
-the corner points from the left edge while the second and fourth values represent
-the vertical offsets from the top edge.
-.TP
-.B \-F horiz|vert
-Flip, ie mirror, the image or extracted region horizontally or vertically.
-.TP
-.B \-R 90|180|270
-Rotate the image or extracted region 90, 180, or 270 degrees clockwise.
-.TP
-.B \\-I [black|white|data|both]
-Invert color space, eg dark to light for bilevel and grayscale images.
-This can be used to modify negative images to positive or to correct
-images that have the PHOTOMETRIC_INTERPRETATIN tag set incorrectly.
-If the value is black or white, the PHOTOMETRIC_INTERPRETATION tag is set to
-MinIsBlack or MinIsWhite, without altering the image data. If the argument
-is data or both, the data values of the image are modified. Specifying both
-inverts the data and the PHOTOMETRIC_INTERPRETATION tag, whereas using data
-inverts the data but not the PHOTOMETRIC_INTERPRETATION tag.
-No support for modifying the color space of color images in this release.
-.TP
-.B \-H #
-Set the horizontal resolution of output images to #
-expressed in the current units.
-.TP
-.B \-V #
-Set the vertical resolution of the output images to #
-expressed in the current units.
-.TP
-.B \-J #
-Set the horizontal margin of an output page size to #
-expressed in the current units when sectioning image into columns x rows
-subimages using the \-S cols:rows option.
-.TP
-.B \-K #
-Set the vertical margin of an output page size to #
-expressed in the current units when sectioning image into columns x rows
-submiages using the \-S cols:rows option.
-.TP
-.B \-O portrait|landscape|auto
-Set the output orientation of the pages or sections.
-Auto will use the arrangement that requires the fewest pages.
-This option is only meaningful in conjunction with the -P
-option to format an image to fit on a specific paper size.
-.TP
-.B \-P page
-Format the output images to fit on page size paper. Use
-\-P list to show the supported page sizes and dimensions.
-.TP
-.B \-S cols:rows
-Divide each image into cols across and rows down equal sections.
-.TP
-.B \-B
-Force output to be written with Big\-Endian byte order.
-This option only has an effect when the output file is created or
-overwritten and not when it is appended to.
-.TP
-.B \-C
-Suppress the use of ``strip chopping'' when reading images
-that have a single strip/tile of uncompressed data.
-.TP
-.B \-c
-Specify the compression to use for data written to the output file:
-.B none
-for no compression,
-.B packbits
-for PackBits compression,
-.B lzw
-for Lempel\-Ziv & Welch compression,
-.B jpeg
-for baseline JPEG compression.
-.B zip
-for Deflate compression,
-.B g3
-for CCITT Group 3 (T.4) compression,
-and
-.B g4
-for CCITT Group 4 (T.6) compression.
-By default
-.I tiffcrop
-will compress data according to the value of the
-.I Compression
-tag found in the source file.
-.IP
-The
-.SM CCITT
-Group 3 and Group 4 compression algorithms can only
-be used with bilevel data.
-.IP
-Group 3 compression can be specified together with several
-T.4\-specific options:
-.B 1d
-for 1\-dimensional encoding,
-.B 2d
-for 2\-dimensional encoding,
-and
-.B fill
-to force each encoded scanline to be zero\-filled so that the
-terminating EOL code lies on a byte boundary.
-Group 3\-specific options are specified by appending a ``:''\-separated
-list to the ``g3'' option; e.g.
-.B "\-c g3:2d:fill"
-to get 2D\-encoded data with byte\-aligned EOL codes.
-.IP
-.SM LZW
-compression can be specified together with a
-.I predictor
-value.
-A predictor value of 2 causes
-each scanline of the output image to undergo horizontal
-differencing before it is encoded; a value
-of 1 forces each scanline to be encoded without differencing.
-LZW\-specific options are specified by appending a ``:''\-separated
-list to the ``lzw'' option; e.g.
-.B "\-c lzw:2"
-for
-.SM LZW
-compression with horizontal differencing.
-.TP
-.B \-f
-Specify the bit fill order to use in writing output data.
-By default,
-.I tiffcrop
-will create a new file with the same fill order as the original.
-Specifying
-.B "\-f lsb2msb"
-will force data to be written with the FillOrder tag set to
-.SM LSB2MSB,
-while
-.B "\-f msb2lsb"
-will force data to be written with the FillOrder tag set to
-.SM MSB2LSB.
-.TP
-.B \-i
-Ignore non\-fatal read errors and continue processing of the input file.
-.TP
-.B \-l
-Specify the length of a tile (in pixels).
-.I Tiffcrop
-attempts to set the tile dimensions so
-that no more than 8 kilobytes of data appear in a tile.
-.TP
-.B \-L
-Force output to be written with Little\-Endian byte order.
-This option only has an effect when the output file is created or
-overwritten and not when it is appended to.
-.TP
-.B \-M
-Suppress the use of memory\-mapped files when reading images.
-.TP
-.B \-p
-Specify the planar configuration to use in writing image data
-that has more than one sample per pixel.
-By default,
-.I tiffcrop
-will create a new file with the same planar configuration as
-the original.
-Specifying
-.B "\-p contig"
-will force data to be written with multi\-sample data packed
-together, while
-.B "\-p separate"
-will force samples to be written in separate planes.
-.TP
-.B \-r
-Specify the number of rows (scanlines) in each strip of data
-written to the output file.
-By default (or when value
-.B 0
-is specified),
-.I tiffcrop
-attempts to set the rows/strip that no more than 8 kilobytes of
-data appear in a strip. If you specify the special value
-.B \-1
-it will results in infinite number of the rows per strip. The entire image
-will be the one strip in that case.
-.TP
-.B \-s
-Force the output file to be written with data organized in strips
-(rather than tiles).
-.TP
-.B \-t
-Force the output file to be written with data organized in tiles
-(rather than strips).
-.TP
-.B \-w
-Specify the width of a tile (in pixels).
-.I tiffcrop
-attempts to set the tile dimensions so
-that no more than 8 kilobytes of data appear in a tile.
-.I tiffcrop
-attempts to set the tile dimensions so
-that no more than 8 kilobytes of data appear in a tile.
-.TP
-Debug and dump facility
-.B \-D opt1:value1,opt2:value2,opt3:value3:opt4:value4
-Display program progress and/or dump raw data to non\-TIFF files.
-Options include the following and must be joined as a comma
-separated list. The use of this option is generally limited to
-program debugging and development of future options. An equal sign
-may be substituted for the colon in option:value pairs.
-.IP
-debug:N Display limited program progress indicators where larger N
-increase the level of detail.
-.IP
-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.
-.IP
-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.
-.IP
-input:full\-path\-to\-directory/input\-dumpname
-.IP
-output:full\-path\-to\-directory/output\-dumpname
-.IP
-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.
-.IP
-Note: Tiffcrop may be compiled with -DDEVELMODE to enable additional very
- low level debug reporting.
-.SH "EXAMPLES"
-The following concatenates two files and writes the result using
-.SM LZW
-encoding:
-.RS
-.nf
-tiffcrop \-c lzw a.tif b.tif result.tif
-.fi
-.RE
-.PP
-To convert a G3 1d\-encoded
-.SM TIFF
-to a single strip of G4\-encoded data the following might be used:
-.RS
-.nf
-tiffcrop \-c g4 \-r 10000 g3.tif g4.tif
-.fi
-.RE
-(1000 is just a number that is larger than the number of rows in
-the source file.)
-
-To extract a selected set of images from a multi\-image TIFF file
-use the \-N option described above. Thus, to copy the 1st and 3rd
-images of image file "album.tif" to "result.tif":
-.RS
-.nf
-tiffcrop \-N 1,3 album.tif result.tif
-.fi
-.RE
-.PP
-Invert a bilevel image scan of a microfilmed document and crop off margins of
-0.25 inches on the left and right, 0.5 inch on the top, and 0.75 inch on the
-bottom. From the remaining portion of the image, select the second and third
-quarters, ie, one half of the area left from the center to each margin.
-.RS
-tiffcrop \-U in \-m 0.5,0.25,0.75,0.25 \-E left \-Z 2:4,3:4 \-I both MicrofilmNegative.tif MicrofilmPostiveCenter.tif
-.fi
-.RE
-.PP
-Extract only the final image of a large Architectural E sized
-multipage TIFF file and rotate it 90 degrees clockwise while
-reformatting the output to fit on tabloid sized sheets with one
-quarter of an inch on each side:
-.RS
-tiffcrop \-N last \-R 90 \-O auto \-P tabloid \-U in \-J 0.25 \-K 0.25 \-H 300 \-V 300 Big\-PlatMap.tif BigPlatMap\-Tabloid.tif
-.fi
-.RE
-The output images will have a specified resolution of 300 dpi in both
-directions. The orientation of each page will be determined by whichever
-choice requires the fewest pages. To specify a specific orientation, use
-the portrait or landscape option. The paper size option does not resample
-the image. It breaks each original image into a series of smaller images
-that will fit on the target paper size at the specified resolution.
-.fi
-.RE
-.PP
-Extract two regions 2048 pixels wide by 2048 pixels high from each page of
-a multi\-page input file and write each region to a separate output file.
-.RS
-tiffcrop \-U px \-z 1,1,2048,2048:1,2049,2048,4097 \-e separate CheckScans.tiff Check
-.fi
-.RE
-The output file names will use the stem Check with a numeric suffix which is
-incremented for each region of each image, eg Check\-001.tiff, Check\-002.tiff ...
-Check\-NNN.tiff. To produce a unique file for each page of the input image
-with one new image for each region of the input image on that page, change
-the export option to \-e multiple.
-
-.SH "NOTES"
-.PP
-In general, bilevel, grayscale, palette and RGB(A) data with bit depths
-from 1 to 32 bits should work in both interleaved and separate plane
-formats. Unlike tiffcp, tiffcrop can read and write tiled images with
-bits per sample that are not a multiple of 8 in both interleaved and
-separate planar format. Floating point data types are supported at
-bit depts of 16, 24, 32 and 64 bits per sample.
-.PP
-Not all images can be converted from one compression scheme to another.
-Data with some photometric interpretations and/or bit depths are tied to
-specific compression schemes and vice-versa, e.g. Group 3/4 compression
-is only usable for bilevel data. JPEG compression is only useable on 8
-bit per sample data (or 12 bit if
-.I LibTIFF
-was compiled with 12 bit JPEG support). Support for OJPEG compressed
-images is problematic at best. Since OJPEG compression is no longer
-supported for writing images with LibTIFF, these images will be updated
-to the newer JPEG compression when they are copied or processed. This
-may cause the image to appear color shifted or distorted after conversion.
-In some cases, it is possible to remove the original compression from
-image data using the option -cnone.
-.PP
-Tiffcrop does not currently provide options to up or downsample data to
-different bit depths or convert data from one photometric interpretation
-to another, e.g. 16 bits per sample to 8 bits per sample or RGB to grayscale.
-.PP
-Tiffcrop is very loosely derived from code in
-.I tiffcp
-with extensive modifications and additions to support the selection of input
-images and regions and the exporting of them to one or more output files in
-various groupings. The image manipulation routines are entirely new and
-additional ones may be added in the future. It will handle tiled images with
-bit depths that are not a multiple of eight that tiffcp may refuse to read.
-.PP
-.I Tiffcrop
-was designed to handle large files containing many moderate sized images
-with memory usage that is independent of the number of images in the file.
-In order to support compression modes that are not based on individual
-scanlines, e.g. JPEG, it now reads images by strip or tile rather than by
-indvidual scanlines. In addition to the memory required by the input and
-output buffers associated with
-.I LibTIFF
-one or more buffers at least as large as the largest image to be read are
-required. The design favors large volume document processing uses over
-scientific or graphical manipulation of large datasets as might be found
-in research or remote sensing scenarios.
-.SH "SEE ALSO"
-.BR pal2rgb (1),
-.BR tiffinfo (1),
-.BR tiffcmp (1),
-.BR tiffcp (1),
-.BR tiffmedian (1),
-.BR tiffsplit (1),
-.BR libtiff (3TIFF)
-.PP
-Libtiff library home page:
-.BR http://www.remotesensing.org/libtiff/
-
+.\" $Id: tiffcrop.1,v 1.6 2010-06-11 22:25:36 bfriesen Exp $ +.\" tiffcrop -- a port of tiffcp.c extended to include extended processing of images +.\" +.\" Original code: +.\" +.\" Copyright (c) 1988-1997 Sam Leffler +.\" Copyright (c) 1991-1997 Silicon Graphics, Inc. +.\" +.\" Permission to use, copy, modify, distribute, and sell this software and +.\" its documentation for any purpose is hereby granted without fee, provided +.\" 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. +.\" +.\" Additional code Copyright (c) 2006-2009 Richard Nolde +.\" Lasted Updated 9/2009 +.\" .if n .po 0 +.TH "TIFFCROP" "1" "December, 2008" "libtiff" "" +.SH "NAME" +tiffcrop \- select, copy, crop, convert, extract, and/or process one or more +.SM TIFF +files. +.SH "SYNOPSIS" +.B tiffcrop +[ +.I options +] +.I "src1.tif ... srcN.tif dst.tif" +.SH "DESCRIPTION" +.I Tiffcrop +processes one or more files created according +to the Tag Image File Format, Revision 6.0, specification +into one or more +.SM TIFF +file(s). +.I Tiffcrop +is most often used to extract portions of an image for processing +with bar code recognizer or OCR software when that software cannot +restrict the region of interest to a specific portion of the image +or to improve efficiency when the regions of interest must be rotated. +It can also be used to subdivide all or part of a processed image into +smaller sections and export individual images or sections of images +as separate files or separate images within one or more files derived +from the original input image or images. +.PP +The available functions can be grouped broadly into three classes: +.IP +Those that select individual images or sections of images from the input files. +The options \-N for sequences or lists of individual images in the input files, +\-Z for zones, \-z for regions, \-X and \-Y for fixed sized selections, +\-m for margins, \-U for units, and \-E for edge reference provide a variety of +ways to specify portions of the input image. +.IP +Those that allow the individual images or selections to be exported to one or +more output files in different groupings and control the organization of the +data in the output images. The options \-P for page size grouping, \-S for +subdivision into columns and rows and \-e for export mode options that produce +one or more files from each input image. The options \-r, \-s, \-t, \-w control +strip and tile format and sizes while \-B \-L \-c \-f modify the endian addressing +scheme, the compression options, and the bit fill sequence of images as they +are written. +.IP +Those that perform some action on each image that is selected from the input file. +The options include \-R for rotate, \-I for inversion of the photometric +interpretation and/or data values, and \-F to flip (mirror) the image horizontally +or vertically. +.PP + +Functions are applied to the input image(s) in the following order: +cropping, fixed area extraction, zone and region extraction, +inversion, mirroring, rotation. +.PP +Functions are applied to the output image(s) in the following order: +export mode options for grouping zones, regions, or images into +one or more files, +.I or +row and column divisions with output margins, +.I or +page size divisions with page orientation options. +.PP +Finally, strip, tile, byte order, output resolution, and compression options are +applied to all output images. +.PP +The output file(s) may be organized and compressed using a different +algorithm from the input files. +By default, +.I tiffcrop +will copy all the understood tags in a +.SM TIFF +directory of an input file to the associated directory in the output file. +Options can be used to force the resultant image to be written as strips +or tiles of data, respectively. +.PP +.I Tiffcrop +can be used to reorganize the storage characteristics of data +in a file, and to reorganize, extract, rotate, and otherwise +process the image data as specified at the same time whereas +tiffcp does not alter the image data within the file. +.PP +Using the options for selecting individual input images and the +options for exporting images and/or segments defined as zones or +regions of each input image, +.I tiffcrop +can perform the functions of tiffcp and tiffsplit in a single pass +while applying multiple operations to individual selections or images. +.PP +.SH "OPTIONS" +.TP +.B \-h +Display the syntax summary for tiffcrop. +.TP +.B \-v +Report the current version and last modification date for tiffcrop. +.TP +.B \-N odd|even|#,#\-#,#|last +Specify one or more series or range(s) of images within each file to process. +The words +.B odd +or +.B even +may be used to specify all odd or even numbered images counting from one. +Note that internally, TIFF images are numbered from zero rather than one +but since this convention is not obvious to most users, tiffcrop used 1 +to specifiy the first image in a multipage file. The word +.B 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. +Ranges of images may be specified with a dash and multiple sets +can be indicated by joining them in a comma\-separated list. eg. use +.B \-N 1,5\-7,last +to process the 1st, 5th through 7th, and final image in the file. +.TP +.B \-E top|bottom|left|right +Specify the top, bottom, left, or right edge as the reference from +which to calcuate the width and length of crop regions or sequence +of postions for zones. When used with the \-e option for exporting +zones or regions, the reference edge determines how composite images +are arranged. Using \-E left or right causes successive zones or +regions to be merged horizontally whereas using \-E top or bottom +causes successive zones or regions to be arranged vertically. This +option has no effect on export layout when multiple zones or regions +are not being exported to composite images. Edges may be abbreviated +to the first letter. +.TP +.B \-e combined|divided|image|multiple|separate +Specify the export mode for images and selections from input images. +The final filename on the command line is considered to be the +destination file or filename stem for automatically generated +sequences of files. Modes may be abbreviated to the first letter. +.IP +combined All images and selections are written to a single file with +multiple selections from one image combined into a single image (default) +.IP +divided All images and selections are written to a single file +with each selection from one image written to a new image +.IP +image Each input image is written to a new file (numeric filename sequence) +with multiple selections from the image combined into one image +.IP +multiple Each input image is written to a new file (numeric filename sequence) +with each selection from the image written to a new image +.IP +separate Individual selections from each image are written to separate files +.TP +.B \-U in|cm|px +Specify the type of units to apply to dimensions for margins and +crop regions for input and output images. Inches or centimeters +are converted to pixels using the resolution unit specified in the +TIFF file (which defaults to inches if not specified in the IFD). +.TP +.B \-m #,#,#,# +Specify margins to be removed from the input image. The order must +be top, left, bottom, right with only commas separating the elements +of the list. Margins are scaled according to the current units and +removed before any other extractions are computed.. +.TP +.B \-X # +Set the horizontal (X\-axis) dimension of a region to extract relative to +the specified origin reference. If the origin is the top or bottom +edge, the X axis value will be assumed to start at the left edge. +.TP +.B \-Y # +Set the vertical (Y\-axis) dimension of a region to extract relative to +the specified origin reference. If the origin is the left or right +edge, the Y axis value will be assumed to start at the top. +.TP +.B \-Z #:#,#:# +Specify zones of the image designated as position X of Y equal sized portions +measured from the reference edge, eg 1:3 would be first third of the +image starting from the reference edge minus any margins specified +for the confining edges. Multiple zones can be specified as a comma +separated list but they must reference the same edge. To extract the +top quarter and the bottom third of an image you would use +.B \-Z 1:4,3:3. +.TP +.B \-z x1,y1,x2,y2: ... :xN,yN,xN+1,yN+1 +Specify a series of coordinates to define regions for processing and exporting. +The coordinates represent the top left and lower right corners of each region +in the current units, eg inch, cm, or pixels. Pixels are counted from one to +width or height and inches or cm are calculated from image resolution data. + +Each colon delimited series of four values represents the horizontal and vertical +offsets from the top and left edges of the image, regardless of the edge specified +with the \-E option. The first and third values represent the horizontal offsets of +the corner points from the left edge while the second and fourth values represent +the vertical offsets from the top edge. +.TP +.B \-F horiz|vert +Flip, ie mirror, the image or extracted region horizontally or vertically. +.TP +.B \-R 90|180|270 +Rotate the image or extracted region 90, 180, or 270 degrees clockwise. +.TP +.B \\-I [black|white|data|both] +Invert color space, eg dark to light for bilevel and grayscale images. +This can be used to modify negative images to positive or to correct +images that have the PHOTOMETRIC_INTERPRETATIN tag set incorrectly. +If the value is black or white, the PHOTOMETRIC_INTERPRETATION tag is set to +MinIsBlack or MinIsWhite, without altering the image data. If the argument +is data or both, the data values of the image are modified. Specifying both +inverts the data and the PHOTOMETRIC_INTERPRETATION tag, whereas using data +inverts the data but not the PHOTOMETRIC_INTERPRETATION tag. +No support for modifying the color space of color images in this release. +.TP +.B \-H # +Set the horizontal resolution of output images to # +expressed in the current units. +.TP +.B \-V # +Set the vertical resolution of the output images to # +expressed in the current units. +.TP +.B \-J # +Set the horizontal margin of an output page size to # +expressed in the current units when sectioning image into columns x rows +subimages using the \-S cols:rows option. +.TP +.B \-K # +Set the vertical margin of an output page size to # +expressed in the current units when sectioning image into columns x rows +submiages using the \-S cols:rows option. +.TP +.B \-O portrait|landscape|auto +Set the output orientation of the pages or sections. +Auto will use the arrangement that requires the fewest pages. +This option is only meaningful in conjunction with the -P +option to format an image to fit on a specific paper size. +.TP +.B \-P page +Format the output images to fit on page size paper. Use +\-P list to show the supported page sizes and dimensions. +You can define a custom page size by entering the width and length of the +page in the current units with the following format #.#x#.#. +.TP +.B \-S cols:rows +Divide each image into cols across and rows down equal sections. +.TP +.B \-B +Force output to be written with Big\-Endian byte order. +This option only has an effect when the output file is created or +overwritten and not when it is appended to. +.TP +.B \-C +Suppress the use of ``strip chopping'' when reading images +that have a single strip/tile of uncompressed data. +.TP +.B \-c +Specify the compression to use for data written to the output file: +.B none +for no compression, +.B packbits +for PackBits compression, +.B lzw +for Lempel\-Ziv & Welch compression, +.B jpeg +for baseline JPEG compression. +.B zip +for Deflate compression, +.B g3 +for CCITT Group 3 (T.4) compression, +and +.B g4 +for CCITT Group 4 (T.6) compression. +By default +.I tiffcrop +will compress data according to the value of the +.I Compression +tag found in the source file. +.IP +The +.SM CCITT +Group 3 and Group 4 compression algorithms can only +be used with bilevel data. +.IP +Group 3 compression can be specified together with several +T.4\-specific options: +.B 1d +for 1\-dimensional encoding, +.B 2d +for 2\-dimensional encoding, +and +.B fill +to force each encoded scanline to be zero\-filled so that the +terminating EOL code lies on a byte boundary. +Group 3\-specific options are specified by appending a ``:''\-separated +list to the ``g3'' option; e.g. +.B "\-c g3:2d:fill" +to get 2D\-encoded data with byte\-aligned EOL codes. +.IP +.SM LZW +compression can be specified together with a +.I predictor +value. +A predictor value of 2 causes +each scanline of the output image to undergo horizontal +differencing before it is encoded; a value +of 1 forces each scanline to be encoded without differencing. +LZW\-specific options are specified by appending a ``:''\-separated +list to the ``lzw'' option; e.g. +.B "\-c lzw:2" +for +.SM LZW +compression with horizontal differencing. +.TP +.B \-f +Specify the bit fill order to use in writing output data. +By default, +.I tiffcrop +will create a new file with the same fill order as the original. +Specifying +.B "\-f lsb2msb" +will force data to be written with the FillOrder tag set to +.SM LSB2MSB, +while +.B "\-f msb2lsb" +will force data to be written with the FillOrder tag set to +.SM MSB2LSB. +.TP +.B \-i +Ignore non\-fatal read errors and continue processing of the input file. +.TP +.B \-l +Specify the length of a tile (in pixels). +.I Tiffcrop +attempts to set the tile dimensions so +that no more than 8 kilobytes of data appear in a tile. +.TP +.B \-L +Force output to be written with Little\-Endian byte order. +This option only has an effect when the output file is created or +overwritten and not when it is appended to. +.TP +.B \-M +Suppress the use of memory\-mapped files when reading images. +.TP +.B \-p +Specify the planar configuration to use in writing image data +that has more than one sample per pixel. +By default, +.I tiffcrop +will create a new file with the same planar configuration as +the original. +Specifying +.B "\-p contig" +will force data to be written with multi\-sample data packed +together, while +.B "\-p separate" +will force samples to be written in separate planes. +.TP +.B \-r +Specify the number of rows (scanlines) in each strip of data +written to the output file. +By default (or when value +.B 0 +is specified), +.I tiffcrop +attempts to set the rows/strip that no more than 8 kilobytes of +data appear in a strip. If you specify the special value +.B \-1 +it will results in infinite number of the rows per strip. The entire image +will be the one strip in that case. +.TP +.B \-s +Force the output file to be written with data organized in strips +(rather than tiles). +.TP +.B \-t +Force the output file to be written with data organized in tiles +(rather than strips). +.TP +.B \-w +Specify the width of a tile (in pixels). +.I tiffcrop +attempts to set the tile dimensions so +that no more than 8 kilobytes of data appear in a tile. +.I tiffcrop +attempts to set the tile dimensions so +that no more than 8 kilobytes of data appear in a tile. +.TP +Debug and dump facility +.B \-D opt1:value1,opt2:value2,opt3:value3:opt4:value4 +Display program progress and/or dump raw data to non\-TIFF files. +Options include the following and must be joined as a comma +separated list. The use of this option is generally limited to +program debugging and development of future options. An equal sign +may be substituted for the colon in option:value pairs. +.IP +debug:N Display limited program progress indicators where larger N +increase the level of detail. +.IP +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. +.IP +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. +.IP +input:full\-path\-to\-directory/input\-dumpname +.IP +output:full\-path\-to\-directory/output\-dumpname +.IP +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. +.IP +Note: Tiffcrop may be compiled with -DDEVELMODE to enable additional very + low level debug reporting. +.SH "EXAMPLES" +The following concatenates two files and writes the result using +.SM LZW +encoding: +.RS +.nf +tiffcrop \-c lzw a.tif b.tif result.tif +.fi +.RE +.PP +To convert a G3 1d\-encoded +.SM TIFF +to a single strip of G4\-encoded data the following might be used: +.RS +.nf +tiffcrop \-c g4 \-r 10000 g3.tif g4.tif +.fi +.RE +(1000 is just a number that is larger than the number of rows in +the source file.) + +To extract a selected set of images from a multi\-image TIFF file +use the \-N option described above. Thus, to copy the 1st and 3rd +images of image file "album.tif" to "result.tif": +.RS +.nf +tiffcrop \-N 1,3 album.tif result.tif +.fi +.RE +.PP +Invert a bilevel image scan of a microfilmed document and crop off margins of +0.25 inches on the left and right, 0.5 inch on the top, and 0.75 inch on the +bottom. From the remaining portion of the image, select the second and third +quarters, ie, one half of the area left from the center to each margin. +.RS +tiffcrop \-U in \-m 0.5,0.25,0.75,0.25 \-E left \-Z 2:4,3:4 \-I both MicrofilmNegative.tif MicrofilmPostiveCenter.tif +.fi +.RE +.PP +Extract only the final image of a large Architectural E sized +multipage TIFF file and rotate it 90 degrees clockwise while +reformatting the output to fit on tabloid sized sheets with one +quarter of an inch on each side: +.RS +tiffcrop \-N last \-R 90 \-O auto \-P tabloid \-U in \-J 0.25 \-K 0.25 \-H 300 \-V 300 Big\-PlatMap.tif BigPlatMap\-Tabloid.tif +.fi +.RE +The output images will have a specified resolution of 300 dpi in both +directions. The orientation of each page will be determined by whichever +choice requires the fewest pages. To specify a specific orientation, use +the portrait or landscape option. The paper size option does not resample +the image. It breaks each original image into a series of smaller images +that will fit on the target paper size at the specified resolution. +.fi +.RE +.PP +Extract two regions 2048 pixels wide by 2048 pixels high from each page of +a multi\-page input file and write each region to a separate output file. +.RS +tiffcrop \-U px \-z 1,1,2048,2048:1,2049,2048,4097 \-e separate CheckScans.tiff Check +.fi +.RE +The output file names will use the stem Check with a numeric suffix which is +incremented for each region of each image, eg Check\-001.tiff, Check\-002.tiff ... +Check\-NNN.tiff. To produce a unique file for each page of the input image +with one new image for each region of the input image on that page, change +the export option to \-e multiple. + +.SH "NOTES" +.PP +In general, bilevel, grayscale, palette and RGB(A) data with bit depths +from 1 to 32 bits should work in both interleaved and separate plane +formats. Unlike tiffcp, tiffcrop can read and write tiled images with +bits per sample that are not a multiple of 8 in both interleaved and +separate planar format. Floating point data types are supported at +bit depts of 16, 24, 32 and 64 bits per sample. +.PP +Not all images can be converted from one compression scheme to another. +Data with some photometric interpretations and/or bit depths are tied to +specific compression schemes and vice-versa, e.g. Group 3/4 compression +is only usable for bilevel data. JPEG compression is only useable on 8 +bit per sample data (or 12 bit if +.I LibTIFF +was compiled with 12 bit JPEG support). Support for OJPEG compressed +images is problematic at best. Since OJPEG compression is no longer +supported for writing images with LibTIFF, these images will be updated +to the newer JPEG compression when they are copied or processed. This +may cause the image to appear color shifted or distorted after conversion. +In some cases, it is possible to remove the original compression from +image data using the option -cnone. +.PP +Tiffcrop does not currently provide options to up or downsample data to +different bit depths or convert data from one photometric interpretation +to another, e.g. 16 bits per sample to 8 bits per sample or RGB to grayscale. +.PP +Tiffcrop is very loosely derived from code in +.I tiffcp +with extensive modifications and additions to support the selection of input +images and regions and the exporting of them to one or more output files in +various groupings. The image manipulation routines are entirely new and +additional ones may be added in the future. It will handle tiled images with +bit depths that are not a multiple of eight that tiffcp may refuse to read. +.PP +.I Tiffcrop +was designed to handle large files containing many moderate sized images +with memory usage that is independent of the number of images in the file. +In order to support compression modes that are not based on individual +scanlines, e.g. JPEG, it now reads images by strip or tile rather than by +indvidual scanlines. In addition to the memory required by the input and +output buffers associated with +.I LibTIFF +one or more buffers at least as large as the largest image to be read are +required. The design favors large volume document processing uses over +scientific or graphical manipulation of large datasets as might be found +in research or remote sensing scenarios. +.SH "SEE ALSO" +.BR pal2rgb (1), +.BR tiffinfo (1), +.BR tiffcmp (1), +.BR tiffcp (1), +.BR tiffmedian (1), +.BR tiffsplit (1), +.BR libtiff (3TIFF) +.PP +Libtiff library home page: +.BR http://www.remotesensing.org/libtiff/ + diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c index 20192921..18027695 100644 --- a/tools/tiffcrop.c +++ b/tools/tiffcrop.c @@ -1,4 +1,4 @@ -/* $Id: tiffcrop.c,v 1.16 2010-03-10 18:56:50 bfriesen Exp $ */ +/* $Id: tiffcrop.c,v 1.17 2010-06-11 22:25:36 bfriesen Exp $ */ /* tiffcrop.c -- a port of tiffcp.c extended to include manipulations of * the image data through additional options listed below @@ -327,7 +327,9 @@ struct paperdef { double asratio; }; -/* Paper Size Width Length Aspect Ratio */ +/* European page sizes corrected from update sent by + * thomas . jarosch @ intra2net . com on 5/7/2010 + * Paper Size Width Length Aspect Ratio */ struct paperdef PaperTable[MAX_PAPERNAMES] = { {"default", 8.500, 14.000, 0.607}, {"pa4", 8.264, 11.000, 0.751}, @@ -352,31 +354,31 @@ struct paperdef PaperTable[MAX_PAPERNAMES] = { {"envelope-dl", 4.333, 8.681, 0.499}, {"envelope-c5", 6.389, 9.028, 0.708}, {"europostcard", 4.139, 5.833, 0.710}, - {"a0", 33.111, 46.806, 0.707}, - {"a1", 23.389, 33.111, 0.706}, - {"a2", 16.542, 23.389, 0.707}, - {"a3", 11.694, 16.542, 0.707}, - {"a4", 8.264, 11.694, 0.707}, - {"a5", 5.833, 8.264, 0.706}, - {"a6", 4.125, 5.833, 0.707}, - {"a7", 2.917, 4.125, 0.707}, - {"a8", 2.056, 2.917, 0.705}, - {"a9", 1.458, 2.056, 0.709}, - {"a10", 1.014, 1.458, 0.695}, - {"b0", 39.375, 55.667, 0.707}, - {"b1", 27.833, 39.375, 0.707}, - {"b2", 19.681, 27.833, 0.707}, - {"b3", 13.903, 19.681, 0.706}, - {"b4", 9.847, 13.903, 0.708}, - {"b5", 6.931, 9.847, 0.704}, - {"b6", 4.917, 6.931, 0.709}, - {"c0", 36.097, 51.069, 0.707}, - {"c1", 25.514, 36.097, 0.707}, - {"c2", 18.028, 25.514, 0.707}, - {"c3", 12.750, 18.028, 0.707}, - {"c4", 9.014, 12.750, 0.707}, - {"c5", 6.375, 9.014, 0.707}, - {"c6", 4.486, 6.375, 0.704}, + {"a0", 33.110, 46.811, 0.707}, + {"a1", 23.386, 33.110, 0.706}, + {"a2", 16.535, 23.386, 0.707}, + {"a3", 11.693, 16.535, 0.707}, + {"a4", 8.268, 11.693, 0.707}, + {"a5", 5.827, 8.268, 0.705}, + {"a6", 4.134, 5.827, 0.709}, + {"a7", 2.913, 4.134, 0.705}, + {"a8", 2.047, 2.913, 0.703}, + {"a9", 1.457, 2.047, 0.712}, + {"a10", 1.024, 1.457, 0.703}, + {"b0", 39.370, 55.669, 0.707}, + {"b1", 27.835, 39.370, 0.707}, + {"b2", 19.685, 27.835, 0.707}, + {"b3", 13.898, 19.685, 0.706}, + {"b4", 9.843, 13.898, 0.708}, + {"b5", 6.929, 9.843, 0.704}, + {"b6", 4.921, 6.929, 0.710}, + {"c0", 36.102, 51.063, 0.707}, + {"c1", 25.512, 36.102, 0.707}, + {"c2", 18.031, 25.512, 0.707}, + {"c3", 12.756, 18.031, 0.707}, + {"c4", 9.016, 12.756, 0.707}, + {"c5", 6.378, 9.016, 0.707}, + {"c6", 4.488, 6.378, 0.704}, {"", 0.000, 0.000, 1.000}, }; @@ -698,6 +700,8 @@ static char* stuff[] = { " ", " -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", @@ -961,7 +965,7 @@ static int readSeparateTilesIntoBuffer (TIFF* in, uint8 *obuf, tbuff = (unsigned char *)_TIFFmalloc(tilesize + 8); if (!tbuff) { - TIFFError ("readSeparateStripsIntoBuffer", + TIFFError ("readSeparateTilesIntoBuffer", "Unable to allocate tile read buffer for sample %d", sample); for (i = 0; i < sample; i++) _TIFFfree (srcbuffs[i]); @@ -1526,7 +1530,7 @@ static struct cpTag { #define CopyTag(tag, count, type) cpTag(in, out, tag, count, type) -/* Fucntions written by Richard Nolde, with exceptions noted. */ +/* 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, @@ -1898,6 +1902,12 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32 } break; case 'P': /* page size selection */ + if (sscanf(optarg, "%lfx%lf", &page->width, &page->length) == 2) + { + strcpy (page->name, "Custom"); + page->mode |= PAGE_MODE_PAPERSIZE; + break; + } if (get_page_geometry (optarg, page)) { if (!strcmp(optarg, "list")) @@ -5446,9 +5456,9 @@ computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image, struct dump_opts* dump) { double scale; - uint32 iwidth, ilength; /* Input image width and length */ - uint32 owidth, olength; /* Output image width and length */ - uint32 pwidth, plength; /* Output page width and length */ + 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; @@ -5514,7 +5524,7 @@ computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image, "Hmargin: %3.2f, Vmargin: %3.2f\n", page->name, page->vres, page->hres, page->hmargin, page->vmargin); - TIFFError("", "Res_unit: %d, Scale: %3.2f, Page width: %d, length: %d\n", + TIFFError("", "Res_unit: %d, Scale: %3.2f, Page width: %3.2f, length: %3.2f\n", page->res_unit, scale, pwidth, plength); } @@ -5703,8 +5713,77 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c res_unit = RESUNIT_INCH; if (!TIFFGetField(in, TIFFTAG_COMPRESSION, &input_compression)) input_compression = COMPRESSION_NONE; - scanlinesize = TIFFScanlineSize(in); +#ifdef DEBUG2 + char compressionid[16]; + + switch (compression) + { + case COMPRESSION_NONE: /* 1 dump mode */ + stcrcpy ("None/dump", compressionid); + break; + case COMPRESSION_CCITTRLE: /* 2 CCITT modified Huffman RLE */ + stcrcpy ("Huffman RLE", compressionid); + break; + case COMPRESSION_CCITTFAX3: /* 3 CCITT Group 3 fax encoding */ + case COMPRESSION_CCITT_T4: /* 3 CCITT T.4 (TIFF 6 name) */ + stcrcpy ("Group3 Fax", compressionid); + break; + case COMPRESSION_CCITTFAX4: /* 4 CCITT Group 4 fax encoding */ + case COMPRESSION_CCITT_T6: /* 4 CCITT T.6 (TIFF 6 name) */ + stcrcpy ("Group4 Fax", compressionid); + break; + case COMPRESSION_LZW: /* 5 Lempel-Ziv & Welch */ + stcrcpy ("LZW", compressionid); + break; + case COMPRESSION_OJPEG: /* 6 !6.0 JPEG */ + stcrcpy ("Old Jpeg", compressionid); + break; + case COMPRESSION_JPEG: /* 7 %JPEG DCT compression */ + stcrcpy ("New Jpeg", compressionid); + break; + case COMPRESSION_NEXT: /* 32766 NeXT 2-bit RLE */ + stcrcpy ("Next RLE", compressionid); + break; + case COMPRESSION_CCITTRLEW: /* 32771 #1 w/ word alignment */ + stcrcpy ("CITTRLEW", compressionid); + break; + case COMPRESSION_PACKBITS: /* 32773 Macintosh RLE */ + stcrcpy ("Mac Packbits", compressionid); + break; + case COMPRESSION_THUNDERSCAN: /* 32809 ThunderScan RLE */ + stcrcpy ("Thunderscan", compressionid); + break; + case COMPRESSION_IT8CTPAD: /* 32895 IT8 CT w/padding */ + stcrcpy ("IT8 padded", compressionid); + break; + case COMPRESSION_IT8LW: /* 32896 IT8 Linework RLE */ + stcrcpy ("IT8 RLE", compressionid); + break; + case COMPRESSION_IT8MP: /* 32897 IT8 Monochrome picture */ + stcrcpy ("IT8 mono", compressionid); + break; + case COMPRESSION_IT8BL: /* 32898 IT8 Binary line art */ + stcrcpy ("IT8 lineart", compressionid); + break; + case COMPRESSION_PIXARFILM: /* 32908 Pixar companded 10bit LZW */ + stcrcpy ("Pixar 10 bit", compressionid); + break; + case COMPRESSION_PIXARLOG: /* 32909 Pixar companded 11bit ZIP */ + stcrcpy ("Pixar 11bit", compressionid); + break; + case COMPRESSION_DEFLATE: /* 32946 Deflate compression */ + stcrcpy ("Deflate", compressionid); + break; + case COMPRESSION_ADOBE_DEFLATE: /* 8 Deflate compression */ + stcrcpy ("Adobe deflate", compressionid); + break; + default: + stcrcpy ("None/unknown", compressionid); + break; + } +#endif + scanlinesize = TIFFScanlineSize(in); image->bps = bps; image->spp = spp; image->planar = planar; @@ -5714,6 +5793,55 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c image->yres = yres; image->res_unit = res_unit; image->photometric = photometric; + +#ifdef DEBUG2 + char photmetricid[12]; + + switch (photometric) + { + case PHOTOMETRIC_MINISWHITE: + strcpy (photometricid, "MinIsWhite"); + break; + case PHOTOMETRIC_MINISBLACK: + strcpy (photometricid, "MinIsBlack"); + break; + case PHOTOMETRIC_RGB: + strcpy (photometricid, "RGB"); + break; + case PHOTOMETRIC_PALETTE: + strcpy (photometricid, "Palette"); + break; + case PHOTOMETRIC_MASK: + strcpy (photometricid, "Mask"); + break; + case PHOTOMETRIC_SEPARATED: + strcpy (photometricid, "Separated"); + break; + case PHOTOMETRIC_YCBCR: + strcpy (photometricid, "YCBCR"); + break; + case PHOTOMETRIC_CIELAB: + strcpy (photometricid, "CIELab"); + break; + case PHOTOMETRIC_ICCLAB: + strcpy (photometricid, "ICCLab"); + break; + case PHOTOMETRIC_ITULAB: + strcpy (photometricid, "ITULab"); + break; + case PHOTOMETRIC_LOGL: + strcpy (photometricid, "LogL"); + break; + case PHOTOMETRIC_LOGLUV: + strcpy (photometricid, "LOGLuv"); + break; + default: + strcpy (photometricid, "Unknown"); + break; + } + TIFFError("loadImage", "Input photometric interpretation %s", photometricid); +#endif + image->orientation = orientation; switch (orientation) { @@ -6781,6 +6909,12 @@ writeSingleSection(TIFF *in, TIFF *out, struct image_data *image, TIFFSetField(out, TIFFTAG_PHOTOMETRIC, image->photometric); } +#ifdef DEBUG2 + TIFFError("writeSingleSection", "Input photometric: %s", + (input_photmetric == PHOTMETRIC_RGB) ? "RGB" : + ((input_photometric == PHOTOMETRIC_YCBCR) ? "YCbCr" : "Not RGB or YCrCr")); +#endif + if (((input_photometric == PHOTOMETRIC_LOGL) || (input_photometric == PHOTOMETRIC_LOGLUV)) && ((compression != COMPRESSION_SGILOG) && |