43 #define M_PI 3.14159265358979323846
58 assert(y < image->ysize);
68 int i, j, d, bpp, ysize;
72 assert(x < image->xsize);
77 for(i = 0, p = image->
data + x * bpp; i < ysize; p += d, i++) {
78 for (j = 0; j < bpp; j++) {
92 assert(x < image->xsize);
94 assert(y < image->ysize);
97 p = image->
data + image->
span * y + x * bpp;
98 for (i = 0; i < bpp; i++) {
100 if (val < 0.0f) val = 0.0f;
101 else if (val > 255.0f) val = 255.0f;
102 *p++ = (
unsigned char) val;
111 #define filter_support (1.0f)
118 if(t < 1.0f)
return((2.0f * t - 3.0f) * t * t + 1.0f);
122 #define box_support (0.5f)
127 if((t > -0.5f) && (t <= 0.5f))
return(1.0f);
131 #define triangle_support (1.0f)
137 if(t < 1.0f)
return(1.0f - t);
141 #define bell_support (1.5f)
147 if(t < 0.5f)
return(0.75f - (t * t));
150 return(0.5f * (t * t));
155 #define B_spline_support (2.0f)
165 return((.5f * tt * t) - tt + (2.0f / 3.0f));
166 }
else if(t < 2.0f) {
168 return((1.0f / 6.0f) * (t * t * t));
177 if(x != 0.0f)
return (
float)(sin(x) / x);
181 #define Lanczos3_support (3.0f)
187 if(t < 3.0f)
return(
sinc(t) *
sinc(t/3.0f));
191 #define Mitchell_support (2.0)
193 #define B (1.0f / 3.0f)
194 #define C (1.0f / 3.0f)
204 t = (((12.0f - 9.0f *
B - 6.0f *
C) * (t * tt))
205 + ((-18.0f + 12.0f *
B + 6.0f *
C) * tt)
206 + (6.0f - 2.0f *
B));
210 t = (((-1.0f *
B - 6.0f *
C) * (t * tt))
211 + ((6.0f *
B + 30.0f *
C) * tt)
212 + ((-12.0f *
B - 48.0f * C) * t)
213 + (8.0f *
B + 24.0f * C));
234 new_image(
int xsize,
int ysize,
int bpp,
unsigned char * data)
240 img->
span = xsize * bpp;
242 if (data == NULL) img->
data = (
unsigned char*) malloc((
size_t)img->
span*img->
ysize);
249 float (*filterf)(
float),
254 float xscale, yscale;
259 float width, fscale, weight;
260 unsigned char * raster;
263 unsigned char * dstptr;
264 int dstxsize, dstysize;
267 dstxsize = dst->
xsize;
268 dstysize = dst->
ysize;
272 xscale = (float) dstxsize / (
float) src->
xsize;
273 yscale = (float) dstysize / (
float) src->
ysize;
276 contrib = (
CLIST *)calloc(dstxsize,
sizeof(
CLIST));
278 width = fwidth / xscale;
279 fscale = 1.0f / xscale;
280 for(i = 0; i < dstxsize; i++) {
282 contrib[i].
p = (
CONTRIB *)calloc((
int) (width * 2 + 1),
284 center = (float) i / xscale;
285 left = (int) ceil(center - width);
286 right = (int) floor(center + width);
287 for(j = left; j <= right; j++) {
288 weight = center - (float) j;
289 weight = (*filterf)(weight / fscale) / fscale;
293 else if(j >= src->
xsize) {
300 contrib[i].
p[k].
pixel = n*bpp;
301 contrib[i].
p[k].
weight = weight;
306 for(i = 0; i < dstxsize; i++) {
308 contrib[i].
p = (
CONTRIB *)calloc((
int) (fwidth * 2 + 1),
310 center = (float) i / xscale;
311 left = (int) ceil(center - fwidth);
312 right = (int) floor(center + fwidth);
313 for(j = left; j <= right; j++) {
314 weight = center - (float) j;
315 weight = (*filterf)(weight);
319 else if(j >= src->
xsize) {
326 contrib[i].
p[k].
pixel = n*bpp;
327 contrib[i].
p[k].
weight = weight;
333 raster = (
unsigned char *)calloc(src->
xsize, src->
bpp);
337 for(k = 0; k < tmp->
ysize; k++) {
339 for(i = 0; i < tmp->
xsize; i++) {
340 for (b = 0; b < bpp; b++) pixel[b] = 0.0f;
341 for(j = 0; j < contrib[i].
n; j++) {
342 for (b = 0; b < bpp; b++) {
343 pixel[b] += raster[contrib[i].
p[j].
pixel+b]
350 for (b = 0; b < bpp; b++) {
351 float val = pixel[b];
352 if (val < 0.0f) val = 0.0f;
353 else if (val > 255.0f) val = 255.0f;
354 *dstptr++ = (
unsigned char ) val;
362 for(i = 0; i < tmp->
xsize; i++) {
368 contrib = (
CLIST *)calloc(dstysize,
sizeof(
CLIST));
370 width = fwidth / yscale;
371 fscale = 1.0f / yscale;
372 for(i = 0; i < dstysize; i++) {
374 contrib[i].
p = (
CONTRIB *)calloc((
int) (width * 2 + 1),
376 center = (float) i / yscale;
377 left = (int) ceil(center - width);
378 right = (int) floor(center + width);
379 for(j = left; j <= right; j++) {
380 weight = center - (float) j;
381 weight = (*filterf)(weight / fscale) / fscale;
385 else if(j >= tmp->
ysize) {
392 contrib[i].
p[k].
pixel = n*bpp;
393 contrib[i].
p[k].
weight = weight;
398 for(i = 0; i < dstysize; i++) {
400 contrib[i].
p = (
CONTRIB *)calloc((
int) (fwidth * 2 + 1),
402 center = (float) i / yscale;
403 left = (int) ceil(center - fwidth);
404 right = (int) floor(center + fwidth);
405 for(j = left; j <= right; j++) {
406 weight = center - (float) j;
407 weight = (*filterf)(weight);
411 else if(j >= tmp->
ysize) {
418 contrib[i].
p[k].
pixel = n*bpp;
419 contrib[i].
p[k].
weight = weight;
425 raster = (
unsigned char *) calloc(tmp->
ysize, tmp->
bpp);
426 for(k = 0; k < dstxsize; k++) {
428 dstptr = dst->
data + k * bpp;
429 for(i = 0; i < dstysize; i++) {
430 for (b = 0; b < bpp; b++) pixel[b] = 0.0f;
431 for(j = 0; j < contrib[i].
n; ++j) {
432 for (b = 0; b < bpp; b++) {
433 pixel[b] += raster[contrib[i].
p[j].
pixel+b]
440 for (b = 0; b < bpp; b++) {
441 float val = pixel[b];
442 if (val < 0.0f) val = 0.0f;
443 else if (val > 255.0f) val = 255.0f;
444 dstptr[b] = (
unsigned char) val;
447 dstptr += bpp * dstxsize;
454 for(i = 0; i < dstysize; ++i) {
465 static unsigned char *
467 int height,
int num_comp,
468 int newwidth,
int newheight)
470 float sx, sy, dx, dy;
471 int src_bpr, dest_bpr, xstop, ystop, x, y, offset, i;
472 unsigned char *dest =
473 (
unsigned char*) malloc((
size_t)newwidth*newheight*num_comp);
475 dx = ((float)width)/((float)newwidth);
476 dy = ((float)height)/((float)newheight);
477 src_bpr = width * num_comp;
478 dest_bpr = newwidth * num_comp;
481 ystop = newheight * dest_bpr;
482 xstop = newwidth * num_comp;
483 for (y = 0; y < ystop; y += dest_bpr) {
485 for (x = 0; x < xstop; x += num_comp) {
486 offset = ((int)sy)*src_bpr + ((int)sx)*num_comp;
487 for (i = 0; i < num_comp; i++) dest[x+y+i] = src[offset+i];
513 int height,
int num_comp,
514 int newwidth,
int newheight)
516 unsigned char * dstdata;
517 Image * srcimg, * dstimg;
522 newwidth, newheight);
524 srcimg =
new_image(width, height, num_comp, src);
525 dstimg =
new_image(newwidth, newheight, num_comp, NULL);
530 dstdata = dstimg->
data;
static float triangle_filter(float t)
static float box_filter(float t)
static float Lanczos3_filter(float t)
static void put_pixel(Image *image, int x, int y, float *data)
static unsigned char * simage_resize_fast(unsigned char *src, int width, int height, int num_comp, int newwidth, int newheight)
static float Mitchell_filter(float t)
static float sinc(float x)
static float B_spline_filter(float t)
Windows specific information.
unsigned char * simage_resize(unsigned char *src, int width, int height, int num_comp, int newwidth, int newheight)
static void get_row(unsigned char *row, Image *image, int y)
static float filter(float t)
static Image * new_image(int xsize, int ysize, int bpp, unsigned char *data)
static void get_column(unsigned char *column, Image *image, int x)
static float bell_filter(float t)
static void zoom(Image *dst, Image *src, float(*filterf)(float), float fwidth)