public class FrameBuffer extends java.lang.Object
This FrameBuffer represents a two-dimensional array of pixel data. The data is stored as a one dimensional array in row-major order. The first row of data should be displayed as the top row of pixels in the image (or window).
The "viewport" is a two-dimensional sub array of this framebuffer. The viewport is represented by its upper-left-hand corner and its lower-right-hand corner.
Framebuffer and viewport coordinates act like Java Graphics coordinates; the positive x direction is to the right and the positive y direction is downward.
Modifier and Type | Field and Description |
---|---|
protected int[] |
pixel_buffer |
Constructor and Description |
---|
FrameBuffer(int w,
int h)
Construct a FrameBuffer with the given dimensions.
|
FrameBuffer(java.lang.String inputFileName)
Construct a FrameBuffer from a PPM image file.
|
Modifier and Type | Method and Description |
---|---|
void |
clearFB(java.awt.Color c)
Clear the framebuffer (set a background color).
|
void |
clearVP(java.awt.Color c)
Clear the viewport (set a background color).
|
FrameBuffer |
convertBlue2FB()
Convert the blue plane of the framebuffer into a framebuffer.
|
FrameBuffer |
convertGreen2FB()
Convert the green plane of the framebuffer into a framebuffer.
|
FrameBuffer |
convertRed2FB()
Convert the red plane of the framebuffer into a framebuffer.
|
FrameBuffer |
convertVP2FB()
Convert the viewport into a framebuffer.
|
void |
dumpFB2File(java.lang.String filename)
Write the framebuffer to the specified file.
|
void |
dumpPixels2File(int ul_x,
int ul_y,
int lr_x,
int lr_y,
java.lang.String filename)
Write a rectangular sub array of pixels from the framebuffer to the specified file.
|
void |
dumpVP2File(java.lang.String filename)
Write the viewport to the specified file.
|
void |
fbTest()
A simple test of the framebuffer.
|
java.awt.Color |
getBgColorFB()
Get the background color of the framebuffer.
|
java.awt.Color |
getBgColorVP()
Get the background color of the viewport.
|
int |
getHeightFB()
Get the height of the framebuffer.
|
int |
getHeightVP()
Get the height of the viewport.
|
java.awt.Point |
getLocationVP()
Get the upper left hand corner of the viewport.
|
java.awt.Color |
getPixelFB(int x,
int y)
Get the color of the pixel with coordinates
(x,y) in the framebuffer.
|
java.awt.Color |
getPixelVP(int x,
int y)
Get the color of the pixel with coordinates
(x,y) relative to the current viewport.
|
int |
getWidthFB()
Get the width of the framebuffer.
|
int |
getWidthVP()
Get the width of the viewport.
|
static void |
main(java.lang.String[] args)
A main() method for testing the FrameBuffer class.
|
void |
setPixelFB(int x,
int y,
java.awt.Color c)
Set the color of the pixel with coordinates
(x,y) in the framebuffer.
|
void |
setPixelVP(int x,
int y,
java.awt.Color c)
Set the color of the pixel with coordinates
(x,y) relative to the current viewport.
|
void |
setViewport(int vp_ul_x,
int vp_ul_y,
FrameBuffer sourceFB)
Create a Viewport from a FrameBuffer.
|
void |
setViewport(int vp_ul_x,
int vp_ul_y,
int width,
int height)
Set the coordinates, within the FrameBuffer, of the
viewport's upper-left-hand corner, width, and height.
|
void |
setViewport(int vp_ul_x,
int vp_ul_y,
java.lang.String inputFileName)
Create a Viewport from a PPM image file.
|
void |
vpTest()
A simple test of the viewport.
|
protected int[] pixel_buffer
public FrameBuffer(int w, int h)
w
- Width of the FrameBuffer.h
- Height of the FrameBuffer.public FrameBuffer(java.lang.String inputFileName)
inputFileName
- Must name a PPM image file with magic number P6.public void clearFB(java.awt.Color c)
c
- color to clear framebuffer withpublic void clearVP(java.awt.Color c)
c
- color to clear current viewport withpublic FrameBuffer convertBlue2FB()
public FrameBuffer convertGreen2FB()
public FrameBuffer convertRed2FB()
public FrameBuffer convertVP2FB()
public void dumpFB2File(java.lang.String filename)
filename
- name of PPM image file to hold framebuffer datapublic void dumpPixels2File(int ul_x, int ul_y, int lr_x, int lr_y, java.lang.String filename)
Write a rectangular sub array of pixels from the framebuffer to the specified file.
http://stackoverflow.com/questions/2693631/read-ppm-file-and-store-it-in-an-array-coded-with-c
ul_x
- upper left hand x-coordinate of pixel data rectangleul_y
- upper left hand y-coordinate of pixel data rectanglelr_x
- lower right hand x-coordinate of pixel data rectanglelr_y
- lower right hand y-coordinate of pixel data rectanglefilename
- name of PPM image file to hold pixel datapublic void dumpVP2File(java.lang.String filename)
filename
- name of PPM image file to hold viewport datapublic void fbTest()
public java.awt.Color getBgColorFB()
public java.awt.Color getBgColorVP()
public int getHeightFB()
public int getHeightVP()
public java.awt.Point getLocationVP()
public java.awt.Color getPixelFB(int x, int y)
x
- horizontal coordinate within the framebuffery
- vertical coordinate within the framebufferpublic java.awt.Color getPixelVP(int x, int y)
x
- horizontal coordinate within the current viewporty
- vertical coordinate within the current viewportpublic int getWidthFB()
public int getWidthVP()
public static void main(java.lang.String[] args)
args
- command-line arguments to main() methodpublic void setPixelFB(int x, int y, java.awt.Color c)
x
- horizontal coordinate within the framebuffery
- vertical coordinate within the framebufferc
- color for the pixel at the given pixel coordinatespublic void setPixelVP(int x, int y, java.awt.Color c)
x
- horizontal coordinate within the current viewporty
- vertical coordinate within the current viewportc
- color for the pixel at the given viewport coordinatespublic void setViewport(int vp_ul_x, int vp_ul_y, FrameBuffer sourceFB)
vp_ul_x
- upper left hand x-coordinate of new viewport rectanglevp_ul_y
- upper left hand y-coordinate of new viewport rectanglesourceFB
- FrameBuffer to use as the source of the pixel data..public void setViewport(int vp_ul_x, int vp_ul_y, int width, int height)
vp_ul_x
- upper left hand x-coordinate of new viewport rectanglevp_ul_y
- upper left hand y-coordinate of new viewport rectanglewidth
- viewport's widthheight
- viewport's heightpublic void setViewport(int vp_ul_x, int vp_ul_y, java.lang.String inputFileName)
vp_ul_x
- upper left hand x-coordinate of new viewport rectanglevp_ul_y
- upper left hand y-coordinate of new viewport rectangleinputFileName
- Must name a PPM image file with magic number P6.public void vpTest()