Browse Source

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

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2846 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 years ago
parent
commit
59e4d8ccd6
4 changed files with 35 additions and 7 deletions
  1. +11
    -0
      pipi/context.c
  2. +1
    -0
      pipi/pipi.h
  3. +15
    -7
      pipi/pixels.c
  4. +8
    -0
      src/pipi.c

+ 11
- 0
pipi/context.c View File

@@ -71,6 +71,17 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...)
pipi_save(ctx->images[ctx->nimages], file);
pipi_free(ctx->images[ctx->nimages]);
}
else if(!strcmp(cmd, "gamma"))
{
char const *val;
va_list ap;

va_start(ap, cmd);
val = va_arg(ap, char const *);
va_end(ap);

pipi_set_gamma(atof(val));
}
else if(!strcmp(cmd, "dither"))
{
pipi_image_t *src, *dst;


+ 1
- 0
pipi/pipi.h View File

@@ -118,6 +118,7 @@ extern pipi_image_t *pipi_copy(pipi_image_t *);
extern void pipi_free(pipi_image_t *);
extern int pipi_save(pipi_image_t *, const char *);

extern void pipi_set_gamma(double);
extern pipi_pixels_t *pipi_getpixels(pipi_image_t *, pipi_format_t);
extern int pipi_get_image_width(pipi_image_t *img);
extern int pipi_get_image_height(pipi_image_t *img);


+ 15
- 7
pipi/pixels.c View File

@@ -28,14 +28,14 @@
#include "pipi.h"
#include "pipi_internals.h"

#define GAMMA 1.0

static void init_tables(void);

static double global_gamma = 2.2;
static int done = 0;

static float u8tof32_table[256];
static inline float u8tof32(uint8_t p) { return u8tof32_table[(int)p]; }


/* Return a direct pointer to an image's pixels. */
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.;
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;

@@ -188,7 +188,7 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)

if(p < 0.) d = 0.;
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;

@@ -251,17 +251,25 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t 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 int done = 0;
int i;

if(done)
return;

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;
}


+ 8
- 0
src/pipi.c View File

@@ -33,6 +33,14 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
argv++;
}
else if(!strcmp(argv[0], "--gamma"))
{
if(argv[1] == NULL)
return EXIT_FAILURE;
if(pipi_command(ctx, "gamma", argv[1]) != 0)
return EXIT_FAILURE;
argv++;
}
else if(!strcmp(argv[0], "--scale"))
{
if(argv[1] == NULL)


Loading…
Cancel
Save