Browse Source

* pixels.c: start supporting grayscale images.

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

+ 2
- 1
pipi/pipi.h View File

@@ -34,8 +34,9 @@ typedef enum
PIPI_PIXELS_RGBA32 = 0,
PIPI_PIXELS_BGR24 = 1,
PIPI_PIXELS_RGBA_F = 2,
PIPI_PIXELS_Y_F = 3,

PIPI_PIXELS_MAX = 3
PIPI_PIXELS_MAX = 4
}
pipi_format_t;



+ 39
- 0
pipi/pixels.c View File

@@ -62,6 +62,9 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
case PIPI_PIXELS_RGBA_F:
bytes = img->w * img->h * 4 * sizeof(float);
break;
case PIPI_PIXELS_Y_F:
bytes = img->w * img->h * sizeof(float);
break;
default:
return NULL;
}
@@ -176,6 +179,42 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
}
}
}
else if(img->last_modified == PIPI_PIXELS_Y_F
&& type == PIPI_PIXELS_RGBA_F)
{
float *src = (float *)img->p[PIPI_PIXELS_Y_F].pixels;
float *dest = (float *)img->p[PIPI_PIXELS_RGBA_F].pixels;

init_tables();

for(y = 0; y < img->h; y++)
for(x = 0; x < img->w; x++)
{
float p = src[y * img->w + x];
dest[4 * (y * img->w + x)] = p;
dest[4 * (y * img->w + x) + 1] = p;
dest[4 * (y * img->w + x) + 2] = p;
dest[4 * (y * img->w + x) + 3] = 1.0;
}
}
else if(img->last_modified == PIPI_PIXELS_RGBA_F
&& type == PIPI_PIXELS_Y_F)
{
float *src = (float *)img->p[PIPI_PIXELS_RGBA_F].pixels;
float *dest = (float *)img->p[PIPI_PIXELS_Y_F].pixels;

init_tables();

for(y = 0; y < img->h; y++)
for(x = 0; x < img->w; x++)
{
float p = 0.;
p += 0.299 * src[4 * (y * img->w + x)];
p += 0.587 * src[4 * (y * img->w + x) + 1];
p += 0.114 * src[4 * (y * img->w + x) + 2];
dest[y * img->w + x] = p;
}
}
else
{
memset(img->p[type].pixels, 0, bytes);


Loading…
Cancel
Save