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. /**
  6.  * Class untuk mendefinisikan gambar sebagai OF (Object Firsts).
  7.  *
  8.  * @author Ghifari A.U
  9.  *
  10.  */
  11.  
  12. public class OFImage extends BufferedImage
  13. {
  14.     public OFImage(BufferedImage image)
  15.     {
  16.         super(image.getColorModel(), image.copyData(null),
  17.         image.isAlphaPremultiplied(), null);
  18.     }
  19.    
  20.     public OFImage(int width, int height)
  21.     {
  22.         super(width, height, TYPE_INT_RGB);
  23.     }
  24.    
  25.     public void setPixel(int x, int y, Color col)
  26.     {
  27.         int pixel = col.getRGB();
  28.         setRGB(x, y, pixel);
  29.     }
  30.    
  31.     public Color getPixel(int x, int y)
  32.     {
  33.         int pixel = getRGB(x, y);
  34.        
  35.         return new Color(pixel);
  36.     }
  37.    
  38.     public void darker()
  39.     {
  40.         int height = getHeight();
  41.         int width = getWidth();
  42.        
  43.         for (int y = 0; y < height; y++)
  44.         {
  45.             for (int x = 0; x < width; x++)
  46.             {
  47.                 setPixel(x, y, getPixel(x, y).darker());
  48.             }
  49.         }
  50.     }
  51.    
  52.     public void lighter()
  53.     {
  54.         int height = getHeight();
  55.         int width = getWidth();
  56.        
  57.         for (int y = 0; y < height; y++)
  58.         {
  59.             for (int x = 0; x < width; x++)
  60.             {
  61.                 setPixel(x, y, getPixel(x, y).brighter());
  62.             }
  63.         }
  64.     }
  65.    
  66.     public void threshold()
  67.     {
  68.         int height = getHeight();
  69.         int width = getWidth();
  70.        
  71.         for (int y = 0; y < height; y++)
  72.         {
  73.             for (int x = 0; x < width; x++)
  74.             {
  75.                 Color pixel = getPixel(x, y);
  76.                 int brightness = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;
  77.                
  78.                 if (brightness <= 85)
  79.                 {
  80.                     setPixel(x, y, Color.BLACK);
  81.                 }
  82.                
  83.                 else if (brightness <= 170)
  84.                 {
  85.                     setPixel(x, y, Color.GRAY);
  86.                 }
  87.                
  88.                 else
  89.                 {
  90.                     setPixel(x, y, Color.WHITE);
  91.                 }
  92.             }
  93.         }
  94.     }
  95. }
');