|
@@ -28,14 +28,14 @@ |
|
|
#include "pipi.h" |
|
|
#include "pipi.h" |
|
|
#include "pipi_internals.h" |
|
|
#include "pipi_internals.h" |
|
|
|
|
|
|
|
|
#define GAMMA 1.0 |
|
|
|
|
|
|
|
|
|
|
|
static void init_tables(void); |
|
|
static void init_tables(void); |
|
|
|
|
|
|
|
|
|
|
|
static double global_gamma = 2.2; |
|
|
|
|
|
static int done = 0; |
|
|
|
|
|
|
|
|
static float u8tof32_table[256]; |
|
|
static float u8tof32_table[256]; |
|
|
static inline float u8tof32(uint8_t p) { return u8tof32_table[(int)p]; } |
|
|
static inline float u8tof32(uint8_t p) { return u8tof32_table[(int)p]; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return a direct pointer to an image's pixels. */ |
|
|
/* Return a direct pointer to an image's pixels. */ |
|
|
pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) |
|
|
pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) |
|
|
{ |
|
|
{ |
|
@@ -152,7 +152,7 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) |
|
|
|
|
|
|
|
|
if(p < 0.) d = 0.; |
|
|
if(p < 0.) d = 0.; |
|
|
else if(p > 1.) d = 255; |
|
|
else if(p > 1.) d = 255; |
|
|
else d = (int)(255.999 * pow(p, 1. / GAMMA)); |
|
|
|
|
|
|
|
|
else d = (int)(255.999 * pow(p, 1. / global_gamma)); |
|
|
|
|
|
|
|
|
dest[4 * (y * img->w + x) + i] = d; |
|
|
dest[4 * (y * img->w + x) + i] = d; |
|
|
|
|
|
|
|
@@ -188,7 +188,7 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) |
|
|
|
|
|
|
|
|
if(p < 0.) d = 0.; |
|
|
if(p < 0.) d = 0.; |
|
|
else if(p > 1.) d = 255; |
|
|
else if(p > 1.) d = 255; |
|
|
else d = (int)(255.999 * pow(p, 1. / GAMMA)); |
|
|
|
|
|
|
|
|
else d = (int)(255.999 * pow(p, 1. / global_gamma)); |
|
|
|
|
|
|
|
|
dest[3 * (y * img->w + x) + i] = d; |
|
|
dest[3 * (y * img->w + x) + i] = d; |
|
|
|
|
|
|
|
@@ -251,17 +251,25 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) |
|
|
return &img->p[type]; |
|
|
return &img->p[type]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void pipi_set_gamma(double g) |
|
|
|
|
|
{ |
|
|
|
|
|
if(g > 0.) |
|
|
|
|
|
{ |
|
|
|
|
|
global_gamma = g; |
|
|
|
|
|
done = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static void init_tables(void) |
|
|
static void init_tables(void) |
|
|
{ |
|
|
{ |
|
|
static int done = 0; |
|
|
|
|
|
int i; |
|
|
int i; |
|
|
|
|
|
|
|
|
if(done) |
|
|
if(done) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
for(i = 0; i < 256; i++) |
|
|
for(i = 0; i < 256; i++) |
|
|
u8tof32_table[i] = pow((double)i / 255., GAMMA); |
|
|
|
|
|
|
|
|
u8tof32_table[i] = pow((double)i / 255., global_gamma); |
|
|
|
|
|
|
|
|
done = 1; |
|
|
done = 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|