]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/contrib/dbs/tiff-palette.c
3 * tiff-palette.c -- create a Class P (palette) 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
34 #define SCALE(x) ((x) * 257L)
39 int main(int argc
, char **argv
)
41 int bits_per_pixel
= 8, cmsize
, i
, j
, k
,
42 cmap_index
, chunk_size
= 32, nchunks
= 16;
43 unsigned char * scan_line
;
44 uint16
*red
, *green
, *blue
;
47 programName
= argv
[0];
52 if (!strcmp(argv
[1], "-depth"))
53 bits_per_pixel
= atoi(argv
[2]);
57 switch (bits_per_pixel
) {
78 if (bits_per_pixel
!= 1) {
79 cmsize
= nchunks
* nchunks
;
83 red
= (uint16
*) malloc(cmsize
* sizeof(uint16
));
84 green
= (uint16
*) malloc(cmsize
* sizeof(uint16
));
85 blue
= (uint16
*) malloc(cmsize
* sizeof(uint16
));
87 switch (bits_per_pixel
) {
89 for (i
= 0; i
< cmsize
; i
++) {
110 green
[i
] = SCALE(36);
111 else if ((i
% 32) < 12)
112 green
[i
] = SCALE(73);
113 else if ((i
% 32) < 16)
114 green
[i
] = SCALE(109);
115 else if ((i
% 32) < 20)
116 green
[i
] = SCALE(146);
117 else if ((i
% 32) < 24)
118 green
[i
] = SCALE(182);
119 else if ((i
% 32) < 28)
120 green
[i
] = SCALE(219);
121 else if ((i
% 32) < 32)
122 green
[i
] = SCALE(255);
126 else if ((i
% 4) == 1)
128 else if ((i
% 4) == 2)
129 blue
[i
] = SCALE(170);
130 else if ((i
% 4) == 3)
131 blue
[i
] = SCALE(255);
140 green
[1] = SCALE(255);
145 blue
[2] = SCALE(255);
148 green
[3] = SCALE(255);
149 blue
[3] = SCALE(255);
152 green
[4] = SCALE(255);
153 blue
[4] = SCALE(255);
157 blue
[5] = SCALE(255);
160 green
[6] = SCALE(255);
168 green
[8] = SCALE(224);
169 blue
[8] = SCALE(230);
171 green
[9] = SCALE(149);
172 blue
[9] = SCALE(237);
174 green
[10] = SCALE(139);
175 blue
[10] = SCALE(87);
176 red
[11] = SCALE(160);
177 green
[11] = SCALE(82);
178 blue
[11] = SCALE(45);
179 red
[12] = SCALE(238);
180 green
[12] = SCALE(130);
181 blue
[12] = SCALE(238);
182 red
[13] = SCALE(176);
183 green
[13] = SCALE(48);
184 blue
[13] = SCALE(96);
186 green
[14] = SCALE(205);
187 blue
[14] = SCALE(50);
188 red
[15] = SCALE(240);
189 green
[15] = SCALE(152);
190 blue
[15] = SCALE(35);
198 green
[1] = SCALE(255);
203 blue
[2] = SCALE(255);
205 green
[3] = SCALE(255);
206 blue
[3] = SCALE(255);
214 green
[1] = SCALE(255);
215 blue
[1] = SCALE(255);
219 if ((tif
= TIFFOpen(argv
[3], "w")) == NULL
) {
220 fprintf(stderr
, "can't open %s as a TIFF file\n", argv
[3]);
221 free(red
);free(green
);free(blue
);
225 TIFFSetField(tif
, TIFFTAG_IMAGEWIDTH
, WIDTH
);
226 TIFFSetField(tif
, TIFFTAG_IMAGELENGTH
, HEIGHT
);
227 TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, bits_per_pixel
);
228 TIFFSetField(tif
, TIFFTAG_COMPRESSION
, COMPRESSION_NONE
);
229 TIFFSetField(tif
, TIFFTAG_PHOTOMETRIC
, PHOTOMETRIC_PALETTE
);
230 TIFFSetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, 1);
231 TIFFSetField(tif
, TIFFTAG_ROWSPERSTRIP
, 1);
232 TIFFSetField(tif
, TIFFTAG_PLANARCONFIG
, PLANARCONFIG_CONTIG
);
233 TIFFSetField(tif
, TIFFTAG_RESOLUTIONUNIT
, RESUNIT_NONE
);
234 TIFFSetField(tif
, TIFFTAG_COLORMAP
, red
, green
, blue
);
236 scan_line
= (unsigned char *) malloc(WIDTH
/ (8 / bits_per_pixel
));
238 for (i
= 0; i
< HEIGHT
; i
++) {
239 for (j
= 0, k
= 0; j
< WIDTH
;) {
240 cmap_index
= (j
/ chunk_size
) + ((i
/ chunk_size
) * nchunks
);
242 switch (bits_per_pixel
) {
244 scan_line
[k
++] = cmap_index
;
248 scan_line
[k
++] = (cmap_index
<< 4) + cmap_index
;
252 scan_line
[k
++] = (cmap_index
<< 6) + (cmap_index
<< 4)
253 + (cmap_index
<< 2) + cmap_index
;
258 ((j
/ chunk_size
) == (i
/ chunk_size
)) ? 0x00 : 0xff;
263 TIFFWriteScanline(tif
, scan_line
, i
, 0);
274 fprintf(stderr
, "Usage: %s -depth (8 | 4 | 2 | 1) tiff-image\n", programName
);