lib/chunky_png/canvas.rb in chunky_png-0.9.2 vs lib/chunky_png/canvas.rb in chunky_png-0.10.0

- old
+ new

@@ -95,24 +95,41 @@ # Replaces a single pixel in this canvas. # @param [Integer] x The x-coordinate of the pixel (column) # @param [Integer] y The y-coordinate of the pixel (row) # @param [ChunkyPNG::Color] pixel The new pixel for the provided coordinates. + # @return [Integer] the new pixel value, i.e. <tt>color</tt>. + # @raise [ChunkyPNG::OutOfBounds] when the coordinates are outside of the image's dimensions. def []=(x, y, color) assert_xy!(x, y) @pixels[y * width + x] = color end + # Replaces a single pixel in this canvas, without bounds checking. + # @param (see #[]=) + # @return [Integer] the new pixel value, i.e. <tt>color</tt>. + def set_pixel(x, y, color) + @pixels[y * width + x] = color + end + # Returns a single pixel from this canvas. # @param [Integer] x The x-coordinate of the pixel (column) # @param [Integer] y The y-coordinate of the pixel (row) # @return [ChunkyPNG::Color] The current pixel at the provided coordinates. + # @raise [ChunkyPNG::OutOfBounds] when the coordinates are outside of the image's dimensions. def [](x, y) assert_xy!(x, y) @pixels[y * width + x] end + # Returns a single pixel from this canvas, without checking bounds. + # @param (see #[]) + # @return [ChunkyPNG::Color] The current pixel at the provided coordinates. + def get_pixel(x, y) + @pixels[y * width + x] + end + # Returns an extracted row as vector of pixels # @param [Integer] y The 0-based row index # @return [Array<Integer>] The vector of pixels in the requested row def row(y) assert_y!(y) @@ -122,11 +139,11 @@ # Returns an extracted column as vector of pixels. # @param [Integer] x The 0-based column index. # @return [Array<Integer>] The vector of pixels in the requested column. def column(x) assert_x!(x) - (0...height).inject([]) { |pixels, y| pixels << self[x, y] } + (0...height).inject([]) { |pixels, y| pixels << get_pixel(x, y) } end # Replaces a row of pixels on this canvas. # @param [Integer] y The 0-based row index. # @param [Array<Integer>] vector The vector of pixels to replace the row with. @@ -139,10 +156,10 @@ # @param [Integer] x The 0-based column index. # @param [Array<Integer>] vector The vector of pixels to replace the column with. def replace_column!(x, vector) assert_x!(x) && assert_height!(vector.length) for y in 0...height do - self[x, y] = vector[y] + set_pixel(x, y, vector[y]) end end # Checks whether the given coordinates are in the range of the canvas # @param [Integer] x The x-coordinate of the pixel (column)