temporary, though. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3075 92316355-f0b4-4df1-b90c-862c8a59935fremotes/tiles
| @@ -183,7 +183,34 @@ 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") | ||||
| if test "${ac_cv_my_have_il}" = "no" -a "${ac_cv_my_have_ole}" = "no" -a "${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"; then | |||||
| # Use Modular codecs ? | |||||
| MODULAR_CODEC="" | |||||
| ac_cv_my_have_modular="no" | |||||
| ac_cv_my_have_libjpeg="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}]) | |||||
| fi | |||||
| if test "${ac_cv_my_have_il}" = "no" -a "${ac_cv_my_have_ole}" = "no" -a "${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 | |||||
| AC_MSG_ERROR([[cannot find DevIL, OLE, SDL_Image, Imlib2, Cocoa, or OpenCV, please install one of them]]) | AC_MSG_ERROR([[cannot find DevIL, OLE, SDL_Image, Imlib2, Cocoa, or OpenCV, please install one of them]]) | ||||
| fi | fi | ||||
| @@ -122,3 +122,12 @@ codec_objcflags = -I"/Developer//SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Q | |||||
| codec_libs += -framework Cocoa -framework IOKit -framework CoreFoundation -framework QuartzCore | codec_libs += -framework Cocoa -framework IOKit -framework CoreFoundation -framework QuartzCore | ||||
| 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 | |||||
| codec_libs += -ljpeg | |||||
| codec_sources += codec/modular/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_LIBJPEG | |||||
| if(!ret) | |||||
| ret = pipi_load_modular(name); | |||||
| #endif | |||||
| #if USE_IMLIB2 | #if USE_IMLIB2 | ||||
| if(!ret) | if(!ret) | ||||
| ret = pipi_load_imlib2(name); | ret = pipi_load_imlib2(name); | ||||
| @@ -110,7 +114,7 @@ int pipi_save(pipi_image_t *img, const char *name) | |||||
| if(ret < 0) | if(ret < 0) | ||||
| ret = pipi_save_coreimage(img, name); | ret = pipi_save_coreimage(img, name); | ||||
| #endif | #endif | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -0,0 +1,12 @@ | |||||
| #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) | |||||
| { | |||||
| return pipi_save_jpeg(img, name); | |||||
| } | |||||
| @@ -0,0 +1,34 @@ | |||||
| /* | |||||
| * 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); | |||||
| @@ -0,0 +1,132 @@ | |||||
| /* | |||||
| * 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. | |||||
| */ | |||||
| /* | |||||
| * jpeg.c: libjpeg I/O functions | |||||
| */ | |||||
| #include "../modular.h" | |||||
| static int pipi_free_jpeg(pipi_image_t *img); | |||||
| static void format_msg(j_common_ptr cinfo, char *buf) | |||||
| { | |||||
| } | |||||
| static void emit_msg(j_common_ptr cinfo, int level) | |||||
| { | |||||
| } | |||||
| static void error_msg(j_common_ptr cinfo) | |||||
| { | |||||
| cinfo->client_data = (void*)0x1; | |||||
| } | |||||
| static void output_msg(j_common_ptr cinfo) | |||||
| { | |||||
| } | |||||
| pipi_image_t *pipi_load_jpeg(const char *name) | |||||
| { | |||||
| struct jpeg_decompress_struct cinfo; | |||||
| struct jpeg_error_mgr jerr; | |||||
| unsigned char *image = NULL, *scanline = NULL; | |||||
| pipi_image_t *img = NULL; | |||||
| unsigned int i, j, k = 0; | |||||
| FILE *fp = fopen(name, "rb"); | |||||
| if(!fp) goto end; | |||||
| cinfo.err = jpeg_std_error(&jerr); | |||||
| jerr.error_exit = error_msg; | |||||
| jerr.emit_message = emit_msg; | |||||
| jerr.output_message = output_msg; | |||||
| jerr.format_message = format_msg; | |||||
| jpeg_create_decompress(&cinfo); | |||||
| cinfo.client_data = 0x0; | |||||
| jpeg_stdio_src(&cinfo, fp); | |||||
| if((int)cinfo.client_data == 0x1) { | |||||
| goto end; | |||||
| } | |||||
| jpeg_read_header(&cinfo, TRUE); | |||||
| if((int)cinfo.client_data == 0x1) { | |||||
| goto end; | |||||
| } | |||||
| jpeg_start_decompress(&cinfo); | |||||
| if((int)cinfo.client_data == 0x1) { | |||||
| goto end; | |||||
| } | |||||
| image = malloc(cinfo.output_width * cinfo.output_height * 4); | |||||
| if(!image) goto end; | |||||
| scanline = malloc(cinfo.output_width * 3); | |||||
| /* Read scanlines, converting them to RGBA */ | |||||
| for(i=0; i < cinfo.output_height; i++) | |||||
| { | |||||
| jpeg_read_scanlines(&cinfo, &scanline, 1); | |||||
| if((int)cinfo.client_data == 0x1) { | |||||
| free(img); | |||||
| img = NULL; | |||||
| goto end; | |||||
| } | |||||
| for(j=0 ; j<cinfo.output_width*3; j+=3) | |||||
| { | |||||
| image[k+2] = scanline[j]; | |||||
| image[k+1] = scanline[j+1]; | |||||
| image[k] = scanline[j+2]; | |||||
| image[k+3] = 255; | |||||
| k+=4; | |||||
| } | |||||
| } | |||||
| img = pipi_new(cinfo.output_width, cinfo.output_height); | |||||
| img->p[PIPI_PIXELS_RGBA_C].pixels = image; | |||||
| img->p[PIPI_PIXELS_RGBA_C].w = cinfo.output_width; | |||||
| img->p[PIPI_PIXELS_RGBA_C].h = cinfo.output_height; | |||||
| img->p[PIPI_PIXELS_RGBA_C].pitch = cinfo.output_width*4; | |||||
| img->p[PIPI_PIXELS_RGBA_C].bpp = 24; | |||||
| img->p[PIPI_PIXELS_RGBA_C].bytes = 4 * img->w * img->h; | |||||
| img->last_modified = PIPI_PIXELS_RGBA_C; | |||||
| img->codec_priv = (void *)&cinfo; | |||||
| img->codec_format = PIPI_PIXELS_RGBA_C; | |||||
| img->codec_free = pipi_free_jpeg; | |||||
| img->wrap = 0; | |||||
| img->u8 = 1; | |||||
| end: | |||||
| if(fp) fclose(fp); | |||||
| if(scanline) free(scanline); | |||||
| jpeg_destroy_decompress(&cinfo); | |||||
| return img; | |||||
| } | |||||
| int pipi_save_jpeg(pipi_image_t *img, const char *name) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| static int pipi_free_jpeg(pipi_image_t *img) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| @@ -97,6 +97,13 @@ 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); | |||||
| #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); | ||||