• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Private image library definitions for CUPS.
3  *
4  *   Copyright 2007-2010 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 
13 #ifndef _CUPS_IMAGE_PRIVATE_H_
14 #  define _CUPS_IMAGE_PRIVATE_H_
15 
16 /*
17  * Include necessary headers...
18  */
19 
20 #  include <config.h>
21 #  include "image.h"
22 #  include <cups/cups.h>
23 #  define DEBUG_printf(x)
24 #  define DEBUG_puts(x)
25 #  include <stdlib.h>
26 #  include <string.h>
27 #  include <ctype.h>
28 #  ifdef WIN32
29 #    include <io.h>
30 #  else
31 #    include <unistd.h>
32 #  endif /* WIN32 */
33 #  include <errno.h>
34 #  include <math.h>
35 
36 #ifdef HAVE_EXIF
37 #	include <libexif/exif-data.h>
38 #endif
39 
40 /*
41  * Constants...
42  */
43 
44 #  define CUPS_IMAGE_MAX_WIDTH	0x07ffffff
45 					/* 2^27-1 to allow for 15-channel data */
46 #  define CUPS_IMAGE_MAX_HEIGHT	0x3fffffff
47 					/* 2^30-1 */
48 
49 #  define CUPS_TILE_SIZE	256	/* 256x256 pixel tiles */
50 #  define CUPS_TILE_MINIMUM	10	/* Minimum number of tiles */
51 
52 
53 /*
54  * min/max/abs macros...
55  */
56 
57 #  ifndef max
58 #    define 	max(a,b)	((a) > (b) ? (a) : (b))
59 #  endif /* !max */
60 #  ifndef min
61 #    define 	min(a,b)	((a) < (b) ? (a) : (b))
62 #  endif /* !min */
63 #  ifndef abs
64 #    define	abs(a)		((a) < 0 ? -(a) : (a))
65 #  endif /* !abs */
66 
67 
68 /*
69  * Types and structures...
70  */
71 
72 typedef enum cups_iztype_e		/**** Image zoom type ****/
73 {
74   CUPS_IZOOM_FAST,			/* Use nearest-neighbor sampling */
75   CUPS_IZOOM_NORMAL,			/* Use bilinear interpolation */
76   CUPS_IZOOM_BEST			/* Use bicubic interpolation */
77 } cups_iztype_t;
78 
79 struct cups_ic_s;
80 
81 typedef struct cups_itile_s		/**** Image tile ****/
82 {
83   int			dirty;		/* True if tile is dirty */
84   off_t			pos;		/* Position of tile on disk (-1 if not written) */
85   struct cups_ic_s	*ic;		/* Pixel data */
86 } cups_itile_t;
87 
88 typedef struct cups_ic_s		/**** Image tile cache ****/
89 {
90   struct cups_ic_s	*prev,		/* Previous tile in cache */
91 			*next;		/* Next tile in cache */
92   cups_itile_t		*tile;		/* Tile this is attached to */
93   cups_ib_t		*pixels;	/* Pixel data */
94 } cups_ic_t;
95 
96 struct cups_image_s			/**** Image file data ****/
97 {
98   cups_icspace_t	colorspace;	/* Colorspace of image */
99   unsigned		xsize,		/* Width of image in pixels */
100 			ysize,		/* Height of image in pixels */
101 			xppi,		/* X resolution in pixels-per-inch */
102 			yppi,		/* Y resolution in pixels-per-inch */
103 			num_ics,	/* Number of cached tiles */
104 			max_ics;	/* Maximum number of cached tiles */
105   cups_itile_t		**tiles;	/* Tiles in image */
106   cups_ic_t		*first,		/* First cached tile in image */
107 			*last;		/* Last cached tile in image */
108   int			cachefile;	/* Tile cache file */
109   char			cachename[256];	/* Tile cache filename */
110 };
111 
112 struct cups_izoom_s			/**** Image zoom data ****/
113 {
114   cups_image_t		*img;		/* Image to zoom */
115   cups_iztype_t		type;		/* Type of zooming */
116   unsigned		xorig,		/* X origin */
117 			yorig,		/* Y origin */
118 			width,		/* Width of input area */
119 			height,		/* Height of input area */
120 			depth,		/* Number of bytes per pixel */
121 			rotated,	/* Non-zero if image needs to be rotated */
122 			xsize,		/* Width of output image */
123 			ysize,		/* Height of output image */
124 			xmax,		/* Maximum input image X position */
125 			ymax,		/* Maximum input image Y position */
126 			xmod,		/* Threshold for Bresenheim rounding */
127 			ymod;		/* ... */
128   int			xstep,		/* Amount to step for each pixel along X */
129 			xincr,
130 			instep,		/* Amount to step pixel pointer along X */
131 			inincr,
132 			ystep,		/* Amount to step for each pixel along Y */
133 			yincr,
134 			row;		/* Current row */
135   cups_ib_t		*rows[2],	/* Horizontally scaled pixel data */
136 			*in;		/* Unscaled input pixel data */
137 };
138 
139 
140 /*
141  * Prototypes...
142  */
143 
144 extern int		_cupsImagePutCol(cups_image_t *img, int x, int y,
145 			                 int height, const cups_ib_t *pixels);
146 extern int		_cupsImagePutRow(cups_image_t *img, int x, int y,
147 			                 int width, const cups_ib_t *pixels);
148 extern int		_cupsImageReadBMP(cups_image_t *img, FILE *fp,
149 			                  cups_icspace_t primary,
150 					  cups_icspace_t secondary,
151 			                  int saturation, int hue,
152 					  const cups_ib_t *lut);
153 extern int		_cupsImageReadFPX(cups_image_t *img, FILE *fp,
154 			                  cups_icspace_t primary,
155 					  cups_icspace_t secondary,
156 			                  int saturation, int hue,
157 					  const cups_ib_t *lut);
158 extern int		_cupsImageReadGIF(cups_image_t *img, FILE *fp,
159 			                  cups_icspace_t primary,
160 					  cups_icspace_t secondary,
161 			                  int saturation, int hue,
162 					  const cups_ib_t *lut);
163 extern int		_cupsImageReadJPEG(cups_image_t *img, FILE *fp,
164 			                   cups_icspace_t primary,
165 					   cups_icspace_t secondary,
166 			                   int saturation, int hue,
167 					   const cups_ib_t *lut);
168 extern int		_cupsImageReadPIX(cups_image_t *img, FILE *fp,
169 			                  cups_icspace_t primary,
170 					  cups_icspace_t secondary,
171 			                  int saturation, int hue,
172 					  const cups_ib_t *lut);
173 extern int		_cupsImageReadPNG(cups_image_t *img, FILE *fp,
174 			                  cups_icspace_t primary,
175 					  cups_icspace_t secondary,
176 			                  int saturation, int hue,
177 					  const cups_ib_t *lut);
178 extern int		_cupsImageReadPNM(cups_image_t *img, FILE *fp,
179 			                  cups_icspace_t primary,
180 					  cups_icspace_t secondary,
181 			                  int saturation, int hue,
182 					  const cups_ib_t *lut);
183 extern int		_cupsImageReadPhotoCD(cups_image_t *img, FILE *fp,
184 			                      cups_icspace_t primary,
185 			                      cups_icspace_t secondary,
186 					      int saturation, int hue,
187 					      const cups_ib_t *lut);
188 extern int		_cupsImageReadSGI(cups_image_t *img, FILE *fp,
189 			                  cups_icspace_t primary,
190 					  cups_icspace_t secondary,
191 			                  int saturation, int hue,
192 					  const cups_ib_t *lut);
193 extern int		_cupsImageReadSunRaster(cups_image_t *img, FILE *fp,
194 			                        cups_icspace_t primary,
195 			                        cups_icspace_t secondary,
196 						int saturation, int hue,
197 					        const cups_ib_t *lut);
198 extern int		_cupsImageReadTIFF(cups_image_t *img, FILE *fp,
199 			                   cups_icspace_t primary,
200 					   cups_icspace_t secondary,
201 			                   int saturation, int hue,
202 					   const cups_ib_t *lut);
203 extern void		_cupsImageZoomDelete(cups_izoom_t *z);
204 extern void		_cupsImageZoomFill(cups_izoom_t *z, int iy);
205 extern cups_izoom_t	*_cupsImageZoomNew(cups_image_t *img, int xc0, int yc0,
206 			                   int xc1, int yc1, int xsize,
207 					   int ysize, int rotated,
208 					   cups_iztype_t type);
209 
210 extern int		_cupsRasterExecPS(cups_page_header2_t *h,
211 			                  int *preferred_bits,
212 			                  const char *code);
213 extern void		_cupsRasterAddError(const char *f, ...);
214 extern void		_cupsRasterClearError(void);
215 
216 #ifdef HAVE_EXIF
217 int		_cupsImageReadEXIF(cups_image_t *img, FILE *fp);
218 #endif
219 
220 #endif /* !_CUPS_IMAGE_PRIVATE_H_ */
221 
222