something far better, but later. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2261 92316355-f0b4-4df1-b90c-862c8a59935fremotes/tiles
@@ -10,31 +10,41 @@ pkgconfigdir = $(libdir)/pkgconfig | |||
include_HEADERS = pipi.h | |||
# Conditional sources | |||
codec_cflags = | |||
codec_libs = | |||
codec_sources = | |||
# The main library | |||
lib_LTLIBRARIES = libpipi.la | |||
libpipi_la_SOURCES = \ | |||
pipi.c \ | |||
pipi.h \ | |||
pipi_internals.h \ | |||
io.c \ | |||
pixels.c \ | |||
codec.c \ | |||
resize.c \ | |||
$(codec_sources) \ | |||
$(NULL) | |||
libpipi_la_CFLAGS = $(CFLAGS_EXTRA) | |||
libpipi_la_LDFLAGS = $(LDFLAGS_EXTRA) \ | |||
libpipi_la_CFLAGS = $(codec_cflags) | |||
libpipi_la_LDFLAGS = $(codec_libs) \ | |||
-no-undefined -version-number @LT_VERSION@ | |||
if USE_SDL | |||
CFLAGS_EXTRA = `sdl-config --cflags` | |||
LDFLAGS_EXTRA = `sdl-config --libs` -lSDL_image | |||
else | |||
if USE_IMLIB2 | |||
CFLAGS_EXTRA = @IMLIB2_CFLAGS@ | |||
LDFLAGS_EXTRA = @IMLIB2_LIBS@ | |||
else | |||
if USE_OPENCV | |||
CFLAGS_EXTRA = `opencv-config --cflags` | |||
LDFLAGS_EXTRA = `opencv-config --libs opencv highgui` | |||
codec_cflags += `sdl-config --cflags` | |||
codec_libs += `sdl-config --libs` -lSDL_image | |||
codec_sources += codec/sdl.c | |||
endif | |||
if USE_IMLIB2 | |||
codec_cflags += @IMLIB2_CFLAGS@ | |||
codec_libs += @IMLIB2_LIBS@ | |||
codec_sources += codec/imlib.c | |||
endif | |||
if USE_OPENCV | |||
codec_cflags += `opencv-config --cflags` | |||
codec_libs += `opencv-config --libs opencv highgui` | |||
codec_sources += codec/opencv.c | |||
endif | |||
@@ -0,0 +1,90 @@ | |||
/* | |||
* libpipi Proper image processing implementation library | |||
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||
* 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. | |||
*/ | |||
/* | |||
* codec.c: image I/O functions | |||
*/ | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include "config.h" | |||
#include "common.h" | |||
#include "pipi.h" | |||
#include "pipi_internals.h" | |||
pipi_image_t *pipi_load(const char *name) | |||
{ | |||
#if USE_SDL | |||
return pipi_load_sdl(name); | |||
#elif USE_IMLIB2 | |||
return pipi_load_imlib2(name); | |||
#elif USE_OPENCV | |||
return pipi_load_opencv(name); | |||
#else | |||
# error "No imaging library" | |||
#endif | |||
} | |||
pipi_image_t *pipi_new(int width, int height) | |||
{ | |||
#if USE_SDL | |||
return pipi_new_sdl(width, height); | |||
#elif USE_IMLIB2 | |||
return pipi_new_imlib2(width, height); | |||
#elif USE_OPENCV | |||
return pipi_new_opencv(width, height); | |||
#endif | |||
} | |||
pipi_image_t *pipi_copy(pipi_image_t const *img) | |||
{ | |||
pipi_image_t *dst; | |||
int x, y; | |||
dst = pipi_new(img->width, img->height); | |||
for(y = 0; y < img->height; y++) | |||
{ | |||
for(x = 0; x < img->width; x++) | |||
{ | |||
double r, g, b; | |||
pipi_getpixel(img, x, y, &r, &g, &b); | |||
pipi_setpixel(dst, x, y, r, g, b); | |||
} | |||
} | |||
return dst; | |||
} | |||
void pipi_free(pipi_image_t *img) | |||
{ | |||
#if USE_SDL | |||
return pipi_free_sdl(img); | |||
#elif USE_IMLIB2 | |||
return pipi_free_imlib2(img); | |||
#elif USE_OPENCV | |||
return pipi_free_opencv(img); | |||
#endif | |||
} | |||
void pipi_save(pipi_image_t *img, const char *name) | |||
{ | |||
#if USE_SDL | |||
return pipi_save_sdl(img, name); | |||
#elif USE_IMLIB2 | |||
return pipi_save_imlib2(img, name); | |||
#elif USE_OPENCV | |||
return pipi_save_opencv(img, name); | |||
#endif | |||
} | |||
@@ -0,0 +1,84 @@ | |||
/* | |||
* libpipi Proper image processing implementation library | |||
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||
* 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 <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <Imlib2.h> | |||
#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)); | |||
imlib_context_set_image(priv); | |||
img->width = imlib_image_get_width(); | |||
img->height = imlib_image_get_height(); | |||
img->pitch = 4 * imlib_image_get_width(); | |||
img->channels = 4; | |||
img->pixels = (char *)imlib_image_get_data(); | |||
img->priv = (void *)priv; | |||
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)); | |||
imlib_context_set_image(priv); | |||
img->width = imlib_image_get_width(); | |||
img->height = imlib_image_get_height(); | |||
img->pitch = 4 * imlib_image_get_width(); | |||
img->channels = 4; | |||
img->pixels = (char *)imlib_image_get_data(); | |||
img->priv = (void *)priv; | |||
return img; | |||
} | |||
void pipi_free_imlib2(pipi_image_t *img) | |||
{ | |||
imlib_context_set_image(img->priv); | |||
imlib_free_image(); | |||
free(img); | |||
} | |||
void pipi_save_imlib2(pipi_image_t *img, const char *name) | |||
{ | |||
imlib_context_set_image(img->priv); | |||
imlib_save_image(name); | |||
} | |||
@@ -0,0 +1,83 @@ | |||
/* | |||
* libpipi Proper image processing implementation library | |||
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||
* 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. | |||
*/ | |||
/* | |||
* image.c: image I/O functions | |||
*/ | |||
#include "config.h" | |||
#include "common.h" | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <cv.h> | |||
#include <highgui.h> | |||
#include "pipi.h" | |||
#include "pipi_internals.h" | |||
pipi_image_t *pipi_load_opencv(const char *name) | |||
{ | |||
pipi_image_t *img; | |||
IplImage *priv = cvLoadImage(name, -1); | |||
if(!priv) | |||
return NULL; | |||
img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); | |||
img->width = priv->width; | |||
img->height = priv->height; | |||
img->pitch = priv->widthStep; | |||
img->channels = priv->nChannels; | |||
img->pixels = priv->imageData; | |||
img->priv = (void *)priv; | |||
return img; | |||
} | |||
pipi_image_t *pipi_new_opencv(int width, int height) | |||
{ | |||
pipi_image_t *img; | |||
IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); | |||
if(!priv) | |||
return NULL; | |||
img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); | |||
img->width = priv->width; | |||
img->height = priv->height; | |||
img->pitch = priv->widthStep; | |||
img->channels = priv->nChannels; | |||
img->pixels = priv->imageData; | |||
img->priv = (void *)priv; | |||
return img; | |||
} | |||
void pipi_free_opencv(pipi_image_t *img) | |||
{ | |||
IplImage *iplimg; | |||
iplimg = (IplImage *)img->priv; | |||
cvReleaseImage(&iplimg); | |||
free(img); | |||
} | |||
void pipi_save_opencv(pipi_image_t *img, const char *name) | |||
{ | |||
cvSaveImage(name, img->priv); | |||
} | |||
@@ -0,0 +1,102 @@ | |||
/* | |||
* libpipi Proper image processing implementation library | |||
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||
* 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. | |||
*/ | |||
/* | |||
* sdl.c: SDL_image I/O functions | |||
*/ | |||
#include "config.h" | |||
#include "common.h" | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <SDL_image.h> | |||
#include "pipi.h" | |||
#include "pipi_internals.h" | |||
pipi_image_t *pipi_load_sdl(const char *name) | |||
{ | |||
pipi_image_t *img; | |||
SDL_Surface *priv = IMG_Load(name); | |||
if(!priv) | |||
return NULL; | |||
if(priv->format->BytesPerPixel == 1) | |||
{ | |||
img = pipi_new(priv->w, priv->h); | |||
SDL_BlitSurface(priv, NULL, img->priv, NULL); | |||
SDL_FreeSurface(priv); | |||
return img; | |||
} | |||
img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); | |||
img->width = priv->w; | |||
img->height = priv->h; | |||
img->pitch = priv->pitch; | |||
img->channels = priv->format->BytesPerPixel; | |||
img->pixels = priv->pixels; | |||
img->priv = (void *)priv; | |||
return img; | |||
} | |||
pipi_image_t *pipi_new_sdl(int width, int height) | |||
{ | |||
pipi_image_t *img; | |||
SDL_Surface *priv; | |||
Uint32 rmask, gmask, bmask, amask; | |||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN | |||
rmask = 0xff000000; | |||
gmask = 0x00ff0000; | |||
bmask = 0x0000ff00; | |||
amask = 0x00000000; | |||
#else | |||
rmask = 0x000000ff; | |||
gmask = 0x0000ff00; | |||
bmask = 0x00ff0000; | |||
amask = 0x00000000; | |||
#endif | |||
priv = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, | |||
rmask, gmask, bmask, amask); | |||
if(!priv) | |||
return NULL; | |||
img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); | |||
img->width = priv->w; | |||
img->height = priv->h; | |||
img->pitch = priv->pitch; | |||
img->channels = priv->format->BytesPerPixel; | |||
img->pixels = priv->pixels; | |||
img->priv = (void *)priv; | |||
return img; | |||
} | |||
void pipi_free_sdl(pipi_image_t *img) | |||
{ | |||
SDL_FreeSurface(img->priv); | |||
free(img); | |||
} | |||
void pipi_save_sdl(pipi_image_t *img, const char *name) | |||
{ | |||
SDL_SaveBMP(img->priv, name); | |||
} | |||
@@ -1,188 +0,0 @@ | |||
/* | |||
* libpipi Proper image processing implementation library | |||
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||
* 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. | |||
*/ | |||
/* | |||
* image.c: image I/O functions | |||
*/ | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include "config.h" | |||
#include "common.h" | |||
#if defined(HAVE_SDL_IMAGE_H) | |||
# include <SDL_image.h> | |||
#elif defined(HAVE_IMLIB2_H) | |||
# include <Imlib2.h> | |||
#elif defined(HAVE_CV_H) | |||
# include <cv.h> | |||
# include <highgui.h> | |||
#else | |||
# error "No imaging library" | |||
#endif | |||
#include "pipi_internals.h" | |||
#include "pipi.h" | |||
pipi_image_t *pipi_load(const char *name) | |||
{ | |||
pipi_image_t *img; | |||
#if defined(HAVE_SDL_IMAGE_H) | |||
SDL_Surface *priv = IMG_Load(name); | |||
#elif defined(HAVE_IMLIB2_H) | |||
Imlib_Image priv = imlib_load_image(name); | |||
#elif defined(HAVE_CV_H) | |||
IplImage *priv = cvLoadImage(name, -1); | |||
#endif | |||
if(!priv) | |||
return NULL; | |||
#if defined(HAVE_SDL_IMAGE_H) | |||
if(priv->format->BytesPerPixel == 1) | |||
{ | |||
img = pipi_new(priv->w, priv->h); | |||
SDL_BlitSurface(priv, NULL, img->priv, NULL); | |||
SDL_FreeSurface(priv); | |||
return img; | |||
} | |||
#endif | |||
img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); | |||
#if defined(HAVE_SDL_IMAGE_H) | |||
img->width = priv->w; | |||
img->height = priv->h; | |||
img->pitch = priv->pitch; | |||
img->channels = priv->format->BytesPerPixel; | |||
img->pixels = priv->pixels; | |||
#elif defined(HAVE_IMLIB2_H) | |||
imlib_context_set_image(priv); | |||
img->width = imlib_image_get_width(); | |||
img->height = imlib_image_get_height(); | |||
img->pitch = 4 * imlib_image_get_width(); | |||
img->channels = 4; | |||
img->pixels = (char *)imlib_image_get_data(); | |||
#elif defined(HAVE_CV_H) | |||
img->width = priv->width; | |||
img->height = priv->height; | |||
img->pitch = priv->widthStep; | |||
img->channels = priv->nChannels; | |||
img->pixels = priv->imageData; | |||
#endif | |||
img->priv = (void *)priv; | |||
return img; | |||
} | |||
pipi_image_t *pipi_new(int width, int height) | |||
{ | |||
pipi_image_t *img; | |||
#if defined(HAVE_SDL_IMAGE_H) | |||
SDL_Surface *priv; | |||
Uint32 rmask, gmask, bmask, amask; | |||
# if SDL_BYTEORDER == SDL_BIG_ENDIAN | |||
rmask = 0xff000000; | |||
gmask = 0x00ff0000; | |||
bmask = 0x0000ff00; | |||
amask = 0x00000000; | |||
# else | |||
rmask = 0x000000ff; | |||
gmask = 0x0000ff00; | |||
bmask = 0x00ff0000; | |||
amask = 0x00000000; | |||
# endif | |||
priv = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, | |||
rmask, gmask, bmask, amask); | |||
#elif defined(HAVE_IMLIB2_H) | |||
Imlib_Image priv = imlib_create_image(width, height); | |||
#elif defined(HAVE_CV_H) | |||
IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); | |||
#endif | |||
if(!priv) | |||
return NULL; | |||
img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); | |||
#if defined(HAVE_SDL_IMAGE_H) | |||
img->width = priv->w; | |||
img->height = priv->h; | |||
img->pitch = priv->pitch; | |||
img->channels = priv->format->BytesPerPixel; | |||
img->pixels = priv->pixels; | |||
#elif defined(HAVE_IMLIB2_H) | |||
imlib_context_set_image(priv); | |||
img->width = imlib_image_get_width(); | |||
img->height = imlib_image_get_height(); | |||
img->pitch = 4 * imlib_image_get_width(); | |||
img->channels = 4; | |||
img->pixels = (char *)imlib_image_get_data(); | |||
#elif defined(HAVE_CV_H) | |||
img->width = priv->width; | |||
img->height = priv->height; | |||
img->pitch = priv->widthStep; | |||
img->channels = priv->nChannels; | |||
img->pixels = priv->imageData; | |||
#endif | |||
img->priv = (void *)priv; | |||
return img; | |||
} | |||
pipi_image_t *pipi_copy(pipi_image_t const *img) | |||
{ | |||
pipi_image_t *dst; | |||
int x, y; | |||
dst = pipi_new(img->width, img->height); | |||
for(y = 0; y < img->height; y++) | |||
{ | |||
for(x = 0; x < img->width; x++) | |||
{ | |||
int r, g, b; | |||
pipi_getpixel(img, x, y, &r, &g, &b); | |||
pipi_setpixel(dst, x, y, r, g, b); | |||
} | |||
} | |||
return dst; | |||
} | |||
void pipi_free(pipi_image_t *img) | |||
{ | |||
#if defined(HAVE_SDL_IMAGE_H) | |||
SDL_FreeSurface(img->priv); | |||
#elif defined(HAVE_IMLIB2_H) | |||
imlib_context_set_image(img->priv); | |||
imlib_free_image(); | |||
#elif defined(HAVE_CV_H) | |||
IplImage *iplimg; | |||
iplimg = (IplImage *)img->priv; | |||
cvReleaseImage(&iplimg); | |||
#endif | |||
free(img); | |||
} | |||
void pipi_save(pipi_image_t *img, const char *name) | |||
{ | |||
#if defined(HAVE_SDL_IMAGE_H) | |||
SDL_SaveBMP(img->priv, name); | |||
#elif defined(HAVE_IMLIB2_H) | |||
imlib_context_set_image(img->priv); | |||
imlib_save_image(name); | |||
#elif defined(HAVE_CV_H) | |||
cvSaveImage(name, img->priv); | |||
#endif | |||
} | |||
@@ -13,7 +13,7 @@ | |||
*/ | |||
/* | |||
* pipi_internals.h: internal types | |||
* pipi_internals.h: internal types | |||
*/ | |||
#ifndef __CACA_INTERNALS_H__ | |||
@@ -26,5 +26,26 @@ struct pipi_image | |||
void *priv; | |||
}; | |||
#ifdef USE_IMLIB2 | |||
pipi_image_t *pipi_load_imlib2(const char *name); | |||
pipi_image_t *pipi_new_imlib2(int width, int height); | |||
void pipi_free_imlib2(pipi_image_t *img); | |||
void pipi_save_imlib2(pipi_image_t *img, const char *name); | |||
#endif | |||
#ifdef USE_OPENCV | |||
pipi_image_t *pipi_load_opencv(const char *name); | |||
pipi_image_t *pipi_new_opencv(int width, int height); | |||
void pipi_free_opencv(pipi_image_t *img); | |||
void pipi_save_opencv(pipi_image_t *img, const char *name); | |||
#endif | |||
#ifdef USE_SDL | |||
pipi_image_t *pipi_load_sdl(const char *name); | |||
pipi_image_t *pipi_new_sdl(int width, int height); | |||
void pipi_free_sdl(pipi_image_t *img); | |||
void pipi_save_sdl(pipi_image_t *img, const char *name); | |||
#endif | |||
#endif /* __PIPI_INTERNALS_H__ */ | |||