Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.awt.*;
  2. import java.awt.image.*;
  3. import javax.swing.*;
  4.  
  5. public class OFImage extends BufferedImage {
  6.     public OFImage(BufferedImage image) {
  7.         // TODO Auto-generated constructor stub
  8.         super(image.getColorModel(), image.copyData(null), image.isAlphaPremultiplied(), null);
  9.     }
  10.     public OFImage(int width, int height)
  11.     {
  12.         super(width, height, TYPE_INT_RGB);
  13.     }
  14.    
  15.     public void setPixel(int x, int y, Color col)
  16.     {
  17.         int pixel = col.getRGB();
  18.         setRGB(x,y,pixel);
  19.     }
  20.    
  21.     public Color getPixel(int x, int y)
  22.     {
  23.         int pixel = getRGB(x, y);
  24.         return new Color(pixel);
  25.     }
  26.    
  27.     public void darker()
  28.     {
  29.         int height = getHeight(), width = getWidth();
  30.         for (int y = 0; y < height; y++)
  31.         {
  32.             for (int x = 0; x < width; x++)
  33.             {
  34.                 setPixel(x, y, getPixel(x, y).darker());
  35.             }
  36.         }
  37.     }
  38.     public void lighter()
  39.     {
  40.         int height = getHeight(), width = getWidth();
  41.         for (int y = 0; y < height; y++)
  42.         {
  43.             for (int x = 0; x < width; x++)
  44.             {
  45.                 setPixel(x, y, getPixel(x, y).brighter());
  46.             }
  47.         }
  48.     }
  49.     public void threshold()
  50.     {
  51.         int height = getHeight(), width = getWidth();
  52.         for (int y = 0; y < height; y++)
  53.         {
  54.             for (int x = 0; x < width; x++)
  55.             {
  56.                 Color pixel = getPixel(x, y);
  57.                 int brightness = (pixel.getRed() + pixel.getGreen() + pixel.getBlue()) / 3;
  58.                 if(brightness <= 85)
  59.                 {
  60.                     setPixel(x, y, Color.BLACK);
  61.                 }
  62.                 else if (brightness <= 170)
  63.                 {
  64.                     setPixel(x, y, Color.GRAY);
  65.                 }
  66.                 else
  67.                 {
  68.                     setPixel(x, y, Color.WHITE);
  69.                 }
  70.                
  71.             }
  72.         }
  73.     }
  74. }