|
|
@@ -0,0 +1,64 @@ |
|
|
|
/* |
|
|
|
* libpipi Proper image processing implementation library |
|
|
|
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> |
|
|
|
* All Rights Reserved |
|
|
|
* |
|
|
|
* $Id$ |
|
|
|
* |
|
|
|
* This library is free software. It comes without any warranty, to |
|
|
|
* the extent permitted by applicable law. You can redistribute it |
|
|
|
* and/or modify it under the terms of the Do What The Fuck You Want |
|
|
|
* To Public License, Version 2, as published by Sam Hocevar. See |
|
|
|
* http://sam.zoy.org/wtfpl/COPYING for more details. |
|
|
|
*/ |
|
|
|
|
|
|
|
/* |
|
|
|
* resize.c: image resizing functions |
|
|
|
*/ |
|
|
|
|
|
|
|
#include "config.h" |
|
|
|
#include "common.h" |
|
|
|
|
|
|
|
#include "pipi_internals.h" |
|
|
|
#include "pipi.h" |
|
|
|
|
|
|
|
pipi_image_t *pipi_resize(pipi_image_t const *src, int w, int h) |
|
|
|
{ |
|
|
|
pipi_image_t *dst; |
|
|
|
int x, y, x0, y0; |
|
|
|
dst = pipi_new(w, h); |
|
|
|
|
|
|
|
int sw = src->width; |
|
|
|
int dw = dst->width; |
|
|
|
|
|
|
|
for(y = 0, y0 = 0; y < dst->height; y++) |
|
|
|
{ |
|
|
|
for(x = 0, x0 = 0; x < dst->width; x++) |
|
|
|
{ |
|
|
|
int rem = 0, tot = 0; |
|
|
|
int ar = 0, ag = 0, ab = 0; |
|
|
|
int r = 0, g = 0, b = 0; |
|
|
|
int n; |
|
|
|
|
|
|
|
while(tot < sw) |
|
|
|
{ |
|
|
|
if(rem == 0) |
|
|
|
{ |
|
|
|
pipi_getpixel(src, x0, y, &r, &g, &b); |
|
|
|
x0++; |
|
|
|
rem = dw; |
|
|
|
} |
|
|
|
|
|
|
|
n = (tot + rem <= sw) ? rem : sw - tot; |
|
|
|
ar += n * r; ag += n * g; ab += n * b; |
|
|
|
tot += n; |
|
|
|
rem -= n; |
|
|
|
} |
|
|
|
|
|
|
|
pipi_setpixel(dst, x, y, ar / sw, ag / sw, ab / sw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return dst; |
|
|
|
} |
|
|
|
|