CrImage::Uniform
Inherits CrImage::Image / CrImage::Color::Model / CrImage::Color::Color / Reference / Object
Uniform is an infinite-sized image of a single uniform color.
This is a memory-efficient representation for solid color images. Instead of storing pixel data, it returns the same color for all coordinates.
Bounds: Effectively infinite (±1 billion pixels) Memory: Only stores a single color value
Use Uniform for:
- Solid color backgrounds
- Fill patterns
- Compositing operations with uniform colors
Example:
white = CrImage::Uniform.new(CrImage::Color::WHITE)
red = CrImage::Uniform.new(CrImage::Color.rgb(255, 0, 0))
color = white.at(1000, 1000) # Always returns white
Constructors
Instance methods
Returns true if this reference is the same as other. Invokes same?.
Returns the color of the pixel at (x,y).
If coordinates are outside bounds, returns a default color (typically transparent black) rather than raising an exception. This simplifies image processing algorithms.
at(bounds().min.x, bounds().min.y)returns the upper-left pixel of the grid.at(bounds().max.x-1, bounds().max.y-1)returns the lower-right one.
For explicit nil on out-of-bounds, concrete types provide at? method.
bounds returns the domain for which at can return non-zero color.
The bounds do not necessarily contain the point(0,0).
See Object#hash(hasher)
RGBA returns the alpha-premultiplied red, green, blue and alpha values for the color. Each value ranges within [0, 0xffff], but is represented by a uint32 so that multiplying by a blend factor up to 0xffff will not overflow.
An alpha-premultiplied color component c has been scaled by alpha (a), so has valid values 0 <= c <= a.
Sets the color of the pixel at (x,y).
If the provided coordinates are not within bounds, this method does nothing (no-op). This simplifies drawing operations that may extend beyond image boundaries.