From 99d8af784e5a1476ee98bdbd09f03c38adbba0e2 Mon Sep 17 00:00:00 2001 From: sam Date: Sun, 3 Aug 2008 11:47:11 +0000 Subject: [PATCH] * pixels.c: support more conversion combinations. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2655 92316355-f0b4-4df1-b90c-862c8a59935f --- examples/dither.c | 2 -- examples/edd.c | 1 - pipi/pixels.c | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/dither.c b/examples/dither.c index 463cf70..246df80 100644 --- a/examples/dither.c +++ b/examples/dither.c @@ -27,7 +27,6 @@ int main(int argc, char *argv[]) dstname = argv[3]; img = pipi_load(srcname); - pipi_getpixels(img, PIPI_PIXELS_RGBA_F); switch(atoi(argv[2])) { @@ -42,7 +41,6 @@ int main(int argc, char *argv[]) pipi_free(img); - pipi_getpixels(newimg, PIPI_PIXELS_RGBA_F); pipi_save(newimg, dstname); pipi_free(newimg); diff --git a/examples/edd.c b/examples/edd.c index 2c9c12c..baa576a 100644 --- a/examples/edd.c +++ b/examples/edd.c @@ -50,7 +50,6 @@ int main(int argc, char *argv[]) /* Load image, convert it to grayscale, dither it with Floyd-Steinberg */ img = pipi_load(argv[1]); - pipi_getpixels(img, PIPI_PIXELS_RGBA_F); pipi_getpixels(img, PIPI_PIXELS_Y_F); gauss = pipi_gaussian_blur(img, sigma); dither = pipi_floydsteinberg(img); diff --git a/pipi/pixels.c b/pipi/pixels.c index 45bb3a4..702ead8 100644 --- a/pipi/pixels.c +++ b/pipi/pixels.c @@ -48,6 +48,20 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) if(img->last_modified == type) return &img->p[type]; + /* Preliminary conversions */ + if(img->last_modified == PIPI_PIXELS_RGBA32 + && type == PIPI_PIXELS_Y_F) + pipi_getpixels(img, PIPI_PIXELS_RGBA_F); + else if(img->last_modified == PIPI_PIXELS_BGR24 + && type == PIPI_PIXELS_Y_F) + pipi_getpixels(img, PIPI_PIXELS_RGBA_F); + else if(img->last_modified == PIPI_PIXELS_Y_F + && type == PIPI_PIXELS_RGBA32) + pipi_getpixels(img, PIPI_PIXELS_RGBA_F); + else if(img->last_modified == PIPI_PIXELS_Y_F + && type == PIPI_PIXELS_BGR24) + pipi_getpixels(img, PIPI_PIXELS_RGBA_F); + /* Allocate pixels if necessary */ if(!img->p[type].pixels) {