Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/test-data/itu/fax/generate_sized_pages.c @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 15:50:58 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
---|---|
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.3 2009/03/01 12:39:02 steveu Exp $ | |
27 */ | |
28 | |
29 /*! \file */ | |
30 | |
31 #if defined(HAVE_CONFIG_H) | |
32 #include "config.h" | |
33 #endif | |
34 | |
35 #include <stdio.h> | |
36 #include <inttypes.h> | |
37 #include <limits.h> | |
38 #include <unistd.h> | |
39 #include <fcntl.h> | |
40 #include <stdlib.h> | |
41 #include <time.h> | |
42 #include <memory.h> | |
43 #include <string.h> | |
44 #if defined(HAVE_TGMATH_H) | |
45 #include <tgmath.h> | |
46 #endif | |
47 #if defined(HAVE_MATH_H) | |
48 #include <math.h> | |
49 #endif | |
50 | |
51 #include "spandsp.h" | |
52 | |
53 struct | |
54 { | |
55 const char *name; | |
56 int x_res; | |
57 int y_res; | |
58 int width; | |
59 int length; | |
60 } sequence[] = | |
61 { | |
62 { | |
63 "R8_385_A4.tif", | |
64 T4_X_RESOLUTION_R8, | |
65 T4_Y_RESOLUTION_STANDARD, | |
66 T4_WIDTH_R8_A4, | |
67 1100 | |
68 }, | |
69 { | |
70 "R8_385_B4.tif", | |
71 T4_X_RESOLUTION_R8, | |
72 T4_Y_RESOLUTION_STANDARD, | |
73 T4_WIDTH_R8_B4, | |
74 1200 | |
75 }, | |
76 { | |
77 "R8_385_A3.tif", | |
78 T4_X_RESOLUTION_R8, | |
79 T4_Y_RESOLUTION_STANDARD, | |
80 T4_WIDTH_R8_A3, | |
81 1556 | |
82 }, | |
83 { | |
84 "R8_77_A4.tif", | |
85 T4_X_RESOLUTION_R8, | |
86 T4_Y_RESOLUTION_FINE, | |
87 T4_WIDTH_R8_A4, | |
88 2200 | |
89 }, | |
90 { | |
91 "R8_77_B4.tif", | |
92 T4_X_RESOLUTION_R8, | |
93 T4_Y_RESOLUTION_FINE, | |
94 T4_WIDTH_R8_B4, | |
95 2400 | |
96 }, | |
97 { | |
98 "R8_77_A3.tif", | |
99 T4_X_RESOLUTION_R8, | |
100 T4_Y_RESOLUTION_FINE, | |
101 T4_WIDTH_R8_A3, | |
102 3111 | |
103 }, | |
104 { | |
105 "R8_154_A4.tif", | |
106 T4_X_RESOLUTION_R8, | |
107 T4_Y_RESOLUTION_SUPERFINE, | |
108 T4_WIDTH_R8_A4, | |
109 4400 | |
110 }, | |
111 { | |
112 "R8_154_B4.tif", | |
113 T4_X_RESOLUTION_R8, | |
114 T4_Y_RESOLUTION_SUPERFINE, | |
115 T4_WIDTH_R8_B4, | |
116 4800 | |
117 }, | |
118 { | |
119 "R8_154_A3.tif", | |
120 T4_X_RESOLUTION_R8, | |
121 T4_Y_RESOLUTION_SUPERFINE, | |
122 T4_WIDTH_R8_A3, | |
123 6222 | |
124 }, | |
125 { | |
126 "R300_300_A4.tif", | |
127 T4_X_RESOLUTION_300, | |
128 T4_Y_RESOLUTION_300, | |
129 T4_WIDTH_300_A4, | |
130 4400 | |
131 }, | |
132 { | |
133 "R300_300_B4.tif", | |
134 T4_X_RESOLUTION_300, | |
135 T4_Y_RESOLUTION_300, | |
136 T4_WIDTH_300_B4, | |
137 4800 | |
138 }, | |
139 { | |
140 "R300_300_A3.tif", | |
141 T4_X_RESOLUTION_300, | |
142 T4_Y_RESOLUTION_300, | |
143 T4_WIDTH_300_A3, | |
144 6222 | |
145 }, | |
146 { | |
147 "R300_600_A4.tif", | |
148 T4_X_RESOLUTION_300, | |
149 T4_Y_RESOLUTION_600, | |
150 T4_WIDTH_300_A4, | |
151 4400 | |
152 }, | |
153 { | |
154 "R300_600_B4.tif", | |
155 T4_X_RESOLUTION_300, | |
156 T4_Y_RESOLUTION_600, | |
157 T4_WIDTH_300_B4, | |
158 4800 | |
159 }, | |
160 { | |
161 "R300_600_A3.tif", | |
162 T4_X_RESOLUTION_300, | |
163 T4_Y_RESOLUTION_600, | |
164 T4_WIDTH_300_A3, | |
165 6222 | |
166 }, | |
167 { | |
168 "R16_154_A4.tif", | |
169 T4_X_RESOLUTION_R16, | |
170 T4_Y_RESOLUTION_SUPERFINE, | |
171 T4_WIDTH_R16_A4, | |
172 4400 | |
173 }, | |
174 { | |
175 "R16_154_B4.tif", | |
176 T4_X_RESOLUTION_R16, | |
177 T4_Y_RESOLUTION_SUPERFINE, | |
178 T4_WIDTH_R16_B4, | |
179 4800 | |
180 }, | |
181 { | |
182 "R16_154_A3.tif", | |
183 T4_X_RESOLUTION_R16, | |
184 T4_Y_RESOLUTION_SUPERFINE, | |
185 T4_WIDTH_R16_A3, | |
186 6222 | |
187 }, | |
188 { | |
189 "R16_800_A4.tif", | |
190 T4_X_RESOLUTION_R16, | |
191 T4_Y_RESOLUTION_800, | |
192 T4_WIDTH_R16_A4, | |
193 4400 | |
194 }, | |
195 { | |
196 "R16_800_B4.tif", | |
197 T4_X_RESOLUTION_R16, | |
198 T4_Y_RESOLUTION_800, | |
199 T4_WIDTH_R16_B4, | |
200 4800 | |
201 }, | |
202 { | |
203 "R16_800_A3.tif", | |
204 T4_X_RESOLUTION_R16, | |
205 T4_Y_RESOLUTION_800, | |
206 T4_WIDTH_R16_A3, | |
207 6222 | |
208 }, | |
209 { | |
210 "R600_600_A4.tif", | |
211 T4_X_RESOLUTION_600, | |
212 T4_Y_RESOLUTION_600, | |
213 T4_WIDTH_600_A4, | |
214 4400 | |
215 }, | |
216 { | |
217 "R600_600_B4.tif", | |
218 T4_X_RESOLUTION_600, | |
219 T4_Y_RESOLUTION_600, | |
220 T4_WIDTH_600_B4, | |
221 4800 | |
222 }, | |
223 { | |
224 "R600_600_A3.tif", | |
225 T4_X_RESOLUTION_600, | |
226 T4_Y_RESOLUTION_600, | |
227 T4_WIDTH_600_A3, | |
228 6222 | |
229 }, | |
230 { | |
231 "R600_1200_A4.tif", | |
232 T4_X_RESOLUTION_600, | |
233 T4_Y_RESOLUTION_1200, | |
234 T4_WIDTH_600_A4, | |
235 4400 | |
236 }, | |
237 { | |
238 "R600_1200_B4.tif", | |
239 T4_X_RESOLUTION_600, | |
240 T4_Y_RESOLUTION_1200, | |
241 T4_WIDTH_600_B4, | |
242 4800 | |
243 }, | |
244 { | |
245 "R600_1200_A3.tif", | |
246 T4_X_RESOLUTION_600, | |
247 T4_Y_RESOLUTION_1200, | |
248 T4_WIDTH_600_A3, | |
249 6222 | |
250 }, | |
251 { | |
252 "R1200_1200_A4.tif", | |
253 T4_X_RESOLUTION_1200, | |
254 T4_Y_RESOLUTION_1200, | |
255 T4_WIDTH_1200_A4, | |
256 4400 | |
257 }, | |
258 { | |
259 "R1200_1200_B4.tif", | |
260 T4_X_RESOLUTION_1200, | |
261 T4_Y_RESOLUTION_1200, | |
262 T4_WIDTH_1200_B4, | |
263 4800 | |
264 }, | |
265 { | |
266 "R1200_1200_A3.tif", | |
267 T4_X_RESOLUTION_1200, | |
268 T4_Y_RESOLUTION_1200, | |
269 T4_WIDTH_1200_A3, | |
270 6222 | |
271 }, | |
272 { | |
273 NULL, | |
274 0, | |
275 0, | |
276 0, | |
277 0 | |
278 }, | |
279 }; | |
280 | |
281 int main(int argc, char *argv[]) | |
282 { | |
283 int row; | |
284 uint8_t image_buffer[8192]; | |
285 TIFF *tiff_file; | |
286 struct tm *tm; | |
287 time_t now; | |
288 char buf[133]; | |
289 float x_resolution; | |
290 float y_resolution; | |
291 int i; | |
292 int opt; | |
293 int compression; | |
294 int photo_metric; | |
295 int fill_order; | |
296 | |
297 compression = T4_COMPRESSION_ITU_T6; | |
298 photo_metric = PHOTOMETRIC_MINISWHITE; | |
299 fill_order = FILLORDER_LSB2MSB; | |
300 while ((opt = getopt(argc, argv, "126ir")) != -1) | |
301 { | |
302 switch (opt) | |
303 { | |
304 case '1': | |
305 compression = T4_COMPRESSION_ITU_T4_1D; | |
306 break; | |
307 case '2': | |
308 compression = T4_COMPRESSION_ITU_T4_2D; | |
309 break; | |
310 case '6': | |
311 compression = T4_COMPRESSION_ITU_T6; | |
312 break; | |
313 case 'i': | |
314 photo_metric = PHOTOMETRIC_MINISBLACK; | |
315 break; | |
316 case 'r': | |
317 fill_order = FILLORDER_MSB2LSB; | |
318 break; | |
319 default: | |
320 //usage(); | |
321 exit(2); | |
322 break; | |
323 } | |
324 } | |
325 | |
326 for (i = 0; sequence[i].name; i++) | |
327 { | |
328 if ((tiff_file = TIFFOpen(sequence[i].name, "w")) == NULL) | |
329 exit(2); | |
330 | |
331 /* Prepare the directory entry fully before writing the image, or libtiff complains */ | |
332 TIFFSetField(tiff_file, TIFFTAG_COMPRESSION, compression); | |
333 TIFFSetField(tiff_file, TIFFTAG_IMAGEWIDTH, sequence[i].width); | |
334 TIFFSetField(tiff_file, TIFFTAG_BITSPERSAMPLE, 1); | |
335 TIFFSetField(tiff_file, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); | |
336 TIFFSetField(tiff_file, TIFFTAG_SAMPLESPERPIXEL, 1); | |
337 TIFFSetField(tiff_file, TIFFTAG_ROWSPERSTRIP, -1L); | |
338 TIFFSetField(tiff_file, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); | |
339 TIFFSetField(tiff_file, TIFFTAG_PHOTOMETRIC, photo_metric); | |
340 TIFFSetField(tiff_file, TIFFTAG_FILLORDER, fill_order); | |
341 | |
342 x_resolution = sequence[i].x_res/100.0f; | |
343 y_resolution = sequence[i].y_res/100.0f; | |
344 TIFFSetField(tiff_file, TIFFTAG_XRESOLUTION, floorf(x_resolution*2.54f + 0.5f)); | |
345 TIFFSetField(tiff_file, TIFFTAG_YRESOLUTION, floorf(y_resolution*2.54f + 0.5f)); | |
346 TIFFSetField(tiff_file, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); | |
347 | |
348 TIFFSetField(tiff_file, TIFFTAG_SOFTWARE, "spandsp"); | |
349 if (gethostname(buf, sizeof(buf)) == 0) | |
350 TIFFSetField(tiff_file, TIFFTAG_HOSTCOMPUTER, buf); | |
351 | |
352 TIFFSetField(tiff_file, TIFFTAG_IMAGEDESCRIPTION, "Blank test image"); | |
353 TIFFSetField(tiff_file, TIFFTAG_MAKE, "soft-switch.org"); | |
354 TIFFSetField(tiff_file, TIFFTAG_MODEL, "test data"); | |
355 | |
356 time(&now); | |
357 tm = localtime(&now); | |
358 sprintf(buf, | |
359 "%4d/%02d/%02d %02d:%02d:%02d", | |
360 tm->tm_year + 1900, | |
361 tm->tm_mon + 1, | |
362 tm->tm_mday, | |
363 tm->tm_hour, | |
364 tm->tm_min, | |
365 tm->tm_sec); | |
366 TIFFSetField(tiff_file, TIFFTAG_DATETIME, buf); | |
367 | |
368 TIFFSetField(tiff_file, TIFFTAG_IMAGELENGTH, sequence[i].length); | |
369 TIFFSetField(tiff_file, TIFFTAG_PAGENUMBER, 0, 1); | |
370 TIFFSetField(tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_CLEAN); | |
371 TIFFSetField(tiff_file, TIFFTAG_IMAGEWIDTH, sequence[i].width); | |
372 | |
373 /* Write the image first.... */ | |
374 for (row = 0; row < sequence[i].length; row++) | |
375 { | |
376 memset(image_buffer, 0, sequence[i].width/8 + 1); | |
377 if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0) | |
378 { | |
379 printf("Write error at row %d.\n", row); | |
380 exit(2); | |
381 } | |
382 } | |
383 /* ....then the directory entry, and libtiff is happy. */ | |
384 TIFFWriteDirectory(tiff_file); | |
385 TIFFClose(tiff_file); | |
386 } | |
387 return 0; | |
388 } | |
389 /*- End of function --------------------------------------------------------*/ | |
390 /*- End of file ------------------------------------------------------------*/ |