Class: Quartz::Bitmap

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyquartz/bitmap.rb

Instance Method Summary collapse

Constructor Details

#initialize(width, height, colorspace, options = {}) ⇒ Bitmap



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rubyquartz/bitmap.rb', line 28

def initialize(width, height, colorspace, options={})
  raise "Width must be an integer" if width.to_i != width
  raise "Height must be an integer" if height.to_i != height
  
  super()
  
  bits_per_channel = options[:bits_per_channel] || 8
  alpha = options[:alpha] || Bitmap::ALPHA_PREMULTIPLIED_FIRST
  float_pixels = options[:float_pixels] || false
  byte_order = options[:byte_order] || Bitmap::BYTE_ORDER_DEFAULT
  
  bytes_per_row = options[:bytes_per_row]
  if bytes_per_row.nil?
    case alpha
    when Bitmap::ALPHA_NONE
      component_count = colorspace.component_count
    when Bitmap::ALPHA_ONLY
      component_count = 1
    else
      component_count = colorspace.component_count + 1
    end
    
    if float_pixels
      bytes_per_component = 4
    else
      bytes_per_component = 1
    end
    
    bytes_per_row = width * component_count * bytes_per_component
  end
  
  _initialize(width, height, bits_per_channel, bytes_per_row, alpha, float_pixels, byte_order)
end