]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
f7faf1f5 | 2 | * "$Id: testimage.c 4485 2005-01-03 19:30:00Z mike $" |
ef416fc2 | 3 | * |
4 | * Image library test program for the Common UNIX Printing System (CUPS). | |
5 | * | |
bc44d920 | 6 | * Copyright 2007 by Apple Inc. |
e1d6a774 | 7 | * Copyright 1993-2006 by Easy Software Products. |
ef416fc2 | 8 | * |
9 | * These coded instructions, statements, and computer programs are the | |
bc44d920 | 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/". | |
ef416fc2 | 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 | ||
e1d6a774 | 33 | int /* O - Exit status */ |
34 | main(int argc, /* I - Number of command-line arguments */ | |
35 | char *argv[]) /* I - Command-line arguments */ | |
ef416fc2 | 36 | { |
e1d6a774 | 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 */ | |
ef416fc2 | 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) | |
e1d6a774 | 54 | primary = CUPS_IMAGE_RGB; |
ef416fc2 | 55 | else |
e1d6a774 | 56 | primary = CUPS_IMAGE_WHITE; |
ef416fc2 | 57 | |
e1d6a774 | 58 | img = cupsImageOpen(argv[1], primary, CUPS_IMAGE_WHITE, 100, 0, NULL); |
ef416fc2 | 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]); | |
e1d6a774 | 71 | cupsImageClose(img); |
ef416fc2 | 72 | return (1); |
73 | } | |
74 | ||
e1d6a774 | 75 | width = cupsImageGetWidth(img); |
76 | height = cupsImageGetHeight(img); | |
77 | depth = cupsImageGetDepth(img); | |
78 | line = calloc(width, depth); | |
ef416fc2 | 79 | |
e1d6a774 | 80 | fprintf(out, "P%d\n%d\n%d\n255\n", |
81 | cupsImageGetColorSpace(img) == CUPS_IMAGE_WHITE ? 5 : 6, | |
82 | width, height); | |
ef416fc2 | 83 | |
e1d6a774 | 84 | for (y = 0; y < height; y ++) |
ef416fc2 | 85 | { |
e1d6a774 | 86 | cupsImageGetRow(img, 0, y, width, line); |
87 | fwrite(line, width, depth, out); | |
ef416fc2 | 88 | } |
89 | ||
e1d6a774 | 90 | cupsImageClose(img); |
ef416fc2 | 91 | fclose(out); |
92 | ||
93 | return (0); | |
94 | } | |
95 | ||
96 | ||
97 | /* | |
f7faf1f5 | 98 | * End of "$Id: testimage.c 4485 2005-01-03 19:30:00Z mike $". |
ef416fc2 | 99 | */ |