Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3098 in orxonox.OLD


Ignore:
Timestamp:
Dec 5, 2004, 4:05:57 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/images: libPNG included, and also a routine to read it, but this one is not the best i Could find.

Location:
orxonox/branches/images
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/images/configure

    r3086 r3098  
    60216021         echo "jpeg library not found."
    60226022         echo "please install the jpeg library from the Independent JPEG Group, which can be found at http://www.ijg.org"
     6023         echo "------------------"
     6024         exit -1
     6025    fi
     6026
     6027
     6028## checking for libpng
     6029
     6030for ac_header in png.h
     6031do
     6032as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
     6033if eval "test \"\${$as_ac_Header+set}\" = set"; then
     6034  echo "$as_me:$LINENO: checking for $ac_header" >&5
     6035echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
     6036if eval "test \"\${$as_ac_Header+set}\" = set"; then
     6037  echo $ECHO_N "(cached) $ECHO_C" >&6
     6038fi
     6039echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
     6040echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
     6041else
     6042  # Is the header compilable?
     6043echo "$as_me:$LINENO: checking $ac_header usability" >&5
     6044echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
     6045cat >conftest.$ac_ext <<_ACEOF
     6046/* confdefs.h.  */
     6047_ACEOF
     6048cat confdefs.h >>conftest.$ac_ext
     6049cat >>conftest.$ac_ext <<_ACEOF
     6050/* end confdefs.h.  */
     6051$ac_includes_default
     6052#include <$ac_header>
     6053_ACEOF
     6054rm -f conftest.$ac_objext
     6055if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
     6056  (eval $ac_compile) 2>conftest.er1
     6057  ac_status=$?
     6058  grep -v '^ *+' conftest.er1 >conftest.err
     6059  rm -f conftest.er1
     6060  cat conftest.err >&5
     6061  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     6062  (exit $ac_status); } &&
     6063         { ac_try='test -z "$ac_c_werror_flag"
     6064                         || test ! -s conftest.err'
     6065  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     6066  (eval $ac_try) 2>&5
     6067  ac_status=$?
     6068  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     6069  (exit $ac_status); }; } &&
     6070         { ac_try='test -s conftest.$ac_objext'
     6071  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     6072  (eval $ac_try) 2>&5
     6073  ac_status=$?
     6074  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     6075  (exit $ac_status); }; }; then
     6076  ac_header_compiler=yes
     6077else
     6078  echo "$as_me: failed program was:" >&5
     6079sed 's/^/| /' conftest.$ac_ext >&5
     6080
     6081ac_header_compiler=no
     6082fi
     6083rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
     6084echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
     6085echo "${ECHO_T}$ac_header_compiler" >&6
     6086
     6087# Is the header present?
     6088echo "$as_me:$LINENO: checking $ac_header presence" >&5
     6089echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
     6090cat >conftest.$ac_ext <<_ACEOF
     6091/* confdefs.h.  */
     6092_ACEOF
     6093cat confdefs.h >>conftest.$ac_ext
     6094cat >>conftest.$ac_ext <<_ACEOF
     6095/* end confdefs.h.  */
     6096#include <$ac_header>
     6097_ACEOF
     6098if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
     6099  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
     6100  ac_status=$?
     6101  grep -v '^ *+' conftest.er1 >conftest.err
     6102  rm -f conftest.er1
     6103  cat conftest.err >&5
     6104  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     6105  (exit $ac_status); } >/dev/null; then
     6106  if test -s conftest.err; then
     6107    ac_cpp_err=$ac_c_preproc_warn_flag
     6108    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
     6109  else
     6110    ac_cpp_err=
     6111  fi
     6112else
     6113  ac_cpp_err=yes
     6114fi
     6115if test -z "$ac_cpp_err"; then
     6116  ac_header_preproc=yes
     6117else
     6118  echo "$as_me: failed program was:" >&5
     6119sed 's/^/| /' conftest.$ac_ext >&5
     6120
     6121  ac_header_preproc=no
     6122fi
     6123rm -f conftest.err conftest.$ac_ext
     6124echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
     6125echo "${ECHO_T}$ac_header_preproc" >&6
     6126
     6127# So?  What about this header?
     6128case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
     6129  yes:no: )
     6130    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
     6131echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
     6132    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
     6133echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
     6134    ac_header_preproc=yes
     6135    ;;
     6136  no:yes:* )
     6137    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
     6138echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
     6139    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
     6140echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
     6141    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
     6142echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
     6143    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
     6144echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
     6145    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
     6146echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
     6147    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
     6148echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
     6149    (
     6150      cat <<\_ASBOX
     6151## ------------------------------------------- ##
     6152## Report this to orxonox-dev@mail.datacore.ch ##
     6153## ------------------------------------------- ##
     6154_ASBOX
     6155    ) |
     6156      sed "s/^/$as_me: WARNING:     /" >&2
     6157    ;;
     6158esac
     6159echo "$as_me:$LINENO: checking for $ac_header" >&5
     6160echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
     6161if eval "test \"\${$as_ac_Header+set}\" = set"; then
     6162  echo $ECHO_N "(cached) $ECHO_C" >&6
     6163else
     6164  eval "$as_ac_Header=\$ac_header_preproc"
     6165fi
     6166echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
     6167echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
     6168
     6169fi
     6170if test `eval echo '${'$as_ac_Header'}'` = yes; then
     6171  cat >>confdefs.h <<_ACEOF
     6172#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
     6173_ACEOF
     6174
     6175else
     6176  { { echo "$as_me:$LINENO: error: cannot find jpeg headers" >&5
     6177echo "$as_me: error: cannot find jpeg headers" >&2;}
     6178   { (exit 1); exit 1; }; }
     6179fi
     6180
     6181done
     6182
     6183
     6184echo "$as_me:$LINENO: checking for main in -lpng" >&5
     6185echo $ECHO_N "checking for main in -lpng... $ECHO_C" >&6
     6186if test "${ac_cv_lib_png_main+set}" = set; then
     6187  echo $ECHO_N "(cached) $ECHO_C" >&6
     6188else
     6189  ac_check_lib_save_LIBS=$LIBS
     6190LIBS="-lpng  $LIBS"
     6191cat >conftest.$ac_ext <<_ACEOF
     6192/* confdefs.h.  */
     6193_ACEOF
     6194cat confdefs.h >>conftest.$ac_ext
     6195cat >>conftest.$ac_ext <<_ACEOF
     6196/* end confdefs.h.  */
     6197
     6198
     6199int
     6200main ()
     6201{
     6202main ();
     6203  ;
     6204  return 0;
     6205}
     6206_ACEOF
     6207rm -f conftest.$ac_objext conftest$ac_exeext
     6208if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
     6209  (eval $ac_link) 2>conftest.er1
     6210  ac_status=$?
     6211  grep -v '^ *+' conftest.er1 >conftest.err
     6212  rm -f conftest.er1
     6213  cat conftest.err >&5
     6214  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     6215  (exit $ac_status); } &&
     6216         { ac_try='test -z "$ac_c_werror_flag"
     6217                         || test ! -s conftest.err'
     6218  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     6219  (eval $ac_try) 2>&5
     6220  ac_status=$?
     6221  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     6222  (exit $ac_status); }; } &&
     6223         { ac_try='test -s conftest$ac_exeext'
     6224  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     6225  (eval $ac_try) 2>&5
     6226  ac_status=$?
     6227  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     6228  (exit $ac_status); }; }; then
     6229  ac_cv_lib_png_main=yes
     6230else
     6231  echo "$as_me: failed program was:" >&5
     6232sed 's/^/| /' conftest.$ac_ext >&5
     6233
     6234ac_cv_lib_png_main=no
     6235fi
     6236rm -f conftest.err conftest.$ac_objext \
     6237      conftest$ac_exeext conftest.$ac_ext
     6238LIBS=$ac_check_lib_save_LIBS
     6239fi
     6240echo "$as_me:$LINENO: result: $ac_cv_lib_png_main" >&5
     6241echo "${ECHO_T}$ac_cv_lib_png_main" >&6
     6242if test $ac_cv_lib_png_main = yes; then
     6243  FOUND_png=yes
     6244fi
     6245
     6246    if test "$FOUND_png" = "yes" ; then
     6247      LIBS="$LIBS -lpng"
     6248    else
     6249         echo "------------------"
     6250         echo "png library not found."
     6251         echo "please install the png library, which can be found at http://libpng.org/pub/png/libpng.html"
    60236252         echo "------------------"
    60246253         exit -1
  • orxonox/branches/images/configure.ac

    r3086 r3098  
    219219
    220220
     221## checking for libpng
     222AC_CHECK_HEADERS(png.h ,,
     223        [AC_MSG_ERROR([cannot find jpeg headers]) ])
     224
     225AC_CHECK_LIB([png], [main], FOUND_png=yes)
     226    if test "$FOUND_png" = "yes" ; then
     227      LIBS="$LIBS -lpng"
     228    else
     229         echo "------------------"
     230         echo "png library not found."
     231         echo "please install the png library, which can be found at http://libpng.org/pub/png/libpng.html"
     232         echo "------------------"
     233         exit -1
     234    fi   
     235
     236
    221237## checking for GTK
    222238PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.0.3 gthread-2.0 >= 2.0.3, have_gtk2=yes, have_gtk2=no)
  • orxonox/branches/images/importer/material.cc

    r3097 r3098  
    1717
    1818#include "material.h"
     19
    1920
    2021/**
     
    401402        printf ("Requested tga-image. Trying to Import\n");
    402403      return loadTGA(imageName, texture);
     404    }
     405  else if (!strncmp(imageName+strlen(imageName)-4, ".png", 4))
     406    {
     407      if (verbose >=2)
     408        printf ("Requested png-image. Trying to Import\n");
     409      return loadPNG(imageName, texture);
    403410    }
    404411  else
     
    933940}
    934941
     942
     943/*
     944static int ST_is_power_of_two(unsigned int number)
     945{
     946  return (number & (number - 1)) == 0;
     947}
     948*/
     949
     950/**
     951   \brief reads in a png-file
     952   \param pngName the Name of the Image to load
     953   \param texture a reference to the Texture to write the image to
     954*/
     955bool Material::loadPNG(const char* pngName, GLuint* texture)
     956{
     957  Image* pImage = new Image;
     958
     959  FILE *PNG_file = fopen(pngName, "rb");
     960  if (PNG_file == NULL)
     961    {
     962      return 0;
     963    }
     964 
     965  GLubyte PNG_header[8];
     966 
     967  fread(PNG_header, 1, 8, PNG_file);
     968  if (png_sig_cmp(PNG_header, 0, 8) != 0)
     969    {
     970      if (verbose >=2)
     971        printf ("Not Recognized as a pngFile\n");
     972      fclose (PNG_file);
     973      return 0;
     974    }
     975 
     976  png_structp PNG_reader = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
     977  if (PNG_reader == NULL)
     978    {
     979      fclose(PNG_file);
     980      return 0;
     981    }
     982 
     983  png_infop PNG_info = png_create_info_struct(PNG_reader);
     984  if (PNG_info == NULL)
     985    {
     986      png_destroy_read_struct(&PNG_reader, NULL, NULL);
     987      fclose(PNG_file);
     988      return 0;
     989    }
     990 
     991  png_infop PNG_end_info = png_create_info_struct(PNG_reader);
     992  if (PNG_end_info == NULL)
     993    {
     994      png_destroy_read_struct(&PNG_reader, &PNG_info, NULL);
     995      fclose(PNG_file);
     996      return 0;
     997    }
     998 
     999  if (setjmp(png_jmpbuf(PNG_reader)))
     1000    {
     1001      png_destroy_read_struct(&PNG_reader, &PNG_info, &PNG_end_info);
     1002      fclose(PNG_file);
     1003      return (0);
     1004    }
     1005 
     1006  png_init_io(PNG_reader, PNG_file);
     1007  png_set_sig_bytes(PNG_reader, 8);
     1008 
     1009  png_read_info(PNG_reader, PNG_info);
     1010 
     1011  pImage->width = png_get_image_width(PNG_reader, PNG_info);
     1012  pImage->height = png_get_image_height(PNG_reader, PNG_info);
     1013 
     1014  png_uint_32 bit_depth, color_type;
     1015  bit_depth = png_get_bit_depth(PNG_reader, PNG_info);
     1016  color_type = png_get_color_type(PNG_reader, PNG_info);
     1017 
     1018  if (color_type == PNG_COLOR_TYPE_PALETTE)
     1019    {
     1020      png_set_palette_to_rgb(PNG_reader);
     1021    }
     1022 
     1023  if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
     1024    {
     1025      png_set_gray_1_2_4_to_8(PNG_reader);
     1026    }
     1027 
     1028  if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
     1029    {
     1030      png_set_gray_to_rgb(PNG_reader);
     1031    }
     1032 
     1033  if (png_get_valid(PNG_reader, PNG_info, PNG_INFO_tRNS))
     1034    {
     1035      png_set_tRNS_to_alpha(PNG_reader);
     1036    }
     1037  else
     1038    {
     1039      png_set_filler(PNG_reader, 0xff, PNG_FILLER_AFTER);
     1040    }
     1041 
     1042  if (bit_depth == 16)
     1043    {
     1044      png_set_strip_16(PNG_reader);
     1045    }
     1046 
     1047  png_read_update_info(PNG_reader, PNG_info);
     1048 
     1049  pImage->data = (png_byte*)malloc(4 * pImage->width * pImage->height);
     1050  png_byte** PNG_rows = (png_byte**)malloc(pImage->height * sizeof(png_byte*));
     1051 
     1052  unsigned int row;
     1053  for (row = 0; row < pImage->height; ++row)
     1054    {
     1055      PNG_rows[pImage->height - 1 - row] = pImage->data + (row * 4 * pImage->width);
     1056    }
     1057 
     1058  png_read_image(PNG_reader, PNG_rows);
     1059 
     1060  free(PNG_rows);
     1061 
     1062  png_destroy_read_struct(&PNG_reader, &PNG_info, &PNG_end_info);
     1063  fclose(PNG_file);
     1064 
     1065  /*  if (!ST_is_power_of_two(pImage->width) || !ST_is_power_of_two(pImage->height))
     1066    {
     1067      free(pImage->data);
     1068      return 0;
     1069    }
     1070  */
     1071  loadTexToGL (pImage, texture); 
     1072 
     1073  free(pImage->data);
     1074 
     1075  return true;
     1076}
  • orxonox/branches/images/importer/material.h

    r3096 r3098  
    1919#include <jpeglib.h>
    2020}
     21#include <png.h>
    2122//! Class to handle Materials.
    2223class Material
     
    102103  bool loadCompressedTGA(const char * filename, FILE * fTGA, GLuint* texture);
    103104
     105  bool loadPNG(const char* pngName, GLuint* texture);
    104106};
    105107#endif
Note: See TracChangeset for help on using the changeset viewer.