Thread: [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. |
From: <gl...@us...> - 2007-09-29 20:54:23
|
Revision: 321 http://hdrflow.svn.sourceforge.net/hdrflow/?rev=321&view=rev Author: glslang Date: 2007-09-29 13:54:22 -0700 (Sat, 29 Sep 2007) Log Message: ----------- + fixes tiff reader (strips != 1) 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-29 12:49:48 UTC (rev 320) +++ trunk/lib/openlibraries/src/openimagelib/plugins/tiff/tiff_plugin.cpp 2007-09-29 20:54:22 UTC (rev 321) @@ -85,9 +85,6 @@ if( !im ) return il::image_type_ptr( ); - if( orientation == ORIENTATION_TOPLEFT ) - im->set_flipped( true ); - il::image_type::pointer data = im->data( ); int bytes_per_pixel = components * bpp / 8; @@ -126,14 +123,29 @@ if( is_float ) pitch *= sizeof( float ); - unsigned int rows; + unsigned int rows, strip_size; TIFFGetField( tif, TIFFTAG_ROWSPERSTRIP, &rows ); + strip_size = TIFFStripSize( tif ); + + typedef std::vector<unsigned char> buffer_t; + buffer_t buf( strip_size ); + + int linesize = strip_size / rows; + + tstrip_t nstrips = TIFFNumberOfStrips( tif ); + for( tstrip_t i = 0; i < nstrips; ++i ) + { + TIFFReadEncodedStrip( tif, i, &buf[ 0 ], strip_size ); + + buffer_t::pointer buf_data = &buf[ 0 ]; + + for( unsigned int j = 0; j < rows; ++j ) + { + memcpy( data, buf_data, linesize ); - unsigned int strip_size = TIFFStripSize( tif ); - for( int i = 0; i < height * depth; i += rows ) - { - tstrip_t strip = TIFFComputeStrip( tif, i, 0 ); - TIFFReadEncodedStrip( tif, strip, data + i * pitch, strip_size ); + buf_data += linesize; + data += pitch; + } } } @@ -149,7 +161,7 @@ virtual il::image_type_ptr load( const pl::string& uri ) { return load_tiff( uri ); } - virtual bool store( const pl::string& uri, il::image_type_ptr ) + virtual bool store( const pl::string&, il::image_type_ptr ) { return false; } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |