2 * "$Id: image-zoom.c 9502 2011-01-21 23:56:14Z mike $"
4 * cupsImage zoom routines 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 * _cupsImageZoomDelete() - Free a zoom record...
20 * _cupsImageZoomFill() - Fill a zoom record...
21 * _cupsImageZoomNew() - Allocate a pixel zoom record...
22 * zoom_bilinear() - Fill a zoom record with image data utilizing
23 * bilinear interpolation.
24 * zoom_nearest() - Fill a zoom record quickly using nearest-neighbor
29 * Include necessary headers...
32 #include "image-private.h"
39 static void zoom_bilinear(cups_izoom_t *z, int iy);
40 static void zoom_nearest(cups_izoom_t *z, int iy);
44 * '_cupsImageZoomDelete()' - Free a zoom record...
48 _cupsImageZoomDelete(cups_izoom_t *z) /* I - Zoom record to free */
58 * '_cupsImageZoomFill()' - Fill a zoom record with image data utilizing bilinear
63 _cupsImageZoomFill(cups_izoom_t *z, /* I - Zoom record to fill */
64 int iy) /* I - Zoom image row */
68 case CUPS_IZOOM_FAST :
80 * '_cupsImageZoomNew()' - Allocate a pixel zoom record...
85 cups_image_t *img, /* I - cupsImage to zoom */
86 int xc0, /* I - Upper-lefthand corner */
87 int yc0, /* I - ... */
88 int xc1, /* I - Lower-righthand corner */
89 int yc1, /* I - ... */
90 int xsize, /* I - Final width of image */
91 int ysize, /* I - Final height of image */
92 int rotated, /* I - Non-zero if image is rotated 90 degs */
93 cups_iztype_t type) /* I - Zoom type */
95 cups_izoom_t *z; /* New zoom record */
96 int flip; /* Flip on X axis? */
99 if (xsize > CUPS_IMAGE_MAX_WIDTH ||
100 ysize > CUPS_IMAGE_MAX_HEIGHT ||
101 (xc1 - xc0) > CUPS_IMAGE_MAX_WIDTH ||
102 (yc1 - yc0) > CUPS_IMAGE_MAX_HEIGHT)
103 return (NULL); /* Protect against integer overflow */
105 if ((z = (cups_izoom_t *)calloc(1, sizeof(cups_izoom_t))) == NULL)
110 z->depth = cupsImageGetDepth(img);
111 z->rotated = rotated;
128 z->width = yc1 - yc0 + 1;
129 z->height = xc1 - xc0 + 1;
132 z->xmod = z->width % z->xsize;
133 z->xstep = z->width / z->xsize;
135 z->ymod = z->height % z->ysize;
136 z->ystep = z->height / z->ysize;
138 z->instep = z->xstep * z->depth;
139 z->inincr = /* z->xincr * */ z->depth; /* z->xincr is always 1 */
141 if (z->width < img->ysize)
144 z->xmax = z->width - 1;
146 if (z->height < img->xsize)
149 z->ymax = z->height - 1;
155 z->width = xc1 - xc0 + 1;
156 z->height = yc1 - yc0 + 1;
159 z->xmod = z->width % z->xsize;
160 z->xstep = z->width / z->xsize;
162 z->ymod = z->height % z->ysize;
163 z->ystep = z->height / z->ysize;
165 z->instep = z->xstep * z->depth;
166 z->inincr = /* z->xincr * */ z->depth; /* z->xincr is always 1 */
168 if (z->width < img->xsize)
171 z->xmax = z->width - 1;
173 if (z->height < img->ysize)
176 z->ymax = z->height - 1;
181 z->instep = -z->instep;
182 z->inincr = -z->inincr;
185 if ((z->rows[0] = (cups_ib_t *)malloc(z->xsize * z->depth)) == NULL)
191 if ((z->rows[1] = (cups_ib_t *)malloc(z->xsize * z->depth)) == NULL)
198 if ((z->in = (cups_ib_t *)malloc(z->width * z->depth)) == NULL)
211 * 'zoom_bilinear()' - Fill a zoom record with image data utilizing bilinear
216 zoom_bilinear(cups_izoom_t *z, /* I - Zoom record to fill */
217 int iy) /* I - Zoom image row */
219 cups_ib_t *r, /* Row pointer */
220 *inptr; /* Pixel pointer */
221 int xerr0, /* X error counter */
247 z_instep = z->instep;
248 z_inincr = z->inincr;
251 cupsImageGetCol(z->img, z->xorig - iy, z->yorig, z->width, z->in);
253 cupsImageGetRow(z->img, z->xorig, z->yorig + iy, z->width, z->in);
256 inptr = z->in + (z->width - 1) * z_depth;
260 for (x = z_xsize, xerr0 = z_xsize, xerr1 = 0, ix = 0, r = z->rows[z->row];
266 for (count = 0; count < z_depth; count ++)
267 *r++ = (inptr[count] * xerr0 + inptr[z_depth + count] * xerr1) / z_xsize;
271 for (count = 0; count < z_depth; count ++)
292 * 'zoom_nearest()' - Fill a zoom record quickly using nearest-neighbor
297 zoom_nearest(cups_izoom_t *z, /* I - Zoom record to fill */
298 int iy) /* I - Zoom image row */
300 cups_ib_t *r, /* Row pointer */
301 *inptr; /* Pixel pointer */
302 int xerr0; /* X error counter */
325 z_instep = z->instep;
326 z_inincr = z->inincr;
329 cupsImageGetCol(z->img, z->xorig - iy, z->yorig, z->width, z->in);
331 cupsImageGetRow(z->img, z->xorig, z->yorig + iy, z->width, z->in);
334 inptr = z->in + (z->width - 1) * z_depth;
338 for (x = z_xsize, xerr0 = z_xsize, ix = 0, r = z->rows[z->row];
342 for (count = 0; count < z_depth; count ++)
360 * End of "$Id: image-zoom.c 9502 2011-01-21 23:56:14Z mike $".