mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-28 06:55:34 +00:00
immutable PointInt class => less object construction
This commit is contained in:
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.exporters.commonshape;
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.exporters.commonshape;
|
||||
|
||||
/**
|
||||
@@ -21,13 +22,23 @@ package com.jpexs.decompiler.flash.exporters.commonshape;
|
||||
*/
|
||||
public class PointInt {
|
||||
|
||||
|
||||
public int x;
|
||||
public static final PointInt MAX = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public PointInt(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
@@ -285,7 +285,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
|
||||
protected void exportFillPath(int groupIndex) {
|
||||
List<IMorphEdge> path = createPathFromEdgeMap(_fillEdgeMaps.get(groupIndex));
|
||||
PointInt pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
PointInt pos = PointInt.MAX;
|
||||
int fillStyleIdx = Integer.MAX_VALUE;
|
||||
if (path.size() > 0) {
|
||||
beginFills();
|
||||
@@ -296,7 +296,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
endFill();
|
||||
}
|
||||
fillStyleIdx = e.getFillStyleIdx();
|
||||
pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
pos = PointInt.MAX;
|
||||
try {
|
||||
Matrix matrix;
|
||||
Matrix matrixEnd;
|
||||
@@ -349,13 +349,13 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
}
|
||||
}
|
||||
if (!pos.equals(e.getFrom())) {
|
||||
moveTo(e.getFrom().x, e.getFrom().y, e.getFromEnd().x, e.getFromEnd().y);
|
||||
moveTo(e.getFrom().getX(), e.getFrom().getY(), e.getFromEnd().getX(), e.getFromEnd().getY());
|
||||
}
|
||||
if (e instanceof CurvedMorphEdge) {
|
||||
CurvedMorphEdge c = (CurvedMorphEdge) e;
|
||||
curveTo(c.getControl().x, c.getControl().y, c.to.x, c.to.y, c.getControlEnd().x, c.getControlEnd().y, c.toEnd.x, c.toEnd.y);
|
||||
curveTo(c.getControl().getX(), c.getControl().getY(), c.to.getX(), c.to.getY(), c.getControlEnd().getX(), c.getControlEnd().getY(), c.toEnd.getX(), c.toEnd.getY());
|
||||
} else {
|
||||
lineTo(e.getTo().x, e.getTo().y, e.getToEnd().x, e.getToEnd().y);
|
||||
lineTo(e.getTo().getX(), e.getTo().getY(), e.getToEnd().getX(), e.getToEnd().getY());
|
||||
}
|
||||
pos = e.getTo();
|
||||
}
|
||||
@@ -368,7 +368,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
|
||||
protected void exportLinePath(int groupIndex) {
|
||||
List<IMorphEdge> path = createPathFromEdgeMap(_lineEdgeMaps.get(groupIndex));
|
||||
PointInt pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
PointInt pos = PointInt.MAX;
|
||||
int lineStyleIdx = Integer.MAX_VALUE;
|
||||
if (path.size() > 0) {
|
||||
beginLines();
|
||||
@@ -376,7 +376,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
IMorphEdge e = path.get(i);
|
||||
if (lineStyleIdx != e.getLineStyleIdx()) {
|
||||
lineStyleIdx = e.getLineStyleIdx();
|
||||
pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
pos = PointInt.MAX;
|
||||
LINESTYLE lineStyle = null;
|
||||
LINESTYLE lineStyleEnd = null;
|
||||
try {
|
||||
@@ -452,13 +452,13 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
}
|
||||
}
|
||||
if (!e.getFrom().equals(pos)) {
|
||||
moveTo(e.getFrom().x, e.getFrom().y, e.getFromEnd().x, e.getFromEnd().y);
|
||||
moveTo(e.getFrom().getX(), e.getFrom().getY(), e.getFromEnd().getX(), e.getFromEnd().getY());
|
||||
}
|
||||
if (e instanceof CurvedMorphEdge) {
|
||||
CurvedMorphEdge c = (CurvedMorphEdge) e;
|
||||
curveTo(c.getControl().x, c.getControl().y, c.to.x, c.to.y, c.getControlEnd().x, c.getControlEnd().y, c.toEnd.x, c.toEnd.y);
|
||||
curveTo(c.getControl().getX(), c.getControl().getY(), c.to.getX(), c.to.getY(), c.getControlEnd().getX(), c.getControlEnd().getY(), c.toEnd.getX(), c.toEnd.getY());
|
||||
} else {
|
||||
lineTo(e.getTo().x, e.getTo().y, e.getToEnd().x, e.getToEnd().y);
|
||||
lineTo(e.getTo().getX(), e.getTo().getY(), e.getToEnd().getX(), e.getToEnd().getY());
|
||||
}
|
||||
pos = e.getTo();
|
||||
}
|
||||
@@ -515,7 +515,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
Map<String, List<IMorphEdge>> coordMap = new HashMap<>();
|
||||
for (int i = 0; i < path.size(); i++) {
|
||||
PointInt from = path.get(i).getFrom();
|
||||
String key = from.x + "_" + from.y;
|
||||
String key = from.getX() + "_" + from.getY();
|
||||
List<IMorphEdge> coordMapArray = coordMap.get(key);
|
||||
if (coordMapArray == null) {
|
||||
List<IMorphEdge> list = new ArrayList<>();
|
||||
@@ -529,7 +529,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
}
|
||||
|
||||
protected void removeEdgeFromCoordMap(Map<String, List<IMorphEdge>> coordMap, IMorphEdge edge) {
|
||||
String key = edge.getFrom().x + "_" + edge.getFrom().y;
|
||||
String key = edge.getFrom().getX() + "_" + edge.getFrom().getY();
|
||||
List<IMorphEdge> coordMapArray = coordMap.get(key);
|
||||
if (coordMapArray != null) {
|
||||
if (coordMapArray.size() == 1) {
|
||||
@@ -544,7 +544,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
}
|
||||
|
||||
protected IMorphEdge findNextEdgeInCoordMap(Map<String, List<IMorphEdge>> coordMap, IMorphEdge edge) {
|
||||
String key = edge.getTo().x + "_" + edge.getTo().y;
|
||||
String key = edge.getTo().getX() + "_" + edge.getTo().getY();
|
||||
List<IMorphEdge> coordMapArray = coordMap.get(key);
|
||||
if (coordMapArray != null && coordMapArray.size() > 0) {
|
||||
return coordMapArray.get(0);
|
||||
|
||||
@@ -224,7 +224,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
|
||||
protected void exportFillPath(int groupIndex) {
|
||||
List<IEdge> path = createPathFromEdgeMap(_fillEdgeMaps.get(groupIndex));
|
||||
PointInt pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
PointInt pos = PointInt.MAX;
|
||||
int fillStyleIdx = Integer.MAX_VALUE;
|
||||
if (path.size() > 0) {
|
||||
beginFills();
|
||||
@@ -235,7 +235,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
endFill();
|
||||
}
|
||||
fillStyleIdx = e.getFillStyleIdx();
|
||||
pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
pos = PointInt.MAX;
|
||||
try {
|
||||
Matrix matrix;
|
||||
FILLSTYLE fillStyle = _fillStyles.get(fillStyleIdx - 1);
|
||||
@@ -280,13 +280,13 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
}
|
||||
}
|
||||
if (!pos.equals(e.getFrom())) {
|
||||
moveTo(e.getFrom().x, e.getFrom().y);
|
||||
moveTo(e.getFrom().getX(), e.getFrom().getY());
|
||||
}
|
||||
if (e instanceof CurvedEdge) {
|
||||
CurvedEdge c = (CurvedEdge) e;
|
||||
curveTo(c.getControl().x, c.getControl().y, c.to.x, c.to.y);
|
||||
curveTo(c.getControl().getX(), c.getControl().getY(), c.to.getX(), c.to.getY());
|
||||
} else {
|
||||
lineTo(e.getTo().x, e.getTo().y);
|
||||
lineTo(e.getTo().getX(), e.getTo().getY());
|
||||
}
|
||||
pos = e.getTo();
|
||||
}
|
||||
@@ -299,7 +299,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
|
||||
protected void exportLinePath(int groupIndex) {
|
||||
List<IEdge> path = createPathFromEdgeMap(_lineEdgeMaps.get(groupIndex));
|
||||
PointInt pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
PointInt pos = PointInt.MAX;
|
||||
int lineStyleIdx = Integer.MAX_VALUE;
|
||||
if (path.size() > 0) {
|
||||
beginLines();
|
||||
@@ -307,7 +307,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
IEdge e = path.get(i);
|
||||
if (lineStyleIdx != e.getLineStyleIdx()) {
|
||||
lineStyleIdx = e.getLineStyleIdx();
|
||||
pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
pos = PointInt.MAX;
|
||||
LINESTYLE lineStyle = null;
|
||||
try {
|
||||
lineStyle = _lineStyles.get(lineStyleIdx - 1);
|
||||
@@ -373,13 +373,13 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
}
|
||||
}
|
||||
if (!e.getFrom().equals(pos)) {
|
||||
moveTo(e.getFrom().x, e.getFrom().y);
|
||||
moveTo(e.getFrom().getX(), e.getFrom().getY());
|
||||
}
|
||||
if (e instanceof CurvedEdge) {
|
||||
CurvedEdge c = (CurvedEdge) e;
|
||||
curveTo(c.getControl().x, c.getControl().y, c.to.x, c.to.y);
|
||||
curveTo(c.getControl().getX(), c.getControl().getY(), c.to.getX(), c.to.getY());
|
||||
} else {
|
||||
lineTo(e.getTo().x, e.getTo().y);
|
||||
lineTo(e.getTo().getX(), e.getTo().getY());
|
||||
}
|
||||
pos = e.getTo();
|
||||
}
|
||||
@@ -436,7 +436,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
Map<String, List<IEdge>> coordMap = new HashMap<>();
|
||||
for (int i = 0; i < path.size(); i++) {
|
||||
PointInt from = path.get(i).getFrom();
|
||||
String key = from.x + "_" + from.y;
|
||||
String key = from.getX() + "_" + from.getY();
|
||||
List<IEdge> coordMapArray = coordMap.get(key);
|
||||
if (coordMapArray == null) {
|
||||
List<IEdge> list = new ArrayList<>();
|
||||
@@ -450,7 +450,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
}
|
||||
|
||||
protected void removeEdgeFromCoordMap(Map<String, List<IEdge>> coordMap, IEdge edge) {
|
||||
String key = edge.getFrom().x + "_" + edge.getFrom().y;
|
||||
String key = edge.getFrom().getX() + "_" + edge.getFrom().getY();
|
||||
List<IEdge> coordMapArray = coordMap.get(key);
|
||||
if (coordMapArray != null) {
|
||||
if (coordMapArray.size() == 1) {
|
||||
@@ -465,7 +465,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
}
|
||||
|
||||
protected IEdge findNextEdgeInCoordMap(Map<String, List<IEdge>> coordMap, IEdge edge) {
|
||||
String key = edge.getTo().x + "_" + edge.getTo().y;
|
||||
String key = edge.getTo().getX() + "_" + edge.getTo().getY();
|
||||
List<IEdge> coordMapArray = coordMap.get(key);
|
||||
if (coordMapArray != null && coordMapArray.size() > 0) {
|
||||
return coordMapArray.get(0);
|
||||
|
||||
@@ -17,18 +17,26 @@
|
||||
package com.jpexs.decompiler.flash.tags.base;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
|
||||
import com.jpexs.decompiler.flash.exporters.shape.BitmapExporter;
|
||||
import com.jpexs.decompiler.flash.exporters.shape.CanvasShapeExporter;
|
||||
import com.jpexs.decompiler.flash.exporters.shape.PathExporter;
|
||||
import com.jpexs.decompiler.flash.exporters.shape.SVGShapeExporter;
|
||||
import com.jpexs.decompiler.flash.timeline.DepthState;
|
||||
import com.jpexs.decompiler.flash.types.ColorTransform;
|
||||
import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.PathIterator;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -37,6 +45,8 @@ import java.util.Set;
|
||||
*/
|
||||
public abstract class ShapeTag extends CharacterTag implements DrawableTag {
|
||||
|
||||
private final int markerSize = 10;
|
||||
|
||||
public ShapeTag(SWF swf, int id, String name, ByteArrayRange data) {
|
||||
super(swf, id, name, data);
|
||||
}
|
||||
@@ -53,6 +63,45 @@ public abstract class ShapeTag extends CharacterTag implements DrawableTag {
|
||||
@Override
|
||||
public void toImage(int frame, int time, int ratio, DepthState stateUnderCursor, int mouseButton, SerializableImage image, Matrix transformation, ColorTransform colorTransform) {
|
||||
BitmapExporter.export(swf, getShapes(), null, image, transformation, colorTransform);
|
||||
if (Configuration.debugMode.get()) { // show control points
|
||||
List<GeneralPath> paths = PathExporter.export(getShapes());
|
||||
double[] coords = new double[6];
|
||||
AffineTransform at = transformation.toTransform();
|
||||
at.preConcatenate(AffineTransform.getScaleInstance(1 / SWF.unitDivisor, 1 / SWF.unitDivisor));
|
||||
|
||||
// get the graphics from the inner image object, because it creates a new Graphics object
|
||||
Graphics2D graphics = (Graphics2D) image.getBufferedImage().getGraphics();
|
||||
graphics.setPaint(Color.black);
|
||||
for (GeneralPath path : paths) {
|
||||
PathIterator iterator = path.getPathIterator(at);
|
||||
while (!iterator.isDone()) {
|
||||
int type = iterator.currentSegment(coords);
|
||||
double x = coords[0];
|
||||
double y = coords[1];
|
||||
switch (type) {
|
||||
case PathIterator.SEG_MOVETO:
|
||||
graphics.drawRect((int) (x - markerSize / 2), (int) (y - markerSize / 2), markerSize, markerSize);
|
||||
break;
|
||||
case PathIterator.SEG_LINETO:
|
||||
graphics.drawRect((int) (x - markerSize / 2), (int) (y - markerSize / 2), markerSize, markerSize);
|
||||
break;
|
||||
case PathIterator.SEG_QUADTO:
|
||||
graphics.drawRect((int) (x - markerSize / 2), (int) (y - markerSize / 2), markerSize, markerSize);
|
||||
x = coords[2];
|
||||
y = coords[3];
|
||||
graphics.drawRect((int) (x - markerSize / 2), (int) (y - markerSize / 2), markerSize, markerSize);
|
||||
break;
|
||||
case PathIterator.SEG_CUBICTO:
|
||||
System.out.print("CUBICTO NOT SUPPORTED. ");
|
||||
break;
|
||||
case PathIterator.SEG_CLOSE:
|
||||
System.out.print("CLOSE NOT SUPPORTED. ");
|
||||
break;
|
||||
}
|
||||
iterator.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user