Soft Light

From Director Online Wiki
Jump to: navigation, search
--c := a * b SHR 8;
--result := c + a * (255 - ((255-a)*(255-b) SHR 8)-c) SHR 8;
-- ******** XFader soft light mode - better than photoshop's version *******
on softlightBlendMode (image1, image2)
  -- using the source image for the width and height
  -- you can add your own code here to determine how
  -- you want to handle this.
  theWidth = image1.width - 1
  theHeight = image1.height - 1
  theImage = image(theWidth + 1, theHeight + 1, 32)
  theDivisor = 255.0
  -- running through each pixel in theImage
  repeat with x = 0 to theWidth
    repeat with y = 0 to theHeight
      theColour1 = image1.getPixel(point(x,y))
      theColour2 = image2.getPixel(point(x,y))
 
      theComp = theColour1.red * theColour2.red / theDivisor
      theRed = theComp + theColour1.red * (255 - ((255 - theColour1.red) * (255 - theColour2.red) / theDivisor) - theComp) / theDivisor
 
      theComp = theColour1.green * theColour2.green / theDivisor
      theGreen = theComp + theColour1.green * (255 - ((255 - theColour1.green) * (255 - theColour2.green) / theDivisor) - theComp) / theDivisor
 
      theComp = theColour1.blue * theColour2.blue / theDivisor
      theBlue = theComp + theColour1.blue  * (255 - ((255 - theColour1.blue ) * (255 - theColour2.blue ) / theDivisor) - theComp) / theDivisor
      theNewColour = color(theRed, theGreen, theBlue)
      theImage.setPixel(point(x, y), theNewColour)
    end repeat
  end repeat
  return theImage
end