From 64753fe42676112b421f9a77e87ee033281ed2a7 Mon Sep 17 00:00:00 2001 From: Chris Laurel Date: Mon, 30 Apr 2001 22:56:25 +0000 Subject: [PATCH] Added PNG support for UNIX. --- config.h.in | 3 ++ configure | 73 +++++++++++++++++++++++++++++++++++++++---------- configure.in | 8 +++--- src/texture.cpp | 24 +++++++++++++++- 4 files changed, 89 insertions(+), 19 deletions(-) diff --git a/config.h.in b/config.h.in index b74259007..a4cfa86cc 100644 --- a/config.h.in +++ b/config.h.in @@ -30,6 +30,9 @@ /* Define if you have the jpeg library (-ljpeg). */ #undef HAVE_LIBJPEG +/* Define if you have the png library (-lpng). */ +#undef HAVE_LIBPNG + /* Name of package */ #undef PACKAGE diff --git a/configure b/configure index 4fc8871ec..6760d964d 100755 --- a/configure +++ b/configure @@ -2509,16 +2509,64 @@ else fi +echo $ac_n "checking for png_create_info_struct in -lpng""... $ac_c" 1>&6 +echo "configure:2514: checking for png_create_info_struct in -lpng" >&5 +ac_lib_var=`echo png'_'png_create_info_struct | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_save_LIBS="$LIBS" +LIBS="-lpng $LIBS" +cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=no" +fi +rm -f conftest* +LIBS="$ac_save_LIBS" + +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_lib=HAVE_LIB`echo png | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + cat >> confdefs.h <&6 +{ echo "configure: error: png library not found" 1>&2; exit 1; } +fi + echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:2517: checking for ANSI C header files" >&5 +echo "configure:2565: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -2526,7 +2574,7 @@ else #include EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:2530: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:2578: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -2543,7 +2591,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -2561,7 +2609,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -2582,7 +2630,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -2593,7 +2641,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:2597: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2645: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then : else @@ -2621,17 +2669,17 @@ for ac_hdr in GL/gl.h GL/glut.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:2625: checking for $ac_hdr" >&5 +echo "configure:2673: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:2635: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:2683: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -3044,10 +3092,7 @@ test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1 echo "$ac_t""" 1>&6 echo "$ac_t""" 1>&6 echo "$ac_t""********************************************************************" 1>&6 -echo "$ac_t""*** Before compiling Celestia take a look at the configuration " 1>&6 -echo "$ac_t""*** file in the conf directory. Default configuration file is tuned " 1>&6 -echo "$ac_t""*** for a GeForce card so if you own a less powerful card you'll " 1>&6 -echo "$ac_t""*** have to edit that file and read carefully " 1>&6 +echo "$ac_t""*** Celestia configuration complete." 1>&6 echo "$ac_t""********************************************************************" 1>&6 echo "$ac_t""" 1>&6 echo "$ac_t""" 1>&6 diff --git a/configure.in b/configure.in index c6bb58d90..96493f926 100644 --- a/configure.in +++ b/configure.in @@ -71,6 +71,9 @@ dnl Check for JPEG library. AC_CHECK_LIB(jpeg, jpeg_start_decompress,, AC_MSG_ERROR(jpeg library not found)) +dnl Check for PNG library. +AC_CHECK_LIB(png, png_create_info_struct,, + AC_MSG_ERROR(png library not found)) dnl Checks for header files. @@ -91,10 +94,7 @@ AC_OUTPUT( Makefile \ AC_MSG_RESULT() AC_MSG_RESULT() AC_MSG_RESULT(********************************************************************) -AC_MSG_RESULT(*** Before compiling Celestia take a look at the configuration ) -AC_MSG_RESULT(*** file in the conf directory. Default configuration file is tuned ) -AC_MSG_RESULT(*** for a GeForce card so if you own a less powerful card you'll ) -AC_MSG_RESULT(*** have to edit that file and read carefully ) +AC_MSG_RESULT(*** Celestia configuration complete.) AC_MSG_RESULT(********************************************************************) AC_MSG_RESULT() AC_MSG_RESULT() diff --git a/src/texture.cpp b/src/texture.cpp index 2a40ee19b..2ac88eabf 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -12,6 +12,7 @@ #define PNG_SUPPORT #else #define IJG_JPEG_SUPPORT +#define PNG_SUPPORT #endif // _WIN32 #include @@ -24,16 +25,31 @@ #include "ijl.h" #endif #ifdef IJG_JPEG_SUPPORT +#ifndef PNG_SUPPORT #include "setjmp.h" +#endif // PNG_SUPPORT extern "C" { #include } #endif + #ifdef PNG_SUPPORT -#include "setjmp.h" #include "png.h" + +// Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng +#ifndef png_jmpbuf +#define png_jmpbuf(png_ptr) png_ptr->jmpbuf #endif +// Define various expansion transformations for old versions of libpng +#if PNG_LIBPNG_VER < 10004 +#define png_set_palette_to_rgb(p) png_set_expand(p) +#define png_set_gray_1_2_4_to_8(p) png_set_expand(p) +#define png_set_tRNS_to_alpha(p) png_set_expand(p) +#endif + +#endif // PNG_SUPPORT + #include "celestia.h" #include "vecmath.h" #include "filetype.h" @@ -712,13 +728,19 @@ CTexture* CreatePNGTexture(const string& filename) // TODO: consider using paletted textures if they're available if (color_type == PNG_COLOR_TYPE_PALETTE) + { png_set_palette_to_rgb(png_ptr); + } if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + { png_set_gray_1_2_4_to_8(png_ptr); + } if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) + { png_set_tRNS_to_alpha(png_ptr); + } // TODO: consider passing textures with < 8 bits/component to // GL without expanding