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.ColorModel;
import java.awt.image.DataBufferInt;
import java.util.Arrays;

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() {
		// test to make assert that the bit depth is 32 bit
		
		ColorModel colorModel = GraphicsEnvironment.getLocalGraphicsEnvironment().
		getDefaultScreenDevice().getDefaultConfiguration().getColorModel();
		
		int[] bitAllocations = colorModel.getComponentSize();
		
		int bitDepth = 0;
		
		for(int pixelBitSize : bitAllocations) {
			bitDepth += pixelBitSize; 
		}
		
		if(bitDepth != 32) {
			throw new IllegalStateException("Could not start - display bit depth is not 32-bit");
		}
	}
}

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.ColorModel;
import java.awt.image.DataBufferInt;
import java.util.Arrays;

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() {
		// test to make assert that the bit depth has 8 bits per pixel
		
		ColorModel colorModel = GraphicsEnvironment.getLocalGraphicsEnvironment().
		getDefaultScreenDevice().getDefaultConfiguration().getColorModel();
		
		int[] bitAllocations = colorModel.getComponentSize();
		
		// don't count alpha bits
		int bitDepth = bitAllocations[0] + bitAllocations[1] + bitAllocations[2];
		
		if(bitDepth != 24) {
			throw new IllegalStateException("Display colour depth incorrect (should be 8 bits of red, blue and green). Currently: " 
					+ bitAllocations[0] + "-" + bitAllocations[1] + "-" + bitAllocations[2]);
		}
	}
}

Fix bit depth detection logic, and error message