performance improvements

This commit is contained in:
honfika@gmail.com
2014-12-10 21:04:38 +01:00
parent 87b9620405
commit e2ba5aaf8d
9 changed files with 81 additions and 35 deletions

View File

@@ -431,11 +431,12 @@ public class SWFInputStream implements AutoCloseable {
private int lastPercent = -1;
private int readNoBitReset() throws IOException, EndOfStreamException {
informListeners();
int r = is.read();
if (r == -1) {
throw new EndOfStreamException();
}
informListeners();
return r;
}
@@ -727,13 +728,13 @@ public class SWFInputStream implements AutoCloseable {
return new byte[0];
}
informListeners();
bitPos = 0;
byte[] ret = new byte[(int) count];
if (is.read(ret) != count) {
throw new EndOfStreamException();
}
informListeners();
return ret;
}
@@ -744,10 +745,17 @@ public class SWFInputStream implements AutoCloseable {
* @throws IOException
*/
public void skipBytesEx(long count) throws IOException {
bitPos = 0;
for (int i = 0; i < count; i++) {
readNoBitReset();
if (count <= 0) {
return;
}
bitPos = 0;
is.seek(is.getPos() + count);
if (is.available() < 0) {
throw new EndOfStreamException();
}
informListeners();
}
/**

View File

@@ -85,13 +85,16 @@ public class FontHelper {
} catch (Throwable ex) {
//ignore
}
if (fonts == null) {
fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
}
List<String> javaFonts = Arrays.asList("Dialog", "DialogInput", "Monospaced", "Serif", "SansSerif");
for (Font f : fonts) {
String fam = f.getFamily(Locale.ENGLISH);
//Do not want Java logical fonts
if (Arrays.asList("Dialog", "DialogInput", "Monospaced", "Serif", "SansSerif").contains(fam)) {
if (javaFonts.contains(fam)) {
continue;
}
if (!ret.containsKey(fam)) {
@@ -100,6 +103,7 @@ public class FontHelper {
ret.get(fam).put(f.getFontName(Locale.ENGLISH), f);
}
return ret;
}

View File

@@ -94,20 +94,26 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
} else {
stream = new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength());
}
BufferedImage image = ImageHelper.read(stream);
SerializableImage img = image == null ? null : new SerializableImage(image);
if (bitmapAlphaData.length == 0) {
cachedImage = img;
return img;
}
SerializableImage img2 = new SerializableImage(img.getWidth(), img.getHeight(), SerializableImage.TYPE_INT_ARGB_PRE);
for (int y = 0; y < img.getHeight(); y++) {
for (int x = 0; x < img.getWidth(); x++) {
int width = img.getWidth();
int height = img.getHeight();
SerializableImage img2 = new SerializableImage(width, height, SerializableImage.TYPE_INT_ARGB);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int val = img.getRGB(x, y);
int a = bitmapAlphaData[x + y * img.getWidth()] & 0xff;
int a = bitmapAlphaData[x + y * width] & 0xff;
val = (val & 0xffffff) | (a << 24);
img2.setRGB(x, y, colorToInt(multiplyAlpha(intToColor(val))));
img2.setRGB(x, y, multiplyAlpha(val));
}
}
cachedImage = img2;
return img2;
} catch (IOException ex) {

View File

@@ -99,17 +99,22 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
BufferedImage image = ImageHelper.read(new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength()));
SerializableImage img = image == null ? null : new SerializableImage(image);
if (bitmapAlphaData.getLength() == 0) {
cachedImage = img;
return img;
}
SerializableImage img2 = new SerializableImage(img.getWidth(), img.getHeight(), SerializableImage.TYPE_INT_ARGB);
for (int y = 0; y < img.getHeight(); y++) {
for (int x = 0; x < img.getWidth(); x++) {
int width = img.getWidth();
int height = img.getHeight();
SerializableImage img2 = new SerializableImage(width, height, SerializableImage.TYPE_INT_ARGB);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int val = img.getRGB(x, y);
int a = bitmapAlphaData.get(x + y * img.getWidth()) & 0xff;
int a = bitmapAlphaData.get(x + y * width) & 0xff;
val = (val & 0xffffff) | (a << 24);
img2.setRGB(x, y, colorToInt(multiplyAlpha(intToColor(val))));
img2.setRGB(x, y, multiplyAlpha(val));
}
}
cachedImage = img2;
return img2;
} catch (IOException ex) {

View File

@@ -241,14 +241,14 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
int pos = 0;
for (int y = 0; y < bitmapHeight; y++) {
for (int x = 0; x < bitmapWidth; x++) {
Color c = null;
int c = 0;
if ((bitmapFormat == DefineBitsLossless2Tag.FORMAT_8BIT_COLORMAPPED)) {
c = (multiplyAlpha(colorMapData.colorTableRGB[colorMapData.colorMapPixelData[pos32aligned] & 0xff].toColor()));
c = multiplyAlpha(colorMapData.colorTableRGB[colorMapData.colorMapPixelData[pos32aligned] & 0xff].toInt());
}
if ((bitmapFormat == DefineBitsLossless2Tag.FORMAT_32BIT_ARGB)) {
c = (multiplyAlpha(bitmapData.bitmapPixelData[pos].toColor()));
c = (multiplyAlpha(bitmapData.bitmapPixelData[pos].toInt()));
}
bi.setRGB(x, y, c.getRGB());
bi.setRGB(x, y, c);
pos32aligned++;
pos++;
}

View File

@@ -36,7 +36,6 @@ import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.SerializableImage;
import java.awt.Color;
import java.awt.Shape;
import java.io.IOException;
import java.io.InputStream;
@@ -97,17 +96,16 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
return (int) val;
}
protected static Color intToColor(int val) {
return new Color(val & 0xff, (val >> 8) & 0xff, (val >> 16) & 0xff, (val >> 24) & 0xff);
}
protected static int colorToInt(Color c) {
return (c.getAlpha() << 24) | (c.getBlue() << 16) | (c.getGreen() << 8) | c.getRed();
}
protected static Color multiplyAlpha(Color c) {
float multiplier = c.getAlpha() == 0 ? 0 : 255.0f / c.getAlpha();
return new Color(max255(c.getRed() * multiplier), max255(c.getGreen() * multiplier), max255(c.getBlue() * multiplier), c.getAlpha());
protected static int multiplyAlpha(int value) {
int a = (value >> 24) & 0xFF;
int r = (value >> 16) & 0xFF;
int g = (value >> 8) & 0xFF;
int b = value & 0xFF;
float multiplier = a == 0 ? 0 : 255.0f / a;
r = max255(r * multiplier);
g = max255(g * multiplier);
b = max255(b * multiplier);
return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
}
private SHAPEWITHSTYLE getShape() {

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.types;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
@@ -56,6 +57,13 @@ public class ARGB implements Serializable {
return new Color(red, green, blue, alpha);
}
public int toInt() {
return ((alpha & 0xFF) << 24) |
((red & 0xFF) << 16) |
((green & 0xFF) << 8) |
(blue & 0xFF);
}
public ARGB() {
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.types;
import com.jpexs.decompiler.flash.configuration.Configuration;
@@ -72,6 +73,13 @@ public class RGB implements Serializable {
return new Color(red, green, blue);
}
public int toInt() {
return (0xFF << 24) |
((red & 0xFF) << 16) |
((green & 0xFF) << 8) |
(blue & 0xFF);
}
public RGB(Color color) {
this.red = color.getRed();
this.green = color.getGreen();

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.types;
import com.jpexs.decompiler.flash.configuration.Configuration;
@@ -75,6 +76,14 @@ public class RGBA extends RGB implements Serializable {
return new Color(red, green, blue, alpha);
}
@Override
public int toInt() {
return ((alpha & 0xFF) << 24) |
((red & 0xFF) << 16) |
((green & 0xFF) << 8) |
(blue & 0xFF);
}
@Override
public String toString() {
if (Configuration.useHexColorFormat.get()) {