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 <stdio.h> |
---|
20 | #include <stdlib.h> |
---|
21 | |
---|
22 | #include "config.h" |
---|
23 | #include "common.h" |
---|
24 | |
---|
25 | #include "pipi.h" |
---|
26 | #include "pipi_internals.h" |
---|
27 | |
---|
28 | pipi_image_t *pipi_load(const char *name) |
---|
29 | { |
---|
30 | #if USE_SDL |
---|
31 | return pipi_load_sdl(name); |
---|
32 | #elif USE_IMLIB2 |
---|
33 | return pipi_load_imlib2(name); |
---|
34 | #elif USE_OPENCV |
---|
35 | return pipi_load_opencv(name); |
---|
36 | #else |
---|
37 | # error "No imaging library" |
---|
38 | #endif |
---|
39 | } |
---|
40 | |
---|
41 | pipi_image_t *pipi_new(int width, int height) |
---|
42 | { |
---|
43 | #if USE_SDL |
---|
44 | return pipi_new_sdl(width, height); |
---|
45 | #elif USE_IMLIB2 |
---|
46 | return pipi_new_imlib2(width, height); |
---|
47 | #elif USE_OPENCV |
---|
48 | return pipi_new_opencv(width, height); |
---|
49 | #endif |
---|
50 | } |
---|
51 | |
---|
52 | pipi_image_t *pipi_copy(pipi_image_t const *img) |
---|
53 | { |
---|
54 | pipi_image_t *dst; |
---|
55 | int x, y; |
---|
56 | dst = pipi_new(img->width, img->height); |
---|
57 | for(y = 0; y < img->height; y++) |
---|
58 | { |
---|
59 | for(x = 0; x < img->width; x++) |
---|
60 | { |
---|
61 | double r, g, b; |
---|
62 | pipi_getpixel(img, x, y, &r, &g, &b); |
---|
63 | pipi_setpixel(dst, x, y, r, g, b); |
---|
64 | } |
---|
65 | } |
---|
66 | return dst; |
---|
67 | } |
---|
68 | |
---|
69 | void pipi_free(pipi_image_t *img) |
---|
70 | { |
---|
71 | #if USE_SDL |
---|
72 | return pipi_free_sdl(img); |
---|
73 | #elif USE_IMLIB2 |
---|
74 | return pipi_free_imlib2(img); |
---|
75 | #elif USE_OPENCV |
---|
76 | return pipi_free_opencv(img); |
---|
77 | #endif |
---|
78 | } |
---|
79 | |
---|
80 | void pipi_save(pipi_image_t *img, const char *name) |
---|
81 | { |
---|
82 | #if USE_SDL |
---|
83 | return pipi_save_sdl(img, name); |
---|
84 | #elif USE_IMLIB2 |
---|
85 | return pipi_save_imlib2(img, name); |
---|
86 | #elif USE_OPENCV |
---|
87 | return pipi_save_opencv(img, name); |
---|
88 | #endif |
---|
89 | } |
---|
90 | |
---|