class

Image::Gray8

Inherits Image::PixelBuffer < Reference < Object

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

Optimized for grayscale images - uses 1 byte per pixel instead of 4.

Storage format: Raw bytes, one byte per pixel (grayscale value) Memory usage: width × height × 1 byte

Features:

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

Example:

img = Image::Gray8.new(Image.rect(0, 0, 640, 480))
img[10, 20] = Image::Color::Gray8.new(128)

Constructors

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

Instance methods

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

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

Source
bounds

Returns the rectangular bounds where pixels are defined

Source
opaque?

Grayscale images are always fully opaque (no alpha channel)

Source
pix

Direct access to underlying byte buffer

Source
set(x : Int32, y : Int32, pixel : Color::Gray8) : 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) : Gray8

Returns a sub-image that shares the same byte buffer

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

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

Source