pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1769322 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/SoftMask.java
Date Fri, 11 Nov 2016 18:20:08 GMT
Author: tilman
Date: Fri Nov 11 18:20:08 2016
New Revision: 1769322

URL: http://svn.apache.org/viewvc?rev=1769322&view=rev
Log:
PDFBOX-3000, PDFBOX-3564: use the colormodel corresponding to the source raster to convert
into the components, as suggested by PDFBOX-3564

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=1769322&r1=1769321&r2=1769322&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 Fri Nov 11
18:20:08 2016
@@ -91,6 +91,7 @@ class SoftMask implements Paint
         public Raster getRaster(int x1, int y1, int w, int h)
         {
             WritableRaster raster = (WritableRaster)context.getRaster(x1, y1, w, h);
+            ColorModel rasterCM = context.getColorModel();
 
             // buffer
             WritableRaster output = getColorModel().createCompatibleWritableRaster(w, h);
@@ -100,23 +101,28 @@ class SoftMask implements Paint
             y1 = y1 - (int)bboxDevice.getY();
 
             int[] gray = new int[4];
-            int[] rgba = new int[4];
+            Object pixelInput = null;
+            int[] pixelOutput = new int[4];
             for (int y = 0; y < h; y++)
             {
                 for (int x = 0; x < w; x++)
                 {
-                    raster.getPixel(x, y, rgba);
+                    pixelInput = raster.getDataElements(x, y, pixelInput);
 
+                    pixelOutput[0] = rasterCM.getRed(pixelInput);
+                    pixelOutput[1] = rasterCM.getGreen(pixelInput);
+                    pixelOutput[2] = rasterCM.getBlue(pixelInput);
+                    pixelOutput[3] = rasterCM.getAlpha(pixelInput);
+                    
                     // get the alpha value from the gray mask, if within mask bounds
                     gray[0] = 0;
                     if (x1 + x >= 0 && y1 + y >= 0 && x1 + x < mask.getWidth()
&& y1 + y < mask.getHeight())
                     {
                         mask.getRaster().getPixel(x1 + x, y1 + y, gray);
 
-                        // multiply alpha
-                        rgba[3] = Math.round(rgba[3] * (gray[0] / 255f));
+                        pixelOutput[3] = Math.round(pixelOutput[3] * (gray[0] / 255f));
                     }
-                    output.setPixel(x, y, rgba);
+                    output.setPixel(x, y, pixelOutput);
                 }
             }
 



Mime
View raw message