
// sRGB_vector.cpp - sRGB color space conversion vector utilities

// Depends on cg4cpp, Cg for C++ templates.
#include <Cg/vector/rgba.hpp>
#include <Cg/vector.hpp>

#include "sRGB_math.h"
#include "sRGB_vector.hpp"

using namespace Cg;

float3 srgb2linear(const float srgb[3])
{
    float3 linear;

    linear.r = convertSRGBColorComponentToLinearf(srgb[0]);
    linear.g = convertSRGBColorComponentToLinearf(srgb[1]);
    linear.b = convertSRGBColorComponentToLinearf(srgb[2]);
    return linear;
}

float3 linear2srgb(const float linear[3])
{
    float3 srgb;

    srgb.r = convertLinearColorComponentToSRGBf(linear[0]);
    srgb.g = convertLinearColorComponentToSRGBf(linear[1]);
    srgb.b = convertLinearColorComponentToSRGBf(linear[2]);
    return srgb;
}

float4 srgba2linear(const float srgb[4])
{
    float4 linear;


    linear.r = convertSRGBColorComponentToLinearf(srgb[0]);
    linear.g = convertSRGBColorComponentToLinearf(srgb[1]);
    linear.b = convertSRGBColorComponentToLinearf(srgb[2]);
    linear[3] = srgb[3];
    return linear;
}

float4 linear2srgba(const float linear[4])
{
    float4 srgb;

    srgb.r = convertLinearColorComponentToSRGBf(linear[0]);
    srgb.g = convertLinearColorComponentToSRGBf(linear[1]);
    srgb.b = convertLinearColorComponentToSRGBf(linear[2]);
    srgb[3] = linear[3];
    return srgb;
}

float3 srgb2linear(float3 srgb)
{
    float3 linear;

    linear.r = convertSRGBColorComponentToLinearf(srgb.r);
    linear.g = convertSRGBColorComponentToLinearf(srgb.g);
    linear.b = convertSRGBColorComponentToLinearf(srgb.b);
    return linear;
}

float3 linear2srgb(float3 linear)
{
    float3 srgb;

    srgb.r = convertLinearColorComponentToSRGBf(linear.r);
    srgb.g = convertLinearColorComponentToSRGBf(linear.g);
    srgb.b = convertLinearColorComponentToSRGBf(linear.b);
    return srgb;
}

float4 srgba2linear(float4 srgb)
{
    float4 linear;

    
    linear.r = convertSRGBColorComponentToLinearf(srgb.r);
    linear.g = convertSRGBColorComponentToLinearf(srgb.g);
    linear.b = convertSRGBColorComponentToLinearf(srgb.b);
#if 0 // VS 2008 compiler bug??
    linear.a = srgb.a;
#else
    linear[3] = srgb[3];
#endif
    return linear;
}

float4 linear2srgba(float4 linear)
{
    float4 srgb;

    srgb.r = convertLinearColorComponentToSRGBf(linear.r);
    srgb.g = convertLinearColorComponentToSRGBf(linear.g);
    srgb.b = convertLinearColorComponentToSRGBf(linear.b); 
#if 0 // VS 2008 compiler bug??
    srgb.a = linear.a;
#else
    srgb[3] = linear[3];
#endif
    return srgb;
}

