document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * OFImage ialah Class yang mendefinisikan image dalam format Object First
  3.  *
  4.  * @author Muhammad Bagus Istighfar
  5.  * @version 10 Desember 2020
  6.  */
  7.  
  8. import java.awt.*;
  9. import java.awt.image.BufferedImage;
  10. public class OFImage extends BufferedImage
  11. {
  12.    /**
  13.      * mencopy OFimage dari BufferedImage
  14.      * @param image image yang mau di-copy
  15.      */
  16.     public OFImage(BufferedImage image){
  17.         super(image.getColorModel(), image.copyData(null),
  18.                 image.isAlphaPremultiplied(), null);
  19.     }
  20.  
  21.     /**
  22.      * membuat OFImage dengan ukuran yang spesifik dan
  23.      * konten yang tak spesifik
  24.      * @param width lebar gambar
  25.      * @param height tinggi gambar
  26.      */
  27.     public OFImage( int width, int height){
  28.         super(width,height,TYPE_INT_RGB);
  29.     }
  30.  
  31.     /**
  32.      * mengatur pixel yang diberikan dari image ke warna yang spesifik
  33.      * color merepresentasikan nilai RGB
  34.      * @param x posisi-x dari pixel
  35.      * @param y posisi-y dari pixel
  36.      * @param col warna dari pixel
  37.      */
  38.     public void setPixel(int x, int y, Color col){
  39.         int pixel =col.getRGB();
  40.         setRGB(x, y, pixel);
  41.     }
  42.  
  43.     /**
  44.      * mendapatkan nilai warna pada posisi spesifik pada pixel
  45.      * @param x posisi-x dari pixel
  46.      * @param y posisi-y dari pixel
  47.      * @return warna dari posisi [ixel yang diberikan
  48.      */
  49.     public Color getPixel(int x, int y){
  50.         int pixel = getRGB(x, y);
  51.         return new Color(pixel);
  52.     }
  53.  
  54.     /**
  55.      * membuat gambar jadi sedikit lebih gelap
  56.      */
  57.     public void darker()
  58.     {
  59.         int height = getHeight();
  60.         int width = getWidth();
  61.         for(int y=0; y < height; y++){
  62.             for (int x=0; x < width; x++){
  63.                 setPixel(x,y, getPixel(x,y).darker());
  64.             }
  65.         }
  66.     }
  67.  
  68.     /**
  69.      * membuat gambar jadi sedikit lebih terang
  70.      */
  71.     public void lighter(){
  72.         int height = getHeight();
  73.         int width = getWidth();
  74.         for(int y=0; y < height; y++){
  75.             for (int x=0; x < width; x++){
  76.                 setPixel(x,y, getPixel(x,y).brighter());
  77.             }
  78.         }
  79.     }
  80.  
  81.     /**
  82.      * melakukan tiga level opereasi thershold
  83.      */
  84.     public void threshold() {
  85.         int height = getHeight();
  86.         int width = getWidth();
  87.         for (int y = 0; y < height; y++) {
  88.             for (int x = 0; x < width; x++) {
  89.                 Color pixel = getPixel(x, y);
  90.                 int brightness = (pixel.getRed() + pixel.getBlue() + pixel.getGreen())/3;
  91.  
  92.                 if (brightness <=85){
  93.                     setPixel(x,y, Color.BLACK);
  94.                 } else if(brightness<=170){
  95.                     setPixel(x,y, Color.GRAY);
  96.                 } else {
  97.                     setPixel(x,y, Color.WHITE);
  98.                 }
  99.             }
  100.         }
  101.     }
  102. }
  103.  
');