Browse Source

* pixels.c: add support for 24-bpp BGR format.

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

+ 3
- 2
pipi/pipi.h View File

@@ -32,9 +32,10 @@ typedef enum
PIPI_PIXELS_UNINITIALISED = -1,

PIPI_PIXELS_RGBA32 = 0,
PIPI_PIXELS_RGBA_F = 1,
PIPI_PIXELS_BGR24 = 1,
PIPI_PIXELS_RGBA_F = 2,

PIPI_PIXELS_MAX = 2
PIPI_PIXELS_MAX = 3
}
pipi_format_t;



+ 59
- 0
pipi/pixels.c View File

@@ -56,6 +56,9 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
case PIPI_PIXELS_RGBA32:
bytes = img->w * img->h * 4 * sizeof(uint8_t);
break;
case PIPI_PIXELS_BGR24:
bytes = img->w * img->h * 3 * sizeof(uint8_t);
break;
case PIPI_PIXELS_RGBA_F:
bytes = img->w * img->h * 4 * sizeof(float);
break;
@@ -81,6 +84,26 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
dest[4 * (y * img->w + x) + i]
= u8tof32(src[4 * (y * img->w + x) + i]);
}
else if(img->last_modified == PIPI_PIXELS_BGR24
&& type == PIPI_PIXELS_RGBA_F)
{
uint8_t *src = (uint8_t *)img->p[PIPI_PIXELS_BGR24].pixels;
float *dest = (float *)img->p[type].pixels;

init_tables();

for(y = 0; y < img->h; y++)
for(x = 0; x < img->w; x++)
{
dest[4 * (y * img->w + x)]
= u8tof32(src[3 * (y * img->w + x) + 2]);
dest[4 * (y * img->w + x) + 1]
= u8tof32(src[3 * (y * img->w + x) + 1]);
dest[4 * (y * img->w + x) + 2]
= u8tof32(src[3 * (y * img->w + x)]);
dest[4 * (y * img->w + x) + 3] = 1.0;
}
}
else if(img->last_modified == PIPI_PIXELS_RGBA_F
&& type == PIPI_PIXELS_RGBA32)
{
@@ -117,6 +140,42 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
}
}
}
else if(img->last_modified == PIPI_PIXELS_RGBA_F
&& type == PIPI_PIXELS_BGR24)
{
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 < 3; i++)
{
double p, e;
uint8_t d;

p = src[4 * (y * img->w + x) + i];

if(p < 0.) d = 0.;
else if(p > 1.) d = 255;
else d = (int)(255.999 * pow(p, 1. / GAMMA));

dest[3 * (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
{
memset(img->p[type].pixels, 0, bytes);


Loading…
Cancel
Save