From: Fridrich S. <str...@us...> - 2008-07-23 15:05:51
|
Update of /cvsroot/libwpg/libwpg/src/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2347/src/lib Modified Files: WPG1Parser.cpp WPG2Parser.cpp Log Message: some optimizations + change in handling corrupted bitmap Index: WPG2Parser.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPG2Parser.cpp,v retrieving revision 1.78 retrieving revision 1.79 diff -u -d -r1.78 -r1.79 --- WPG2Parser.cpp 23 Jul 2008 14:42:47 -0000 1.78 +++ WPG2Parser.cpp 23 Jul 2008 15:05:46 -0000 1.79 @@ -1447,6 +1447,8 @@ std::vector<unsigned char> buffer; + buffer.reserve(tmpBufferSize); + // plain data, uncompression if(compression_format==0) for(unsigned ii=0; ii < tmpBufferSize && m_input->tell() <= m_recordEnd; ii++) @@ -1473,7 +1475,10 @@ { data_size = new_data_size; if (tmpBufferSize < data_size*width*height) + { tmpBufferSize = data_size*width*height; + buffer.reserve(tmpBufferSize); + } raster_len = data_size*width; } } @@ -1512,7 +1517,7 @@ { unsigned count = 1 + readU8(); if ( buffer.size() < raster_len ) - return; + break; unsigned raster_source = buffer.size() - raster_len; for( ; count; --count) for(unsigned long r = 0; r < raster_len; r++) Index: WPG1Parser.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPG1Parser.cpp,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -r1.43 -r1.44 --- WPG1Parser.cpp 23 Jul 2008 09:53:55 -0000 1.43 +++ WPG1Parser.cpp 23 Jul 2008 15:05:46 -0000 1.44 @@ -511,6 +511,8 @@ // round to the next byte unsigned scanline_width = (width * depth + 7)/8; + unsigned tmpBufferSize = scanline_width * height; + buffer.reserve(tmpBufferSize); WPG_DEBUG_MSG(("Scanline width: %d\n", scanline_width)); WPG_DEBUG_MSG(("Output size: %d\n", scanline_width * height)); @@ -545,8 +547,7 @@ if (buffer.size() < scanline_width ) { WPG_DEBUG_MSG(("Cannot copy the scanline, not enough data %li\n", (long)buffer.size())); - buffer.clear(); - return; + break; } unsigned raster_source = buffer.size() - scanline_width; for( ; count; --count) @@ -560,6 +561,9 @@ } WPG_DEBUG_MSG(("Finish decoding RLE data\n")); WPG_DEBUG_MSG(("Buffer length: %li\n", (long)buffer.size())); + + for ( ; buffer.size() < tmpBufferSize ; ) + buffer.push_back(0); } void WPG1Parser::fillPixels(libwpg::WPGBitmap& bitmap, const unsigned char* buffer, int width, int height, int depth) |