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 | |
---|
29 | pipi_image_t *pipi_load(char const *name) |
---|
30 | { |
---|
31 | if(!strncmp(name, "pipi:", 5)) |
---|
32 | return pipi_load_stock(name + 5); |
---|
33 | |
---|
34 | #if USE_IMLIB2 |
---|
35 | return pipi_load_imlib2(name); |
---|
36 | #elif USE_OPENCV |
---|
37 | return pipi_load_opencv(name); |
---|
38 | #elif USE_SDL |
---|
39 | return pipi_load_sdl(name); |
---|
40 | #else |
---|
41 | # error "No imaging library" |
---|
42 | #endif |
---|
43 | } |
---|
44 | |
---|
45 | void pipi_free(pipi_image_t *img) |
---|
46 | { |
---|
47 | int i; |
---|
48 | |
---|
49 | for(i = 0; i < PIPI_PIXELS_MAX; i++) |
---|
50 | if(i != img->codec_format && img->p[i].pixels) |
---|
51 | free(img->p[i].pixels); |
---|
52 | |
---|
53 | if(img->codec_priv) |
---|
54 | #if USE_IMLIB2 |
---|
55 | pipi_free_imlib2(img); |
---|
56 | #elif USE_OPENCV |
---|
57 | pipi_free_opencv(img); |
---|
58 | #elif USE_SDL |
---|
59 | pipi_free_sdl(img); |
---|
60 | #endif |
---|
61 | |
---|
62 | free(img); |
---|
63 | } |
---|
64 | |
---|
65 | void pipi_save(pipi_image_t *img, const char *name) |
---|
66 | { |
---|
67 | #if USE_IMLIB2 |
---|
68 | return pipi_save_imlib2(img, name); |
---|
69 | #elif USE_OPENCV |
---|
70 | return pipi_save_opencv(img, name); |
---|
71 | #elif USE_SDL |
---|
72 | return pipi_save_sdl(img, name); |
---|
73 | #endif |
---|
74 | } |
---|
75 | |
---|