class PNG::Canvas

Overview

A canvas holds all of the PNG data including the header and other chunk information

Included Modules

Defined in:

png/canvas.cr

Constructors

Class Method Summary

Instance Method Summary

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

def self.new(width : UInt32, height : UInt32, palette : PNG::Palette | Nil = nil) #

[View source]
def self.new(header : PNG::Header, data : Bytes | Nil = nil, palette : PNG::Palette | Nil = nil) #

[View source]

Class Method Detail

def self.make(width : UInt32, height : UInt32, palette : Palette | Nil = nil, &) #

[View source]
def self.make(header : Header, palette : Palette | Nil = nil, &) #

[View source]

Instance Method Detail

def [](x : UInt32, y : UInt32) #

Get the data at x, y into the canvas. This returns the Bytes that represent the pixel.


[View source]
def [](x : Number, y : Number) #

Get the data at x, y into the canvas. This returns the Bytes that represent the pixel.


[View source]
def []=(x : UInt32, y : UInt32, c : Int, value : UInt8) #

[View source]
def []=(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.

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]


[View source]
def []=(x, y, values : Indexable(UInt8)) #

[View source]
def []=(x, y, values : Indexable(UInt16)) #

[View source]
def []=(x, y, values : Indexable(Number)) #

[View source]
def []=(x, y, value : Int) #

[View source]
def bg_color : Bytes | Nil #

[View source]
def bg_color=(bg_color : Bytes | Nil) #

[View source]
def bit_depth(*args, **options) #

[View source]
def bit_depth(*args, **options, &) #

[View source]
def 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


[View source]
def bits_per_pixel(*args, **options) #

[View source]
def bits_per_pixel(*args, **options, &) #

[View source]
def byte_index(x : UInt32, y : UInt32) #

[View source]
def bytes_per_pixel(*args, **options) #

[View source]
def bytes_per_pixel(*args, **options, &) #

[View source]
def bytes_per_row(*args, **options) #

[View source]
def bytes_per_row(*args, **options, &) #

[View source]
def clone #

Return a deep clone of this canvas


[View source]
def color(x, y) : Enumerable #

Get the color at x, y


[View source]
def color_type(*args, **options) #

[View source]
def color_type(*args, **options, &) #

[View source]
def copy_ancilarry(to : Canvas) #

Copy the ancillarry data to a new canvas


[View source]
def crop(start_x : Int, start_y : Int, end_x : Int, end_y : Int) #

Crop a canvas in absolute coordinates


[View source]
def data : Bytes #

[View source]
def data=(data : Bytes) #

[View source]
def gama : UInt32 | Nil #

[View source]
def gama=(gama : UInt32 | Nil) #

[View source]
def header : Header #

[View source]
def header=(header : Header) #

[View source]
def height(*args, **options) #

[View source]
def height(*args, **options, &) #

[View source]
def interlaced? : Bool #

[View source]
def last_modified : Time | Nil #

[View source]
def last_modified=(last_modified : Time | Nil) #

[View source]
def palette : Palette | Nil #

[View source]
def palette=(palette : Palette | Nil) #

[View source]
def pixel_size : PixelSize | Nil #

[View source]
def pixel_size=(pixel_size : PixelSize | Nil) #

[View source]
def resize_bilinear(width, height) #

[View source]
def resize_nearest_neighbor(width, height) #

[View source]
def scanline(y) #

Return the bytes corresponding to scanline


[View source]
def set_color(x, y, color : Enumerable) #

Set a color at x, y


[View source]
def transparency : Bytes | Nil #

[View source]
def transparency=(transparency : Bytes | Nil) #

[View source]
def width(*args, **options) #

[View source]
def width(*args, **options, &) #

[View source]