class
UIng::ImageBuffer
- UIng::ImageBuffer
- Reference
- Object
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
- UIng::BlockConstructor
Defined in:
uing/crimage.cruing/image_buffer.cr
Constructors
- .new(*args, &)
- .new(*args, **kwargs, &)
- .new(width : Int32, height : Int32, *, format : Format = Format::RGBA8Straight)
-
.new(source : CrImage::Image, *, format : Format = CrImageAdapter.image_buffer_format(source))
Creates and fills a buffer.
Class Method Summary
-
.open(width : Int32, height : Int32, *, format : Format = Format::RGBA8Straight, &)
Always frees the buffer, including on exceptions; returns the block value.
-
.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.
Instance Method Summary
- #format : Format
-
#free : Nil
Idempotent.
- #height : Int32
- #released? : Bool
-
#size : Tuple(Int32, Int32)
Pixel dimensions, independent of drawing coordinates or display DPI.
- #to_unsafe : Pointer(LibUI::ImageBuffer)
-
#update(source : CrImage::Image) : Nil
Copies a CrImage image with matching dimensions.
-
#update(pixels : Bytes, *, byte_stride : Int = @width.to_i64 * 4) : Nil
Copies the input before return.
-
#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.
-
#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.
- #width : Int32
Macros inherited from module UIng::BlockConstructor
block_constructor
block_constructor
Constructor Detail
Creates and fills a buffer. NRGBA/NRGBA64 use straight alpha; other image types use premultiplied alpha. An explicit format overrides that choice.
Class Method Detail
Always frees the buffer, including on exceptions; returns the block value. Keep the event loop inside the block when callbacks refer to this buffer.
Keeps the event loop inside the block and frees the buffer on every exit.
Instance Method Detail
Pixel dimensions, independent of drawing coordinates or display DPI.
Copies a CrImage image with matching dimensions. Alpha representation and stride are adapted to this buffer's format. Does not request a redraw.
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.
pixels starts at the patch's top-left pixel. The rectangle must fit fully inside this buffer; pixels outside it are preserved, without compositing.
Copies the entire patch at destination (x, y), using its visible bounds for the patch dimensions. Pixels outside the destination are preserved.