1994.08.26 17:57 "tiffcp with invert and resolution switch - patch", by Uwe Bonnes
As I and others had problems with the photometric tag, here a patch to invert min-is-white to min-is-black and vice-verse with "-invert". With "-resolution n [m]" you can set or overwrite the resolution tag. With "-resolution n" you get the same resolution for X and Y, with "-resolution n m" you set X to n and Y to m. I find this usefull, as "xv" doesn't output the resolution-tag, but offers a lot of possibilities to manipulate pictures. With "-resolution" I can fix it afterwards.
Please check it out and let me know, if something goes wrong. The unified diff is against v3.3beta015.
Hope you find it usefull!
--- tools/tiffcp.c~ Wed Jul 27 04:01:16 1994
+++ tools/tiffcp.c Fri Aug 26 19:00:50 1994
@@ -50,6 +50,7 @@
#define FALSE 0
static int outtiled = -1;
+static int invert = FALSE;
static uint32 tilewidth;
static uint32 tilelength;
@@ -57,8 +58,11 @@
static uint16 compression;
static uint16 predictor;
static uint16 fillorder;
+static uint16 photometric;
static uint32 rowsperstrip;
static uint32 g3opts;
+static float xresolution;
+static float yresolution;
static int ignore = FALSE; /* if true, ignore read errors */
static char *filename;
@@ -76,6 +80,8 @@
uint32 deftilelength = -1;
uint32 defrowsperstrip = -1;
uint32 defg3opts = -1;
+ float defxresolution = -1.0;
+ float defyresolution = -1.0;
TIFF *in, *out;
argc--, argv++;
@@ -146,6 +152,20 @@
defpredictor = atoi(argv[0]);
continue;
}
+ if (streq(argv[0], "-resolution")) {
+ argc--, argv++;
+ defxresolution = atof(argv[0]);
+ if (isdigit(argv[1][0])) {
+ argc--, argv++;
+ defyresolution = atof(argv[0]);}
+ else
+ defyresolution = defxresolution;
+ continue;
+ }
+ if (streq(argv[0], "-invert")) {
+ invert = TRUE;
+ continue;
+ }
if (streq(argv[0], "-strips")) {
outtiled = FALSE;
continue;
@@ -187,6 +207,8 @@
tilewidth = deftilewidth;
tilelength = deftilelength;
g3opts = defg3opts;
+ xresolution = defxresolution;
+ yresolution = defyresolution;
if (!tiffcp(in, out) || !TIFFWriteDirectory(out)) {
(void) TIFFClose(out);
exit(1);
@@ -226,6 +248,8 @@
" -fill zero-fill scanlines with CCITT Group 3 encoding",
"",
" -predictor set predictor value for Lempel-Ziv & Welch encoding",
+" -resolution # [#] set resolution for x and y [separately]",
+" -invert if min-is-white set to min-is-black and vice versa",
NULL
};
@@ -265,7 +289,7 @@
TIFFDataType type;
} tags[] = {
{ TIFFTAG_SUBFILETYPE, 1, TIFF_LONG },
- { TIFFTAG_PHOTOMETRIC, 1, TIFF_SHORT },
+/* { TIFFTAG_PHOTOMETRIC, 1, TIFF_SHORT },*/
{ TIFFTAG_THRESHHOLDING, 1, TIFF_SHORT },
{ TIFFTAG_DOCUMENTNAME, 1, TIFF_ASCII },
{ TIFFTAG_IMAGEDESCRIPTION, 1, TIFF_ASCII },
@@ -274,8 +298,8 @@
{ TIFFTAG_ORIENTATION, 1, TIFF_SHORT },
{ TIFFTAG_MINSAMPLEVALUE, 1, TIFF_SHORT },
{ TIFFTAG_MAXSAMPLEVALUE, 1, TIFF_SHORT },
- { TIFFTAG_XRESOLUTION, 1, TIFF_RATIONAL },
- { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL },
+/* { TIFFTAG_XRESOLUTION, 1, TIFF_RATIONAL },
+ { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL },*/
{ TIFFTAG_PAGENAME, 1, TIFF_ASCII },
{ TIFFTAG_XPOSITION, 1, TIFF_RATIONAL },
{ TIFFTAG_YPOSITION, 1, TIFF_RATIONAL },
@@ -419,6 +443,19 @@
TIFFSetField(out, TIFFTAG_COLORMAP, red, green, blue);
}
}
+ if (xresolution > 0) {
+ TIFFSetField(out, TIFFTAG_XRESOLUTION, xresolution);
+ TIFFSetField(out, TIFFTAG_YRESOLUTION, yresolution);
+ }
+ else {
+ CopyField(TIFFTAG_XRESOLUTION, xresolution);
+ CopyField(TIFFTAG_YRESOLUTION, yresolution);
+ }
+ TIFFGetField(in,TIFFTAG_PHOTOMETRIC,&shortv);
+ if (invert && (shortv < 2)) /*invert meaning*/
+ TIFFSetField(out, TIFFTAG_PHOTOMETRIC, shortv^0001);
+ else
+ CopyField(TIFFTAG_PHOTOMETRIC, shortv);
/* SMinSampleValue & SMaxSampleValue */
/* JPEG stuff */
cpOtherTags(in, out);
--- man/man1/tiffcp.1~ Wed Jul 27 04:01:23 1994
+++ man/man1/tiffcp.1 Fri Aug 26 19:12:08 1994
@@ -40,6 +40,9 @@
.B \-tilewidth
.I n
] [
+.B \-resolution
+.I n [m]
+] [
.B \-tilelength
.I n
] [
@@ -47,6 +50,8 @@
] [
.B \-separate
] [
+.B \-invert
+] [
.B \-lsb2msb
] [
.B \-msb2lsb
@@ -147,7 +152,10 @@
options can be used to specify the dimensions of tiles.
By default, the output file attempts to setup strip and tile
dimensions so that no more than 8 kilobytes of data appear in
-a strip or tile.
+a strip or tile. With
+.B \-resolution
+you may set or overwrite the resolution tag with one or independent
+values for both axes.
.PP
The
.B \-contig
@@ -156,6 +164,11 @@
options can be used to convert between different planar
configurations if the original files have one 8-bit
sample per pixel.
+.PP
+With
+.B \-invert
+you can toggle between min-is-white and min-is-black and vice versa, other
+values of the photometric tag don't get touched.
.PP
By default,
.I tiffcp