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