]> git.saurik.com Git - wxWidgets.git/blob - src/tiff/contrib/dbs/tiff-rgb.c
Compilation fix for wxMSW with wxUSE_MSGBOX_HOOK==0.
[wxWidgets.git] / src / tiff / contrib / dbs / tiff-rgb.c
1
2 /*
3 * tiff-rgb.c -- create a 24-bit Class R (rgb) TIFF file
4 *
5 * Copyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
6 *
7 * All Rights Reserved
8 *
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.
16 *
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
23 * SOFTWARE.
24 */
25
26 #include <math.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "tiffio.h"
32
33 #define ROUND(x) (uint16) ((x) + 0.5)
34 #define CMSIZE 256
35 #define WIDTH 525
36 #define HEIGHT 512
37 #define TIFF_GAMMA 2.2
38
39 void Usage();
40 char * programName;
41
42 int main(int argc, char **argv)
43 {
44 char * input_file = NULL;
45 double image_gamma = TIFF_GAMMA;
46 int i, j;
47 TIFF * tif;
48 unsigned char * scan_line;
49 uint16 red[CMSIZE], green[CMSIZE], blue[CMSIZE];
50 float refblackwhite[2*3];
51
52 programName = argv[0];
53
54 switch (argc) {
55 case 2:
56 image_gamma = TIFF_GAMMA;
57 input_file = argv[1];
58 break;
59 case 4:
60 if (!strcmp(argv[1], "-gamma")) {
61 image_gamma = atof(argv[2]);
62 input_file = argv[3];
63 } else
64 Usage();
65 break;
66 default:
67 Usage();
68 }
69
70 for (i = 0; i < CMSIZE; i++) {
71 if (i == 0)
72 red[i] = green[i] = blue[i] = 0;
73 else {
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));
77 }
78 }
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;
82
83 if ((tif = TIFFOpen(input_file, "w")) == NULL) {
84 fprintf(stderr, "can't open %s as a TIFF file\n", input_file);
85 exit(0);
86 }
87
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);
97 #ifdef notdef
98 TIFFSetField(tif, TIFFTAG_WHITEPOINT, whitex, whitey);
99 TIFFSetField(tif, TIFFTAG_PRIMARYCHROMATICITIES, primaries);
100 #endif
101 TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, refblackwhite);
102 TIFFSetField(tif, TIFFTAG_TRANSFERFUNCTION, red, green, blue);
103
104 scan_line = (unsigned char *) malloc(WIDTH * 3);
105
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;
111 }
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;
116 }
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;
121 }
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;
126 }
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;
131 }
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;
136 }
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;
141 }
142 TIFFWriteScanline(tif, scan_line, i, 0);
143 }
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;
149 }
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;
154 }
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;
159 }
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;
164 }
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;
169 }
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;
174 }
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;
179 }
180 TIFFWriteScanline(tif, scan_line, i, 0);
181 }
182
183 free(scan_line);
184 TIFFClose(tif);
185 exit(0);
186 }
187
188 void
189 Usage()
190 {
191 fprintf(stderr, "Usage: %s -gamma gamma tiff-image\n", programName);
192 exit(0);
193 }
194 /*
195 * Local Variables:
196 * mode: c
197 * c-basic-offset: 8
198 * fill-column: 78
199 * End:
200 */