mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-13 05:18:45 +00:00
replace shape with image
This commit is contained in:
@@ -59,7 +59,7 @@ public class ApplicationInfo {
|
||||
if (nightly) {
|
||||
version = version + " nightly build " + version_build;
|
||||
}
|
||||
} catch (IOException | NullPointerException ex) {
|
||||
} catch (IOException | NullPointerException | NumberFormatException ex) {
|
||||
//ignore
|
||||
version = "unknown";
|
||||
}
|
||||
|
||||
@@ -1195,10 +1195,10 @@ public class SWFOutputStream extends OutputStream {
|
||||
*/
|
||||
public void writeGRADRECORD(GRADRECORD value, int shapeNum) throws IOException {
|
||||
writeUI8(value.ratio);
|
||||
if (shapeNum == 1 || shapeNum == 2) {
|
||||
writeRGB(value.color);
|
||||
} else if (shapeNum == 3) {
|
||||
if (shapeNum >= 3) {
|
||||
writeRGBA((RGBA) value.color);
|
||||
} else {
|
||||
writeRGB(value.color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1303,6 +1303,8 @@ public class SWFOutputStream extends OutputStream {
|
||||
public void writeSHAPEWITHSTYLE(SHAPEWITHSTYLE value, int shapeNum) throws IOException {
|
||||
writeFILLSTYLEARRAY(value.fillStyles, shapeNum);
|
||||
writeLINESTYLEARRAY(value.lineStyles, shapeNum);
|
||||
value.numFillBits = getNeededBitsU(value.fillStyles.fillStyles.length);
|
||||
value.numLineBits = getNeededBitsU(value.lineStyles.lineStyles.length);
|
||||
writeUB(4, value.numFillBits);
|
||||
writeUB(4, value.numLineBits);
|
||||
writeSHAPERECORDS(value.shapeRecords, value.numFillBits, value.numLineBits, shapeNum);
|
||||
@@ -1323,15 +1325,17 @@ public class SWFOutputStream extends OutputStream {
|
||||
CurvedEdgeRecord cer = (CurvedEdgeRecord) sh;
|
||||
writeUB(1, 1); //typeFlag
|
||||
writeUB(1, 0);//curvedEdge
|
||||
cer.numBits = Math.max(getNeededBitsS(cer.controlDeltaX, cer.controlDeltaY, cer.anchorDeltaX, cer.anchorDeltaY) - 2, 0);
|
||||
writeUB(4, cer.numBits);
|
||||
writeUB(cer.numBits + 2, cer.controlDeltaX);
|
||||
writeUB(cer.numBits + 2, cer.controlDeltaY);
|
||||
writeUB(cer.numBits + 2, cer.anchorDeltaX);
|
||||
writeUB(cer.numBits + 2, cer.anchorDeltaY);
|
||||
writeSB(cer.numBits + 2, cer.controlDeltaX);
|
||||
writeSB(cer.numBits + 2, cer.controlDeltaY);
|
||||
writeSB(cer.numBits + 2, cer.anchorDeltaX);
|
||||
writeSB(cer.numBits + 2, cer.anchorDeltaY);
|
||||
} else if (sh instanceof StraightEdgeRecord) {
|
||||
StraightEdgeRecord ser = (StraightEdgeRecord) sh;
|
||||
writeUB(1, 1); //typeFlag
|
||||
writeUB(1, 1);//straightEdge
|
||||
ser.numBits = Math.max(getNeededBitsS(ser.deltaX, ser.deltaY) - 2, 0);
|
||||
writeUB(4, ser.numBits);
|
||||
writeUB(1, ser.generalLineFlag ? 1 : 0);
|
||||
if (!ser.generalLineFlag) {
|
||||
@@ -1352,9 +1356,10 @@ public class SWFOutputStream extends OutputStream {
|
||||
writeUB(1, scr.stateFillStyle0 ? 1 : 0);
|
||||
writeUB(1, scr.stateMoveTo ? 1 : 0);
|
||||
if (scr.stateMoveTo) {
|
||||
scr.moveBits = getNeededBitsS(scr.moveDeltaX, scr.moveDeltaY);
|
||||
writeUB(5, scr.moveBits);
|
||||
writeUB(scr.moveBits, scr.moveDeltaX);
|
||||
writeUB(scr.moveBits, scr.moveDeltaY);
|
||||
writeSB(scr.moveBits, scr.moveDeltaX);
|
||||
writeSB(scr.moveBits, scr.moveDeltaY);
|
||||
}
|
||||
if (scr.stateFillStyle0) {
|
||||
writeUB(fillBits, scr.fillStyle0);
|
||||
@@ -1368,6 +1373,10 @@ public class SWFOutputStream extends OutputStream {
|
||||
if (scr.stateNewStyles) {
|
||||
writeFILLSTYLEARRAY(scr.fillStyles, shapeNum);
|
||||
writeLINESTYLEARRAY(scr.lineStyles, shapeNum);
|
||||
scr.numFillBits = getNeededBitsU(scr.fillStyles.fillStyles.length);
|
||||
scr.numLineBits = getNeededBitsU(scr.lineStyles.lineStyles.length);
|
||||
fillBits = scr.numFillBits;
|
||||
fillBits = scr.numLineBits;
|
||||
writeUB(4, scr.numFillBits);
|
||||
writeUB(4, scr.numLineBits);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2014 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.importers;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineShape2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineShape3Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineShape4Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineShapeTag;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.base.BoundedTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
|
||||
import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class ShapeImporter {
|
||||
|
||||
public Tag importImage(ShapeTag st, byte[] newData) throws IOException {
|
||||
SWF swf = st.getSwf();
|
||||
DefineBitsJPEG2Tag jpeg2Tag = new DefineBitsJPEG2Tag(swf, null, swf.getNextCharacterId(), newData);
|
||||
jpeg2Tag.setModified(true);
|
||||
swf.tags.add(jpeg2Tag);
|
||||
swf.updateCharacters();
|
||||
SHAPEWITHSTYLE shapes = jpeg2Tag.getShape(st.getRect(new HashSet<BoundedTag>()), true);
|
||||
|
||||
if (st instanceof DefineShapeTag) {
|
||||
DefineShapeTag dst = (DefineShapeTag) st;
|
||||
dst.shapes = shapes;
|
||||
} else if (st instanceof DefineShape2Tag) {
|
||||
DefineShape2Tag dst = (DefineShape2Tag) st;
|
||||
dst.shapes = shapes;
|
||||
} else if (st instanceof DefineShape3Tag) {
|
||||
DefineShape3Tag dst = (DefineShape3Tag) st;
|
||||
dst.shapes = shapes;
|
||||
} else if (st instanceof DefineShape4Tag) {
|
||||
DefineShape4Tag dst = (DefineShape4Tag) st;
|
||||
dst.shapes = shapes;
|
||||
}
|
||||
|
||||
return (Tag) st;
|
||||
}
|
||||
}
|
||||
@@ -109,6 +109,12 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
|
||||
}
|
||||
|
||||
private SHAPEWITHSTYLE getShape() {
|
||||
RECT rect = getRect(new HashSet<BoundedTag>());
|
||||
return getShape(rect, false);
|
||||
}
|
||||
|
||||
public SHAPEWITHSTYLE getShape(RECT rect, boolean fill) {
|
||||
boolean translated = rect.Xmin != 0 || rect.Ymin != 0;
|
||||
SHAPEWITHSTYLE shape = new SHAPEWITHSTYLE();
|
||||
shape.fillStyles = new FILLSTYLEARRAY();
|
||||
shape.fillStyles.fillStyles = new FILLSTYLE[1];
|
||||
@@ -117,8 +123,18 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
|
||||
fillStyle.bitmapId = getCharacterId();
|
||||
MATRIX matrix = new MATRIX();
|
||||
matrix.hasScale = true;
|
||||
matrix.scaleX = ((int) SWF.unitDivisor) << 16;
|
||||
matrix.scaleY = matrix.scaleX;
|
||||
if (fill) {
|
||||
RECT imageRect = getRect(new HashSet<BoundedTag>());
|
||||
matrix.scaleX = (int) ((((long) SWF.unitDivisor) << 16) * rect.getWidth() / imageRect.getWidth());
|
||||
matrix.scaleY = (int) ((((long) SWF.unitDivisor) << 16) * rect.getHeight() / imageRect.getHeight());
|
||||
} else {
|
||||
matrix.scaleX = ((int) SWF.unitDivisor) << 16;
|
||||
matrix.scaleY = matrix.scaleX;
|
||||
}
|
||||
if (translated) {
|
||||
matrix.translateX = rect.Xmin;
|
||||
matrix.translateY = rect.Ymin;
|
||||
}
|
||||
fillStyle.bitmapMatrix = matrix;
|
||||
shape.fillStyles.fillStyles[0] = fillStyle;
|
||||
|
||||
@@ -129,8 +145,11 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
|
||||
style.stateFillStyle0 = true;
|
||||
style.fillStyle0 = 1;
|
||||
style.stateMoveTo = true;
|
||||
if (translated) {
|
||||
style.moveDeltaX = rect.Xmin;
|
||||
style.moveDeltaY = rect.Ymin;
|
||||
}
|
||||
shape.shapeRecords.add(style);
|
||||
RECT rect = getRect(new HashSet<BoundedTag>());
|
||||
StraightEdgeRecord top = new StraightEdgeRecord();
|
||||
top.generalLineFlag = true;
|
||||
top.deltaX = rect.getWidth();
|
||||
|
||||
Reference in New Issue
Block a user