Skip to content

Commit

Permalink
Fixed a bug concerning illegal frames in BAM files for BAM exporter and
Browse files Browse the repository at this point in the history
BAM converter
  • Loading branch information
Argent77 committed Jul 22, 2014
1 parent 4e3365d commit 4591b63
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
16 changes: 13 additions & 3 deletions src/infinity/gui/converter/ConvertToBam.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 9 additions & 4 deletions src/infinity/resource/graphics/BamResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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",
Expand Down

0 comments on commit 4591b63

Please sign in to comment.