| 1 | /* |
|---|
| 2 | * libpipi Pathetic image processing interface 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 | |
|---|
| 21 | #include <stdio.h> |
|---|
| 22 | #include <stdlib.h> |
|---|
| 23 | #include <string.h> |
|---|
| 24 | |
|---|
| 25 | #include "pipi.h" |
|---|
| 26 | #include "pipi_internals.h" |
|---|
| 27 | |
|---|
| 28 | pipi_image_t *pipi_load(char const *name) |
|---|
| 29 | { |
|---|
| 30 | pipi_image_t *ret = NULL; |
|---|
| 31 | |
|---|
| 32 | if(!strncmp(name, "random:", 7) || |
|---|
| 33 | !strncmp(name, "ediff:", 6) || |
|---|
| 34 | !strncmp(name, "halftone:", 6) || |
|---|
| 35 | !strncmp(name, "bayer:", 6)) |
|---|
| 36 | ret = pipi_load_stock(name); |
|---|
| 37 | |
|---|
| 38 | if(!ret) |
|---|
| 39 | ret = pipi_load_oric(name); |
|---|
| 40 | |
|---|
| 41 | #if USE_JPEG |
|---|
| 42 | if(!ret) |
|---|
| 43 | ret = pipi_load_jpeg(name); |
|---|
| 44 | #endif |
|---|
| 45 | #if USE_IMLIB2 |
|---|
| 46 | if(!ret) |
|---|
| 47 | ret = pipi_load_imlib2(name); |
|---|
| 48 | #endif |
|---|
| 49 | #if USE_OPENCV |
|---|
| 50 | if(!ret) |
|---|
| 51 | ret = pipi_load_opencv(name); |
|---|
| 52 | #endif |
|---|
| 53 | #if USE_SDL |
|---|
| 54 | if(!ret) |
|---|
| 55 | ret = pipi_load_sdl(name); |
|---|
| 56 | #endif |
|---|
| 57 | #if USE_GDIPLUS |
|---|
| 58 | if(!ret) |
|---|
| 59 | ret = pipi_load_gdiplus(name); |
|---|
| 60 | #endif |
|---|
| 61 | #if USE_GDI |
|---|
| 62 | if(!ret) |
|---|
| 63 | ret = pipi_load_gdi(name); |
|---|
| 64 | #endif |
|---|
| 65 | #if USE_COCOA |
|---|
| 66 | if(!ret) |
|---|
| 67 | ret = pipi_load_coreimage(name); |
|---|
| 68 | #endif |
|---|
| 69 | return ret; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | void pipi_free(pipi_image_t *img) |
|---|
| 73 | { |
|---|
| 74 | int i; |
|---|
| 75 | |
|---|
| 76 | for(i = 0; i < PIPI_PIXELS_MAX; i++) |
|---|
| 77 | if(i != img->codec_format && img->p[i].pixels) |
|---|
| 78 | free(img->p[i].pixels); |
|---|
| 79 | |
|---|
| 80 | if(img->codec_priv) |
|---|
| 81 | img->codec_free(img); |
|---|
| 82 | |
|---|
| 83 | free(img); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | int pipi_save(pipi_image_t *img, const char *name) |
|---|
| 87 | { |
|---|
| 88 | int ret = -1; |
|---|
| 89 | |
|---|
| 90 | if(ret < 0) |
|---|
| 91 | ret = pipi_save_oric(img, name); |
|---|
| 92 | |
|---|
| 93 | #if USE_JPEG |
|---|
| 94 | if(ret < 0) |
|---|
| 95 | ret = pipi_save_jpeg(img, name); |
|---|
| 96 | #endif |
|---|
| 97 | #if USE_IMLIB2 |
|---|
| 98 | if(ret < 0) |
|---|
| 99 | ret = pipi_save_imlib2(img, name); |
|---|
| 100 | #endif |
|---|
| 101 | #if USE_OPENCV |
|---|
| 102 | if(ret < 0) |
|---|
| 103 | ret = pipi_save_opencv(img, name); |
|---|
| 104 | #endif |
|---|
| 105 | #if USE_SDL |
|---|
| 106 | if(ret < 0) |
|---|
| 107 | ret = pipi_save_sdl(img, name); |
|---|
| 108 | #endif |
|---|
| 109 | #if USE_GDIPLUS |
|---|
| 110 | if(ret < 0) |
|---|
| 111 | ret = pipi_save_gdiplus(img, name); |
|---|
| 112 | #endif |
|---|
| 113 | #if USE_GDI |
|---|
| 114 | if(ret < 0) |
|---|
| 115 | ret = pipi_save_gdi(img, name); |
|---|
| 116 | #endif |
|---|
| 117 | #if USE_COCOA |
|---|
| 118 | if(ret < 0) |
|---|
| 119 | ret = pipi_save_coreimage(img, name); |
|---|
| 120 | #endif |
|---|
| 121 | |
|---|
| 122 | return ret; |
|---|
| 123 | } |
|---|
| 124 | |
|---|