Class: Cul::Image::Properties::Bmp

Inherits:
Base
  • Object
show all
Defined in:
lib/cul_image_props/image/properties/types.rb

Constant Summary

Constants inherited from Base

Cul::Image::Properties::Base::BASE_XML

Instance Attribute Summary

Attributes inherited from Base

#nodeset

Instance Method Summary collapse

Methods inherited from Base

#[], #add_dt_prop, #extent=, #format=, #hex_inspect, #inspect, #length=, #ord_value, #sampling_unit=, #width=, #x_sampling_freq=, #y_sampling_freq=

Constructor Details

#initialize(srcfile = nil) ⇒ Bmp

Returns a new instance of Bmp.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/cul_image_props/image/properties/types.rb', line 110

def initialize(srcfile=nil)
  super
  header_bytes = @src.read(18)
  unless header_bytes[0...2].unpack('C*') == Cul::Image::Magic::BMP
    raise "Source file is not a bitmap: #{hex_inspect(header_bytes[0...2])}"
  end
  size = header_bytes[-4,4].unpack('V')[0]
  header_bytes = header_bytes + @src.read(size)
  dims = header_bytes[0x12...0x1a].unpack('VV')
  sampling = header_bytes[0x26...0x2e].unpack('VV')
  self.sampling_unit=3
  self.width= dims[0]
  self.length= dims[1]
  self.format= MIME[:bmp]
  self.extent= srcfile.stat.size unless srcfile.nil?
  self.x_sampling_freq= (sampling[0]) # / 100).ceil
  self.y_sampling_freq= (sampling[1]) # / 100).ceil
end