Fw: Enhanced tiffset
"Kevin Myers" <[email protected]>
| Newsgroups | gmane.comp.video.gimp.windows.devel,gmane.comp.video.gimp.user,gmane.comp.video.gimp.devel,gmane.comp.video.image-magick.user,gmane.comp.video.image-magick.devel |
|---|---|
| Message-ID | <05b801c2b894$2bc07920$66c8a8c0@gusher> |
----- Original Message ----- From: "Kevin Myers" <[email protected]> To: <[email protected]> Cc: "Kevin Myers" <[email protected]> Sent: Friday, January 10, 2003 4:30 AM Subject: Enhanced tiffset > Hello, > > I've just developed an enhanced version of the tiffset tool that is shipped > with libtiff. This version provides the ability to change the values of > many more tags and tag types. The new version is named tiffset2, and both a > Win 32 executable and the source code is attached. > > The primary reason that I developed this was to provide a fast and easy way > to change the x and y resolution metadata values in TIFF image headers. > This allows one to effectively change the physical image dimensions without > changing the number of pixels, for example. I needed to do this to work > around a bug in the GIMP v1.2.4 which seems to affect images greater than > about 187.5 feet in any dimension (yes, my images are that long!). > > I started from version 1.2 of tiffset, and did a fair amount of re-work to > support the additional tags and types. However, it is quite obvious that > much more could still be done. Additionally, I am NOT an expert C developer > by any stretch of the imagination. So, any comments, suggestions, and > corrections would be appreciated and well received. > > I'm not familiar with using CVS to check modifications in and out, so I > haven't made any attempt to upload this new version to any central code > repository. Perhaps someone else would consider doing that...? > > Meanwhile, I hope this may prove useful to some of you out there. If so, > then perhaps this new version could be included with a future release of the > libtiff tools. > > s/KAM > > P.S. - This utility uses and requires libtiff, in case that wasn't already > obvious. > > ------------------------ Yahoo! Groups Sponsor ---------------------~--> Turn flat surfaces into speakers with the Soundbug. http://us.click.yahoo.com/QWAVSC/onCFAA/xGHJAA/NhFolB/TM ---------------------------------------------------------------------~-> To Post a message, send it to: [email protected] To Unsubscribe, send a blank message to: [email protected] Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
tiffset2.exe
(application/x-msdownload, 288 KB) - not displayed
tiffset2.c
(application/octet-stream, 8.4 KB)
/****************************************************************************** * * Project: libtiff tools * Purpose: Mainline for setting metadata in existing TIFF files. * Author: Frank Warmerdam, [email protected] * ****************************************************************************** * Copyright (c) 2000, Frank Warmerdam * Copyright (c) 2002, Kevin A. Myers * * 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. ****************************************************************************** * * $Log: tiffset.c,v $ * Revision 2.0 2003/01/10 01:33:48 kamyers1 * additional fields and types * * $Log: tiffset.c,v $ * Revision 1.2 2001/09/26 17:42:18 warmerda * added TIFFRewriteDirectory * * Revision 1.1 2001/03/02 04:58:53 warmerda * New * */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include "tiffiop.h" #define TAGLEN 32 typedef struct { ttag_t tagID; uint16 tagType; char tagName[TAGLEN]; } tagInfoT; static tagInfoT* tag_name_to_info(const char*); static char* upcase(char*); static void usage(void); static char* usageMsg[] = { "\n", "tiffset v2.0 by Kevin A. Myers 2003/01/10\n", "modified from tiffset v1.2 by Frank Warmerdam\n", "\n", "Changes tag values in TIFF image headers.\n", "\n", "usage: tiffset [-s name value [-s name value [...]]] filename\n", "\n", "Most common tag names that don't impact file structure are supported.\n", "No error checking is performed, use with caution!!!\n", "\n", "Example(s)\n", "\n", "Change the resolution to 200 dpi for the file myimage.tif.\n", "tiffset -s xresolution 200 -s yresolution 200 myimage.tif\n", "\n", "This example changes the image size without changing the number of pixels.\n", NULL }; const tagInfoT tagArray[] = { /* character fields */ {TIFFTAG_ARTIST, TIFF_ASCII, "ARTIST"}, {TIFFTAG_COPYRIGHT, TIFF_ASCII, "COPYRIGHT"}, {TIFFTAG_DATETIME, TIFF_ASCII, "DATETIME"}, {TIFFTAG_DOCUMENTNAME, TIFF_ASCII, "DOCUMENTNAME"}, {TIFFTAG_HOSTCOMPUTER, TIFF_ASCII, "HOSTCOMPUTER"}, {TIFFTAG_IMAGEDESCRIPTION, TIFF_ASCII, "IMAGEDESCRIPTION"}, {TIFFTAG_INKNAMES, TIFF_ASCII, "INKNAMES"}, {TIFFTAG_MAKE, TIFF_ASCII, "MAKE"}, {TIFFTAG_MODEL, TIFF_ASCII, "MODEL"}, {TIFFTAG_PAGENAME, TIFF_ASCII, "PAGENAME"}, {TIFFTAG_SOFTWARE, TIFF_ASCII, "SOFTWARE"}, {TIFFTAG_TARGETPRINTER, TIFF_ASCII, "TARGETPRINTER"}, /* double fields */ {TIFFTAG_SMAXSAMPLEVALUE, TIFF_DOUBLE, "SMAXSAMPLEVALUE"}, {TIFFTAG_SMINSAMPLEVALUE, TIFF_DOUBLE, "SMINSAMPLEVALUE"}, /* float fields */ {TIFFTAG_XPOSITION, TIFF_FLOAT, "XPOSITION"}, {TIFFTAG_XRESOLUTION, TIFF_FLOAT, "XRESOLUTION"}, {TIFFTAG_YPOSITION, TIFF_FLOAT, "YPOSITION"}, {TIFFTAG_YRESOLUTION, TIFF_FLOAT, "YRESOLUTION"}, /* uint16 fields */ {TIFFTAG_CLEANFAXDATA, TIFF_SHORT, "CLEANFAXDATA"}, {TIFFTAG_MAXSAMPLEVALUE, TIFF_SHORT, "MAXSAMPLEVALUE"}, {TIFFTAG_MINSAMPLEVALUE, TIFF_SHORT, "MINSAMPLEVALUE"}, {TIFFTAG_ORIENTATION, TIFF_SHORT, "ORIENTATION"}, {TIFFTAG_PHOTOMETRIC, TIFF_SHORT, "PHOTOMETRIC"}, {TIFFTAG_RESOLUTIONUNIT, TIFF_SHORT, "RESOLUTIONUNIT"}, {TIFFTAG_THRESHHOLDING, TIFF_SHORT, "THRESHHOLDING"}, /* uint32 fields */ {TIFFTAG_BADFAXLINES, TIFF_LONG, "BADFAXLINES"}, {TIFFTAG_CONSECUTIVEBADFAXLINES, TIFF_LONG, "CONSECUTIVEBADFAXLINES"}, {TIFFTAG_SUBFILETYPE, TIFF_LONG, "SUBFILETYPE"} }; int main(int argc, char* argv[]) { TIFF *tiff; int arg_index; if (argc < 2) usage(); tiff = TIFFOpen(argv[argc-1], "r+"); if (tiff == NULL) return (-2); for( arg_index = 1; arg_index < argc-1; arg_index++ ) { if(arg_index < argc-3 && (strcmp(argv[arg_index],"-s") == 0 || strcmp(argv[arg_index],"-sf") == 0) ) { int strLen; ttag_t id = 0; int tagType = 0; int setRC = 0; char* tagName = NULL; char* tagText = NULL; tagInfoT *tagInfo = tag_name_to_info(argv[arg_index+1]); if(tagInfo == NULL) { fprintf( stderr, "Field name %s not recognised.\n", argv[arg_index+1] ); exit(-3); } id = tagInfo->tagID; tagType = tagInfo->tagType; tagName = tagInfo->tagName; if(strcmp(argv[arg_index],"-s") == 0) { strLen = strlen(argv[arg_index+2]); tagText = strcpy((char*) malloc(strLen + 1), argv[arg_index+2]); } else if(strcmp(argv[arg_index],"-sf") == 0) { FILE* fp = fopen( argv[arg_index+2], "rt" ); if(fp == NULL) { perror( argv[arg_index+2] ); continue; } else { tagText = (char*) malloc(65536); strLen = fread(tagText, 1, 65535, fp); tagText[strLen] = '\0'; fclose( fp ); } } switch(tagType) { case TIFF_ASCII: setRC = TIFFSetField(tiff, id, tagText); break; case TIFF_DOUBLE: setRC = TIFFSetField(tiff, id, atof(tagText)); break; case TIFF_FLOAT: setRC = TIFFSetField(tiff, id, (float) atof(tagText)); break; case TIFF_SHORT: setRC = TIFFSetField(tiff, id, (uint16) atof(tagText)); break; case TIFF_LONG: setRC = TIFFSetField(tiff, id, (uint32) atof(tagText)); break; default: fprintf(stderr, "Unexpected tag type %i encountered.\n", tagType); exit(-3); break; } if (setRC != 1) { fprintf( stderr, "Failed to set %s=%s\n", argv[arg_index+1], argv[arg_index+2] ); } if (tagText != NULL) free(tagText); arg_index += 2; } else { fprintf( stderr, "Unrecognised option: %s\n", argv[arg_index] ); usage(); } } #ifdef notdef tiff->tif_header.tiff_diroff = 0; tiff->tif_diroff = 0; #endif TIFFRewriteDirectory(tiff); TIFFClose(tiff); return (0); } static tagInfoT* tag_name_to_info(const char* name) { char* uname; int tagNo; if (strlen(name) >= TAGLEN) return NULL; uname = upcase(strcpy((char*) malloc(TAGLEN), name)); for(tagNo=0; tagNo < sizeof tagArray/sizeof(tagInfoT); tagNo++) { if (strstr(uname, tagArray[tagNo].tagName) != NULL) return &tagArray[tagNo]; } free(uname); /* matching tag not found */ return NULL; } static char* upcase(char* str) { int strLen; int charNo; strLen = strlen(str); for(charNo=0; charNo < strLen; charNo++) str[charNo]=toupper(str[charNo]); return str; } static void usage(void) { int i; for (i = 0; usageMsg[i]; i++) fprintf(stderr, "%s", usageMsg[i]); exit(-1); }