public Bitmap getRegionBitmap()

in src/main/java/org/apache/pdfbox/jbig2/segments/GenericRegion.java [159:254]


    public Bitmap getRegionBitmap() throws IOException
    {
        if (null == regionBitmap)
        {

            if (isMMREncoded)
            {

                /*
                 * MMR DECODER CALL
                 */
                if (null == mmrDecompressor)
                {
                    mmrDecompressor = new MMRDecompressor(regionInfo.getBitmapWidth(),
                            regionInfo.getBitmapHeight(),
                            new SubInputStream(subInputStream, dataOffset, dataLength));
                }

                /* 6.2.6 */
                regionBitmap = mmrDecompressor.uncompress();

            }
            else
            {

                /*
                 * ARITHMETIC DECODER PROCEDURE for generic region segments
                 */

                updateOverrideFlags();

                /* 6.2.5.7 - 1) */
                int ltp = 0;

                if (arithDecoder == null)
                {
                    arithDecoder = new ArithmeticDecoder(subInputStream);
                }
                if (cx == null)
                {
                    cx = new CX(65536, 1);
                }

                /* 6.2.5.7 - 2) */
                regionBitmap = new Bitmap(regionInfo.getBitmapWidth(),
                        regionInfo.getBitmapHeight());

                final int paddedWidth = (regionBitmap.getWidth() + 7) & -8;

                /* 6.2.5.7 - 3 */
                for (int line = 0; line < regionBitmap.getHeight(); line++)
                {

                    /* 6.2.5.7 - 3 b) */
                    if (isTPGDon)
                    {
                        ltp ^= decodeSLTP();
                    }

                    /* 6.2.5.7 - 3 c) */
                    if (ltp == 1)
                    {
                        if (line > 0)
                        {
                            copyLineAbove(line);
                        }
                    }
                    else
                    {
                        /* 3 d) */
                        // NOT USED ATM - If corresponding pixel of SKIP bitmap is 0, set
                        // current pixel to 0. Something like that:
                        // if (useSkip) {
                        // for (int i = 1; i < rowstride; i++) {
                        // if (skip[pixel] == 1) {
                        // gbReg[pixel] = 0;
                        // }
                        // pixel++;
                        // }
                        // } else {
                        decodeLine(line, regionBitmap.getWidth(), regionBitmap.getRowStride(),
                                paddedWidth);
                        // }
                    }
                }
            }
        }

        // if (JBIG2ImageReader.DEBUG)
        // if (header != null && header.getSegmentNr() == 3)
        // new Testbild(gbReg.getByteArray(), (int) gbReg.getWidth(), (int) gbReg.getHeight(),
        // gbReg.getRowStride());

        /* 4 */
        return regionBitmap;
    }