use of com.facebook.common.internal.DoNotStrip in project fresco by facebook.
the class WebpBitmapFactoryImpl method getScaleFromOptions.
@DoNotStrip
private static float getScaleFromOptions(BitmapFactory.Options options) {
float scale = 1.0f;
if (options != null) {
int sampleSize = options.inSampleSize;
if (sampleSize > 1) {
scale = 1.0f / (float) sampleSize;
}
if (options.inScaled) {
int density = options.inDensity;
int targetDensity = options.inTargetDensity;
int screenDensity = options.inScreenDensity;
if (density != 0 && targetDensity != 0 && density != screenDensity) {
scale = targetDensity / (float) density;
}
}
}
return scale;
}
use of com.facebook.common.internal.DoNotStrip in project fresco by facebook.
the class WebpBitmapFactoryImpl method hookDecodeResource.
@DoNotStrip
public static Bitmap hookDecodeResource(Resources res, int id, BitmapFactory.Options opts) {
Bitmap bm = null;
TypedValue value = new TypedValue();
try (InputStream is = res.openRawResource(id, value)) {
bm = hookDecodeResourceStream(res, value, is, null, opts);
} catch (Exception e) {
// Keep resulting bitmap as null
}
if (IN_BITMAP_SUPPORTED && bm == null && opts != null && opts.inBitmap != null) {
throw new IllegalArgumentException("Problem decoding into existing bitmap");
}
return bm;
}
use of com.facebook.common.internal.DoNotStrip in project fresco by facebook.
the class WebpBitmapFactoryImpl method hookDecodeStream.
@DoNotStrip
public static Bitmap hookDecodeStream(InputStream inputStream, Rect outPadding, BitmapFactory.Options opts) {
StaticWebpNativeLoader.ensure();
inputStream = wrapToMarkSupportedStream(inputStream);
Bitmap bitmap;
byte[] header = getWebpHeader(inputStream, opts);
if (WebpSupportStatus.sIsWebpSupportRequired && isWebpHeader(header, 0, HEADER_SIZE)) {
bitmap = nativeDecodeStream(inputStream, opts, getScaleFromOptions(opts), getInTempStorageFromOptions(opts));
// We notify that the direct decoder failed
if (bitmap == null) {
sendWebpErrorLog("webp_direct_decode_stream");
}
setWebpBitmapOptions(bitmap, opts);
setPaddingDefaultValues(outPadding);
} else {
bitmap = originalDecodeStream(inputStream, outPadding, opts);
if (bitmap == null) {
sendWebpErrorLog("webp_direct_decode_stream_failed_on_no_webp");
}
}
return bitmap;
}
use of com.facebook.common.internal.DoNotStrip in project fresco by facebook.
the class WebpBitmapFactoryImpl method hookDecodeFileDescriptor.
@DoNotStrip
public static Bitmap hookDecodeFileDescriptor(FileDescriptor fd, Rect outPadding, BitmapFactory.Options opts) {
StaticWebpNativeLoader.ensure();
Bitmap bitmap;
long originalSeekPosition = nativeSeek(fd, 0, false);
if (originalSeekPosition != -1) {
InputStream inputStream = wrapToMarkSupportedStream(new FileInputStream(fd));
try {
byte[] header = getWebpHeader(inputStream, opts);
if (WebpSupportStatus.sIsWebpSupportRequired && isWebpHeader(header, 0, HEADER_SIZE)) {
bitmap = nativeDecodeStream(inputStream, opts, getScaleFromOptions(opts), getInTempStorageFromOptions(opts));
// We send error if the direct decode failed
if (bitmap == null) {
sendWebpErrorLog("webp_direct_decode_fd");
}
setPaddingDefaultValues(outPadding);
setWebpBitmapOptions(bitmap, opts);
} else {
nativeSeek(fd, originalSeekPosition, true);
bitmap = originalDecodeFileDescriptor(fd, outPadding, opts);
if (bitmap == null) {
sendWebpErrorLog("webp_direct_decode_fd_failed_on_no_webp");
}
}
} finally {
try {
inputStream.close();
} catch (Throwable t) {
/* ignore */
}
}
} else {
bitmap = hookDecodeStream(new FileInputStream(fd), outPadding, opts);
setPaddingDefaultValues(outPadding);
}
return bitmap;
}
use of com.facebook.common.internal.DoNotStrip in project fresco by facebook.
the class WebpBitmapFactoryImpl method hookDecodeByteArray.
@DoNotStrip
public static Bitmap hookDecodeByteArray(byte[] array, int offset, int length, BitmapFactory.Options opts) {
StaticWebpNativeLoader.ensure();
Bitmap bitmap;
if (WebpSupportStatus.sIsWebpSupportRequired && isWebpHeader(array, offset, length)) {
bitmap = nativeDecodeByteArray(array, offset, length, opts, getScaleFromOptions(opts), getInTempStorageFromOptions(opts));
// We notify that the direct decoding failed
if (bitmap == null) {
sendWebpErrorLog("webp_direct_decode_array");
}
setWebpBitmapOptions(bitmap, opts);
} else {
bitmap = originalDecodeByteArray(array, offset, length, opts);
if (bitmap == null) {
sendWebpErrorLog("webp_direct_decode_array_failed_on_no_webp");
}
}
return bitmap;
}
Aggregations