class

Image::NRGBA8

Inherits Image::PixelBuffer < Reference < Object

NRGBA8 is an in-memory image storing Color::NRGBA8 pixels.

Non-premultiplied alpha version of RGBA8. RGB values are independent of alpha. Easier for color manipulation but less efficient for compositing than RGBA8.

Storage format: Raw bytes in R, G, B, A order Memory usage: width × height × 4 bytes

Use cases:

  • Color editing (adjust RGB without affecting transparency)
  • Image formats that store non-premultiplied data (PNG)
  • Interchange format between different alpha conventions

Features:

  • Direct byte buffer access via pix method
  • Sub-image support (shares underlying buffer)
  • Stride support for flexible memory layouts

Example:

img = Image::NRGBA8.new(Image.rect(0, 0, 640, 480))
img[10, 20] = Image::Color::NRGBA8.new(255, 0, 0, 128) # 50% transparent red

Constructors

new(pix : Bytes, stride : Int32, rect : Rectangle)
Source
new(rect : Rectangle)
Source

Instance methods

at(x : Int32, y : Int32) : Color::NRGBA8

Returns the pixel at (x, y), or default value if out of bounds

Source
bounds

Returns the rectangular bounds where pixels are defined

Source
pix

Direct access to underlying byte buffer

Source
set(x : Int32, y : Int32, pixel : Color::NRGBA8) : Nil

Sets the pixel at (x, y), no-op if out of bounds

Source
stride

Stride in bytes (bytes per row)

Source
sub_image(rect : Rectangle) : NRGBA8

Returns a sub-image that shares the same byte buffer

Source
unsafe_at(x : Int32, y : Int32) : Color::NRGBA8

Returns the pixel at (x, y) without bounds checking. undefined behavior if out of bounds.

Source