class

Image::Gray16

Inherits Image::PixelBuffer < Reference < Object

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

Higher precision version of Gray8 for scientific imaging and smooth gradients. Uses 16 bits per pixel (2 bytes).

Storage format: Raw bytes in big-endian (2 bytes per pixel) Memory usage: width × height × 2 bytes

Use cases:

  • Medical imaging (X-rays, MRI scans)
  • Scientific visualization
  • Astronomy images
  • Smooth gradients without banding

Features:

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

Example:

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

Constructors

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

Instance methods

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

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::Gray16) : 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) : Gray16

Returns a sub-image that shares the same byte buffer

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

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

Source