Class: FastImageParsing::Jxlc
- Inherits:
-
Object
- Object
- FastImageParsing::Jxlc
- Defined in:
- lib/fastimage/fastimage_parsing/jxlc.rb
Overview
:nodoc:
Constant Summary collapse
- LENGTHS =
[9, 13, 18, 30]
- MULTIPLIERS =
[1, 1.2, Rational(4, 3), 1.5, Rational(16, 9), 1.25, 2]
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #get_bits(size) ⇒ Object
-
#initialize(stream) ⇒ Jxlc
constructor
A new instance of Jxlc.
- #parse_jxlc ⇒ Object
- #x_from_ratio(y) ⇒ Object
Constructor Details
#initialize(stream) ⇒ Jxlc
Returns a new instance of Jxlc.
8 9 10 11 12 13 |
# File 'lib/fastimage/fastimage_parsing/jxlc.rb', line 8 def initialize(stream) @stream = stream @width, @height´ = nil @bit_counter = 0 parse_jxlc end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
3 4 5 |
# File 'lib/fastimage/fastimage_parsing/jxlc.rb', line 3 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
3 4 5 |
# File 'lib/fastimage/fastimage_parsing/jxlc.rb', line 3 def width @width end |
Instance Method Details
#get_bits(size) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fastimage/fastimage_parsing/jxlc.rb', line 40 def get_bits(size) if @words.size < (@bit_counter + size) / 16 + 1 @words += @stream.read(4).unpack('vv') end dest_pos = 0 dest = 0 size.times do word = @bit_counter / 16 source_pos = @bit_counter % 16 dest |= ((@words[word] & (1 << source_pos)) > 0 ? 1 : 0) << dest_pos dest_pos += 1 @bit_counter += 1 end dest end |
#parse_jxlc ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fastimage/fastimage_parsing/jxlc.rb', line 15 def parse_jxlc @words = @stream.read(6)[2..5].unpack('vv') # small mode allows for values <= 256 that are divisible by 8 small = get_bits(1) if small == 1 y = (get_bits(5) + 1) * 8 x = x_from_ratio(y) if !x x = (get_bits(5) + 1) * 8 end @width, @height = x, y return end len = LENGTHS[get_bits(2)] y = get_bits(len) + 1 x = x_from_ratio(y) if !x len = LENGTHS[get_bits(2)] x = get_bits(len) + 1 end @width, @height = x, y end |
#x_from_ratio(y) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/fastimage/fastimage_parsing/jxlc.rb', line 57 def x_from_ratio(y) ratio = get_bits(3) if ratio == 0 return nil else return (y * MULTIPLIERS[ratio - 1]).to_i end end |