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

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

Wrote an Oric hires file parser.

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