ppt
Class ImageStreamer

java.lang.Object
  extended by ppt.ImageStreamer

public class ImageStreamer
extends java.lang.Object

The ImageStreamer class is used as client in ImageServer. The class main functionality is to receive PNG file as BufferedImage, divide the image by squares. The square then get compared with the previous ones from the same location. The new square gets sent to the client via real time protocol - RTP


Field Summary
(package private)  java.awt.image.BufferedImage image
           
(package private)  int imageHeight
           
(package private)  int imageWidth
           
(package private)  boolean initialized
           
(package private) static org.apache.log4j.Logger logger
           
(package private)  int numOfCols
           
(package private)  int numOfRows
           
(package private)  java.io.OutputStream out
           
(package private) static int tileHeight
           
(package private)  java.lang.Object[] tiles
           
(package private) static int tileWidth
           
 
Constructor Summary
ImageStreamer(java.io.OutputStream socketOutputStream, java.awt.image.BufferedImage bufImage)
          Constructor which is used for each client to open a window, initialize an array for storing squares with dimensions according to the first image recived.
 
Method Summary
 byte[] createPacketHeader(int code, int id, int length, boolean isMarker)
          The method creates header as byte array
 byte[] createWindowDimensions(byte[] b, int left, int top, int width, int heigth, int x)
          The method adds creates dimensions for window in byte array It is used in packets for resizing a window (code 2)
 byte[] dataPacket(byte[] buffer, int l, int t, int w, int h, boolean isMarker)
          THe method creates packet with data.
 boolean equals(byte[] array1, byte[] array2)
          The method compares two subimages as byte arrays
 byte[] imageToByteArray(java.awt.image.BufferedImage bi)
          The method gets BufferedImage as byte array
 byte[] openWindowPacket()
          The method opens a window (code 0)
 byte[] resizeWindowPacket()
          The method resizes window (code 2)
 void sendImage()
          The method gets splits image on squares.
 void setImage(java.awt.image.BufferedImage bufImage)
          The method sets image for every new png created file and sends the image to client
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static org.apache.log4j.Logger logger

out

java.io.OutputStream out

initialized

boolean initialized

image

java.awt.image.BufferedImage image

imageWidth

int imageWidth

imageHeight

int imageHeight

tileWidth

static int tileWidth

tileHeight

static int tileHeight

tiles

java.lang.Object[] tiles

numOfCols

int numOfCols

numOfRows

int numOfRows
Constructor Detail

ImageStreamer

public ImageStreamer(java.io.OutputStream socketOutputStream,
                     java.awt.image.BufferedImage bufImage)
Constructor which is used for each client to open a window, initialize an array for storing squares with dimensions according to the first image recived.

Parameters:
socketOutputStream - as OutputStream
bufImage - as BufferedImage
Method Detail

setImage

public void setImage(java.awt.image.BufferedImage bufImage)
The method sets image for every new png created file and sends the image to client

Parameters:
bufImage - as BufferedImage

sendImage

public void sendImage()
               throws java.io.IOException
The method gets splits image on squares. A data packet is created and gets sent for each new square after comparison with the previous one from the same location if such existed.

Throws:
java.io.IOException

openWindowPacket

public byte[] openWindowPacket()
The method opens a window (code 0)

Returns:
byte array

resizeWindowPacket

public byte[] resizeWindowPacket()
The method resizes window (code 2)

Returns:
byte array

dataPacket

public byte[] dataPacket(byte[] buffer,
                         int l,
                         int t,
                         int w,
                         int h,
                         boolean isMarker)
THe method creates packet with data. (code 3)

Parameters:
buffer - contained subimage
l - - left position for the subimage
t - - top position for the subimage
w - - width of of subimage
h - - height of the subimage
isMarker - is true for each packet
Returns:
byte array contained header, dimensions and subimage in bytes before encoding it on client side

createPacketHeader

public byte[] createPacketHeader(int code,
                                 int id,
                                 int length,
                                 boolean isMarker)
The method creates header as byte array

Parameters:
code -
id -
length -
isMarker -
Returns:
byte array for a header, code and window id

createWindowDimensions

public byte[] createWindowDimensions(byte[] b,
                                     int left,
                                     int top,
                                     int width,
                                     int heigth,
                                     int x)
The method adds creates dimensions for window in byte array It is used in packets for resizing a window (code 2)

Parameters:
b - - byte array
left -
top -
width -
heigth -
x - - position in byte array which starts after header end position
Returns:
byte array for left, top, width and heigth window sizes

imageToByteArray

public byte[] imageToByteArray(java.awt.image.BufferedImage bi)
The method gets BufferedImage as byte array

Parameters:
bi - as BufferedImage
Returns:
byte array

equals

public boolean equals(byte[] array1,
                      byte[] array2)
The method compares two subimages as byte arrays

Parameters:
array1 - as byte array
array2 - as byte array
Returns:
boolean