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 | * imlib.c: ImLib 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 <Imlib2.h> |
---|
27 | |
---|
28 | #include "pipi.h" |
---|
29 | #include "pipi_internals.h" |
---|
30 | |
---|
31 | pipi_image_t *pipi_load_imlib2(const char *name) |
---|
32 | { |
---|
33 | pipi_image_t *img; |
---|
34 | Imlib_Image priv = imlib_load_image(name); |
---|
35 | |
---|
36 | if(!priv) |
---|
37 | return NULL; |
---|
38 | |
---|
39 | img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); |
---|
40 | imlib_context_set_image(priv); |
---|
41 | img->width = imlib_image_get_width(); |
---|
42 | img->height = imlib_image_get_height(); |
---|
43 | img->pitch = 4 * imlib_image_get_width(); |
---|
44 | img->channels = 4; |
---|
45 | img->pixels = (char *)imlib_image_get_data(); |
---|
46 | img->priv = (void *)priv; |
---|
47 | |
---|
48 | return img; |
---|
49 | } |
---|
50 | |
---|
51 | pipi_image_t *pipi_new_imlib2(int width, int height) |
---|
52 | { |
---|
53 | pipi_image_t *img; |
---|
54 | Imlib_Image priv = imlib_create_image(width, height); |
---|
55 | |
---|
56 | if(!priv) |
---|
57 | return NULL; |
---|
58 | |
---|
59 | img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); |
---|
60 | imlib_context_set_image(priv); |
---|
61 | img->width = imlib_image_get_width(); |
---|
62 | img->height = imlib_image_get_height(); |
---|
63 | img->pitch = 4 * imlib_image_get_width(); |
---|
64 | img->channels = 4; |
---|
65 | img->pixels = (char *)imlib_image_get_data(); |
---|
66 | img->priv = (void *)priv; |
---|
67 | |
---|
68 | return img; |
---|
69 | } |
---|
70 | |
---|
71 | void pipi_free_imlib2(pipi_image_t *img) |
---|
72 | { |
---|
73 | imlib_context_set_image(img->priv); |
---|
74 | imlib_free_image(); |
---|
75 | |
---|
76 | free(img); |
---|
77 | } |
---|
78 | |
---|
79 | void pipi_save_imlib2(pipi_image_t *img, const char *name) |
---|
80 | { |
---|
81 | imlib_context_set_image(img->priv); |
---|
82 | imlib_save_image(name); |
---|
83 | } |
---|
84 | |
---|