From 0a241eb0881a3f2219135b52e4958255b6772180 Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 12 Jan 2009 23:51:36 +0000 Subject: [PATCH] Got rid of the modular codec stuff. All codecs should work the same way. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3343 92316355-f0b4-4df1-b90c-862c8a59935f --- configure.ac | 32 ++++++++---------------------- pipi/Makefile.am | 9 +++------ pipi/codec.c | 12 +++++------ pipi/codec/{modular => }/jpeg.c | 31 +++++++++++++++++++++++++---- pipi/codec/modular.c | 35 --------------------------------- pipi/codec/modular.h | 34 -------------------------------- pipi/pipi_internals.h | 9 +++------ 7 files changed, 47 insertions(+), 115 deletions(-) rename pipi/codec/{modular => }/jpeg.c (88%) delete mode 100644 pipi/codec/modular.c delete mode 100644 pipi/codec/modular.h diff --git a/configure.ac b/configure.ac index 01a14e5..3469c93 100644 --- a/configure.ac +++ b/configure.ac @@ -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") - -# 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_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 +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]]) fi diff --git a/pipi/Makefile.am b/pipi/Makefile.am index d29d426..3c277f3 100644 --- a/pipi/Makefile.am +++ b/pipi/Makefile.am @@ -124,11 +124,8 @@ codec_libs += -framework Cocoa -framework IOKit -framework CoreFoundation -frame codec_sources += codec/coreimage.m endif -# Modular codecs -if USE_MODULAR -codec_sources += codec/modular.c -if USE_LIBJPEG +if USE_JPEG codec_libs += -ljpeg -codec_sources += codec/modular/jpeg.c -endif +codec_sources += codec/jpeg.c endif + diff --git a/pipi/codec.c b/pipi/codec.c index 2276d66..bdaae09 100644 --- a/pipi/codec.c +++ b/pipi/codec.c @@ -38,6 +38,10 @@ pipi_image_t *pipi_load(char const *name) if(!ret) ret = pipi_load_oric(name); +#if USE_JPEG + if(!ret) + ret = pipi_load_jpeg(name); +#endif #if USE_IMLIB2 if(!ret) ret = pipi_load_imlib2(name); @@ -61,10 +65,6 @@ pipi_image_t *pipi_load(char const *name) #if USE_COCOA if(!ret) ret = pipi_load_coreimage(name); -#endif -#if USE_MODULAR - if(!ret) - ret = pipi_load_modular(name); #endif return ret; } @@ -90,9 +90,9 @@ int pipi_save(pipi_image_t *img, const char *name) if(ret < 0) ret = pipi_save_oric(img, name); -#if USE_MODULAR +#if USE_JPEG if(ret < 0) - ret = pipi_save_modular(img, name); + ret = pipi_save_jpeg(img, name); #endif #if USE_IMLIB2 if(ret < 0) diff --git a/pipi/codec/modular/jpeg.c b/pipi/codec/jpeg.c similarity index 88% rename from pipi/codec/modular/jpeg.c rename to pipi/codec/jpeg.c index ffb2716..ef76e7f 100644 --- a/pipi/codec/modular/jpeg.c +++ b/pipi/codec/jpeg.c @@ -17,13 +17,20 @@ * jpeg.c: libjpeg I/O functions */ -#include "../modular.h" -#include +#include "config.h" -static int pipi_free_jpeg(pipi_image_t *img); +#include +#include +#include +#include +#include +#include +#include "pipi.h" +#include "pipi_internals.h" +static int pipi_free_jpeg(pipi_image_t *img); struct my_error_mgr { struct jpeg_error_mgr pub; @@ -55,8 +62,9 @@ pipi_image_t *pipi_load_jpeg(const char *name) unsigned char *image = NULL, *scanline = NULL; pipi_image_t *img = NULL; unsigned int i, j, k = 0; + FILE *fp; - FILE *fp = fopen(name, "rb"); + fp = fopen(name, "rb"); if(!fp) goto end; @@ -142,6 +150,21 @@ int pipi_save_jpeg(pipi_image_t *img, const char *name) struct my_error_mgr jerr; unsigned char *data = 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); diff --git a/pipi/codec/modular.c b/pipi/codec/modular.c deleted file mode 100644 index 181ba9e..0000000 --- a/pipi/codec/modular.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * libpipi Pathetic image processing interface library - * Copyright (c) 2004-2008 Sam Hocevar - * 2008 Jean-Yves Lamoureux - * 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; -} diff --git a/pipi/codec/modular.h b/pipi/codec/modular.h deleted file mode 100644 index 947cab4..0000000 --- a/pipi/codec/modular.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * libpipi Pathetic image processing interface library - * Copyright (c) 2004-2008 Sam Hocevar - * 2008 Jean-Yves Lamoureux - * 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 -#include -#include - -#include - -#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); diff --git a/pipi/pipi_internals.h b/pipi/pipi_internals.h index ab7d47c..15c08b6 100644 --- a/pipi/pipi_internals.h +++ b/pipi/pipi_internals.h @@ -118,14 +118,11 @@ pipi_image_t *pipi_load_coreimage(const char *name); int pipi_save_coreimage(pipi_image_t *img, const char *name); #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 - - pipi_image_t *pipi_load_oric(const char *name); int pipi_save_oric(pipi_image_t *img, const char *name);