From: Fridrich S. <str...@us...> - 2008-07-17 15:38:58
|
Update of /cvsroot/libwpg/libwpg/src/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17394/src/lib Modified Files: Tag: STABLE-0-1-0 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.33.2.7 retrieving revision 1.33.2.8 diff -u -d -r1.33.2.7 -r1.33.2.8 --- WPG1Parser.cpp 17 Jul 2008 14:41:39 -0000 1.33.2.7 +++ WPG1Parser.cpp 17 Jul 2008 15:38:53 -0000 1.33.2.8 @@ -557,8 +557,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++]; } } } @@ -592,9 +592,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++) { @@ -760,7 +787,7 @@ if (!m_graphicsStarted) return; #ifdef DEBUG - size_t lengthOfData = readU32(); + unsigned lengthOfData = readU32(); int rotation = readS16(); #else readU32(); |