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
The following commit(s) were added to refs/heads/master by this push:
new e05b440 PDFBOX-6151: fix equals so that last not fully used byte is
checked
e05b440 is described below
commit e05b440b7087c1776d230f0738efd381ad810127
Author: Tilman Hausherr <[email protected]>
AuthorDate: Sat Feb 14 12:24:48 2026 +0100
PDFBOX-6151: fix equals so that last not fully used byte is checked
---
src/main/java/org/apache/pdfbox/jbig2/Bitmap.java | 41 +++++++++++++++++++++--
1 file changed, 38 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
b/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
index b33b8f4..562b2ff 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
@@ -258,7 +258,7 @@ public class Bitmap
{
Arrays.fill(bitmap, fillByte);
}
-
+
@Override
public boolean equals(Object obj)
{
@@ -268,9 +268,44 @@ public class Bitmap
return false;
}
Bitmap other = (Bitmap)obj;
- return Arrays.equals(bitmap, other.bitmap);
+ if (Arrays.equals(bitmap, other.bitmap))
+ {
+ return true;
+ }
+ // the last byte can have differences e.g. because XNOR puts 1 in
unused parts
+ // maybe pixel difference
+ if (width != other.width || height != other.height)
+ {
+ return false;
+ }
+ if ((width % 8) == 0)
+ {
+ return false; // no extra bits, thus unequal for sure
+ }
+ int p = (rowStride - 1) * 8; // index of first pixel in last byte
+ for (int y = 0; y < height; ++y)
+ {
+ // compare stride except last byte
+ int idx = getByteIndex(0, y);
+ for (int i = idx; i < idx + rowStride - 1; ++i)
+ {
+ if (bitmap[i] != other.bitmap[i])
+ {
+ return false;
+ }
+ }
+ // compare the last bits
+ for (int x = p; x < width; ++x)
+ {
+ if (getPixel(x, y) != other.getPixel(x, y))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
}
-
+
/**
* Copy parts of the underlying array of a Bitmap to another Bitmap.
*