sclass Image332 implements MakesBufferedImage {
  int w;
  byte[] pixels;
  
  *() {} // for persistence
  
  *(BufferedImage img) { this(RGBImage(img)); }
  *(RGBImage img) {
    w = img.getWidth();
    int h = img.getHeight();
    pixels = new byte[w*h];
    for y to h: for x to w:
      pixels[y*w+x] = to332(img.getInt(x, y));
  }
  
  public int getWidth() { ret w; }
  public int getHeight() { ret h(); }

  int h() {
    ret l(pixels)/w;
  }
  
  RGBImage toRGB() {
    int h = h();
    RGBImage img = new RGBImage(w, h);
    int i = 0;
    for y to h: for x to w:
      img.setPixel(x, y, from332(pixels[i++]));
    ret img;
  }
  
  public BufferedImage getBufferedImage() {
    ret toRGB().getBufferedImage();
  }
  
  // 0 to 255
  int get332Pixel(int x, int y) {
    ret ubyteToInt(pixels[y*w+x]);
  }
}