Soft Burn

From Director Online Wiki
Jump to: navigation, search
--if a+b < 256 then begin
--  if a = 255 then
--    Result := 255
--  else begin
--    c := (b SHL 7) DIV (255-a);
--    if c > 255 then Result := 255 else Result := c;
--  end;
--end
--else begin
--  // b cannot be zero here
--  c := 255-(((255-a) SHL 7) DIV b);
--  if c < 0 then Result := 0 else Result := c;
--end;
-- ******* soft burn mode *************
on softBurnBlendMode (image1, image2)
  theWidth = image1.width - 1
  theHeight = image1.height - 1
  theImage = image(theWidth + 1, theHeight + 1, 32)
  theMultiplier = 127
  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)
 
      if (theColour1.red + theColour2.red) < 256 then
        if theColour1.red = 255 then
          theNewColour.red = 255
        else
          theNewColour.red = min((theCOlour2.red * theMultiplier) / float(255 - theColour1.red), 255)
        end if
      else
        -- theColour2 cannot be zero here
        theNewColour.red = max(255 - (((255 - theColour1.red) * theMultiplier) / float(theColour2.red)), 0)
      end if
 
      if (theColour1.green + theColour2.green) < 256 then
        if theColour1.green = 255 then
          theNewColour.green = 255
        else
          theNewColour.green = min((theCOlour2.green * theMultiplier) / float(255 - theColour1.green), 255)
        end if
      else
        -- theColour2 cannot be zero here
        theNewColour.green = max(255 - (((255 - theColour1.green) * theMultiplier) / float(theColour2.green)), 0)
      end if
 
      if (theColour1.blue + theColour2.blue) < 256 then
        if theColour1.blue = 255 then
          theNewColour.blue = 255
        else
          theNewColour.blue = min((theCOlour2.blue * theMultiplier) / float(255 - theColour1.blue), 255)
        end if
      else
        -- theColour2 cannot be zero here
        theNewColour.blue = max(255 - (((255 - theColour1.blue) * theMultiplier) / float(theColour2.blue)), 0)
      end if
 
      theImage.setPixel(point(x, y), theNewColour)
 
    end repeat
  end repeat
  return theImage
end