Changeset 2846


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).

Location:
libpipi/trunk
Files:
4 edited

Legend:

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

    r2844 r2846  
    7171        pipi_save(ctx->images[ctx->nimages], file); 
    7272        pipi_free(ctx->images[ctx->nimages]); 
     73    } 
     74    else if(!strcmp(cmd, "gamma")) 
     75    { 
     76        char const *val; 
     77        va_list ap; 
     78 
     79        va_start(ap, cmd); 
     80        val = va_arg(ap, char const *); 
     81        va_end(ap); 
     82 
     83        pipi_set_gamma(atof(val)); 
    7384    } 
    7485    else if(!strcmp(cmd, "dither")) 
  • libpipi/trunk/pipi/pipi.h

    r2844 r2846  
    119119extern int pipi_save(pipi_image_t *, const char *); 
    120120 
     121extern void pipi_set_gamma(double); 
    121122extern pipi_pixels_t *pipi_getpixels(pipi_image_t *, pipi_format_t); 
    122123extern int pipi_get_image_width(pipi_image_t *img); 
  • 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 
  • libpipi/trunk/src/pipi.c

    r2790 r2846  
    3434            argv++; 
    3535        } 
     36        else if(!strcmp(argv[0], "--gamma")) 
     37        { 
     38            if(argv[1] == NULL) 
     39                return EXIT_FAILURE; 
     40            if(pipi_command(ctx, "gamma", argv[1]) != 0) 
     41                return EXIT_FAILURE; 
     42            argv++; 
     43        } 
    3644        else if(!strcmp(argv[0], "--scale")) 
    3745        { 
Note: See TracChangeset for help on using the changeset viewer.