package com.bumptech.glide.load.data;

import java.io.FilterInputStream;
import java.io.InputStream;

/* loaded from: classes4.dex */
public final class g extends FilterInputStream {

    /* renamed from: r, reason: collision with root package name */
    private static final byte[] f12587r;

    /* renamed from: s, reason: collision with root package name */
    private static final int f12588s;

    /* renamed from: t, reason: collision with root package name */
    private static final int f12589t;

    /* renamed from: p, reason: collision with root package name */
    private final byte f12590p;

    /* renamed from: q, reason: collision with root package name */
    private int f12591q;

    static {
        byte[] bArr = {-1, -31, 0, 28, 69, 120, 105, 102, 0, 0, 77, 77, 0, 0, 0, 0, 0, 8, 0, 1, 1, 18, 0, 2, 0, 0, 0, 1, 0};
        f12587r = bArr;
        int length = bArr.length;
        f12588s = length;
        f12589t = length + 2;
    }

    public g(InputStream inputStream, int i10) {
        super(inputStream);
        if (i10 >= -1 && i10 <= 8) {
            this.f12590p = (byte) i10;
            return;
        }
        throw new IllegalArgumentException("Cannot add invalid orientation: " + i10);
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public void mark(int i10) {
        throw new UnsupportedOperationException();
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public boolean markSupported() {
        return false;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public int read() {
        int read;
        int i10;
        int i11 = this.f12591q;
        if (i11 < 2 || i11 > (i10 = f12589t)) {
            read = super.read();
        } else if (i11 == i10) {
            read = this.f12590p;
        } else {
            read = f12587r[i11 - 2] & 255;
        }
        if (read != -1) {
            this.f12591q++;
        }
        return read;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public void reset() {
        throw new UnsupportedOperationException();
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public long skip(long j10) {
        long skip = super.skip(j10);
        if (skip > 0) {
            this.f12591q = (int) (this.f12591q + skip);
        }
        return skip;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public int read(byte[] bArr, int i10, int i11) {
        int i12;
        int i13 = this.f12591q;
        int i14 = f12589t;
        if (i13 > i14) {
            i12 = super.read(bArr, i10, i11);
        } else if (i13 == i14) {
            bArr[i10] = this.f12590p;
            i12 = 1;
        } else if (i13 < 2) {
            i12 = super.read(bArr, i10, 2 - i13);
        } else {
            int min = Math.min(i14 - i13, i11);
            System.arraycopy(f12587r, this.f12591q - 2, bArr, i10, min);
            i12 = min;
        }
        if (i12 > 0) {
            this.f12591q += i12;
        }
        return i12;
    }
}
