System.out.println("==== Segment Header ====");
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:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Segment Symbol Dictionary ====");
segment = new SymbolDictionarySegment(this);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.INTERMEDIATE_TEXT_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Intermediate Text Region ====");
segment = new TextRegionSegment(this, false);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.IMMEDIATE_TEXT_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Immediate Text Region ====");
segment = new TextRegionSegment(this, true);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.IMMEDIATE_LOSSLESS_TEXT_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Immediate Lossless Text Region ====");
segment = new TextRegionSegment(this, true);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.PATTERN_DICTIONARY:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Pattern Dictionary ====");
segment = new PatternDictionarySegment(this);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.INTERMEDIATE_HALFTONE_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Intermediate Halftone Region ====");
segment = new HalftoneRegionSegment(this, false);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.IMMEDIATE_HALFTONE_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Immediate Halftone Region ====");
segment = new HalftoneRegionSegment(this, true);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.IMMEDIATE_LOSSLESS_HALFTONE_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Immediate Lossless Halftone Region ====");
segment = new HalftoneRegionSegment(this, true);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.INTERMEDIATE_GENERIC_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Intermediate Generic Region ====");
segment = new GenericRegionSegment(this, false);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.IMMEDIATE_GENERIC_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Immediate Generic Region ====");
segment = new GenericRegionSegment(this, true);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.IMMEDIATE_LOSSLESS_GENERIC_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Immediate Lossless Generic Region ====");
segment = new GenericRegionSegment(this, true);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.INTERMEDIATE_GENERIC_REFINEMENT_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Intermediate Generic Refinement Region ====");
segment = new RefinementRegionSegment(this, false, referredToSegments, noOfReferredToSegments);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.IMMEDIATE_GENERIC_REFINEMENT_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Immediate Generic Refinement Region ====");
segment = new RefinementRegionSegment(this, true, referredToSegments, noOfReferredToSegments);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.IMMEDIATE_LOSSLESS_GENERIC_REFINEMENT_REGION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Immediate lossless Generic Refinement Region ====");
segment = new RefinementRegionSegment(this, true, referredToSegments, noOfReferredToSegments);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.PAGE_INFORMATION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Page Information Dictionary ====");
segment = new PageInformationSegment(this);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.END_OF_PAGE:
continue;
case Segment.END_OF_STRIPE:
if (JBIG2StreamDecoder.debug)
System.out.println("==== End of Stripes ====");
segment = new EndOfStripeSegment(this);
segment.setSegmentHeader(segmentHeader);
break;
case Segment.END_OF_FILE:
if (JBIG2StreamDecoder.debug)
System.out.println("==== End of File ====");
finished = true;
continue;
case Segment.PROFILES:
if (JBIG2StreamDecoder.debug)
System.out.println("PROFILES UNIMPLEMENTED");
break;
case Segment.TABLES:
if (JBIG2StreamDecoder.debug)
System.out.println("TABLES UNIMPLEMENTED");
break;
case Segment.EXTENSION:
if (JBIG2StreamDecoder.debug)
System.out.println("==== Extensions ====");
segment = new ExtensionSegment(this);
segment.setSegmentHeader(segmentHeader);
break;
default:
System.out.println("Unknown Segment type in JBIG2 stream");
break;
}
if (!randomAccessOrganisation) {
segment.readSegment();
}
segments.add(segment);
}
if (randomAccessOrganisation) {
for (Iterator it = segments.iterator(); it.hasNext();) {
Segment segment = (Segment) it.next();
segment.readSegment();
}
}
}