]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/tiff/contrib/dbs/tiff-rgb.c
Add missing WXK constants for the control keys
[wxWidgets.git] / src / tiff / contrib / dbs / tiff-rgb.c
... / ...
CommitLineData
1/* $Id$ */
2
3/*
4 * tiff-rgb.c -- create a 24-bit Class R (rgb) TIFF file
5 *
6 * Copyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
7 *
8 * All Rights Reserved
9 *
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.
17 *
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
24 * SOFTWARE.
25 */
26
27#include <math.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31
32#include "tiffio.h"
33
34#define ROUND(x) (uint16) ((x) + 0.5)
35#define CMSIZE 256
36#define WIDTH 525
37#define HEIGHT 512
38#define TIFF_GAMMA 2.2
39
40void Usage();
41char * programName;
42
43int main(int argc, char **argv)
44{
45 char * input_file = NULL;
46 double image_gamma = TIFF_GAMMA;
47 int i, j;
48 TIFF * tif;
49 unsigned char * scan_line;
50 uint16 red[CMSIZE], green[CMSIZE], blue[CMSIZE];
51 float refblackwhite[2*3];
52
53 programName = argv[0];
54
55 switch (argc) {
56 case 2:
57 image_gamma = TIFF_GAMMA;
58 input_file = argv[1];
59 break;
60 case 4:
61 if (!strcmp(argv[1], "-gamma")) {
62 image_gamma = atof(argv[2]);
63 input_file = argv[3];
64 } else
65 Usage();
66 break;
67 default:
68 Usage();
69 }
70
71 for (i = 0; i < CMSIZE; i++) {
72 if (i == 0)
73 red[i] = green[i] = blue[i] = 0;
74 else {
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));
78 }
79 }
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;
83
84 if ((tif = TIFFOpen(input_file, "w")) == NULL) {
85 fprintf(stderr, "can't open %s as a TIFF file\n", input_file);
86 exit(0);
87 }
88
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);
98#ifdef notdef
99 TIFFSetField(tif, TIFFTAG_WHITEPOINT, whitex, whitey);
100 TIFFSetField(tif, TIFFTAG_PRIMARYCHROMATICITIES, primaries);
101#endif
102 TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, refblackwhite);
103 TIFFSetField(tif, TIFFTAG_TRANSFERFUNCTION, red, green, blue);
104
105 scan_line = (unsigned char *) malloc(WIDTH * 3);
106
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;
112 }
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;
117 }
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;
122 }
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;
127 }
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;
132 }
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;
137 }
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;
142 }
143 TIFFWriteScanline(tif, scan_line, i, 0);
144 }
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;
150 }
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;
155 }
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;
160 }
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;
165 }
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;
170 }
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;
175 }
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;
180 }
181 TIFFWriteScanline(tif, scan_line, i, 0);
182 }
183
184 free(scan_line);
185 TIFFClose(tif);
186 exit(0);
187}
188
189void
190Usage()
191{
192 fprintf(stderr, "Usage: %s -gamma gamma tiff-image\n", programName);
193 exit(0);
194}