public static ResourceDecoder<ParcelFileDescriptor, Bitmap> parcel(BitmapPool bitmapPool) { return new VideoDecoder<>(bitmapPool, new ParcelFileDescriptorInitializer()); }
public static ResourceDecoder<AssetFileDescriptor, Bitmap> asset(BitmapPool bitmapPool) { return new VideoDecoder<>(bitmapPool, new AssetFileDescriptorInitializer()); }
@SuppressWarnings("WeakerAccess") public VideoBitmapDecoder(BitmapPool bitmapPool) { super(bitmapPool, new ParcelFileDescriptorInitializer()); } }
/** * @deprecated Use {@link #obtain(Resources, Resource)} instead, it can be unsafe to extract * {@link Bitmap}s from their wrapped {@link Resource}. */ @Deprecated public static LazyBitmapDrawableResource obtain(Resources resources, BitmapPool bitmapPool, Bitmap bitmap) { return (LazyBitmapDrawableResource) obtain(resources, BitmapResource.obtain(bitmap, bitmapPool)); }
@Test public void testTransform_withNarrowRectangle() { Bitmap redNarrowRectangle = createSolidRedBitmap(20, 50); Bitmap result = circleCrop.transform(bitmapPool, redNarrowRectangle, 40, 80); Bitmap expected = createBitmapWithRedCircle(40, 80); assertSamePixels(expected, result); }
@Test(expected = IllegalArgumentException.class) public void testThrowsIfGivenInvalidWidth() { BitmapTransformation transformation = new BitmapTransformation() { @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { } @Override protected Bitmap transform(@NonNull BitmapPool bitmapPool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { return null; } }; transformation.transform(context, mockResource(1, 1), -1, 100); }
/** * Returns a Bitmap decoded from the given {@link InputStream} that is rotated to match any EXIF * data present in the stream and that is downsampled according to the given dimensions and any * provided {@link com.bumptech.glide.load.resource.bitmap.DownsampleStrategy} option. * * @see #decode(InputStream, int, int, Options, DecodeCallbacks) */ public Resource<Bitmap> decode(InputStream is, int outWidth, int outHeight, Options options) throws IOException { return decode(is, outWidth, outHeight, options, EMPTY_CALLBACKS); }
static Api onAllApisAndAllFormatsExpect(int width, int height) { return allApis().with(allFormats().expect(width, height)); }
/** * BitmapFactory calculates the density scale factor as a float. This introduces some non-trivial * error. This method attempts to account for that error by adjusting the inTargetDensity so that * the final scale factor is as close to our target as possible. */ private static int adjustTargetDensityForError(double adjustedScaleFactor) { int densityMultiplier = getDensityMultiplier(adjustedScaleFactor); int targetDensity = round(densityMultiplier * adjustedScaleFactor); float scaleFactorWithError = targetDensity / (float) densityMultiplier; double difference = adjustedScaleFactor / scaleFactorWithError; return round(difference * targetDensity); }
@Override public void onObtainBounds() { // Once we've read the image header, we no longer need to allow the buffer to expand in // size. To avoid unnecessary allocations reading image data, we fix the mark limit so that it // is no larger than our current buffer size here. See issue #225. bufferedStream.fixMarkLimit(); }
@Override public short getUInt8() { return (short) (getByte() & 0xFF); }
static HardwareConfigState getInstance() { if (instance == null) { synchronized (HardwareConfigState.class) { if (instance == null) { instance = new HardwareConfigState(); } } } return instance; }
@Override public void cleanup() { bufferedStream.release(); }
Api with(Formats... formats) { return new Api(minVersion, maxVersion, formats); } }
Formats expect(int width, int height) { return new Formats(formats, width, height); } }
static Builder formats(CompressFormat... formats) { return new Builder(formats); }
@Test public void testTransform_withSquare() { Bitmap redSquare = createSolidRedBitmap(50, 50); Bitmap result = circleCrop.transform(bitmapPool, redSquare, 50, 50); Bitmap expected = createBitmapWithRedCircle(50, 50); assertSamePixels(expected, result); }
@Test public void testTransform_withWideRectangle() { Bitmap redWideRectangle = createSolidRedBitmap(100, 50); Bitmap result = circleCrop.transform(bitmapPool, redWideRectangle, 80, 50); Bitmap expected = createBitmapWithRedCircle(80, 50); assertSamePixels(expected, result); }