public void processImage(BufferedImage bi) throws ImageReadException,
            IOException
    {
        DataBuffer db = bi.getRaster().getDataBuffer();

        int count = 0;
        int width = bhi.width;
        int height = bhi.height;
        int x = 0, y = height - 1;

        //        bfp.setDebug(true);

        boolean done = false;
        while (!done)
        {
            count++;
            //            if (count > 100)
            //                return;

            int a = 0xff & bfp.readByte("RLE (" + x + "," + y + ") a", is,
                    "BMP: Bad RLE");
            //                baos.write(a);
            int b = 0xff & bfp.readByte("RLE (" + x + "," + y + ")  b", is,
                    "BMP: Bad RLE");
            //                baos.write(b);

            if (a == 0)
            {
                switch (b)
                {
                    case 0 : // EOL
                    {
                        //                        System.out.println("EOL");
                        y--;
                        x = 0;
                    }
                        break;
                    case 1 : // EOF
                        //                        System.out
                        //                                .println("xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
                        done = true;
                        break;
                    case 2 : {
                        //                        System.out
                        //                                .println("xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
                        int c = 0xff & bfp
                                .readByte("RLE c", is, "BMP: Bad RLE");
                        //                            baos.write(c);
                        int d = 0xff & bfp
                                .readByte("RLE d", is, "BMP: Bad RLE");
                        //                            baos.write(d);

                    }
                        break;
                    default : {
                        //                        System.out
                        //                                .println("xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

                        int SamplesPerByte = getSamplesPerByte();
                        int size = b / SamplesPerByte;
                        if ((b % SamplesPerByte) > 0)
                            size++;
                        if ((size % 2) != 0)
                            size++;

                        //                        System.out.println("b: " + b);
                        //                        System.out.println("size: " + size);
                        //                        System.out.println("SamplesPerByte: " + SamplesPerByte);

                        byte bytes[] = bfp.readByteArray("bytes", size, is,
                                "RLE: Absolute Mode");

                        int remaining = b;

                        //                        while(true)
                        for (int i = 0; remaining > 0; i++)
                        //                                for (int i = 0; i < bytes.length; i++)
                        {
                            int samples[] = convertDataToSamples(0xff & bytes[i]);
                            int towrite = Math.min(remaining, SamplesPerByte);
                            //                            System.out.println("remaining: " + remaining);
                            //                            System.out.println("SamplesPerByte: "
                            //                                    + SamplesPerByte);
                            //                            System.out.println("towrite: " + towrite);
                            int written = processByteOfData(samples, towrite,
                                    x, y, width, height, db, bi);
                            //                            System.out.println("written: " + written);
                            //                            System.out.println("");
                            x += written;
                            remaining -= written;
                        }
                        //                            baos.write(bytes);
                    }
                        break;
                }
            }
            else
            {
                int rgbs[] = convertDataToSamples(b);

                x += processByteOfData(rgbs, a, x, y, width, height, db, bi);
                //                    x += processByteOfData(b, a, x, y, width, height, bi);

            }
        }

    }