Module: JXL::Color::YCbCr

Defined in:
lib/jxl/color/ycbcr.rb

Class Method Summary collapse

Class Method Details

.to_rgb(channels, frame) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jxl/color/ycbcr.rb', line 8

def to_rgb(channels, frame)
  full = channels.first(3).each_with_index.map do |plane, channel|
    hshift, vshift = frame.chroma_subsampling[channel]
    hshift.times { plane = double_horizontal(plane) }
    vshift.times { plane = double_vertical(plane) }
    crop(plane, frame.encoded_width, frame.encoded_height)
  end
  output = Array.new(3) { Plane.new(frame.encoded_width, frame.encoded_height) }
  full[0].data.length.times do |index|
    cb = full[0].data[index]
    y = full[1].data[index] + (128.0 / 255)
    cr = full[2].data[index]
    output[0].data[index] = y + (1.402 * cr)
    output[1].data[index] = y - ((0.114 * 1.772 / 0.587) * cb) - ((0.299 * 1.402 / 0.587) * cr)
    output[2].data[index] = y + (1.772 * cb)
  end
  output + channels.drop(3)
end