do not apply color transform when it has the default values

This commit is contained in:
honfika@gmail.com
2016-02-07 10:23:29 +01:00
parent 09a7f68583
commit ab4a7bfbdb
23 changed files with 74 additions and 60 deletions

View File

@@ -2690,13 +2690,10 @@ public final class SWF implements SWFContainerItem, Timelined {
}
CharacterTag character = timeline.swf.getCharacter(layer.characterId);
if (colorTransform == null) {
colorTransform = new ColorTransform();
}
ColorTransform clrTrans = colorTransform.clone();
ColorTransform clrTrans = colorTransform;
if (layer.colorTransForm != null && layer.blendMode <= 1) { // Normal blend mode
clrTrans = colorTransform.merge(layer.colorTransForm);
clrTrans = clrTrans == null ? layer.colorTransForm : colorTransform.merge(layer.colorTransForm);
}
if (character instanceof DrawableTag) {
@@ -2847,13 +2844,9 @@ public final class SWF implements SWFContainerItem, Timelined {
Matrix mat = transformation.concatenate(layerMatrix);
Matrix absMat = absoluteTransformation.concatenate(layerMatrix);
if (colorTransform == null) {
colorTransform = new ColorTransform();
}
ColorTransform clrTrans = colorTransform.clone();
ColorTransform clrTrans = colorTransform;
if (layer.colorTransForm != null && layer.blendMode <= 1) { // Normal blend mode
clrTrans = colorTransform.merge(layer.colorTransForm);
clrTrans = clrTrans == null ? layer.colorTransForm : colorTransform.merge(layer.colorTransForm);
}
boolean showPlaceholder = false;
@@ -2907,7 +2900,7 @@ public final class SWF implements SWFContainerItem, Timelined {
SerializableImage img = null;
String cacheKey = null;
if (drawable instanceof ShapeTag) {
cacheKey = ((ShapeTag) drawable).getCharacterId() + m.toString() + clrTrans.toString();
cacheKey = ((ShapeTag) drawable).getCharacterId() + m.toString() + (clrTrans == null ? "" : clrTrans.toString());
img = renderContext.shapeCache.get(cacheKey);
}

View File

@@ -33,7 +33,6 @@ import com.jpexs.decompiler.flash.exporters.settings.FontExportSettings;
import com.jpexs.decompiler.flash.exporters.shape.PathExporter;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.base.FontTag;
import com.jpexs.decompiler.flash.types.ColorTransform;
import com.jpexs.decompiler.flash.types.SHAPE;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.Path;
@@ -181,7 +180,7 @@ public class FontExporter {
for (int i = 0; i < shapes.size(); i++) {
SHAPE s = shapes.get(i);
final List<FPoint[]> contours = new ArrayList<>();
PathExporter seb = new PathExporter(swf, s, new ColorTransform()) {
PathExporter seb = new PathExporter(swf, s, null) {
private double transformX(double x) {
return Math.ceil((double) (x / divider));

View File

@@ -200,7 +200,7 @@ public class FrameExporter {
if (fbackgroundColor != null) {
exporter.setBackGroundColor(fbackgroundColor);
}
SWF.frameToSvg(tim, frame, 0, null, 0, exporter, new ColorTransform(), 0, settings.zoom);
SWF.frameToSvg(tim, frame, 0, null, 0, exporter, null, 0, settings.zoom);
fos.write(Utf8Helper.getBytes(exporter.getSVG()));
}
ret.add(f);
@@ -246,7 +246,7 @@ public class FrameExporter {
sb.append("function ").append(currentName).append("(ctx,ctrans,frame,ratio,time){\r\n");
sb.append("\tctx.save();\r\n");
sb.append("\tctx.transform(1,0,0,1,").append(-ftim.displayRect.Xmin * settings.zoom / SWF.unitDivisor).append(",").append(-ftim.displayRect.Ymin * settings.zoom / SWF.unitDivisor).append(");\r\n");
framesToHtmlCanvas(sb, SWF.unitDivisor / settings.zoom, ftim, fframes, 0, null, 0, ftim.displayRect, new ColorTransform(), fbackgroundColor);
framesToHtmlCanvas(sb, SWF.unitDivisor / settings.zoom, ftim, fframes, 0, null, 0, ftim.displayRect, null, fbackgroundColor);
sb.append("\tctx.restore();\r\n");
sb.append("}\r\n\r\n");
@@ -359,7 +359,7 @@ public class FrameExporter {
}
int fframe = fframes.get(pos++);
BufferedImage result = SWF.frameToImageGet(ftim, fframe, fframe, null, 0, ftim.displayRect, new Matrix(), new Matrix(), new ColorTransform(), fbackgroundColor, false, settings.zoom).getBufferedImage();
BufferedImage result = SWF.frameToImageGet(ftim, fframe, fframe, null, 0, ftim.displayRect, new Matrix(), new Matrix(), null, fbackgroundColor, false, settings.zoom).getBufferedImage();
if (evl != null) {
evl.handleExportedEvent("frame", pos, fframes.size(), tagName);
@@ -535,9 +535,6 @@ public class FrameExporter {
}
CharacterTag character = timeline.swf.getCharacter(layer.characterId);
if (colorTransform == null) {
colorTransform = new ColorTransform();
}
Matrix placeMatrix = new Matrix(layer.matrix);
placeMatrix.scaleX /= unitDivisor;
@@ -578,11 +575,9 @@ public class FrameExporter {
result.append("\t\t\tctx = fctx;\r\n");
}
ColorTransform ctrans = layer.colorTransForm;
ColorTransform ctrans = layer.colorTransForm; // todo: colorTransform from parameter is not used? why?
String ctrans_str = "ctrans";
if (ctrans == null) {
ctrans = new ColorTransform();
} else {
if (ctrans != null) {
ctrans_str = "ctrans.merge(new cxform("
+ ctrans.getRedAdd() + "," + ctrans.getGreenAdd() + "," + ctrans.getBlueAdd() + "," + ctrans.getAlphaAdd() + ","
+ ctrans.getRedMulti() + "," + ctrans.getGreenMulti() + "," + ctrans.getBlueMulti() + "," + ctrans.getAlphaMulti()

View File

@@ -226,7 +226,10 @@ public class CanvasMorphShapeExporter extends MorphShapeExporterBase {
if (img != null) {
fillWidth = img.getWidth();
fillHeight = img.getHeight();
colorTransform.apply(img);
if (colorTransform != null) {
colorTransform.apply(img);
}
if (matrix != null) {
fillMatrix = matrix;
fillMatrixEnd = matrixEnd;

View File

@@ -305,7 +305,11 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
switch (fillStyle.fillStyleType) {
case FILLSTYLE.SOLID:
// Solid fill
beginFill(colorTransform.apply(fillStyle.color), colorTransform.apply(fillStyleEnd.color));
if (colorTransform == null) {
beginFill(fillStyle.color, fillStyleEnd.color);
} else {
beginFill(colorTransform.apply(fillStyle.color), colorTransform.apply(fillStyleEnd.color));
}
break;
case FILLSTYLE.LINEAR_GRADIENT:
case FILLSTYLE.RADIAL_GRADIENT:
@@ -315,8 +319,8 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
matrixEnd = new Matrix(fillStyleEnd.gradientMatrix);
beginGradientFill(
fillStyle.fillStyleType,
colorTransform.apply(fillStyle.gradient.gradientRecords),
colorTransform.apply(fillStyleEnd.gradient.gradientRecords),
colorTransform == null ? fillStyle.gradient.gradientRecords : colorTransform.apply(fillStyle.gradient.gradientRecords),
colorTransform == null ? fillStyleEnd.gradient.gradientRecords : colorTransform.apply(fillStyleEnd.gradient.gradientRecords),
matrix,
matrixEnd,
fillStyle.gradient.spreadMode,
@@ -414,8 +418,8 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
lineStyle(
lineStyle.width,
lineStyleEnd.width,
colorTransform.apply(lineStyle.color),
colorTransform.apply(lineStyleEnd.color),
colorTransform == null ? lineStyle.color : colorTransform.apply(lineStyle.color),
colorTransform == null ? lineStyleEnd.color : colorTransform.apply(lineStyleEnd.color),
pixelHintingFlag,
scaleMode,
startCapStyle,

View File

@@ -107,7 +107,10 @@ public class SVGMorphShapeExporter extends DefaultSVGMorphShapeExporter {
if (image != null) {
SerializableImage img = image.getImage();
if (img != null) {
colorTransform.apply(img);
if (colorTransform != null) {
colorTransform.apply(img);
}
int width = img.getWidth();
int height = img.getHeight();
lastPatternId++;

View File

@@ -306,7 +306,10 @@ public class BitmapExporter extends ShapeExporterBase {
if (imageTag != null) {
SerializableImage img = imageTag.getImage();
if (img != null) {
img = colorTransform.apply(img);
if (colorTransform != null) {
img = colorTransform.apply(img);
}
fillPaint = new TexturePaint(img.getBufferedImage(), new java.awt.Rectangle(img.getWidth(), img.getHeight()));
fillTransform = matrix.toTransform();
}

View File

@@ -261,7 +261,10 @@ public class CanvasShapeExporter extends ShapeExporterBase {
if (img != null) {
fillWidth = img.getWidth();
fillHeight = img.getHeight();
colorTransform.apply(img);
if (colorTransform != null) {
colorTransform.apply(img);
}
if (matrix != null) {
fillMatrix = matrix;
}

View File

@@ -37,7 +37,7 @@ public class PathExporter extends ShapeExporterBase {
private GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
public static List<GeneralPath> export(SWF swf, SHAPE shape) {
PathExporter exporter = new PathExporter(swf, shape, new ColorTransform());
PathExporter exporter = new PathExporter(swf, shape, null);
exporter.export();
return exporter.paths;
}

View File

@@ -104,7 +104,10 @@ public class SVGShapeExporter extends DefaultSVGShapeExporter {
if (image != null) {
SerializableImage img = image.getImage();
if (img != null) {
colorTransform.apply(img);
if (colorTransform != null) {
colorTransform.apply(img);
}
int width = img.getWidth();
int height = img.getHeight();
lastPatternId++;

View File

@@ -267,7 +267,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
switch (fillStyle.fillStyleType) {
case FILLSTYLE.SOLID:
// Solid fill
beginFill(colorTransform.apply(fillStyle.color));
beginFill(colorTransform == null ? fillStyle.color : colorTransform.apply(fillStyle.color));
break;
case FILLSTYLE.LINEAR_GRADIENT:
case FILLSTYLE.RADIAL_GRADIENT:
@@ -275,7 +275,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
// Gradient fill
beginGradientFill(
fillStyle.fillStyleType,
colorTransform.apply(fillStyle.gradient.gradientRecords),
colorTransform == null ? fillStyle.gradient.gradientRecords : colorTransform.apply(fillStyle.gradient.gradientRecords),
fillStyle.gradientMatrix,
fillStyle.gradient.spreadMode,
fillStyle.gradient.interpolationMode,
@@ -368,7 +368,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
}
lineStyle(
lineStyle.width,
colorTransform.apply(lineStyle.color),
colorTransform == null ? lineStyle.color : colorTransform.apply(lineStyle.color),
pixelHintingFlag,
scaleMode,
startCapStyle,

View File

@@ -29,7 +29,6 @@ import com.jpexs.decompiler.flash.tags.DefineShape4Tag;
import com.jpexs.decompiler.flash.tags.ExportAssetsTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
import com.jpexs.decompiler.flash.types.ColorTransform;
import com.jpexs.decompiler.flash.types.FILLSTYLE;
import com.jpexs.decompiler.flash.types.FILLSTYLEARRAY;
import com.jpexs.decompiler.flash.types.FOCALGRADIENT;
@@ -1041,7 +1040,7 @@ public class SvgImporter {
st = (DefineShape4Tag) (new SvgImporter().importSvg(st, svgDataS));
swf.addTag(st);
SerializableImage si = new SerializableImage(480, 360, BufferedImage.TYPE_4BYTE_ABGR);
BitmapExporter.export(swf, st.shapes, Color.yellow, si, new Matrix(), new ColorTransform());
BitmapExporter.export(swf, st.shapes, Color.yellow, si, new Matrix(), null);
List<Tag> li = new ArrayList<>();
li.add(st);
ImageIO.write(si.getBufferedImage(), "PNG", new File(name + ".imported.png"));

View File

@@ -927,7 +927,7 @@ public class DefineEditTextTag extends TextTag {
@Override
public void toHtmlCanvas(StringBuilder result, double unitDivisor) {
render(TextRenderMode.HTML5_CANVAS, null, null, result, new Matrix(), new ColorTransform(), unitDivisor);
render(TextRenderMode.HTML5_CANVAS, null, null, result, new Matrix(), null, unitDivisor);
}
private void render(TextRenderMode renderMode, SerializableImage image, SVGExporter svgExporter, StringBuilder htmlCanvasBuilder, Matrix transformation, ColorTransform colorTransform, double zoom) {

View File

@@ -341,7 +341,7 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable
String cs = "" + c;
cs = cs.replace("\\", "\\\\").replace("\"", "\\\"");
result.append("\t\tcase \"").append(cs).append("\":\r\n");
CanvasShapeExporter exporter = new CanvasShapeExporter(null, unitDivisor, swf, shapes.get(i), new ColorTransform(), 0, 0);
CanvasShapeExporter exporter = new CanvasShapeExporter(null, unitDivisor, swf, shapes.get(i), null, 0, 0);
exporter.export();
result.append("\t\t").append(exporter.getShapeData().replaceAll("\r\n", "\r\n\t\t"));
result.append("\tbreak;\r\n");

View File

@@ -295,7 +295,7 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
@Override
public void toHtmlCanvas(StringBuilder result, double unitDivisor) {
CanvasShapeExporter cse = new CanvasShapeExporter(null, unitDivisor, swf, getShape(), new ColorTransform(), 0, 0);
CanvasShapeExporter cse = new CanvasShapeExporter(null, unitDivisor, swf, getShape(), null, 0, 0);
cse.export();
result.append(cse.getShapeData());
}

View File

@@ -320,7 +320,7 @@ public abstract class MorphShapeTag extends CharacterTag implements DrawableTag
@Override
public void toHtmlCanvas(StringBuilder result, double unitDivisor) {
CanvasMorphShapeExporter cmse = new CanvasMorphShapeExporter(swf, getShapeAtRatio(0), getShapeAtRatio(MAX_RATIO), new ColorTransform(), unitDivisor, 0, 0);
CanvasMorphShapeExporter cmse = new CanvasMorphShapeExporter(swf, getShapeAtRatio(0), getShapeAtRatio(MAX_RATIO), null, unitDivisor, 0, 0);
cmse.export();
result.append(cmse.getShapeData());
}

View File

@@ -183,7 +183,7 @@ public abstract class ShapeTag extends CharacterTag implements DrawableTag, Lazy
@Override
public void toHtmlCanvas(StringBuilder result, double unitDivisor) {
CanvasShapeExporter cse = new CanvasShapeExporter(null, unitDivisor, swf, getShapes(), new ColorTransform(), 0, 0);
CanvasShapeExporter cse = new CanvasShapeExporter(null, unitDivisor, swf, getShapes(), null, 0, 0);
cse.export();
result.append(cse.getShapeData());
}

View File

@@ -674,6 +674,6 @@ public abstract class StaticTextTag extends TextTag {
@Override
public void toHtmlCanvas(StringBuilder result, double unitDivisor) {
staticTextToHtmlCanvas(unitDivisor, swf, textRecords, getTextNum(), result, textBounds, textMatrix, new ColorTransform());
staticTextToHtmlCanvas(unitDivisor, swf, textRecords, getTextNum(), result, textBounds, textMatrix, null);
}
}

View File

@@ -424,9 +424,13 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
for (TEXTRECORD rec : textRecords) {
if (rec.styleFlagsHasColor) {
if (numText == 2) {
textColor = colorTransform.apply(rec.textColorA.toInt());
textColor = rec.textColorA.toInt();
} else {
textColor = colorTransform.apply(rec.textColor.toInt());
textColor = rec.textColor.toInt();
}
if (colorTransform != null) {
textColor = colorTransform.apply(textColor);
}
}
if (rec.styleFlagsHasFont) {
@@ -574,9 +578,13 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
for (TEXTRECORD rec : textRecords) {
if (rec.styleFlagsHasColor) {
if (numText == 2) {
textColor = colorTransform.apply(rec.textColorA.toInt());
textColor = rec.textColorA.toInt();
} else {
textColor = colorTransform.apply(rec.textColor.toInt());
textColor = rec.textColor.toInt();
}
if (colorTransform != null) {
textColor = colorTransform.apply(textColor);
}
}
if (rec.styleFlagsHasFont) {
@@ -619,9 +627,13 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
for (TEXTRECORD rec : textRecords) {
if (rec.styleFlagsHasColor) {
if (numText == 2) {
textColor = colorTransform.apply(rec.textColorA.toInt());
textColor = rec.textColorA.toInt();
} else {
textColor = colorTransform.apply(rec.textColor.toInt());
textColor = rec.textColor.toInt();
}
if (colorTransform != null) {
textColor = colorTransform.apply(textColor);
}
}
if (rec.styleFlagsHasFont) {

View File

@@ -535,7 +535,7 @@ public class Timeline {
}
public void toHtmlCanvas(StringBuilder result, double unitDivisor, List<Integer> frames) {
FrameExporter.framesToHtmlCanvas(result, unitDivisor, this, frames, 0, null, 0, displayRect, new ColorTransform(), null);
FrameExporter.framesToHtmlCanvas(result, unitDivisor, this, frames, 0, null, 0, displayRect, null, null);
}
public void getSounds(int frame, int time, DepthState stateUnderCursor, int mouseButton, List<Integer> sounds, List<String> soundClasses) {