Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Get the default fixedLineSpace from a text member
Button Animator on how close cursor is to it
Simple slide show
Roil-Alphamania
ESCAPE Video Studio
EXE Screen Saver
Get VideoForWindows Version
Change ShapeType of a Shape cast member
Audio Xtra
Sprite Recorder
 

 

 

Behavior Bilinear Resample Algorithm

Added on 8/23/2005

 

Compatibilities:
behavior D8 D8_5 D9 Mac Parent PC Shockwave

This item has not yet been rated

Author: Chunick (website)

This is a true bilinear resampling algorithm. Because it's purly done in Lingo it's rather slow compared to resampling done by Xtras. The benefit is it's free.

-- Bilinear Image Resampling Code
-- ©2005 by Josh Chunick (josh@chunick.com)
-- code optimizations by Thomas Mavrofides
-- This code is free to use in commercial applications
-- or however you want.If you use this code you
-- must keep the comments, including this message,
-- intact. Feel free to add any changes or make improvements.
--
-- inspired by VB code from vbAccelerator.com

on bilinearResample2 (theImage, newWidth, newHeight, sharpen, amount)
  --theImage = anImage.duplicate()
  newImage = image(newWidth, newHeight, 32)
  oldWidth = theImage.width - 1
  oldHeight = theImage.height - 1
  
  -- return the original image if the scale factor is 1
  if newImage.rect = theImage.rect then return theImage
  
  -- the look-up table for the original image (done for speed purposes)
  -- this shaves off 600 milliseconds from my 320x240 test image
  listX = []
  listY = []
  repeat with x = 0 to oldWidth
    repeat with y = 0 to oldHeight
      listY.add(theImage.getPixel(x,y))
    end repeat
    listX.add(listY)
    listY = []
  end repeat
  
  -- get the ratio between the old image and the new one
  xScale = (oldWidth) / float(newWidth)
  yScale = (oldHeight) / float(newHeight)
  
  -- draw each pixel in the new image
  repeat with y = 1 to newHeight
    
    -- generate the y calculation variables
    dstY = (y - 1) * yScale
    interplY = bitXor(dstY, 0)
    calcY = dstY - interplY
    
    repeat with x = 1 to newWidth
      -- generate the x calculation variables
      dstX = (x - 1) * xScale
      interplX = bitXor(dstX, 0)
      calcX = dstX - interplX
      
      -- get the 4 pixels around the interpolated one
      theColour1 = listX[interplX + 1][interplY + 1]
      theColour2 = listX[interplX + 2][interplY + 1]
      theColour3 = listX[interplX + 1][interplY + 2]
      theColour4 = listX[interplX + 2][interplY + 2]
      
      -- calculate the new colour
      newColor1 = theColour1 * (1 - calcY) + theColour3 * calcY
      newColor2 = theColour2 * (1 - calcY) + theColour4 * calcY
      newColor= newColor1 * (1 - calcX) + newColor2 * calcX
      
      --Set this pixel into the new image
      
      newImage.setPixel(point(x - 1,y - 1), newColor)
      
    end repeat
  end repeat
  
  return newImage
  
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail