]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/testimage.c
4 * Image library test program for CUPS.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1993-2006 by Easy Software Products.
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/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * main() - Main entry...
23 * Include necessary headers...
30 * 'main()' - Main entry...
33 int /* O - Exit status */
34 main(int argc
, /* I - Number of command-line arguments */
35 char *argv
[]) /* I - Command-line arguments */
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 */
49 puts("Usage: testimage filename.ext filename.[ppm|pgm]");
53 if (strstr(argv
[2], ".ppm") != NULL
)
54 primary
= CUPS_IMAGE_RGB
;
56 primary
= CUPS_IMAGE_WHITE
;
58 img
= cupsImageOpen(argv
[1], primary
, CUPS_IMAGE_WHITE
, 100, 0, NULL
);
66 out
= fopen(argv
[2], "wb");
75 width
= cupsImageGetWidth(img
);
76 height
= cupsImageGetHeight(img
);
77 depth
= cupsImageGetDepth(img
);
78 line
= calloc(width
, depth
);
80 fprintf(out
, "P%d\n%d\n%d\n255\n",
81 cupsImageGetColorSpace(img
) == CUPS_IMAGE_WHITE
? 5 : 6,
84 for (y
= 0; y
< height
; y
++)
86 cupsImageGetRow(img
, 0, y
, width
, line
);
87 fwrite(line
, width
, depth
, out
);