254 lines
6.8 KiB
Java
254 lines
6.8 KiB
Java
package pl.droidsonroids.gif;
|
|
|
|
import android.content.ContentResolver;
|
|
import android.content.res.AssetFileDescriptor;
|
|
import android.graphics.Bitmap;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
import android.system.ErrnoException;
|
|
import android.system.Os;
|
|
import java.io.FileDescriptor;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.nio.ByteBuffer;
|
|
|
|
/* loaded from: classes2.dex */
|
|
final class GifInfoHandle {
|
|
private volatile long a;
|
|
|
|
static {
|
|
LibraryLoader.b();
|
|
}
|
|
|
|
GifInfoHandle(FileDescriptor fileDescriptor) throws GifIOException {
|
|
this.a = a(fileDescriptor, 0L, true);
|
|
}
|
|
|
|
private static long a(FileDescriptor fileDescriptor, long j, boolean z) throws GifIOException {
|
|
int a;
|
|
if (Build.VERSION.SDK_INT > 27) {
|
|
try {
|
|
a = a(fileDescriptor, z);
|
|
} catch (Exception e) {
|
|
throw new GifIOException(GifError.OPEN_FAILED.errorCode, e.getMessage());
|
|
}
|
|
} else {
|
|
a = extractNativeFileDescriptor(fileDescriptor, z);
|
|
}
|
|
return openNativeFileDescriptor(a, j);
|
|
}
|
|
|
|
static native int createTempNativeFileDescriptor() throws GifIOException;
|
|
|
|
static native int extractNativeFileDescriptor(FileDescriptor fileDescriptor, boolean z) throws GifIOException;
|
|
|
|
private static native void free(long j);
|
|
|
|
private static native long getAllocationByteCount(long j);
|
|
|
|
private static native int getCurrentFrameIndex(long j);
|
|
|
|
private static native int getCurrentLoop(long j);
|
|
|
|
private static native int getCurrentPosition(long j);
|
|
|
|
private static native int getDuration(long j);
|
|
|
|
private static native int getHeight(long j);
|
|
|
|
private static native int getLoopCount(long j);
|
|
|
|
private static native long getMetadataByteCount(long j);
|
|
|
|
private static native int getNativeErrorCode(long j);
|
|
|
|
private static native int getNumberOfFrames(long j);
|
|
|
|
private static native long[] getSavedState(long j);
|
|
|
|
private static native int getWidth(long j);
|
|
|
|
private static native boolean isOpaque(long j);
|
|
|
|
static native long openByteArray(byte[] bArr) throws GifIOException;
|
|
|
|
static native long openDirectByteBuffer(ByteBuffer byteBuffer) throws GifIOException;
|
|
|
|
static native long openFile(String str) throws GifIOException;
|
|
|
|
static native long openNativeFileDescriptor(int i, long j) throws GifIOException;
|
|
|
|
static native long openStream(InputStream inputStream) throws GifIOException;
|
|
|
|
private static native long renderFrame(long j, Bitmap bitmap);
|
|
|
|
private static native boolean reset(long j);
|
|
|
|
private static native long restoreRemainder(long j);
|
|
|
|
private static native int restoreSavedState(long j, long[] jArr, Bitmap bitmap);
|
|
|
|
private static native void saveRemainder(long j);
|
|
|
|
private static native void seekToTime(long j, int i, Bitmap bitmap);
|
|
|
|
private static native void setLoopCount(long j, char c);
|
|
|
|
synchronized int b() {
|
|
return getCurrentFrameIndex(this.a);
|
|
}
|
|
|
|
synchronized int c() {
|
|
return getCurrentLoop(this.a);
|
|
}
|
|
|
|
synchronized int d() {
|
|
return getCurrentPosition(this.a);
|
|
}
|
|
|
|
synchronized int e() {
|
|
return getDuration(this.a);
|
|
}
|
|
|
|
synchronized int f() {
|
|
return getHeight(this.a);
|
|
}
|
|
|
|
protected void finalize() throws Throwable {
|
|
try {
|
|
o();
|
|
} finally {
|
|
super.finalize();
|
|
}
|
|
}
|
|
|
|
synchronized int g() {
|
|
return getLoopCount(this.a);
|
|
}
|
|
|
|
synchronized long h() {
|
|
return getMetadataByteCount(this.a);
|
|
}
|
|
|
|
synchronized int i() {
|
|
return getNativeErrorCode(this.a);
|
|
}
|
|
|
|
synchronized int j() {
|
|
return getNumberOfFrames(this.a);
|
|
}
|
|
|
|
synchronized long[] k() {
|
|
return getSavedState(this.a);
|
|
}
|
|
|
|
synchronized int l() {
|
|
return getWidth(this.a);
|
|
}
|
|
|
|
synchronized boolean m() {
|
|
return isOpaque(this.a);
|
|
}
|
|
|
|
synchronized boolean n() {
|
|
return this.a == 0;
|
|
}
|
|
|
|
synchronized void o() {
|
|
free(this.a);
|
|
this.a = 0L;
|
|
}
|
|
|
|
synchronized boolean p() {
|
|
return reset(this.a);
|
|
}
|
|
|
|
synchronized long q() {
|
|
return restoreRemainder(this.a);
|
|
}
|
|
|
|
synchronized void r() {
|
|
saveRemainder(this.a);
|
|
}
|
|
|
|
GifInfoHandle(byte[] bArr) throws GifIOException {
|
|
this.a = openByteArray(bArr);
|
|
}
|
|
|
|
GifInfoHandle(ByteBuffer byteBuffer) throws GifIOException {
|
|
this.a = openDirectByteBuffer(byteBuffer);
|
|
}
|
|
|
|
private static int a(FileDescriptor fileDescriptor, boolean z) throws GifIOException, ErrnoException {
|
|
try {
|
|
int createTempNativeFileDescriptor = createTempNativeFileDescriptor();
|
|
Os.dup2(fileDescriptor, createTempNativeFileDescriptor);
|
|
return createTempNativeFileDescriptor;
|
|
} finally {
|
|
if (z) {
|
|
Os.close(fileDescriptor);
|
|
}
|
|
}
|
|
}
|
|
|
|
GifInfoHandle(String str) throws GifIOException {
|
|
this.a = openFile(str);
|
|
}
|
|
|
|
GifInfoHandle(InputStream inputStream) throws GifIOException {
|
|
if (inputStream.markSupported()) {
|
|
this.a = openStream(inputStream);
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("InputStream does not support marking");
|
|
}
|
|
|
|
static GifInfoHandle a(ContentResolver contentResolver, Uri uri) throws IOException {
|
|
if ("file".equals(uri.getScheme())) {
|
|
return new GifInfoHandle(uri.getPath());
|
|
}
|
|
AssetFileDescriptor openAssetFileDescriptor = contentResolver.openAssetFileDescriptor(uri, "r");
|
|
if (openAssetFileDescriptor != null) {
|
|
return new GifInfoHandle(openAssetFileDescriptor);
|
|
}
|
|
throw new IOException("Could not open AssetFileDescriptor for " + uri);
|
|
}
|
|
|
|
GifInfoHandle(AssetFileDescriptor assetFileDescriptor) throws IOException {
|
|
try {
|
|
this.a = a(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), false);
|
|
} finally {
|
|
try {
|
|
assetFileDescriptor.close();
|
|
} catch (IOException unused) {
|
|
}
|
|
}
|
|
}
|
|
|
|
synchronized long a(Bitmap bitmap) {
|
|
return renderFrame(this.a, bitmap);
|
|
}
|
|
|
|
void a(int i) {
|
|
if (i >= 0 && i <= 65535) {
|
|
synchronized (this) {
|
|
setLoopCount(this.a, (char) i);
|
|
}
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("Loop count of range <0, 65535>");
|
|
}
|
|
|
|
synchronized void a(int i, Bitmap bitmap) {
|
|
seekToTime(this.a, i, bitmap);
|
|
}
|
|
|
|
synchronized long a() {
|
|
return getAllocationByteCount(this.a);
|
|
}
|
|
|
|
synchronized int a(long[] jArr, Bitmap bitmap) {
|
|
return restoreSavedState(this.a, jArr, bitmap);
|
|
}
|
|
}
|