lib/RMagick.rb in rmagick-1.11.1 vs lib/RMagick.rb in rmagick-1.12.0

- old
+ new

@@ -1,6 +1,6 @@ -# $Id: RMagick.rb,v 1.39 2006/03/11 15:28:06 rmagick Exp $ +# $Id: RMagick.rb,v 1.42 2006/06/03 22:56:40 rmagick Exp $ #============================================================================== # Copyright (C) 2006 by Timothy P. Hunter # Name: RMagick.rb # Author: Tim Hunter # Purpose: Extend Ruby to interface with ImageMagick. @@ -696,11 +696,39 @@ end end return hash end - # These four methods are equivalent to the Draw#matte - # method with the "Point", "Replace", "Floodfill", "FilltoBorder", and + # Patches problematic change to the order of arguments in 1.11.0. + # Before this release, the order was + # black_point, gamma, white_point + # RMagick 1.11.0 changed this to + # black_point, white_point, gamma + # This fix tries to determine if the arguments are in the old order and + # if so, swaps the gamma and white_point arguments. Then it calls + # level2, which simply accepts the arguments as given. + + # Inspect the gamma and white point values and swap them if they + # look like they're in the old order. + + # (Thanks to Al Evans for the suggestion.) + def level(black_point=0.0, white_point=nil, gamma=nil) + white_point ||= Magick::MaxRGB - black_point + gamma_arg = gamma + gamma ||= 1.0 + + if gamma.abs > 10.0 || white_point.abs <= 10.0 || white_point.abs < gamma.abs + gamma, white_point = white_point, gamma + unless gamma_arg + white_point = Magick::MaxRGB - black_point + end + end + + return level2(black_point, white_point, gamma) + end + + # These four methods are equivalent to the Draw#matte method + # with the "Point", "Replace", "Floodfill", "FilltoBorder", and # "Replace" arguments, respectively. # Make the pixel at (x,y) transparent. def matte_point(x, y) f = copy