com.facebook.imagepipeline.animated.base.AnimatedImage Java Examples

The following examples show how to use com.facebook.imagepipeline.animated.base.AnimatedImage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GifImage.java    From fresco with MIT License 6 votes vote down vote up
@Override
public int getLoopCount() {
  // If a GIF image has no Netscape 2.0 loop extension, it is meant to play once and then stop. A
  // loop count of 0 indicates an endless looping of the animation. Any loop count X>0 indicates
  // that the animation shall be repeated X times, resulting in the animation to play X+1 times.
  final int loopCount = nativeGetLoopCount();
  switch (loopCount) {
    case LOOP_COUNT_FOREVER:
      return AnimatedImage.LOOP_COUNT_INFINITE;

    case LOOP_COUNT_MISSING:
      return 1;

    default:
      return loopCount + 1;
  }
}
 
Example #2
Source File: AnimatedImageFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
private CloseableImage getCloseableImage(ImageDecodeOptions options, AnimatedImage image) {
  int frameForPreview = options.useLastFrameForPreview ? image.getFrameCount() - 1 : 0;
  CloseableReference<Bitmap> previewBitmap = null;
  if (options.decodePreviewFrame) {
    previewBitmap = createPreviewBitmap(image, frameForPreview);
  }
  try {
    AnimatedImageResult animatedImageResult = AnimatedImageResult.newBuilder(image)
        .setPreviewBitmap(previewBitmap)
        .setFrameForPreview(frameForPreview)
        .build();
    return new CloseableAnimatedImage(animatedImageResult);
  } finally {
    CloseableReference.closeSafely(previewBitmap);
  }
}
 
Example #3
Source File: AnimatedImageFactoryImpl.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Decode a WebP into a CloseableImage.
 *
 * @param encodedImage encoded image (native byte array holding the encoded bytes and meta data)
 * @param options the options for the decode
 * @param bitmapConfig the Bitmap.Config used to generate the output bitmaps
 * @return a {@link CloseableImage} for the WebP image
 */
public CloseableImage decodeWebP(
    final EncodedImage encodedImage,
    final ImageDecodeOptions options,
    final Bitmap.Config bitmapConfig) {
  if (sWebpAnimatedImageDecoder == null) {
    throw new UnsupportedOperationException(
        "To encode animated webp please add the dependency " + "to the animated-webp module");
  }
  final CloseableReference<PooledByteBuffer> bytesRef = encodedImage.getByteBufferRef();
  Preconditions.checkNotNull(bytesRef);
  try {
    final PooledByteBuffer input = bytesRef.get();
    AnimatedImage webPImage;
    if (input.getByteBuffer() != null) {
      webPImage = sWebpAnimatedImageDecoder.decodeFromByteBuffer(input.getByteBuffer(), options);
    } else {
      webPImage =
          sWebpAnimatedImageDecoder.decodeFromNativeMemory(
              input.getNativePtr(), input.size(), options);
    }
    return getCloseableImage(options, webPImage, bitmapConfig);
  } finally {
    CloseableReference.closeSafely(bytesRef);
  }
}
 
Example #4
Source File: AnimatedImageFactoryImpl.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Decodes a GIF into a CloseableImage.
 *
 * @param encodedImage encoded image (native byte array holding the encoded bytes and meta data)
 * @param options the options for the decode
 * @param bitmapConfig the Bitmap.Config used to generate the output bitmaps
 * @return a {@link CloseableImage} for the GIF image
 */
public CloseableImage decodeGif(
    final EncodedImage encodedImage,
    final ImageDecodeOptions options,
    final Bitmap.Config bitmapConfig) {
  if (sGifAnimatedImageDecoder == null) {
    throw new UnsupportedOperationException(
        "To encode animated gif please add the dependency " + "to the animated-gif module");
  }
  final CloseableReference<PooledByteBuffer> bytesRef = encodedImage.getByteBufferRef();
  Preconditions.checkNotNull(bytesRef);
  try {
    final PooledByteBuffer input = bytesRef.get();
    AnimatedImage gifImage;
    if (input.getByteBuffer() != null) {
      gifImage = sGifAnimatedImageDecoder.decodeFromByteBuffer(input.getByteBuffer(), options);
    } else {
      gifImage =
          sGifAnimatedImageDecoder.decodeFromNativeMemory(
              input.getNativePtr(), input.size(), options);
    }
    return getCloseableImage(options, gifImage, bitmapConfig);
  } finally {
    CloseableReference.closeSafely(bytesRef);
  }
}
 
Example #5
Source File: AnimatedImageFactoryImpl.java    From fresco with MIT License 5 votes vote down vote up
private CloseableImage getCloseableImage(
    ImageDecodeOptions options, AnimatedImage image, Bitmap.Config bitmapConfig) {
  List<CloseableReference<Bitmap>> decodedFrames = null;
  CloseableReference<Bitmap> previewBitmap = null;
  try {
    final int frameForPreview = options.useLastFrameForPreview ? image.getFrameCount() - 1 : 0;
    if (options.forceStaticImage) {
      return new CloseableStaticBitmap(
          createPreviewBitmap(image, bitmapConfig, frameForPreview),
          ImmutableQualityInfo.FULL_QUALITY,
          0);
    }

    if (options.decodeAllFrames) {
      decodedFrames = decodeAllFrames(image, bitmapConfig);
      previewBitmap = CloseableReference.cloneOrNull(decodedFrames.get(frameForPreview));
    }

    if (options.decodePreviewFrame && previewBitmap == null) {
      previewBitmap = createPreviewBitmap(image, bitmapConfig, frameForPreview);
    }
    AnimatedImageResult animatedImageResult =
        AnimatedImageResult.newBuilder(image)
            .setPreviewBitmap(previewBitmap)
            .setFrameForPreview(frameForPreview)
            .setDecodedFrames(decodedFrames)
            .setBitmapTransformation(options.bitmapTransformation)
            .build();
    return new CloseableAnimatedImage(animatedImageResult);
  } finally {
    CloseableReference.closeSafely(previewBitmap);
    CloseableReference.closeSafely(decodedFrames);
  }
}
 
Example #6
Source File: AnimatedDrawableBackendImpl.java    From fresco with MIT License 5 votes vote down vote up
private static Rect getBoundsToUse(AnimatedImage image, Rect targetBounds) {
  if (targetBounds == null) {
    return new Rect(0, 0, image.getWidth(), image.getHeight());
  }
  return new Rect(
      0,
      0,
      Math.min(targetBounds.width(), image.getWidth()),
      Math.min(targetBounds.height(), image.getHeight()));
}
 
Example #7
Source File: AnimatedDrawableBackendImpl.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private static Rect getBoundsToUse(AnimatedImage image, Rect targetBounds) {
  if (targetBounds == null) {
    return new Rect(0, 0, image.getWidth(), image.getHeight());
  }
  return new Rect(
      0,
      0,
      Math.min(targetBounds.width(), image.getWidth()),
      Math.min(targetBounds.height(), image.getHeight()));
}
 
Example #8
Source File: AnimatedDrawableFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an {@link AnimatedDrawable} based on an {@link AnimatedImage}.
 *
 * @param animatedImageResult the result of the code
 * @param options additional options
 * @return a newly constructed {@link AnimatedDrawable}
 */
public AnimatedDrawable create(
    AnimatedImageResult animatedImageResult,
    AnimatedDrawableOptions options) {
  AnimatedImage animatedImage = animatedImageResult.getImage();
  Rect initialBounds = new Rect(0, 0, animatedImage.getWidth(), animatedImage.getHeight());
  AnimatedDrawableBackend animatedDrawableBackend =
      mAnimatedDrawableBackendProvider.get(animatedImageResult, initialBounds);
  return createAnimatedDrawable(options, animatedDrawableBackend);
}
 
Example #9
Source File: CloseableAnimatedImage.java    From fresco with MIT License 4 votes vote down vote up
public synchronized @Nullable AnimatedImage getImage() {
  return isClosed() ? null : mImageResult.getImage();
}
 
Example #10
Source File: ExperimentalBitmapAnimationDrawableFactory.java    From fresco with MIT License 4 votes vote down vote up
private AnimatedDrawableBackend createAnimatedDrawableBackend(
    AnimatedImageResult animatedImageResult) {
  AnimatedImage animatedImage = animatedImageResult.getImage();
  Rect initialBounds = new Rect(0, 0, animatedImage.getWidth(), animatedImage.getHeight());
  return mAnimatedDrawableBackendProvider.get(animatedImageResult, initialBounds);
}
 
Example #11
Source File: CloseableAnimatedImage.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
public synchronized AnimatedImage getImage() {
  return isClosed() ? null : mImageResult.getImage();
}
 
Example #12
Source File: WebPImage.java    From fresco with MIT License 4 votes vote down vote up
@Override
public AnimatedImage decodeFromNativeMemory(
    long nativePtr, int sizeInBytes, ImageDecodeOptions options) {
  return WebPImage.createFromNativeMemory(nativePtr, sizeInBytes);
}
 
Example #13
Source File: WebPImage.java    From fresco with MIT License 4 votes vote down vote up
@Override
public AnimatedImage decodeFromByteBuffer(ByteBuffer byteBuffer, ImageDecodeOptions options) {
  return WebPImage.createFromByteBuffer(byteBuffer);
}
 
Example #14
Source File: GifImage.java    From fresco with MIT License 4 votes vote down vote up
@Override
public AnimatedImage decodeFromNativeMemory(
    long nativePtr, int sizeInBytes, ImageDecodeOptions options) {
  return GifImage.createFromNativeMemory(nativePtr, sizeInBytes, options);
}
 
Example #15
Source File: GifImage.java    From fresco with MIT License 4 votes vote down vote up
@Override
public AnimatedImage decodeFromByteBuffer(ByteBuffer byteBuffer, ImageDecodeOptions options) {
  return GifImage.createFromByteBuffer(byteBuffer, options);
}
 
Example #16
Source File: AnimatedImageDecoder.java    From fresco with MIT License 2 votes vote down vote up
/**
 * Factory method to create the AnimatedImage from a native pointer
 *
 * @param nativePtr The native pointer
 * @param sizeInBytes The size in byte to allocate
 * @param options The options for decoding
 * @return The AnimatedImage allocation
 */
AnimatedImage decodeFromNativeMemory(long nativePtr, int sizeInBytes, ImageDecodeOptions options);
 
Example #17
Source File: AnimatedImageDecoder.java    From fresco with MIT License 2 votes vote down vote up
/**
 * Factory method to create the AnimatedImage from a ByteBuffer
 *
 * @param byteBuffer The ByteBuffer containing the image
 * @param options The options for decoding
 * @return The AnimatedImage allocation
 */
AnimatedImage decodeFromByteBuffer(ByteBuffer byteBuffer, ImageDecodeOptions options);