Changeset 2837 for libpipi


Ignore:
Timestamp:
Sep 28, 2008, 7:07:57 AM (12 years ago)
Author:
Sam Hocevar
Message:

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

Location:
libpipi/trunk/pipi
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/codec.c

    r2767 r2837  
    2929pipi_image_t *pipi_load(char const *name)
    3030{
     31    pipi_image_t *ret = NULL;
     32
    3133    if(!strncmp(name, "random:", 7) ||
    3234       !strncmp(name, "ediff:", 6) ||
    3335       !strncmp(name, "halftone:", 6) ||
    3436       !strncmp(name, "bayer:", 6))
    35         return pipi_load_stock(name);
     37        ret = pipi_load_stock(name);
    3638
    3739#if USE_IMLIB2
    38     return pipi_load_imlib2(name);
    39 #elif USE_OPENCV
    40     return pipi_load_opencv(name);
    41 #elif USE_SDL
    42     return pipi_load_sdl(name);
    43 #else
    44 #   error "No imaging library"
     40    if(!ret)
     41        ret = pipi_load_imlib2(name);
    4542#endif
     43#if USE_OPENCV
     44    if(!ret)
     45        ret = pipi_load_opencv(name);
     46#endif
     47#if USE_SDL
     48    if(!ret)
     49        ret = pipi_load_sdl(name);
     50#endif
     51
     52    return ret;
    4653}
    4754
     
    5562
    5663    if(img->codec_priv)
    57 #if USE_IMLIB2
    58         pipi_free_imlib2(img);
    59 #elif USE_OPENCV
    60         pipi_free_opencv(img);
    61 #elif USE_SDL
    62         pipi_free_sdl(img);
    63 #endif
     64        img->codec_free(img);
    6465
    6566    free(img);
    6667}
    6768
    68 void pipi_save(pipi_image_t *img, const char *name)
     69int pipi_save(pipi_image_t *img, const char *name)
    6970{
     71    int ret = -1;
     72
    7073#if USE_IMLIB2
    71     return pipi_save_imlib2(img, name);
    72 #elif USE_OPENCV
    73     return pipi_save_opencv(img, name);
    74 #elif USE_SDL
    75     return pipi_save_sdl(img, name);
     74    if(ret < 0)
     75        ret = pipi_save_imlib2(img, name);
    7676#endif
     77#if USE_OPENCV
     78    if(ret < 0)
     79        ret = pipi_save_opencv(img, name);
     80#endif
     81#if USE_SDL
     82    if(ret < 0)
     83        ret = pipi_save_sdl(img, name);
     84#endif
     85
     86    return ret;
    7787}
    7888
  • libpipi/trunk/pipi/codec/imlib.c

    r2772 r2837  
    2929#include "pipi_internals.h"
    3030
     31static int pipi_free_imlib2(pipi_image_t *);
     32
    3133pipi_image_t *pipi_load_imlib2(const char *name)
    3234{
     
    5052    img->codec_priv = (void *)priv;
    5153    img->codec_format = PIPI_PIXELS_RGBA_C;
     54    img->codec_free = pipi_free_imlib2;
    5255
    5356    img->wrap = 0;
     
    5760}
    5861
    59 void pipi_free_imlib2(pipi_image_t *img)
    60 {
    61     imlib_context_set_image(img->codec_priv);
    62     imlib_free_image();
    63 }
    64 
    65 void pipi_save_imlib2(pipi_image_t *img, const char *name)
     62int pipi_save_imlib2(pipi_image_t *img, const char *name)
    6663{
    6764    if(!img->codec_priv)
     
    9895    imlib_context_set_image(img->codec_priv);
    9996    imlib_save_image(name);
     97
     98    return 0;
    10099}
    101100
     101/*
     102 * XXX: The following functions are local.
     103 */
     104
     105static int pipi_free_imlib2(pipi_image_t *img)
     106{
     107    imlib_context_set_image(img->codec_priv);
     108    imlib_free_image();
     109
     110    return 0;
     111}
     112
  • libpipi/trunk/pipi/codec/opencv.c

    r2814 r2837  
    3232/* FIXME: this whole file is broken until we support BGR24 images */
    3333
     34static int pipi_free_opencv(pipi_image_t *);
     35
    3436pipi_image_t *pipi_load_opencv(const char *name)
    3537{
     
    5355    img->codec_priv = (void *)priv;
    5456    img->codec_format = PIPI_PIXELS_BGR_C;
     57    img->codec_free = pipi_free_opencv;
    5558
    5659    img->wrap = 0;
     
    6063}
    6164
    62 void pipi_free_opencv(pipi_image_t *img)
    63 {
    64     IplImage *iplimg;
    65     iplimg = (IplImage *)img->codec_priv;
    66     cvReleaseImage(&iplimg);
    67 }
    68 
    69 void pipi_save_opencv(pipi_image_t *img, const char *name)
     65int pipi_save_opencv(pipi_image_t *img, const char *name)
    7066{
    7167    if(!img->codec_priv)
     
    9894    pipi_getpixels(img, img->codec_format);
    9995    cvSaveImage(name, img->codec_priv);
     96
     97    return 0;
    10098}
    10199
     100/*
     101 * XXX: The following functions are local.
     102 */
     103
     104static int pipi_free_opencv(pipi_image_t *img)
     105{
     106    IplImage *iplimg;
     107    iplimg = (IplImage *)img->codec_priv;
     108    cvReleaseImage(&iplimg);
     109
     110    return 0;
     111}
     112
  • libpipi/trunk/pipi/codec/sdl.c

    r2772 r2837  
    2929#include "pipi_internals.h"
    3030
     31static int pipi_free_sdl(pipi_image_t *);
    3132static SDL_Surface *create_32bpp_surface(int w, int h);
    3233
     
    5960    img->codec_priv = (void *)priv;
    6061    img->codec_format = PIPI_PIXELS_RGBA_C;
     62    img->codec_free = pipi_free_sdl;
    6163
    6264    img->wrap = 0;
     
    6668}
    6769
    68 void pipi_free_sdl(pipi_image_t *img)
    69 {
    70     SDL_FreeSurface(img->codec_priv);
    71 }
    72 
    73 void pipi_save_sdl(pipi_image_t *img, const char *name)
     70int pipi_save_sdl(pipi_image_t *img, const char *name)
    7471{
    7572    if(!img->codec_priv)
     
    10198    pipi_getpixels(img, img->codec_format);
    10299    SDL_SaveBMP(img->codec_priv, name);
     100
     101    return 0;
    103102}
    104103
    105104/*
    106  * The following functions are local.
     105 * XXX: The following functions are local.
    107106 */
     107
     108static int pipi_free_sdl(pipi_image_t *img)
     109{
     110    SDL_FreeSurface(img->codec_priv);
     111
     112    return 0;
     113}
    108114
    109115static SDL_Surface *create_32bpp_surface(int w, int h)
  • libpipi/trunk/pipi/pipi.h

    r2814 r2837  
    117117extern pipi_image_t *pipi_copy(pipi_image_t *);
    118118extern void pipi_free(pipi_image_t *);
    119 extern void pipi_save(pipi_image_t *, const char *);
     119extern int pipi_save(pipi_image_t *, const char *);
    120120
    121121extern pipi_pixels_t *pipi_getpixels(pipi_image_t *, pipi_format_t);
  • libpipi/trunk/pipi/pipi_internals.h

    r2809 r2837  
    5757    pipi_format_t codec_format;
    5858    void *codec_priv;
     59    int (*codec_free)(pipi_image_t *);
    5960};
    6061
     
    6768#ifdef USE_IMLIB2
    6869pipi_image_t *pipi_load_imlib2(const char *name);
    69 pipi_image_t *pipi_new_imlib2(int width, int height);
    70 void pipi_free_imlib2(pipi_image_t *img);
    71 void pipi_save_imlib2(pipi_image_t *img, const char *name);
     70int pipi_save_imlib2(pipi_image_t *img, const char *name);
    7271#endif
    7372
    7473#ifdef USE_OPENCV
    7574pipi_image_t *pipi_load_opencv(const char *name);
    76 pipi_image_t *pipi_new_opencv(int width, int height);
    77 void pipi_free_opencv(pipi_image_t *img);
    78 void pipi_save_opencv(pipi_image_t *img, const char *name);
     75int pipi_save_opencv(pipi_image_t *img, const char *name);
    7976#endif
    8077
    8178#ifdef USE_SDL
    8279pipi_image_t *pipi_load_sdl(const char *name);
    83 pipi_image_t *pipi_new_sdl(int width, int height);
    84 void pipi_free_sdl(pipi_image_t *img);
    85 void pipi_save_sdl(pipi_image_t *img, const char *name);
     80int pipi_save_sdl(pipi_image_t *img, const char *name);
    8681#endif
    8782
Note: See TracChangeset for help on using the changeset viewer.