public int getNextRGB() throws ImageReadException, IOException
    {
        int data;

        if (bhi.bitsPerPixel == 8)
        {
            data = 0xff & imageData[bytecount + 0];
            bytecount += 1;
        }
        else if (bhi.bitsPerPixel == 24)
        {
            data = bfp.read3Bytes("Pixel", is, "BMP Image Data");
            bytecount += 3;
        }
        else if (bhi.bitsPerPixel == 32)
        {
            data = bfp.read4Bytes("Pixel", is, "BMP Image Data");
            bytecount += 4;
        }
        else if (bhi.bitsPerPixel == 16)
        {
            data = bfp.read2Bytes("Pixel", is, "BMP Image Data");
            bytecount += 2;
        }
        else
            throw new ImageReadException("Unknown BitsPerPixel: "
                    + bhi.bitsPerPixel);

        int red = (redMask & data);
        int green = (greenMask & data);
        int blue = (blueMask & data);

        red = (redShift >= 0) ? red >> redShift : red << -redShift;
        green = (greenShift >= 0) ? green >> greenShift : green << -greenShift;
        blue = (blueShift >= 0) ? blue >> blueShift : blue << -blueShift;

        int alpha = 0xff;

        int rgb = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);

        return rgb;
    }