⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tiff2pdf.c

📁 tiff文件开发库
💻 C
📖 第 1 页 / 共 5 页
字号:
/* $Id: tiff2pdf.c,v 1.4 2003/12/01 10:51:39 rossf Exp $ * * tiff2pdf - converts a TIFF image to a PDF document * * $Log: tiff2pdf.c,v $ * Revision 1.4  2003/12/01 10:51:39  rossf * Some bugs fixed. * * Revision 1.3  2003/11/29 15:32:40  rossf * Some bugs fixed. * * * "d" - Improved colorimetry support * "c" - Added support for orientation, planar configuration * "b" - Improved JPEG handling * "a" - Written/ported for libtiff * * Copyright (c) 2003 Ross Finlayson * * 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 name of * Ross Finlayson may not be used in any advertising or * publicity relating to the software without the specific, prior written * permission of Ross Finlayson. *  * 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 ROSS FINLAYSON 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. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <time.h>#ifdef __STDC__#include <unistd.h> /* getopt, unlink */#else#ifndef _WIN32#include <getopt.h> /* getopt in getopt.h, unlink in stdio.h */#endif#endif#include "tiffiop.h"#ifndef NULL#define NULL ((void*)0)#endif#if defined(VMS)#define unlink remove#endif#if defined(_WIN32)#include <windows.h>#include <tchar.h>#define unlink DeleteFileA#endif#define TIFF2PDF_MODULE "tiff2pdf"#define T2P_VERSION "d"/* This type is of PDF color spaces. */typedef enum{	T2P_CS_BILEVEL=0x01, /* Bilevel, black and white */	T2P_CS_GRAY=0x02, /* Single channel */	T2P_CS_RGB=0x04, /* Three channel tristimulus RGB */#ifdef CMYK_SUPPORT	T2P_CS_CMYK=0x08, /* Four channel CMYK print inkset */#endif	T2P_CS_LAB=0x10, /* Three channel L*a*b* color space */	T2P_CS_PALETTE=0x1000 /* One of the above with a color map */#ifdef COLORIMETRY_SUPPORT	, T2P_CS_CALGRAY=0x20 /* Calibrated single channel */	, T2P_CS_CALRGB=0x40 /* Calibrated three channel tristimulus RGB */#endif#ifdef ICC_SUPPORT	, T2P_CS_ICCBASED=0x80 /* ICC profile color specification */#endif} t2p_cs_t;/* This type is of PDF compression types.  */typedef enum{	T2P_COMPRESS_NONE=0x00#ifdef CCITT_SUPPORT	, T2P_COMPRESS_G4=0x01#endif#if defined(JPEG_SUPPORT) || defined(OJPEG_SUPPORT)	, T2P_COMPRESS_JPEG=0x02#endif#ifdef ZIP_SUPPORT	, T2P_COMPRESS_ZIP=0x04#endif} t2p_compress_t;/* This type is whether TIFF image data can be used in PDF without transcoding. */typedef enum{	T2P_TRANSCODE_RAW=0x01, /* The raw data from the input can be used without recompressing */	T2P_TRANSCODE_ENCODE=0x02 /* The data from the input is perhaps unencoded and reencoded */} t2p_transcode_t;/* This type is of information about the data samples of the input image. */typedef enum{	T2P_SAMPLE_NOTHING=0x0000, /* The unencoded samples are normal for the output colorspace */	T2P_SAMPLE_ABGR_TO_RGB=0x0001, /* The unencoded samples are the result of ReadRGBAImage */	T2P_SAMPLE_RGBA_TO_RGB=0x0002, /* The unencoded samples are contiguous RGBA */	T2P_SAMPLE_RGBAA_TO_RGB=0x0004, /* The unencoded samples are RGBA with premultiplied alpha */	T2P_SAMPLE_YCBCR_TO_RGB=0x0008, 	T2P_SAMPLE_YCBCR_TO_LAB=0x0010, 	T2P_SAMPLE_REALIZE_PALETTE=0x0020, /* The unencoded samples are indexes into the color map */	T2P_SAMPLE_SIGNED_TO_UNSIGNED=0x0040, /* The unencoded samples are signed instead of unsignd */	T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED=0x0040, /* The L*a*b* samples have a* and b* signed */	T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG=0x0100 /* The unencoded samples are separate instead of contiguous */} t2p_sample_t;/* This type is of error status of the T2P struct. */typedef enum{	T2P_ERR_OK = 0, /* This is the value of t2p->t2p_error when there is no error */	T2P_ERR_ERROR = 1 /* This is the value of t2p->t2p_error when there was an error */} t2p_err_t;/* This struct defines a logical page of a TIFF. */typedef struct {	tdir_t page_directory;	uint32 page_number;	ttile_t page_tilecount;	uint32 page_extra;} T2P_PAGE;/* This struct defines a PDF rectangle's coordinates. */typedef struct {	float x1;	float y1;	float x2;	float y2;	float mat[9];} T2P_BOX;/* This struct defines a tile of a PDF.  */typedef struct {	T2P_BOX tile_box;} T2P_TILE;/* 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;	T2P_TILE* tiles_tiles;} T2P_TILES;/* This struct is the context of a function to generate PDF from a TIFF. */typedef struct {	t2p_err_t t2p_error;	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;	float tiff_xres;	float tiff_yres;	uint16 tiff_orientation;	toff_t tiff_dataoffset;	tsize_t tiff_datasize;	TIFFReadWriteProc tiff_readproc;	TIFFReadWriteProc tiff_writeproc;	TIFFSeekProc tiff_seekproc;	uint16 tiff_resunit;	uint16 pdf_centimeters;	uint16 pdf_overrideres;	uint16 pdf_overridepagesize;	float pdf_defaultxres;	float pdf_defaultyres;	float pdf_xres;	float pdf_yres;	float pdf_defaultpagewidth;	float pdf_defaultpagelength;	float pdf_pagewidth;	float pdf_pagelength;	float pdf_imagewidth;	float pdf_imagelength;	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;	char* pdf_fileid;	char* pdf_datetime;	char* pdf_creator;	char* pdf_author;	char* pdf_title;	char* pdf_subject;	char* pdf_keywords;	t2p_cs_t pdf_colorspace;	uint16 pdf_colorspace_invert;	uint16 pdf_switchdecode;	uint16 pdf_palettesize;	unsigned char* pdf_palette;	int pdf_labrange[4];	t2p_compress_t pdf_defaultcompression;	uint16 pdf_defaultcompressionquality;	t2p_compress_t pdf_compression;	uint16 pdf_compressionquality;	uint16 pdf_nopassthrough;	t2p_transcode_t pdf_transcode;	t2p_sample_t pdf_sample;	uint32* pdf_xrefoffsets;	uint32 pdf_xrefcount;	tdir_t pdf_page;#ifdef OJPEG_SUPPORT	tdata_t pdf_ojpegdata;	uint32 pdf_ojpegdatalength;	uint32 pdf_ojpegiflength;#endif#ifdef COLORIMETRY_SUPPORT	float tiff_whitechromaticities[2];	float tiff_primarychromaticities[6];	float tiff_referenceblackwhite[2];	float* tiff_transferfunction[3];	uint16 tiff_transferfunctioncount;#endif#ifdef ICC_SUPPORT	uint32 pdf_icccs;	uint32 tiff_iccprofilelength;	tdata_t tiff_iccprofile;#endif} T2P;/* These functions are called by main. */void tiff2pdf_usage(void);int tiff2pdf_match_paper_size(float*, float*, char*);/* These functions are used to generate a PDF from a TIFF. */ #ifdef __cplusplusextern "C" {#endifT2P* t2p_init(void);void t2p_validate(T2P*);tsize_t t2p_write_pdf(T2P*, TIFF*, TIFF*);void t2p_free(T2P*);#ifdef __cplusplus}#endiftsize_t t2p_empty_readproc(thandle_t, tdata_t, tsize_t);tsize_t t2p_empty_writeproc(thandle_t, tdata_t, tsize_t);toff_t t2p_empty_seekproc(thandle_t, toff_t, int);int t2p_empty_closeproc(thandle_t);void t2p_read_tiff_init(T2P*, TIFF*);int t2p_cmp_t2p_page(const void*, const void*);void t2p_read_tiff_data(T2P*, TIFF*);void t2p_read_tiff_size(T2P*, TIFF*);void t2p_read_tiff_size_tile(T2P*, TIFF*, ttile_t);int t2p_tile_is_right_edge(T2P_TILES, ttile_t);int t2p_tile_is_bottom_edge(T2P_TILES, ttile_t);int t2p_tile_is_edge(T2P_TILES, ttile_t);int t2p_tile_is_corner_edge(T2P_TILES, ttile_t);tsize_t t2p_readwrite_pdf_image(T2P*, TIFF*, TIFF*);tsize_t t2p_readwrite_pdf_image_tile(T2P*, TIFF*, TIFF*, ttile_t);#ifdef OJPEG_SUPPORTint t2p_process_ojpeg_tables(T2P*, TIFF*);#endif#ifdef JPEG_SUPPORTint t2p_process_jpeg_strip(unsigned char*, tsize_t*, unsigned char*, tsize_t*, tstrip_t, uint32);#endifvoid t2p_tile_collapse_left(tdata_t, tsize_t, uint32, uint32, uint32);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_write_pdf_header(T2P*, TIFF*);tsize_t t2p_write_pdf_obj_start(uint32, TIFF*);tsize_t t2p_write_pdf_obj_end(TIFF*);tsize_t t2p_write_pdf_name(char*, TIFF*);tsize_t t2p_write_pdf_string(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_start(TIFF*);tsize_t t2p_write_pdf_stream_dict_end(TIFF*);tsize_t t2p_write_pdf_stream_length(tsize_t, TIFF*);tsize_t t2p_write_pdf_catalog(T2P*, TIFF*);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*);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);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*);#ifdef COLORIMETRY_SUPPORTtsize_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_xobject_calcs(T2P*, TIFF*);#endif#ifdef ICC_SUPPORTtsize_t t2p_write_pdf_xobject_icccs(T2P*, TIFF*);tsize_t t2p_write_pdf_xobject_icccs_dict(T2P*, TIFF*);tsize_t t2p_write_pdf_xobject_icccs_stream(T2P*, TIFF*);#endiftsize_t t2p_write_pdf_xobject_cs_stream(T2P*, TIFF*);tsize_t t2p_write_pdf_xobject_decode(T2P*, TIFF*);tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t, T2P*, TIFF*);tsize_t t2p_write_pdf_xreftable(T2P*, TIFF*);tsize_t t2p_write_pdf_trailer(T2P*, TIFF*);/*  This is the main function.  The program converts one TIFF file to one PDF file, including multiple page   TIFF files, tiled TIFF files, black and white. grayscale, and color TIFF   files that contain data of TIFF photometric interpretations of bilevel,   grayscale, RGB, YCbCr, CMYK separation, and ICC L*a*b* as supported by   libtiff and PDF.  If you have multiple TIFF files to convert into one PDF file then use tiffcp   or other program to concatenate the files into a multiple page TIFF file.    If the input TIFF file is of huge dimensions (greater than 10000 pixels height  or width) convert the input image to a tiled TIFF if it is not already.  The standard output is standard output.  Set the output file name with the   "-o output.pdf" option.  All black and white files are compressed into a single strip CCITT G4 Fax   compressed PDF, unless tiled, where tiled black and white images are   compressed into tiled CCITT G4 Fax compressed PDF, libtiff CCITT support   is assumed.  Color and grayscale data can be compressed using either JPEG compression,   ITU-T T.81, or Zip/Deflate LZ77 compression, per PNG 1.2 and RFC 1951.  Set   the compression type using the -j or -z options.  JPEG compression support   requires that libtiff be configured with JPEG support, and Zip/Deflate   compression support requires that libtiff is configured with Zip support,   in tiffconf.h.  Use only one or the other of -j and -z.  The -q option   sets the image compression quality, that is 1-100 with libjpeg JPEG   compression and one of 1, 10, 11, 12, 13, 14, or 15 for PNG group compression   predictor methods, add 100, 200, ..., 900 to set zlib compression quality 1-9.  PNG Group differencing predictor methods are not currently implemented.  If the input TIFF contains single strip CCITT G4 Fax compressed information,   then that is written to the PDF file without transcoding, unless the options   of no compression and no passthrough are set, -d and -n.  If the input TIFF contains JPEG or single strip Zip/Deflate compressed   information, and they are configured, then that is written to the PDF file   without transcoding, unless the options of no compression and no passthrough   are set.  The default page size upon which the TIFF image is placed is determined by   the resolution and extent of the image data.  Default values for the TIFF   image resolution can be set using the -x and -y options.  The page size can   be set using the -p option for paper size, or -w and -l for paper width and   length, then each page of the TIFF image is centered on its page.  The   distance unit for default resolution and page width and length can be set   by the -u option, the default unit is inch.  Various items of the output document information can be set with the -e, -c,   -a, -t, -s, and -k tags.  Setting the argument of the option to "" for these   tags causes the relevant document information field to be not written.  Some   of the document information values otherwise get their information from the   input TIFF image, the software, author, document name, and image description.  The output PDF file conforms to the PDF 1.1 specification or PDF 1.2 if using   Zip/Deflate compression.      The Portable Document Format (PDF) specification is copyrighted by Adobe   Systems, Incorporated.  Todos derechos reservados.  Here is a listing of the usage example and the options to the tiff2pdf   program that is part of the libtiff distribution.  Options followed by   a colon have a required argument.      usage:  tiff2pdf [options] input.tif    options:    -o: output to file name    -j  compress with JPEG (requires libjpeg configured with libtiff)    -z  compress with Zip/Deflate (requires zlib configured with libtiff)    -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    -y: set y resolution default    -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  set PDF "Fit Window" user preference    -e: date, overrides image or current date/time default, YYYYMMDDHHMMSS    -c: creator, overrides image software default    -a: author, overrides image artist default    -t: title, overrides image document name default    -s: subject, overrides image image description default    -k: keywords    -h  usage    examples:        tiff2pdf -o output.pdf input.tiff    The above example would generate the file output.pdf from input.tiff.        tiff2pdf input.tiff    The above example would generate PDF output from input.tiff and write it     to standard output.        tiff2pdf -j -p letter -o output.pdf input.tiff    The above example would generate the file output.pdf from input.tiff,     putting the image pages on a letter sized page, compressing the output     with JPEG.	Please report bugs through:	 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -