Class GenericRefinementRegionDecodingProcedure
- java.lang.Object
-
- org.apache.pdfbox.jbig2.decoder.GenericRefinementRegionDecodingProcedure
-
public class GenericRefinementRegionDecodingProcedure extends java.lang.ObjectImplements the JBIG2 Generic Refinement Region decoding procedure as defined in ITU-T T.88, §6.3 including the core decoding loop defined in §6.3.5.6.This class is purely algorithmic. It has no knowledge of how its inputs are obtained and no dependency on segment headers or input streams. The entry point is the static
decode()method; callers supply theArithmeticDecoderandCXcontext model directly, so they decide whether to create fresh instances or share existing ones:GenericRefinementRegion— creates its ownArithmeticDecoderandCX, then callsdecode().- Symbol dictionary refinement (§6.5.8.2) — passes the
parent dictionary's shared
ArithmeticDecoderandCX. - Text region refinement (§6.4) — passes the parent text
region's shared
ArithmeticDecoderandCX.
This class cannot be instantiated by callers. The private constructor and the internal
run(int, int, short, boolean, org.apache.pdfbox.jbig2.Bitmap, int, int, short[], short[])method exist solely to let the many private helper methods share state through fields rather than through long parameter lists.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGenericRefinementRegionDecodingProcedure.TemplateEncapsulates the template-specific operations: context bit formation (GenericRefinementRegionDecodingProcedure.Template.form(short, short, short, short, short)) and initial CX index selection (GenericRefinementRegionDecodingProcedure.Template.setIndex(org.apache.pdfbox.jbig2.decoder.arithmetic.CX)).private static classGenericRefinementRegionDecodingProcedure.Template0private static classGenericRefinementRegionDecodingProcedure.Template1
-
Field Summary
Fields Modifier and Type Field Description private ArithmeticDecoderarithDecoderprivate CXcxprivate boolean[]grAtOverrideprivate short[]grAtXprivate short[]grAtYprivate booleanoverrideprivate BitmapreferenceBitmapprivate intreferenceDXprivate intreferenceDYprivate BitmapregionBitmapThe bitmap being built; held as a field to avoid passing it everywhere.private static intSLTP_CONTEXT_TEMPLATE0private static intSLTP_CONTEXT_TEMPLATE1static GenericRefinementRegionDecodingProcedure.TemplateT0Singleton template 0 instance (stateless).static GenericRefinementRegionDecodingProcedure.TemplateT1Singleton template 1 instance (stateless).private GenericRefinementRegionDecodingProcedure.Templatetemplateprivate shorttemplateID
-
Constructor Summary
Constructors Modifier Constructor Description privateGenericRefinementRegionDecodingProcedure(ArithmeticDecoder arithDecoder, CX cx)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private intbuildContextT1(int x, int y)static Bitmapdecode(ArithmeticDecoder arithDecoder, CX cx, int width, int height, short grTemplate, boolean isTPGROn, Bitmap referenceBitmap, int referenceDX, int referenceDY, short[] grAtX, short[] grAtY)Executes the Generic Refinement Region decoding procedure (§6.3.5.6) and returns the decoded bitmap.private voiddecodeLineExplicitT1(int y, int width)private voiddecodeLineTPGRT1(int y, int width)private voiddecodeOptimized(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int lineOffset)private intdecodeSLTP()private voiddecodeTemplate(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int lineOffset, int byteIndex, int currentLine, int refByteIndex, GenericRefinementRegionDecodingProcedure.Template templateFormation)private voiddecodeTypicalPredictedLine(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride)private voiddecodeTypicalPredictedLineTemplate0(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int byteIndex, int currentLine, int refByteIndex)private voiddecodeTypicalPredictedLineTemplate1(int lineNumber, int width, int rowStride, int refRowStride, int paddedWidth, int deltaRefStride, int byteIndex, int currentLine, int refByteIndex)private intgetPixelSafe(Bitmap bitmap, int x, int y)private intgetReferenceBit(int x, int y)private intgetRegionBit(int x, int y)private intoverrideAtTemplate0(int context, int x, int y, int result, int minorX)private Bitmaprun(int width, int height, short grTemplate, boolean isTPGROn, Bitmap referenceBitmap, int referenceDX, int referenceDY, short[] grAtX, short[] grAtY)private voidupdateOverride()
-
-
-
Field Detail
-
SLTP_CONTEXT_TEMPLATE0
private static final int SLTP_CONTEXT_TEMPLATE0
- See Also:
- Constant Field Values
-
SLTP_CONTEXT_TEMPLATE1
private static final int SLTP_CONTEXT_TEMPLATE1
- See Also:
- Constant Field Values
-
T0
public static final GenericRefinementRegionDecodingProcedure.Template T0
Singleton template 0 instance (stateless).
-
T1
public static final GenericRefinementRegionDecodingProcedure.Template T1
Singleton template 1 instance (stateless).
-
arithDecoder
private final ArithmeticDecoder arithDecoder
-
cx
private final CX cx
-
templateID
private short templateID
-
template
private GenericRefinementRegionDecodingProcedure.Template template
-
referenceBitmap
private Bitmap referenceBitmap
-
referenceDX
private int referenceDX
-
referenceDY
private int referenceDY
-
grAtX
private short[] grAtX
-
grAtY
private short[] grAtY
-
override
private boolean override
-
grAtOverride
private boolean[] grAtOverride
-
regionBitmap
private Bitmap regionBitmap
The bitmap being built; held as a field to avoid passing it everywhere.
-
-
Constructor Detail
-
GenericRefinementRegionDecodingProcedure
private GenericRefinementRegionDecodingProcedure(ArithmeticDecoder arithDecoder, CX cx)
-
-
Method Detail
-
decode
public static Bitmap decode(ArithmeticDecoder arithDecoder, CX cx, int width, int height, short grTemplate, boolean isTPGROn, Bitmap referenceBitmap, int referenceDX, int referenceDY, short[] grAtX, short[] grAtY) throws java.io.IOException
Executes the Generic Refinement Region decoding procedure (§6.3.5.6) and returns the decoded bitmap.A short-lived instance is created internally so that the many private helper methods can share state through fields rather than through long parameter lists. No state survives the return of this method.
- Parameters:
arithDecoder- the arithmetic decoder — shared with the parent when called from a symbol dictionary or text region, or freshly created when called from a standalone segment; must not benullcx- the context model — shared or fresh, as above; must not benullwidth- decoded bitmap width (GRW); must be > 0height- decoded bitmap height (GRH); must be > 0grTemplate- template index: must be 0 or 1 (GRTEMPLATE)isTPGROn- whether typical prediction is enabled (TPGRON)referenceBitmap- the reference / base bitmap (GRREFERENCE); must not benullreferenceDX- horizontal offset of reference bitmap (GRREFERENCEDX)referenceDY- vertical offset of reference bitmap (GRREFERENCEDY)grAtX- AT pixel X offsets; required forgrTemplate == 0, must be a non-null array of length 2 in that case; ignored forgrTemplate == 1grAtY- AT pixel Y offsets; same requirements asgrAtX- Returns:
- the decoded bitmap
- Throws:
java.lang.IllegalArgumentException- if any parameter constraint above is violatedjava.io.IOException- if an underlying I/O operation fails
-
run
private Bitmap run(int width, int height, short grTemplate, boolean isTPGROn, Bitmap referenceBitmap, int referenceDX, int referenceDY, short[] grAtX, short[] grAtY) throws java.io.IOException
- Throws:
java.io.IOException
-
getPixelSafe
private int getPixelSafe(Bitmap bitmap, int x, int y)
-
getReferenceBit
private int getReferenceBit(int x, int y)
-
getRegionBit
private int getRegionBit(int x, int y)
-
buildContextT1
private int buildContextT1(int x, int y)
-
decodeLineExplicitT1
private void decodeLineExplicitT1(int y, int width) throws java.io.IOException- Throws:
java.io.IOException
-
decodeLineTPGRT1
private void decodeLineTPGRT1(int y, int width) throws java.io.IOException- Throws:
java.io.IOException
-
decodeSLTP
private int decodeSLTP() throws java.io.IOException- Throws:
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, GenericRefinementRegionDecodingProcedure.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)
-
-