CrImage::YCbCr
Inherits CrImage::Image / Reference / Object
YCbCr is an in-memory image using the Y'CbCr color space.
Y'CbCr separates luminance (Y') from chrominance (Cb, Cr), commonly used in JPEG compression and video encoding. There is one Y sample per pixel, but Cb and Cr samples can span multiple pixels depending on the subsampling ratio.
Memory layout:
y_stride: Y slice index delta between vertically adjacent pixelsc_stride: Cb/Cr slice index delta between vertically adjacent chroma samples
Typical stride relationships (y_stride and y.size are multiples of 8):
- For 4:4:4: c_stride == y_stride//1 && cb.size == cr.size == y.size//1
- For 4:2:2: c_stride == y_stride//2 && cb.size == cr.size == y.size//2
- For 4:2:0: c_stride == y_stride//2 && cb.size == cr.size == y.size//4
- For 4:4:0: c_stride == y_stride//1 && cb.size == cr.size == y.size//2
- For 4:1:1: c_stride == y_stride//4 && cb.size == cr.size == y.size//4
- For 4:1:0: c_stride == y_stride//4 && cb.size == cr.size == y.size//8
Example:
# Create YCbCr image with 4:2:0 subsampling (JPEG standard)
img = CrImage::YCbCr.new(
CrImage.rect(0, 0, 640, 480),
CrImage::YCbCrSubSampleRatio::YCbCrSubsampleRatio420
)
# Set pixel in YCbCr space
img.set_ycbcr(100, 100, CrImage::Color::YCbCr.new(128, 128, 128))
Constructors
Instance methods
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).
returns the index of the first element of cb or cr that corresponds to the pixel at (x,y)
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.
sub_image returns an image representing the portion of the image visible though r. the returned value shares pixes with the original image.
returns the index of the first element of Y that corresponds to the pixel at (x,y)