public boolean dispose() {
    if (decoder.imageComplete(ImageConsumer.SINGLEFRAMEDONE, false) == 0) {
      return false;
    } else {
      if (delay > 0) {
        try {
          if (verbose) {
            System.out.println("sleeping: " + delay);
          }
          Thread.sleep(delay);
        } catch (InterruptedException e) {
          return false;
        }
      } else {
        Thread.yield();
      }

      if (verbose && disposal_method != 0) {
        System.out.println("disposal method: " + disposal_method);
      }

      int global_width = decoder.global_width;
      int global_height = decoder.global_height;

      if (x < 0) {
        width += x;
        x = 0;
      }
      if (x + width > global_width) {
        width = global_width - x;
      }
      if (width <= 0) {
        disposal_method = DISPOSAL_NONE;
      } else {
        if (y < 0) {
          height += y;
          y = 0;
        }
        if (y + height > global_height) {
          height = global_height - y;
        }
        if (height <= 0) {
          disposal_method = DISPOSAL_NONE;
        }
      }

      switch (disposal_method) {
        case DISPOSAL_PREVIOUS:
          byte[] saved_image = decoder.saved_image;
          IndexColorModel saved_model = decoder.saved_model;
          if (saved_image != null) {
            setPixels(
                x, y, width, height, saved_model, saved_image, y * global_width + x, global_width);
          }
          break;
        case DISPOSAL_BGCOLOR:
          byte tpix;
          if (model.getTransparentPixel() < 0) {
            model = trans_model;
            if (model == null) {
              model = new IndexColorModel(8, 1, new byte[4], 0, true);
              trans_model = model;
            }
            tpix = 0;
          } else {
            tpix = (byte) model.getTransparentPixel();
          }

          int rassize = width * height;
          byte[] rasfill = new byte[rassize];
          if (tpix != 0) {
            for (int i = 0; i < rassize; i++) {
              rasfill[i] = tpix;
            }
          }
          //		setPixels(x, y, width, height, model, rasfill, 0, 0);
          setPixels(x, y, width, height, model, rasfill, 0, width);
          break;
        case DISPOSAL_SAVE:
          decoder.saved_model = model;
          break;
      }
    }
    return true;
  }
 private void setPixels(int x, int y, int w, int h, ColorModel cm, byte[] pix, int off, int scan) {
   decoder.setPixels(x, y, w, h, cm, pix, off, scan);
 }