Interpolation

From Director Online Wiki
Jump to: navigation, search
-- for i := 0 to 255 do CosineTab[i] := Round(64-Cos(i*Pi/255)*64);
--c := CosineTab[b] + CosineTab[a];
--if c > 255 then result := 255 else result := c;
-- ******* interpolation mode *************
on interpolationBlendMode (image1, image2)
 
  theWidth = image1.width - 1
  theHeight = image1.height - 1
  theImage = image(theWidth + 1, theHeight + 1, 32)
  CosineTab = []
  repeat with i = 1 to 256
    CosineTab[i] = integer(64-Cos((i-1)*Pi/255.0)*64)
  end repeat
 
  repeat with x = 0 to theWidth
    repeat with y = 0 to theHeight
      theColour1 = image1.getPixel(point(x,y))
      theColour2 = image2.getPixel(point(x,y))
      theNewColour = color(0,0,0)
      theNewColour.red = min(CosineTab[theColour2.red + 1] + CosineTab[theColour1.red + 1], 255)
      theNewColour.green = min(CosineTab[theColour2.green + 1] + CosineTab[theColour1.green + 1], 255)
      theNewColour.blue = min(CosineTab[theColour2.blue + 1] + CosineTab[theColour1.blue + 1], 255)
 
      theImage.setPixel(point(x, y), theNewColour)
 
    end repeat
  end repeat
  return theImage
end