From: Fridrich S. <str...@us...> - 2008-07-17 15:38:23
|
Update of /cvsroot/libwpg/libwpg/src/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17370/src/lib Modified Files: WPG1Parser.cpp Log Message: handle bitmaps with colour depth 2 and 4 in wpg1 Index: WPG1Parser.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPG1Parser.cpp,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- WPG1Parser.cpp 17 Jul 2008 14:41:57 -0000 1.41 +++ WPG1Parser.cpp 17 Jul 2008 15:38:19 -0000 1.42 @@ -558,8 +558,8 @@ if (!raster_source || raster_source < buffer) return 0; for( ; count; --count) - for(unsigned r = 0; r < scanline_width && ptr < buffer + buffer_size; r++) - *ptr++ = raster_source[r]; + for(unsigned r = 0; r < scanline_width && ptr < buffer + buffer_size;) + *ptr++ = raster_source[r++]; } } } @@ -593,9 +593,36 @@ bitmap.setPixel(x, y, black); } } - - // 8-bit image: indexed color - if(depth == 8) + // 2-bit image: 4-color bitmap (indexed) + else if(depth == 2) + { + int i = 0; + for (int y = 0; y < height; y++) + for (int x = 0; x < width; x++, i++) + { + if ((x==0) && (i % 4 != 0)) + i = (i/4 + 1) * 4; + unsigned index = ((buffer[i/4] & (0x03 << 2*(3 - (i % 4)))) >> 2*(3 - (i % 4))); + const libwpg::WPGColor& color = m_colorPalette[index]; + bitmap.setPixel(x, y, color); + } + } + // 4 -bit image: 16-colour bitmap (indexed) + else if(depth == 4) + { + int i = 0; + for (int y = 0; y < height; y++) + for (int x = 0; x < width; x++, i++) + { + if ((x==0) && (i % 2 != 0)) + i = (i/2 + 1) * 2; + unsigned index = ((buffer[i/2] & (0x0f << 4*(1 - (i % 2)))) >> 4*(1 - (i % 2))); + const libwpg::WPGColor& color = m_colorPalette[index]; + bitmap.setPixel(x, y, color); + } + } + // 8-bit image: 256-colour image (indexed) + else if(depth == 8) { for(int y = 0; y < height; y++) { @@ -761,7 +788,7 @@ if (!m_graphicsStarted) return; #ifdef DEBUG - size_t lengthOfData = readU32(); + unsigned lengthOfData = readU32(); int rotation = readS16(); #else readU32(); |