Color Systems and Blending

Chapter 3: Color Systems and Blending

Color is a fundamental aspect of computer graphics. In this chapter, we explore how digital systems represent color, the different color spaces used in various industries, and the mathematical methods for blending colors.

Color Models

A color model is an abstract mathematical model describing the way colors can be represented as tuples of numbers, typically as three or four values or color components.

RGB (Red, Green, Blue)

The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. It is the standard for digital displays.

  • Additive: Starting with black (no light), we add light of different wavelengths.
  • Representation: Typically (0-255) for each channel.
    • (255, 0, 0) is pure Red.
    • (0, 255, 0) is pure Green.
    • (0, 0, 255) is pure Blue.
    • (255, 255, 255) is White.
    • (0, 0, 0) is Black.

CMYK (Cyan, Magenta, Yellow, Black)

The CMYK color model is a subtractive color model used in color printing.

  • Subtractive: Starting with white (paper), we subtract light using inks.
  • Channels:
    • Cyan, Magenta, and Yellow (CMY) can theoretically create all colors, including black.
    • In practice, mixing CMY produces a muddy dark brown, so a separate Key (Black) channel is added for efficiency and clarity.

HSV / HSB (Hue, Saturation, Value/Brightness)

This model is more intuitive for humans than RGB.

  • Hue: The "color" itself, measured as an angle on the color wheel (0-360°).
  • Saturation: The "vividness" or "purity" of the color (0-100%).
  • Value/Brightness: The "lightness" of the color (0-100%).
Hue Spectrum (0-360°)

The Alpha Channel and RGBA

RGBA is simply RGB with an additional Alpha channel, which represents transparency.

  • Range: Usually 0.0 (fully transparent) to 1.0 (fully opaque), or 0 to 255 in integer formats.
  • Purpose: Allows for compositing multiple layers of images.

Color Blending (Alpha Compositing)

When we have two overlapping layers, we must calculate the final color of the resulting pixel. The most common method is Alpha Blending.

Linear Interpolation (Lerp)

The simplest way to blend two colors (C1C_1 and C2C_2) based on an alpha value (α\alpha) of the top color (C2C_2):

Cfinal=C1(1α)+C2αC_{final} = C_1 \cdot (1 - \alpha) + C_2 \cdot \alpha

This is applied separately to each RGB channel.

Porter-Duff Compositing

This is a more comprehensive framework for alpha compositing. The "Source Over" operation is the most common (where one image is placed over another).

  1. Source Over: The classic "on top" operation.
  2. Destination Over: Places the new image behind the existing one.
  3. Source In / Out: Only shows parts of the source that are inside/outside the destination's opaque areas.

Gamma Correction

Humans perceive light non-linearly. Most displays follow this non-linear response. Gamma correction is the process of adjusting the brightness of an image to compensate for the non-linear way that cameras and displays handle light.

  • Linear Workflow: Modern graphics engines perform calculations in a linear color space (where 0.5+0.5=1.00.5 + 0.5 = 1.0 mathematically and visually) and then convert to gamma-corrected space for display.

Summary

Choosing the right color system is vital for specific tasks: RGB for displays, CMYK for print, and HSV for artistic selection. Mastering alpha blending and compositing is the key to creating complex, layered visual scenes in computer graphics.