]> git.ipfire.org Git - thirdparty/cups.git/blame - filter/testimage.c
Load cups into easysw/current.
[thirdparty/cups.git] / filter / testimage.c
CommitLineData
ef416fc2 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 *
e1d6a774 6 * Copyright 1993-2006 by Easy Software Products.
ef416fc2 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
e1d6a774 42int /* O - Exit status */
43main(int argc, /* I - Number of command-line arguments */
44 char *argv[]) /* I - Command-line arguments */
ef416fc2 45{
e1d6a774 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 */
ef416fc2 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)
e1d6a774 63 primary = CUPS_IMAGE_RGB;
ef416fc2 64 else
e1d6a774 65 primary = CUPS_IMAGE_WHITE;
ef416fc2 66
e1d6a774 67 img = cupsImageOpen(argv[1], primary, CUPS_IMAGE_WHITE, 100, 0, NULL);
ef416fc2 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]);
e1d6a774 80 cupsImageClose(img);
ef416fc2 81 return (1);
82 }
83
e1d6a774 84 width = cupsImageGetWidth(img);
85 height = cupsImageGetHeight(img);
86 depth = cupsImageGetDepth(img);
87 line = calloc(width, depth);
ef416fc2 88
e1d6a774 89 fprintf(out, "P%d\n%d\n%d\n255\n",
90 cupsImageGetColorSpace(img) == CUPS_IMAGE_WHITE ? 5 : 6,
91 width, height);
ef416fc2 92
e1d6a774 93 for (y = 0; y < height; y ++)
ef416fc2 94 {
e1d6a774 95 cupsImageGetRow(img, 0, y, width, line);
96 fwrite(line, width, depth, out);
ef416fc2 97 }
98
e1d6a774 99 cupsImageClose(img);
ef416fc2 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 */