# T7 Adding Gamma Correction

Gamma correction is needed to map the colour generated to the real colour of your display.

If we don't have Gamma correction, the images will look darker.

### Introduce Gamma Correction in color.h

Revise color.h as follows to do a non-linear mapping.

It is using sqrt to increase the intensity of your colour value.

For example, 0.64 will be converted to 0.8

```cpp
#ifndef COLOR_H
#define COLOR_H

#include "vec3.h"

using color = vec3;

// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline double linear_to_gamma(double linear_component)
{
    if (linear_component > 0)
        return std::sqrt(linear_component);

    return 0;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


void write_color(std::ostream& out, const color & pixel_color) {
    auto r = pixel_color.x();
    auto g = pixel_color.y();
    auto b = pixel_color.z();

    // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    // Apply a linear to gamma transform for gamma 2
    r = linear_to_gamma(r);
    g = linear_to_gamma(g);
    b = linear_to_gamma(b);
    // <<<<<<<<<<<<<<<<<<<<<<<<<<<<

    // ============================================
    static const interval intensity(0.000, 0.999);
    int rbyte = int(256 * intensity.clamp(r));
    int gbyte = int(256 * intensity.clamp(g));
    int bbyte = int(256 * intensity.clamp(b));
    // ============================================

    // Write out the pixel color components.
    out << rbyte << ' ' << gbyte << ' ' << bbyte << '\n';
}

#endif
```
