mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-05 00:05:27 +00:00
glitch fixed, text border, font y offset
This commit is contained in:
@@ -2225,9 +2225,6 @@ public final class SWF implements TreeItem {
|
||||
(int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB);
|
||||
//Make all pixels transparent
|
||||
Graphics2D g = (Graphics2D) image.getGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
g.setColor(new Color(0, 0, 0, 0f));
|
||||
g.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||
@@ -2374,9 +2371,6 @@ public final class SWF implements TreeItem {
|
||||
(int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB);
|
||||
//Make all pixels transparent
|
||||
Graphics2D g = (Graphics2D) image.getGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
g.setColor(new Color(0, 0, 0, 0f));
|
||||
g.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||
@@ -2469,12 +2463,6 @@ public final class SWF implements TreeItem {
|
||||
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);
|
||||
|
||||
@@ -2495,12 +2483,9 @@ public final class SWF implements TreeItem {
|
||||
|
||||
//Make all pixels transparent
|
||||
Graphics2D gr = (Graphics2D) img.getGraphics();
|
||||
gr.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
gr.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
gr.setComposite(AlphaComposite.Src);
|
||||
gr.setColor(new Color(0, 0, 0, 0f));
|
||||
gr.fillRect(0, 0, img.getWidth(), image.getHeight());
|
||||
gr.fillRect(0, 0, img.getWidth(), img.getHeight());
|
||||
drawable.toImage(dframe, layer.ratio, allTags, characters, visited, img, m, clrTrans);
|
||||
} else if (drawable instanceof FontTag) {
|
||||
// only DefineFont tags
|
||||
@@ -2589,7 +2574,7 @@ public final class SWF implements TreeItem {
|
||||
prevClips.add(g.getClip());
|
||||
g.setTransform(AffineTransform.getTranslateInstance(0, 0));
|
||||
g.setClip(clip.shape);
|
||||
} else {
|
||||
} else {
|
||||
g.setTransform(trans);
|
||||
g.drawImage(img.getBufferedImage(), 0, 0, null);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import java.awt.LinearGradientPaint;
|
||||
import java.awt.MultipleGradientPaint;
|
||||
import java.awt.Paint;
|
||||
import java.awt.RadialGradientPaint;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.TexturePaint;
|
||||
import java.awt.geom.AffineTransform;
|
||||
@@ -106,9 +105,6 @@ public class BitmapExporter extends ShapeExporterBase implements IShapeExporter
|
||||
double height = bounds.getHeight() / unitDivisor + 2 * (maxLineWidth + 1);
|
||||
image = new SerializableImage((int) width, (int) height, SerializableImage.TYPE_INT_ARGB);
|
||||
graphics = (Graphics2D) image.getGraphics();
|
||||
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
graphics.setComposite(AlphaComposite.Src);
|
||||
|
||||
//Make all pixels transparent
|
||||
|
||||
@@ -33,7 +33,6 @@ import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.HashMap;
|
||||
@@ -145,9 +144,6 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis
|
||||
(int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB);
|
||||
//Make all pixels transparent
|
||||
Graphics2D g = (Graphics2D) image.getGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
g.setColor(new Color(0, 0, 0, 0f));
|
||||
g.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||
@@ -233,9 +229,6 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis
|
||||
(int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB);
|
||||
//Make all pixels transparent
|
||||
Graphics2D g = (Graphics2D) image.getGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
g.setColor(new Color(0, 0, 0, 0f));
|
||||
g.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||
|
||||
@@ -205,6 +205,7 @@ public class DefineEditTextTag extends TextTag {
|
||||
TextStyle style = new TextStyle();
|
||||
style.font = getFontTag();
|
||||
style.fontHeight = fontHeight;
|
||||
style.fontLeading = leading;
|
||||
if (hasTextColor) {
|
||||
style.textColor = textColor;
|
||||
}
|
||||
@@ -258,6 +259,7 @@ public class DefineEditTextTag extends TextTag {
|
||||
if (firstChar != '+' && firstChar != '-') {
|
||||
int fontSize = Integer.parseInt(size);
|
||||
style.fontHeight = fontSize * style.font.getDivider();
|
||||
style.fontLeading = leading;
|
||||
} else {
|
||||
// todo: parse relative sizes
|
||||
}
|
||||
@@ -756,15 +758,19 @@ public class DefineEditTextTag extends TextTag {
|
||||
|
||||
@Override
|
||||
public void toImage(int frame, int ratio, List<Tag> tags, Map<Integer, CharacterTag> characters, Stack<Integer> visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) {
|
||||
if (border) {
|
||||
drawBorder(swf, image, textColor, getRect(characters, visited), getTextMatrix(), transformation, colorTransform);
|
||||
}
|
||||
if (hasText) {
|
||||
DynamicTextModel textModel = new DynamicTextModel();
|
||||
List<CharacterWithStyle> txt = getTextWithStyle();
|
||||
TextStyle lastStyle = null;
|
||||
char prevChar = 0;
|
||||
boolean lastWasWhiteSpace = false;
|
||||
for (int i = 0; i < txt.size(); i++) {
|
||||
CharacterWithStyle cs = txt.get(i);
|
||||
char c = cs.character;
|
||||
if (c != '\n') {
|
||||
if (c != '\r' && c != '\n') {
|
||||
// create new SameStyleTextRecord for all words and all diffrent style text parts
|
||||
if (lastWasWhiteSpace && !Character.isWhitespace(c)) {
|
||||
textModel.newWord();
|
||||
@@ -800,10 +806,13 @@ public class DefineEditTextTag extends TextTag {
|
||||
lastWasWhiteSpace = true;
|
||||
}
|
||||
} else {
|
||||
if (multiline) {
|
||||
textModel.newParagraph();
|
||||
if (c == '\r' || prevChar != '\r') {
|
||||
if (multiline) {
|
||||
textModel.newParagraph();
|
||||
}
|
||||
}
|
||||
}
|
||||
prevChar = c;
|
||||
}
|
||||
|
||||
textModel.calculateTexWidths();
|
||||
@@ -864,11 +873,15 @@ public class DefineEditTextTag extends TextTag {
|
||||
List<TEXTRECORD> allTextRecords = new ArrayList<>();
|
||||
int yOffset = 0;
|
||||
for (List<SameStyleTextRecord> line : lines) {
|
||||
yOffset += fontHeight;
|
||||
int width = 0;
|
||||
int currentOffset = 0;
|
||||
for (SameStyleTextRecord tr : line) {
|
||||
width += tr.width;
|
||||
if (tr.style.fontHeight + tr.style.fontLeading > currentOffset) {
|
||||
currentOffset = tr.style.fontHeight + tr.style.fontLeading;
|
||||
}
|
||||
}
|
||||
yOffset += currentOffset;
|
||||
int alignOffset = 0;
|
||||
switch (align) {
|
||||
case 0: // left
|
||||
|
||||
@@ -23,11 +23,17 @@ import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.text.ParseException;
|
||||
import com.jpexs.decompiler.flash.types.ColorTransform;
|
||||
import com.jpexs.decompiler.flash.types.GLYPHENTRY;
|
||||
import com.jpexs.decompiler.flash.types.LINESTYLE;
|
||||
import com.jpexs.decompiler.flash.types.LINESTYLEARRAY;
|
||||
import com.jpexs.decompiler.flash.types.MATRIX;
|
||||
import com.jpexs.decompiler.flash.types.RECT;
|
||||
import com.jpexs.decompiler.flash.types.RGB;
|
||||
import com.jpexs.decompiler.flash.types.SHAPE;
|
||||
import com.jpexs.decompiler.flash.types.TEXTRECORD;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
@@ -192,6 +198,43 @@ public abstract class TextTag extends CharacterTag implements BoundedTag, Drawab
|
||||
return att;
|
||||
}
|
||||
|
||||
public static void drawBorder(SWF swf, SerializableImage image, RGB color, RECT rect, MATRIX textMatrix, Matrix transformation, ColorTransform colorTransform) {
|
||||
Graphics2D g = (Graphics2D) image.getGraphics();
|
||||
Matrix mat = transformation.clone();
|
||||
mat = mat.concatenate(new Matrix(textMatrix));
|
||||
SHAPE shape = new SHAPE();
|
||||
shape.shapeRecords = new ArrayList<>();
|
||||
StyleChangeRecord style = new StyleChangeRecord();
|
||||
style.lineStyle = 1;
|
||||
style.stateLineStyle = true;
|
||||
style.stateMoveTo = true;
|
||||
style.lineStyles = new LINESTYLEARRAY();
|
||||
style.lineStyles.lineStyles = new LINESTYLE[1];
|
||||
LINESTYLE lineStyle = new LINESTYLE();
|
||||
lineStyle.color = color;
|
||||
lineStyle.width = 20;
|
||||
style.lineStyles.lineStyles[0] = lineStyle;
|
||||
shape.shapeRecords.add(style);
|
||||
StraightEdgeRecord top = new StraightEdgeRecord();
|
||||
top.generalLineFlag = true;
|
||||
top.deltaX = rect.getWidth();
|
||||
StraightEdgeRecord right = new StraightEdgeRecord();
|
||||
right.generalLineFlag = true;
|
||||
right.deltaY = rect.getHeight();
|
||||
StraightEdgeRecord bottom = new StraightEdgeRecord();
|
||||
bottom.generalLineFlag = true;
|
||||
bottom.deltaX = -rect.getWidth();
|
||||
StraightEdgeRecord left = new StraightEdgeRecord();
|
||||
left.generalLineFlag = true;
|
||||
left.deltaY = -rect.getHeight();
|
||||
shape.shapeRecords.add(top);
|
||||
shape.shapeRecords.add(right);
|
||||
shape.shapeRecords.add(bottom);
|
||||
shape.shapeRecords.add(left);
|
||||
shape.shapeRecords.add(new EndShapeRecord());
|
||||
BitmapExporter.exportTo(swf, shape, null, image, mat, colorTransform);
|
||||
}
|
||||
|
||||
public static void staticTextToImage(SWF swf, Map<Integer, CharacterTag> characters, List<TEXTRECORD> textRecords, int numText, SerializableImage image, MATRIX textMatrix, Matrix transformation, ColorTransform colorTransform) {
|
||||
Color textColor = new Color(0, 0, 0);
|
||||
FontTag font = null;
|
||||
|
||||
@@ -30,6 +30,8 @@ public class TextStyle {
|
||||
|
||||
public int fontHeight;
|
||||
|
||||
public int fontLeading;
|
||||
|
||||
public boolean bold;
|
||||
|
||||
public boolean italic;
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BandCombineOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.BufferedImageOp;
|
||||
import java.awt.image.ConvolveOp;
|
||||
import java.awt.image.Kernel;
|
||||
@@ -216,14 +217,14 @@ public class Filtering {
|
||||
}
|
||||
|
||||
public static SerializableImage blur(SerializableImage src, int hRadius, int vRadius, int iterations) {
|
||||
return blur(src, hRadius, vRadius, iterations, null);
|
||||
return new SerializableImage(blur(src.getBufferedImage(), hRadius, vRadius, iterations, null));
|
||||
}
|
||||
|
||||
private static SerializableImage blur(SerializableImage src, int hRadius, int vRadius, int iterations, int[] mask) {
|
||||
private static BufferedImage blur(BufferedImage src, int hRadius, int vRadius, int iterations, int[] mask) {
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
|
||||
SerializableImage dst = new SerializableImage(width, height, src.getType());
|
||||
BufferedImage dst = new BufferedImage(width, height, src.getType());
|
||||
|
||||
int[] inPixels = getRGB(src, 0, 0, width, height);
|
||||
premultiply(inPixels);
|
||||
@@ -238,30 +239,34 @@ public class Filtering {
|
||||
}
|
||||
|
||||
public static SerializableImage bevel(SerializableImage src, int blurX, int blurY, float strength, int type, Color highlightColor, Color shadowColor, float angle, float distance, boolean knockout, int iterations) {
|
||||
return gradientBevel(src, new Color[]{
|
||||
return new SerializableImage(gradientBevel(src.getBufferedImage(), new Color[]{
|
||||
highlightColor,
|
||||
new Color(highlightColor.getRed(), highlightColor.getGreen(), highlightColor.getBlue(), 0),
|
||||
new Color(shadowColor.getRed(), shadowColor.getGreen(), shadowColor.getBlue(), 0),
|
||||
shadowColor
|
||||
}, new float[]{0, 127f / 255f, 128f / 255f, 1}, blurX, blurY, strength, type, angle, distance, knockout, iterations);
|
||||
}, new float[]{0, 127f / 255f, 128f / 255f, 1}, blurX, blurY, strength, type, angle, distance, knockout, iterations));
|
||||
}
|
||||
|
||||
public static SerializableImage gradientBevel(SerializableImage src, Color[] colors, float[] ratios, int blurX, int blurY, float strength, int type, float angle, float distance, boolean knockout, int iterations) {
|
||||
return new SerializableImage(gradientBevel(src.getBufferedImage(), colors, ratios, blurX, blurY, strength, type, angle, distance, knockout, iterations));
|
||||
}
|
||||
|
||||
private static BufferedImage gradientBevel(BufferedImage src, Color[] colors, float[] ratios, int blurX, int blurY, float strength, int type, float angle, float distance, boolean knockout, int iterations) {
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
SerializableImage retImg = new SerializableImage(width, height, src.getType());
|
||||
BufferedImage retImg = new BufferedImage(width, height, src.getType());
|
||||
if (type == FULL) {
|
||||
SerializableImage partIn = gradientBevel(src, colors, ratios, blurX, blurY, strength, INNER, angle, distance, true, iterations);
|
||||
SerializableImage partOut = gradientBevel(src, colors, ratios, blurX, blurY, strength, OUTER, angle, distance, true, iterations);
|
||||
BufferedImage partIn = gradientBevel(src, colors, ratios, blurX, blurY, strength, INNER, angle, distance, true, iterations);
|
||||
BufferedImage partOut = gradientBevel(src, colors, ratios, blurX, blurY, strength, OUTER, angle, distance, true, iterations);
|
||||
Graphics2D g = (Graphics2D) retImg.getGraphics();
|
||||
g.drawImage(partIn.getBufferedImage(), 0, 0, null);
|
||||
g.drawImage(partIn, 0, 0, null);
|
||||
g.setComposite(AlphaComposite.SrcOver);
|
||||
g.drawImage(partOut.getBufferedImage(), 0, 0, null);
|
||||
g.drawImage(partOut, 0, 0, null);
|
||||
} else {
|
||||
boolean inner = type == INNER;
|
||||
|
||||
int[] srcPixels = getRGB(src, 0, 0, width, height);
|
||||
SerializableImage gradient = new SerializableImage(512, 1, SerializableImage.TYPE_INT_ARGB);
|
||||
BufferedImage gradient = new BufferedImage(512, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D gg = (Graphics2D) gradient.getGraphics();
|
||||
Point pnt1 = new Point(0, 0);
|
||||
Point pnt2 = new Point(512, 0);
|
||||
@@ -269,8 +274,8 @@ public class Filtering {
|
||||
gg.fill(new Rectangle(512, 1));
|
||||
int[] gradientPixels = getRGB(gradient, 0, 0, gradient.getWidth(), gradient.getHeight());
|
||||
|
||||
SerializableImage hilightIm = dropShadow(src, blurX, blurY, angle, distance, Color.black, inner, iterations, strength, true);//new DropShadowFilter(blurX, blurY, strength, inner ? highlightColor : shadowColor, angle, distance, inner, true, iterations).filter(src);
|
||||
SerializableImage shadowIm = dropShadow(src, blurX, blurY, angle + 180, distance, Color.black, inner, iterations, strength, true); //new DropShadowFilter(blurX, blurY, strength, inner ? shadowColor : highlightColor, angle + 180, distance, inner, true, iterations).filter(src);
|
||||
BufferedImage hilightIm = dropShadow(src, blurX, blurY, angle, distance, Color.black, inner, iterations, strength, true);//new DropShadowFilter(blurX, blurY, strength, inner ? highlightColor : shadowColor, angle, distance, inner, true, iterations).filter(src);
|
||||
BufferedImage shadowIm = dropShadow(src, blurX, blurY, angle + 180, distance, Color.black, inner, iterations, strength, true); //new DropShadowFilter(blurX, blurY, strength, inner ? shadowColor : highlightColor, angle + 180, distance, inner, true, iterations).filter(src);
|
||||
int[] hilight = getRGB(hilightIm, 0, 0, width, height);
|
||||
int[] shadow = getRGB(shadowIm, 0, 0, width, height);
|
||||
for (int i = 0; i < srcPixels.length; i++) {
|
||||
@@ -307,35 +312,43 @@ public class Filtering {
|
||||
if (!knockout) {
|
||||
Graphics2D g = (Graphics2D) retImg.getGraphics();
|
||||
g.setComposite(AlphaComposite.DstOver);
|
||||
g.drawImage(src.getBufferedImage(), 0, 0, null);
|
||||
g.drawImage(src, 0, 0, null);
|
||||
}
|
||||
return retImg;
|
||||
}
|
||||
|
||||
public static SerializableImage glow(SerializableImage src, int blurX, int blurY, float strength, Color color, boolean inner, boolean knockout, int iterations) {
|
||||
return dropShadow(src, blurX, blurY, 45, 0, color, inner, iterations, strength, knockout);
|
||||
return new SerializableImage(dropShadow(src.getBufferedImage(), blurX, blurY, 45, 0, color, inner, iterations, strength, knockout));
|
||||
}
|
||||
|
||||
public static SerializableImage dropShadow(SerializableImage src, int blurX, int blurY, float angle, double distance, Color color, boolean inner, int iterations, float strength, boolean knockout) {
|
||||
return new SerializableImage(dropShadow(src.getBufferedImage(), blurX, blurY, angle, distance, color, inner, iterations, strength, knockout));
|
||||
}
|
||||
|
||||
private static BufferedImage dropShadow(BufferedImage src, int blurX, int blurY, float angle, double distance, Color color, boolean inner, int iterations, float strength, boolean knockout) {
|
||||
return gradientGlow(src, blurX, blurY, angle, distance, new Color[]{new Color(color.getRed(), color.getGreen(), color.getBlue(), 0), color}, new float[]{0, 1}, inner ? INNER : OUTER, iterations, strength, knockout);
|
||||
}
|
||||
|
||||
public static SerializableImage gradientGlow(SerializableImage src, int blurX, int blurY, float angle, double distance, Color[] colors, float[] ratios, int type, int iterations, float strength, boolean knockout) {
|
||||
return new SerializableImage(gradientGlow(src.getBufferedImage(), blurX, blurY, angle, distance, colors, ratios, type, iterations, strength, knockout));
|
||||
}
|
||||
|
||||
private static BufferedImage gradientGlow(BufferedImage src, int blurX, int blurY, float angle, double distance, Color[] colors, float[] ratios, int type, int iterations, float strength, boolean knockout) {
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
SerializableImage retImg = new SerializableImage(width, height, src.getType());
|
||||
BufferedImage retImg = new BufferedImage(width, height, src.getType());
|
||||
|
||||
if (type == FULL) {
|
||||
SerializableImage partIn = gradientGlow(src, blurX, blurY, angle, distance, colors, ratios, INNER, iterations, strength, true);
|
||||
SerializableImage partOut = gradientGlow(src, blurX, blurY, angle, distance, colors, ratios, OUTER, iterations, strength, true);
|
||||
BufferedImage partIn = gradientGlow(src, blurX, blurY, angle, distance, colors, ratios, INNER, iterations, strength, true);
|
||||
BufferedImage partOut = gradientGlow(src, blurX, blurY, angle, distance, colors, ratios, OUTER, iterations, strength, true);
|
||||
Graphics2D g = (Graphics2D) retImg.getGraphics();
|
||||
g.drawImage(partIn.getBufferedImage(), 0, 0, null);
|
||||
g.drawImage(partIn, 0, 0, null);
|
||||
g.setComposite(AlphaComposite.SrcOver);
|
||||
g.drawImage(partOut.getBufferedImage(), 0, 0, null);
|
||||
g.drawImage(partOut, 0, 0, null);
|
||||
} else {
|
||||
boolean inner = type == INNER;
|
||||
|
||||
SerializableImage gradient = new SerializableImage(256, 1, SerializableImage.TYPE_INT_ARGB);
|
||||
BufferedImage gradient = new BufferedImage(256, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D gg = (Graphics2D) gradient.getGraphics();
|
||||
gg.setPaint(new LinearGradientPaint(new Point(0, 0), new Point(256, 0), ratios, colors));
|
||||
gg.fill(new Rectangle(256, 1));
|
||||
@@ -389,23 +402,23 @@ public class Filtering {
|
||||
Graphics2D g = (Graphics2D) retImg.getGraphics();
|
||||
//g.setComposite(inner ? AlphaComposite.DstOver : AlphaComposite.SrcOver);
|
||||
g.setComposite(AlphaComposite.DstOver);
|
||||
g.drawImage(src.getBufferedImage(), 0, 0, null);
|
||||
g.drawImage(src, 0, 0, null);
|
||||
}
|
||||
|
||||
return retImg;
|
||||
}
|
||||
|
||||
private static int[] getRGB(SerializableImage image, int x, int y, int width, int height) {
|
||||
private static int[] getRGB(BufferedImage image, int x, int y, int width, int height) {
|
||||
int type = image.getType();
|
||||
if (type == SerializableImage.TYPE_INT_ARGB || type == SerializableImage.TYPE_INT_RGB) {
|
||||
if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) {
|
||||
return (int[]) image.getRaster().getDataElements(x, y, width, height, null);
|
||||
}
|
||||
return image.getRGB(x, y, width, height, null, 0, width);
|
||||
}
|
||||
|
||||
private static void setRGB(SerializableImage image, int x, int y, int width, int height, int[] pixels) {
|
||||
private static void setRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
|
||||
int type = image.getType();
|
||||
if (type == SerializableImage.TYPE_INT_ARGB || type == SerializableImage.TYPE_INT_RGB) {
|
||||
if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) {
|
||||
image.getRaster().setDataElements(x, y, width, height, pixels);
|
||||
} else {
|
||||
image.setRGB(x, y, width, height, pixels, 0, width);
|
||||
@@ -413,9 +426,9 @@ public class Filtering {
|
||||
}
|
||||
|
||||
private static int[] moveRGB(int width, int height, int[] rgb, double deltaX, double deltaY, Color fill) {
|
||||
SerializableImage img = new SerializableImage(width, height, SerializableImage.TYPE_INT_ARGB);
|
||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
setRGB(img, 0, 0, width, height, rgb);
|
||||
SerializableImage retImg = new SerializableImage(width, height, SerializableImage.TYPE_INT_ARGB);
|
||||
BufferedImage retImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = (Graphics2D) retImg.getGraphics();
|
||||
g.setPaint(fill);
|
||||
g.fillRect(0, 0, width, height);
|
||||
@@ -425,15 +438,15 @@ public class Filtering {
|
||||
|
||||
g.setTransform(AffineTransform.getTranslateInstance(deltaX, deltaY));
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
g.drawImage(img.getBufferedImage(), 0, 0, null);
|
||||
g.drawImage(img, 0, 0, null);
|
||||
return getRGB(retImg, 0, 0, width, height);
|
||||
}
|
||||
|
||||
public static SerializableImage convolution(SerializableImage src, float[] matrix, int w, int h) {
|
||||
SerializableImage dst = new SerializableImage(src.getWidth(), src.getHeight(), src.getType());
|
||||
BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), src.getType());
|
||||
BufferedImageOp op = new ConvolveOp(new Kernel(w, h, matrix), ConvolveOp.EDGE_ZERO_FILL, new RenderingHints(null));
|
||||
op.filter(src.getBufferedImage(), dst.getBufferedImage());
|
||||
return dst;
|
||||
op.filter(src.getBufferedImage(), dst);
|
||||
return new SerializableImage(dst);
|
||||
}
|
||||
|
||||
public static SerializableImage colorMatrix(SerializableImage src, float[][] matrix) {
|
||||
@@ -473,8 +486,8 @@ public class Filtering {
|
||||
public static SerializableImage colorEffect(SerializableImage src,
|
||||
int redAddTerm, int greenAddTerm, int blueAddTerm, int alphaAddTerm,
|
||||
int redMultTerm, int greenMultTerm, int blueMultTerm, int alphaMultTerm) {
|
||||
SerializableImage dst = new SerializableImage(src.getWidth(), src.getHeight(), src.getType());
|
||||
int rgb[] = getRGB(src, 0, 0, src.getWidth(), src.getHeight());
|
||||
BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), src.getType());
|
||||
int rgb[] = getRGB(src.getBufferedImage(), 0, 0, src.getWidth(), src.getHeight());
|
||||
for (int i = 0; i < rgb.length; i++) {
|
||||
int a = (rgb[i] >> 24) & 0xff;
|
||||
int r = (rgb[i] >> 16) & 0xff;
|
||||
@@ -487,6 +500,6 @@ public class Filtering {
|
||||
rgb[i] = (a << 24) | (r << 16) | (g << 8) | (b);
|
||||
}
|
||||
setRGB(dst, 0, 0, src.getWidth(), src.getHeight(), rgb);
|
||||
return dst;
|
||||
return new SerializableImage(dst);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package com.jpexs.helpers;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.IndexColorModel;
|
||||
@@ -82,7 +84,11 @@ public class SerializableImage implements Serializable {
|
||||
if (graphics != null) {
|
||||
return graphics;
|
||||
}
|
||||
return graphics = image.getGraphics();
|
||||
Graphics2D g = (Graphics2D) image.getGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
return graphics = g;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
|
||||
Reference in New Issue
Block a user