import java.io.*;
import java.awt.*;
import java.awt.image.*;

// affiche une image PGM en gris
public class DisplayPixmap {
  
  public static void main(String[] args) {
    BytePixmap p;
    try {
      p = new BytePixmap(args[0]);     // lecture du fichier
    } catch (IOException e) { System.out.println(e); return; }

    GrafPort frame = new GrafPort(args[0], p.width, p.height, p.width, p.height);
    // fabrication des pixels gris au format usuel AWT : ColorModel.RGBdefault
    int[] pixels = new int[p.size];
    for (int i = 0; i < pixels.length; i++)
      pixels[i] = 0xFF000000 + Pixmap.intValue(p.data[i]) * 0x010101; // réplique l'octet 3 fois
    // construit une image avec ces pixels
    MemoryImageSource source = new MemoryImageSource(p.width, p.height, pixels, 0, p.width);
    Image img = frame.createImage(source);
    
    frame.drawImage(img, 0, 0);
  }

}

