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) {