[Hdrflow-svn] SF.net SVN: hdrflow: [290] trunk/lib/openlibraries/src/openimagelib/plugins /tiff/tif
Status: Pre-Alpha
Brought to you by:
glslang
From: <gl...@us...> - 2007-09-01 20:24:08
|
Revision: 290 http://hdrflow.svn.sourceforge.net/hdrflow/?rev=290&view=rev Author: glslang Date: 2007-09-01 13:24:03 -0700 (Sat, 01 Sep 2007) Log Message: ----------- + make the tiff loader float aware (still misses some encodings) Modified Paths: -------------- trunk/lib/openlibraries/src/openimagelib/plugins/tiff/tiff_plugin.cpp Modified: trunk/lib/openlibraries/src/openimagelib/plugins/tiff/tiff_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/tiff/tiff_plugin.cpp 2007-09-01 16:42:57 UTC (rev 289) +++ trunk/lib/openlibraries/src/openimagelib/plugins/tiff/tiff_plugin.cpp 2007-09-01 20:24:03 UTC (rev 290) @@ -6,7 +6,7 @@ // For more information, see http://www.openlibraries.org. #include <vector> -#include <string> +#include <sstream> #include <tiffio.h> @@ -19,51 +19,67 @@ namespace { - il::image_type_ptr tiff_image_type_to_image_type( unsigned short components, int width, int height ) + il::image_type_ptr tiff_image_type_to_image_type( unsigned short bpp, unsigned short components, int width, int height, bool is_float = false ) { - if( components == 4 ) - return il::allocate( L"r8g8b8a8", width, height ); - else if( components == 3 ) - return il::allocate( L"r8g8b8", width, height ); + std::wstringstream str; + if( components >= 3 ) + { + str << L"r" << bpp << L"g" << bpp << L"b" << bpp; + if( components == 4 ) + str << L"a" << bpp; + } + + if( is_float ) str << L"f"; + + return il::allocate( str.str( ), width, height ); + } + il::image_type_ptr tiff_null_image( TIFF* tif ) + { + TIFFClose( tif ); return il::image_type_ptr( ); } il::image_type_ptr load_tiff( pl::stream_ptr stream ) - { - struct tiff* tif = TIFFOpen( stream->path( ).c_str( ), "r" ); + { + TIFF* tif = TIFFOpen( stream->path( ).c_str( ), "r" ); if( tif == NULL ) return il::image_type_ptr( ); int width, height, depth; - TIFFGetField( tif, TIFFTAG_IMAGEWIDTH, &width ); - TIFFGetField( tif, TIFFTAG_IMAGELENGTH, &height ); - if( !TIFFGetField( tif, TIFFTAG_IMAGEDEPTH, &depth ) ) depth = 1; + TIFFGetFieldDefaulted( tif, TIFFTAG_IMAGEWIDTH, &width ); + TIFFGetFieldDefaulted( tif, TIFFTAG_IMAGELENGTH, &height ); + if( !TIFFGetFieldDefaulted( tif, TIFFTAG_IMAGEDEPTH, &depth ) ) depth = 1; unsigned short config; - TIFFGetField( tif, TIFFTAG_PLANARCONFIG, &config ); + TIFFGetFieldDefaulted( tif, TIFFTAG_PLANARCONFIG, &config ); if( config != PLANARCONFIG_CONTIG ) - { - TIFFClose( tif ); - return il::image_type_ptr( ); - } + return tiff_null_image( tif ); - unsigned short photo; - TIFFGetField( tif, TIFFTAG_PHOTOMETRIC, &photo ); + unsigned short photo, compression, sample_format; + TIFFGetFieldDefaulted( tif, TIFFTAG_PHOTOMETRIC, &photo ); + TIFFGetFieldDefaulted( tif, TIFFTAG_SAMPLEFORMAT, &sample_format ); + TIFFGetFieldDefaulted( tif, TIFFTAG_COMPRESSION, &compression ); - if( config != PHOTOMETRIC_MINISBLACK && photo != PHOTOMETRIC_RGB ) + bool is_float = false; + switch( photo ) { - TIFFClose( tif ); - return il::image_type_ptr( ); + case PHOTOMETRIC_RGB: + if( sample_format == SAMPLEFORMAT_IEEEFP ) + is_float = true; + break; + + default: + return tiff_null_image( tif ); } - + unsigned short bpp, components; - TIFFGetField( tif, TIFFTAG_BITSPERSAMPLE, &bpp ); - TIFFGetField( tif, TIFFTAG_SAMPLESPERPIXEL, &components ); + TIFFGetFieldDefaulted( tif, TIFFTAG_BITSPERSAMPLE, &bpp ); + TIFFGetFieldDefaulted( tif, TIFFTAG_SAMPLESPERPIXEL, &components ); - il::image_type_ptr im = tiff_image_type_to_image_type( components, width, height ); + il::image_type_ptr im = tiff_image_type_to_image_type( bpp, components, width, height, is_float ); if( !im ) return il::image_type_ptr( ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |