Class: Cairo::ImageSurface

Inherits:
Surface
  • Object
show all
Defined in:
lib/autoload/autoload_graphics_cairo.rb,
lib/graphics/cairo.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new_from_ca(ca) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/graphics/cairo.rb', line 18

def self.new_from_ca (ca)
  
  if ca.data_type != CA_UINT8
    raise "invalid data_type for Cairo::ImageSurface"
  end
  
  case true
  when ( ca.rank == 2 ),
       ( ( ca.rank == 3 ) and ( ca.dim2 == 1 ) )
    image_type = Cairo::FORMAT_A8
    img = Cairo::ImageSurface.new(image_type, ca.dim1, ca.dim0)
    img.ca[] = ca
  when ( ca.data_type == CA_UINT8 and ca.rank == 3 and ca.dim2 == 3 )
    image_type = Cairo::FORMAT_RGB24
    img = Cairo::ImageSurface.new(image_type, ca.dim1, ca.dim0)
    img.ca[] = ca
  when ( ca.data_type == CA_UINT8 and ca.rank == 3 and ca.dim2 == 4 )
    image_type = Cairo::FORMAT_ARGB32
    img = Cairo::ImageSurface.new(image_type, ca.dim1, ca.dim0)
    img.ca[] = ca
  else
    raise "invalid shape of carray to create Cairo::ImageSurface"
  end

  return img
end

Instance Method Details

#to_caObject



45
46
47
# File 'lib/graphics/cairo.rb', line 45

def to_ca
  return ca.to_ca
end