Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/test-data/itu/fax/generate_dithered_tif.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_dithered_tif.c - Create a fine checkerboard TIFF file for test purposes. | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2006 Steve Underwood | |
9 * | |
10 * All rights reserved. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License version 2, as | |
14 * published by the Free Software Foundation. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 * | |
25 * $Id: generate_dithered_tif.c,v 1.2 2008/07/10 13:34:01 steveu Exp $ | |
26 */ | |
27 | |
28 /*! \file */ | |
29 | |
30 /* | |
31 This program generates an A4 sized FAX image of a fine checkerboard. This doesn't | |
32 compress well, so it results in a rather large file for a single page. This is | |
33 good for testing the handling of extreme pages. | |
34 | |
35 Note that due to a bug in FAX image handling, versions of libtiff up to 3.8.2 fail | |
36 to handle this complex image properly, if 2-D compression is used. The bug should | |
37 be fixed in CVS at the time of writing, and so should be fixed in released versions | |
38 after 3.8.2. This code uses 1-D compression to avoid the issue. | |
39 */ | |
40 | |
41 #if defined(HAVE_CONFIG_H) | |
42 #include "config.h" | |
43 #endif | |
44 | |
45 #include <stdio.h> | |
46 #include <inttypes.h> | |
47 #include <limits.h> | |
48 #include <unistd.h> | |
49 #include <fcntl.h> | |
50 #include <stdlib.h> | |
51 #include <time.h> | |
52 #include <memory.h> | |
53 #include <string.h> | |
54 #if defined(HAVE_TGMATH_H) | |
55 #include <tgmath.h> | |
56 #endif | |
57 #if defined(HAVE_MATH_H) | |
58 #include <math.h> | |
59 #endif | |
60 #include <tiffio.h> | |
61 | |
62 #include "spandsp.h" | |
63 | |
64 int main(int argc, char *argv[]) | |
65 { | |
66 int image_width; | |
67 int row; | |
68 int resunit; | |
69 int output_compression; | |
70 int output_t4_options; | |
71 uint8_t image_buffer[1024]; | |
72 TIFF *tiff_file; | |
73 struct tm *tm; | |
74 time_t now; | |
75 char buf[133]; | |
76 float x_resolution; | |
77 float y_resolution; | |
78 int x_res; | |
79 int y_res; | |
80 int image_length; | |
81 | |
82 if ((tiff_file = TIFFOpen("dithered.tif", "w")) == NULL) | |
83 exit(2); | |
84 | |
85 output_compression = COMPRESSION_CCITT_T4; | |
86 /* Use 1-D compression until a fixed libtiff is the norm. */ | |
87 //output_t4_options = GROUP3OPT_FILLBITS | GROUP3OPT_2DENCODING; | |
88 output_t4_options = GROUP3OPT_FILLBITS; | |
89 | |
90 x_res = T4_X_RESOLUTION_R8; | |
91 y_res = T4_Y_RESOLUTION_FINE; | |
92 image_width = 1728; | |
93 image_length = 2200; | |
94 | |
95 /* Prepare the directory entry fully before writing the image, or libtiff complains */ | |
96 TIFFSetField(tiff_file, TIFFTAG_COMPRESSION, output_compression); | |
97 if (output_compression == COMPRESSION_CCITT_T4) | |
98 { | |
99 TIFFSetField(tiff_file, TIFFTAG_T4OPTIONS, output_t4_options); | |
100 TIFFSetField(tiff_file, TIFFTAG_FAXMODE, FAXMODE_CLASSF); | |
101 } | |
102 TIFFSetField(tiff_file, TIFFTAG_IMAGEWIDTH, image_width); | |
103 TIFFSetField(tiff_file, TIFFTAG_BITSPERSAMPLE, 1); | |
104 TIFFSetField(tiff_file, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); | |
105 TIFFSetField(tiff_file, TIFFTAG_SAMPLESPERPIXEL, 1); | |
106 TIFFSetField(tiff_file, TIFFTAG_ROWSPERSTRIP, -1L); | |
107 TIFFSetField(tiff_file, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); | |
108 TIFFSetField(tiff_file, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); | |
109 TIFFSetField(tiff_file, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB); | |
110 | |
111 x_resolution = x_res/100.0f; | |
112 y_resolution = y_res/100.0f; | |
113 TIFFSetField(tiff_file, TIFFTAG_XRESOLUTION, floorf(x_resolution*2.54f + 0.5f)); | |
114 TIFFSetField(tiff_file, TIFFTAG_YRESOLUTION, floorf(y_resolution*2.54f + 0.5f)); | |
115 resunit = RESUNIT_INCH; | |
116 TIFFSetField(tiff_file, TIFFTAG_RESOLUTIONUNIT, resunit); | |
117 | |
118 TIFFSetField(tiff_file, TIFFTAG_SOFTWARE, "spandsp"); | |
119 if (gethostname(buf, sizeof(buf)) == 0) | |
120 TIFFSetField(tiff_file, TIFFTAG_HOSTCOMPUTER, buf); | |
121 | |
122 TIFFSetField(tiff_file, TIFFTAG_IMAGEDESCRIPTION, "Checkerboard or dithered ones"); | |
123 TIFFSetField(tiff_file, TIFFTAG_MAKE, "soft-switch.org"); | |
124 TIFFSetField(tiff_file, TIFFTAG_MODEL, "test data"); | |
125 | |
126 time(&now); | |
127 tm = localtime(&now); | |
128 sprintf(buf, | |
129 "%4d/%02d/%02d %02d:%02d:%02d", | |
130 tm->tm_year + 1900, | |
131 tm->tm_mon + 1, | |
132 tm->tm_mday, | |
133 tm->tm_hour, | |
134 tm->tm_min, | |
135 tm->tm_sec); | |
136 TIFFSetField(tiff_file, TIFFTAG_DATETIME, buf); | |
137 | |
138 TIFFSetField(tiff_file, TIFFTAG_IMAGELENGTH, image_length); | |
139 TIFFSetField(tiff_file, TIFFTAG_PAGENUMBER, 0, 1); | |
140 TIFFSetField(tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_CLEAN); | |
141 TIFFSetField(tiff_file, TIFFTAG_IMAGEWIDTH, image_width); | |
142 | |
143 /* Write the image first.... */ | |
144 for (row = 0; row < image_length; row++) | |
145 { | |
146 if ((row & 1) == 0) | |
147 memset(image_buffer, 0xAA, image_width/8 + 1); | |
148 else | |
149 memset(image_buffer, 0x55, image_width/8 + 1); | |
150 if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0) | |
151 { | |
152 printf("Write error at row %d.\n", row); | |
153 exit(2); | |
154 } | |
155 } | |
156 /* ....then the directory entry, and libtiff is happy. */ | |
157 TIFFWriteDirectory(tiff_file); | |
158 TIFFClose(tiff_file); | |
159 return 0; | |
160 } | |
161 /*- End of function --------------------------------------------------------*/ | |
162 /*- End of file ------------------------------------------------------------*/ |