Package org.apache.pdfbox.jbig2.segments
Class GenericRegion
- java.lang.Object
-
- org.apache.pdfbox.jbig2.segments.GenericRegion
-
- All Implemented Interfaces:
Region
,SegmentData
public class GenericRegion extends java.lang.Object implements Region
This class represents a generic region segment.
Parsing is done as described in 7.4.5.
Decoding procedure is done as described in 6.2.5.7 and 7.4.6.4.
-
-
Field Summary
Fields Modifier and Type Field Description private ArithmeticDecoder
arithDecoder
private CX
cx
private long
dataHeaderLength
private long
dataHeaderOffset
private long
dataLength
private long
dataOffset
private boolean[]
gbAtOverride
private short[]
gbAtX
Generic region segment AT flags, 7.4.6.3private short[]
gbAtY
private byte
gbTemplate
private boolean
isMMREncoded
private boolean
isTPGDon
private MMRDecompressor
mmrDecompressor
private boolean
override
If true, AT pixels are not on their nominal location and have to be overriddenprivate Bitmap
regionBitmap
Decoded data as pixel values (use row stride/width to wrap line)private RegionSegmentInformation
regionInfo
Region segment information field, 7.4.1private SubInputStream
subInputStream
private boolean
useExtTemplates
Generic region segment flags, 7.4.6.2
-
Constructor Summary
Constructors Constructor Description GenericRegion()
GenericRegion(SubInputStream subInputStream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
computeSegmentDataStructure()
private void
copyLineAbove(int lineNumber)
Each pixel gets the value from the corresponding pixel of the row above.private void
decodeLine(int lineNumber, int width, int rowStride, int paddedWidth)
private int
decodeSLTP()
private void
decodeTemplate0a(int lineNumber, int width, int rowStride, int paddedWidth, int byteIndex, int idx)
private void
decodeTemplate0b(int lineNumber, int width, int rowStride, int paddedWidth, int byteIndex, int idx)
private void
decodeTemplate1(int lineNumber, int width, int rowStride, int paddedWidth, int byteIndex, int idx)
private void
decodeTemplate2(int lineNumber, int width, int rowStride, int paddedWidth, int byteIndex, int idx)
private void
decodeTemplate3(int lineNumber, int width, int rowStride, int paddedWidth, int byteIndex, int idx)
protected short[]
getGbAtX()
protected short[]
getGbAtY()
protected byte
getGbTemplate()
private byte
getPixel(int x, int y)
Bitmap
getRegionBitmap()
The procedure is described in 6.2.5.7, page 17.RegionSegmentInformation
getRegionInfo()
Simply returns theRegionSegmentInformation
.void
init(SegmentHeader header, SubInputStream sis)
Parse the stream and read information of header.protected boolean
isMMREncoded()
protected boolean
isTPGDon()
private int
overrideAtTemplate0a(int context, int x, int y, int result, int minorX, int toShift)
private int
overrideAtTemplate0b(int context, int x, int y, int result, int minorX, int toShift)
private int
overrideAtTemplate1(int context, int x, int y, int result, int minorX)
private int
overrideAtTemplate2(int context, int x, int y, int result, int minorX)
private int
overrideAtTemplate3(int context, int x, int y, int result, int minorX)
private void
parseHeader()
private void
readGbAtPixels(int amountOfGbAt)
protected void
resetBitmap()
Simply sets the memory-critical bitmap of this region tonull
.private void
setOverrideFlag(int index)
protected void
setParameters(boolean isMMREncoded, byte sdTemplate, boolean isTPGDon, boolean useSkip, short[] sdATX, short[] sdATY, int symWidth, int hcHeight, CX cx, ArithmeticDecoder arithmeticDecoder)
protected void
setParameters(boolean isMMREncoded, long dataOffset, long dataLength, int gbh, int gbw)
Used bySymbolDictionary
.protected void
setParameters(boolean isMMREncoded, long dataOffset, long dataLength, int gbh, int gbw, byte gbTemplate, boolean isTPGDon, boolean useSkip, short[] gbAtX, short[] gbAtY)
Used byPatternDictionary
andHalftoneRegion
.private void
updateOverrideFlags()
protected boolean
useExtTemplates()
-
-
-
Field Detail
-
subInputStream
private SubInputStream subInputStream
-
dataHeaderOffset
private long dataHeaderOffset
-
dataHeaderLength
private long dataHeaderLength
-
dataOffset
private long dataOffset
-
dataLength
private long dataLength
-
regionInfo
private RegionSegmentInformation regionInfo
Region segment information field, 7.4.1
-
useExtTemplates
private boolean useExtTemplates
Generic region segment flags, 7.4.6.2
-
isTPGDon
private boolean isTPGDon
-
gbTemplate
private byte gbTemplate
-
isMMREncoded
private boolean isMMREncoded
-
gbAtX
private short[] gbAtX
Generic region segment AT flags, 7.4.6.3
-
gbAtY
private short[] gbAtY
-
gbAtOverride
private boolean[] gbAtOverride
-
override
private boolean override
If true, AT pixels are not on their nominal location and have to be overridden
-
regionBitmap
private Bitmap regionBitmap
Decoded data as pixel values (use row stride/width to wrap line)
-
arithDecoder
private ArithmeticDecoder arithDecoder
-
cx
private CX cx
-
mmrDecompressor
private MMRDecompressor mmrDecompressor
-
-
Constructor Detail
-
GenericRegion
public GenericRegion()
-
GenericRegion
public GenericRegion(SubInputStream subInputStream)
-
-
Method Detail
-
parseHeader
private void parseHeader() throws java.io.IOException, InvalidHeaderValueException
- Throws:
java.io.IOException
InvalidHeaderValueException
-
readGbAtPixels
private void readGbAtPixels(int amountOfGbAt) throws java.io.IOException
- Throws:
java.io.IOException
-
computeSegmentDataStructure
private void computeSegmentDataStructure() throws java.io.IOException
- Throws:
java.io.IOException
-
getRegionBitmap
public Bitmap getRegionBitmap() throws java.io.IOException
The procedure is described in 6.2.5.7, page 17.- Specified by:
getRegionBitmap
in interfaceRegion
- Returns:
- The decoded
Bitmap
of this region. - Throws:
java.io.IOException
- if an underlying IO operation fails
-
decodeSLTP
private int decodeSLTP() throws java.io.IOException
- Throws:
java.io.IOException
-
decodeLine
private void decodeLine(int lineNumber, int width, int rowStride, int paddedWidth) throws java.io.IOException
- Throws:
java.io.IOException
-
copyLineAbove
private void copyLineAbove(int lineNumber)
Each pixel gets the value from the corresponding pixel of the row above. Line 0 cannot get copied values (source will be -1, doesn't exist).- Parameters:
lineNumber
- - Coordinate of the row that should be set.
-
decodeTemplate0a
private void decodeTemplate0a(int lineNumber, int width, int rowStride, int paddedWidth, int byteIndex, int idx) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeTemplate0b
private void decodeTemplate0b(int lineNumber, int width, int rowStride, int paddedWidth, int byteIndex, int idx) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeTemplate1
private void decodeTemplate1(int lineNumber, int width, int rowStride, int paddedWidth, int byteIndex, int idx) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeTemplate2
private void decodeTemplate2(int lineNumber, int width, int rowStride, int paddedWidth, int byteIndex, int idx) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeTemplate3
private void decodeTemplate3(int lineNumber, int width, int rowStride, int paddedWidth, int byteIndex, int idx) throws java.io.IOException
- Throws:
java.io.IOException
-
updateOverrideFlags
private void updateOverrideFlags()
-
setOverrideFlag
private void setOverrideFlag(int index)
-
overrideAtTemplate0a
private int overrideAtTemplate0a(int context, int x, int y, int result, int minorX, int toShift) throws java.io.IOException
- Throws:
java.io.IOException
-
overrideAtTemplate0b
private int overrideAtTemplate0b(int context, int x, int y, int result, int minorX, int toShift) throws java.io.IOException
- Throws:
java.io.IOException
-
overrideAtTemplate1
private int overrideAtTemplate1(int context, int x, int y, int result, int minorX) throws java.io.IOException
- Throws:
java.io.IOException
-
overrideAtTemplate2
private int overrideAtTemplate2(int context, int x, int y, int result, int minorX) throws java.io.IOException
- Throws:
java.io.IOException
-
overrideAtTemplate3
private int overrideAtTemplate3(int context, int x, int y, int result, int minorX) throws java.io.IOException
- Throws:
java.io.IOException
-
getPixel
private byte getPixel(int x, int y) throws java.io.IOException
- Throws:
java.io.IOException
-
setParameters
protected void setParameters(boolean isMMREncoded, long dataOffset, long dataLength, int gbh, int gbw)
Used bySymbolDictionary
.- Parameters:
isMMREncoded
- the data is MMR encodeddataOffset
- the offsetdataLength
- the length of the datagbh
- bitmap heightgbw
- bitmap width
-
setParameters
protected void setParameters(boolean isMMREncoded, byte sdTemplate, boolean isTPGDon, boolean useSkip, short[] sdATX, short[] sdATY, int symWidth, int hcHeight, CX cx, ArithmeticDecoder arithmeticDecoder)
- Parameters:
isMMREncoded
- the data is MMR encodedsdTemplate
- sd templateisTPGDon
- is TPGDonuseSkip
- use skipsdATX
- x values gbA pixelssdATY
- y values gbA pixelssymWidth
- bitmap widthhcHeight
- bitmap heightcx
- context for the arithmetic decoderarithmeticDecoder
- the arithmetic decode to be used Used bySymbolDictionary
.
-
setParameters
protected void setParameters(boolean isMMREncoded, long dataOffset, long dataLength, int gbh, int gbw, byte gbTemplate, boolean isTPGDon, boolean useSkip, short[] gbAtX, short[] gbAtY)
Used byPatternDictionary
andHalftoneRegion
.- Parameters:
isMMREncoded
- the data is MMR encodeddataOffset
- the offsetdataLength
- the length of the datagbh
- bitmap heightgbw
- bitmap widthgbTemplate
- gb templateisTPGDon
- is TPGDonuseSkip
- use skipgbAtX
- x values of gbA pixelsgbAtY
- y values of gbA pixels
-
resetBitmap
protected void resetBitmap()
Simply sets the memory-critical bitmap of this region tonull
.
-
init
public void init(SegmentHeader header, SubInputStream sis) throws InvalidHeaderValueException, 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:
InvalidHeaderValueException
- if the segment header value is invalidjava.io.IOException
- if an underlying IO operation fails
-
getRegionInfo
public RegionSegmentInformation getRegionInfo()
Description copied from interface:Region
Simply returns theRegionSegmentInformation
.- Specified by:
getRegionInfo
in interfaceRegion
- Returns:
- The
RegionSegmentInformation
.
-
useExtTemplates
protected boolean useExtTemplates()
-
isTPGDon
protected boolean isTPGDon()
-
getGbTemplate
protected byte getGbTemplate()
-
isMMREncoded
protected boolean isMMREncoded()
-
getGbAtX
protected short[] getGbAtX()
-
getGbAtY
protected short[] getGbAtY()
-
-