1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * generate_striped_pages.c
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2010 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
26 /*! \file */
27
28 /*
29 This program generates an TIFF image as a number of small image striped, rather than
30 the usual all in one page FAX images usually consist of in TIFF files.
31 */
32
33 #if defined(HAVE_CONFIG_H)
34 #include "config.h"
35 #endif
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 #include "spandsp.h"
55
56 #define IMAGE_WIDTH 1728
57 #define IMAGE_LENGTH 2600
58 #define ROWS_PER_STRIPE 37
59
main(int argc,char * argv[])60 int main(int argc, char *argv[])
61 {
62 TIFF *tiff_file;
63 uint8_t image_buffer[10000];
64 int image_size;
65 time_t now;
66 struct tm *tm;
67 char buf[256 + 1];
68 int i;
69
70 if ((tiff_file = TIFFOpen("striped.tif", "w")) == NULL)
71 return -1;
72
73 TIFFSetField(tiff_file, TIFFTAG_COMPRESSION, COMPRESSION_CCITT_T6);
74 TIFFSetField(tiff_file, TIFFTAG_BITSPERSAMPLE, 1);
75 TIFFSetField(tiff_file, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
76 TIFFSetField(tiff_file, TIFFTAG_SAMPLESPERPIXEL, 1);
77 TIFFSetField(tiff_file, TIFFTAG_ROWSPERSTRIP, (int32_t) ROWS_PER_STRIPE);
78 TIFFSetField(tiff_file, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
79 TIFFSetField(tiff_file, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
80 TIFFSetField(tiff_file, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB);
81 TIFFSetField(tiff_file, TIFFTAG_XRESOLUTION, 204.0f);
82 TIFFSetField(tiff_file, TIFFTAG_YRESOLUTION, 196.0f);
83 TIFFSetField(tiff_file, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
84 TIFFSetField(tiff_file, TIFFTAG_FAXSUBADDRESS, "1111");
85
86 if (gethostname(buf, sizeof(buf)) == 0)
87 TIFFSetField(tiff_file, TIFFTAG_HOSTCOMPUTER, buf);
88
89 TIFFSetField(tiff_file, TIFFTAG_SOFTWARE, "Spandsp");
90 TIFFSetField(tiff_file, TIFFTAG_IMAGEDESCRIPTION, "Image in stripes");
91 TIFFSetField(tiff_file, TIFFTAG_MAKE, "soft-switch.org");
92 TIFFSetField(tiff_file, TIFFTAG_MODEL, "testy");
93
94 time(&now);
95 tm = localtime(&now);
96 sprintf(buf,
97 "%4d/%02d/%02d %02d:%02d:%02d",
98 tm->tm_year + 1900,
99 tm->tm_mon + 1,
100 tm->tm_mday,
101 tm->tm_hour,
102 tm->tm_min,
103 tm->tm_sec);
104 TIFFSetField(tiff_file, TIFFTAG_DATETIME, buf);
105 TIFFSetField(tiff_file, TIFFTAG_FAXRECVTIME, 10);
106 TIFFSetField(tiff_file, TIFFTAG_IMAGEWIDTH, IMAGE_WIDTH);
107 TIFFSetField(tiff_file, TIFFTAG_IMAGELENGTH, IMAGE_LENGTH);
108 TIFFSetField(tiff_file, TIFFTAG_PAGENUMBER, 0, 1);
109 TIFFCheckpointDirectory(tiff_file);
110
111 image_size = IMAGE_WIDTH*ROWS_PER_STRIPE/8;
112 memset(image_buffer, 0x18, image_size);
113
114 for (i = 0; i*ROWS_PER_STRIPE < IMAGE_LENGTH; i++)
115 {
116 if (IMAGE_LENGTH > (i + 1)*ROWS_PER_STRIPE)
117 image_size = IMAGE_WIDTH*ROWS_PER_STRIPE/8;
118 else
119 image_size = IMAGE_WIDTH*(IMAGE_LENGTH - i*ROWS_PER_STRIPE)/8;
120 if (TIFFWriteEncodedStrip(tiff_file, i, image_buffer, image_size) < 0)
121 return -1;
122 }
123
124 TIFFWriteDirectory(tiff_file);
125 TIFFClose(tiff_file);
126 return 0;
127 }
128