scale the image to 16x9

This commit is contained in:
Aaron Neyer
2013-12-13 13:07:05 -05:00
parent 5fc3487317
commit dd366b2e62
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 int width, height;
private Graphics graphics; private Graphics graphics;
private JFrame frame;
private BufferedImage image; private BufferedImage image;
private static final int DECODER_BUFFER_SIZE = 92*1024; 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); throw new IllegalStateException("AVC decoder initialization failure: "+err);
} }
graphics = ((JFrame)renderTarget).getGraphics(); frame = (JFrame)renderTarget;
graphics = frame.getGraphics();
image = new BufferedImage(width, height, image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_BGR); BufferedImage.TYPE_INT_BGR);
@@ -82,10 +84,15 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
} catch (InterruptedException e) { } catch (InterruptedException e) {
return; 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); nextFrameTime = computePresentationTimeMs(targetFps);
if (AvcDecoder.getRgbFrameInt(imageBuffer, imageBuffer.length)) { 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; bestConfig = config;
} }
} }
if (bestConfig == null) {
return configs[0];
}
return bestConfig; return bestConfig;
} }
@@ -109,12 +112,6 @@ public class StreamFrame extends JFrame {
DisplayMode config = getBestDisplay(gd.getDisplayModes()); DisplayMode config = getBestDisplay(gd.getDisplayModes());
if (config != null) { if (config != null) {
gd.setDisplayMode(config); gd.setDisplayMode(config);
} else {
JOptionPane.showMessageDialog(
this,
"Your display does not support a resolution greater than 1280x720",
"No Supported Resolution",
JOptionPane.ERROR_MESSAGE);
} }
} else { } else {
JOptionPane.showMessageDialog( JOptionPane.showMessageDialog(