/* * libpipi Proper image processing implementation library * Copyright (c) 2004-2008 Sam Hocevar * All Rights Reserved * * $Id$ * * This library is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/wtfpl/COPYING for more details. */ /* * imlib.c: ImLib I/O functions */ #include "config.h" #include "common.h" #include #include #include #include #include "pipi.h" #include "pipi_internals.h" pipi_image_t *pipi_load_imlib2(const char *name) { pipi_image_t *img; Imlib_Image priv = imlib_load_image(name); if(!priv) return NULL; img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); memset(img, 0, sizeof(pipi_image_t)); imlib_context_set_image(priv); img->w = imlib_image_get_width(); img->h = imlib_image_get_height(); img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data(); img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width(); img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height(); img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width(); img->last_modified = PIPI_PIXELS_RGBA32; img->codec_priv = (void *)priv; img->codec_format = PIPI_PIXELS_RGBA32; return img; } pipi_image_t *pipi_new_imlib2(int width, int height) { pipi_image_t *img; Imlib_Image priv = imlib_create_image(width, height); if(!priv) return NULL; img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); memset(img, 0, sizeof(pipi_image_t)); imlib_context_set_image(priv); img->w = imlib_image_get_width(); img->h = imlib_image_get_height(); img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data(); img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width(); img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height(); img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width(); img->last_modified = PIPI_PIXELS_RGBA32; img->codec_priv = (void *)priv; img->codec_format = PIPI_PIXELS_RGBA32; return img; } void pipi_free_imlib2(pipi_image_t *img) { imlib_context_set_image(img->codec_priv); imlib_free_image(); free(img); } void pipi_save_imlib2(pipi_image_t *img, const char *name) { pipi_getpixels(img, img->codec_format); imlib_context_set_image(img->codec_priv); imlib_save_image(name); }