class PNG::Canvas
- PNG::Canvas
- Reference
- Object
Overview
A canvas holds all of the PNG data including the header and other chunk information
Included Modules
Defined in:
png/canvas.crConstructors
- .new(width : UInt32, height : UInt32, palette : PNG::Palette | Nil = nil)
- .new(header : PNG::Header, data : Bytes | Nil = nil, palette : PNG::Palette | Nil = nil)
Class Method Summary
- .make(width : UInt32, height : UInt32, palette : Palette | Nil = nil, &)
- .make(header : Header, palette : Palette | Nil = nil, &)
Instance Method Summary
-
#[](x : UInt32, y : UInt32)
Get the data at x, y into the canvas.
-
#[](x : Number, y : Number)
Get the data at x, y into the canvas.
- #[]=(x : UInt32, y : UInt32, c : Int, value : UInt8)
-
#[]=(x : UInt32, y : UInt32, values : Indexable(UInt8))
Set the pixel at x, y on the canvas via bytes that correspond to the color type and bit depth.
- #[]=(x, y, values : Indexable(UInt8))
- #[]=(x, y, values : Indexable(UInt16))
- #[]=(x, y, values : Indexable(Number))
- #[]=(x, y, value : Int)
- #bg_color : Bytes | Nil
- #bg_color=(bg_color : Bytes | Nil)
- #bit_depth(*args, **options)
- #bit_depth(*args, **options, &)
-
#bit_index(x : UInt32, y : UInt32)
Calculates the index into the canvas that a value would be at, accounting for padding that would exist at the end of a scanline where bit depth < 8
- #bits_per_pixel(*args, **options)
- #bits_per_pixel(*args, **options, &)
- #byte_index(x : UInt32, y : UInt32)
- #bytes_per_pixel(*args, **options)
- #bytes_per_pixel(*args, **options, &)
- #bytes_per_row(*args, **options)
- #bytes_per_row(*args, **options, &)
-
#clone
Return a deep clone of this canvas
-
#color(x, y) : Enumerable
Get the color at x, y
- #color_type(*args, **options)
- #color_type(*args, **options, &)
-
#copy_ancilarry(to : Canvas)
Copy the ancillarry data to a new canvas
-
#crop(start_x : Int, start_y : Int, end_x : Int, end_y : Int)
Crop a canvas in absolute coordinates
- #data : Bytes
- #data=(data : Bytes)
- #gama : UInt32 | Nil
- #gama=(gama : UInt32 | Nil)
- #header : Header
- #header=(header : Header)
- #height(*args, **options)
- #height(*args, **options, &)
- #interlaced? : Bool
- #last_modified : Time | Nil
- #last_modified=(last_modified : Time | Nil)
- #palette : Palette | Nil
- #palette=(palette : Palette | Nil)
- #pixel_size : PixelSize | Nil
- #pixel_size=(pixel_size : PixelSize | Nil)
- #resize_bilinear(width, height)
- #resize_nearest_neighbor(width, height)
-
#scanline(y)
Return the bytes corresponding to scanline
-
#set_color(x, y, color : Enumerable)
Set a color at x, y
- #transparency : Bytes | Nil
- #transparency=(transparency : Bytes | Nil)
- #width(*args, **options)
- #width(*args, **options, &)
Instance methods inherited from module Drawable
color(x, y) : Enumerable
color,
fill(&)
fill,
height
height,
set_color(x, y, color : Enumerable)
set_color,
width
width
Class methods inherited from module Drawable
resize_bilinear(source : Drawable, dest : Drawable)
resize_bilinear,
resize_nearest_neighbor(source : Drawable, dest : Drawable)
resize_nearest_neighbor
Constructor Detail
Class Method Detail
Instance Method Detail
Get the data at x, y into the canvas. This returns the Bytes that represent the pixel.
Get the data at x, y into the canvas. This returns the Bytes that represent the pixel.
Set the pixel at x, y on the canvas via bytes that correspond to the color type and bit depth.
For example, an image with 8bits per channel in RGB (PNG::ColorType::TrueColor
)
would be set with 3 bytes: canvas[0, 0] = Bytes[255, 0, 255]
A canvas with 16bits in RGB would accept 6 bytes, (2 bytes per channel):
canvas[0, 0] = Bytes[255, 255, 0, 0, 255, 255]
Calculates the index into the canvas that a value would be at, accounting for padding that would exist at the end of a scanline where bit depth < 8
Crop a canvas in absolute coordinates