Exemple #1
0
        private void HandleSegmentHeaderFlags(SegmentHeader segmentHeader)
        {
            short segmentHeaderFlags = reader.Readbyte();

            // System.out.println("SegmentHeaderFlags = " + SegmentHeaderFlags);
            segmentHeader.SetSegmentHeaderFlags(segmentHeaderFlags);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
            }
        }
Exemple #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("");
            }
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #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("");
            }
        }
Exemple #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();
                }
            }
        }
 public void SetSegmentHeader(SegmentHeader segmentHeader)
 {
     this.segmentHeader = segmentHeader;
 }