示例#1
0
 public void Write(OutputStream output) throws IOException {
   BitUtils.WriteWord(output, localScreenWidth_);
   BitUtils.WriteWord(output, localScreenHeight_);
   output.write(byte_);
   output.write(backgroundColorIndex_);
   output.write(pixelAspectRatio_);
 }
示例#2
0
 public void Write(OutputStream output) throws IOException {
   output.write(separator_);
   BitUtils.WriteWord(output, leftPosition_);
   BitUtils.WriteWord(output, topPosition_);
   BitUtils.WriteWord(output, width_);
   BitUtils.WriteWord(output, height_);
   output.write(byte_);
 }
示例#3
0
  void ToIndexedColor(byte r[][], byte g[][], byte b[][]) throws AWTException {
    pixels_ = new byte[width_ * height_];
    colors_ = new byte[256 * 3];
    int colornum = 0;
    for (int x = 0; x < width_; ++x) {
      for (int y = 0; y < height_; ++y) {
        int search;
        for (search = 0; search < colornum; ++search)
          if (colors_[search * 3] == r[x][y]
              && colors_[search * 3 + 1] == g[x][y]
              && colors_[search * 3 + 2] == b[x][y]) break;

        if (search > 255) throw new AWTException("Too many colors.");

        pixels_[y * width_ + x] = (byte) search;

        if (search == colornum) {
          colors_[search * 3] = r[x][y];
          colors_[search * 3 + 1] = g[x][y];
          colors_[search * 3 + 2] = b[x][y];
          ++colornum;
        }
      }
    }
    numColors_ = 1 << BitUtils.BitsNeeded(colornum);
    byte copy[] = new byte[numColors_ * 3];
    System.arraycopy(colors_, 0, copy, 0, numColors_ * 3);
    colors_ = copy;
  }
示例#4
0
 public ScreenDescriptor(short width, short height, int numColors) {
   localScreenWidth_ = width;
   localScreenHeight_ = height;
   SetGlobalColorTableSize((byte) (BitUtils.BitsNeeded(numColors) - 1));
   SetGlobalColorTableFlag((byte) 1);
   SetSortFlag((byte) 0);
   SetColorResolution((byte) 7);
   backgroundColorIndex_ = 0;
   pixelAspectRatio_ = 0;
 }
示例#5
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();
  }