mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-27 23:40:45 +00:00
log when failed to load the image from a tag
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -32,8 +33,16 @@ import javax.imageio.ImageIO;
|
||||
*/
|
||||
public class ImageHelper {
|
||||
|
||||
public static BufferedImage read(byte[] data) throws IOException {
|
||||
return read(new ByteArrayInputStream(data));
|
||||
}
|
||||
|
||||
public static BufferedImage read(InputStream input) throws IOException {
|
||||
BufferedImage in = ImageIO.read(input);
|
||||
if (in == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int type = in.getType();
|
||||
if (type != BufferedImage.TYPE_INT_ARGB && type != BufferedImage.TYPE_INT_RGB) {
|
||||
// convert to ARGB
|
||||
|
||||
@@ -72,7 +72,12 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
}
|
||||
try {
|
||||
BufferedImage image = ImageHelper.read(getImageData());
|
||||
SerializableImage ret = image == null ? null : new SerializableImage(image);
|
||||
if (image == null) {
|
||||
Logger.getLogger(DefineBitsJPEG2Tag.class.getName()).log(Level.SEVERE, "Failed to load image");
|
||||
return null;
|
||||
}
|
||||
|
||||
SerializableImage ret = new SerializableImage(image);
|
||||
cachedImage = ret;
|
||||
return ret;
|
||||
} catch (IOException ex) {
|
||||
|
||||
@@ -61,7 +61,7 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
@Override
|
||||
public void setImage(byte[] data) throws IOException {
|
||||
if (ImageTag.getImageFormat(data).equals("jpg")) {
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(new ByteArrayInputStream(data)));
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(data));
|
||||
byte[] ba = new byte[image.getWidth() * image.getHeight()];
|
||||
for (int i = 0; i < ba.length; i++) {
|
||||
ba[i] = (byte) 255;
|
||||
@@ -97,7 +97,12 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
}
|
||||
try {
|
||||
BufferedImage image = ImageHelper.read(getImageData());
|
||||
SerializableImage img = image == null ? null : new SerializableImage(image);
|
||||
if (image == null) {
|
||||
Logger.getLogger(DefineBitsJPEG3Tag.class.getName()).log(Level.SEVERE, "Failed to load image");
|
||||
return null;
|
||||
}
|
||||
|
||||
SerializableImage img = new SerializableImage(image);
|
||||
if (bitmapAlphaData.length == 0) {
|
||||
cachedImage = img;
|
||||
return img;
|
||||
|
||||
@@ -99,7 +99,12 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
}
|
||||
try {
|
||||
BufferedImage image = ImageHelper.read(getImageData());
|
||||
SerializableImage img = image == null ? null : new SerializableImage(image);
|
||||
if (image == null) {
|
||||
Logger.getLogger(DefineBitsJPEG4Tag.class.getName()).log(Level.SEVERE, "Failed to load image");
|
||||
return null;
|
||||
}
|
||||
|
||||
SerializableImage img = new SerializableImage(image);
|
||||
if (bitmapAlphaData.getLength() == 0) {
|
||||
cachedImage = img;
|
||||
return img;
|
||||
|
||||
@@ -105,7 +105,7 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public void setImage(byte[] data) throws IOException {
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(new ByteArrayInputStream(data)));
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(data));
|
||||
ALPHABITMAPDATA bitmapData = new ALPHABITMAPDATA();
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
|
||||
@@ -102,7 +102,7 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public void setImage(byte[] data) throws IOException {
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(new ByteArrayInputStream(data)));
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(data));
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
bitmapData = new BITMAPDATA();
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.jpexs.decompiler.flash.types.BasicType;
|
||||
import com.jpexs.decompiler.flash.types.annotations.SWFType;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -98,9 +98,16 @@ public class DefineBitsTag extends ImageTag implements TagChangedListener {
|
||||
baos.write(jttdata, jttErrorLength, jttdata.length - jttErrorLength - 2);
|
||||
}
|
||||
|
||||
int jpegDataErrorLength = hasErrorHeader(jpegData) ? 4 : 0;
|
||||
baos.write(jpegData.getArray(), jpegData.getPos() + jpegDataErrorLength + 2, jpegData.getLength() - jpegDataErrorLength - 2);
|
||||
SerializableImage ret = new SerializableImage(ImageHelper.read(new ByteArrayInputStream(baos.toByteArray())));
|
||||
int errorLength = hasErrorHeader(jpegData) ? 4 : 0;
|
||||
baos.write(jpegData.getArray(), jpegData.getPos() + errorLength, jpegData.getLength() - errorLength);
|
||||
|
||||
BufferedImage image = ImageHelper.read(baos.toByteArray());
|
||||
if (image == null) {
|
||||
Logger.getLogger(DefineBitsTag.class.getName()).log(Level.SEVERE, "Failed to load image");
|
||||
return null;
|
||||
}
|
||||
|
||||
SerializableImage ret = new SerializableImage(image);
|
||||
cachedImage = ret;
|
||||
return ret;
|
||||
} catch (IOException ex) {
|
||||
|
||||
Reference in New Issue
Block a user