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