]> git.ipfire.org Git - thirdparty/cups.git/blob - filter/testimage.c
Load cups into easysw/current.
[thirdparty/cups.git] / filter / testimage.c
1 /*
2 * "$Id: testimage.c 4485 2005-01-03 19:30:00Z mike $"
3 *
4 * Image library test program for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1993-2006 by Easy Software Products.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * This file is subject to the Apple OS-Developed Software exception.
25 *
26 * Contents:
27 *
28 * main() - Main entry...
29 */
30
31 /*
32 * Include necessary headers...
33 */
34
35 #include "image.h"
36
37
38 /*
39 * 'main()' - Main entry...
40 */
41
42 int /* O - Exit status */
43 main(int argc, /* I - Number of command-line arguments */
44 char *argv[]) /* I - Command-line arguments */
45 {
46 cups_image_t *img; /* Image to print */
47 cups_icspace_t primary; /* Primary image colorspace */
48 FILE *out; /* Output PPM/PGM file */
49 cups_ib_t *line; /* Line from file */
50 int y, /* Current line */
51 width, /* Width of image */
52 height, /* Height of image */
53 depth; /* Depth of image */
54
55
56 if (argc != 3)
57 {
58 puts("Usage: testimage filename.ext filename.[ppm|pgm]");
59 return (1);
60 }
61
62 if (strstr(argv[2], ".ppm") != NULL)
63 primary = CUPS_IMAGE_RGB;
64 else
65 primary = CUPS_IMAGE_WHITE;
66
67 img = cupsImageOpen(argv[1], primary, CUPS_IMAGE_WHITE, 100, 0, NULL);
68
69 if (!img)
70 {
71 perror(argv[1]);
72 return (1);
73 }
74
75 out = fopen(argv[2], "wb");
76
77 if (!out)
78 {
79 perror(argv[2]);
80 cupsImageClose(img);
81 return (1);
82 }
83
84 width = cupsImageGetWidth(img);
85 height = cupsImageGetHeight(img);
86 depth = cupsImageGetDepth(img);
87 line = calloc(width, depth);
88
89 fprintf(out, "P%d\n%d\n%d\n255\n",
90 cupsImageGetColorSpace(img) == CUPS_IMAGE_WHITE ? 5 : 6,
91 width, height);
92
93 for (y = 0; y < height; y ++)
94 {
95 cupsImageGetRow(img, 0, y, width, line);
96 fwrite(line, width, depth, out);
97 }
98
99 cupsImageClose(img);
100 fclose(out);
101
102 return (0);
103 }
104
105
106 /*
107 * End of "$Id: testimage.c 4485 2005-01-03 19:30:00Z mike $".
108 */