@Test public void testWidthAndHeightWithRotatedImage() { // Reverse width and height as the rotation angle should put them back again mBitmap = Bitmap.createBitmap(HEIGHT, WIDTH, Bitmap.Config.ARGB_8888); ResourceReleaser<Bitmap> releaser = SimpleBitmapReleaser.getInstance(); mCloseableStaticBitmap = new CloseableStaticBitmap( mBitmap, releaser, ImmutableQualityInfo.FULL_QUALITY, 90, ExifInterface.ORIENTATION_ROTATE_90); assertThat(mCloseableStaticBitmap.getWidth()).isEqualTo(WIDTH); assertThat(mCloseableStaticBitmap.getHeight()).isEqualTo(HEIGHT); }
@Test public void testWidthAndHeightWithInvertedOrientationImage() { // Reverse width and height as the inverted orienvation should put them back again mBitmap = Bitmap.createBitmap(HEIGHT, WIDTH, Bitmap.Config.ARGB_8888); ResourceReleaser<Bitmap> releaser = SimpleBitmapReleaser.getInstance(); mCloseableStaticBitmap = new CloseableStaticBitmap( mBitmap, releaser, ImmutableQualityInfo.FULL_QUALITY, 0, ExifInterface.ORIENTATION_TRANSPOSE); assertThat(mCloseableStaticBitmap.getWidth()).isEqualTo(WIDTH); assertThat(mCloseableStaticBitmap.getHeight()).isEqualTo(HEIGHT); }
public BitmapCounter(int maxCount, int maxSize) { Preconditions.checkArgument(maxCount > 0); Preconditions.checkArgument(maxSize > 0); mMaxCount = maxCount; mMaxSize = maxSize; mUnpooledBitmapsReleaser = new ResourceReleaser<Bitmap>() { @Override public void release(Bitmap value) { try { decrease(value); } finally { value.recycle(); } } }; }
public SharedByteArray( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams params) { Preconditions.checkNotNull(memoryTrimmableRegistry); Preconditions.checkArgument(params.minBucketSize > 0); Preconditions.checkArgument(params.maxBucketSize >= params.minBucketSize); mMaxByteArraySize = params.maxBucketSize; mMinByteArraySize = params.minBucketSize; mByteArraySoftRef = new OOMSoftReference<byte[]>(); mSemaphore = new Semaphore(1); mResourceReleaser = new ResourceReleaser<byte[]>() { @Override public void release(byte[] unused) { mSemaphore.release(); } }; memoryTrimmableRegistry.registerMemoryTrimmable(this); }
public PooledByteArrayBufferedInputStream( InputStream inputStream, byte[] byteArray, ResourceReleaser<byte[]> resourceReleaser) { mInputStream = Preconditions.checkNotNull(inputStream); mByteArray = Preconditions.checkNotNull(byteArray); mResourceReleaser = Preconditions.checkNotNull(resourceReleaser); mBufferedSize = 0; mBufferOffset = 0; mClosed = false; }
/** Creates a new reference for the client. */ private synchronized CloseableReference<V> newClientReference(final Entry<K, V> entry) { increaseClientCount(entry); return CloseableReference.of( entry.valueRef.get(), new ResourceReleaser<V>() { @Override public void release(V unused) { releaseClientReference(entry); } }); }
/** * Creates a new instance of a CloseableStaticBitmap. * * @param bitmap the bitmap to wrap * @param resourceReleaser ResourceReleaser to release the bitmap to */ public CloseableStaticBitmap( Bitmap bitmap, ResourceReleaser<Bitmap> resourceReleaser, QualityInfo qualityInfo, int rotationAngle) { this(bitmap, resourceReleaser, qualityInfo, rotationAngle, ExifInterface.ORIENTATION_UNDEFINED); }
/** * Creates a new instance of a CloseableStaticBitmap. * * @param bitmap the bitmap to wrap * @param resourceReleaser ResourceReleaser to release the bitmap to */ public CloseableStaticBitmap( Bitmap bitmap, ResourceReleaser<Bitmap> resourceReleaser, QualityInfo qualityInfo, int rotationAngle, int exifOrientation) { mBitmap = Preconditions.checkNotNull(bitmap); mBitmapReference = CloseableReference.of( mBitmap, Preconditions.checkNotNull(resourceReleaser)); mQualityInfo = qualityInfo; mRotationAngle = rotationAngle; mExifOrientation = exifOrientation; }
@Before public void setUp() { mBitmap = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888); ResourceReleaser<Bitmap> releaser = SimpleBitmapReleaser.getInstance(); mCloseableStaticBitmap = new CloseableStaticBitmap( mBitmap, releaser, ImmutableQualityInfo.FULL_QUALITY, 0, ExifInterface.ORIENTATION_NORMAL); }
public FlexByteArrayPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams params) { Preconditions.checkArgument(params.maxNumThreads > 0); mDelegatePool = new SoftRefByteArrayPool( memoryTrimmableRegistry, params, NoOpPoolStatsTracker.getInstance()); mResourceReleaser = new ResourceReleaser<byte[]>() { @Override public void release(byte[] unused) { FlexByteArrayPool.this.release(unused); } }; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); mResourceReleaser = mock(ResourceReleaser.class); mResultRef1 = CloseableReference.of(new Object(), mResourceReleaser); mResultRef2 = CloseableReference.of(new Object(), mResourceReleaser); mResultRef3 = CloseableReference.of(new Object(), mResourceReleaser); mException = mock(Exception.class); mDataSubscriber1 = mock(DataSubscriber.class); mDataSubscriber2 = mock(DataSubscriber.class); mSettableProducerContext = mock(SettableProducerContext.class); when(mSettableProducerContext.getId()).thenReturn(mRequestId); when(mSettableProducerContext.isPrefetch()).thenReturn(false); mProducer = mock(Producer.class); mDataSource = CloseableProducerToDataSourceAdapter.create( mProducer, mSettableProducerContext, mRequestListener); ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); verify(mRequestListener).onRequestStart( mSettableProducerContext.getImageRequest(), mSettableProducerContext.getCallerContext(), mRequestId, mSettableProducerContext.isPrefetch()); verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class)); mInternalConsumer = captor.getValue(); mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance()); }
@Before public void setUp() { mBitmap = MockBitmapFactory.create(); mBitmapCounter = new BitmapCounter(MAX_BITMAP_COUNT, MAX_BITMAP_SIZE); mockStatic(BitmapCounterProvider.class); when(BitmapCounterProvider.get()).thenReturn(mBitmapCounter); mockStatic(BitmapFactory.class); when(BitmapFactory.decodeFileDescriptor( any(FileDescriptor.class), any(Rect.class), any(BitmapFactory.Options.class))) .thenReturn(mBitmap); mInputBuf = new byte[LENGTH]; PooledByteBuffer input = new TrivialPooledByteBuffer(mInputBuf, POINTER); mByteBufferRef = CloseableReference.of(input); mEncodedImage = new EncodedImage(mByteBufferRef); mDecodeBuf = new byte[LENGTH + 2]; mDecodeBufRef = CloseableReference.of(mDecodeBuf, mock(ResourceReleaser.class)); mockStatic(Bitmaps.class); mGingerbreadPurgeableDecoder = new GingerbreadPurgeableDecoder(); }
@Before public void setUp() { mFlexByteArrayPool = mock(FlexByteArrayPool.class); mBitmap = MockBitmapFactory.create(); mBitmapCounter = new BitmapCounter(MAX_BITMAP_COUNT, MAX_BITMAP_SIZE); mockStatic(BitmapCounterProvider.class); when(BitmapCounterProvider.get()).thenReturn(mBitmapCounter); mockStatic(BitmapFactory.class); when(BitmapFactory.decodeByteArray( any(byte[].class), anyInt(), anyInt(), any(BitmapFactory.Options.class))) .thenReturn(mBitmap); mInputBuf = new byte[LENGTH]; PooledByteBuffer input = new TrivialPooledByteBuffer(mInputBuf, POINTER); mByteBufferRef = CloseableReference.of(input); mEncodedImage = new EncodedImage(mByteBufferRef); mDecodeBuf = new byte[LENGTH + 2]; mDecodeBufRef = CloseableReference.of(mDecodeBuf, mock(ResourceReleaser.class)); when(mFlexByteArrayPool.get(Integer.valueOf(LENGTH))).thenReturn(mDecodeBufRef); mockStatic(Bitmaps.class); mKitKatPurgeableDecoder = new KitKatPurgeableDecoder(mFlexByteArrayPool); }
@Before public void setUp() { mResourceReleaser = mock(ResourceReleaser.class); final byte[] bytes = new byte[256]; for (int i = 0; i < 256; ++i) { bytes[i] = (byte) i; } InputStream unbufferedStream = new ByteArrayInputStream(bytes); mBuffer = new byte[10]; mPooledByteArrayBufferedInputStream = new PooledByteArrayBufferedInputStream( unbufferedStream, mBuffer, mResourceReleaser); }
public ResourceReleaser<Bitmap> getReleaser() { return mUnpooledBitmapsReleaser; }