Class: CAMagickImage

Inherits:
CAObject
  • Object
show all
Defined in:
lib/object/ca_obj_magick_image.rb

Constant Summary collapse

DEPTH_TO_TYPE =
{ 
  8 => CA_UINT8,
  16 => CA_UINT16,
  32 => CA_UINT32
}

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ CAMagickImage



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/object/ca_obj_magick_image.rb', line 24

def initialize (image)
  @image = image
  if Magick.const_defined?(:QuantumDepth)
    magick_quantum_depth = Magick::QuantumDepth
  else
    magick_quantum_depth = Magick::MAGICKCORE_QUANTUM_DEPTH      
  end
  @qtype = DEPTH_TO_TYPE[magick_quantum_depth]
  type   = DEPTH_TO_TYPE[@image.quantum_depth]
  @scale = 0
  (magick_quantum_depth / @image.quantum_depth).times do |i|
    @scale += 1 << @image.quantum_depth * i
  end
  super(type, [@image.rows, @image.columns, 4])
end

Instance Method Details

#copy_data(data) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/object/ca_obj_magick_image.rb', line 48

def copy_data (data)
  qdata = CArray.wrap_writable(data, @qtype)
  qdata.attach! {
    @image._copy_data_to_ca(qdata)
    if @scale != 1
      qdata.div!(@scale)
    end
  }
end

#fetch_index(idx) ⇒ Object



40
41
42
# File 'lib/object/ca_obj_magick_image.rb', line 40

def fetch_index (idx)
  return @image._fetch_index(idx)/@scale
end

#fill_data(val) ⇒ Object



68
69
70
# File 'lib/object/ca_obj_magick_image.rb', line 68

def fill_data (val)
  return @image._fill_data(val*@scale)
end

#store_index(idx, val) ⇒ Object



44
45
46
# File 'lib/object/ca_obj_magick_image.rb', line 44

def store_index (idx, val)
  return @image._store_index(idx, val*@scale)
end

#sync_data(data) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/object/ca_obj_magick_image.rb', line 58

def sync_data (data)
  qdata = CArray.wrap_readonly(data, @qtype)
  qdata.attach {
    if @scale != 1
      qdata.mul!(@scale)
    end 
    @image._sync_data_from_ca(qdata)
  }
end