class UIng::ImageBuffer

Overview

A mutable, fixed-resolution RGBA image. All native operations must run on the UI thread between UIng.init and UIng.uninit. Call free explicitly or use open; native resources are not released by a GC finalizer. Requires ImageBuffer-capable libui-ng (dev da49cf29 or later), included in the release pinned in download.cr.

Included Modules

Defined in:

uing/crimage.cr
uing/image_buffer.cr

Constructors

Class Method Summary

Instance Method Summary

Macros inherited from module UIng::BlockConstructor

block_constructor block_constructor

Constructor Detail

def self.new(*args, &) #

[View source]
def self.new(*args, **kwargs, &) #

[View source]
def self.new(width : Int32, height : Int32, *, format : Format = Format::RGBA8Straight) #

[View source]
def self.new(source : CrImage::Image, *, format : Format = CrImageAdapter.image_buffer_format(source)) #

Creates and fills a buffer. NRGBA/NRGBA64 use straight alpha; other image types use premultiplied alpha. An explicit format overrides that choice.


[View source]

Class Method Detail

def self.open(width : Int32, height : Int32, *, format : Format = Format::RGBA8Straight, &) #

Always frees the buffer, including on exceptions; returns the block value. Keep the event loop inside the block when callbacks refer to this buffer.


[View source]
def self.open(source : CrImage::Image, *, format : Format = CrImageAdapter.image_buffer_format(source), &) #

Keeps the event loop inside the block and frees the buffer on every exit.


[View source]

Instance Method Detail

def format : Format #

[View source]
def free : Nil #

Idempotent. Already submitted draws remain valid after this call.


[View source]
def height : Int32 #

[View source]
def released? : Bool #

[View source]
def size : Tuple(Int32, Int32) #

Pixel dimensions, independent of drawing coordinates or display DPI.


[View source]
def to_unsafe : Pointer(LibUI::ImageBuffer) #

[View source]
def update(source : CrImage::Image) : Nil #

Copies a CrImage image with matching dimensions. Alpha representation and stride are adapted to this buffer's format. Does not request a redraw.


[View source]
def update(pixels : Bytes, *, byte_stride : Int = @width.to_i64 * 4) : Nil #

Copies the input before return. Final-row padding is optional. Straight RGBA is premultiplied natively; premultiplied input requires R, G, B <= A. Updates do not request a redraw; call Area#queue_redraw_all as needed.


[View source]
def update_rect(x : Int32, y : Int32, width : Int32, height : Int32, pixels : Bytes, *, byte_stride : Int = width.to_i64 * 4) : Nil #

pixels starts at the patch's top-left pixel. The rectangle must fit fully inside this buffer; pixels outside it are preserved, without compositing.


[View source]
def update_rect(x : Int32, y : Int32, source : CrImage::Image) : Nil #

Copies the entire patch at destination (x, y), using its visible bounds for the patch dimensions. Pixels outside the destination are preserved.


[View source]
def width : Int32 #

[View source]