You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/10/05 16:09:24 UTC
svn commit: r1763463 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/SoftMask.java
Author: tilman
Date: Wed Oct 5 16:09:24 2016
New Revision: 1763463
URL: http://svn.apache.org/viewvc?rev=1763463&view=rev
Log:
PDFBOX-3000: avoid ArrayIndexOutOfBoundsException, simplify output raster creation, assign rgba[3] only if within bounds
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/SoftMask.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/SoftMask.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/SoftMask.java?rev=1763463&r1=1763462&r2=1763463&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/SoftMask.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/SoftMask.java Wed Oct 5 16:09:24 2016
@@ -93,8 +93,7 @@ class SoftMask implements Paint
WritableRaster raster = (WritableRaster)context.getRaster(x1, y1, w, h);
// buffer
- BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
- WritableRaster output = image.getRaster();
+ WritableRaster output = getColorModel().createCompatibleWritableRaster(w, h);
// the soft mask has its own bbox
x1 = x1 - (int)bboxDevice.getX();
@@ -110,18 +109,13 @@ class SoftMask implements Paint
// get the alpha value from the gray mask, if within mask bounds
gray[0] = 0;
- if (x1 + x < mask.getWidth() && y1 + y < mask.getHeight())
+ if (x1 + x >= 0 && y1 + y >= 0 && x1 + x < mask.getWidth() && y1 + y < mask.getHeight())
{
- try
- {
- mask.getRaster().getPixel(x1 + x, y1 + y, gray);
- }
- catch (ArrayIndexOutOfBoundsException e)
- {
- //TODO bounds check not yet correct
- }
+ mask.getRaster().getPixel(x1 + x, y1 + y, gray);
+
+ // multiply alpha
+ rgba[3] = Math.round(rgba[3] * (gray[0] / 255f));
}
- rgba[3] = Math.round(rgba[3] * (gray[0] / 255f)); // multiply alpha
output.setPixel(x, y, rgba);
}
}