3 * tiff-rgb.c -- create a 24-bit Class R (rgb) TIFF file
5 * Copyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
9 * Permission to use, copy, modify, and distribute this software and its
10 * documentation for any purpose and without fee is hereby granted,
11 * provided that the above copyright notice appear in all copies and that
12 * both that copyright notice and this permission notice appear in
13 * supporting documentation, and that the name of Digital not be
14 * used in advertising or publicity pertaining to distribution of the
15 * software without specific, written prior permission.
17 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
18 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
19 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
20 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
22 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
33 #define ROUND(x) (uint16) ((x) + 0.5)
37 #define TIFF_GAMMA 2.2
42 int main(int argc
, char **argv
)
44 char * input_file
= NULL
;
45 double image_gamma
= TIFF_GAMMA
;
48 unsigned char * scan_line
;
49 uint16 red
[CMSIZE
], green
[CMSIZE
], blue
[CMSIZE
];
50 float refblackwhite
[2*3];
52 programName
= argv
[0];
56 image_gamma
= TIFF_GAMMA
;
60 if (!strcmp(argv
[1], "-gamma")) {
61 image_gamma
= atof(argv
[2]);
70 for (i
= 0; i
< CMSIZE
; i
++) {
72 red
[i
] = green
[i
] = blue
[i
] = 0;
74 red
[i
] = ROUND((pow(i
/ 255.0, 1.0 / image_gamma
) * 65535.0));
75 green
[i
] = ROUND((pow(i
/ 255.0, 1.0 / image_gamma
) * 65535.0));
76 blue
[i
] = ROUND((pow(i
/ 255.0, 1.0 / image_gamma
) * 65535.0));
79 refblackwhite
[0] = 0.0; refblackwhite
[1] = 255.0;
80 refblackwhite
[2] = 0.0; refblackwhite
[3] = 255.0;
81 refblackwhite
[4] = 0.0; refblackwhite
[5] = 255.0;
83 if ((tif
= TIFFOpen(input_file
, "w")) == NULL
) {
84 fprintf(stderr
, "can't open %s as a TIFF file\n", input_file
);
88 TIFFSetField(tif
, TIFFTAG_IMAGEWIDTH
, WIDTH
);
89 TIFFSetField(tif
, TIFFTAG_IMAGELENGTH
, HEIGHT
);
90 TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, 8);
91 TIFFSetField(tif
, TIFFTAG_COMPRESSION
, COMPRESSION_NONE
);
92 TIFFSetField(tif
, TIFFTAG_PHOTOMETRIC
, PHOTOMETRIC_RGB
);
93 TIFFSetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, 3);
94 TIFFSetField(tif
, TIFFTAG_ROWSPERSTRIP
, 1);
95 TIFFSetField(tif
, TIFFTAG_PLANARCONFIG
, PLANARCONFIG_CONTIG
);
96 TIFFSetField(tif
, TIFFTAG_RESOLUTIONUNIT
, RESUNIT_NONE
);
98 TIFFSetField(tif
, TIFFTAG_WHITEPOINT
, whitex
, whitey
);
99 TIFFSetField(tif
, TIFFTAG_PRIMARYCHROMATICITIES
, primaries
);
101 TIFFSetField(tif
, TIFFTAG_REFERENCEBLACKWHITE
, refblackwhite
);
102 TIFFSetField(tif
, TIFFTAG_TRANSFERFUNCTION
, red
, green
, blue
);
104 scan_line
= (unsigned char *) malloc(WIDTH
* 3);
106 for (i
= 0; i
< 255; i
++) {
107 for (j
= 0; j
< 75; j
++) {
108 scan_line
[j
* 3] = 255;
109 scan_line
[(j
* 3) + 1] = 255 - i
;
110 scan_line
[(j
* 3) + 2] = 255 - i
;
112 for (j
= 75; j
< 150; j
++) {
113 scan_line
[j
* 3] = 255 - i
;
114 scan_line
[(j
* 3) + 1] = 255;
115 scan_line
[(j
* 3) + 2] = 255 - i
;
117 for (j
= 150; j
< 225; j
++) {
118 scan_line
[j
* 3] = 255 - i
;
119 scan_line
[(j
* 3) + 1] = 255 - i
;
120 scan_line
[(j
* 3) + 2] = 255;
122 for (j
= 225; j
< 300; j
++) {
123 scan_line
[j
* 3] = (i
- 1) / 2;
124 scan_line
[(j
* 3) + 1] = (i
- 1) / 2;
125 scan_line
[(j
* 3) + 2] = (i
- 1) / 2;
127 for (j
= 300; j
< 375; j
++) {
128 scan_line
[j
* 3] = 255 - i
;
129 scan_line
[(j
* 3) + 1] = 255;
130 scan_line
[(j
* 3) + 2] = 255;
132 for (j
= 375; j
< 450; j
++) {
133 scan_line
[j
* 3] = 255;
134 scan_line
[(j
* 3) + 1] = 255 - i
;
135 scan_line
[(j
* 3) + 2] = 255;
137 for (j
= 450; j
< 525; j
++) {
138 scan_line
[j
* 3] = 255;
139 scan_line
[(j
* 3) + 1] = 255;
140 scan_line
[(j
* 3) + 2] = 255 - i
;
142 TIFFWriteScanline(tif
, scan_line
, i
, 0);
144 for (i
= 255; i
< 512; i
++) {
145 for (j
= 0; j
< 75; j
++) {
146 scan_line
[j
* 3] = i
;
147 scan_line
[(j
* 3) + 1] = 0;
148 scan_line
[(j
* 3) + 2] = 0;
150 for (j
= 75; j
< 150; j
++) {
151 scan_line
[j
* 3] = 0;
152 scan_line
[(j
* 3) + 1] = i
;
153 scan_line
[(j
* 3) + 2] = 0;
155 for (j
= 150; j
< 225; j
++) {
156 scan_line
[j
* 3] = 0;
157 scan_line
[(j
* 3) + 1] = 0;
158 scan_line
[(j
* 3) + 2] = i
;
160 for (j
= 225; j
< 300; j
++) {
161 scan_line
[j
* 3] = (i
- 1) / 2;
162 scan_line
[(j
* 3) + 1] = (i
- 1) / 2;
163 scan_line
[(j
* 3) + 2] = (i
- 1) / 2;
165 for (j
= 300; j
< 375; j
++) {
166 scan_line
[j
* 3] = 0;
167 scan_line
[(j
* 3) + 1] = i
;
168 scan_line
[(j
* 3) + 2] = i
;
170 for (j
= 375; j
< 450; j
++) {
171 scan_line
[j
* 3] = i
;
172 scan_line
[(j
* 3) + 1] = 0;
173 scan_line
[(j
* 3) + 2] = i
;
175 for (j
= 450; j
< 525; j
++) {
176 scan_line
[j
* 3] = i
;
177 scan_line
[(j
* 3) + 1] = i
;
178 scan_line
[(j
* 3) + 2] = 0;
180 TIFFWriteScanline(tif
, scan_line
, i
, 0);
191 fprintf(stderr
, "Usage: %s -gamma gamma tiff-image\n", programName
);