Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3086 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Dec 4, 2004, 6:05:54 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/images: ability to readIn jpg-files

Location:
orxonox/branches/images
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/images/config.h.in

    r3084 r3086  
    1212/* Define to 1 if you have the <inttypes.h> header file. */
    1313#undef HAVE_INTTYPES_H
     14
     15/* Define to 1 if you have the <jpeglib.h> header file. */
     16#undef HAVE_JPEGLIB_H
    1417
    1518/* Define to 1 if you have the `m' library (-lm). */
  • orxonox/branches/images/configure

    r3084 r3086  
    57975797
    57985798
    5799 
     5799## checking for libjpeg
     5800
     5801for ac_header in jpeglib.h
     5802do
     5803as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
     5804if eval "test \"\${$as_ac_Header+set}\" = set"; then
     5805  echo "$as_me:$LINENO: checking for $ac_header" >&5
     5806echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
     5807if eval "test \"\${$as_ac_Header+set}\" = set"; then
     5808  echo $ECHO_N "(cached) $ECHO_C" >&6
     5809fi
     5810echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
     5811echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
     5812else
     5813  # Is the header compilable?
     5814echo "$as_me:$LINENO: checking $ac_header usability" >&5
     5815echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
     5816cat >conftest.$ac_ext <<_ACEOF
     5817/* confdefs.h.  */
     5818_ACEOF
     5819cat confdefs.h >>conftest.$ac_ext
     5820cat >>conftest.$ac_ext <<_ACEOF
     5821/* end confdefs.h.  */
     5822$ac_includes_default
     5823#include <$ac_header>
     5824_ACEOF
     5825rm -f conftest.$ac_objext
     5826if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
     5827  (eval $ac_compile) 2>conftest.er1
     5828  ac_status=$?
     5829  grep -v '^ *+' conftest.er1 >conftest.err
     5830  rm -f conftest.er1
     5831  cat conftest.err >&5
     5832  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5833  (exit $ac_status); } &&
     5834         { ac_try='test -z "$ac_c_werror_flag"
     5835                         || test ! -s conftest.err'
     5836  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5837  (eval $ac_try) 2>&5
     5838  ac_status=$?
     5839  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5840  (exit $ac_status); }; } &&
     5841         { ac_try='test -s conftest.$ac_objext'
     5842  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5843  (eval $ac_try) 2>&5
     5844  ac_status=$?
     5845  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5846  (exit $ac_status); }; }; then
     5847  ac_header_compiler=yes
     5848else
     5849  echo "$as_me: failed program was:" >&5
     5850sed 's/^/| /' conftest.$ac_ext >&5
     5851
     5852ac_header_compiler=no
     5853fi
     5854rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
     5855echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
     5856echo "${ECHO_T}$ac_header_compiler" >&6
     5857
     5858# Is the header present?
     5859echo "$as_me:$LINENO: checking $ac_header presence" >&5
     5860echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
     5861cat >conftest.$ac_ext <<_ACEOF
     5862/* confdefs.h.  */
     5863_ACEOF
     5864cat confdefs.h >>conftest.$ac_ext
     5865cat >>conftest.$ac_ext <<_ACEOF
     5866/* end confdefs.h.  */
     5867#include <$ac_header>
     5868_ACEOF
     5869if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
     5870  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
     5871  ac_status=$?
     5872  grep -v '^ *+' conftest.er1 >conftest.err
     5873  rm -f conftest.er1
     5874  cat conftest.err >&5
     5875  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5876  (exit $ac_status); } >/dev/null; then
     5877  if test -s conftest.err; then
     5878    ac_cpp_err=$ac_c_preproc_warn_flag
     5879    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
     5880  else
     5881    ac_cpp_err=
     5882  fi
     5883else
     5884  ac_cpp_err=yes
     5885fi
     5886if test -z "$ac_cpp_err"; then
     5887  ac_header_preproc=yes
     5888else
     5889  echo "$as_me: failed program was:" >&5
     5890sed 's/^/| /' conftest.$ac_ext >&5
     5891
     5892  ac_header_preproc=no
     5893fi
     5894rm -f conftest.err conftest.$ac_ext
     5895echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
     5896echo "${ECHO_T}$ac_header_preproc" >&6
     5897
     5898# So?  What about this header?
     5899case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
     5900  yes:no: )
     5901    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
     5902echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
     5903    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
     5904echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
     5905    ac_header_preproc=yes
     5906    ;;
     5907  no:yes:* )
     5908    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
     5909echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
     5910    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
     5911echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
     5912    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
     5913echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
     5914    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
     5915echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
     5916    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
     5917echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
     5918    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
     5919echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
     5920    (
     5921      cat <<\_ASBOX
     5922## ------------------------------------------- ##
     5923## Report this to orxonox-dev@mail.datacore.ch ##
     5924## ------------------------------------------- ##
     5925_ASBOX
     5926    ) |
     5927      sed "s/^/$as_me: WARNING:     /" >&2
     5928    ;;
     5929esac
     5930echo "$as_me:$LINENO: checking for $ac_header" >&5
     5931echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
     5932if eval "test \"\${$as_ac_Header+set}\" = set"; then
     5933  echo $ECHO_N "(cached) $ECHO_C" >&6
     5934else
     5935  eval "$as_ac_Header=\$ac_header_preproc"
     5936fi
     5937echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
     5938echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
     5939
     5940fi
     5941if test `eval echo '${'$as_ac_Header'}'` = yes; then
     5942  cat >>confdefs.h <<_ACEOF
     5943#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
     5944_ACEOF
     5945
     5946else
     5947  { { echo "$as_me:$LINENO: error: cannot find jpeg headers" >&5
     5948echo "$as_me: error: cannot find jpeg headers" >&2;}
     5949   { (exit 1); exit 1; }; }
     5950fi
     5951
     5952done
     5953
     5954
     5955echo "$as_me:$LINENO: checking for main in -ljpeg" >&5
     5956echo $ECHO_N "checking for main in -ljpeg... $ECHO_C" >&6
     5957if test "${ac_cv_lib_jpeg_main+set}" = set; then
     5958  echo $ECHO_N "(cached) $ECHO_C" >&6
     5959else
     5960  ac_check_lib_save_LIBS=$LIBS
     5961LIBS="-ljpeg  $LIBS"
     5962cat >conftest.$ac_ext <<_ACEOF
     5963/* confdefs.h.  */
     5964_ACEOF
     5965cat confdefs.h >>conftest.$ac_ext
     5966cat >>conftest.$ac_ext <<_ACEOF
     5967/* end confdefs.h.  */
     5968
     5969
     5970int
     5971main ()
     5972{
     5973main ();
     5974  ;
     5975  return 0;
     5976}
     5977_ACEOF
     5978rm -f conftest.$ac_objext conftest$ac_exeext
     5979if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
     5980  (eval $ac_link) 2>conftest.er1
     5981  ac_status=$?
     5982  grep -v '^ *+' conftest.er1 >conftest.err
     5983  rm -f conftest.er1
     5984  cat conftest.err >&5
     5985  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5986  (exit $ac_status); } &&
     5987         { ac_try='test -z "$ac_c_werror_flag"
     5988                         || test ! -s conftest.err'
     5989  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5990  (eval $ac_try) 2>&5
     5991  ac_status=$?
     5992  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5993  (exit $ac_status); }; } &&
     5994         { ac_try='test -s conftest$ac_exeext'
     5995  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5996  (eval $ac_try) 2>&5
     5997  ac_status=$?
     5998  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5999  (exit $ac_status); }; }; then
     6000  ac_cv_lib_jpeg_main=yes
     6001else
     6002  echo "$as_me: failed program was:" >&5
     6003sed 's/^/| /' conftest.$ac_ext >&5
     6004
     6005ac_cv_lib_jpeg_main=no
     6006fi
     6007rm -f conftest.err conftest.$ac_objext \
     6008      conftest$ac_exeext conftest.$ac_ext
     6009LIBS=$ac_check_lib_save_LIBS
     6010fi
     6011echo "$as_me:$LINENO: result: $ac_cv_lib_jpeg_main" >&5
     6012echo "${ECHO_T}$ac_cv_lib_jpeg_main" >&6
     6013if test $ac_cv_lib_jpeg_main = yes; then
     6014  FOUND_jpeg=yes
     6015fi
     6016
     6017    if test "$FOUND_jpeg" = "yes" ; then
     6018      LIBS="$LIBS -ljpeg"
     6019    else
     6020         echo "------------------"
     6021         echo "jpeg library not found."
     6022         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
    58006026
    58016027
  • orxonox/branches/images/configure.ac

    r3084 r3086  
    203203AC_SUBST(MSBITFIELDS)
    204204
    205 
     205## checking for libjpeg
     206AC_CHECK_HEADERS(jpeglib.h ,,
     207        [AC_MSG_ERROR([cannot find jpeg headers]) ])
     208
     209AC_CHECK_LIB([jpeg], [main], FOUND_jpeg=yes)
     210    if test "$FOUND_jpeg" = "yes" ; then
     211      LIBS="$LIBS -ljpeg"
     212    else
     213         echo "------------------"
     214         echo "jpeg library not found."
     215         echo "please install the jpeg library from the Independent JPEG Group, which can be found at http://www.ijg.org"
     216         echo "------------------"
     217         exit -1
     218    fi   
    206219
    207220
  • orxonox/branches/images/console/Makefile.in

    r2991 r3086  
    425425
    426426
    427 #  uncomment the following if bencoder requires the math library
     427#  uncomment the following if orxonox requires the math library
    428428#gui_LDADD=-lm
    429429
  • orxonox/branches/images/gui/Makefile.in

    r2991 r3086  
    178178noinst_HEADERS = orxonox_gui.h orxonox_gui_video.h orxonox_gui_audio.h orxonox_gui_exec.h orxonox_gui_flags.h orxonox_gui_banner.h orxonox_gui_keys.h
    179179
    180 #  uncomment the following if bencoder requires the math library
     180#  uncomment the following if orxonox requires the math library
    181181#gui_LDADD=-lm
    182182
  • orxonox/branches/images/importer/material.cc

    r3085 r3086  
    319319    printf ("setting Diffuse Map %s\n", dMap);
    320320
    321   diffuseTextureSet = loadBMP(dMap, &diffuseTexture);
     321  //  diffuseTextureSet = loadBMP(dMap, &diffuseTexture);
     322  diffuseTextureSet = loadJPG(dMap, &diffuseTexture);
    322323
    323324}
     
    384385}
    385386
    386 
    387 
    388 
     387bool Material::loadJPG (char* jpgName, GLuint* texture)
     388{
     389  struct jpeg_decompress_struct cinfo;
     390  tImageJPG *pImage = NULL;
     391  FILE *pFile;
     392 
     393  // Open a file pointer to the jpeg file and check if it was found and opened
     394  if((pFile = fopen(jpgName, "rb")) == NULL)
     395    {
     396      // Display an error message saying the file was not found, then return NULL
     397      printf("Unable to load JPG File %s.\n", jpgName);
     398      return false;
     399    }
     400 
     401  // Create an error handler
     402  jpeg_error_mgr jerr;
     403 
     404  // Have our compression info object point to the error handler address
     405  cinfo.err = jpeg_std_error(&jerr);
     406 
     407  // Initialize the decompression object
     408  jpeg_create_decompress(&cinfo);
     409 
     410  // Specify the data source (Our file pointer)
     411  jpeg_stdio_src(&cinfo, pFile);
     412 
     413  // Allocate the structure that will hold our eventual jpeg data (must free it!)
     414  pImage = (tImageJPG*)malloc(sizeof(tImageJPG));
     415 
     416  // Decode the jpeg file and fill in the image data structure to pass back
     417  decodeJPG(&cinfo, pImage);
     418 
     419  // This releases all the stored memory for reading and decoding the jpeg
     420  jpeg_destroy_decompress(&cinfo);
     421 
     422  // Close the file pointer that opened the file
     423  fclose(pFile);
     424 
     425
     426  if(pImage == NULL)                                                                    // If we can't load the file, quit!
     427    exit(0);
     428
     429  // Generate a texture with the associative texture ID stored in the array
     430  glGenTextures(1, texture);
     431 
     432  // Bind the texture to the texture arrays index and init the texture
     433  glBindTexture(GL_TEXTURE_2D, *texture);
     434 
     435  // Build Mipmaps (builds different versions of the picture for distances - looks better)
     436  gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pImage->sizeX, pImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);
     437 
     438  // Lastly, we need to tell OpenGL the quality of our texture map.  GL_LINEAR_MIPMAP_LINEAR
     439  // is the smoothest.  GL_LINEAR_MIPMAP_NEAREST is faster than GL_LINEAR_MIPMAP_LINEAR,
     440  // but looks blochy and pixilated.  Good for slower computers though.
     441 
     442  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
     443  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
     444 
     445
     446  // Now we need to free the image data that we loaded since OpenGL stored it as a texture
     447 
     448  if (pImage)                                                                           // If we loaded the image
     449    {
     450      if (pImage->data)                                                 // If there is texture data
     451        {
     452          free(pImage->data);                                           // Free the texture data, we don't need it anymore
     453        }
     454     
     455      free(pImage);                                                             // Free the image structure
     456    }
     457
     458}
     459
     460void Material::decodeJPG(jpeg_decompress_struct* cinfo, tImageJPG *pImageData)
     461{
     462  // Read in the header of the jpeg file
     463  jpeg_read_header(cinfo, TRUE);
     464 
     465  // Start to decompress the jpeg file with our compression info
     466  jpeg_start_decompress(cinfo);
     467 
     468  // Get the image dimensions and row span to read in the pixel data
     469  pImageData->rowSpan = cinfo->image_width * cinfo->num_components;
     470  pImageData->sizeX   = cinfo->image_width;
     471  pImageData->sizeY   = cinfo->image_height;
     472 
     473  // Allocate memory for the pixel buffer
     474  pImageData->data = new unsigned char[pImageData->rowSpan * pImageData->sizeY];
     475 
     476  // Here we use the library's state variable cinfo.output_scanline as the
     477  // loop counter, so that we don't have to keep track ourselves.
     478 
     479  // Create an array of row pointers
     480  unsigned char** rowPtr = new unsigned char*[pImageData->sizeY];
     481  for (int i = 0; i < pImageData->sizeY; i++)
     482    rowPtr[i] = &(pImageData->data[i*pImageData->rowSpan]);
     483 
     484  // Now comes the juice of our work, here we extract all the pixel data
     485  int rowsRead = 0;
     486  while (cinfo->output_scanline < cinfo->output_height)
     487    {
     488      // Read in the current row of pixels and increase the rowsRead count
     489      rowsRead += jpeg_read_scanlines(cinfo, &rowPtr[rowsRead], cinfo->output_height - rowsRead);
     490    }
     491 
     492  // Delete the temporary row pointers
     493  delete [] rowPtr;
     494 
     495  // Finish decompressing the data
     496  jpeg_finish_decompress(cinfo);
     497}
     498
  • orxonox/branches/images/importer/material.h

    r3085 r3086  
    1616
    1717// IMAGE LIBS //
     18extern "C"{         // This has to be done, because not a c++ lib
    1819#include <jpeglib.h>
    19 
     20}
    2021//! Class to handle Materials.
    2122class Material
     
    6364  void setBump(char* bump);
    6465
    65   // TEXTURING
    66   bool loadBMP (char* bmpName, GLuint* texture);
    6766
    6867 private:
     68  struct tImageJPG
     69  {
     70    int rowSpan;
     71    int sizeX;
     72    int sizeY;
     73    unsigned char *data;
     74  };
     75
     76
    6977  char* name;
    7078  int illumModel;
     
    7684  Material* nextMat; //!< pointer to the Next Material of the List. NULL if no next exists.
    7785
     86  // TEXTURING
     87  bool loadBMP (char* bmpName, GLuint* texture);
     88  bool loadJPG (char* jpgName, GLuint* texture);
     89  void decodeJPG(jpeg_decompress_struct* cinfo, tImageJPG *pImageData);
    7890};
    7991#endif
Note: See TracChangeset for help on using the changeset viewer.