From a44221b3632272f5342d8abb2db74fc5f6ee3437 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Tue, 13 Dec 2016 12:46:53 +0100 Subject: [PATCH] Character tag removing simplified/fixed --- .../src/com/jpexs/decompiler/flash/SWF.java | 49 +++++++------------ .../flash/iggy/streams/SeekMode.java | 2 +- .../flash/tags/PlaceObject2Tag.java | 11 +++-- .../flash/tags/PlaceObject3Tag.java | 9 +++- .../flash/tags/PlaceObject4Tag.java | 9 +++- .../decompiler/flash/gui/ImagePanel.java | 1 - .../decompiler/flash/gui/PreviewPanel.java | 4 +- 7 files changed, 43 insertions(+), 42 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 00b1cc676..bae8d5805 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -2762,21 +2762,8 @@ public final class SWF implements SWFContainerItem, Timelined { ReadOnlyTagList tags = timelined.getTags(); if (toRemove instanceof CharacterTag) { int characterId = ((CharacterTag) toRemove).getCharacterId(); - - if (characterId != 0) { - dependingChars.add(characterId); - for (int i = 0; i < tags.size(); i++) { - Tag t = tags.get(i); - if (t instanceof CharacterIdTag) { - CharacterIdTag c = (CharacterIdTag) t; - Set needed = new HashSet<>(); - t.getNeededCharacters(needed); - if (needed.contains(characterId)) { - dependingChars.add(c.getCharacterId()); - } - } - } - } + dependingChars = getDependentCharacters(characterId); + dependingChars.add(characterId); } for (int i = 0; i < tags.size(); i++) { @@ -2794,19 +2781,24 @@ public final class SWF implements SWFContainerItem, Timelined { } } } + if (t instanceof PlaceObjectTypeTag) { PlaceObjectTypeTag po = (PlaceObjectTypeTag) t; int placeCharId = po.getCharacterId(); int depth = po.getDepth(); - if (placeCharId != 0) { + if (placeCharId >= 0) { stage.put(depth, placeCharId); - if (dependingChars.contains(placeCharId)) { - timelined.removeTag(i); - i--; - continue; - } + } else if (stage.containsKey(depth)) { + placeCharId = stage.get(depth); + } + + if (placeCharId >= 0 && dependingChars.contains(placeCharId)) { + timelined.removeTag(i); + i--; + continue; } } + if (t instanceof CharacterIdTag) { CharacterIdTag c = (CharacterIdTag) t; if (dependingChars.contains(c.getCharacterId())) { @@ -2815,20 +2807,13 @@ public final class SWF implements SWFContainerItem, Timelined { continue; } } - Set needed = new HashSet<>(); - t.getNeededCharacters(needed); - for (int dep : dependingChars) { - if (needed.contains(dep)) { - timelined.removeTag(i); - i--; - //continue; - } - } + if (t == toRemove) { timelined.removeTag(i); i--; continue; } + if (t instanceof Timelined) { removeTagWithDependenciesFromTimeline(toRemove, ((Timelined) t).getTimeline()); } @@ -2916,7 +2901,8 @@ public final class SWF implements SWFContainerItem, Timelined { timelined.setModified(true); timelined.resetTimeline(); } else // timeline should be always the swf here - if (removeDependencies) { + { + if (removeDependencies) { removeTagWithDependenciesFromTimeline(tag, timelined.getTimeline()); timelined.setModified(true); } else { @@ -2925,6 +2911,7 @@ public final class SWF implements SWFContainerItem, Timelined { timelined.setModified(true); } } + } } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/SeekMode.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/SeekMode.java index 3fd82daab..1c211f572 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/SeekMode.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/SeekMode.java @@ -2,7 +2,7 @@ package com.jpexs.decompiler.flash.iggy.streams; /** * - * @author Jindra + * @author JPEXS */ public enum SeekMode { SET, CUR, END diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java index 7b3b7a748..8dccfe100 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java @@ -158,7 +158,7 @@ public class PlaceObject2Tag extends PlaceObjectTypeTag implements ASMSourceCont this.placeFlagHasRatio = ratio >= 0; this.placeFlagHasColorTransform = colorTransform != null; this.placeFlagHasMatrix = matrix != null; - this.placeFlagHasCharacter = characterId > 0; + this.placeFlagHasCharacter = characterId >= 0; this.placeFlagMove = placeFlagMove; this.depth = depth; this.characterId = characterId; @@ -317,8 +317,13 @@ public class PlaceObject2Tag extends PlaceObjectTypeTag implements ASMSourceCont @Override public void setCharacterId(int characterId) { - placeFlagHasCharacter = true; - this.characterId = characterId; + if (characterId >= 0) { + placeFlagHasCharacter = true; + this.characterId = characterId; + } else { + placeFlagHasCharacter = false; + this.characterId = -1; + } } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java index 45583dd94..0eb27da27 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java @@ -486,8 +486,13 @@ public class PlaceObject3Tag extends PlaceObjectTypeTag implements ASMSourceCont @Override public void setCharacterId(int characterId) { - placeFlagHasCharacter = true; - this.characterId = characterId; + if (characterId >= 0) { + placeFlagHasCharacter = true; + this.characterId = characterId; + } else { + placeFlagHasCharacter = false; + this.characterId = -1; + } } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java index 17b5c968a..db4298e0d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java @@ -507,8 +507,13 @@ public class PlaceObject4Tag extends PlaceObjectTypeTag implements ASMSourceCont @Override public void setCharacterId(int characterId) { - placeFlagHasCharacter = true; - this.characterId = characterId; + if (characterId >= 0) { + placeFlagHasCharacter = true; + this.characterId = characterId; + } else { + placeFlagHasCharacter = false; + this.characterId = -1; + } } @Override diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 221060330..5105d5d09 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -1362,7 +1362,6 @@ public final class ImagePanel extends JPanel implements MediaDisplay { fpsShouldBe = timeline.frameRate; fpsIs = fpsShouldBe; scheduleTask(singleFrame, 0); - } @Override diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index 2cc05a333..76848ceaa 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -796,7 +796,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel if (treeItem instanceof DefineSpriteTag) { isSprite = true; } - int chtId = 0; + int chtId = -1; if (treeItem instanceof CharacterTag) { chtId = ((CharacterTag) treeItem).getCharacterId(); } @@ -1068,7 +1068,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel for (VideoFrameTag f : frs) { if (!first) { ratio++; - new PlaceObject2Tag(swf, true, 1, 0, null, null, ratio, null, -1, null).writeTag(sos2); + new PlaceObject2Tag(swf, true, 1, -1, null, null, ratio, null, -1, null).writeTag(sos2); } f.writeTag(sos2); new ShowFrameTag(swf).writeTag(sos2);