git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3343 92316355-f0b4-4df1-b90c-862c8a59935fmaster
@@ -177,33 +177,17 @@ AC_CHECK_HEADERS(/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h, | |||||
) | ) | ||||
AM_CONDITIONAL(USE_COCOA, test "${ac_cv_my_have_cocoa}" = "yes") | AM_CONDITIONAL(USE_COCOA, test "${ac_cv_my_have_cocoa}" = "yes") | ||||
# Use Modular codecs ? | |||||
MODULAR_CODEC="" | |||||
ac_cv_my_have_modular="no" | |||||
ac_cv_my_have_libjpeg="no" | |||||
# Use libjpeg? | |||||
ac_cv_my_have_jpeg="no" | |||||
AC_CHECK_HEADERS(jpeglib.h, | AC_CHECK_HEADERS(jpeglib.h, | ||||
[ac_cv_my_have_libjpeg="yes"], | |||||
[ac_cv_my_have_libjpeg="no"]) | |||||
if test "${ac_cv_my_have_libjpeg}" != "no"; then | |||||
ac_cv_my_have_modular="yes" | |||||
AC_DEFINE(USE_LIBJPEG, 1, Define to 1 to use libjpeg) | |||||
AC_DEFINE(USE_MODULAR, 1, Define to 1 to use modular codecs) | |||||
MODULAR_CODEC="${MODULAR_CODEC} libjpeg" | |||||
fi | |||||
AM_CONDITIONAL(USE_LIBJPEG, test "${ac_cv_my_have_libjpeg}" = "yes") | |||||
AM_CONDITIONAL(USE_MODULAR, test "${ac_cv_my_have_modular}" = "yes") | |||||
AC_MSG_CHECKING(valid modular codecs) | |||||
if test -z "${MODULAR_CODEC}"; then | |||||
AC_MSG_RESULT(none) | |||||
else | |||||
MODULAR_CODEC="${MODULAR_CODEC# *}" | |||||
AC_MSG_RESULT([${MODULAR_CODEC}]) | |||||
[ac_cv_my_have_jpeg="yes"], | |||||
[ac_cv_my_have_jpeg="no"]) | |||||
if test "${ac_cv_my_have_jpeg}" != "no"; then | |||||
AC_DEFINE(USE_JPEG, 1, Define to 1 to use libjpeg) | |||||
fi | fi | ||||
AM_CONDITIONAL(USE_JPEG, test "${ac_cv_my_have_jpeg}" = "yes") | |||||
if test "${ac_cv_my_have_sdl}" = "no" -a "${ac_cv_my_have_imlib2}" = "no" -a "${ac_cv_my_have_opencv}" = "no" -a "${ac_cv_my_have_cocoa}" = "no" -a "${ac_cv_my_have_modular}" = "no"; then | |||||
if test "${ac_cv_my_have_sdl}" = "no" -a "${ac_cv_my_have_imlib2}" = "no" -a "${ac_cv_my_have_opencv}" = "no" -a "${ac_cv_my_have_cocoa}" = "no" -a "${ac_cv_my_have_jpeg}" = "no"; then | |||||
AC_MSG_ERROR([[cannot find GDI+, SDL_Image, Imlib2, Cocoa or OpenCV, please install one of them]]) | AC_MSG_ERROR([[cannot find GDI+, SDL_Image, Imlib2, Cocoa or OpenCV, please install one of them]]) | ||||
fi | fi | ||||
@@ -124,11 +124,8 @@ codec_libs += -framework Cocoa -framework IOKit -framework CoreFoundation -frame | |||||
codec_sources += codec/coreimage.m | codec_sources += codec/coreimage.m | ||||
endif | endif | ||||
# Modular codecs | |||||
if USE_MODULAR | |||||
codec_sources += codec/modular.c | |||||
if USE_LIBJPEG | |||||
if USE_JPEG | |||||
codec_libs += -ljpeg | codec_libs += -ljpeg | ||||
codec_sources += codec/modular/jpeg.c | |||||
endif | |||||
codec_sources += codec/jpeg.c | |||||
endif | endif | ||||
@@ -38,6 +38,10 @@ pipi_image_t *pipi_load(char const *name) | |||||
if(!ret) | if(!ret) | ||||
ret = pipi_load_oric(name); | ret = pipi_load_oric(name); | ||||
#if USE_JPEG | |||||
if(!ret) | |||||
ret = pipi_load_jpeg(name); | |||||
#endif | |||||
#if USE_IMLIB2 | #if USE_IMLIB2 | ||||
if(!ret) | if(!ret) | ||||
ret = pipi_load_imlib2(name); | ret = pipi_load_imlib2(name); | ||||
@@ -61,10 +65,6 @@ pipi_image_t *pipi_load(char const *name) | |||||
#if USE_COCOA | #if USE_COCOA | ||||
if(!ret) | if(!ret) | ||||
ret = pipi_load_coreimage(name); | ret = pipi_load_coreimage(name); | ||||
#endif | |||||
#if USE_MODULAR | |||||
if(!ret) | |||||
ret = pipi_load_modular(name); | |||||
#endif | #endif | ||||
return ret; | return ret; | ||||
} | } | ||||
@@ -90,9 +90,9 @@ int pipi_save(pipi_image_t *img, const char *name) | |||||
if(ret < 0) | if(ret < 0) | ||||
ret = pipi_save_oric(img, name); | ret = pipi_save_oric(img, name); | ||||
#if USE_MODULAR | |||||
#if USE_JPEG | |||||
if(ret < 0) | if(ret < 0) | ||||
ret = pipi_save_modular(img, name); | |||||
ret = pipi_save_jpeg(img, name); | |||||
#endif | #endif | ||||
#if USE_IMLIB2 | #if USE_IMLIB2 | ||||
if(ret < 0) | if(ret < 0) | ||||
@@ -17,13 +17,20 @@ | |||||
* jpeg.c: libjpeg I/O functions | * jpeg.c: libjpeg I/O functions | ||||
*/ | */ | ||||
#include "../modular.h" | |||||
#include <setjmp.h> | |||||
#include "config.h" | |||||
static int pipi_free_jpeg(pipi_image_t *img); | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include <ctype.h> | |||||
#include <setjmp.h> | |||||
#include <jpeglib.h> | |||||
#include "pipi.h" | |||||
#include "pipi_internals.h" | |||||
static int pipi_free_jpeg(pipi_image_t *img); | |||||
struct my_error_mgr { | struct my_error_mgr { | ||||
struct jpeg_error_mgr pub; | struct jpeg_error_mgr pub; | ||||
@@ -55,8 +62,9 @@ pipi_image_t *pipi_load_jpeg(const char *name) | |||||
unsigned char *image = NULL, *scanline = NULL; | unsigned char *image = NULL, *scanline = NULL; | ||||
pipi_image_t *img = NULL; | pipi_image_t *img = NULL; | ||||
unsigned int i, j, k = 0; | unsigned int i, j, k = 0; | ||||
FILE *fp; | |||||
FILE *fp = fopen(name, "rb"); | |||||
fp = fopen(name, "rb"); | |||||
if(!fp) goto end; | if(!fp) goto end; | ||||
@@ -142,6 +150,21 @@ int pipi_save_jpeg(pipi_image_t *img, const char *name) | |||||
struct my_error_mgr jerr; | struct my_error_mgr jerr; | ||||
unsigned char *data = NULL; | unsigned char *data = NULL; | ||||
unsigned char *line = NULL; | unsigned char *line = NULL; | ||||
size_t len; | |||||
len = strlen(name); | |||||
if(len < 4 || name[len - 4] != '.' | |||||
|| toupper(name[len - 3]) != 'J' | |||||
|| toupper(name[len - 2]) != 'P' | |||||
|| toupper(name[len - 1]) != 'G') | |||||
{ | |||||
if(len < 5 || name[len - 5] != '.' | |||||
|| toupper(name[len - 4]) != 'J' | |||||
|| toupper(name[len - 3]) != 'P' | |||||
|| toupper(name[len - 2]) != 'E' | |||||
|| toupper(name[len - 1]) != 'G') | |||||
return -1; | |||||
} | |||||
pipi_pixels_t *pixels = pipi_get_pixels(img, PIPI_PIXELS_RGBA_U8); | pipi_pixels_t *pixels = pipi_get_pixels(img, PIPI_PIXELS_RGBA_U8); | ||||
@@ -1,35 +0,0 @@ | |||||
/* | |||||
* libpipi Pathetic image processing interface library | |||||
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||||
* 2008 Jean-Yves Lamoureux <jylam@lnxscene.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. | |||||
*/ | |||||
/* | |||||
* modular.c: hand-written codecs multiplexer | |||||
*/ | |||||
#include "modular.h" | |||||
pipi_image_t *pipi_load_modular(const char *name) | |||||
{ | |||||
return pipi_load_jpeg(name); | |||||
} | |||||
int pipi_save_modular(pipi_image_t *img, const char *name) | |||||
{ | |||||
if(strlen(name) >= 4) | |||||
if(!strncasecmp(&name[strlen(name) - 3], "jpg", 3) || | |||||
!strncasecmp(&name[strlen(name) - 4], "jpeg", 4) ) | |||||
return pipi_save_jpeg(img, name); | |||||
return -1; | |||||
} |
@@ -1,34 +0,0 @@ | |||||
/* | |||||
* libpipi Pathetic image processing interface library | |||||
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||||
* 2008 Jean-Yves Lamoureux <jylam@lnxscene.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. | |||||
*/ | |||||
/* | |||||
* modular.h: modular I/O functions | |||||
*/ | |||||
#include "config.h" | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include <jpeglib.h> | |||||
#include "pipi.h" | |||||
#include "pipi_internals.h" | |||||
pipi_image_t *pipi_load_jpeg(const char *name); | |||||
int pipi_save_jpeg(pipi_image_t *img, const char *name); |
@@ -118,14 +118,11 @@ pipi_image_t *pipi_load_coreimage(const char *name); | |||||
int pipi_save_coreimage(pipi_image_t *img, const char *name); | int pipi_save_coreimage(pipi_image_t *img, const char *name); | ||||
#endif | #endif | ||||
/* Modular codecs */ | |||||
#ifdef USE_MODULAR | |||||
pipi_image_t *pipi_load_modular(const char *name); | |||||
int pipi_save_modular(pipi_image_t *img, const char *name); | |||||
#ifdef USE_JPEG | |||||
pipi_image_t *pipi_load_jpeg(const char *name); | |||||
int pipi_save_jpeg(pipi_image_t *img, const char *name); | |||||
#endif | #endif | ||||
pipi_image_t *pipi_load_oric(const char *name); | pipi_image_t *pipi_load_oric(const char *name); | ||||
int pipi_save_oric(pipi_image_t *img, const char *name); | int pipi_save_oric(pipi_image_t *img, const char *name); | ||||