Quellcode durchsuchen

* pixels.c: speed up the RGBA32 -> float32 conversion, using a simple LUT.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2609 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam vor 16 Jahren
Ursprung
Commit
0105b6f3b6
1 geänderte Dateien mit 27 neuen und 4 gelöschten Zeilen
  1. +27
    -4
      pipi/pixels.c

+ 27
- 4
pipi/pixels.c Datei anzeigen

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

#define C2I(p) (pow(((double)p)/255., 2.2))
#define I2C(p) ((int)255.999*pow(((double)p), 1./2.2))
static void init_tables(void);

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)
@@ -68,11 +71,13 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
uint8_t *src = (uint8_t *)img->p[PIPI_PIXELS_RGBA32].pixels;
float *dest = (float *)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++)
dest[4 * (y * img->w + x) + i]
= C2I(src[4 * (y * img->w + x) + i]);
= u8tof32(src[4 * (y * img->w + x) + i]);
}
else if(img->last_modified == PIPI_PIXELS_RGBA_F
&& type == PIPI_PIXELS_RGBA32)
@@ -83,8 +88,11 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
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]
= I2C(src[4 * (y * img->w + x) + i]);
= (int)(255.999 * pow(p, 1. / 2.2));
}
}
else
{
@@ -96,3 +104,18 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
return &img->p[type];
}


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., 2.2);

done = 1;
}


Laden…
Abbrechen
Speichern