Merge "Remove BufferedImage allocation from PorterDuff filter" into mnc-ub-dev
This commit is contained in:
@@ -48,7 +48,7 @@ public class PorterDuffColorFilter_Delegate extends ColorFilter_Delegate {
|
|||||||
|
|
||||||
// ---- delegate data ----
|
// ---- delegate data ----
|
||||||
|
|
||||||
private final int mSrcColor;
|
private final java.awt.Color mSrcColor;
|
||||||
private final Mode mMode;
|
private final Mode mMode;
|
||||||
|
|
||||||
|
|
||||||
@@ -66,9 +66,9 @@ public class PorterDuffColorFilter_Delegate extends ColorFilter_Delegate {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyFilter(Graphics2D g, int width, int height) {
|
public void applyFilter(Graphics2D g, int width, int height) {
|
||||||
BufferedImage image = createFilterImage(width, height);
|
|
||||||
g.setComposite(getComposite(mMode, 0xFF));
|
g.setComposite(getComposite(mMode, 0xFF));
|
||||||
g.drawImage(image, 0, 0, null);
|
g.setColor(mSrcColor);
|
||||||
|
g.fillRect(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- native methods ----
|
// ---- native methods ----
|
||||||
@@ -84,22 +84,10 @@ public class PorterDuffColorFilter_Delegate extends ColorFilter_Delegate {
|
|||||||
// ---- Private delegate/helper methods ----
|
// ---- Private delegate/helper methods ----
|
||||||
|
|
||||||
private PorterDuffColorFilter_Delegate(int srcColor, int mode) {
|
private PorterDuffColorFilter_Delegate(int srcColor, int mode) {
|
||||||
mSrcColor = srcColor;
|
mSrcColor = new java.awt.Color(srcColor, true /* hasAlpha */);
|
||||||
mMode = getCompatibleMode(getPorterDuffMode(mode));
|
mMode = getCompatibleMode(getPorterDuffMode(mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
private BufferedImage createFilterImage(int width, int height) {
|
|
||||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
|
||||||
Graphics2D graphics = image.createGraphics();
|
|
||||||
try {
|
|
||||||
graphics.setColor(new java.awt.Color(mSrcColor, true /* hasAlpha */));
|
|
||||||
graphics.fillRect(0, 0, width, height);
|
|
||||||
} finally {
|
|
||||||
graphics.dispose();
|
|
||||||
}
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For filtering the colors, the src image should contain the "color" only for pixel values
|
// For filtering the colors, the src image should contain the "color" only for pixel values
|
||||||
// which are not transparent in the target image. But, we are using a simple rectangular image
|
// which are not transparent in the target image. But, we are using a simple rectangular image
|
||||||
// completely filled with color. Hence some Composite rules do not apply as intended. However,
|
// completely filled with color. Hence some Composite rules do not apply as intended. However,
|
||||||
|
|||||||
Reference in New Issue
Block a user