Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Imaging Lingo: Bicubic Sampling

0 views
Skip to first unread message

protocol_droid

unread,
Aug 31, 2003, 8:37:19 PM8/31/03
to
I wanted to resize a bitmap member (to later resave on disk), but thought I might have to use an Xtra to do what I need. I'm not big into Xtras, so I took a PHP Function (specifically for GD 1.0) and translated it into lingo, and added a few notes.

It's probably not the fastest way to do it, but, I thought someone might also find this handy.

(Look out for long lines!)

on ImageCopyResampleBicubic (src_image, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
----------------------------------------------------------
-- FUNCTION: Copys a portion of an image, and resizes it.
-- Averages colors to retain image quality.
----------------------------------------------------------
-- RETURNS: newImage (of ilk #image)
----------------------------------------------------------
-- ACCEPTS:
--
-- src_image => Original Image, i.e. member("My Flower Picture").image
-- dst_x => X position of where copy will be start being placed on newImage
-- dst_y => Y position of where copy will be start being placed on newImage
-- src_x => X position of area to start copying from
-- src_y => Y position of area to start copying from
-- dst_w => Width of copied portion onto newImage
-- dst_h => Height of copied portion onto newImage
-- src_w => Width of resulting newImage
-- src_h => Height of resulting newImage
----------------------------------------------------------
-- EXAMPLE:
--
-- -- Copy Entire Image into a smaller image, 40% the size
-- bigFlower = member("flower").image
-- pct = [bigFlower.width * .4,bigFlower.width * .4]
-- littleFlower = ImageCopyResampleBicubic(bigFlower, 0, 0, 0, 0, pct[1], pct[2], bigFlower.width, bigFlower.height)
----------------------------------------------------------
-- ORIGIN:
-- User comments @ http://www.php.net/manual/en/function.imagecopyresized.php
-- Originally by: daniel dot stankewitz at onvista dot de




newImage = image( (dst_w + dst_x), (dst_h + dst_y), src_image.depth )


rX = src_w / dst_w
rY = src_h / dst_h

w = 0
repeat with y = dst_y to dst_h

ow = w
w = integer((y + 1) * rY)
t = 0
repeat with x = dst_x to dst_w

r = 0
g = 0
b = 0
a = 0

ot = t
t = integer((x + 1) * rX)
repeat with u = 0 to (w - ow)

repeat with p = 0 to (t - ot)
cA = src_image.getPixel(ot + p, ow + u)
r = r + cA.red
g = g + cA.green
b = b + cA.blue
a = a + 1
end repeat

end repeat
newImage.setPixel(x,y,rgb(integer(r / a), integer(g / a), integer(b / a))) -- ImageSetPixel (dst_img, x, y, ImageColorClosest (dst_img, r / a, g / a, b / a));
end repeat

end repeat

return newImage

end


Andrew Morton

unread,
Sep 1, 2003, 5:32:42 AM9/1/03
to
The default for copyPixels (i.e. using #copy ink) is to resample the image. Even
if MM didn't document it. And it does a very good job when shrinkifying
pictures.

Andrew Morton

hairybobby

unread,
Sep 1, 2003, 6:35:30 AM9/1/03
to
hi droid,

how about checking out the copypixels function. if you are wanting to resize downwards then it works a treat.

on startmovie me
new(#bitmap,member 3)--create a new member at cast member 3
newimage=image(100,100,32)-- create a new image
newimage.copypixels(member(2).image,newimage.rect,member(2).rect)
member(3).image=newimage --sets the image of member 3 as newimage
end


this copies member 2 into member 3. Resizing upwards might be a different matter as that involves skill . For that I'd probably use photoshop.

HAIRYBOBBY - why didn't I choose a really cool name like the vulcanpimp

http://www.geocities.com/hairybobby2000

Photography section

http://www.geocities.com/hairybobby2000/px1.html

Photoshop section

http://www.geocities.com/hairybobby2000/photo1.html

0 new messages