GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


update texture gamma by [pr]jazzd
void ChangeGamma(byte *pImage, int size, float factor)
{
    for(int i = 0; i < size / 3; i++, pImage += 3) 
    {
        float scale = 1.0f, temp = 0.0f;
        float r = 0, g = 0, b = 0;

        
        r = (float)pImage[0];
        g = (float)pImage[1];
        b = (float)pImage[2];

        
        r = r * factor / 255.0f;
        g = g * factor / 255.0f;
        b = b * factor / 255.0f;
        
        
        if(r > 1.0f && (temp = (1.0f/r)) < scale) scale=temp;
        if(g > 1.0f && (temp = (1.0f/g)) < scale) scale=temp;
        if(b > 1.0f && (temp = (1.0f/b)) < scale) scale=temp;

        
        scale*=255.0f;        
        r*=scale;    g*=scale;    b*=scale;

        pImage[0] = (byte)r;
        pImage[1] = (byte)g;
        pImage[2] = (byte)b;
    }
}