document.write('
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.   * @author Rafif Ridho
  6.   * @version 1.0  
  7.   */  
  8.   public class OFImage extends BufferedImage  
  9.   {  
  10.    public OFImage(BufferedImage image)  
  11.    {  
  12.     super(image.getColorModel(), image.copyData(null),    
  13.       image.isAlphaPremultiplied(), null);  
  14.    }    
  15.    public OFImage(int width, int height)  
  16.    {  
  17.     super(width, height, TYPE_INT_RGB);  
  18.    }    
  19.    public void setPixel(int x, int y, Color col)  
  20.    {  
  21.     int pixel = col.getRGB();  
  22.     setRGB(x, y, pixel);  
  23.    }  
  24.    public Color getPixel(int x, int y)  
  25.    {  
  26.     int pixel = getRGB(x, y);  
  27.     return new Color(pixel);  
  28.    }  
  29.    public void darker()  
  30.    {  
  31.     int height = getHeight();  
  32.     int width = getWidth();  
  33.     for(int y = 0; y < height; y++) {  
  34.      for(int x = 0; x < width; x++) {  
  35.       setPixel(x, y, getPixel(x, y).darker());  
  36.      }  
  37.     }  
  38.    }  
  39.    public void lighter()  
  40.    {  
  41.     int height = getHeight();  
  42.     int width = getWidth();  
  43.     for(int y = 0; y < height; y++) {  
  44.      for(int x = 0; x < width; x++) {  
  45.       setPixel(x, y, getPixel(x, y).brighter());  
  46.      }  
  47.     }  
  48.    }  
  49.    public void threshold()  
  50.    {  
  51.     int height = getHeight();  
  52.     int width = getWidth();  
  53.     for(int y = 0; y < height; y++) {  
  54.      for(int x = 0; x < width; x++) {  
  55.       Color pixel = getPixel(x, y);  
  56.       int brightness = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;  
  57.       if(brightness <= 85) {  
  58.        setPixel(x, y, Color.BLACK);  
  59.       }  
  60.       else if(brightness <= 170) {  
  61.        setPixel(x, y, Color.GRAY);  
  62.       }  
  63.       else {  
  64.        setPixel(x, y, Color.WHITE);  
  65.       }  
  66.      }  
  67.     }  
  68.    }  
  69.   }
');