コード例 #1
0
        private void handleSegmentHeaderFlags(SegmentHeader segmentHeader)
        {
            short segmentHeaderFlags = reader.readbyte();

            // System.out.println("SegmentHeaderFlags = " + SegmentHeaderFlags);
            segmentHeader.setSegmentHeaderFlags(segmentHeaderFlags);
        }
コード例 #2
0
        private void handleSegmentNumber(SegmentHeader segmentHeader)
        {
            short[] segmentbytes = new short[4];
            reader.readbyte(segmentbytes);

            int segmentNumber = BinaryOperation.getInt32(segmentbytes);

            if (JBIG2StreamDecoder.debug)
            {
                Console.WriteLine("SegmentNumber = " + segmentNumber);
            }
            segmentHeader.setSegmentNumber(segmentNumber);
        }
コード例 #3
0
        public PageInformationSegment findPageSegement(int page)
        {
            foreach (Segment segment in segments)
            {
                SegmentHeader segmentHeader = segment.getSegmentHeader();
                if (segmentHeader.getSegmentType() == Segment.PAGE_INFORMATION && segmentHeader.getPageAssociation() == page)
                {
                    return((PageInformationSegment)segment);
                }
            }

            return(null);
        }
コード例 #4
0
        private void handleSegmentDataLength(SegmentHeader segmentHeader)
        {
            short[] buf = new short[4];
            reader.readbyte(buf);

            int dateLength = BinaryOperation.getInt32(buf);

            segmentHeader.setDataLength(dateLength);

            if (JBIG2StreamDecoder.debug)
            {
                Console.WriteLine("dateLength = " + dateLength);
            }
        }
コード例 #5
0
        private void handleReferedToSegmentNumbers(SegmentHeader segmentHeader)
        {
            int referredToSegmentCount = segmentHeader.getReferredToSegmentCount();

            int[] referredToSegments = new int[referredToSegmentCount];

            int segmentNumber = segmentHeader.getSegmentNumber();

            if (segmentNumber <= 256)
            {
                for (int i = 0; i < referredToSegmentCount; i++)
                {
                    referredToSegments[i] = reader.readbyte();
                }
            }
            else if (segmentNumber <= 65536)
            {
                short[] buf = new short[2];
                for (int i = 0; i < referredToSegmentCount; i++)
                {
                    reader.readbyte(buf);
                    referredToSegments[i] = BinaryOperation.getInt16(buf);
                }
            }
            else
            {
                short[] buf = new short[4];
                for (int i = 0; i < referredToSegmentCount; i++)
                {
                    reader.readbyte(buf);
                    referredToSegments[i] = BinaryOperation.getInt32(buf);
                }
            }

            segmentHeader.setReferredToSegments(referredToSegments);

            if (JBIG2StreamDecoder.debug)
            {
                Console.WriteLine("referredToSegments = ");
                for (int i = 0; i < referredToSegments.Length; i++)
                {
                    Console.WriteLine(referredToSegments[i] + " ");
                }
                Console.WriteLine("");
            }
        }
コード例 #6
0
        private void readSegmentHeader(SegmentHeader segmentHeader)
        {
            handleSegmentNumber(segmentHeader);

            handleSegmentHeaderFlags(segmentHeader);

            handleSegmentReferredToCountAndRententionFlags(segmentHeader);

            handleReferedToSegmentNumbers(segmentHeader);

            handlePageAssociation(segmentHeader);

            if (segmentHeader.getSegmentType() != Segment.END_OF_FILE)
            {
                handleSegmentDataLength(segmentHeader);
            }
        }
コード例 #7
0
        private void handlePageAssociation(SegmentHeader segmentHeader)
        {
            int pageAssociation;

            bool isPageAssociationSizeSet = segmentHeader.isPageAssociationSizeSet();

            if (isPageAssociationSizeSet)
            { // field is 4 bytes long
                short[] buf = new short[4];
                reader.readbyte(buf);
                pageAssociation = BinaryOperation.getInt32(buf);
            }
            else
            { // field is 1 byte long
                pageAssociation = reader.readbyte();
            }

            segmentHeader.setPageAssociation(pageAssociation);

            if (JBIG2StreamDecoder.debug)
            {
                Console.WriteLine("pageAssociation = " + pageAssociation);
            }
        }
コード例 #8
0
        private void handleSegmentReferredToCountAndRententionFlags(SegmentHeader segmentHeader)
        {
            short referedToSegmentCountAndRetentionFlags = reader.readbyte();

            int referredToSegmentCount = (referedToSegmentCountAndRetentionFlags & 224) >> 5; // 224

            // =
            // 11100000
            short[] retentionFlags = null;
            /** take off the first three bits of the first byte */
            short firstbyte = (short)(referedToSegmentCountAndRetentionFlags & 31); // 31 =

            // 00011111

            if (referredToSegmentCount <= 4)
            { // short form
                retentionFlags    = new short[1];
                retentionFlags[0] = firstbyte;
            }
            else if (referredToSegmentCount == 7)
            { // long form
                short[] longFormCountAndFlags = new short[4];
                /** add the first byte of the four */
                longFormCountAndFlags[0] = firstbyte;

                for (int i = 1; i < 4; i++)
                {
                    // add the next 3 bytes to the array
                    longFormCountAndFlags[i] = reader.readbyte();
                }

                /** get the count of the referred to Segments */
                referredToSegmentCount = BinaryOperation.getInt32(longFormCountAndFlags);

                /** calculate the number of bytes in this field */
                int noOfbytesInField = (int)Math.Ceiling(4 + ((referredToSegmentCount + 1) / 8d));
                // System.out.println("noOfbytesInField = " + noOfbytesInField);

                int noOfRententionFlagbytes = noOfbytesInField - 4;
                retentionFlags = new short[noOfRententionFlagbytes];
                reader.readbyte(retentionFlags);
            }
            else
            { // error
              //throw new JBIG2Exception("Error, 3 bit Segment count field = " + referredToSegmentCount);
            }

            segmentHeader.setReferredToSegmentCount(referredToSegmentCount);

            if (JBIG2StreamDecoder.debug)
            {
                Console.WriteLine("referredToSegmentCount = " + referredToSegmentCount);
            }

            segmentHeader.setRententionFlags(retentionFlags);

            if (JBIG2StreamDecoder.debug)
            {
                Console.WriteLine("retentionFlags = ");
            }

            if (JBIG2StreamDecoder.debug)
            {
                for (int i = 0; i < retentionFlags.Length; i++)
                {
                    Console.WriteLine(retentionFlags[i] + " ");
                }
                Console.WriteLine("");
            }
        }
コード例 #9
0
        private void readSegments()
        {
            bool finished = false;

            while (!reader.isFinished() && !finished)
            {
                SegmentHeader segmentHeader = new SegmentHeader();
                readSegmentHeader(segmentHeader);

                // read the Segment data
                Segment segment = null;

                int   segmentType            = segmentHeader.getSegmentType();
                int[] referredToSegments     = segmentHeader.getReferredToSegments();
                int   noOfReferredToSegments = segmentHeader.getReferredToSegmentCount();

                switch (segmentType)
                {
                case Segment.SYMBOL_DICTIONARY:

                    segment = new SymbolDictionarySegment(this);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.INTERMEDIATE_TEXT_REGION:

                    segment = new TextRegionSegment(this, false);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.IMMEDIATE_TEXT_REGION:

                    segment = new TextRegionSegment(this, true);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.IMMEDIATE_LOSSLESS_TEXT_REGION:

                    segment = new TextRegionSegment(this, true);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.PATTERN_DICTIONARY:

                    segment = new PatternDictionarySegment(this);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.INTERMEDIATE_HALFTONE_REGION:

                    segment = new HalftoneRegionSegment(this, false);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.IMMEDIATE_HALFTONE_REGION:

                    segment = new HalftoneRegionSegment(this, true);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.IMMEDIATE_LOSSLESS_HALFTONE_REGION:

                    segment = new HalftoneRegionSegment(this, true);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.INTERMEDIATE_GENERIC_REGION:

                    segment = new GenericRegionSegment(this, false);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.IMMEDIATE_GENERIC_REGION:

                    segment = new GenericRegionSegment(this, true);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.IMMEDIATE_LOSSLESS_GENERIC_REGION:

                    segment = new GenericRegionSegment(this, true);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.INTERMEDIATE_GENERIC_REFINEMENT_REGION:

                    segment = new RefinementRegionSegment(this, false, referredToSegments, noOfReferredToSegments);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.IMMEDIATE_GENERIC_REFINEMENT_REGION:

                    segment = new RefinementRegionSegment(this, true, referredToSegments, noOfReferredToSegments);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.IMMEDIATE_LOSSLESS_GENERIC_REFINEMENT_REGION:

                    segment = new RefinementRegionSegment(this, true, referredToSegments, noOfReferredToSegments);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.PAGE_INFORMATION:

                    segment = new PageInformationSegment(this);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                case Segment.END_OF_PAGE:
                    continue;

                case Segment.END_OF_STRIPE:

                    segment = new EndOfStripeSegment(this);

                    segment.setSegmentHeader(segmentHeader);
                    break;

                case Segment.END_OF_FILE:

                    finished = true;

                    continue;

                case Segment.PROFILES:
                    break;

                case Segment.TABLES:
                    break;

                case Segment.EXTENSION:

                    segment = new ExtensionSegment(this);

                    segment.setSegmentHeader(segmentHeader);

                    break;

                default:
                    break;
                }

                if (!randomAccessOrganisation)
                {
                    segment.readSegment();
                }
                segments.Add(segment);
            }

            if (randomAccessOrganisation)
            {
                foreach (Segment segment in segments)
                {
                    segment.readSegment();
                }
            }
        }
コード例 #10
0
ファイル: Segment.cs プロジェクト: jimleigh/JBig2Decoder.NET
 public void setSegmentHeader(SegmentHeader segmentHeader)
 {
     this.segmentHeader = segmentHeader;
 }