Path: utzoo!attcan!uunet!nih-csl!lhc!adm!cmcl2!yale!cs.utexas.edu!usc!apple!bionet!agate!shelby!morrow.stanford.edu!pangea.Stanford.EDU!rick From: rick@pangea.Stanford.EDU (Rick Ottolini) Newsgroups: comp.graphics Subject: Re: Fast Image Scaling Message-ID: <1990Oct26.011905.16187@morrow.stanford.edu> Date: 26 Oct 90 01:19:05 GMT References: Sender: news@morrow.stanford.edu (UNIX News Service) Organization: Stanford Univ. Earth Sciences Lines: 30 In article dal@syntel.syntel.mn.org (Dale A. Schumacher) writes: >The following pseudo-code is from a rough draft of a paper I'm preparing >for inclusion in Graphics Gems '91. It is in the public domain. > > >src_x_size: integer; >src_y_size: integer; >source: array[0..src_x_size-1] of array[0..src_y_size-1] of pixel; >dst_x_size: integer; >dst_y_size: integer; >destination: array[0..dst_x_size-1] of array[0..dst_y_size-1] of pixel; >sx, sy, dx, dy: integer; > >begin > dx <- 0; > dy <- 0; > while dy < dst_y_size do > sy <- ((dy * src_y_size) / dst_y_size); > while dx < dst_x_size do > sx <- ((dx * src_x_size) / dst_x_size); > destination[dx][dy] <- source[sx][sy]; > endloop; > endloop; >end; Two problems (at least): (1) When shrinking the high freqyency components of an image must be removed or else aliasing will result. A fast way to do this is to smooth with a (rectangular) window the degree of compression. (2) Pre-computing each axis of of sx and sy is even faster than above.