Imaging Lingo: Bicubic Sampling

Ask a Question related to Macromedia Director Lingo, Design and Development.

  1. #1

    Default Imaging Lingo: Bicubic Sampling

    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 @ [url]http://www.php.net/manual/en/function.imagecopyresized.php[/url]
    -- 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


    protocol_droid webforumsuser@macromedia.com Guest

  2. Similar Questions and Discussions

    1. Imaging Lingo issues- PLEASE HELP
      Hi, Im having a major problem getting some simple features ready with imaging lingo, and I need help!! 1st feature: Select an X-ray, it pops up...
    2. imaging lingo
      hey, Is there a way to resize a member's image without it getting distorted. Director is a vector based program, so when you resize a sprite(with...
    3. imaging lingo (zoom + pan)
      Hi, I need to make a zoom & pan feature for a small part of the stage. There are a few problems: 1) I can make the image expand and contract, but...
    4. text over bmp w/ imaging lingo
      I'm using imaging lingo to compose some text over a bitmap. The result i scored was quite good --until i set the composed member on stage. The...
    5. Imaging lingo challenge...
      Okay, I was asking this in the Photoshop newsgroups, but not getting much luck, so I wonder if there's a coding-approach I can take to this. I have...
  3. #2

    Default Re: Imaging Lingo: Bicubic Sampling

    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

    Andrew Morton Guest

  4. #3

    Default Re: Imaging Lingo: Bicubic Sampling

    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

    [url]http://www.geocities.com/hairybobby2000[/url]

    Photography section

    [url]http://www.geocities.com/hairybobby2000/px1.html[/url]

    Photoshop section

    [url]http://www.geocities.com/hairybobby2000/photo1.html[/url]
    hairybobby webforumsuser@macromedia.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139