在这段代码中
im = Vips::Image.new_from_file "some.jpg"
r = (im * [1,0,0]).avg
g = (im * [0,1,0]).avg
b = (im * [0,0,1]).avg
p [r,g,b] # => [57.1024, 53.818933333333334, 51.9258]
p Vips::Image.sRGB2HSV [r,g,b]
最后一行抛出
/ruby-vips-1.0.3/lib/vips/argument.rb:154:in `set_property': invalid argument Array (expect #<Class:0x007fbd7c923600>) (ArgumentError)`
PS:临时采用并重构了 ChunkyPNG 实现:
def to_hsv r, g, b
r, g, b = [r, g, b].map{ |component| component.fdiv 255 }
min, max = [r, g, b].minmax
chroma = max - min
[
60.0 * ( chroma.zero? ? 0 : case max
when r ; (g - b) / chroma
when g ; (b - r) / chroma + 2
when b ; (r - g) / chroma + 4
else 0
end % 6 ),
chroma / max,
max,
]
end