vxp
Class PixelSource

java.lang.Object
  extended byvxp.PixelSource
Direct Known Subclasses:
ImagePixelSource, JMFLivePixelSource, JMFLivePushPixelSource, QTLivePixelSource, QTMoviePixelSource, StillImagePixelSource

public abstract class PixelSource
extends java.lang.Object

Author:
Dan O'Sullivan Abastracts the particulars or getting video. Video is usually returned to you in a big long linear array when you would like a two dimenensionaly array for x and y. Furthermore the individual colors are packed inside a single int. Of course you also have the problems of different video systems delivering things differently. Pixelsource and it's implementations try to give you single simple interface for getting at the individual pictures of video.

Field Summary
 int kHeight
          This is the height of the video that you requested when you constructed this object
 int kWidth
          This is the width of the video that you requested when you constructed this object
 int vidWidth
          This is the width of the video after you have created the video.
 
Constructor Summary
PixelSource(int pw, int ph)
          Constructor class.
 
Method Summary
 void addVideoListener(VideoListener _videoListener)
          This will make the pixelsource notify you when a new frame is ready.
 void getArray(java.awt.image.BufferedImage _bi, int _x, int _y, int _w, int _h, int[] _iArray)
          Converts a Buffered Image into an array.
 int[] getColorOrder()
          This is the amount you would would have to shift a byte packed into an int to give you an accurate value.
 java.lang.String[] getDeviceList()
           
 java.lang.String getDeviceName()
           
 java.awt.image.BufferedImage getImage()
          Gives you the video image in the form of a bufferedImage.
 void getImage(java.awt.image.BufferedImage _bi)
          Puts a the video image into an image supplied by you.
 int[] getPixel(int[] inArray, int _offset)
          Separates Red Green and Blue out of an array where where all three colors are packed into a single int.
 int[] getPixel(int[] inArray, int x, int y)
          Separates Red Green and Blue out of an array where where all three colors are packed into a single int.
 int[] getPixel(int x, int y)
           
 int[] getPixelArray()
          Gives you all the pixels as a linear int array with the r,g and b all packed into integers.
 void getPixelArray(int[] _outsidePixels)
          Copies all the currrent pixels into the array that you supply
 int[] getPixelBrightness(int x, int y)
           
 int getVideoHeight()
          This returns the height of the video.
 int getVideoWidth()
          This returns the actual width of the video which may differ from the width you requested because some extra slop bytes may be added at the end of each line.
 boolean grabFrame()
          Brings a new set of pixels into the system to be used by getPixel, setPixel, getImage etc...
 void idleIt()
          Tells the digitizer to freshen up the pixels.
 void killSession()
          Be sure to call this when you close or destroy your main window so a connection to your camera is not left hanging .
 java.lang.String setDevice(int whichSource)
           
 java.lang.String setDevice(java.lang.String whichSource)
           
 void setImageType()
          This needs to be done after configuring the video where you learn about the format of the pixels.
 void setImageType(int type)
          You can specify which type of image to supply with the getImage command
 void setInput(int _bla)
          This returns the height of the video.
 void setNativeArrays()
          This needs to be done after configuring the video where you learn about the widths and heights available.
 void setPixel(int[] inputArray, int _offset, int red, int green, int blue, int alpha)
          Sets the color of a given pixel within a supplied array but uses a precomputed offset instead of the x and y.
 void setPixel(int[] inputArray, int x, int y, int red, int green, int blue, int alpha)
          Sets the color of a given pixel within an array of pixels.
 void setPixel(int _offset, int red, int green, int blue, int alpha)
          Sets the color of a given pixel within the current frame but uses a precomputed offset instead of the x and y.
 void setPixel(int x, int y, int red, int green, int blue, int alpha)
          Sets the color of a pixel in the current frame of video at a given location.
 void tellVideoListeners()
           
 void videoSettings()
          Gives you a pop up dialog box for the video digitizer driver.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kWidth

public int kWidth
This is the width of the video that you requested when you constructed this object


vidWidth

public int vidWidth
This is the width of the video after you have created the video. It may vary from your requested width


kHeight

public int kHeight
This is the height of the video that you requested when you constructed this object

Constructor Detail

PixelSource

public PixelSource(int pw,
                   int ph)
Constructor class. Remember the eventual width may vary from what you asked for. Safer to use getVideoWidth() after making this object

Parameters:
pw - width of the video
ph - height of the video
Method Detail

getVideoWidth

public int getVideoWidth()
This returns the actual width of the video which may differ from the width you requested because some extra slop bytes may be added at the end of each line. Sometimes no bytes are added (on most pc's) but sometime 4 bytes are added (most MACs).


getVideoHeight

public int getVideoHeight()
This returns the height of the video.


setNativeArrays

public void setNativeArrays()
This needs to be done after configuring the video where you learn about the widths and heights available. You usually don't have to worry about this.


setImageType

public void setImageType()
This needs to be done after configuring the video where you learn about the format of the pixels. You usually don't have to worry about this.


setImageType

public void setImageType(int type)
You can specify which type of image to supply with the getImage command

Parameters:
type - Usually this is is either BufferedImage.TYPE_INT_ARGB or BufferedImage.TYPE_INT_RGB.

getImage

public java.awt.image.BufferedImage getImage()
Gives you the video image in the form of a bufferedImage.


getImage

public void getImage(java.awt.image.BufferedImage _bi)
Puts a the video image into an image supplied by you.

Parameters:
_bi - the BufferedImage into which you would like the video image placed.

getArray

public void getArray(java.awt.image.BufferedImage _bi,
                     int _x,
                     int _y,
                     int _w,
                     int _h,
                     int[] _iArray)
Converts a Buffered Image into an array. This is useful for using built in operators for imaging but then being able to through it as an array.

Parameters:
_bi -
_x -
_y -
_w -
_h -
_iArray -

getDeviceName

public java.lang.String getDeviceName()

getPixel

public int[] getPixel(int x,
                      int y)
Parameters:
x -
y -
Returns:
integer array with the offset in 0, the r in 1, the g in 2 and the b in 3

getPixelBrightness

public int[] getPixelBrightness(int x,
                                int y)

addVideoListener

public void addVideoListener(VideoListener _videoListener)
This will make the pixelsource notify you when a new frame is ready. You have to have made your other class a "VideoListener" by implementing "VideoListener." You also have to have put in a "newFrame()" function in the other class.

Parameters:
_videoListener - This should be your other class. Try using "this".

tellVideoListeners

public void tellVideoListeners()

getPixel

public int[] getPixel(int[] inArray,
                      int x,
                      int y)
Separates Red Green and Blue out of an array where where all three colors are packed into a single int. Offset comes back first, then R, then G then B.

Parameters:
x -
y -
Returns:
int array with offset in the 0 position Red in 1, Green in 2, Blue in 3

getPixel

public int[] getPixel(int[] inArray,
                      int _offset)
Separates Red Green and Blue out of an array where where all three colors are packed into a single int. Offset comes back first, then R, then G then B.

Returns:
int array with offset in the 0 position Red in 1, Green in 2, Blue in 3

getPixelArray

public int[] getPixelArray()
Gives you all the pixels as a linear int array with the r,g and b all packed into integers.

Returns:

getPixelArray

public void getPixelArray(int[] _outsidePixels)
Copies all the currrent pixels into the array that you supply

Parameters:
_outsidePixels - array that you want the pixel values placed into

setPixel

public void setPixel(int x,
                     int y,
                     int red,
                     int green,
                     int blue,
                     int alpha)
Sets the color of a pixel in the current frame of video at a given location.

Parameters:
x -
y -
red -
green -
blue -
alpha -

setPixel

public void setPixel(int[] inputArray,
                     int x,
                     int y,
                     int red,
                     int green,
                     int blue,
                     int alpha)
Sets the color of a given pixel within an array of pixels.

Parameters:
inputArray -
x -
y -
red -
green -
blue -
alpha -

setPixel

public void setPixel(int _offset,
                     int red,
                     int green,
                     int blue,
                     int alpha)
Sets the color of a given pixel within the current frame but uses a precomputed offset instead of the x and y. Often set pixel is used after getPixel where you get the offset back so there it is faster if you this function does not have to computer it again.

Parameters:
_offset -
red -
green -
blue -
alpha -

setPixel

public void setPixel(int[] inputArray,
                     int _offset,
                     int red,
                     int green,
                     int blue,
                     int alpha)
Sets the color of a given pixel within a supplied array but uses a precomputed offset instead of the x and y. Often set pixel is used after getPixel where you get the offset back so there it is faster if you this function does not have to computer it again.

Parameters:
inputArray -
_offset -
red -
green -
blue -
alpha -

videoSettings

public void videoSettings()
Gives you a pop up dialog box for the video digitizer driver.


idleIt

public void idleIt()
Tells the digitizer to freshen up the pixels. You don't have to call this if you set the frame rate in the constructor.


grabFrame

public boolean grabFrame()
Brings a new set of pixels into the system to be used by getPixel, setPixel, getImage etc...

Returns:

killSession

public void killSession()
Be sure to call this when you close or destroy your main window so a connection to your camera is not left hanging .


setDevice

public java.lang.String setDevice(int whichSource)

setDevice

public java.lang.String setDevice(java.lang.String whichSource)

setInput

public void setInput(int _bla)
This returns the height of the video.


getDeviceList

public java.lang.String[] getDeviceList()

getColorOrder

public int[] getColorOrder()
This is the amount you would would have to shift a byte packed into an int to give you an accurate value. You only need this if you start accessing the int array yourself and unpacking the ARGB out of the ints. They are returned in the order of argb. Using getPixel and setPixel allows you to avoid all of this.