From 8c9e23dc0abf44452e0715b3df495eb381d9d252 Mon Sep 17 00:00:00 2001 From: martin-osborne Date: Sun, 22 Mar 2015 09:40:51 +0000 Subject: [PATCH] Added support for screen origin bit of targa files (Ticket 8429) Currently GIL refuses to load TARGA files whose screen origin is in the upper left-hand corner. See Trac ticket 8429 for sample image files created from GIMP 2. --- .../boost/gil/extension/io/formats/targa/read.hpp | 36 +++++++++++++++++++--- .../extension/io/formats/targa/reader_backend.hpp | 6 ++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/include/boost/gil/extension/io/formats/targa/read.hpp b/include/boost/gil/extension/io/formats/targa/read.hpp index 95da2a1a..e8a3f39c 100644 --- a/include/boost/gil/extension/io/formats/targa/read.hpp +++ b/include/boost/gil/extension/io/formats/targa/read.hpp @@ -127,7 +127,14 @@ class reader< Device { this->_scanline_length = this->_info._width * ( this->_info._bits_per_pixel / 8 ); - read_data< bgr8_view_t >( dst_view ); + if( this->_info._descriptor & 0x20 ) + { + read_data< bgr8_view_t >( flipped_up_down_view( dst_view ) ); + } + else + { + read_data< bgr8_view_t >( dst_view ); + } break; } @@ -135,7 +142,14 @@ class reader< Device { this->_scanline_length = this->_info._width * ( this->_info._bits_per_pixel / 8 ); - read_data< bgra8_view_t >( dst_view ); + if( this->_info._descriptor & 0x20 ) + { + read_data< bgra8_view_t >( flipped_up_down_view( dst_view ) ); + } + else + { + read_data< bgra8_view_t >( dst_view ); + } break; } @@ -164,12 +178,26 @@ class reader< Device { case 24: { - read_rle_data< bgr8_view_t >( dst_view ); + if( this->_info._descriptor & 0x20 ) + { + read_rle_data< bgr8_view_t >( flipped_up_down_view( dst_view ) ); + } + else + { + read_rle_data< bgr8_view_t >( dst_view ); + } break; } case 32: { - read_rle_data< bgra8_view_t >( dst_view ); + if( this->_info._descriptor & 0x20 ) + { + read_rle_data< bgra8_view_t >( flipped_up_down_view( dst_view ) ); + } + else + { + read_rle_data< bgra8_view_t >( dst_view ); + } break; } default: diff --git a/include/boost/gil/extension/io/formats/targa/reader_backend.hpp b/include/boost/gil/extension/io/formats/targa/reader_backend.hpp index 67130666..e5d4493d 100644 --- a/include/boost/gil/extension/io/formats/targa/reader_backend.hpp +++ b/include/boost/gil/extension/io/formats/targa/reader_backend.hpp @@ -94,8 +94,10 @@ struct reader_backend< Device } _info._descriptor = _io_dev.read_uint8(); - if( ( _info._bits_per_pixel == 24 && _info._descriptor != 0 ) - || ( _info._bits_per_pixel == 32 && _info._descriptor != 8 ) + targa_descriptor::type pixel_type = _info._descriptor & 0xdf; + + if( ( _info._bits_per_pixel == 24 && pixel_type != 0 ) + || ( _info._bits_per_pixel == 32 && pixel_type != 8 ) ) { io_error( "Unsupported descriptor for targa file" );