import java.lang.*;
import java.awt.*;
import java.io.*;
import java.awt.image.*;

public class Lochblech extends Frame{
  private static Lochblech application;

  // Application starten
  public static void main(String[] args){
    application = new Lochblech(args[0]);
    // ...und beenden
    System.exit(0);
  }

  // Konstruktor (macht alles)
  public Lochblech(String imageName){
    // Farbkanäle
    int red,green,blue;
    // Bild
    Image image = Toolkit.getDefaultToolkit().getImage(imageName);
    // Laden des Bildes überwachen
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    // Warten, bis Bild vollständig geladen
    try{
      mt.waitForID(0);
    }catch(Exception e){
      // Wenn was schiefgeht
      System.exit(0);
    }

    // Breite und Höhe ermitteln
    int w = image.getWidth(this);
    int h = image.getHeight(this);
    // Speicherplatz Breite x Höhe reservieren
    int[] pixels = new int[w * h];
    // Die Pixel auslesen
    try{
      PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
      pg.grabPixels();
    }catch(Exception e){

    }

    // Breite und Höhe ausgeben
    System.out.println(w);
    System.out.println(h);
    // Den Rotanteil der Pixel ausgeben
    for(int i = 0; i < w * h; i++){
      red = (pixels[i] & 0x00ff0000) >> 16;
      //green = (pixels[i] & 0x0000ff00) >> 8;
      //blue = (pixels[i] & 0x000000ff);

      System.out.println(red);
    }
  }
}



