8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/jxl/color/opsin.rb', line 8
def to_linear(channels, transform, intensity_target: 255.0)
output = Array.new(3) { Plane.new(channels[0].width, channels[0].height) }
matrix = transform.inverse_matrix.map { _1 * (255.0 / intensity_target) }
bias_roots = transform.biases.map { Math.cbrt(_1) }
channels[0].data.length.times do |index|
x = channels[0].data[index]
y = channels[1].data[index]
b = channels[2].data[index]
mixed = [((y + x - bias_roots[0])**3) + transform.biases[0],
((y - x - bias_roots[1])**3) + transform.biases[1],
((b - bias_roots[2])**3) + transform.biases[2]]
3.times do |channel|
offset = channel * 3
output[channel].data[index] = matrix[offset, 3].each_with_index.sum { |value, c| value * mixed[c] }
end
end
output + channels.drop(3)
end
|