Selaa lähdekoodia

* pixels.c: add Floyd-Steinberg dithering to the float32 -> rgba32

conversion.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2616 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 vuotta sitten
vanhempi
commit
e15f20a316
1 muutettua tiedostoa jossa 23 lisäystä ja 4 poistoa
  1. +23
    -4
      pipi/pixels.c

+ 23
- 4
pipi/pixels.c Näytä tiedosto

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

#define GAMMA 2.2

static void init_tables(void);

static float u8tof32_table[256];
@@ -85,13 +87,30 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
float *src = (float *)img->p[PIPI_PIXELS_RGBA_F].pixels;
uint8_t *dest = (uint8_t *)img->p[type].pixels;

init_tables();

for(y = 0; y < img->h; y++)
for(x = 0; x < img->w; x++)
for(i = 0; i < 4; i++)
{
double p = src[4 * (y * img->w + x) + i];
dest[4 * (y * img->w + x) + i]
= (int)(255.999 * pow(p, 1. / 2.2));
double p, e;
uint8_t d;

p = src[4 * (y * img->w + x) + i];
d = (int)(255.999 * pow(p, 1. / GAMMA));
dest[4 * (y * img->w + x) + i] = d;

e = p - u8tof32(d);
if(x < img->w - 1)
src[4 * (y * img->w + x + 1) + i] += e * .4375;
if(y < img->h - 1)
{
if(x < img->w - 1)
src[4 * ((y + 1) * img->w + x - 1) + i] += e * .1875;
src[4 * ((y + 1) * img->w + x) + i] += e * .3125;
if(x < img->w - 1)
src[4 * ((y + 1) * img->w + x + 1) + i] += e * .0625;
}
}
}
else
@@ -114,7 +133,7 @@ static void init_tables(void)
return;

for(i = 0; i < 256; i++)
u8tof32_table[i] = pow((double)i / 255., 2.2);
u8tof32_table[i] = pow((double)i / 255., GAMMA);

done = 1;
}


Ladataan…
Peruuta
Tallenna