scale the image to 16x9

This commit is contained in:
Aaron Neyer
2013-12-13 13:07:05 -05:00
parent a6ed6e2233
commit 3147e34a5a
2 changed files with 12 additions and 8 deletions

View File

@@ -19,6 +19,7 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
private int width, height;
private Graphics graphics;
private JFrame frame;
private BufferedImage image;
private static final int DECODER_BUFFER_SIZE = 92*1024;
@@ -50,7 +51,8 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
throw new IllegalStateException("AVC decoder initialization failure: "+err);
}
graphics = ((JFrame)renderTarget).getGraphics();
frame = (JFrame)renderTarget;
graphics = frame.getGraphics();
image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_BGR);
@@ -82,10 +84,15 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
} catch (InterruptedException e) {
return;
}
double widthScale = (double)frame.getWidth() / width;
double heightScale = (double)frame.getHeight() / height;
double lowerScale = Math.min(widthScale, heightScale);
int newWidth = (int)(width * lowerScale);
int newHeight = (int)(height * lowerScale);
nextFrameTime = computePresentationTimeMs(targetFps);
if (AvcDecoder.getRgbFrameInt(imageBuffer, imageBuffer.length)) {
graphics.drawImage(image, 0, 0, width, height, null);
graphics.drawImage(image, 0, 0, newWidth, newHeight, null);
}
}
}

View File

@@ -96,6 +96,9 @@ public class StreamFrame extends JFrame {
bestConfig = config;
}
}
if (bestConfig == null) {
return configs[0];
}
return bestConfig;
}
@@ -109,12 +112,6 @@ public class StreamFrame extends JFrame {
DisplayMode config = getBestDisplay(gd.getDisplayModes());
if (config != null) {
gd.setDisplayMode(config);
} else {
JOptionPane.showMessageDialog(
this,
"Your display does not support a resolution greater than 1280x720",
"No Supported Resolution",
JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(