struct Shale::Surface

Defined in:

shale/surface.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(width : UInt32, height : UInt32, channels : Int32 = 4) #

Create a surface buffer.

Arguments

  • width
  • height
  • channels

Description


[View source]

Instance Method Detail

def channels : Int32 #

[View source]
def clear(shade : UInt8 = 0) #

Clear the buffer.

Arguments

  • shade Provide an 8-bit colour to fill the buffer.

Description

This will fill in the buffer's @data property to clear whatever has been set.


[View source]
def copy_pixel(dest_x, dest_y, src_x, src_y, src : Surface) #

quick and dirty way to copy value from slice to slice, trying to get it working first from what's coded in the video, then i will look up another way that maybe better from the crystal docs


[View source]
def data : Bytes #

[View source]
def height : UInt32 #

[View source]
def inspect(io : IO) : Nil #
Description copied from struct Struct

Appends this struct's name and instance variables names and values to the given IO.

struct Point
  def initialize(@x : Int32, @y : Int32)
  end
end

p1 = Point.new 1, 2
p1.to_s    # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"

[View source]
def map_pixel(x : UInt32, y : UInt32, *colours : UInt8) #

Map pixel to the surface

Arguments

  • x Horizontal coordinate.
  • y Vertial coordinate.
  • *colours Tuple of colour values, order currently is for BGRA.

Description

Maps a pixel at the exact coordinate in the surface buffer with the provided colour channels.

There is bounds checking on the incoming parameters, and the mapping of the colours are using Slice#unsafe_put method to skip its own bounds checking. This is done for performance reasons, however (in limited test time) the speed up is more significant when not building with the --release flag.

NOTE Im not sure about a splat for the incoming colours, since I'm not sure if or how to support other colour channel sequences, i.e. CMYK, YCbCr, etc.


[View source]
def to_unsafe : Pointer(Bytes) #

[View source]
def width : UInt32 #

[View source]