Index: sources/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFPainter.java =================================================================== --- sources/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFPainter.java (revision 1341257) +++ sources/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFPainter.java (working copy) @@ -140,7 +140,7 @@ // Determine the number of colors int nbColors = 0; if (_clrused > 0) nbColors = _clrused; - else nbColors = (1 & 0x00ff) << 8; + else nbColors = 1 << 8; // Read the palette colors. int offset = _headerSize; int[] palette = new int[nbColors]; @@ -164,6 +164,36 @@ } offset += pad; } + // 4 bit image + } else if (_nbit == 4) { + // Determine the number of colors + int nbColors = 0; + if (_clrused > 0) nbColors = _clrused; + else nbColors = 1 << 4; + // Read the palette colors. + int offset = _headerSize; + int[] palette = new int[nbColors]; + for (int i = 0; i < nbColors; i++) { + palette[i] = (255 & 0x00ff) << 24 | (((int)bit[offset+2] & 0x00ff) << 16) + | (((int)bit[offset+1] & 0x00ff) << 8) + | (int)bit[offset] & 0x00ff; + offset += 4; + } + + // populate the int array + int usedBytesPerRow = _width / 2; + if (_width % 2 != 0) usedBytesPerRow++; + int pad = (_size / _height) - usedBytesPerRow; + for (int j = 0; j < _height; j++) { + for (int i = 0; i < _width; i+=2) { + int nibble1 = (int) ((bit[offset] >> 4) & 0x000f); + int nibble2 = (int) (bit[offset] & 0x000f); + bitI[_width*(_height-j-1)+i] = palette [nibble1]; + bitI[_width*(_height-j-1)+i+1] = palette [nibble2]; + offset++; + } + offset += pad; + } // black and white image } else if (_nbit == 1) { // 2 colors only (black and white image)