Developing the Perfect Curve
In the red-lit darkness of the darkroom, you learn that film doesn’t respond to light the way your eyes expect. Double the exposure time, and you don’t get double the brightness—film has its own curved relationship with light, a characteristic response that photographers have exploited for over a century.
Early computer graphics engineers faced the same puzzle when CRT monitors arrived. Human vision perceives light logarithmically, but digital systems think in linear steps. The solution? Gamma correction—a power-law transformation that bends linear pixel values into curves that match how we actually see.
gamma_correct <- function(linear_values, gamma = 2.2) {
linear_values^(1/gamma)
}
# Test with standard RGB values
linear <- c(0.0, 0.2, 0.4, 0.6, 0.8, 1.0)
corrected <- gamma_correct(linear)
print(round(corrected, 3))
# [1] 0.000 0.481 0.659 0.793 0.904 1.000
R’s vectorized approach mirrors how film development affects entire frames at once. That gamma value of 2.2? It’s the inverse of CRT phosphor response—a historical accident that became the standard.
program GammaCorrect;
var
i: integer;
linear, corrected: real;
gamma: real = 2.2;
begin
writeln('Linear -> Gamma Corrected');
for i := 0 to 10 do begin
linear := i / 10.0;
if linear = 0.0 then
corrected := 0.0
else
corrected := exp(ln(linear) / gamma);
writeln(linear:4:1, ' -> ', corrected:5:3);
end;
end.
Pascal’s explicit loop structure reflects the era when every calculation mattered—when graphics cards were luxuries and CPU cycles were precious. Notice the explicit zero check before the logarithm? That’s the digital equivalent of keeping pure black anchored while avoiding mathematical undefined behaviour.
Just as photographers choose different film stocks for their unique response curves, modern displays still rely on gamma correction to transform the linear mathematics of light into the perceptual reality of human vision. The darkroom’s chemical curves live on in every pixel.