class

CrImage::RGBA64

Inherits CrImage::Image / Reference / Object

RGBA64 is an in-memory 64-bit image with premultiplied alpha.

Each pixel is stored as 8 bytes (16 bits per channel: R, G, B, A). Provides higher color precision than 8-bit RGBA for professional imaging.

Memory layout: Contiguous byte array with 8 bytes per pixel Color model: RGBA64 with premultiplied alpha (16-bit per channel)

Example:

img = CrImage::RGBA64.new(CrImage.rect(0, 0, 640, 480))
img.set_rgba64(100, 100, CrImage::Color::RGBA64.new(65535, 0, 0, 65535))

Constructors

from_buffer(buffer : Bytes, width : Int32, height : Int32) : self

Creates an image from an existing pixel buffer.

Convenience constructor that calculates stride automatically. The buffer is used directly (not copied), so modifications to the image will affect the original buffer.

Parameters:

  • buffer : Raw pixel data in row-major order
  • width : Image width in pixels
  • height : Image height in pixels

Raises: ArgumentError if buffer size doesn't match expected size

Example:

# Create 100x100 RGBA image from raw bytes
pixels = Bytes.new(100 * 100 * 4)
img = CrImage::RGBA.from_buffer(pixels, 100, 100)
Source
new(r : Rectangle)
Source
new(pix : Slice(UInt8) = Bytes.empty, stride : Int32 = 0, rect : CrImage::Rectangle = Rectangle.zero)
Source

Instance methods

==(other : self)

Returns true if this reference is the same as other. Invokes same?.

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

Returns the color at the specified coordinates.

If the coordinates are outside the image bounds, returns a default color (typically transparent black) rather than raising an exception. This is intentional behavior to simplify image processing algorithms that may sample outside bounds.

For explicit bounds checking, use bounds.in?(Point.new(x, y)) before calling.

Parameters:

  • x : X coordinate
  • y : Y coordinate

Returns: The color at (x, y), or default color if out of bounds

Example:

img = CrImage.rgba(100, 100)
color = img.at(50, 50)      # Returns actual color
color = img.at(200, 200)    # Returns default color (out of bounds)

# Explicit bounds check:
if img.bounds.in?(CrImage.point(x, y))
  color = img.at(x, y)  # Guaranteed to be actual pixel
end
Source
at?(x : Int32, y : Int32) : Color::RGBA64 | Nil

Returns the color at the specified coordinates, or nil if out of bounds.

This is an alternative to at that explicitly returns nil for out-of-bounds coordinates, making bounds checking more explicit in the type system.

Parameters:

  • x : X coordinate
  • y : Y coordinate

Returns: The color at (x, y), or nil if out of bounds

Example:

img = CrImage.rgba(100, 100)
if color = img.at?(50, 50)
  # color is guaranteed to be from the image
end

img.at?(200, 200)  # => nil (out of bounds)
Source
bounds

bounds returns the domain for which at can return non-zero color. The bounds do not necessarily contain the point(0,0).

Source
color_model

color_model returns the Image's color model

Source
hash(hasher)

See Object#hash(hasher)

opaque?
Source
pixel_offset(x : Int32, y : Int32) : Int32
Source
rect
rgba64_at(x : Int32, y : Int32) : Color::RGBA64
Source
set(x : Int32, y : Int32, c : Color::Color)

Sets the color at the specified coordinates.

If the coordinates are outside the image bounds, this method does nothing (no-op) rather than raising an exception. This is intentional behavior to simplify drawing operations that may extend beyond image boundaries.

For explicit bounds checking, use bounds.in?(Point.new(x, y)) before calling.

Parameters:

  • x : X coordinate
  • y : Y coordinate
  • c : Color to set

Example:

img = CrImage.rgba(100, 100)
img.set(50, 50, CrImage::Color::RED)    # Sets pixel
img.set(200, 200, CrImage::Color::RED)  # No-op (out of bounds)
Source
set_rgba64(x : Int32, y : Int32, c : Color::RGBA64)
Source
stride
sub_image(r : Rectangle) : Image
Source
swap_buffer(buffer : Bytes) : Nil

Swaps the underlying pixel buffer without allocation.

Useful for video/realtime processing where you want to reuse an image object with different frame data.

Parameters:

  • buffer : New pixel buffer (must match current dimensions)

Raises: ArgumentError if buffer size doesn't match

Example:

img = CrImage::RGBA.from_buffer(frame1, 1920, 1080)
process(img)
img.swap_buffer(frame2)  # Zero allocation
process(img)
Source