
// glcolor.cpp - send sRGB-encoded color values to OpenGL for sRGB rendering

#include <GL/glew.h>

#include "glcolor.hpp"

#include "color_space.hpp"
#include "glcolor.hpp"
#include "sRGB_math.h"

const float yellow[3] = { 1,1,0 };
const float red[3] = { 1,0,0 };
const float half_red[3] = { 0.5,0,0 };
const float quarter_red[3] = { 0.25,0,0 };
const float orange[3] = { 0.6071f,0.3929f,0 };
const float dark_red[3] = { 0.4f,0,0 };
const float blue[3] = { 0,0,1 };
const float green[3] = { 0,1,0 };
const float dark_green[3] = { 0,0.4f,0 };
const float white[3] = { 1,1,1 };
const float black[3] = { 0,0,0 };
const float purple[3] = { 0.5f,0,0.5f };
const float cyan[3] = { 0,1,1 };
const float windows_blue[3] = { 100 / 255.0f, 100 / 255.0f, 1 };
const float whitishBlue[3] = { 0.7f,0.7f,1.0f };
const float dark_yellow[3] = { 0.3f,0.3f,0 };
const float gray[3] = { 0.5f,0.5f,0.5f };
const float magenta[3] = { 1,0,1 };

const float dim_green[] = { 0,0.1f,0 };
const float lime_green[] = { 169 / 255.0f, 1.0f, 47 / 255.0f };
const float whitish_blue[3] = { 0.7f,0.7f,1.0f };
const float whitish_yellow[3] = { 1,1,0.7f };
const float whitish_red[3] = { 1,0.7f,0.7f };
const float whitish_purple[3] = { 1,0.6f,1 };
const float whitish_green[3] = { 0.7f,1,0.7f };
const float orange_red[3] = { 1, 69 / 255.0f, 0 };
const float light_green[] = { 0.2f,0.6f,0.3f };
const float light_red[] = { 0.6f,0.2f,0.3f };
const float light_cyan[] = { 0,0.2f,0.2f };

void sRGB_glColor3f(float r, float g, float b)
{
  if (color_space == UNCORRECTED) {
    r = convertLinearColorComponentToSRGBf(r);
    g = convertLinearColorComponentToSRGBf(g);
    b = convertLinearColorComponentToSRGBf(b);
  }
  glColor3f(r, g, b);
}

void sRGB_glColor4f(float r, float g, float b, float a)
{
  if (color_space == UNCORRECTED) {
    r = convertLinearColorComponentToSRGBf(r);
    g = convertLinearColorComponentToSRGBf(g);
    b = convertLinearColorComponentToSRGBf(b);
  }
  glColor4f(r, g, b, a);
}

void sRGB_glColor3fv(const float rgb[3])
{
  float r = rgb[0];
  float g = rgb[1];
  float b = rgb[2];
  if (color_space == UNCORRECTED) {
    r = convertLinearColorComponentToSRGBf(r);
    g = convertLinearColorComponentToSRGBf(g);
    b = convertLinearColorComponentToSRGBf(b);
  }
  glColor3f(r, g, b);
}
