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