Example #1
0
 /** Reads Graphics Control Extension values */
 protected void readGraphicControlExt() {
   read(); // block size
   final int packed = read(); // packed fields
   currentFrame.dispose = (packed & 0x1c) >> 2; // disposal method
   if (currentFrame.dispose == 0) {
     currentFrame.dispose = 1; // elect to keep old image if discretionary
   }
   currentFrame.transparency = (packed & 1) != 0;
   currentFrame.delay = readShort() * 10; // delay in milliseconds
   currentFrame.transIndex = read(); // transparent color index
   read(); // block terminator
 }
Example #2
0
  /**
   * Reads GIF image from stream
   *
   * @param is containing GIF file.
   * @return read status code (0 = no errors)
   */
  public int read(final InputStream is, final int contentLength) {
    if (is != null) {
      try {
        final int capacity = (contentLength > 0) ? (contentLength + 4096) : 4096;
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(capacity);
        int nRead;
        final byte[] data = new byte[16384];
        while ((nRead = is.read(data, 0, data.length)) != -1) {
          buffer.write(data, 0, nRead);
        }
        buffer.flush();

        read(buffer.toByteArray());
      } catch (final IOException e) {
        Log.w(TAG, "Error reading data from stream", e);
      }
    } else {
      status = STATUS_OPEN_ERROR;
    }

    try {
      is.close();
    } catch (final Exception e) {
      Log.w(TAG, "Error closing stream", e);
    }

    return status;
  }
Example #3
0
 private void skipBitmapData() {
   read(); // code size
   skip();
 }