source: libpipi/trunk/pipi/codec.c @ 2837

Last change on this file since 2837 was 2837, checked in by Sam Hocevar, 12 years ago

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

File size: 1.7 KB
Line 
1/*
2 *  libpipi       Proper image processing implementation library
3 *  Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id$
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 * codec.c: image I/O functions
17 */
18
19#include "config.h"
20#include "common.h"
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include "pipi.h"
27#include "pipi_internals.h"
28
29pipi_image_t *pipi_load(char const *name)
30{
31    pipi_image_t *ret = NULL;
32
33    if(!strncmp(name, "random:", 7) ||
34       !strncmp(name, "ediff:", 6) ||
35       !strncmp(name, "halftone:", 6) ||
36       !strncmp(name, "bayer:", 6))
37        ret = pipi_load_stock(name);
38
39#if USE_IMLIB2
40    if(!ret)
41        ret = pipi_load_imlib2(name);
42#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;
53}
54
55void pipi_free(pipi_image_t *img)
56{
57    int i;
58
59    for(i = 0; i < PIPI_PIXELS_MAX; i++)
60        if(i != img->codec_format && img->p[i].pixels)
61            free(img->p[i].pixels);
62
63    if(img->codec_priv)
64        img->codec_free(img);
65
66    free(img);
67}
68
69int pipi_save(pipi_image_t *img, const char *name)
70{
71    int ret = -1;
72
73#if USE_IMLIB2
74    if(ret < 0)
75        ret = pipi_save_imlib2(img, name);
76#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;
87}
88
Note: See TracBrowser for help on using the repository browser.