Ignore:
Timestamp:
09/28/08 19:01:56 (5 years ago)
Author:
sam
Message:

Add a --gamma command to modify the global gamma value. This is a nasty
hack that will hopefully disappear in the future. The default gamma is
now 2.2 again (sRGB approximation).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/pixels.c

    r2844 r2846  
    2929#include "pipi_internals.h" 
    3030 
    31 #define GAMMA 1.0 
    32  
    3331static void init_tables(void); 
     32 
     33static double global_gamma = 2.2; 
     34static int done = 0; 
    3435 
    3536static float u8tof32_table[256]; 
    3637static inline float u8tof32(uint8_t p) { return u8tof32_table[(int)p]; } 
    37  
    3838 
    3939/* Return a direct pointer to an image's pixels. */ 
     
    153153                    if(p < 0.) d = 0.; 
    154154                    else if(p > 1.) d = 255; 
    155                     else d = (int)(255.999 * pow(p, 1. / GAMMA)); 
     155                    else d = (int)(255.999 * pow(p, 1. / global_gamma)); 
    156156 
    157157                    dest[4 * (y * img->w + x) + i] = d; 
     
    189189                    if(p < 0.) d = 0.; 
    190190                    else if(p > 1.) d = 255; 
    191                     else d = (int)(255.999 * pow(p, 1. / GAMMA)); 
     191                    else d = (int)(255.999 * pow(p, 1. / global_gamma)); 
    192192 
    193193                    dest[3 * (y * img->w + x) + i] = d; 
     
    252252} 
    253253 
     254void pipi_set_gamma(double g) 
     255{ 
     256    if(g > 0.) 
     257    { 
     258        global_gamma = g; 
     259        done = 0; 
     260    } 
     261} 
    254262 
    255263static void init_tables(void) 
    256264{ 
    257     static int done = 0; 
    258265    int i; 
    259266 
     
    262269 
    263270    for(i = 0; i < 256; i++) 
    264         u8tof32_table[i] = pow((double)i / 255., GAMMA); 
     271        u8tof32_table[i] = pow((double)i / 255., global_gamma); 
    265272 
    266273    done = 1; 
    267274} 
     275 
Note: See TracChangeset for help on using the changeset viewer.