example/daltonize8.rb in vips-8.8.0.3 vs example/daltonize8.rb in vips-8.8.2
- old
+ new
@@ -7,22 +7,22 @@
# http://libvips.blogspot.co.uk/2013/05/daltonize-in-ruby-vips-carrierwave-and.html
# for a discussion of this code
require 'vips'
-#Vips.set_debug true
+# Vips.set_debug true
# matrices to convert D65 XYZ to and from bradford cone space
xyz_to_brad = [
- [0.8951, 0.2664, -0.1614],
- [-0.7502, 1.7135, 0.0367],
- [0.0389, -0.0685, 1.0296]
+ [0.8951, 0.2664, -0.1614],
+ [-0.7502, 1.7135, 0.0367],
+ [0.0389, -0.0685, 1.0296]
]
brad_to_xyz = [
- [0.987, -0.147, 0.16],
- [0.432, 0.5184, 0.0493],
- [-0.0085, 0.04, 0.968]
+ [0.987, -0.147, 0.16],
+ [0.432, 0.5184, 0.0493],
+ [-0.0085, 0.04, 0.968]
]
im = Vips::Image.new_from_file ARGV[0]
# remove any alpha channel before processing
@@ -45,13 +45,13 @@
# through the Deuteranope matrix
# we need rows to sum to 1 in Bradford space --- the matrix in the original
# Python code sums to 1.742
deut = brad.recomb [
- [1, 0, 0],
- [0.7, 0, 0.3],
- [0, 0, 1]
+ [1, 0, 0],
+ [0.7, 0, 0.3],
+ [0, 0, 1]
]
xyz = deut.recomb brad_to_xyz
# .. and back to sRGB
@@ -59,14 +59,12 @@
# so this is the colour error
err = im - rgb
# add the error back to other channels to make a compensated image
-im = im + err.recomb([
- [0, 0, 0],
- [0.7, 1, 0],
- [0.7, 0, 1]
-])
+im = im + err.recomb([[0, 0, 0],
+ [0.7, 1, 0],
+ [0.7, 0, 1]])
# reattach any alpha we saved above
if alpha
im = im.bandjoin(alpha)
end