]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/image-zoom.c
2 * "$Id: image-zoom.c 5191 2006-02-27 02:47:56Z mike $"
4 * cupsImage zoom routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2006 by Easy Software Products.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * _cupsImageZoomDelete() - Free a zoom record...
29 * _cupsImageZoomFill() - Fill a zoom record...
30 * _cupsImageZoomNew() - Allocate a pixel zoom record...
31 * zoom_bilinear() - Fill a zoom record with image data utilizing
32 * bilinear interpolation.
33 * zoom_nearest() - Fill a zoom record quickly using nearest-neighbor
38 * Include necessary headers...
41 #include "image-private.h"
48 static void zoom_bilinear(cups_izoom_t
*z
, int iy
);
49 static void zoom_nearest(cups_izoom_t
*z
, int iy
);
53 * '_cupsImageZoomDelete()' - Free a zoom record...
57 _cupsImageZoomDelete(cups_izoom_t
*z
) /* I - Zoom record to free */
67 * '_cupsImageZoomFill()' - Fill a zoom record with image data utilizing bilinear
72 _cupsImageZoomFill(cups_izoom_t
*z
, /* I - Zoom record to fill */
73 int iy
) /* I - Zoom image row */
77 case CUPS_IZOOM_FAST
:
89 * '_cupsImageZoomNew()' - Allocate a pixel zoom record...
94 cups_image_t
*img
, /* I - cupsImage to zoom */
95 int xc0
, /* I - Upper-lefthand corner */
96 int yc0
, /* I - ... */
97 int xc1
, /* I - Lower-righthand corner */
98 int yc1
, /* I - ... */
99 int xsize
, /* I - Final width of image */
100 int ysize
, /* I - Final height of image */
101 int rotated
, /* I - Non-zero if image is rotated 90 degs */
102 cups_iztype_t type
) /* I - Zoom type */
104 cups_izoom_t
*z
; /* New zoom record */
105 int flip
; /* Flip on X axis? */
108 if (xsize
> CUPS_IMAGE_MAX_WIDTH
||
109 ysize
> CUPS_IMAGE_MAX_HEIGHT
||
110 (xc1
- xc0
) > CUPS_IMAGE_MAX_WIDTH
||
111 (yc1
- yc0
) > CUPS_IMAGE_MAX_HEIGHT
)
112 return (NULL
); /* Protect against integer overflow */
114 if ((z
= (cups_izoom_t
*)calloc(1, sizeof(cups_izoom_t
))) == NULL
)
119 z
->depth
= cupsImageGetDepth(img
);
120 z
->rotated
= rotated
;
137 z
->width
= yc1
- yc0
+ 1;
138 z
->height
= xc1
- xc0
+ 1;
141 z
->xmod
= z
->width
% z
->xsize
;
142 z
->xstep
= z
->width
/ z
->xsize
;
144 z
->ymod
= z
->height
% z
->ysize
;
145 z
->ystep
= z
->height
/ z
->ysize
;
147 z
->instep
= z
->xstep
* z
->depth
;
148 z
->inincr
= z
->xincr
* z
->depth
;
150 if (z
->width
< img
->ysize
)
153 z
->xmax
= z
->width
- 1;
155 if (z
->height
< img
->xsize
)
158 z
->ymax
= z
->height
- 1;
164 z
->width
= xc1
- xc0
+ 1;
165 z
->height
= yc1
- yc0
+ 1;
168 z
->xmod
= z
->width
% z
->xsize
;
169 z
->xstep
= z
->width
/ z
->xsize
;
171 z
->ymod
= z
->height
% z
->ysize
;
172 z
->ystep
= z
->height
/ z
->ysize
;
174 z
->instep
= z
->xstep
* z
->depth
;
175 z
->inincr
= z
->xincr
* z
->depth
;
177 if (z
->width
< img
->xsize
)
180 z
->xmax
= z
->width
- 1;
182 if (z
->height
< img
->ysize
)
185 z
->ymax
= z
->height
- 1;
190 z
->instep
= -z
->instep
;
191 z
->inincr
= -z
->inincr
;
194 if ((z
->rows
[0] = (cups_ib_t
*)malloc(z
->xsize
* z
->depth
)) == NULL
)
200 if ((z
->rows
[1] = (cups_ib_t
*)malloc(z
->xsize
* z
->depth
)) == NULL
)
207 if ((z
->in
= (cups_ib_t
*)malloc(z
->width
* z
->depth
)) == NULL
)
220 * 'zoom_bilinear()' - Fill a zoom record with image data utilizing bilinear
225 zoom_bilinear(cups_izoom_t
*z
, /* I - Zoom record to fill */
226 int iy
) /* I - Zoom image row */
228 cups_ib_t
*r
, /* Row pointer */
229 *inptr
; /* Pixel pointer */
230 int xerr0
, /* X error counter */
256 z_instep
= z
->instep
;
257 z_inincr
= z
->inincr
;
260 cupsImageGetCol(z
->img
, z
->xorig
- iy
, z
->yorig
, z
->width
, z
->in
);
262 cupsImageGetRow(z
->img
, z
->xorig
, z
->yorig
+ iy
, z
->width
, z
->in
);
265 inptr
= z
->in
+ (z
->width
- 1) * z_depth
;
269 for (x
= z_xsize
, xerr0
= z_xsize
, xerr1
= 0, ix
= 0, r
= z
->rows
[z
->row
];
275 for (count
= 0; count
< z_depth
; count
++)
276 *r
++ = (inptr
[count
] * xerr0
+ inptr
[z_depth
+ count
] * xerr1
) / z_xsize
;
280 for (count
= 0; count
< z_depth
; count
++)
301 * 'zoom_nearest()' - Fill a zoom record quickly using nearest-neighbor
306 zoom_nearest(cups_izoom_t
*z
, /* I - Zoom record to fill */
307 int iy
) /* I - Zoom image row */
309 cups_ib_t
*r
, /* Row pointer */
310 *inptr
; /* Pixel pointer */
311 int xerr0
; /* X error counter */
334 z_instep
= z
->instep
;
335 z_inincr
= z
->inincr
;
338 cupsImageGetCol(z
->img
, z
->xorig
- iy
, z
->yorig
, z
->width
, z
->in
);
340 cupsImageGetRow(z
->img
, z
->xorig
, z
->yorig
+ iy
, z
->width
, z
->in
);
343 inptr
= z
->in
+ (z
->width
- 1) * z_depth
;
347 for (x
= z_xsize
, xerr0
= z_xsize
, ix
= 0, r
= z
->rows
[z
->row
];
351 for (count
= 0; count
< z_depth
; count
++)
369 * End of "$Id: image-zoom.c 5191 2006-02-27 02:47:56Z mike $".