Browse Source

Allow to use all available image loaders instead of just the first one.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2837 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 years ago
parent
commit
6fc2b78f37
6 changed files with 86 additions and 53 deletions
  1. +31
    -21
      pipi/codec.c
  2. +18
    -7
      pipi/codec/imlib.c
  3. +19
    -8
      pipi/codec/opencv.c
  4. +13
    -7
      pipi/codec/sdl.c
  5. +1
    -1
      pipi/pipi.h
  6. +4
    -9
      pipi/pipi_internals.h

+ 31
- 21
pipi/codec.c View File

@@ -28,21 +28,28 @@

pipi_image_t *pipi_load(char const *name)
{
pipi_image_t *ret = NULL;

if(!strncmp(name, "random:", 7) ||
!strncmp(name, "ediff:", 6) ||
!strncmp(name, "halftone:", 6) ||
!strncmp(name, "bayer:", 6))
return pipi_load_stock(name);
ret = pipi_load_stock(name);

#if USE_IMLIB2
return pipi_load_imlib2(name);
#elif USE_OPENCV
return pipi_load_opencv(name);
#elif USE_SDL
return pipi_load_sdl(name);
#else
# error "No imaging library"
if(!ret)
ret = pipi_load_imlib2(name);
#endif
#if USE_OPENCV
if(!ret)
ret = pipi_load_opencv(name);
#endif
#if USE_SDL
if(!ret)
ret = pipi_load_sdl(name);
#endif

return ret;
}

void pipi_free(pipi_image_t *img)
@@ -54,25 +61,28 @@ void pipi_free(pipi_image_t *img)
free(img->p[i].pixels);

if(img->codec_priv)
#if USE_IMLIB2
pipi_free_imlib2(img);
#elif USE_OPENCV
pipi_free_opencv(img);
#elif USE_SDL
pipi_free_sdl(img);
#endif
img->codec_free(img);

free(img);
}

void pipi_save(pipi_image_t *img, const char *name)
int pipi_save(pipi_image_t *img, const char *name)
{
int ret = -1;

#if USE_IMLIB2
return pipi_save_imlib2(img, name);
#elif USE_OPENCV
return pipi_save_opencv(img, name);
#elif USE_SDL
return pipi_save_sdl(img, name);
if(ret < 0)
ret = pipi_save_imlib2(img, name);
#endif
#if USE_OPENCV
if(ret < 0)
ret = pipi_save_opencv(img, name);
#endif
#if USE_SDL
if(ret < 0)
ret = pipi_save_sdl(img, name);
#endif

return ret;
}


+ 18
- 7
pipi/codec/imlib.c View File

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

static int pipi_free_imlib2(pipi_image_t *);

pipi_image_t *pipi_load_imlib2(const char *name)
{
pipi_image_t *img;
@@ -49,6 +51,7 @@ pipi_image_t *pipi_load_imlib2(const char *name)

img->codec_priv = (void *)priv;
img->codec_format = PIPI_PIXELS_RGBA_C;
img->codec_free = pipi_free_imlib2;

img->wrap = 0;
img->u8 = 1;
@@ -56,13 +59,7 @@ pipi_image_t *pipi_load_imlib2(const char *name)
return img;
}

void pipi_free_imlib2(pipi_image_t *img)
{
imlib_context_set_image(img->codec_priv);
imlib_free_image();
}

void pipi_save_imlib2(pipi_image_t *img, const char *name)
int pipi_save_imlib2(pipi_image_t *img, const char *name)
{
if(!img->codec_priv)
{
@@ -97,5 +94,19 @@ void pipi_save_imlib2(pipi_image_t *img, const char *name)
pipi_getpixels(img, img->codec_format);
imlib_context_set_image(img->codec_priv);
imlib_save_image(name);

return 0;
}

/*
* XXX: The following functions are local.
*/

static int pipi_free_imlib2(pipi_image_t *img)
{
imlib_context_set_image(img->codec_priv);
imlib_free_image();

return 0;
}


+ 19
- 8
pipi/codec/opencv.c View File

@@ -31,6 +31,8 @@

/* FIXME: this whole file is broken until we support BGR24 images */

static int pipi_free_opencv(pipi_image_t *);

pipi_image_t *pipi_load_opencv(const char *name)
{
pipi_image_t *img;
@@ -52,6 +54,7 @@ pipi_image_t *pipi_load_opencv(const char *name)

img->codec_priv = (void *)priv;
img->codec_format = PIPI_PIXELS_BGR_C;
img->codec_free = pipi_free_opencv;

img->wrap = 0;
img->u8 = 1;
@@ -59,14 +62,7 @@ pipi_image_t *pipi_load_opencv(const char *name)
return img;
}

void pipi_free_opencv(pipi_image_t *img)
{
IplImage *iplimg;
iplimg = (IplImage *)img->codec_priv;
cvReleaseImage(&iplimg);
}

void pipi_save_opencv(pipi_image_t *img, const char *name)
int pipi_save_opencv(pipi_image_t *img, const char *name)
{
if(!img->codec_priv)
{
@@ -97,5 +93,20 @@ void pipi_save_opencv(pipi_image_t *img, const char *name)

pipi_getpixels(img, img->codec_format);
cvSaveImage(name, img->codec_priv);

return 0;
}

/*
* XXX: The following functions are local.
*/

static int pipi_free_opencv(pipi_image_t *img)
{
IplImage *iplimg;
iplimg = (IplImage *)img->codec_priv;
cvReleaseImage(&iplimg);

return 0;
}


+ 13
- 7
pipi/codec/sdl.c View File

@@ -28,6 +28,7 @@
#include "pipi.h"
#include "pipi_internals.h"

static int pipi_free_sdl(pipi_image_t *);
static SDL_Surface *create_32bpp_surface(int w, int h);

pipi_image_t *pipi_load_sdl(const char *name)
@@ -58,6 +59,7 @@ pipi_image_t *pipi_load_sdl(const char *name)

img->codec_priv = (void *)priv;
img->codec_format = PIPI_PIXELS_RGBA_C;
img->codec_free = pipi_free_sdl;

img->wrap = 0;
img->u8 = 1;
@@ -65,12 +67,7 @@ pipi_image_t *pipi_load_sdl(const char *name)
return img;
}

void pipi_free_sdl(pipi_image_t *img)
{
SDL_FreeSurface(img->codec_priv);
}

void pipi_save_sdl(pipi_image_t *img, const char *name)
int pipi_save_sdl(pipi_image_t *img, const char *name)
{
if(!img->codec_priv)
{
@@ -100,12 +97,21 @@ void pipi_save_sdl(pipi_image_t *img, const char *name)

pipi_getpixels(img, img->codec_format);
SDL_SaveBMP(img->codec_priv, name);

return 0;
}

/*
* The following functions are local.
* XXX: The following functions are local.
*/

static int pipi_free_sdl(pipi_image_t *img)
{
SDL_FreeSurface(img->codec_priv);

return 0;
}

static SDL_Surface *create_32bpp_surface(int w, int h)
{
Uint32 rmask, gmask, bmask, amask;


+ 1
- 1
pipi/pipi.h View File

@@ -116,7 +116,7 @@ extern pipi_image_t *pipi_load_stock(char const *);
extern pipi_image_t *pipi_new(int, int);
extern pipi_image_t *pipi_copy(pipi_image_t *);
extern void pipi_free(pipi_image_t *);
extern void pipi_save(pipi_image_t *, const char *);
extern int pipi_save(pipi_image_t *, const char *);

extern pipi_pixels_t *pipi_getpixels(pipi_image_t *, pipi_format_t);
extern int pipi_get_image_width(pipi_image_t *img);


+ 4
- 9
pipi/pipi_internals.h View File

@@ -56,6 +56,7 @@ struct pipi_image
/* Private data used by the codec */
pipi_format_t codec_format;
void *codec_priv;
int (*codec_free)(pipi_image_t *);
};

struct pipi_context
@@ -66,23 +67,17 @@ struct pipi_context

#ifdef USE_IMLIB2
pipi_image_t *pipi_load_imlib2(const char *name);
pipi_image_t *pipi_new_imlib2(int width, int height);
void pipi_free_imlib2(pipi_image_t *img);
void pipi_save_imlib2(pipi_image_t *img, const char *name);
int pipi_save_imlib2(pipi_image_t *img, const char *name);
#endif

#ifdef USE_OPENCV
pipi_image_t *pipi_load_opencv(const char *name);
pipi_image_t *pipi_new_opencv(int width, int height);
void pipi_free_opencv(pipi_image_t *img);
void pipi_save_opencv(pipi_image_t *img, const char *name);
int pipi_save_opencv(pipi_image_t *img, const char *name);
#endif

#ifdef USE_SDL
pipi_image_t *pipi_load_sdl(const char *name);
pipi_image_t *pipi_new_sdl(int width, int height);
void pipi_free_sdl(pipi_image_t *img);
void pipi_save_sdl(pipi_image_t *img, const char *name);
int pipi_save_sdl(pipi_image_t *img, const char *name);
#endif

#endif /* __PIPI_INTERNALS_H__ */


Loading…
Cancel
Save