import java.awt.*;
import java.io.*;
import java.awt.image.*;
/**
Class ImageData is a base class which
respresents image data and the methods for
producing the corresponding wavelet image,
as well as methods to access both of these
datas.
@author L. Grewe
@version 0.0a Feb. 1999
*/
//Note: extends Component to inherit its createImage() method
class ImageData extends Component
{ boolean verbose = false;
//File where data stored and format
String filename = "";
String format = "";
// Num Rows, columns
public int rows=0, cols=0;
//image data
public int data[]; //TIP: MAYBE CHANGING THIS TO USE java.awt.Image WOULD MAKE YOUR CODING EASIER
public float minDataRange = Float.MAX_VALUE;
public float maxDataRange = Float.MIN_VALUE;
//**METHODS: for image data*/
int getData(int row, int col)
{ if (row < rows && col > 16) & 0xff;
green = (pixel >> 8) & 0xff;
blue = (pixel ) & 0xff;
if(verbose)
System.out.println("RGB: " + red + "," + green +"," +blue);
data[r*cols+c] = (int)((red+green+blue)/3); //SPECIAL NOTE: This sample code converts RGB image to a greyscale one
if(verbose)
System.out.println("Pixel: " + (int)((red+green+blue)/3));
minDataRange = Math.min(minDataRange, data[r*cols+c]);
maxDataRange = Math.max(maxDataRange, data[r*cols+c]);
}
//{{INIT_CONTROLS
setBackground(java.awt.Color.white);
setSize(0,0);
//}}
}
/**
* Constructs a ImageData object using the
* specified size indicated by
* numberRows and numberColumns that is EMPTY.
* @param numberRows the number of rows of data
* @param numberColumns the number of columns of data
*/
public ImageData(int numberRows, int numberColumns){
rows = numberRows;
cols = numberColumns;
}
/**
* Constructs a ImageData object using the
* specified size indicated by
* numberRows and numberColumns. Fill the data[]
* array with the information stored in
* the ImageData instance ID, from the 2D
* neighborhood starting at the upper-left coordinate
* (rStart,cStart)
* @param numberRows the number of rows of data
* @param numberColumns the number of columns of data
* @param ID image data to copy data from
* @param rStart,cStart Start of Neighborhood copy
*/
public ImageData(int numberRows, int numberColumns, ImageData ID,
int rStart,int cStart){
//saftey check: Retrieval in ID outside of boundaries
if(ID.rows<(rStart+numberRows) || ID.cols<(cStart+numberColumns))
{ rows = 0;
cols = 0;
return;
}
rows = numberRows;
cols = numberColumns;
//create data[] array.
data = new int[rows*cols];
//Copy data from ID.
for(int i=0; i255) //due to processing
{ t = 255; }
pixels[r*cols+c] = (255 << 24) | (t << 16) | (t << 8) | t;
//note data is greyscale so red=green=blue above (alpha first)
}
//Now create Image using new MemoryImageSource
return ( super.createImage(new MemoryImageSource(cols, rows, pixels, 0, cols)));
}
/**
*Stores the data image to a
* a file as COLOR raw image data format
*/
public void storeImage(String filename)throws IOException
{
int pixel, alpha, red, green,blue;
//Open up file
FileOutputStream file_output = new FileOutputStream(filename);
DataOutputStream DO = new DataOutputStream(file_output);
//Write out each pixel as integers
for(int r=0; r