source: libpipi/trunk/pipi/codec/imlib.c @ 2605

Last change on this file since 2605 was 2605, checked in by Sam Hocevar, 13 years ago
  • Big API reorganisation. Now libpipi can transparently convert between colour spaces for a given image. For instance, if pipi_gaussian_blur is applied to a 32-bpp image, it is automatically converted to gamma-corrected 32-bit floats beforehands, then converted back to normal.
  • TODO: clipping, regions of interest, more formats, getpixel macros...
File size: 2.5 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 * 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
31pipi_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    memset(img, 0, sizeof(pipi_image_t));
41
42    imlib_context_set_image(priv);
43    img->w = imlib_image_get_width();
44    img->h = imlib_image_get_height();
45
46    img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data();
47    img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width();
48    img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height();
49    img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width();
50    img->last_modified = PIPI_PIXELS_RGBA32;
51
52    img->codec_priv = (void *)priv;
53    img->codec_format = PIPI_PIXELS_RGBA32;
54
55    return img;
56}
57
58pipi_image_t *pipi_new_imlib2(int width, int height)
59{
60    pipi_image_t *img;
61    Imlib_Image priv = imlib_create_image(width, height);
62
63    if(!priv)
64        return NULL;
65
66    img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
67    memset(img, 0, sizeof(pipi_image_t));
68
69    imlib_context_set_image(priv);
70    img->w = imlib_image_get_width();
71    img->h = imlib_image_get_height();
72
73    img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data();
74    img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width();
75    img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height();
76    img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width();
77    img->last_modified = PIPI_PIXELS_RGBA32;
78
79    img->codec_priv = (void *)priv;
80    img->codec_format = PIPI_PIXELS_RGBA32;
81
82    return img;
83}
84
85void pipi_free_imlib2(pipi_image_t *img)
86{
87    imlib_context_set_image(img->codec_priv);
88    imlib_free_image();
89
90    free(img);
91}
92
93void pipi_save_imlib2(pipi_image_t *img, const char *name)
94{
95    pipi_getpixels(img, img->codec_format);
96    imlib_context_set_image(img->codec_priv);
97    imlib_save_image(name);
98}
99
Note: See TracBrowser for help on using the repository browser.