diff --git a/src/infinity/gui/converter/ConvertToBam.java b/src/infinity/gui/converter/ConvertToBam.java index 307884657..267af3028 100644 --- a/src/infinity/gui/converter/ConvertToBam.java +++ b/src/infinity/gui/converter/ConvertToBam.java @@ -2303,15 +2303,25 @@ private BamDecoder framesAddBam(int listIndex, File file) BamDecoder.FrameEntry fe = decoder.getFrameInfo(j); BufferedImage image = null; if (cm != null) { - image = new BufferedImage(fe.getWidth(), fe.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, cm); + if (fe.getWidth() > 0 && fe.getHeight() > 0) { + image = new BufferedImage(fe.getWidth(), fe.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, cm); + } else { + image = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED, cm); + } isCompressed = ((BamV1Decoder.BamV1FrameEntry)fe).isCompressed(); rleIndex = ((BamV1Decoder)decoder).getRleIndex(); } else { - image = new BufferedImage(fe.getWidth(), fe.getHeight(), BufferedImage.TYPE_INT_ARGB); + if (fe.getWidth() > 0 && fe.getHeight() > 0) { + image = new BufferedImage(fe.getWidth(), fe.getHeight(), BufferedImage.TYPE_INT_ARGB); + } else { + image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); + } isCompressed = false; rleIndex = 0; } - decoder.frameGet(control, j, image); + if (fe.getWidth() > 0 && fe.getHeight() > 0) { + decoder.frameGet(control, j, image); + } modelFrames.insert(listIndex, image, new Point(fe.getCenterX(), fe.getCenterY())); // setting required extra options PseudoBamFrameEntry fe2 = getBamDecoder(BAM_ORIGINAL).getFrameInfo(listIndex); diff --git a/src/infinity/resource/graphics/BamResource.java b/src/infinity/resource/graphics/BamResource.java index 5a572e30a..87773d808 100644 --- a/src/infinity/resource/graphics/BamResource.java +++ b/src/infinity/resource/graphics/BamResource.java @@ -604,7 +604,11 @@ private void exportFrames(String filePath, String fileBase, String fileExt, Stri max = decoder.frameCount(); for (int i = 0; i < decoder.frameCount(); i++) { String fileIndex = String.format("%1$05d", i); - BufferedImage image = prepareFrameImage(i); + BufferedImage image = null; + try { + image = prepareFrameImage(i); + } catch (Exception e) { + } if (image != null) { decoder.frameGet(control, i, image); try { @@ -614,11 +618,12 @@ private void exportFrames(String filePath, String fileBase, String fileExt, Stri failCounter++; System.err.println("Error writing frame #" + i); } + image.flush(); + image = null; } else { failCounter++; + System.err.println("Skipping frame #" + i); } - image.flush(); - image = null; } } } catch (Throwable t) { @@ -630,7 +635,7 @@ private void exportFrames(String filePath, String fileBase, String fileExt, Stri if (failCounter == 0 && counter == max) { msg = String.format("All %1$d frames exported successfully.", max); } else { - msg = String.format("%2$d/%1$d frames exported.\n%3$d/%1$d frames not exported.", + msg = String.format("%2$d/%1$d frame(s) exported.\n%3$d/%1$d frame(s) skipped.", max, counter, failCounter); } JOptionPane.showMessageDialog(panel.getTopLevelAncestor(), msg, "Information",