Re: Shrinking bitmaps
- Posted by Jiri Babor <jbabor at PARADISE.NET.NZ> Feb 02, 2002
- 503 views
Hi, Jasper, many moons ago, well before this forum became a YAWN (Yet Another Windows Nightmare - jiri' tm), I suggested the following simple-minded approach to scaling of sequences. For the sake of clarity, some rather obvious optimizations are not implemented (special cases, unrolling of critical routines, etc), but it is still more than 10 times faster than Mr Trick's offering, which otherwise seems to work quite well. jiri -- scale.ex -- jiri babor -- jbabor at paradise.net.nz -- 3 Feb 2002 function scale(integer m, integer n) sequence s integer a, dr, r, j s = repeat(1, n) s[n] = m r = -n+1 dr = 2*(m-1) a = 2*(n-1) j = 1 for i = 2 to n-1 do r += dr while r >= 0 do j += 1 r -= a end while s[i] = j end for return s end function function resize(sequence s, integer new_width, integer new_height) sequence u,v, ri,ro integer wi,hi hi = length(s) -- height of input sequence wi = length(s[1]) -- width of input sequence u = scale(hi, new_height) v = scale(wi, new_width) ro = v for i = 1 to new_height do ri = s[u[i]] for j = 1 to new_width do ro[j] = ri[v[j]] end for u[i] = ro end for return u end function -- example ----------------------------------------------------------- include image.e object o sequence bmp, pal o = read_bitmap("c:\\windows\\setup.bmp") if atom(o) then puts(1, "could not read specified bitmap\n") abort(1) end if pal = o[1]/4 bmp = o[2] use_vesa(1) -- just in case... o = graphics_mode(257) -- 640x480x256 all_palette(pal) display_image({0, 0}, bmp) -- full size display_image({0, 0}, resize(bmp, 160,120)) -- quarter size, overlayed while get_key() = -1 do end while -- pause o = graphics_mode(-1) -- restore original text mode ----- Original Message ----- From: <jaspers_post at hotmail.com> To: "EUforum" <EUforum at topica.com> Sent: Friday, February 01, 2002 10:59 PM Subject: Shrinking bitmaps > > Hi Mr Trick, > > I'm also interested in your project. My "problem" is this: I use bitBLt > to copy (dutch baseball) signs to a pixmap / window. This works fine. On > larger resolutions however, the signs become to small. I don't want to > design a optimised signs-bitmap for each resolution. So the idea is > this: I design a bitmap for 1280 x 1024. I get the user's resolution and > then convert this bitmap into pixmap optimised for that resolution. In > short: I want to shrink a bitmap. > > Bye, > > Jasper.