edu.unh.iol.dlc.Framebuffer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sikulixapi Show documentation
Show all versions of sikulixapi Show documentation
... for visual testing and automation
/*
* University of New Hampshire
* InterOperability Laboratory
* Copyright (c) 2014
*
* This software is provided by the IOL ``AS IS'' and any express or implied
* warranties, including, but not limited to, the implied warranties of
* merchantability and fitness for a particular purpose are disclaimed.
* In no event shall the InterOperability Lab be liable for any direct,
* indirect, incidental, special, exemplary, or consequential damages.
*
* This software may not be resold without the express permission of
* the InterOperability Lab.
*
* Feedback on this code may be sent to Mike Johnson ([email protected])
* and [email protected].
*/
package edu.unh.iol.dlc;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import org.sikuli.basics.Debug;
/**
* The framebuffer class is responsible for maintaining the local
* copy of the remote framebuffer. The class extends GraphicsDevice
* so that it can be used with the java2D API.
*
* @author Mike Johnson
*/
public class Framebuffer extends GraphicsDevice {
/*
* Below are the fields associated with the
* Server's PixelFormat and Framebuffer.
*/
private FBConfig conf = null;
private BufferedImage buffer;
private int[][] rgbs = null;
private boolean updated = false;
private BufferedImage doubleBuffer;
//General methods*************************************************************/
/**
* Method that sets the pixel format of the framebuffer.
*
* @param int[] sets the pixel format of the framebuffer for the connection
* @param String name of the remote desktop
* @return true if the pixel format is valid for what the VNC stack
* currently supports
* false if the pixel format is not valid
*/
protected boolean setPF(int[] data, String name){
if(conf != null){
int[] array = {getWidth(), getHeight(), data[0],data[1],data[2],
data[3],data[4],data[5],data[6],data[7],data[8],data[9]};
conf = new FBConfig(array, name);
}
else{
conf = new FBConfig(data, name);
}
if(conf.getIdNum() == 5){
return false;
}
return true;
}
/**
* Resets the pixel format to a different configuration
*
* @param int[] sets the pixel format of the framebuffer for the connection
* @param String name of the remote desktop
* @return true if the pixel format is valid for what the VNC stack
* currently supports
* false if the pixel format is not valid
*
*/
protected boolean resetPF(int[] data){
return setPF(data, conf.getName());
}
/**
* Gets the PixelFormat in the form of a GraphicsConfiguration
* object
*
* @return conf the GraphicsConfiguration
*/
protected GraphicsConfiguration getPF(){
return conf;
}
/**
* Gets the width of the framebuffer
*/
protected int getWidth(){
return conf.getBounds().width;
}
/**
* Gets the height of the framebuffer
*/
protected int getHeight(){
return conf.getBounds().height;
}
/**
* Sets the buffer according to the specified raster
*/
private synchronized void setBuffer(WritableRaster raster){
buffer = conf.createCompatibleImage(
conf.getBounds().width, conf.getBounds().height);
buffer.setData(raster);
updated = true;
doubleBuffer = buffer;
}
/**
* Gets the buffer
*/
protected synchronized BufferedImage getBuffer(){
//return doubleBuffer;
if(updated){
updated=false;
return buffer;
}
return doubleBuffer;
}
//Raw Encoding Methods********************************************************/
/**
* Copies raw pixel array (which is actually a
* rectangle of pixel data) into the buffer.
*
* @param x x location of origin of pixel rectangle
* @param y y location of origin of pixel rectangle
* @param w width of pixel rectangle
* @param h height of pixel rectangle
* @param input array containing pixel data
*/
protected void raw(int x, int y, int w,
int h, int[] input){
if(rgbs==null){
rgbs = new
int[conf.getBounds().width*3][conf.getBounds().height];
}
int count = 0;
label:
for(int j=y;j