小黄书™.apk(点击下载) / ImageSource.java


package ly.img.android.pesdk.backend.decoder;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Base64;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import ly.img.android.PESDK;
import ly.img.android.pesdk.backend.decoder.vector.CanvasDecoder;
import ly.img.android.pesdk.backend.decoder.vector.CanvasDecoderDrawable;
import ly.img.android.pesdk.backend.model.ImageSize;
import ly.img.android.pesdk.backend.model.chunk.MultiRect;
import ly.img.android.pesdk.backend.model.constant.DrawableState;
import ly.img.android.pesdk.backend.model.constant.FileSignature;
import ly.img.android.pesdk.utils.BitmapFactoryUtils;
import ly.img.android.pesdk.utils.UriHelper;

public class ImageSource implements Parcelable {
    static final /* synthetic */ boolean $assertionsDisabled = false;
    public static final Parcelable.Creator<ImageSource> CREATOR = new Parcelable.Creator<ImageSource>() {
        /* class ly.img.android.pesdk.backend.decoder.ImageSource.AnonymousClass1 */

        @Override // android.os.Parcelable.Creator
        public ImageSource createFromParcel(Parcel parcel) {
            return new ImageSource(parcel);
        }

        @Override // android.os.Parcelable.Creator
        public ImageSource[] newArray(int i) {
            return new ImageSource[i];
        }
    };
    public static Context defaultThemeContext = PESDK.getAppContext();
    private Class<? extends CanvasDecoderDrawable> canvasClass;
    private WeakReference<Context> context;
    private Decoder decoder;
    private Drawable drawable;
    private ImageFileFormat imageFormat;
    private ImageSize imageSize;
    private Boolean isStaticBitmap;
    private Boolean isVector;
    private String providerName;
    private int resourceId;
    private int rotation;
    private final SOURCE_TYPE sourceType;
    private final DrawableState[] stateList;
    private final StateSource[] stateSourceList;
    private Uri uri;
    private Integer variant;
    private int variantCount;

    /* access modifiers changed from: private */
    public enum SOURCE_TYPE {
        STATE_SET,
        RESOURCE,
        CANVAS,
        URI,
        NONE
    }

    private void runInfoPreCache() {
    }

    public int describeContents() {
        return 0;
    }

    public static void setTheme(int i) {
        defaultThemeContext = new ContextThemeWrapper(PESDK.getAppContext(), i);
    }

    public void fixExifRotation() {
        getDecoder().fixExifRotation();
    }

    public boolean hasProvider(String str) {
        return str.equals(this.providerName);
    }

    public String searchProviderField(Class<?> cls) {
        try {
            return (String) cls.getDeclaredField("PROVIDER_NAME").get(null);
        } catch (IllegalAccessException | NoSuchFieldException unused) {
            Class<? super Object> superclass = cls.getSuperclass();
            if (superclass != null) {
                return searchProviderField(superclass);
            }
            return null;
        }
    }

    protected ImageSource(Class<? extends CanvasDecoderDrawable> cls, Integer num) {
        this.imageSize = null;
        this.rotation = -1;
        this.resourceId = 0;
        this.uri = null;
        this.canvasClass = null;
        this.isVector = null;
        this.isStaticBitmap = null;
        this.variant = null;
        this.variantCount = 1;
        this.context = new WeakReference<>(defaultThemeContext);
        this.variant = num;
        try {
            this.variantCount = cls.getDeclaredField("VARIANT_COUNT").getInt(null);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException unused) {
        }
        this.providerName = searchProviderField(cls);
        this.sourceType = SOURCE_TYPE.CANVAS;
        this.stateSourceList = null;
        this.stateList = null;
        this.canvasClass = cls;
        runInfoPreCache();
    }

    protected ImageSource(int i) {
        this.imageSize = null;
        this.rotation = -1;
        this.resourceId = 0;
        this.uri = null;
        this.canvasClass = null;
        this.isVector = null;
        this.isStaticBitmap = null;
        this.variant = null;
        this.variantCount = 1;
        this.context = new WeakReference<>(defaultThemeContext);
        this.sourceType = i == 0 ? SOURCE_TYPE.NONE : SOURCE_TYPE.RESOURCE;
        this.stateSourceList = null;
        this.stateList = null;
        this.resourceId = i;
        runInfoPreCache();
    }

    protected ImageSource(Uri uri2) {
        this.imageSize = null;
        this.rotation = -1;
        this.resourceId = 0;
        this.uri = null;
        this.canvasClass = null;
        this.isVector = null;
        this.isStaticBitmap = null;
        this.variant = null;
        this.variantCount = 1;
        this.context = new WeakReference<>(defaultThemeContext);
        this.sourceType = SOURCE_TYPE.URI;
        this.stateSourceList = null;
        this.stateList = null;
        this.uri = uri2;
        runInfoPreCache();
    }

    protected ImageSource(StateSource... stateSourceArr) {
        this.imageSize = null;
        this.rotation = -1;
        this.resourceId = 0;
        this.uri = null;
        this.canvasClass = null;
        this.isVector = null;
        this.isStaticBitmap = null;
        this.variant = null;
        this.variantCount = 1;
        this.context = new WeakReference<>(defaultThemeContext);
        this.sourceType = SOURCE_TYPE.STATE_SET;
        this.stateSourceList = stateSourceArr;
        this.stateList = new DrawableState[stateSourceArr.length];
        for (int i = 0; i < stateSourceArr.length; i++) {
            this.stateList[i] = stateSourceArr[i].drawableState;
        }
    }

    public void setContext(Context context2) {
        this.context = new WeakReference<>(context2);
    }

    public Context getContext() {
        Context context2 = this.context.get();
        return context2 == null ? defaultThemeContext : context2;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        ImageSource imageSource = (ImageSource) obj;
        if (this.resourceId != imageSource.resourceId) {
            return false;
        }
        Uri uri2 = this.uri;
        Uri uri3 = imageSource.uri;
        if (uri2 != null) {
            return uri2.equals(uri3);
        }
        if (uri3 == null) {
            return true;
        }
        return false;
    }

    public int hashCode() {
        int i = this.resourceId * 31;
        Uri uri2 = this.uri;
        return i + (uri2 != null ? uri2.hashCode() : 0);
    }

    public static ImageSource createFromBase64String(String str) {
        return new ImageSource(UriHelper.createFromBase64String(str));
    }

    public static ImageSource create(File file) {
        return new ImageSource(Uri.fromFile(file));
    }

    public static ImageSource create(int i) {
        return new ImageSource(i);
    }

    public static ImageSource create(StateSource... stateSourceArr) {
        return new ImageSource(stateSourceArr);
    }

    public static ImageSource create(Class<? extends CanvasDecoderDrawable> cls) {
        return new ImageSource(cls, null);
    }

    public static ImageSource create(Class<? extends CanvasDecoderDrawable> cls, int i) {
        return new ImageSource(cls, Integer.valueOf(i));
    }

    public static ImageSource create(Uri uri2) {
        return new ImageSource(uri2);
    }

    public void invalidate() {
        Decoder decoder2 = this.decoder;
        if (decoder2 instanceof CanvasDecoder) {
            ((CanvasDecoder) decoder2).invalidate();
            this.imageSize = null;
        }
    }

    public int getResourceId() {
        if (hasResourceId()) {
            return this.resourceId;
        }
        throw new NonStaticResourceException();
    }

    public boolean hasResourceId() {
        return this.sourceType == SOURCE_TYPE.RESOURCE;
    }

    public ImageSize getSize() {
        if (this.imageSize == null) {
            this.imageSize = getDecoder().getSize();
        }
        return this.imageSize;
    }

    public int getRotation() {
        if (this.rotation == -1) {
            this.rotation = getDecoder().getRotation();
        }
        return this.rotation;
    }

    public int getVariantIndex() {
        return this.variant.intValue();
    }

    public int getVariantCount() {
        return this.variantCount;
    }

    public ImageSource getVariant(int i) {
        int i2 = AnonymousClass3.$SwitchMap$ly$img$android$pesdk$backend$decoder$ImageSource$SOURCE_TYPE[this.sourceType.ordinal()];
        if (i2 == 1) {
            return create(this.stateSourceList);
        }
        if (i2 == 2) {
            return create(this.resourceId);
        }
        if (i2 == 3) {
            return create(this.canvasClass, i);
        }
        if (i2 == 4) {
            return create(this.uri);
        }
        if (i2 == 5) {
            return create(0);
        }
        throw new RuntimeException("unhandled source");
    }

    /* access modifiers changed from: protected */
    public Decoder getDecoder() {
        Decoder decoder2 = this.decoder;
        if (decoder2 == null) {
            int i = AnonymousClass3.$SwitchMap$ly$img$android$pesdk$backend$decoder$ImageSource$SOURCE_TYPE[this.sourceType.ordinal()];
            if (i == 1) {
                decoder2 = getImageFormat().getDecoder(getContext().getResources(), this.stateSourceList[0].uri);
            } else if (i == 2) {
                decoder2 = getImageFormat().getDecoder(getContext().getResources(), this.resourceId);
            } else if (i == 3) {
                decoder2 = getImageFormat().getDecoder(getContext(), this.canvasClass, this.variant);
            } else if (i == 4) {
                decoder2 = getImageFormat().getDecoder(getContext().getResources(), this.uri);
            } else if (i == 5) {
                decoder2 = new NullDecoder(getContext().getResources(), 0);
            }
            this.decoder = decoder2;
        }
        return decoder2;
    }

    /* access modifiers changed from: protected */
    public Decoder getStateDecoder(StateSource stateSource) {
        if (this.sourceType == SOURCE_TYPE.STATE_SET) {
            return getImageFormat().getDecoder(getResources(), stateSource.uri);
        }
        return getDecoder();
    }

    public String getAsBase64() {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        try {
            int i = AnonymousClass3.$SwitchMap$ly$img$android$pesdk$backend$decoder$ImageFileFormat[getImageFormat().ordinal()];
            if (i == 1 || i == 2 || i == 3) {
                InputStream inputStream = Decoder.getInputStream(getDecoder().getUri());
                byte[] bArr = new byte[16384];
                while (true) {
                    int read = inputStream.read(bArr, 0, 16384);
                    if (read == -1) {
                        break;
                    }
                    byteArrayOutputStream.write(bArr, 0, read);
                }
            } else {
                Bitmap bitmap = getBitmap();
                if (bitmap != null) {
                    bitmap.compress(Bitmap.CompressFormat.PNG, 0, byteArrayOutputStream);
                }
            }
            String encodeToString = Base64.encodeToString(byteArrayOutputStream.toByteArray(), 2);
            byteArrayOutputStream.close();
            return encodeToString;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

    /* access modifiers changed from: protected */
    public Decoder getStateDecoder(DrawableState drawableState) {
        if (this.sourceType != SOURCE_TYPE.STATE_SET) {
            return getDecoder();
        }
        if (DrawableState.findBestMatch(drawableState, this.stateList) != null) {
            StateSource[] stateSourceArr = this.stateSourceList;
            if (stateSourceArr.length > 0) {
                return getImageFormat().getDecoder(getResources(), stateSourceArr[0].uri);
            }
        }
        return getImageFormat().getDecoder(getResources(), this.stateSourceList[0].uri);
    }

    public DrawableState[] getStateList() {
        DrawableState[] drawableStateArr = this.stateList;
        return drawableStateArr != null ? drawableStateArr : getDecoder().getStateList();
    }

    public ImageFileFormat getImageFormat() {
        if (this.imageFormat == null) {
            try {
                int i = AnonymousClass3.$SwitchMap$ly$img$android$pesdk$backend$decoder$ImageSource$SOURCE_TYPE[this.sourceType.ordinal()];
                if (i == 2) {
                    this.imageFormat = readFormat(this.resourceId);
                } else if (i == 3) {
                    this.imageFormat = ImageFileFormat.CANVAS;
                } else if (i == 4) {
                    this.imageFormat = readFormat(Decoder.getInputStream(this.uri));
                } else if (i == 5) {
                    this.imageFormat = ImageFileFormat.UNSUPPORTED;
                }
            } catch (IOException e) {
                e.printStackTrace();
                this.imageFormat = ImageFileFormat.UNSUPPORTED;
            }
        }
        return this.imageFormat;
    }

    public boolean isSupportedImage() {
        return !getSize().isZero();
    }

    public static ImageFileFormat readFormat(InputStream inputStream) throws IOException {
        if (!(inputStream instanceof BufferedInputStream)) {
            inputStream = new BufferedInputStream(inputStream);
        }
        inputStream.mark(Integer.MAX_VALUE);
        byte[] bArr = new byte[12];
        inputStream.reset();
        inputStream.read(bArr, 0, 12);
        inputStream.reset();
        inputStream.close();
        FileSignature readSignature = FileSignature.readSignature(bArr);
        if (readSignature == null) {
            return ImageFileFormat.JPEG;
        }
        switch (AnonymousClass3.$SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature[readSignature.ordinal()]) {
            case 1:
                return ImageFileFormat.PNG;
            case 2:
            case 3:
            case 4:
            case 5:
                return ImageFileFormat.JPEG;
            case 6:
                return ImageFileFormat.HEIC;
            case 7:
                return ImageFileFormat.WEBP;
            case 8:
                return ImageFileFormat.XML_DRAWABLE;
            case 9:
                return ImageFileFormat.BMP;
            case 10:
            case 11:
                return ImageFileFormat.GIF;
            default:
                return ImageFileFormat.UNSUPPORTED;
        }
    }

    /* access modifiers changed from: package-private */
    /* renamed from: ly.img.android.pesdk.backend.decoder.ImageSource$3  reason: invalid class name */
    public static /* synthetic */ class AnonymousClass3 {
        static final /* synthetic */ int[] $SwitchMap$ly$img$android$pesdk$backend$decoder$ImageFileFormat;
        static final /* synthetic */ int[] $SwitchMap$ly$img$android$pesdk$backend$decoder$ImageSource$SOURCE_TYPE;
        static final /* synthetic */ int[] $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature;

        /* JADX WARNING: Can't wrap try/catch for region: R(40:0|(2:1|2)|3|(2:5|6)|7|9|10|11|(2:13|14)|15|17|18|19|20|21|22|23|24|25|26|27|28|(2:29|30)|31|33|34|35|36|37|38|39|41|42|43|44|45|46|47|48|(3:49|50|52)) */
        /* JADX WARNING: Can't wrap try/catch for region: R(43:0|(2:1|2)|3|(2:5|6)|7|9|10|11|(2:13|14)|15|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|33|34|35|36|37|38|39|41|42|43|44|45|46|47|48|49|50|52) */
        /* JADX WARNING: Can't wrap try/catch for region: R(44:0|(2:1|2)|3|5|6|7|9|10|11|(2:13|14)|15|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|33|34|35|36|37|38|39|41|42|43|44|45|46|47|48|49|50|52) */
        /* JADX WARNING: Can't wrap try/catch for region: R(45:0|1|2|3|5|6|7|9|10|11|(2:13|14)|15|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|33|34|35|36|37|38|39|41|42|43|44|45|46|47|48|49|50|52) */
        /* JADX WARNING: Can't wrap try/catch for region: R(46:0|1|2|3|5|6|7|9|10|11|13|14|15|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|33|34|35|36|37|38|39|41|42|43|44|45|46|47|48|49|50|52) */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:19:0x003e */
        /* JADX WARNING: Missing exception handler attribute for start block: B:21:0x0049 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:23:0x0054 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:25:0x0060 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:27:0x006c */
        /* JADX WARNING: Missing exception handler attribute for start block: B:29:0x0078 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:35:0x0095 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:37:0x009f */
        /* JADX WARNING: Missing exception handler attribute for start block: B:43:0x00ba */
        /* JADX WARNING: Missing exception handler attribute for start block: B:45:0x00c4 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:47:0x00ce */
        /* JADX WARNING: Missing exception handler attribute for start block: B:49:0x00d8 */
        static {
            int[] iArr = new int[FileSignature.values().length];
            $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature = iArr;
            try {
                iArr[FileSignature.PNG.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature[FileSignature.JPEG_RAW.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature[FileSignature.JPEG_EXIF.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature[FileSignature.JPEG_JFIF.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature[FileSignature.JPEG_UNKNOWN.ordinal()] = 5;
            $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature[FileSignature.HEIC.ordinal()] = 6;
            $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature[FileSignature.WEBP.ordinal()] = 7;
            $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature[FileSignature.XML.ordinal()] = 8;
            $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature[FileSignature.BMP.ordinal()] = 9;
            $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature[FileSignature.GIF87a.ordinal()] = 10;
            try {
                $SwitchMap$ly$img$android$pesdk$backend$model$constant$FileSignature[FileSignature.GIF89a.ordinal()] = 11;
            } catch (NoSuchFieldError unused5) {
            }
            int[] iArr2 = new int[ImageFileFormat.values().length];
            $SwitchMap$ly$img$android$pesdk$backend$decoder$ImageFileFormat = iArr2;
            iArr2[ImageFileFormat.UNSUPPORTED.ordinal()] = 1;
            $SwitchMap$ly$img$android$pesdk$backend$decoder$ImageFileFormat[ImageFileFormat.JPEG.ordinal()] = 2;
            try {
                $SwitchMap$ly$img$android$pesdk$backend$decoder$ImageFileFormat[ImageFileFormat.PNG.ordinal()] = 3;
            } catch (NoSuchFieldError unused6) {
            }
            int[] iArr3 = new int[SOURCE_TYPE.values().length];
            $SwitchMap$ly$img$android$pesdk$backend$decoder$ImageSource$SOURCE_TYPE = iArr3;
            iArr3[SOURCE_TYPE.STATE_SET.ordinal()] = 1;
            $SwitchMap$ly$img$android$pesdk$backend$decoder$ImageSource$SOURCE_TYPE[SOURCE_TYPE.RESOURCE.ordinal()] = 2;
            $SwitchMap$ly$img$android$pesdk$backend$decoder$ImageSource$SOURCE_TYPE[SOURCE_TYPE.CANVAS.ordinal()] = 3;
            $SwitchMap$ly$img$android$pesdk$backend$decoder$ImageSource$SOURCE_TYPE[SOURCE_TYPE.URI.ordinal()] = 4;
            try {
                $SwitchMap$ly$img$android$pesdk$backend$decoder$ImageSource$SOURCE_TYPE[SOURCE_TYPE.NONE.ordinal()] = 5;
            } catch (NoSuchFieldError unused7) {
            }
        }
    }

    public static ImageFileFormat readFormat(int i) throws IOException {
        try {
            Resources appResource = PESDK.getAppResource();
            TypedValue typedValue = new TypedValue();
            char c = 1;
            appResource.getValue(i, typedValue, true);
            String lowerCase = typedValue.string.toString().toLowerCase();
            String lowerCase2 = lowerCase.substring(lowerCase.lastIndexOf(".") + 1).toLowerCase();
            switch (lowerCase2.hashCode()) {
                case 97669:
                    if (lowerCase2.equals("bmp")) {
                        c = 5;
                        break;
                    }
                    c = 65535;
                    break;
                case 102340:
                    if (lowerCase2.equals("gif")) {
                        c = 6;
                        break;
                    }
                    c = 65535;
                    break;
                case 105441:
                    if (lowerCase2.equals("jpg")) {
                        break;
                    }
                    c = 65535;
                    break;
                case 111145:
                    if (lowerCase2.equals("png")) {
                        c = 0;
                        break;
                    }
                    c = 65535;
                    break;
                case 118807:
                    if (lowerCase2.equals("xml")) {
                        c = 4;
                        break;
                    }
                    c = 65535;
                    break;
                case 3268712:
                    if (lowerCase2.equals("jpeg")) {
                        c = 2;
                        break;
                    }
                    c = 65535;
                    break;
                case 3645340:
                    if (lowerCase2.equals("webp")) {
                        c = 3;
                        break;
                    }
                    c = 65535;
                    break;
                default:
                    c = 65535;
                    break;
            }
            switch (c) {
                case 0:
                    return ImageFileFormat.PNG;
                case 1:
                case 2:
                    return ImageFileFormat.JPEG;
                case 3:
                    return ImageFileFormat.WEBP;
                case 4:
                    return ImageFileFormat.XML_DRAWABLE;
                case 5:
                    return ImageFileFormat.BMP;
                case 6:
                    return ImageFileFormat.GIF;
                default:
                    return readFormat(Decoder.getInputStream(Decoder.resourceToUri(getResources(), i)));
            }
        } catch (Resources.NotFoundException unused) {
            return ImageFileFormat.UNSUPPORTED;
        }
    }

    public static Resources getResources() {
        return defaultThemeContext.getResources();
    }

    public Uri getUri() {
        int i = AnonymousClass3.$SwitchMap$ly$img$android$pesdk$backend$decoder$ImageSource$SOURCE_TYPE[this.sourceType.ordinal()];
        if (i == 2) {
            return Decoder.resourceToUri(getResources(), this.resourceId);
        }
        if (i != 4) {
            return null;
        }
        return this.uri;
    }

    public InputStream getRawStream() throws FileNotFoundException {
        Uri uri2 = getUri();
        if (uri2 != null) {
            return new BufferedInputStream(Decoder.getInputStream(uri2));
        }
        return null;
    }

    public Bitmap getBitmap() {
        Decoder decoder2 = getDecoder();
        ImageSize size = decoder2.getSize();
        return decoder2.getBitmap(size.width, size.height, true, null);
    }

    public Bitmap getBitmap(DrawableState drawableState) {
        Decoder decoder2 = getDecoder();
        ImageSize size = decoder2.getSize();
        return decoder2.getBitmap(size.width, size.height, true, drawableState);
    }

    public Bitmap getBitmap(int i, int i2, boolean z) {
        return getBitmap(i, i2, z, (DrawableState) null);
    }

    public Bitmap getBitmap(int i, int i2, boolean z, int[] iArr) {
        return getBitmap(i, i2, z, DrawableState.findBestMatch(iArr));
    }

    public Bitmap getBitmap(int i, int i2, boolean z, DrawableState drawableState) {
        return getStateDecoder(drawableState).getBitmap(i, i2, z, drawableState);
    }

    public boolean isStateful() {
        return !isStaticImage() && (this.sourceType == SOURCE_TYPE.STATE_SET || getDecoder().isStateful());
    }

    public Bitmap getBitmap(RectF rectF, RectF rectF2) {
        return getDecoder().getBitmap(rectF, rectF2);
    }

    public Bitmap getBitmap(Rect rect, Rect rect2) {
        return getDecoder().getBitmap(new RectF(rect), new RectF(rect2));
    }

    public Bitmap getBitmap(RectF rectF, Rect rect) {
        return getDecoder().getBitmap(rectF, new RectF(rect));
    }

    public Bitmap getBitmap(MultiRect multiRect, int i) {
        return getDecoder().getBitmap(multiRect, i);
    }

    public Bitmap getBitmap(Rect rect, RectF rectF) {
        return getDecoder().getBitmap(new RectF(rect), rectF);
    }

    public void logErrorIfScaledResource() {
        if (this.sourceType == SOURCE_TYPE.RESOURCE) {
            try {
                TypedValue typedValue = new TypedValue();
                getResources().getValue(this.resourceId, typedValue, true);
                String charSequence = typedValue.string.toString();
                if (!charSequence.contains("/drawable-nodpi") && !charSequence.contains("/raw") && charSequence.contains("/drawable") && !charSequence.endsWith(".xml")) {
                    Log.e("ImageSource", "Critical Warning: Please put your image resource \"" + charSequence + "\" into the \"res/drawable-nodpi/\" folder! https://developer.android.com/guide/practices/screens_support.html#DensityConsiderations");
                }
            } catch (Exception unused) {
            }
        }
    }

    /* JADX DEBUG: Failed to insert an additional move for type inference into block B:17:0x0049 */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v0, types: [android.graphics.drawable.Drawable] */
    /* JADX WARN: Type inference failed for: r0v2, types: [android.graphics.drawable.Drawable] */
    /* JADX WARN: Type inference failed for: r0v3, types: [android.graphics.drawable.StateListDrawable] */
    /* JADX WARN: Type inference failed for: r0v5, types: [android.graphics.drawable.Drawable] */
    /* JADX WARN: Type inference failed for: r0v6, types: [ly.img.android.pesdk.backend.decoder.ImageSource$2] */
    /* JADX WARNING: Unknown variable types count: 1 */
    public Drawable getDrawable() {
        ?? r0 = this.drawable;
        Drawable drawable2 = r0;
        if (r0 == 0) {
            int i = AnonymousClass3.$SwitchMap$ly$img$android$pesdk$backend$decoder$ImageSource$SOURCE_TYPE[this.sourceType.ordinal()];
            if (i == 1) {
                r0 = new StateListDrawable();
                StateSource[] stateSourceArr = this.stateSourceList;
                for (StateSource stateSource : stateSourceArr) {
                    r0.addState(stateSource.drawableState.stateList, getStateDecoder(stateSource).getDrawable());
                }
            } else if (i == 2 || i == 4) {
                r0 = getDecoder().getDrawable();
            } else if (i == 5) {
                r0 = new Drawable() {
                    /* class ly.img.android.pesdk.backend.decoder.ImageSource.AnonymousClass2 */

                    public void draw(Canvas canvas) {
                    }

                    public int getOpacity() {
                        return -2;
                    }

                    public void setAlpha(int i) {
                    }

                    public void setColorFilter(ColorFilter colorFilter) {
                    }
                };
            }
            this.drawable = r0;
            drawable2 = r0;
        }
        return drawable2;
    }

    public void recycle() {
        Decoder decoder2 = this.decoder;
        if (decoder2 != null) {
            decoder2.recycle();
        }
    }

    public boolean isStaticImage() {
        Boolean bool = this.isStaticBitmap;
        if (bool == null) {
            bool = Boolean.valueOf(this.sourceType == SOURCE_TYPE.RESOURCE && !BitmapFactoryUtils.checkIsXMLResource(this.resourceId) && (!ImageFileFormat.hasGifDecoder || !BitmapFactoryUtils.checkIsGifResource(this.resourceId)));
            this.isStaticBitmap = bool;
        }
        return bool.booleanValue();
    }

    public boolean isVector() {
        if (this.isVector == null) {
            this.isVector = Boolean.valueOf(getDecoder().isVector());
        }
        return this.isVector.booleanValue();
    }

    protected ImageSource(Parcel parcel) {
        SOURCE_TYPE source_type;
        Boolean bool;
        Boolean bool2;
        this.imageSize = null;
        this.rotation = -1;
        int i = 0;
        this.resourceId = 0;
        this.uri = null;
        this.canvasClass = null;
        this.isVector = null;
        this.isStaticBitmap = null;
        this.variant = null;
        boolean z = true;
        this.variantCount = 1;
        this.context = new WeakReference<>(defaultThemeContext);
        int readInt = parcel.readInt();
        if (readInt == -1) {
            source_type = null;
        } else {
            source_type = SOURCE_TYPE.values()[readInt];
        }
        this.sourceType = source_type;
        this.uri = (Uri) parcel.readParcelable(Uri.class.getClassLoader());
        this.resourceId = parcel.readInt();
        this.imageSize = (ImageSize) parcel.readParcelable(ImageSize.class.getClassLoader());
        this.imageFormat = (ImageFileFormat) parcel.readSerializable();
        this.rotation = parcel.readInt();
        int readInt2 = parcel.readInt();
        if (readInt2 == 2) {
            bool = null;
        } else {
            bool = Boolean.valueOf(readInt2 == 1);
        }
        this.isVector = bool;
        int readInt3 = parcel.readInt();
        if (readInt3 == 2) {
            bool2 = null;
        } else {
            bool2 = Boolean.valueOf(readInt3 != 1 ? false : z);
        }
        this.isStaticBitmap = bool2;
        this.canvasClass = (Class) parcel.readSerializable();
        this.providerName = parcel.readString();
        StateSource[] stateSourceArr = (StateSource[]) parcel.readParcelableArray(StateSource.class.getClassLoader());
        this.stateSourceList = stateSourceArr;
        if (stateSourceArr != null) {
            this.stateList = new DrawableState[stateSourceArr.length];
            while (true) {
                StateSource[] stateSourceArr2 = this.stateSourceList;
                if (i < stateSourceArr2.length) {
                    this.stateList[i] = stateSourceArr2[i].drawableState;
                    i++;
                } else {
                    return;
                }
            }
        } else {
            this.stateList = null;
        }
    }

    public void writeToParcel(Parcel parcel, int i) {
        SOURCE_TYPE source_type = this.sourceType;
        parcel.writeInt(source_type == null ? -1 : source_type.ordinal());
        parcel.writeParcelable(this.uri, i);
        parcel.writeInt(this.resourceId);
        parcel.writeParcelable(this.imageSize, i);
        parcel.writeSerializable(this.imageFormat);
        parcel.writeInt(this.rotation);
        Boolean bool = this.isVector;
        int i2 = 1;
        parcel.writeInt(bool == null ? 2 : bool.booleanValue() ? 1 : 0);
        Boolean bool2 = this.isStaticBitmap;
        if (bool2 == null) {
            i2 = 2;
        } else if (!bool2.booleanValue()) {
            i2 = 0;
        }
        parcel.writeInt(i2);
        parcel.writeSerializable(this.canvasClass);
        parcel.writeString(this.providerName);
        parcel.writeParcelableArray(this.stateSourceList, i);
    }

    public static final class NonStaticResourceException extends RuntimeException {
        public NonStaticResourceException() {
            super("Can't get resource id from a Non-Resource-ImageFile please check hasResourceId()");
        }
    }

    @Deprecated
    public static final class UnsupportedFormatException extends RuntimeException {
        public UnsupportedFormatException() {
            super("Unsupported Format");
        }
    }

    public static final class UnsupportedSourceException extends RuntimeException {
        public UnsupportedSourceException() {
            super("Unsupported Input-Source Type");
        }
    }
}