From: SiPlus Date: Thu, 2 Jul 2015 12:20:51 +0000 (+0300) Subject: Add grayscale RLE TGA support X-Git-Tag: xonotic-v0.8.2~21^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=refs%2Fmerge-requests%2F14%2Fhead;p=xonotic%2Fnetradiant.git Add grayscale RLE TGA support --- diff --git a/plugins/image/tga.cpp b/plugins/image/tga.cpp index bc498a8f..4fa8731f 100644 --- a/plugins/image/tga.cpp +++ b/plugins/image/tga.cpp @@ -165,6 +165,42 @@ inline TargaPacketSize targa_packet_size( const TargaPacket& packet ){ } +class TargaDecodeGrayPixelRLE +{ +TargaPacketSize m_packetSize; +RGBAPixel m_pixel; +TargaPacket m_packet; +public: +TargaDecodeGrayPixelRLE() : m_packetSize( 0 ){ +} +void operator()( PointerInputStream& istream, RGBAPixel& pixel ){ + if ( m_packetSize == 0 ) { + targa_packet_read_istream( m_packet, istream ); + m_packetSize = targa_packet_size( m_packet ); + + if ( targa_packet_is_rle( m_packet ) ) { + istream_read_gray( istream, m_pixel ); + } + } + + if ( targa_packet_is_rle( m_packet ) ) { + pixel = m_pixel; + } + else + { + istream_read_gray( istream, pixel ); + } + + --m_packetSize; +} +}; + +template +void targa_decode_rle_grayscale( PointerInputStream& istream, RGBAImage& image, const Flip& flip ){ + TargaDecodeGrayPixelRLE decode; + image_decode( istream, decode, image, flip ); +} + class TargaDecodeRGBPixelRLE { TargaPacketSize m_packetSize; @@ -305,9 +341,12 @@ Image* Targa_decodeImageData( const TargaHeader& targa_header, PointerInputStrea return 0; } } - else if ( targa_header.image_type == 10 ) { + else if ( targa_header.image_type == 10 || targa_header.image_type == 11 ) { switch ( targa_header.pixel_size ) { + case 8: + targa_decode_rle_grayscale( istream, *image, flip ); + break; case 24: targa_decode_rle_rgb( istream, *image, flip ); break; @@ -333,9 +372,9 @@ Image* LoadTGABuff( const byte* buffer ){ targa_header_read_istream( targa_header, istream ); - if ( targa_header.image_type != 2 && targa_header.image_type != 10 && targa_header.image_type != 3 ) { + if ( targa_header.image_type != 2 && targa_header.image_type != 10 && targa_header.image_type != 3 && targa_header.image_type != 11 ) { globalErrorStream() << "LoadTGA: TGA type " << targa_header.image_type << " not supported\n"; - globalErrorStream() << "LoadTGA: Only type 2 (RGB), 3 (gray), and 10 (RGB) TGA images supported\n"; + globalErrorStream() << "LoadTGA: Only type 2 (RGB), 3 (gray), 10 (RGB), and 11 (gray) TGA images supported\n"; return 0; } @@ -344,9 +383,9 @@ Image* LoadTGABuff( const byte* buffer ){ return 0; } - if ( ( targa_header.pixel_size != 32 && targa_header.pixel_size != 24 ) - && targa_header.image_type != 3 ) { - globalErrorStream() << "LoadTGA: Only 32 or 24 bit images supported\n"; + if ( ( ( targa_header.image_type == 2 || targa_header.image_type == 10 ) && targa_header.pixel_size != 32 && targa_header.pixel_size != 24 ) || + ( ( targa_header.image_type == 3 || targa_header.image_type == 11 ) && targa_header.pixel_size != 8 ) ) { + globalErrorStream() << "LoadTGA: Only 32, 24 or 8 bit images supported\n"; return 0; }