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
This class represents a generic refinement region and implements the procedure described in JBIG2 ISO standard, 6.3 and 7.4.7.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GenericRefinementRegion.Template
private static class
GenericRefinementRegion.Template0
private static class
GenericRefinementRegion.Template1
-
Field Summary
Fields Modifier and Type Field Description private ArithmeticDecoder
arithDecoder
private CX
cx
private boolean[]
grAtOverride
private short[]
grAtX
Generic refinement region segment AT flags, 7.4.7.3private short[]
grAtY
private boolean
isTPGROn
Generic refinement region segment flags, 7.4.7.2private boolean
override
If true, AT pixels are not on their nominal location and have to be overridden.private Bitmap
referenceBitmap
Variables for decodingprivate int
referenceDX
private int
referenceDY
private Bitmap
regionBitmap
Decoded data as pixel values (use row stride/width to wrap line)private RegionSegmentInformation
regionInfo
Region segment information flags, 7.4.1private SegmentHeader
segmentHeader
private SubInputStream
subInputStream
private static GenericRefinementRegion.Template
T0
private static GenericRefinementRegion.Template
T1
private GenericRefinementRegion.Template
template
private short
templateID
-
Constructor Summary
Constructors Constructor Description GenericRefinementRegion()
GenericRefinementRegion(SubInputStream subInputStream)
GenericRefinementRegion(SubInputStream subInputStream, SegmentHeader segmentHeader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
decodeOptimized(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int lineOffset)
private int
decodeSLTP()
private void
decodeTemplate(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int lineOffset, int byteIndex, int currentLine, int refByteIndex, GenericRefinementRegion.Template templateFormation)
private void
decodeTypicalPredictedLine(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride)
private void
decodeTypicalPredictedLineTemplate0(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int byteIndex, int currentLine, int refByteIndex)
private void
decodeTypicalPredictedLineTemplate1(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int byteIndex, int currentLine, int refByteIndex)
private Bitmap
getGrReference()
private byte
getPixel(Bitmap b, int x, int y)
Bitmap
getRegionBitmap()
Decode using a template and arithmetic coding, as described in 6.3.5.6RegionSegmentInformation
getRegionInfo()
Simply returns theRegionSegmentInformation
.void
init(SegmentHeader header, SubInputStream sis)
Parse the stream and read information of header.private int
overrideAtTemplate0(int context, int x, int y, int result, int minorX)
private void
parseHeader()
Parses the flags described in JBIG2 ISO standard: 7.4.7.2 Generic refinement region segment flags 7.4.7.3 Generic refinement refion segment AT flagsprivate void
readAtPixels()
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)
private void
updateOverride()
-
-
-
Field Detail
-
T0
private static final GenericRefinementRegion.Template T0
-
T1
private static final GenericRefinementRegion.Template T1
-
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
-
template
private GenericRefinementRegion.Template template
-
grAtX
private short[] grAtX
Generic refinement region segment AT flags, 7.4.7.3
-
grAtY
private short[] grAtY
-
regionBitmap
private Bitmap regionBitmap
Decoded data as pixel values (use row stride/width to wrap line)
-
referenceBitmap
private Bitmap referenceBitmap
Variables for decoding
-
referenceDX
private int referenceDX
-
referenceDY
private int referenceDY
-
arithDecoder
private ArithmeticDecoder arithDecoder
-
cx
private CX cx
-
override
private boolean override
If true, AT pixels are not on their nominal location and have to be overridden.
-
grAtOverride
private boolean[] grAtOverride
-
-
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.IOException
Parses the flags described in JBIG2 ISO standard:- 7.4.7.2 Generic refinement region segment flags
- 7.4.7.3 Generic refinement refion 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:
getRegionBitmap
in 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
-
decodeSLTP
private int decodeSLTP() throws java.io.IOException
- Throws:
java.io.IOException
-
getGrReference
private Bitmap getGrReference() throws IntegerMaxValueException, InvalidHeaderValueException, java.io.IOException
- Throws:
IntegerMaxValueException
InvalidHeaderValueException
java.io.IOException
-
decodeOptimized
private void decodeOptimized(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int lineOffset) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeTemplate
private void decodeTemplate(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int lineOffset, int byteIndex, int currentLine, int refByteIndex, GenericRefinementRegion.Template templateFormation) throws java.io.IOException
- Throws:
java.io.IOException
-
updateOverride
private void updateOverride()
-
decodeTypicalPredictedLine
private void decodeTypicalPredictedLine(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeTypicalPredictedLineTemplate0
private void decodeTypicalPredictedLineTemplate0(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int byteIndex, int currentLine, int refByteIndex) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeTypicalPredictedLineTemplate1
private void decodeTypicalPredictedLineTemplate1(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int byteIndex, int currentLine, int refByteIndex) throws java.io.IOException
- Throws:
java.io.IOException
-
overrideAtTemplate0
private int overrideAtTemplate0(int context, int x, int y, int result, int minorX) throws java.io.IOException
- Throws:
java.io.IOException
-
getPixel
private byte getPixel(Bitmap b, int x, int y) throws java.io.IOException
- Throws:
java.io.IOException
-
init
public void init(SegmentHeader header, SubInputStream sis) throws java.io.IOException
Description copied from interface:SegmentData
Parse the stream and read information of header.- Specified by:
init
in interfaceSegmentData
- Parameters:
header
- - The segments' header (to make referred-to segments available in data part).sis
- - WrappedImageInputStream
intoSubInputStream
.- Throws:
java.io.IOException
- if an underlying IO operation fails
-
setParameters
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)
-
getRegionInfo
public RegionSegmentInformation getRegionInfo()
Description copied from interface:Region
Simply returns theRegionSegmentInformation
.- Specified by:
getRegionInfo
in interfaceRegion
- Returns:
- The
RegionSegmentInformation
.
-
-