Thursday, July 12, 2007

[Work] Image resize

Paul Heckbert's homepage
Paul Heckbert's zoom


/*----------------------------------------------------------------------
* The mapping from source coordinates to dest coordinates:
* (Notation: prefix 'a' denotes source coords, 'b' denotes destination coords)
*
* bx = sx*ax+tx
* by = sy*ay+ty
*
* where (ax,ay) and (bx,by) are DISCRETE source and dest coords, respectively.
*
* An important fine point on terminology: there are two kinds of pixel coords:
* DISCRETE COORDINATES take on integer values at pixel centers
* CONTINUOUS COORDINATES take on integer values halfway between pixels
* For example, an image with discrete coordinate range [0..511] has a
* continuous coordinate range of [0..512]. The pixel with
* discrete coords (x,y) has its center at continuous coords (x+.5,y+.5)
* and its continuous coord domain is [x..x+1] in X and [y..y+1] in Y.
* Note: discrete coords are not always stored in ints and continuous coords
* are not always stored in floats.
*
* conversion:
* if c = continuous coord and d = discrete coord, then
* c = d+.5
* d = floor(c)
*
* To map a discrete src interval [a0..a1] to a discrete dst interval [b0..b1]:
*
* b-b0+.5 = bn/an*(a-a0+.5)
* or b = (bn/an)*a + (b0-.5)-(bn/an)*(a0-.5)
* = scale*a+tran
*
* where a and b are the discrete source and dest coords (either x or y)
* and an and bn are the interval lengths: an=a1-a0+1, bn=b1-b0+1.
* a0, an, b0, bn are the mapping parameters used by the zoom routine below.
* In general, however, for sub-pixel scale and translate control, we allow
* any real numbers for scale and tran (although there should usually be some
* correspondence between the mapping function and the src and dst windows).
*
* We'll often want the inverse mapping, from discrete dst coord b to
* continuous src coord ac, relative to the interval origins a0 and b0:
*
* b+b0 = s*(ac+a0-.5)+t
* so ac = (b+b0-s*(a0-.5)-t)/s
* = (b+offset)/scale = MAP(b, scale, offset)
*
* The mapping fields ux and uy in the Mapping structure
* are these offsets in x & y respectively.
*/
/* the mapping from discrete dest coord b to continuous source coord: */
#define MAP(b, scale, offset) (((b)+(offset))/(scale))



#!/bin/bash

for filter in point box triangle quadratic cubic catrom mitchell gaussian sinc bessel hanning hamming blackman kaiser
do
# echo ${filter}
# echo ./bin/zoom -src $1 -dst `basename $1 .tif`_${filter}.tif -s 0 0 340 260 -d 0 0 680 520 -filt ${filter}
./bin/zoom -src $1 -dst `basename $1 .tif`_big_${filter}.tif -s 0 0 406 500 -d 0 0 812 1000 -filt ${filter}
./bin/zoom -src $1 -dst `basename $1 .tif`_small_${filter}.tif -s 0 0 406 500 -d 0 0 203 250 -filt ${filter}
done




http://www.mobilegd.com/index.php?option=com_smf&Itemid=73&topic=34.msg1980

No comments: