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

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

gdi.c: the GDI codec can now open and save BMP files.

File size: 1.9 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#if USE_GDI
52    if(!ret)
53        ret = pipi_load_gdi(name);
54#endif
55
56    return ret;
57}
58
59void pipi_free(pipi_image_t *img)
60{
61    int i;
62
63    for(i = 0; i < PIPI_PIXELS_MAX; i++)
64        if(i != img->codec_format && img->p[i].pixels)
65            free(img->p[i].pixels);
66
67    if(img->codec_priv)
68        img->codec_free(img);
69
70    free(img);
71}
72
73int pipi_save(pipi_image_t *img, const char *name)
74{
75    int ret = -1;
76
77#if USE_IMLIB2
78    if(ret < 0)
79        ret = pipi_save_imlib2(img, name);
80#endif
81#if USE_OPENCV
82    if(ret < 0)
83        ret = pipi_save_opencv(img, name);
84#endif
85#if USE_SDL
86    if(ret < 0)
87        ret = pipi_save_sdl(img, name);
88#endif
89#if USE_GDI
90    if(ret < 0)
91        ret = pipi_save_gdi(img, name);
92#endif
93
94    return ret;
95}
96
Note: See TracBrowser for help on using the repository browser.