288 lines
10 KiB
Java
288 lines
10 KiB
Java
package com.bumptech.glide.load.resource.bitmap;
|
|
|
|
import com.bumptech.glide.load.ImageHeaderParser;
|
|
import com.google.common.primitives.UnsignedBytes;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteOrder;
|
|
import java.nio.charset.Charset;
|
|
import o.Opg;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class DefaultImageHeaderParser implements ImageHeaderParser {
|
|
private static byte[] d = "Exif\u0000\u0000".getBytes(Charset.forName("UTF-8"));
|
|
private static final int[] a = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
|
|
|
|
@Override // com.bumptech.glide.load.ImageHeaderParser
|
|
public final ImageHeaderParser.ImageType b(InputStream inputStream) throws IOException {
|
|
if (inputStream != null) {
|
|
return d(new Sts(inputStream));
|
|
}
|
|
throw new NullPointerException("Argument must not be null");
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.ImageHeaderParser
|
|
public final ImageHeaderParser.ImageType a(ByteBuffer byteBuffer) throws IOException {
|
|
if (byteBuffer != null) {
|
|
return d(new RVV(byteBuffer));
|
|
}
|
|
throw new NullPointerException("Argument must not be null");
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.ImageHeaderParser
|
|
public final int a(InputStream inputStream, Opg opg) throws IOException {
|
|
if (inputStream != null) {
|
|
Sts sts = new Sts(inputStream);
|
|
if (opg != null) {
|
|
return b(sts, opg);
|
|
}
|
|
throw new NullPointerException("Argument must not be null");
|
|
}
|
|
throw new NullPointerException("Argument must not be null");
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.ImageHeaderParser
|
|
public final int d(ByteBuffer byteBuffer, Opg opg) throws IOException {
|
|
if (byteBuffer != null) {
|
|
RVV rvv = new RVV(byteBuffer);
|
|
if (opg != null) {
|
|
return b(rvv, opg);
|
|
}
|
|
throw new NullPointerException("Argument must not be null");
|
|
}
|
|
throw new NullPointerException("Argument must not be null");
|
|
}
|
|
|
|
private static ImageHeaderParser.ImageType d(Reader reader) throws IOException {
|
|
try {
|
|
int b = reader.b();
|
|
if (b == 65496) {
|
|
return ImageHeaderParser.ImageType.JPEG;
|
|
}
|
|
int c = (b << 8) | reader.c();
|
|
if (c == 4671814) {
|
|
return ImageHeaderParser.ImageType.GIF;
|
|
}
|
|
int c2 = (c << 8) | reader.c();
|
|
if (c2 == -1991225785) {
|
|
reader.b(21L);
|
|
try {
|
|
return reader.c() >= 3 ? ImageHeaderParser.ImageType.PNG_A : ImageHeaderParser.ImageType.PNG;
|
|
} catch (Reader.EndOfFileException unused) {
|
|
return ImageHeaderParser.ImageType.PNG;
|
|
}
|
|
}
|
|
if (c2 == 1380533830) {
|
|
reader.b(4L);
|
|
if (((reader.b() << 16) | reader.b()) != 1464156752) {
|
|
return ImageHeaderParser.ImageType.UNKNOWN;
|
|
}
|
|
int b2 = (reader.b() << 16) | reader.b();
|
|
if ((b2 & (-256)) != 1448097792) {
|
|
return ImageHeaderParser.ImageType.UNKNOWN;
|
|
}
|
|
int i = b2 & 255;
|
|
if (i != 88) {
|
|
if (i == 76) {
|
|
reader.b(4L);
|
|
return (reader.c() & 8) != 0 ? ImageHeaderParser.ImageType.WEBP_A : ImageHeaderParser.ImageType.WEBP;
|
|
}
|
|
return ImageHeaderParser.ImageType.WEBP;
|
|
}
|
|
reader.b(4L);
|
|
short c3 = reader.c();
|
|
if ((c3 & 2) != 0) {
|
|
return ImageHeaderParser.ImageType.ANIMATED_WEBP;
|
|
}
|
|
if ((c3 & 16) != 0) {
|
|
return ImageHeaderParser.ImageType.WEBP_A;
|
|
}
|
|
return ImageHeaderParser.ImageType.WEBP;
|
|
}
|
|
if (((reader.b() << 16) | reader.b()) == 1718909296) {
|
|
int b3 = (reader.b() << 16) | reader.b();
|
|
if (b3 != 1635150182 && b3 != 1635150195) {
|
|
reader.b(4L);
|
|
int i2 = c2 - 16;
|
|
if (i2 % 4 == 0) {
|
|
int i3 = 0;
|
|
while (i3 < 5 && i2 > 0) {
|
|
int b4 = (reader.b() << 16) | reader.b();
|
|
if (b4 != 1635150182 && b4 != 1635150195) {
|
|
i3++;
|
|
i2 -= 4;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return ImageHeaderParser.ImageType.AVIF;
|
|
}
|
|
return ImageHeaderParser.ImageType.UNKNOWN;
|
|
} catch (Reader.EndOfFileException unused2) {
|
|
return ImageHeaderParser.ImageType.UNKNOWN;
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:90:0x0139, code lost:
|
|
|
|
if ((r6.b.remaining() - r7) < 2) goto L94;
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:91:0x013b, code lost:
|
|
|
|
r13 = r6.b.getShort(r7);
|
|
*/
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
private static int b(com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.Reader r13, o.Opg r14) throws java.io.IOException {
|
|
/*
|
|
Method dump skipped, instructions count: 337
|
|
To view this dump add '--comments-level debug' option
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.b(com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser$Reader, o.Opg):int");
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes.dex */
|
|
public static final class HBt {
|
|
final ByteBuffer b;
|
|
|
|
HBt(byte[] bArr, int i) {
|
|
this.b = (ByteBuffer) ByteBuffer.wrap(bArr).order(ByteOrder.BIG_ENDIAN).limit(i);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes.dex */
|
|
public interface Reader {
|
|
int a(byte[] bArr, int i) throws IOException;
|
|
|
|
int b() throws IOException;
|
|
|
|
long b(long j) throws IOException;
|
|
|
|
short c() throws IOException;
|
|
|
|
/* loaded from: classes.dex */
|
|
public static final class EndOfFileException extends IOException {
|
|
EndOfFileException() {
|
|
super("Unexpectedly reached end of a file");
|
|
}
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
static final class RVV implements Reader {
|
|
private final ByteBuffer c;
|
|
|
|
RVV(ByteBuffer byteBuffer) {
|
|
this.c = byteBuffer;
|
|
byteBuffer.order(ByteOrder.BIG_ENDIAN);
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.Reader
|
|
public final short c() throws Reader.EndOfFileException {
|
|
if (this.c.remaining() <= 0) {
|
|
throw new Reader.EndOfFileException();
|
|
}
|
|
return (short) (this.c.get() & UnsignedBytes.MAX_VALUE);
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.Reader
|
|
public final int b() throws Reader.EndOfFileException {
|
|
if (this.c.remaining() <= 0) {
|
|
throw new Reader.EndOfFileException();
|
|
}
|
|
int i = ((short) (this.c.get() & UnsignedBytes.MAX_VALUE)) << 8;
|
|
if (this.c.remaining() <= 0) {
|
|
throw new Reader.EndOfFileException();
|
|
}
|
|
return i | ((short) (this.c.get() & UnsignedBytes.MAX_VALUE));
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.Reader
|
|
public final int a(byte[] bArr, int i) {
|
|
int min = Math.min(i, this.c.remaining());
|
|
if (min == 0) {
|
|
return -1;
|
|
}
|
|
this.c.get(bArr, 0, min);
|
|
return min;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.Reader
|
|
public final long b(long j) {
|
|
int min = (int) Math.min(this.c.remaining(), j);
|
|
ByteBuffer byteBuffer = this.c;
|
|
byteBuffer.position(byteBuffer.position() + min);
|
|
return min;
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
static final class Sts implements Reader {
|
|
private final InputStream b;
|
|
|
|
Sts(InputStream inputStream) {
|
|
this.b = inputStream;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.Reader
|
|
public final short c() throws IOException {
|
|
int read = this.b.read();
|
|
if (read != -1) {
|
|
return (short) read;
|
|
}
|
|
throw new Reader.EndOfFileException();
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.Reader
|
|
public final int b() throws IOException {
|
|
int read = this.b.read();
|
|
if (read == -1) {
|
|
throw new Reader.EndOfFileException();
|
|
}
|
|
int i = ((short) read) << 8;
|
|
int read2 = this.b.read();
|
|
if (read2 != -1) {
|
|
return i | ((short) read2);
|
|
}
|
|
throw new Reader.EndOfFileException();
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.Reader
|
|
public final int a(byte[] bArr, int i) throws IOException {
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
while (i3 < i && (i2 = this.b.read(bArr, i3, i - i3)) != -1) {
|
|
i3 += i2;
|
|
}
|
|
if (i3 == 0 && i2 == -1) {
|
|
throw new Reader.EndOfFileException();
|
|
}
|
|
return i3;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.Reader
|
|
public final long b(long j) throws IOException {
|
|
if (j < 0) {
|
|
return 0L;
|
|
}
|
|
long j2 = j;
|
|
while (j2 > 0) {
|
|
long skip = this.b.skip(j2);
|
|
if (skip <= 0) {
|
|
if (this.b.read() == -1) {
|
|
break;
|
|
}
|
|
skip = 1;
|
|
}
|
|
j2 -= skip;
|
|
}
|
|
return j - j2;
|
|
}
|
|
}
|
|
}
|