class

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

==(other : self)

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

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

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.

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
Source
color=(color : Color::Color)
Source
color_model

color_model returns the Image's color model

Source
convert(c : Color::Color) : Color::Color
Source
hash(hasher)

See Object#hash(hasher)

name
Source
opaque?

opaque? scans the entire image and reports whether it is fully opaque

Source
rgba

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.

Source
set(x : Int32, y : Int32, c : Color::Color)

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.

Source