From ed05bf3cf1d23638f512176ed0121a5464bf74bb Mon Sep 17 00:00:00 2001 From: Honfika Date: Wed, 29 Jan 2014 23:47:11 +0100 Subject: [PATCH] morphshape rendering fix (but still wrong) --- .../flash/exporters/CurvedEdge.java | 6 +- .../decompiler/flash/exporters/IEdge.java | 4 +- .../decompiler/flash/exporters/PointInt.java | 49 ++++++++++ .../flash/exporters/ShapeExporterBase.java | 39 ++++---- .../flash/exporters/StraightEdge.java | 10 +- .../decompiler/flash/gui/ImagePanel.java | 3 +- .../flash/tags/DefineMorphShapeTag.java | 96 ++++++++++--------- .../decompiler/flash/tags/base/TextTag.java | 2 +- .../com/jpexs/helpers/SerializableImage.java | 4 +- 9 files changed, 132 insertions(+), 81 deletions(-) create mode 100644 trunk/src/com/jpexs/decompiler/flash/exporters/PointInt.java diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/CurvedEdge.java b/trunk/src/com/jpexs/decompiler/flash/exporters/CurvedEdge.java index 7a5830ce1..c9ad3d156 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/CurvedEdge.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/CurvedEdge.java @@ -22,14 +22,14 @@ package com.jpexs.decompiler.flash.exporters; */ public class CurvedEdge extends StraightEdge implements IEdge { - private final Point control; + private final PointInt control; - CurvedEdge(Point from, Point control, Point to, int lineStyleIdx, int fillStyleIdx) { + CurvedEdge(PointInt from, PointInt control, PointInt to, int lineStyleIdx, int fillStyleIdx) { super(from, to, lineStyleIdx, fillStyleIdx); this.control = control; } - public Point getControl() { + public PointInt getControl() { return control; } diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/IEdge.java b/trunk/src/com/jpexs/decompiler/flash/exporters/IEdge.java index 1c7342308..774ffe9e7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/IEdge.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/IEdge.java @@ -22,9 +22,9 @@ package com.jpexs.decompiler.flash.exporters; */ public interface IEdge { - public Point getFrom(); + public PointInt getFrom(); - public Point getTo(); + public PointInt getTo(); public int getLineStyleIdx(); diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/PointInt.java b/trunk/src/com/jpexs/decompiler/flash/exporters/PointInt.java new file mode 100644 index 000000000..a1d2c347b --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/PointInt.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2010-2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.jpexs.decompiler.flash.exporters; + +/** + * + * @author JPEXS + */ +public class PointInt { + + public int x; + public int y; + + public PointInt(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public int hashCode() { + long bits = Double.doubleToLongBits(x); + bits ^= Double.doubleToLongBits(y) * 31; + return (((int) bits) ^ ((int) (bits >> 32))); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof PointInt) { + PointInt pt = (PointInt) obj; + return (x == pt.x) && (y == pt.y); + } + return super.equals(obj); + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/ShapeExporterBase.java b/trunk/src/com/jpexs/decompiler/flash/exporters/ShapeExporterBase.java index 1449c77cf..020a0e921 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/ShapeExporterBase.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/ShapeExporterBase.java @@ -86,11 +86,8 @@ public abstract class ShapeExporterBase implements IShapeExporter { protected void createEdgeMaps() { if (!edgeMapsCreated) { - double xPos = 0; - double yPos = 0; - Point from; - Point to; - Point control; + int xPos = 0; + int yPos = 0; int fillStyleIdxOffset = 0; int lineStyleIdxOffset = 0; int currentFillStyleIdx0 = 0; @@ -158,7 +155,7 @@ public abstract class ShapeExporterBase implements IShapeExporter { } } else if (shapeRecord instanceof StraightEdgeRecord) { StraightEdgeRecord straightEdgeRecord = (StraightEdgeRecord) shapeRecord; - from = new Point(xPos, yPos); + PointInt from = new PointInt(xPos, yPos); if (straightEdgeRecord.generalLineFlag) { xPos += straightEdgeRecord.deltaX; yPos += straightEdgeRecord.deltaY; @@ -169,17 +166,17 @@ public abstract class ShapeExporterBase implements IShapeExporter { xPos += straightEdgeRecord.deltaX; } } - to = new Point(xPos, yPos); + PointInt to = new PointInt(xPos, yPos); subPath.add(new StraightEdge(from, to, currentLineStyleIdx, currentFillStyleIdx1)); } else if (shapeRecord instanceof CurvedEdgeRecord) { CurvedEdgeRecord curvedEdgeRecord = (CurvedEdgeRecord) shapeRecord; - from = new Point(xPos, yPos); - double xPosControl = xPos + curvedEdgeRecord.controlDeltaX; - double yPosControl = yPos + curvedEdgeRecord.controlDeltaY; + PointInt from = new PointInt(xPos, yPos); + int xPosControl = xPos + curvedEdgeRecord.controlDeltaX; + int yPosControl = yPos + curvedEdgeRecord.controlDeltaY; xPos = xPosControl + curvedEdgeRecord.anchorDeltaX; yPos = yPosControl + curvedEdgeRecord.anchorDeltaY; - control = new Point(xPosControl, yPosControl); - to = new Point(xPos, yPos); + PointInt control = new PointInt(xPosControl, yPosControl); + PointInt to = new PointInt(xPos, yPos); subPath.add(new CurvedEdge(from, control, to, currentLineStyleIdx, currentFillStyleIdx1)); } else if (shapeRecord instanceof EndShapeRecord) { // We're done. Process the last subpath, if any @@ -226,18 +223,18 @@ public abstract class ShapeExporterBase implements IShapeExporter { } private void calculateBound(IEdge edge) { - Point from = edge.getFrom(); - Point to = edge.getTo(); + PointInt from = edge.getFrom(); + PointInt to = edge.getTo(); calculateBound(from); calculateBound(to); if (edge instanceof CurvedEdge) { CurvedEdge curvedEdge = (CurvedEdge) edge; - Point control = curvedEdge.getControl(); + PointInt control = curvedEdge.getControl(); calculateBound(control); } } - private void calculateBound(Point point) { + private void calculateBound(PointInt point) { if (point.x < bounds.xMin) { bounds.xMin = point.x; } @@ -254,7 +251,7 @@ public abstract class ShapeExporterBase implements IShapeExporter { protected void exportFillPath(int groupIndex) { List path = createPathFromEdgeMap(fillEdgeMaps.get(groupIndex)); - Point pos = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); + PointInt pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE); int fillStyleIdx = Integer.MAX_VALUE; if (path.size() > 0) { beginFills(); @@ -266,7 +263,7 @@ public abstract class ShapeExporterBase implements IShapeExporter { endFill(); } fillStyleIdx = e.getFillStyleIdx(); - pos = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); + pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE); try { Matrix matrix; FILLSTYLE fillStyle = _fillStyles.get(fillStyleIdx - 1); @@ -329,7 +326,7 @@ public abstract class ShapeExporterBase implements IShapeExporter { protected void exportLinePath(int groupIndex) { List path = createPathFromEdgeMap(lineEdgeMaps.get(groupIndex)); - Point pos = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); + PointInt pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE); int lineStyleIdx = Integer.MAX_VALUE; LINESTYLE lineStyle; if (path.size() > 0) { @@ -339,7 +336,7 @@ public abstract class ShapeExporterBase implements IShapeExporter { calculateBound(e); if (lineStyleIdx != e.getLineStyleIdx()) { lineStyleIdx = e.getLineStyleIdx(); - pos = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); + pos = new PointInt(Integer.MAX_VALUE, Integer.MAX_VALUE); try { lineStyle = _lineStyles.get(lineStyleIdx - 1); } catch (Exception ex) { @@ -467,7 +464,7 @@ public abstract class ShapeExporterBase implements IShapeExporter { protected void createCoordMap(List path) { coordMap = new HashMap<>(); for (int i = 0; i < path.size(); i++) { - Point from = path.get(i).getFrom(); + PointInt from = path.get(i).getFrom(); String key = from.x + "_" + from.y; List coordMapArray = coordMap.get(key); if (coordMapArray == null) { diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/StraightEdge.java b/trunk/src/com/jpexs/decompiler/flash/exporters/StraightEdge.java index 8877a4c2b..a744ad24c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/StraightEdge.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/StraightEdge.java @@ -22,12 +22,12 @@ package com.jpexs.decompiler.flash.exporters; */ public class StraightEdge implements IEdge { - protected final Point from; - protected final Point to; + protected final PointInt from; + protected final PointInt to; protected final int lineStyleIdx; private final int fillStyleIdx; - StraightEdge(Point from, Point to, int lineStyleIdx, int fillStyleIdx) { + StraightEdge(PointInt from, PointInt to, int lineStyleIdx, int fillStyleIdx) { this.from = from; this.to = to; this.lineStyleIdx = lineStyleIdx; @@ -35,12 +35,12 @@ public class StraightEdge implements IEdge { } @Override - public Point getFrom() { + public PointInt getFrom() { return from; } @Override - public Point getTo() { + public PointInt getTo() { return to; } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 3ca5c569c..3863f314e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -47,7 +47,7 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis public DrawableTag drawable; private Timer timer; private int percent; - private int frame; + private int frame = -1; private SWF swf; private HashMap characters; private int frameRate; @@ -195,6 +195,7 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis mat.translate(img.bounds.getMinX(), img.bounds.getMinY()); ImageIcon icon = new ImageIcon(img.getBufferedImage()); label.setIcon(icon); + frame = nframe; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java index 1ec729272..1a40c22aa 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java @@ -181,71 +181,75 @@ public class DefineMorphShapeTag extends CharacterTag implements BoundedTag, Mor List finalRecords = new ArrayList<>(); FILLSTYLEARRAY fillStyles = morphFillStyles.getFillStylesAt(frame); LINESTYLEARRAY lineStyles = morphLineStyles.getLineStylesAt(getShapeNum(), frame); - int endIndex = 0; - for (int startIndex = 0; startIndex < startEdges.shapeRecords.size(); startIndex++, endIndex++) { + for (int startIndex = 0; startIndex < startEdges.shapeRecords.size(); startIndex++) { - if (startIndex == 0) { + SHAPERECORD edge1 = startEdges.shapeRecords.get(startIndex); + SHAPERECORD edge2 = endEdges.shapeRecords.get(startIndex); + if (edge1 instanceof StyleChangeRecord || edge2 instanceof StyleChangeRecord) { StyleChangeRecord scr1 = (StyleChangeRecord) startEdges.shapeRecords.get(startIndex); - StyleChangeRecord scr2 = (StyleChangeRecord) startEdges.shapeRecords.get(endIndex); + StyleChangeRecord scr2 = (StyleChangeRecord) startEdges.shapeRecords.get(startIndex); StyleChangeRecord scr = (StyleChangeRecord) scr1.clone(); - if (scr1.stateMoveTo && scr2.stateMoveTo) { + if (scr1.stateMoveTo) { scr.moveDeltaX = scr1.moveDeltaX + (scr2.moveDeltaX - scr1.moveDeltaX) * frame / 65535; scr.moveDeltaY = scr1.moveDeltaY + (scr2.moveDeltaY - scr1.moveDeltaY) * frame / 65535; - finalRecords.add(scr); - continue; } + finalRecords.add(scr); + continue; } - SHAPERECORD edge1 = null; - do { - edge1 = startEdges.shapeRecords.get(startIndex); - if (edge1 instanceof StyleChangeRecord) { - finalRecords.add(edge1); - edge1 = null; - startIndex++; - } - } while (edge1 == null); - SHAPERECORD edge2 = endEdges.shapeRecords.get(endIndex); + if (edge1 instanceof EndShapeRecord) { finalRecords.add(edge1); break; } if (edge2 instanceof EndShapeRecord) { + finalRecords.add(edge2); break; } - if ((edge1 instanceof StyleChangeRecord) && (edge2 instanceof StyleChangeRecord)) { - StyleChangeRecord scr1 = (StyleChangeRecord) edge1; - StyleChangeRecord scr2 = (StyleChangeRecord) edge2; - StyleChangeRecord scr = (StyleChangeRecord) scr1.clone(); - if (scr1.stateMoveTo && scr2.stateMoveTo) { - scr.moveDeltaX = scr1.moveDeltaX + (scr2.moveDeltaX - scr1.moveDeltaX) * frame / 65535; - scr.moveDeltaY = scr1.moveDeltaY + (scr2.moveDeltaY - scr1.moveDeltaY) * frame / 65535; - finalRecords.add(scr); + + if (edge1 instanceof CurvedEdgeRecord || edge2 instanceof CurvedEdgeRecord) { + CurvedEdgeRecord cer1 = null; + if (edge1 instanceof CurvedEdgeRecord) { + cer1 = (CurvedEdgeRecord) edge1; + } else if (edge1 instanceof StraightEdgeRecord) { + cer1 = SHAPERECORD.straightToCurve((StraightEdgeRecord) edge1); + } + CurvedEdgeRecord cer2 = null; + if (edge2 instanceof CurvedEdgeRecord) { + cer2 = (CurvedEdgeRecord) edge2; + } else if (edge2 instanceof StraightEdgeRecord) { + cer2 = SHAPERECORD.straightToCurve((StraightEdgeRecord) edge2); + } + if ((cer2 == null) || (cer1 == null)) { continue; } + CurvedEdgeRecord cer = new CurvedEdgeRecord(); + cer.controlDeltaX = cer1.controlDeltaX + (cer2.controlDeltaX - cer1.controlDeltaX) * frame / 65535; + cer.controlDeltaY = cer1.controlDeltaY + (cer2.controlDeltaY - cer1.controlDeltaY) * frame / 65535; + cer.anchorDeltaX = cer1.anchorDeltaX + (cer2.anchorDeltaX - cer1.anchorDeltaX) * frame / 65535; + cer.anchorDeltaY = cer1.anchorDeltaY + (cer2.anchorDeltaY - cer1.anchorDeltaY) * frame / 65535; + finalRecords.add(cer); + } else { + StraightEdgeRecord ser1 = null; + if (edge1 instanceof StraightEdgeRecord) { + ser1 = (StraightEdgeRecord) edge1; + } + StraightEdgeRecord ser2 = null; + if (edge2 instanceof StraightEdgeRecord) { + ser2 = (StraightEdgeRecord) edge2; + } + if ((ser2 == null) || (ser1 == null)) { + continue; + } + StraightEdgeRecord ser = new StraightEdgeRecord(); + ser.generalLineFlag = true; + ser.vertLineFlag = false; + ser.deltaX = ser1.deltaX + (ser2.deltaX - ser1.deltaX) * frame / 65535; + ser.deltaY = ser1.deltaY + (ser2.deltaY - ser1.deltaY) * frame / 65535; + finalRecords.add(ser); } - CurvedEdgeRecord cer1 = null; - if (edge1 instanceof CurvedEdgeRecord) { - cer1 = (CurvedEdgeRecord) edge1; - } else if (edge1 instanceof StraightEdgeRecord) { - cer1 = SHAPERECORD.straightToCurve((StraightEdgeRecord) edge1); - } - CurvedEdgeRecord cer2 = null; - if (edge2 instanceof CurvedEdgeRecord) { - cer2 = (CurvedEdgeRecord) edge2; - } else if (edge2 instanceof StraightEdgeRecord) { - cer2 = SHAPERECORD.straightToCurve((StraightEdgeRecord) edge2); - } - if ((cer2 == null) || (cer1 == null)) { - continue; - } - CurvedEdgeRecord cer = new CurvedEdgeRecord(); - cer.controlDeltaX = cer1.controlDeltaX + (cer2.controlDeltaX - cer1.controlDeltaX) * frame / 65535; - cer.controlDeltaY = cer1.controlDeltaY + (cer2.controlDeltaY - cer1.controlDeltaY) * frame / 65535; - cer.anchorDeltaX = cer1.anchorDeltaX + (cer2.anchorDeltaX - cer1.anchorDeltaX) * frame / 65535; - cer.anchorDeltaY = cer1.anchorDeltaY + (cer2.anchorDeltaY - cer1.anchorDeltaY) * frame / 65535; - finalRecords.add(cer); } + finalRecords.add(new EndShapeRecord()); SHAPEWITHSTYLE shape = new SHAPEWITHSTYLE(); shape.fillStyles = fillStyles; shape.lineStyles = lineStyles; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java index df6cd6d19..0f458decb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -238,7 +238,7 @@ public abstract class TextTag extends CharacterTag implements BoundedTag { SHAPE shape = glyphs.get(entry.glyphIndex); SerializableImage img = BitmapExporter.export(swf, shape, textColor, true); AffineTransform tr = new AffineTransform(); - double rat = (double) textHeight / 1000.0; + double rat = textHeight / 1024.0; tr.translate(x / unzoom + img.bounds.getMinX() * rat + fixX, y / unzoom + img.bounds.getMinY() * rat + fixY); tr.scale(1.0 / font.getDivider(), 1.0 / font.getDivider()); tr.scale(rat, rat); diff --git a/trunk/src/com/jpexs/helpers/SerializableImage.java b/trunk/src/com/jpexs/helpers/SerializableImage.java index 392035912..65c065b72 100644 --- a/trunk/src/com/jpexs/helpers/SerializableImage.java +++ b/trunk/src/com/jpexs/helpers/SerializableImage.java @@ -69,11 +69,11 @@ public class SerializableImage implements Serializable { } public BufferedImage getBufferedImage() { - /*try { + try { ImageIO.write(image, "png", new File("c:\\10\\x\\imageid" + String.format("%03d", imageid++) + ".png")); } catch (IOException ex) { Logger.getLogger(BitmapExporter.class.getName()).log(Level.SEVERE, null, ex); - }*/ + } return image; }