/**
   * Flushes any pending data and closes output file. If writing to an OutputStream, the stream is
   * not closed.
   */
  public boolean finish() {
    if (!started) return false;
    boolean ok = true;
    started = false;
    try {
      out.write(0x3b); // gif trailer
      out.flush();
      if (closeStream) {
        out.close();
      }
    } catch (IOException e) {
      ok = false;
    }

    // reset for subsequent use
    transIndex = 0;
    out = null;
    image = null;
    pixels = null;
    indexedPixels = null;
    colorTab = null;
    closeStream = false;
    firstFrame = true;

    return ok;
  }
Beispiel #2
0
  /** DOCUMENT ME! */
  public void Compress() throws IOException {
    WriteHeaders(out);

    WriteCompressedData(out);

    WriteEOI(out);
    out.flush();
  }
Beispiel #3
0
  /**
   * Writes the image out to a stream in the GIF file format. This will be a single GIF87a image,
   * non-interlaced, with no background color. <B>This may take some time.</B>
   *
   * <p>
   *
   * @param output The stream to output to. This should probably be a buffered stream.
   * @exception IOException Will be thrown if a write operation fails.
   */
  public void Write(OutputStream output) throws IOException {
    BitUtils.WriteString(output, "GIF87a");

    ScreenDescriptor sd = new ScreenDescriptor(width_, height_, numColors_);
    sd.Write(output);

    output.write(colors_, 0, colors_.length);

    ImageDescriptor id = new ImageDescriptor(width_, height_, ',');
    id.Write(output);

    byte codesize = BitUtils.BitsNeeded(numColors_);
    if (codesize == 1) ++codesize;
    output.write(codesize);

    LZWCompressor.LZWCompress(output, codesize, pixels_);
    output.write(0);

    id = new ImageDescriptor((byte) 0, (byte) 0, ';');
    id.Write(output);
    output.flush();
  }