Class: CooCoo::Image::TransformedImage
Instance Method Summary collapse
- #*(transform) ⇒ Object
- #[](x, y, byte = nil) ⇒ Object
- #bpp ⇒ Object
- #filter(pixel, x, y) ⇒ Object
- #height ⇒ Object
-
#initialize(image, transform, filter = nil) ⇒ TransformedImage
constructor
A new instance of TransformedImage.
- #to_a ⇒ Object
- #transform(x, y) ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(image, transform, filter = nil) ⇒ TransformedImage
Returns a new instance of TransformedImage.
79 80 81 82 83 |
# File 'lib/coo-coo/image.rb', line 79 def initialize(image, transform, filter = nil) @image = image @transform = transform @filter = filter end |
Instance Method Details
#*(transform) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/coo-coo/image.rb', line 97 def *(transform) t = if @transform TransformChain.new(@transform, transform) else transform end TransformedImage.new(@image, t, @filter) end |
#[](x, y, byte = nil) ⇒ Object
114 115 116 117 118 |
# File 'lib/coo-coo/image.rb', line 114 def [](x, y, byte = nil) x, y = *transform(x, y) p = @image[x, y, byte] filter(p, x, y) end |
#bpp ⇒ Object
93 94 95 |
# File 'lib/coo-coo/image.rb', line 93 def bpp @image.bpp end |
#filter(pixel, x, y) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/coo-coo/image.rb', line 120 def filter(pixel, x, y) if @filter @filter.call(pixel, x, y) else pixel end end |
#height ⇒ Object
89 90 91 |
# File 'lib/coo-coo/image.rb', line 89 def height @image.height end |
#to_a ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/coo-coo/image.rb', line 106 def to_a height.times.collect do |y| width.times.collect do |x| self[x, y] end.flatten end end |
#transform(x, y) ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/coo-coo/image.rb', line 128 def transform(x, y) if @transform @transform.call(x, y) else [ x, y ] end end |
#width ⇒ Object
85 86 87 |
# File 'lib/coo-coo/image.rb', line 85 def width @image.width end |