File: bmp.rb

package info (click to toggle)
ruby-fastimage 2.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,008 kB
  • sloc: ruby: 1,442; xml: 7; makefile: 2; sh: 1
file content (17 lines) | stat: -rw-r--r-- 463 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module FastImageParsing
  class Bmp < ImageBase # :nodoc:
    def dimensions
      d = @stream.read(32)[14..28]
      header = d.unpack("C")[0]

      result = if header == 12
                 d[4..8].unpack('SS')
               else
                 d[4..-1].unpack('l<l<')
               end

      # ImageHeight is expressed in pixels. The absolute value is necessary because ImageHeight can be negative
      [result.first, result.last.abs]
    end
  end
end