import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class OFImage extends BufferedImage {
public OFImage(BufferedImage image) {
// TODO Auto-generated constructor stub
super(image.getColorModel(), image.copyData(null), image.isAlphaPremultiplied(), null);
}
public OFImage(int width, int height)
{
super(width, height, TYPE_INT_RGB);
}
public void setPixel(int x, int y, Color col)
{
int pixel = col.getRGB();
setRGB(x,y,pixel);
}
public Color getPixel(int x, int y)
{
int pixel = getRGB(x, y);
return new Color(pixel);
}
public void darker()
{
int height = getHeight(), width = getWidth();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
setPixel(x, y, getPixel(x, y).darker());
}
}
}
public void lighter()
{
int height = getHeight(), width = getWidth();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
setPixel(x, y, getPixel(x, y).brighter());
}
}
}
public void threshold()
{
int height = getHeight(), width = getWidth();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
Color pixel = getPixel(x, y);
int brightness = (pixel.getRed() + pixel.getGreen() + pixel.getBlue()) / 3;
if(brightness <= 85)
{
setPixel(x, y, Color.BLACK);
}
else if (brightness <= 170)
{
setPixel(x, y, Color.GRAY);
}
else
{
setPixel(x, y, Color.WHITE);
}
}
}
}
}