Image::PixelBuffer(T)
PixelBuffer represents a finite rectangular grid of pixels.
This is the core interface that all image types implement. It provides a uniform way to access and modify pixels regardless of the underlying storage mechanism.
Type parameter T specifies the pixel type (Color::RGBA8, Color::Gray8, etc.)
Key concepts:
- Bounds define the valid coordinate range (may not start at 0,0)
- Coordinates outside bounds return default values (no exceptions)
- The pixel at (x,y) represents the grid square from (x,y) to (x+1,y+1)
Implementations:
- Slice-based: RGBA8, Gray8 (most common - pixels stored in memory)
- Procedural: Uniform (computed on-the-fly, no storage)
- Custom: Libraries can implement their own
Example iteration:
b = img.bounds
b.min.y.upto(b.max.y - 1) do |y|
b.min.x.upto(b.max.x - 1) do |x|
pixel = img[x, y]
# process pixel
end
end
Instance methods
Returns a sub-image view defined by x and y ranges.
Example:
sub = img[10..20, 5...15]
opaque?
Reports whether the image is fully opaque (no transparency).
Iterates over all pixels and checks if they are fully opaque. Short-circuits on the first non-opaque pixel.
Returns the pixel at (x, y) without bounds checking. undefined behavior if out of bounds.