class CooCoo::Transformers::Image::Scaler
Public Class Methods
new(enum, width, height, scale_x, scale_y)
click to toggle source
Calls superclass method
CooCoo::Transformers::Image::Base::new
# File lib/coo-coo/transformer.rb, line 191 def initialize(enum, width, height, scale_x, scale_y) super(enum, width, height) @scale_x = scale_x @scale_y = scale_y end
Public Instance Methods
next()
click to toggle source
Calls superclass method
CooCoo::Transformers::Proxy#next
# File lib/coo-coo/transformer.rb, line 197 def next i = super() r = NMatrix.zeroes([1, width * height]) height.times do |y| width.times do |x| r[0, map_pixel(x, y)] = sample(i, x, y) end end r end
Private Instance Methods
map_pixel(x, y)
click to toggle source
# File lib/coo-coo/transformer.rb, line 230 def map_pixel(x, y) x + y * width end
sample(image, x, y)
click to toggle source
# File lib/coo-coo/transformer.rb, line 210 def sample(image, x, y) if @scale_x == 1.0 && @scale_y == 1.0 image[0, map_pixel(x, y)] elsif @scale_x > 1.0 && @scale_y > 1.0 rx, ry = *scale_pixel(x, y) image[0, map_pixel(rx.to_i, ry.to_i)] else rx, ry = *scale_pixel(x, y) rx_min = rx.floor % width rx_max = rx.ceil % width ry_min = ry.floor % height ry_max = ry.ceil % height (image[0, map_pixel(rx_min, ry_min)] + image[0, map_pixel(rx_max, ry_min)] + image[0, map_pixel(rx_min, ry_max)] + image[0, map_pixel(rx_max, ry_max)]) / 4.0 end end
scale_pixel(x, y)
click to toggle source
# File lib/coo-coo/transformer.rb, line 234 def scale_pixel(x, y) [ (x * @scale_x) % width, (y * @scale_y) % height ] end