private Image createImage(int width, int height, byte[] data,
                int length, byte[] mask_data) {
            if (pixelFormat_.bitsPerPixel_ == 32) {
                SampleModel sampleModel = new PixelInterleavedSampleModel(
                        DataBuffer.TYPE_BYTE, width, height, 4, width * 4,
                        bandOffsets32_);

                if (mask_data == null) {
                    int index = 3;
                    for (int i = 0; i < width * height; ++i) {
                        data[index] = (byte) 0xff;
                        index += 4;
                    }
                } else {
                    int stride = (width + 7) >> 3;
                    int index = 3;
                    int mask_index = 0;
                    for (int y = 0; y < height; y++) {
                        for (int x = 0; x < width; x++) {
                            data[index] = ((mask_data[mask_index + (x / 8)] & (1 << (7 - (x & 7)))) == 0) ? (byte) 0
                                    : (byte) 0xff;
                            index += 4;
                        }
                        mask_index += stride;
                    }
                }

                DataBuffer dataBuffer = new DataBufferByte(data, length);
                WritableRaster raster = Raster.createWritableRaster(
                        sampleModel, dataBuffer, null);
                return new BufferedImage(colorModel32_, raster, true, null);
            } else if (pixelFormat_.bitsPerPixel_ == 8) {
                SampleModel sampleModel = new SinglePixelPackedSampleModel(
                        DataBuffer.TYPE_BYTE, width, height, width, bitMasks8_);
                DataBuffer dataBuffer = new DataBufferByte(data, length);
                WritableRaster raster = Raster.createWritableRaster(
                        sampleModel, dataBuffer, null);
                return new BufferedImage(colorModel8_, raster, true, null);
            } else {
                throw new RuntimeException("unexpected bits per pixel");
            }
        }