]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/contrib/dbs/tiff-palette.c
4 * tiff-palette.c -- create a Class P (palette) 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
35 #define SCALE(x) ((x) * 257L)
40 int main(int argc
, char **argv
)
42 int bits_per_pixel
= 8, cmsize
, i
, j
, k
,
43 cmap_index
, chunk_size
= 32, nchunks
= 16;
44 unsigned char * scan_line
;
45 uint16
*red
, *green
, *blue
;
48 programName
= argv
[0];
53 if (!strcmp(argv
[1], "-depth"))
54 bits_per_pixel
= atoi(argv
[2]);
58 switch (bits_per_pixel
) {
79 if (bits_per_pixel
!= 1) {
80 cmsize
= nchunks
* nchunks
;
84 red
= (uint16
*) malloc(cmsize
* sizeof(uint16
));
85 green
= (uint16
*) malloc(cmsize
* sizeof(uint16
));
86 blue
= (uint16
*) malloc(cmsize
* sizeof(uint16
));
88 switch (bits_per_pixel
) {
90 for (i
= 0; i
< cmsize
; i
++) {
111 green
[i
] = SCALE(36);
112 else if ((i
% 32) < 12)
113 green
[i
] = SCALE(73);
114 else if ((i
% 32) < 16)
115 green
[i
] = SCALE(109);
116 else if ((i
% 32) < 20)
117 green
[i
] = SCALE(146);
118 else if ((i
% 32) < 24)
119 green
[i
] = SCALE(182);
120 else if ((i
% 32) < 28)
121 green
[i
] = SCALE(219);
122 else if ((i
% 32) < 32)
123 green
[i
] = SCALE(255);
127 else if ((i
% 4) == 1)
129 else if ((i
% 4) == 2)
130 blue
[i
] = SCALE(170);
131 else if ((i
% 4) == 3)
132 blue
[i
] = SCALE(255);
141 green
[1] = SCALE(255);
146 blue
[2] = SCALE(255);
149 green
[3] = SCALE(255);
150 blue
[3] = SCALE(255);
153 green
[4] = SCALE(255);
154 blue
[4] = SCALE(255);
158 blue
[5] = SCALE(255);
161 green
[6] = SCALE(255);
169 green
[8] = SCALE(224);
170 blue
[8] = SCALE(230);
172 green
[9] = SCALE(149);
173 blue
[9] = SCALE(237);
175 green
[10] = SCALE(139);
176 blue
[10] = SCALE(87);
177 red
[11] = SCALE(160);
178 green
[11] = SCALE(82);
179 blue
[11] = SCALE(45);
180 red
[12] = SCALE(238);
181 green
[12] = SCALE(130);
182 blue
[12] = SCALE(238);
183 red
[13] = SCALE(176);
184 green
[13] = SCALE(48);
185 blue
[13] = SCALE(96);
187 green
[14] = SCALE(205);
188 blue
[14] = SCALE(50);
189 red
[15] = SCALE(240);
190 green
[15] = SCALE(152);
191 blue
[15] = SCALE(35);
199 green
[1] = SCALE(255);
204 blue
[2] = SCALE(255);
206 green
[3] = SCALE(255);
207 blue
[3] = SCALE(255);
215 green
[1] = SCALE(255);
216 blue
[1] = SCALE(255);
220 if ((tif
= TIFFOpen(argv
[3], "w")) == NULL
) {
221 fprintf(stderr
, "can't open %s as a TIFF file\n", argv
[3]);
222 free(red
);free(green
);free(blue
);
226 TIFFSetField(tif
, TIFFTAG_IMAGEWIDTH
, WIDTH
);
227 TIFFSetField(tif
, TIFFTAG_IMAGELENGTH
, HEIGHT
);
228 TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, bits_per_pixel
);
229 TIFFSetField(tif
, TIFFTAG_COMPRESSION
, COMPRESSION_NONE
);
230 TIFFSetField(tif
, TIFFTAG_PHOTOMETRIC
, PHOTOMETRIC_PALETTE
);
231 TIFFSetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, 1);
232 TIFFSetField(tif
, TIFFTAG_ROWSPERSTRIP
, 1);
233 TIFFSetField(tif
, TIFFTAG_PLANARCONFIG
, PLANARCONFIG_CONTIG
);
234 TIFFSetField(tif
, TIFFTAG_RESOLUTIONUNIT
, RESUNIT_NONE
);
235 TIFFSetField(tif
, TIFFTAG_COLORMAP
, red
, green
, blue
);
237 scan_line
= (unsigned char *) malloc(WIDTH
/ (8 / bits_per_pixel
));
239 for (i
= 0; i
< HEIGHT
; i
++) {
240 for (j
= 0, k
= 0; j
< WIDTH
;) {
241 cmap_index
= (j
/ chunk_size
) + ((i
/ chunk_size
) * nchunks
);
243 switch (bits_per_pixel
) {
245 scan_line
[k
++] = cmap_index
;
249 scan_line
[k
++] = (cmap_index
<< 4) + cmap_index
;
253 scan_line
[k
++] = (cmap_index
<< 6) + (cmap_index
<< 4)
254 + (cmap_index
<< 2) + cmap_index
;
259 ((j
/ chunk_size
) == (i
/ chunk_size
)) ? 0x00 : 0xff;
264 TIFFWriteScanline(tif
, scan_line
, i
, 0);
275 fprintf(stderr
, "Usage: %s -depth (8 | 4 | 2 | 1) tiff-image\n", programName
);