This is an automated email from the ASF dual-hosted git repository. tilman pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/pdfbox-jbig2.git
commit 3c9c2b3f30e4396cc940a204f1787168a4730d4f Author: Tilman Hausherr <[email protected]> AuthorDate: Sun Feb 1 10:39:55 2026 +0100 PDFBOX-6161: cut out the appropriate part of the page bitmap if there is no reference bitmap --- .../pdfbox/jbig2/segments/GenericRefinementRegion.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRefinementRegion.java b/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRefinementRegion.java index cf252c5..dc69def 100644 --- a/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRefinementRegion.java +++ b/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRefinementRegion.java @@ -17,6 +17,7 @@ package org.apache.pdfbox.jbig2.segments; +import java.awt.Rectangle; import java.io.IOException; import org.apache.pdfbox.jbig2.Bitmap; @@ -26,6 +27,7 @@ import org.apache.pdfbox.jbig2.decoder.arithmetic.ArithmeticDecoder; import org.apache.pdfbox.jbig2.decoder.arithmetic.CX; import org.apache.pdfbox.jbig2.err.IntegerMaxValueException; import org.apache.pdfbox.jbig2.err.InvalidHeaderValueException; +import org.apache.pdfbox.jbig2.image.Bitmaps; import org.apache.pdfbox.jbig2.io.SubInputStream; import org.apache.pdfbox.jbig2.util.CombinationOperator; @@ -288,7 +290,18 @@ public class GenericRefinementRegion implements Region // then its external combination operator must be REPLACE" throw new InvalidHeaderValueException("REPLACE combination operator expected"); } - return pageBitmap; + // See page 79: + // "The region segment is an immediate refinement region segment that refers to no other segments. + // In this case, the region segment is acting as a refinement of part of the page buffer." + // 7.4.7.4 Reference bitmap selection: + // If this segment does not refer to another region segment, set GRREFERENCE to be a bitmap containing the current + // contents of the page buffer (see clause 8), restricted to the area of the page buffer + // specified by this segment’s region segment information field. + Rectangle roi = new Rectangle(regionInfo.getXLocation(), + regionInfo.getYLocation(), + regionInfo.getBitmapWidth(), + regionInfo.getBitmapHeight()); + return Bitmaps.extract(roi, pageBitmap); } final Region region = (Region) segments[0].getSegmentData();
