/**
   * Create an ImageRepresentation for the given Image. The width and height are unknown at this
   * point. The color model is a hint as to the color model to use when creating the buffered image.
   * If null, the src color model will be used.
   */
  public ImageRepresentation(ToolkitImage im, ColorModel cmodel, boolean forceCMhint) {
    image = im;

    if (image.getSource() instanceof InputStreamImageSource) {
      src = (InputStreamImageSource) image.getSource();
    }

    setColorModel(cmodel);

    this.forceCMhint = forceCMhint;
  }
  public void imageComplete(int status) {
    if (src != null) {
      src.checkSecurity(null, false);
    }
    boolean done;
    int info;
    switch (status) {
      default:
      case ImageConsumer.IMAGEABORTED:
        done = true;
        info = ImageObserver.ABORT;
        break;
      case ImageConsumer.IMAGEERROR:
        image.addInfo(ImageObserver.ERROR);
        done = true;
        info = ImageObserver.ERROR;
        dispose();
        break;
      case ImageConsumer.STATICIMAGEDONE:
        done = true;
        info = ImageObserver.ALLBITS;
        break;
      case ImageConsumer.SINGLEFRAMEDONE:
        done = false;
        info = ImageObserver.FRAMEBITS;
        break;
    }
    synchronized (this) {
      if (done) {
        image.getSource().removeConsumer(this);
        consuming = false;
        newbits = null;

        if (bimage != null) {
          bimage = getOpaqueRGBImage();
        }
      }
      availinfo |= info;
      notifyAll();
    }

    newInfo(image, info, 0, 0, width, height);

    image.infoDone(status);
  }
  synchronized void abort() {
    image.getSource().removeConsumer(this);
    consuming = false;
    newbits = null;
    bimage = null;
    biRaster = null;
    cmodel = null;
    srcLUT = null;
    isDefaultBI = false;
    isSameCM = false;

    newInfo(image, ImageObserver.ABORT, -1, -1, -1, -1);
    availinfo &=
        ~(ImageObserver.SOMEBITS
            | ImageObserver.FRAMEBITS
            | ImageObserver.ALLBITS
            | ImageObserver.ERROR);
  }
 synchronized void dispose() {
   image.getSource().removeConsumer(this);
   consuming = false;
   newbits = null;
   availinfo &= ~(ImageObserver.SOMEBITS | ImageObserver.FRAMEBITS | ImageObserver.ALLBITS);
 }
 /*synchronized*/ void startProduction() {
   if (!consuming) {
     consuming = true;
     image.getSource().startProduction(this);
   }
 }