mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-21 00:55:37 +00:00
Library preview
This commit is contained in:
@@ -5851,7 +5851,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
|
||||
} else if (treeItem instanceof ImageTag) {
|
||||
ImageTag imageTag = (ImageTag) treeItem;
|
||||
previewPanel.setImageReplaceButtonVisible(!((Tag) imageTag).isReadOnly() && imageTag.importSupported(), imageTag instanceof DefineBitsJPEG3Tag || imageTag instanceof DefineBitsJPEG4Tag, false, false, false, false, false);
|
||||
SWF imageSWF = makeTimelinedImage(imageTag);
|
||||
SWF imageSWF = TimelinedMaker.makeTimelinedImage(imageTag);
|
||||
previewPanel.showImagePanel(imageSWF, imageSWF, 0, false, true, true, true, true, false, false, true);
|
||||
|
||||
} else if (!isVideoButNotDrawable && (treeItem instanceof DrawableTag) && (!(treeItem instanceof TextTag)) && (!(treeItem instanceof FontTag)) && internalViewer) {
|
||||
@@ -5861,7 +5861,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
|
||||
if (treeItem instanceof Timelined && !(treeItem instanceof ButtonTag)) {
|
||||
timelined = (Timelined) tag;
|
||||
} else {
|
||||
timelined = makeTimelined(tag);
|
||||
timelined = TimelinedMaker.makeTimelined(tag);
|
||||
}
|
||||
|
||||
previewPanel.setParametersPanelVisible(false);
|
||||
@@ -6462,293 +6462,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
|
||||
|
||||
public void setErrorState(ErrorState errorState) {
|
||||
statusPanel.setErrorState(errorState);
|
||||
}
|
||||
|
||||
public static SWF makeTimelinedImage(ImageTag imageTag) {
|
||||
SWF swf = new SWF();
|
||||
swf.gfx = imageTag.getSwf().gfx;
|
||||
swf.version = imageTag.getSwf().version;
|
||||
int w = (int) (imageTag.getImageDimension().getWidth() * SWF.unitDivisor);
|
||||
int h = (int) (imageTag.getImageDimension().getHeight() * SWF.unitDivisor);
|
||||
swf.displayRect = new RECT(0, w, 0, h);
|
||||
swf.frameCount = 1;
|
||||
swf.frameRate = 1;
|
||||
swf.setFile(imageTag.getSwf().getFile()); //DefineSubImage calculates relative paths from it
|
||||
try {
|
||||
|
||||
JPEGTablesTag jpegTablesTag = null;
|
||||
if (imageTag instanceof DefineBitsTag) {
|
||||
jpegTablesTag = imageTag.getSwf().getJtt();
|
||||
}
|
||||
Set<Integer> needed = new LinkedHashSet<>();
|
||||
imageTag.getNeededCharacters(needed, swf);
|
||||
|
||||
List<CharacterTag> neededCopies = new ArrayList<>();
|
||||
for (int n : needed) {
|
||||
CharacterTag ct = imageTag.getSwf().getCharacter(n);
|
||||
if (ct != null) {
|
||||
ct = (CharacterTag) ct.cloneTag();
|
||||
ct.setSwf(swf);
|
||||
neededCopies.add(ct);
|
||||
}
|
||||
}
|
||||
if (imageTag instanceof DefineSubImage) {
|
||||
DefineExternalImage2 dei2 = (DefineExternalImage2) imageTag.getSwf().getExternalImage2(((DefineSubImage) imageTag).imageId);
|
||||
if (dei2 != null) {
|
||||
dei2 = (DefineExternalImage2) dei2.cloneTag();
|
||||
dei2.setSwf(swf);
|
||||
neededCopies.add(dei2);
|
||||
}
|
||||
}
|
||||
|
||||
ImageTag imageTagCopy = (ImageTag) imageTag.cloneTag();
|
||||
imageTagCopy.setSwf(swf);
|
||||
int imageCharId = imageTag.getCharacterId();
|
||||
if ((imageTag instanceof DefineExternalImage2) && (((DefineExternalImage2) imageTag).idType != IdType.IDTYPE_NONE)) {
|
||||
imageCharId = swf.getNextCharacterId();
|
||||
imageTagCopy.characterID = imageCharId;
|
||||
}
|
||||
DefineShape2Tag shapeTag = new DefineShape2Tag(swf);
|
||||
int shapeCharId = imageCharId + 1;
|
||||
shapeTag.shapeId = shapeCharId;
|
||||
shapeTag.shapeBounds = new RECT(swf.displayRect);
|
||||
|
||||
SHAPEWITHSTYLE shapeData = new SHAPEWITHSTYLE();
|
||||
FILLSTYLEARRAY fillStyleArray = new FILLSTYLEARRAY();
|
||||
FILLSTYLE[] fillStyles = new FILLSTYLE[1];
|
||||
FILLSTYLE fillStyle = new FILLSTYLE();
|
||||
fillStyle.bitmapId = imageCharId;
|
||||
fillStyle.inShape3 = false;
|
||||
fillStyle.fillStyleType = FILLSTYLE.CLIPPED_BITMAP;
|
||||
fillStyle.bitmapMatrix = Matrix.getScaleInstance(SWF.unitDivisor).toMATRIX();
|
||||
fillStyles[0] = fillStyle;
|
||||
fillStyleArray.fillStyles = fillStyles;
|
||||
shapeData.fillStyles = fillStyleArray;
|
||||
shapeData.lineStyles = new LINESTYLEARRAY();
|
||||
|
||||
List<SHAPERECORD> shapeRecords = new ArrayList<>();
|
||||
|
||||
StyleChangeRecord scr = new StyleChangeRecord();
|
||||
scr.stateFillStyle0 = true;
|
||||
scr.fillStyle0 = 1;
|
||||
shapeRecords.add(scr);
|
||||
|
||||
StyleChangeRecord scr2 = new StyleChangeRecord();
|
||||
scr2.stateMoveTo = true;
|
||||
scr2.moveDeltaX = 0;
|
||||
scr2.moveDeltaY = 0;
|
||||
scr2.calculateBits();
|
||||
shapeRecords.add(scr2);
|
||||
|
||||
StraightEdgeRecord ser1 = new StraightEdgeRecord();
|
||||
ser1.vertLineFlag = true;
|
||||
ser1.deltaY = h;
|
||||
ser1.calculateBits();
|
||||
shapeRecords.add(ser1);
|
||||
|
||||
StraightEdgeRecord ser2 = new StraightEdgeRecord();
|
||||
ser2.deltaX = w;
|
||||
shapeRecords.add(ser2);
|
||||
|
||||
StraightEdgeRecord ser3 = new StraightEdgeRecord();
|
||||
ser3.vertLineFlag = true;
|
||||
ser3.deltaY = -h;
|
||||
shapeRecords.add(ser3);
|
||||
|
||||
StraightEdgeRecord ser4 = new StraightEdgeRecord();
|
||||
ser4.deltaX = -w;
|
||||
shapeRecords.add(ser4);
|
||||
|
||||
shapeRecords.add(new EndShapeRecord());
|
||||
|
||||
shapeData.shapeRecords = shapeRecords;
|
||||
|
||||
shapeData.numFillBits = 1;
|
||||
shapeData.numLineBits = 0;
|
||||
|
||||
shapeTag.shapes = shapeData;
|
||||
|
||||
PlaceObjectTag placeTag = new PlaceObjectTag(swf, shapeCharId, 1, new Matrix().toMATRIX(), null);
|
||||
|
||||
ShowFrameTag showFrameTag = new ShowFrameTag(swf);
|
||||
|
||||
EndTag endTag = new EndTag(swf);
|
||||
|
||||
if (jpegTablesTag != null) {
|
||||
swf.addTag(jpegTablesTag);
|
||||
}
|
||||
for (CharacterTag neededCopy : neededCopies) {
|
||||
swf.addTag(neededCopy);
|
||||
}
|
||||
swf.addTag(imageTagCopy);
|
||||
swf.addTag(shapeTag);
|
||||
swf.addTag(placeTag);
|
||||
swf.addTag(showFrameTag);
|
||||
swf.addTag(endTag);
|
||||
|
||||
} catch (InterruptedException | IOException ex) {
|
||||
//ignore
|
||||
}
|
||||
return swf;
|
||||
}
|
||||
|
||||
public static Timelined makeTimelined(final Tag tag) {
|
||||
return makeTimelined(tag, -1);
|
||||
}
|
||||
|
||||
public static Timelined makeTimelined(final Tag tag, final int fontFrameNum) {
|
||||
|
||||
return new Timelined() {
|
||||
private Timeline tim;
|
||||
|
||||
@Override
|
||||
public Timeline getTimeline() {
|
||||
if (tim == null) {
|
||||
Timeline timeline = new Timeline(tag.getSwf(), this, ((CharacterTag) tag).getCharacterId(), getRect());
|
||||
initTimeline(timeline);
|
||||
tim = timeline;
|
||||
}
|
||||
|
||||
return tim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTimeline() {
|
||||
if (tim != null) {
|
||||
tim.reset(tag.getSwf(), this, ((CharacterTag) tag).getCharacterId(), getRect());
|
||||
initTimeline(tim);
|
||||
}
|
||||
}
|
||||
|
||||
private void initTimeline(Timeline timeline) {
|
||||
if (tag instanceof MorphShapeTag) {
|
||||
timeline.frameRate = PreviewExporter.MORPH_SHAPE_ANIMATION_FRAME_RATE;
|
||||
int framesCnt = (int) (timeline.frameRate * PreviewExporter.MORPH_SHAPE_ANIMATION_LENGTH);
|
||||
for (int i = 0; i < framesCnt; i++) {
|
||||
Frame f = new Frame(timeline, i);
|
||||
DepthState ds = new DepthState(tag.getSwf(), f, f);
|
||||
ds.characterId = ((CharacterTag) tag).getCharacterId();
|
||||
ds.matrix = new MATRIX();
|
||||
ds.ratio = i * 65535 / framesCnt;
|
||||
f.layers.put(1, ds);
|
||||
f.layersChanged = true;
|
||||
timeline.addFrame(f);
|
||||
}
|
||||
Frame f = new Frame(timeline, framesCnt);
|
||||
DepthState ds = new DepthState(tag.getSwf(), f, f);
|
||||
ds.characterId = ((CharacterTag) tag).getCharacterId();
|
||||
ds.matrix = new MATRIX();
|
||||
ds.ratio = 65535;
|
||||
f.layers.put(1, ds);
|
||||
f.layersChanged = true;
|
||||
timeline.addFrame(f);
|
||||
} else if (tag instanceof FontTag) {
|
||||
int pageCount = PreviewPanel.getFontPageCount((FontTag) tag);
|
||||
int frame = fontFrameNum;
|
||||
if (frame < 0 || frame >= pageCount) {
|
||||
frame = 0;
|
||||
}
|
||||
//TODO: make this static texts instead of FontTag as drawable.
|
||||
//We do not want to draw fonts directly added to stage as
|
||||
//Fonts are really added to stage in some corner cases like for vertical text.
|
||||
Frame f = new Frame(timeline, 0);
|
||||
DepthState ds = new DepthState(tag.getSwf(), f, f);
|
||||
ds.characterId = ((CharacterTag) tag).getCharacterId();
|
||||
ds.matrix = new MATRIX();
|
||||
f.layers.put(1, ds);
|
||||
f.layersChanged = true;
|
||||
timeline.addFrame(f);
|
||||
timeline.fontFrameNum = frame;
|
||||
} else {
|
||||
Frame f = new Frame(timeline, 0);
|
||||
DepthState ds = new DepthState(tag.getSwf(), f, f);
|
||||
ds.characterId = ((CharacterTag) tag).getCharacterId();
|
||||
ds.matrix = new MATRIX();
|
||||
f.layers.put(1, ds);
|
||||
timeline.addFrame(f);
|
||||
}
|
||||
timeline.displayRect = getRect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RECT getRect() {
|
||||
return getRect(new HashSet<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RECT getRect(Set<BoundedTag> added) {
|
||||
BoundedTag bt = (BoundedTag) tag;
|
||||
if (!added.contains(bt)) {
|
||||
return bt.getRect(added);
|
||||
}
|
||||
return new RECT(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return tag.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModified(boolean value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadOnlyTagList getTags() {
|
||||
return ReadOnlyTagList.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTag(int index) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTag(Tag tag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTag(Tag tag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTag(int index, Tag tag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceTag(int index, Tag newTag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceTag(Tag oldTag, Tag newTag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOfTag(Tag tag) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RECT getRectWithStrokes() {
|
||||
return getRect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFrameCount(int frameCount) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFrameCount() {
|
||||
return getTimeline().getFrameCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SWF getSwf() {
|
||||
return tag.getSwf();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void disposeInner(Container container) {
|
||||
for (Component c : container.getComponents()) {
|
||||
if (c instanceof Container) {
|
||||
|
||||
Reference in New Issue
Block a user