Package org.apache.pdfbox.jbig2.segments
Class GenericRefinementRegion
- java.lang.Object
-
- org.apache.pdfbox.jbig2.segments.GenericRefinementRegion
-
- All Implemented Interfaces:
Region,SegmentData
public class GenericRefinementRegion extends java.lang.Object implements Region
Handles a JBIG2 Generic Refinement Region segment (§7.4.7).This class is responsible for segment-level concerns only: parsing the region segment information and flags from the bitstream, resolving the reference bitmap, and delegating pixel decoding to
GenericRefinementRegionDecodingProcedure, which implements the pure algorithm defined in §6.3.5.6.Segment types (§7.4.7)
The three generic refinement region segment types — intermediate, immediate, and immediate lossless — share an identical data encoding. They differ only in how the decoded bitmap is acted upon during page image composition (§8.2):
- Intermediate generic refinement region — the decoded bitmap is stored but not yet composited onto the page buffer.
- Immediate generic refinement region — the decoded bitmap is composited onto the page buffer immediately using lossy encoding.
- Immediate lossless generic refinement region — as above but using lossless encoding.
Usage modes
- Header-driven (standalone segment):
Initialise via
init(SegmentHeader, SubInputStream). The reference bitmap is resolved from referred-to segments or, if none are present, from the current page buffer (§7.4.7.4). Per Table 35,GRREFERENCEDXandGRREFERENCEDYare implicitly zero in this mode. - Parameter-driven:
Call
setParameters(CX, ArithmeticDecoder, short, int, int, Bitmap, int, int, boolean, short[], short[])to supply the sharedArithmeticDecoder,CX, reference bitmap, and offsets before callinggetRegionBitmap().
Deprecated: callers should migrate to invokingGenericRefinementRegionDecodingProcedure.decode( ArithmeticDecoder, CX, int, int, short, boolean, Bitmap, int, int, short[], short[])directly.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGenericRefinementRegion.TemplateDeprecated.
-
Field Summary
Fields Modifier and Type Field Description private ArithmeticDecoderarithDecoderprivate CXcxprivate short[]grAtXGeneric refinement region segment AT flags, 7.4.7.3private short[]grAtYprivate booleanisTPGROnGeneric refinement region segment flags, 7.4.7.2private BitmappageBitmapprivate BitmapreferenceBitmapVariables for decodingprivate intreferenceDXprivate intreferenceDYprivate RegionSegmentInformationregionInfoRegion segment information flags, 7.4.1private SegmentHeadersegmentHeaderprivate SubInputStreamsubInputStreamprivate shorttemplateID
-
Constructor Summary
Constructors Constructor Description GenericRefinementRegion()GenericRefinementRegion(SubInputStream subInputStream)GenericRefinementRegion(SubInputStream subInputStream, SegmentHeader segmentHeader)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private BitmapgetGrReference()BitmapgetRegionBitmap()Decode using a template and arithmetic coding, as described in 6.3.5.6RegionSegmentInformationgetRegionInfo()Simply returns theRegionSegmentInformation.voidinit(SegmentHeader header, SubInputStream sis)Parse the stream and read information of header.private voidparseHeader()Parses the flags described in JBIG2 ISO standard: 7.4.7.2 Generic refinement region segment flags 7.4.7.3 Generic refinement region segment AT flagsprivate voidreadAtPixels()voidsetPageBitmap(Bitmap pageBitmap)Call this to pass the page bitmap in case there is no reference bitmap.protected voidsetParameters(CX cx, ArithmeticDecoder arithmeticDecoder, short grTemplate, int regionWidth, int regionHeight, Bitmap grReference, int grReferenceDX, int grReferenceDY, boolean isTPGRon, short[] grAtX, short[] grAtY)Deprecated.UseGenericRefinementRegionDecodingProcedure.decode( ArithmeticDecoder, CX, int, int, short, boolean, Bitmap, int, int, short[], short[])directly, supplying the sharedArithmeticDecoderandCXas arguments.
-
-
-
Field Detail
-
subInputStream
private SubInputStream subInputStream
-
segmentHeader
private SegmentHeader segmentHeader
-
regionInfo
private RegionSegmentInformation regionInfo
Region segment information flags, 7.4.1
-
isTPGROn
private boolean isTPGROn
Generic refinement region segment flags, 7.4.7.2
-
templateID
private short templateID
-
grAtX
private short[] grAtX
Generic refinement region segment AT flags, 7.4.7.3
-
grAtY
private short[] grAtY
-
referenceBitmap
private Bitmap referenceBitmap
Variables for decoding
-
referenceDX
private int referenceDX
-
referenceDY
private int referenceDY
-
arithDecoder
private ArithmeticDecoder arithDecoder
-
cx
private CX cx
-
pageBitmap
private Bitmap pageBitmap
-
-
Constructor Detail
-
GenericRefinementRegion
public GenericRefinementRegion()
-
GenericRefinementRegion
public GenericRefinementRegion(SubInputStream subInputStream)
-
GenericRefinementRegion
public GenericRefinementRegion(SubInputStream subInputStream, SegmentHeader segmentHeader)
-
-
Method Detail
-
parseHeader
private void parseHeader() throws java.io.IOExceptionParses the flags described in JBIG2 ISO standard:- 7.4.7.2 Generic refinement region segment flags
- 7.4.7.3 Generic refinement region segment AT flags
- Throws:
java.io.IOException
-
readAtPixels
private void readAtPixels() throws java.io.IOException- Throws:
java.io.IOException
-
getRegionBitmap
public Bitmap getRegionBitmap() throws java.io.IOException, IntegerMaxValueException, InvalidHeaderValueException
Decode using a template and arithmetic coding, as described in 6.3.5.6- Specified by:
getRegionBitmapin interfaceRegion- Returns:
- The decoded region as
Bitmap. - Throws:
java.io.IOException- if an underlying IO operation failsInvalidHeaderValueException- if a segment header value is invalidIntegerMaxValueException- if the maximum value limit of an integer is exceeded
-
setPageBitmap
public void setPageBitmap(Bitmap pageBitmap)
Call this to pass the page bitmap in case there is no reference bitmap.- Parameters:
pageBitmap-
-
getGrReference
private Bitmap getGrReference() throws IntegerMaxValueException, InvalidHeaderValueException, java.io.IOException
- Throws:
IntegerMaxValueExceptionInvalidHeaderValueExceptionjava.io.IOException
-
init
public void init(SegmentHeader header, SubInputStream sis) throws java.io.IOException
Description copied from interface:SegmentDataParse the stream and read information of header.- Specified by:
initin interfaceSegmentData- Parameters:
header- - The segments' header (to make referred-to segments available in data part).sis- - WrappedImageInputStreamintoSubInputStream.- Throws:
java.io.IOException- if an underlying IO operation fails
-
setParameters
@Deprecated protected void setParameters(CX cx, ArithmeticDecoder arithmeticDecoder, short grTemplate, int regionWidth, int regionHeight, Bitmap grReference, int grReferenceDX, int grReferenceDY, boolean isTPGRon, short[] grAtX, short[] grAtY)
Deprecated.UseGenericRefinementRegionDecodingProcedure.decode( ArithmeticDecoder, CX, int, int, short, boolean, Bitmap, int, int, short[], short[])directly, supplying the sharedArithmeticDecoderandCXas arguments. This method will be removed in the next major release.
-
getRegionInfo
public RegionSegmentInformation getRegionInfo()
Description copied from interface:RegionSimply returns theRegionSegmentInformation.- Specified by:
getRegionInfoin interfaceRegion- Returns:
- The
RegionSegmentInformation.
-
-