The Code
ImageOpApp.prototype = new MultimediaApp();
ImageOpApp.prototype.constructor = ImageOpApp;
MultimediaApp.images = ["car.png"];
/**
* Default Constructor
*/
function ImageOpApp()
{
var kernel;
kernel = new Kernel(3, 3, [1/9, 1/9, 1/9,
1/9, 1/9, 1/9,
1/9, 1/9, 1/9]);
this.blur = new ConvolveOp(kernel);
kernel = new Kernel(3, 3, [ 0, -1, 0,
-1, 5, -1,
0, -1, 0]);
this.sharpen = new ConvolveOp(kernel);
kernel = new Kernel(3, 3, [ 0, -1, 0,
-1, 4, -1,
0, -1, 0]);
this.edge = new ConvolveOp(kernel);
this.gray = new GrayOp();
}
/**
* Initialize this app
*/
ImageOpApp.prototype.init = function()
{
this.view = new VisualizationView(this.canvas);
this.visualization = new Visualization(this.view);
this.source = this.imageFactory.createBufferedImage("car.png");
this.before = new SampledContent(this.source);
this.before.setLocation(0,0);
this.visualization.add(this.before);
this.visualization.repaint();
}
/**
* Handle button events
*/
ImageOpApp.prototype.actionPerformed = function(actionCommand)
{
if (actionCommand == "Reset")
{
this.visualization.remove(this.before);
this.visualization.remove(this.after);
this.visualization.add(this.before);
this.visualization.repaint();
}
else
{
var dest = null;
if (actionCommand == "Blur") dest = this.blur.filter(this.source);
else if (actionCommand == "Edge") dest = this.edge.filter(this.source);
else if (actionCommand == "Gray") dest = this.gray.filter(this.source);
else if (actionCommand == "Sharpen") dest = this.sharpen.filter(this.source);
if (dest != null)
{
this.visualization.remove(this.before);
this.visualization.remove(this.after);
this.after = new SampledContent(dest);
this.after.setLocation(0,0);
this.visualization.add(this.after);
this.visualization.repaint();
}
}
}