2.8 branch: This change brings the PNG plugin up to sync with trunk head. It adds the OSG_CPP_EXCEPTIONS_AVAILABLE CMake option and adds PNG plugin compatibility with multiple versions of libPNG. Merged from trunk: 10763 and 11121.

This commit is contained in:
Paul MARTZ
2010-04-01 17:41:08 +00:00
parent 6c08cc5937
commit 01b510865f
6 changed files with 1085 additions and 1057 deletions

View File

@@ -265,6 +265,8 @@ MARK_AS_ADVANCED(OSG_DISABLE_MSVC_WARNINGS)
OPTION(OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION "Set to ON to use the ref_ptr<> T* operator() output conversion. " ON)
OPTION(OSG_CPP_EXCEPTIONS_AVAILABLE "Set to OFF to disable compile of OSG components that use C++ exceptions." ON)
################################################################################
# Set Config file

View File

@@ -57,7 +57,6 @@ IF(DYNAMIC_OPENSCENEGRAPH)
ADD_SUBDIRECTORY(osglogicop)
ADD_SUBDIRECTORY(osglogo)
ADD_SUBDIRECTORY(osgmanipulator)
ADD_SUBDIRECTORY(osgmemorytest)
ADD_SUBDIRECTORY(osgmotionblur)
ADD_SUBDIRECTORY(osgmovie)
ADD_SUBDIRECTORY(osgmultiplerendertargets)
@@ -108,7 +107,6 @@ IF(DYNAMIC_OPENSCENEGRAPH)
ADD_SUBDIRECTORY(osgtexture3D)
ADD_SUBDIRECTORY(osgtexturerectangle)
ADD_SUBDIRECTORY(osgthirdpersonview)
ADD_SUBDIRECTORY(osgunittests)
ADD_SUBDIRECTORY(osgvertexprogram)
ADD_SUBDIRECTORY(osgvolume)
ADD_SUBDIRECTORY(osgwindows)
@@ -136,6 +134,11 @@ IF(DYNAMIC_OPENSCENEGRAPH)
ADD_SUBDIRECTORY(osgwidgettable)
ADD_SUBDIRECTORY(osgwidgetwindow)
IF(OSG_CPP_EXCEPTIONS_AVAILABLE)
ADD_SUBDIRECTORY(osgunittests)
ADD_SUBDIRECTORY(osgmemorytest)
ENDIF()
ADD_SUBDIRECTORY(osgpdf)
IF (BUILD_OSG_WRAPPERS)

File diff suppressed because it is too large Load Diff

View File

@@ -168,7 +168,6 @@ ADD_SUBDIRECTORY(lwo)
ADD_SUBDIRECTORY(bvh)
ADD_SUBDIRECTORY(x)
ADD_SUBDIRECTORY(dw)
ADD_SUBDIRECTORY(ply)
ADD_SUBDIRECTORY(dxf)
ADD_SUBDIRECTORY(OpenFlight)
# ADD_SUBDIRECTORY(flt)
@@ -190,13 +189,17 @@ ADD_SUBDIRECTORY(md2)
ADD_SUBDIRECTORY(osgtgz)
ADD_SUBDIRECTORY(tgz)
ADD_SUBDIRECTORY(txp)
ADD_SUBDIRECTORY(shp)
ADD_SUBDIRECTORY(txf)
ADD_SUBDIRECTORY(bsp)
ADD_SUBDIRECTORY(mdl)
IF(OSG_CPP_EXCEPTIONS_AVAILABLE)
ADD_SUBDIRECTORY(ply)
ADD_SUBDIRECTORY(txp)
ENDIF()
IF(XINE_FOUND)
ADD_SUBDIRECTORY(xine)
ENDIF(XINE_FOUND)

View File

@@ -3,9 +3,14 @@
INCLUDE_DIRECTORIES( ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} )
IF(OSG_CPP_EXCEPTIONS_AVAILABLE)
ADD_DEFINITIONS(-DOSG_CPP_EXCEPTIONS_AVAILABLE)
ENDIF()
SET(TARGET_SRC ReaderWriterPNG.cpp )
SET(TARGET_LIBRARIES_VARS PNG_LIBRARY ZLIB_LIBRARY )
#### end var setup ###
SETUP_PLUGIN(png)

View File

@@ -51,7 +51,11 @@ private:
void user_error_fn(png_structp png_ptr, png_const_charp error_msg)
{
#ifdef OSG_CPP_EXCEPTIONS_AVAILABLE
throw PNGError(error_msg);
#else
osg::notify(osg::WARN) << "PNG lib warning : " << error_msg << std::endl;
#endif
}
void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg)
@@ -166,14 +170,15 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
// Set custom error handlers
png_set_error_fn(png, png_get_error_ptr(png), user_error_fn, user_warning_fn);
#ifdef OSG_CPP_EXCEPTIONS_AVAILABLE
try
#endif
{
info = png_create_info_struct(png);
endinfo = png_create_info_struct(png);
fin.read((char*)header,8);
if (fin.gcount() == 8 && png_check_sig(header, 8))
if (fin.gcount() == 8 && png_sig_cmp(header, 0, 8) == 0)
png_set_read_fn(png,&fin,png_read_istream); //Use custom read function that will get data from istream
else
{
@@ -224,7 +229,14 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
if (color == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png);
if (color == PNG_COLOR_TYPE_GRAY && depth < 8)
{
#if PNG_LIBPNG_VER >= 10209
png_set_expand_gray_1_2_4_to_8(png);
#else
// use older now deprecated but identical call
png_set_gray_1_2_4_to_8(png);
#endif
}
if (png_get_valid(png, info, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png);
@@ -300,13 +312,16 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
osg::Image::USE_NEW_DELETE);
return pOsgImage;
}
#ifdef OSG_CPP_EXCEPTIONS_AVAILABLE
catch (PNGError& err)
{
osg::notify(osg::WARN) << err << std::endl;
png_destroy_read_struct(&png, &info, &endinfo);
return ReadResult::ERROR_IN_READING_FILE;
}
#endif
}
int getCompressionLevel(const osgDB::ReaderWriter::Options *options) const