5
|
1 /*
|
|
2 * SpanDSP - a series of DSP components for telephony
|
|
3 *
|
|
4 * generate_sized_pages.c - Create a series of TIFF files in the various page sizes
|
|
5 * and resolutions.
|
|
6 *
|
|
7 * Written by Steve Underwood <steveu@coppice.org>
|
|
8 *
|
|
9 * Copyright (C) 2006 Steve Underwood
|
|
10 *
|
|
11 * All rights reserved.
|
|
12 *
|
|
13 * This program is free software; you can redistribute it and/or modify
|
|
14 * it under the terms of the GNU General Public License version 2, as
|
|
15 * published by the Free Software Foundation.
|
|
16 *
|
|
17 * This program is distributed in the hope that it will be useful,
|
|
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 * GNU General Public License for more details.
|
|
21 *
|
|
22 * You should have received a copy of the GNU General Public License
|
|
23 * along with this program; if not, write to the Free Software
|
|
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
25 *
|
|
26 * $Id: generate_sized_pages.c,v 1.4 2006/11/20 00:00:27 steveu Exp $
|
|
27 */
|
|
28
|
|
29 /*! \file */
|
|
30
|
|
31 #ifdef HAVE_CONFIG_H
|
|
32 #include "config.h"
|
|
33 #endif
|
|
34
|
|
35 #define _GNU_SOURCE
|
|
36
|
|
37 #include <stdio.h>
|
|
38 #include <inttypes.h>
|
|
39 #include <limits.h>
|
|
40 #include <unistd.h>
|
|
41 #include <fcntl.h>
|
|
42 #include <stdlib.h>
|
|
43 #include <time.h>
|
|
44 #include <memory.h>
|
|
45 #include <string.h>
|
|
46 #if defined(HAVE_TGMATH_H)
|
|
47 #include <tgmath.h>
|
|
48 #endif
|
|
49 #if defined(HAVE_MATH_H)
|
|
50 #include <math.h>
|
|
51 #endif
|
|
52 #include <tiffio.h>
|
|
53
|
|
54 #define T4_X_RESOLUTION_R4 4019
|
|
55 #define T4_X_RESOLUTION_R8 8037
|
|
56 #define T4_X_RESOLUTION_R16 16074
|
|
57
|
|
58 #define T4_Y_RESOLUTION_STANDARD 3850
|
|
59 #define T4_Y_RESOLUTION_FINE 7700
|
|
60 #define T4_Y_RESOLUTION_SUPERFINE 15400
|
|
61
|
|
62 struct
|
|
63 {
|
|
64 const char *name;
|
|
65 int x_res;
|
|
66 int y_res;
|
|
67 int width;
|
|
68 int length;
|
|
69 } sequence[] =
|
|
70 {
|
|
71 {
|
|
72 "R8_385_A4.tif",
|
|
73 T4_X_RESOLUTION_R8,
|
|
74 T4_Y_RESOLUTION_STANDARD,
|
|
75 1728,
|
|
76 1100
|
|
77 },
|
|
78 {
|
|
79 "R16_385_A4.tif",
|
|
80 T4_X_RESOLUTION_R16,
|
|
81 T4_Y_RESOLUTION_STANDARD,
|
|
82 3456,
|
|
83 1100
|
|
84 },
|
|
85 {
|
|
86 "R8_77_A4.tif",
|
|
87 T4_X_RESOLUTION_R8,
|
|
88 T4_Y_RESOLUTION_FINE,
|
|
89 1728,
|
|
90 2200
|
|
91 },
|
|
92 {
|
|
93 "R16_77_A4.tif",
|
|
94 T4_X_RESOLUTION_R16,
|
|
95 T4_Y_RESOLUTION_FINE,
|
|
96 3456,
|
|
97 2200
|
|
98 },
|
|
99 {
|
|
100 "R8_154_A4.tif",
|
|
101 T4_X_RESOLUTION_R8,
|
|
102 T4_Y_RESOLUTION_SUPERFINE,
|
|
103 1728,
|
|
104 4400
|
|
105 },
|
|
106 {
|
|
107 "R16_154_A4.tif",
|
|
108 T4_X_RESOLUTION_R16,
|
|
109 T4_Y_RESOLUTION_SUPERFINE,
|
|
110 3456,
|
|
111 4400
|
|
112 },
|
|
113 {
|
|
114 "R8_385_B4.tif",
|
|
115 T4_X_RESOLUTION_R8,
|
|
116 T4_Y_RESOLUTION_STANDARD,
|
|
117 2048,
|
|
118 1200
|
|
119 },
|
|
120 {
|
|
121 "R16_385_B4.tif",
|
|
122 T4_X_RESOLUTION_R16,
|
|
123 T4_Y_RESOLUTION_STANDARD,
|
|
124 4096,
|
|
125 1200
|
|
126 },
|
|
127 {
|
|
128 "R8_77_B4.tif",
|
|
129 T4_X_RESOLUTION_R8,
|
|
130 T4_Y_RESOLUTION_FINE,
|
|
131 2048,
|
|
132 2400
|
|
133 },
|
|
134 {
|
|
135 "R16_77_B4.tif",
|
|
136 T4_X_RESOLUTION_R16,
|
|
137 T4_Y_RESOLUTION_FINE,
|
|
138 4096,
|
|
139 2400
|
|
140 },
|
|
141 {
|
|
142 "R8_154_B4.tif",
|
|
143 T4_X_RESOLUTION_R8,
|
|
144 T4_Y_RESOLUTION_SUPERFINE,
|
|
145 2048,
|
|
146 4800
|
|
147 },
|
|
148 {
|
|
149 "R16_154_B4.tif",
|
|
150 T4_X_RESOLUTION_R16,
|
|
151 T4_Y_RESOLUTION_SUPERFINE,
|
|
152 4096,
|
|
153 4800
|
|
154 },
|
|
155 {
|
|
156 "R8_385_A3.tif",
|
|
157 T4_X_RESOLUTION_R8,
|
|
158 T4_Y_RESOLUTION_STANDARD,
|
|
159 2432,
|
|
160 1556
|
|
161 },
|
|
162 {
|
|
163 "R16_385_A3.tif",
|
|
164 T4_X_RESOLUTION_R16,
|
|
165 T4_Y_RESOLUTION_STANDARD,
|
|
166 4864,
|
|
167 1556
|
|
168 },
|
|
169 {
|
|
170 "R8_77_A3.tif",
|
|
171 T4_X_RESOLUTION_R8,
|
|
172 T4_Y_RESOLUTION_FINE,
|
|
173 2432,
|
|
174 3111
|
|
175 },
|
|
176 {
|
|
177 "R16_77_A3.tif",
|
|
178 T4_X_RESOLUTION_R16,
|
|
179 T4_Y_RESOLUTION_FINE,
|
|
180 4864,
|
|
181 3111
|
|
182 },
|
|
183 {
|
|
184 "R8_154_A3.tif",
|
|
185 T4_X_RESOLUTION_R8,
|
|
186 T4_Y_RESOLUTION_SUPERFINE,
|
|
187 2432,
|
|
188 6222
|
|
189 },
|
|
190 {
|
|
191 "R16_154_A3.tif",
|
|
192 T4_X_RESOLUTION_R16,
|
|
193 T4_Y_RESOLUTION_SUPERFINE,
|
|
194 4864,
|
|
195 6222
|
|
196 },
|
|
197 {
|
|
198 NULL,
|
|
199 0,
|
|
200 0,
|
|
201 0,
|
|
202 0
|
|
203 },
|
|
204 };
|
|
205
|
|
206 int main(int argc, char *argv[])
|
|
207 {
|
|
208 int row;
|
|
209 uint8_t image_buffer[1024];
|
|
210 TIFF *tiff_file;
|
|
211 struct tm *tm;
|
|
212 time_t now;
|
|
213 char buf[133];
|
|
214 float x_resolution;
|
|
215 float y_resolution;
|
|
216 int i;
|
|
217
|
|
218 for (i = 0; sequence[i].name; i++)
|
|
219 {
|
|
220 if ((tiff_file = TIFFOpen(sequence[i].name, "w")) == NULL)
|
|
221 exit(2);
|
|
222
|
|
223 /* Prepare the directory entry fully before writing the image, or libtiff complains */
|
|
224 TIFFSetField(tiff_file, TIFFTAG_COMPRESSION, COMPRESSION_CCITT_T6);
|
|
225 TIFFSetField(tiff_file, TIFFTAG_IMAGEWIDTH, sequence[i].width);
|
|
226 TIFFSetField(tiff_file, TIFFTAG_BITSPERSAMPLE, 1);
|
|
227 TIFFSetField(tiff_file, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
|
228 TIFFSetField(tiff_file, TIFFTAG_SAMPLESPERPIXEL, 1);
|
|
229 TIFFSetField(tiff_file, TIFFTAG_ROWSPERSTRIP, -1L);
|
|
230 TIFFSetField(tiff_file, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
|
231 TIFFSetField(tiff_file, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
|
|
232 TIFFSetField(tiff_file, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB);
|
|
233
|
|
234 x_resolution = sequence[i].x_res/100.0f;
|
|
235 y_resolution = sequence[i].y_res/100.0f;
|
|
236 TIFFSetField(tiff_file, TIFFTAG_XRESOLUTION, floorf(x_resolution*2.54f + 0.5f));
|
|
237 TIFFSetField(tiff_file, TIFFTAG_YRESOLUTION, floorf(y_resolution*2.54f + 0.5f));
|
|
238 TIFFSetField(tiff_file, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
|
|
239
|
|
240 TIFFSetField(tiff_file, TIFFTAG_SOFTWARE, "spandsp");
|
|
241 if (gethostname(buf, sizeof(buf)) == 0)
|
|
242 TIFFSetField(tiff_file, TIFFTAG_HOSTCOMPUTER, buf);
|
|
243
|
|
244 TIFFSetField(tiff_file, TIFFTAG_IMAGEDESCRIPTION, "Blank test image");
|
|
245 TIFFSetField(tiff_file, TIFFTAG_MAKE, "soft-switch.org");
|
|
246 TIFFSetField(tiff_file, TIFFTAG_MODEL, "test data");
|
|
247
|
|
248 time(&now);
|
|
249 tm = localtime(&now);
|
|
250 sprintf(buf,
|
|
251 "%4d/%02d/%02d %02d:%02d:%02d",
|
|
252 tm->tm_year + 1900,
|
|
253 tm->tm_mon + 1,
|
|
254 tm->tm_mday,
|
|
255 tm->tm_hour,
|
|
256 tm->tm_min,
|
|
257 tm->tm_sec);
|
|
258 TIFFSetField(tiff_file, TIFFTAG_DATETIME, buf);
|
|
259
|
|
260 TIFFSetField(tiff_file, TIFFTAG_IMAGELENGTH, sequence[i].length);
|
|
261 TIFFSetField(tiff_file, TIFFTAG_PAGENUMBER, 0, 1);
|
|
262 TIFFSetField(tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_CLEAN);
|
|
263 TIFFSetField(tiff_file, TIFFTAG_IMAGEWIDTH, sequence[i].width);
|
|
264
|
|
265 /* Write the image first.... */
|
|
266 for (row = 0; row < sequence[i].length; row++)
|
|
267 {
|
|
268 memset(image_buffer, 0, sequence[i].width/8 + 1);
|
|
269 if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
|
|
270 {
|
|
271 printf("Write error at row %d.\n", row);
|
|
272 exit(2);
|
|
273 }
|
|
274 }
|
|
275 /* ....then the directory entry, and libtiff is happy. */
|
|
276 TIFFWriteDirectory(tiff_file);
|
|
277 TIFFClose(tiff_file);
|
|
278 }
|
|
279 return 0;
|
|
280 }
|
|
281 /*- End of function --------------------------------------------------------*/
|
|
282 /*- End of file ------------------------------------------------------------*/
|