mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 12:00:45 +00:00
faster image rendering when layer has filters (only the required area is rendered)
This commit is contained in:
@@ -2454,14 +2454,45 @@ public final class SWF implements TreeItem {
|
||||
rect = mat.transform(rect);
|
||||
Matrix m = mat.clone();
|
||||
if (layer.filters != null) {
|
||||
// needs the whole size because of the filters
|
||||
img = new SerializableImage(image.getWidth(), image.getHeight(), SerializableImage.TYPE_INT_ARGB);
|
||||
} else {
|
||||
img = new SerializableImage((int) (rect.getWidth() / SWF.unitDivisor) + 1,
|
||||
(int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB);
|
||||
m.translate(-rect.xMin, -rect.yMin);
|
||||
drawMatrix.translate(rect.xMin, rect.yMin);
|
||||
// calculate size after applying the filters
|
||||
double deltaXMax = 0;
|
||||
double deltaYMax = 0;
|
||||
for (FILTER filter : layer.filters) {
|
||||
double x = filter.getDeltaX();
|
||||
double y = filter.getDeltaY();
|
||||
deltaXMax = Math.max(x, deltaXMax);
|
||||
deltaYMax = Math.max(y, deltaYMax);
|
||||
}
|
||||
rect.xMin -= deltaXMax * SWF.unitDivisor;
|
||||
rect.xMax += deltaXMax * SWF.unitDivisor;
|
||||
rect.yMin -= deltaYMax * SWF.unitDivisor;
|
||||
rect.yMax += deltaYMax * SWF.unitDivisor;
|
||||
}
|
||||
|
||||
// align to whole pixels
|
||||
rect.xMin = (int) (Math.floor(rect.xMin / SWF.unitDivisor) * SWF.unitDivisor);
|
||||
rect.yMin = (int) (Math.floor(rect.yMin / SWF.unitDivisor) * SWF.unitDivisor);
|
||||
rect.xMax = (int) (Math.ceil(rect.xMax / SWF.unitDivisor) * SWF.unitDivisor);
|
||||
rect.yMax = (int) (Math.ceil(rect.yMax / SWF.unitDivisor) * SWF.unitDivisor);
|
||||
|
||||
rect.xMin = Math.max(0, rect.xMin);
|
||||
rect.yMin = Math.max(0, rect.yMin);
|
||||
|
||||
int newWidth = (int) (rect.getWidth() / SWF.unitDivisor);
|
||||
int newHeight = (int) (rect.getHeight() / SWF.unitDivisor);
|
||||
int deltaX = (int) (rect.xMin / SWF.unitDivisor);
|
||||
int deltaY = (int) (rect.yMin / SWF.unitDivisor);
|
||||
newWidth = Math.min(image.getWidth() - deltaX, newWidth);
|
||||
newHeight = Math.min(image.getHeight() - deltaY, newHeight);
|
||||
|
||||
if (newWidth <= 0 || newHeight <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
img = new SerializableImage(newWidth, newHeight, SerializableImage.TYPE_INT_ARGB);
|
||||
m.translate(-rect.xMin, -rect.yMin);
|
||||
drawMatrix.translate(rect.xMin, rect.yMin);
|
||||
|
||||
//Make all pixels transparent
|
||||
Graphics2D gr = (Graphics2D) img.getGraphics();
|
||||
gr.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
|
||||
@@ -168,7 +168,7 @@ public class Configuration {
|
||||
public static final ConfigurationItem<String> locale = null;
|
||||
@ConfigurationDefaultString("_loc%d_")
|
||||
public static final ConfigurationItem<String> registerNameFormat = null;
|
||||
@ConfigurationDefaultInt(8)
|
||||
@ConfigurationDefaultInt(10)
|
||||
public static final ConfigurationItem<Integer> maxRecentFileCount = null;
|
||||
public static final ConfigurationItem<String> recentFiles = null;
|
||||
public static final ConfigurationItem<String> fontPairing = null;
|
||||
@@ -338,7 +338,7 @@ public class Configuration {
|
||||
recentFilesArray.remove(idx);
|
||||
}
|
||||
recentFilesArray.add(path);
|
||||
while (recentFilesArray.size() >= maxRecentFileCount.get()) {
|
||||
while (recentFilesArray.size() > maxRecentFileCount.get()) {
|
||||
recentFilesArray.remove(0);
|
||||
}
|
||||
recentFiles.set(Helper.joinStrings(recentFilesArray, "::"));
|
||||
|
||||
@@ -101,4 +101,14 @@ public class BEVELFILTER extends FILTER {
|
||||
}
|
||||
return Filtering.bevel(src, (int) blurX, (int) blurY, strength, type, highlightColor.toColor(), shadowColor.toColor(), (int) (angle * 180 / Math.PI), (float) distance, knockout, passes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaX() {
|
||||
return blurX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaY() {
|
||||
return blurY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,4 +55,14 @@ public class BLURFILTER extends FILTER {
|
||||
public SerializableImage apply(SerializableImage src) {
|
||||
return Filtering.blur(src, (int) blurX, (int) blurY, passes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaX() {
|
||||
return blurX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaY() {
|
||||
return blurY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,4 +51,14 @@ public class COLORMATRIXFILTER extends FILTER {
|
||||
//matrix2[4][4] = 1;
|
||||
return Filtering.colorMatrix(src, matrix2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaX() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaY() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,4 +89,14 @@ public class CONVOLUTIONFILTER extends FILTER {
|
||||
}
|
||||
return Filtering.convolution(src, matrix2, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaX() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaY() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,4 +86,14 @@ public class DROPSHADOWFILTER extends FILTER {
|
||||
public SerializableImage apply(SerializableImage src) {
|
||||
return Filtering.dropShadow(src, (int) blurX, (int) blurY, (int) (angle * 180 / Math.PI), distance, dropShadowColor.toColor(), innerShadow, passes, strength, knockout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaX() {
|
||||
return blurX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaY() {
|
||||
return blurY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.io.Serializable;
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class FILTER implements Serializable {
|
||||
public abstract class FILTER implements Serializable {
|
||||
|
||||
/**
|
||||
* Identificator of type of the filter
|
||||
@@ -43,7 +43,9 @@ public class FILTER implements Serializable {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public SerializableImage apply(SerializableImage src) {
|
||||
return src;
|
||||
}
|
||||
public abstract SerializableImage apply(SerializableImage src);
|
||||
|
||||
public abstract double getDeltaX();
|
||||
|
||||
public abstract double getDeltaY();
|
||||
}
|
||||
|
||||
@@ -76,4 +76,14 @@ public class GLOWFILTER extends FILTER {
|
||||
public SerializableImage apply(SerializableImage src) {
|
||||
return Filtering.glow(src, (int) blurX, (int) blurY, strength, glowColor.toColor(), innerGlow, knockout, passes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaX() {
|
||||
return blurX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaY() {
|
||||
return blurY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,4 +117,14 @@ public class GRADIENTBEVELFILTER extends FILTER {
|
||||
|
||||
return Filtering.gradientBevel(src, colorsArr, ratiosAr, (int) blurX, (int) blurY, strength, type, (int) (angle * 180 / Math.PI), (float) distance, knockout, passes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaX() {
|
||||
return blurX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaY() {
|
||||
return blurY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,4 +119,14 @@ public class GRADIENTGLOWFILTER extends FILTER {
|
||||
}
|
||||
return Filtering.gradientGlow(src, (int) blurX, (int) blurY, (int) (angle * 180 / Math.PI), distance, colors.toArray(new Color[colors.size()]), ratiosAr, type, passes, strength, knockout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaX() {
|
||||
return blurX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeltaY() {
|
||||
return blurY;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user