public abstract class

DalvikPurgeableDecoder

extends Object
implements PlatformDecoder
java.lang.Object
   ↳ com.facebook.imagepipeline.nativecode.DalvikPurgeableDecoder
Known Direct Subclasses

Class Overview

Base class for bitmap decodes for Dalvik VM (Gingerbread to KitKat).

Native code used by this class is shipped as part of libimagepipeline.so

Summary

Fields
protected static final byte[] EOI
Protected Constructors
DalvikPurgeableDecoder()
Public Methods
CloseableReference<Bitmap> decodeFromEncodedImage(EncodedImage encodedImage, Bitmap.Config bitmapConfig, Rect regionToDecode)
Creates a bitmap from encoded bytes.
CloseableReference<Bitmap> decodeFromEncodedImageWithColorSpace(EncodedImage encodedImage, Bitmap.Config bitmapConfig, Rect regionToDecode, boolean transformToSRGB)
Creates a bitmap from encoded bytes.
CloseableReference<Bitmap> decodeJPEGFromEncodedImage(EncodedImage encodedImage, Bitmap.Config bitmapConfig, Rect regionToDecode, int length)
Creates a bitmap from encoded JPEG bytes.
CloseableReference<Bitmap> decodeJPEGFromEncodedImageWithColorSpace(EncodedImage encodedImage, Bitmap.Config bitmapConfig, Rect regionToDecode, int length, boolean transformToSRGB)
Creates a bitmap from encoded JPEG bytes.
static boolean endsWithEOI(CloseableReference<PooledByteBuffer> bytesRef, int length)
static BitmapFactory.Options getBitmapFactoryOptions(int sampleSize, Bitmap.Config bitmapConfig)
CloseableReference<Bitmap> pinBitmap(Bitmap bitmap)
Pin the bitmap so that it cannot be 'purged'.
Protected Methods
abstract Bitmap decodeByteArrayAsPurgeable(CloseableReference<PooledByteBuffer> bytesRef, BitmapFactory.Options options)
Decodes a byteArray into a purgeable bitmap
abstract Bitmap decodeJPEGByteArrayAsPurgeable(CloseableReference<PooledByteBuffer> bytesRef, int length, BitmapFactory.Options options)
Decodes a byteArray containing jpeg encoded bytes into a purgeable bitmap

Adds a JFIF End-Of-Image marker if needed before decoding.

[Expand]
Inherited Methods
From class java.lang.Object
From interface com.facebook.imagepipeline.platform.PlatformDecoder

Fields

protected static final byte[] EOI

Protected Constructors

protected DalvikPurgeableDecoder ()

Public Methods

public CloseableReference<Bitmap> decodeFromEncodedImage (EncodedImage encodedImage, Bitmap.Config bitmapConfig, Rect regionToDecode)

Creates a bitmap from encoded bytes. Supports JPEG but callers should use decodeJPEGFromEncodedImage(EncodedImage, Bitmap.Config, Rect, int) for partial JPEGs. In addition, a region to decode can be supplied in order to minimize memory usage. NOTE: Not all platform decoders necessarily support supplying specific regions.

Note: This needs to be kept because of dependencies issues.

Parameters
encodedImage the reference to the encoded image with the reference to the encoded bytes
bitmapConfig the android.graphics.Bitmap.Config used to create the decoded Bitmap
regionToDecode optional image region to decode or null to decode the whole image
Returns
  • the bitmap

public CloseableReference<Bitmap> decodeFromEncodedImageWithColorSpace (EncodedImage encodedImage, Bitmap.Config bitmapConfig, Rect regionToDecode, boolean transformToSRGB)

Creates a bitmap from encoded bytes.

Parameters
encodedImage the encoded image with reference to the encoded bytes
bitmapConfig the android.graphics.Bitmap.Config used to create the decoded Bitmap
regionToDecode optional image region to decode. currently not supported.
transformToSRGB whether to allow color space transformation to sRGB at load time
Returns
  • the bitmap
Throws
TooManyBitmapsException if the pool is full
OutOfMemoryError if the Bitmap cannot be allocated

public CloseableReference<Bitmap> decodeJPEGFromEncodedImage (EncodedImage encodedImage, Bitmap.Config bitmapConfig, Rect regionToDecode, int length)

Creates a bitmap from encoded JPEG bytes. Supports a partial JPEG image. In addition, a region to decode can be supplied in order to minimize memory usage. NOTE: Not all platform decoders necessarily support supplying specific regions.

Note: This needs to be kept because of dependencies issues.

Parameters
encodedImage the reference to the encoded image with the reference to the encoded bytes
bitmapConfig the android.graphics.Bitmap.Config used to create the decoded Bitmap
regionToDecode optional image region to decode or null to decode the whole image.
length the number of encoded bytes in the buffer
Returns
  • the bitmap

public CloseableReference<Bitmap> decodeJPEGFromEncodedImageWithColorSpace (EncodedImage encodedImage, Bitmap.Config bitmapConfig, Rect regionToDecode, int length, boolean transformToSRGB)

Creates a bitmap from encoded JPEG bytes. Supports a partial JPEG image.

Parameters
encodedImage the encoded image with reference to the encoded bytes
bitmapConfig the android.graphics.Bitmap.Config used to create the decoded Bitmap
regionToDecode optional image region to decode. currently not supported.
length the number of encoded bytes in the buffer
transformToSRGB whether to allow color space transformation to sRGB at load time
Returns
  • the bitmap
Throws
TooManyBitmapsException if the pool is full
OutOfMemoryError if the Bitmap cannot be allocated

public static boolean endsWithEOI (CloseableReference<PooledByteBuffer> bytesRef, int length)

public static BitmapFactory.Options getBitmapFactoryOptions (int sampleSize, Bitmap.Config bitmapConfig)

public CloseableReference<Bitmap> pinBitmap (Bitmap bitmap)

Pin the bitmap so that it cannot be 'purged'. Only makes sense for purgeable bitmaps WARNING: Use with caution. Make sure that the pinned bitmap is recycled eventually. Otherwise, this will simply eat up ashmem memory and eventually lead to unfortunate crashes. We *may* eventually provide an unpin method - but we don't yet have a compelling use case for that.

Parameters
bitmap the purgeable bitmap to pin

Protected Methods

protected abstract Bitmap decodeByteArrayAsPurgeable (CloseableReference<PooledByteBuffer> bytesRef, BitmapFactory.Options options)

Decodes a byteArray into a purgeable bitmap

Parameters
bytesRef the byte buffer that contains the encoded bytes
options the options passed to the BitmapFactory

protected abstract Bitmap decodeJPEGByteArrayAsPurgeable (CloseableReference<PooledByteBuffer> bytesRef, int length, BitmapFactory.Options options)

Decodes a byteArray containing jpeg encoded bytes into a purgeable bitmap

Adds a JFIF End-Of-Image marker if needed before decoding.

Parameters
bytesRef the byte buffer that contains the encoded bytes
length the number of encoded bytes in the buffer
options the options passed to the BitmapFactory