package com.aimmac23.node;

import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;

import com.aimmac23.node.jna.EncoderInterface;
import com.aimmac23.node.jna.JnaLibraryLoader;
import com.sun.jna.Pointer;

public class RobotScreenshotSource implements ScreenshotSource {

	private Robot robot;

	public RobotScreenshotSource() throws Exception {
		robot = new Robot();
	}
	
	@Override
	public int applyScreenshot(Pointer encoderContext) {
		BufferedImage image = robot.createScreenCapture(getScreenSize());

		int[] screenshotData = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
		
		EncoderInterface encoder = JnaLibraryLoader.getEncoder();

		return encoder.convert_frame(encoderContext, screenshotData);
	}

	@Override
	public int getWidth() {
		return getScreenSize().width;
	}

	@Override
	public int getHeight() {
		return getScreenSize().height;
	}

	protected Rectangle getScreenSize() {
		//XXX: This probably won't work with multiple monitors
		return GraphicsEnvironment.getLocalGraphicsEnvironment().
				getDefaultScreenDevice().getDefaultConfiguration().getBounds();
		
	}

	@Override
	public void doStartupSanityChecks() {
		// nothing to do - creating the Robot should have done this
	}
}

@@ -167,29 +167,88 @@
 t.image.
-DataBufferInt
+ColorModel;%0Aimport java.awt.image.DataBufferInt;%0Aimport java.util.Arrays
 ;%0A%0Aimpor
@@ -1322,64 +1322,487 @@
 %09// 
-nothing to do - creating the Robot should have done 
+test to make assert that the bit depth is 32 bit%0A%09%09%0A%09%09ColorModel colorModel = GraphicsEnvironment.getLocalGraphicsEnvironment().%0A%09%09getDefaultScreenDevice().getDefaultConfiguration().getColorModel();%0A%09%09%0A%09%09int%5B%5D bitAllocations = colorModel.getComponentSize();%0A%09%09%0A%09%09int bitDepth = 0;%0A%09%09%0A%09%09for(int pixelBitSize : bitAllocations) %7B%0A%09%09%09bitDepth += pixelBitSize; %0A%09%09%7D%0A%09%09%0A%09%09if(bitDepth != 32) %7B%0A%09%09%09throw new IllegalStateException(%22Could not start - display bit dep
 th
+ 
 is
+ not 32-bit%22);%0A%09%09%7D
 %0A%09%7D%0A

Add a test to make sure that the display bit depth is 32-bit