Class: CArray
- Inherits:
-
Object
- Object
- CArray
- Defined in:
- lib/autoload/autoload_io_rmagick.rb,
lib/io/rmagick.rb
Class Method Summary collapse
Instance Method Summary collapse
- #display_image(map = "RGBO", ch = nil) ⇒ Object
- #save_image(file, map = "RGBO", ch = nil) ⇒ Object
- #to_image(map = "RGBO", ch = nil) ⇒ Object
Class Method Details
.load_image(file, map = "RGBO", data_type = nil) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/io/rmagick.rb', line 94 def self.load_image (file, map="RGBO", data_type = nil) img = Magick::Image.read(file).first rows, cols = img.rows, img.columns unless data_type case img.quantum_depth when 8 data_type = CA_UINT8 when 16 data_type = CA_UINT16 when 32 data_type = CA_UINT32 end end case map.size when 1 out = CArray.new(data_type, [rows, cols]) else out = CArray.new(data_type, [rows, cols, map.size]) end img.export_pixels_to_ca(out, map) return out end |
Instance Method Details
#display_image(map = "RGBO", ch = nil) ⇒ Object
143 144 145 |
# File 'lib/io/rmagick.rb', line 143 def display_image (map="RGBO", ch=nil) to_image(map, ch).display end |
#save_image(file, map = "RGBO", ch = nil) ⇒ Object
138 139 140 141 |
# File 'lib/io/rmagick.rb', line 138 def save_image (file, map="RGBO", ch=nil) to_image(map, ch).write(file) return nil end |
#to_image(map = "RGBO", ch = nil) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/io/rmagick.rb', line 117 def to_image (map="RGBO", ch=nil) img = Magick::Image.new(dim1, dim0) case data_type when CA_FIXLEN img.import_pixels_from_ca(self, map) else case rank when 2 map = "I" ca = self[:%, :%, 1] when 3 unless ch ch = Array.new(map.size){|i| i} end ca = self[nil,nil,CA_INT(ch)] end img.import_pixels_from_ca(ca, map) end return img end |