class CooCoo::Image::Base
Attributes
background[R]
bpp[R]
height[R]
repeat_x[RW]
repeat_y[RW]
width[R]
Public Class Methods
new(width, height, bpp = 1, pixels = nil, background = nil, repeat_x = false, repeat_y = false)
click to toggle source
# File lib/coo-coo/image.rb, line 9 def initialize(width, height, bpp = 1, pixels = nil, background = nil, repeat_x = false, repeat_y = false) @width = width @height = height @bpp = bpp @span = @width * @bpp @background = background || bpp.times.collect { 0 } @repeat_x = repeat_x @repeat_y = repeat_y @pixels = pixels || Array.new(@width * @height * @bpp, 0) end
Public Instance Methods
*(transform)
click to toggle source
# File lib/coo-coo/image.rb, line 54 def *(transform) TransformedImage.new(self, transform) end
[](x, y, byte = nil)
click to toggle source
# File lib/coo-coo/image.rb, line 20 def [](x, y, byte = nil) if (@repeat_x == false && (x < 0 || x >= width)) || (@repeat_y == false && (y < 0 || y >= height)) p = @background if byte p[byte] else p end else i = pixel_index(x, y, byte || 0) if byte @pixels[i] || @background[byte] else p = @pixels[i, @bpp] if p && !p.empty? p else @background end end end end
[]=(x, y, v)
click to toggle source
# File lib/coo-coo/image.rb, line 44 def []=(x, y, v) @bpp.times do |byte| c = v if v.respond_to?(:[]) c = v[byte] end @pixels[*pixel_index(x, y, byte)] = c end end
filter(f)
click to toggle source
# File lib/coo-coo/image.rb, line 58 def filter(f) TransformedImage.new(self, nil, f) end
to_a()
click to toggle source
# File lib/coo-coo/image.rb, line 62 def to_a @pixels.each_slice(@span).collect do |row| if @bpp > 1 row.each_slice(@bpp).to_a else row.to_a end end end
Private Instance Methods
pixel_index(x, y, byte = 0)
click to toggle source
# File lib/coo-coo/image.rb, line 73 def pixel_index(x, y, byte = 0) (byte || 0) + ((x.round % @width) * @bpp) + ((y.round % @height) * @span) end