package i0;

import android.graphics.Color;
import androidx.annotation.ColorInt;
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
import tv.danmaku.ijk.media.player.IjkMediaMeta;

/* JADX INFO: loaded from: classes.dex */
public final class a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final float f26476a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final float f26477b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final float f26478c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final float f26479d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final float f26480e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final float f26481f;

    public a(float f10, float f11, float f12, float f13, float f14, float f15) {
        this.f26476a = f10;
        this.f26477b = f11;
        this.f26478c = f12;
        this.f26479d = f13;
        this.f26480e = f14;
        this.f26481f = f15;
    }

    public static a a(int i10) {
        float[] fArr = new float[7];
        float[] fArr2 = new float[3];
        fromColorInViewingConditions(i10, t.f26516k, fArr, fArr2);
        return new a(fArr2[0], fArr2[1], fArr[0], fArr[4], fArr[5], fArr[6]);
    }

    public static a b(float f10, float f11, float f12) {
        t tVar = t.f26516k;
        float f13 = tVar.f26520d;
        Math.sqrt(((double) f10) / 100.0d);
        float f14 = tVar.f26517a + 4.0f;
        float f15 = tVar.f26525i * f11;
        Math.sqrt(((f11 / ((float) Math.sqrt(r1))) * tVar.f26520d) / f14);
        float f16 = (1.7f * f10) / ((0.007f * f10) + 1.0f);
        float fLog = ((float) Math.log((((double) f15) * 0.0228d) + 1.0d)) * 43.85965f;
        double d10 = (3.1415927f * f12) / 180.0f;
        return new a(f12, f11, f10, f16, fLog * ((float) Math.cos(d10)), fLog * ((float) Math.sin(d10)));
    }

    public static int c(float f10, float f11, float f12) {
        t tVar = t.f26516k;
        if (f11 < 1.0d || Math.round(f12) <= 0.0d || Math.round(f12) >= 100.0d) {
            return b.a(f12);
        }
        float fMin = f10 < 0.0f ? 0.0f : Math.min(360.0f, f10);
        a aVar = null;
        boolean z10 = true;
        float f13 = 0.0f;
        float f14 = f11;
        while (Math.abs(f13 - f11) >= 0.4f) {
            a aVarFindCamByJ = findCamByJ(fMin, f14, f12);
            if (!z10) {
                if (aVarFindCamByJ == null) {
                    f11 = f14;
                } else {
                    f13 = f14;
                    aVar = aVarFindCamByJ;
                }
                f14 = ((f11 - f13) / 2.0f) + f13;
            } else {
                if (aVarFindCamByJ != null) {
                    return aVarFindCamByJ.d(tVar);
                }
                f14 = ((f11 - f13) / 2.0f) + f13;
                z10 = false;
            }
        }
        return aVar == null ? b.a(f12) : aVar.d(tVar);
    }

    @Nullable
    private static a findCamByJ(@FloatRange(from = 0.0d, to = 360.0d) float f10, @FloatRange(from = 0.0d, to = Double.POSITIVE_INFINITY, toInclusive = false) float f11, @FloatRange(from = 0.0d, to = 100.0d) float f12) {
        float f13 = 100.0f;
        float f14 = 1000.0f;
        float f15 = 100.0f;
        a aVar = null;
        float f16 = 0.0f;
        float f17 = 1000.0f;
        while (Math.abs(f16 - f15) > 0.01f) {
            float f18 = ((f15 - f16) / 2.0f) + f16;
            int iD = b(f18, f11, f10).d(t.f26516k);
            float fB = b.b(Color.red(iD));
            float fB2 = b.b(Color.green(iD));
            float fB3 = b.b(Color.blue(iD));
            float[] fArr = b.f26485d[1];
            float f19 = ((fB3 * fArr[2]) + ((fB2 * fArr[1]) + (fB * fArr[0]))) / f13;
            float fCbrt = f19 <= 0.008856452f ? f19 * 903.2963f : (((float) Math.cbrt(f19)) * 116.0f) - 16.0f;
            float fAbs = Math.abs(f12 - fCbrt);
            if (fAbs < 0.2f) {
                a aVarA = a(iD);
                a aVarB = b(aVarA.f26478c, aVarA.f26477b, f10);
                float f20 = aVarA.f26479d - aVarB.f26479d;
                float f21 = aVarA.f26480e - aVarB.f26480e;
                float f22 = aVarA.f26481f - aVarB.f26481f;
                float fPow = (float) (Math.pow(Math.sqrt((f22 * f22) + (f21 * f21) + (f20 * f20)), 0.63d) * 1.41d);
                if (fPow <= 1.0f) {
                    f17 = fPow;
                    aVar = aVarA;
                    f14 = fAbs;
                }
            }
            if (f14 == 0.0f && f17 == 0.0f) {
                break;
            }
            if (fCbrt < f12) {
                f16 = f18;
            } else {
                f15 = f18;
            }
            f13 = 100.0f;
        }
        return aVar;
    }

    public static void fromColorInViewingConditions(@ColorInt int i10, @NonNull t tVar, @Nullable @Size(IjkMediaMeta.AV_CH_LAYOUT_SURROUND) float[] fArr, @NonNull @Size(IjkMediaMeta.AV_CH_LAYOUT_STEREO) float[] fArr2) {
        float fB = b.b(Color.red(i10));
        float fB2 = b.b(Color.green(i10));
        float fB3 = b.b(Color.blue(i10));
        float[][] fArr3 = b.f26485d;
        float[] fArr4 = fArr3[0];
        float f10 = (fArr4[2] * fB3) + (fArr4[1] * fB2) + (fArr4[0] * fB);
        fArr2[0] = f10;
        float[] fArr5 = fArr3[1];
        float f11 = (fArr5[2] * fB3) + (fArr5[1] * fB2) + (fArr5[0] * fB);
        fArr2[1] = f11;
        float[] fArr6 = fArr3[2];
        float f12 = (fB3 * fArr6[2]) + (fB2 * fArr6[1]) + (fB * fArr6[0]);
        fArr2[2] = f12;
        float[][] fArr7 = b.f26482a;
        float[] fArr8 = fArr7[0];
        float f13 = (fArr8[2] * f12) + (fArr8[1] * f11) + (fArr8[0] * f10);
        float[] fArr9 = fArr7[1];
        float f14 = (fArr9[2] * f12) + (fArr9[1] * f11) + (fArr9[0] * f10);
        float[] fArr10 = fArr7[2];
        float f15 = (f12 * fArr10[2]) + (f11 * fArr10[1]) + (f10 * fArr10[0]);
        float[] fArr11 = tVar.f26523g;
        float f16 = fArr11[0] * f13;
        float f17 = fArr11[1] * f14;
        float f18 = fArr11[2] * f15;
        float fAbs = Math.abs(f16);
        float f19 = tVar.f26524h;
        float fPow = (float) Math.pow(((double) (fAbs * f19)) / 100.0d, 0.42d);
        float fPow2 = (float) Math.pow(((double) (Math.abs(f17) * f19)) / 100.0d, 0.42d);
        float fPow3 = (float) Math.pow(((double) (Math.abs(f18) * f19)) / 100.0d, 0.42d);
        float fSignum = ((Math.signum(f16) * 400.0f) * fPow) / (fPow + 27.13f);
        float fSignum2 = ((Math.signum(f17) * 400.0f) * fPow2) / (fPow2 + 27.13f);
        float fSignum3 = ((Math.signum(f18) * 400.0f) * fPow3) / (fPow3 + 27.13f);
        double d10 = fSignum3;
        float f20 = ((float) (((((double) fSignum2) * (-12.0d)) + (((double) fSignum) * 11.0d)) + d10)) / 11.0f;
        float f21 = ((float) (((double) (fSignum + fSignum2)) - (d10 * 2.0d))) / 9.0f;
        float f22 = fSignum2 * 20.0f;
        float f23 = ((21.0f * fSignum3) + ((fSignum * 20.0f) + f22)) / 20.0f;
        float f24 = (((fSignum * 40.0f) + f22) + fSignum3) / 20.0f;
        float fAtan2 = (((float) Math.atan2(f21, f20)) * 180.0f) / 3.1415927f;
        if (fAtan2 < 0.0f) {
            fAtan2 += 360.0f;
        } else if (fAtan2 >= 360.0f) {
            fAtan2 -= 360.0f;
        }
        float f25 = (3.1415927f * fAtan2) / 180.0f;
        float f26 = f24 * tVar.f26518b;
        float f27 = tVar.f26517a;
        double d11 = f26 / f27;
        float f28 = tVar.f26520d;
        float fPow4 = ((float) Math.pow(d11, tVar.f26526j * f28)) * 100.0f;
        float fSqrt = (f27 + 4.0f) * (4.0f / f28) * ((float) Math.sqrt(fPow4 / 100.0f));
        float f29 = tVar.f26525i;
        float f30 = fSqrt * f29;
        float fSqrt2 = ((float) Math.sqrt(((double) fPow4) / 100.0d)) * ((float) Math.pow(1.64d - Math.pow(0.29d, tVar.f26522f), 0.73d)) * ((float) Math.pow((((((((float) (Math.cos(((((double) (((double) fAtan2) < 20.14d ? 360.0f + fAtan2 : fAtan2)) * 3.141592653589793d) / 180.0d) + 2.0d) + 3.8d)) * 0.25f) * 3846.1538f) * tVar.f26521e) * tVar.f26519c) * ((float) Math.sqrt((f21 * f21) + (f20 * f20)))) / (f23 + 0.305f), 0.9d));
        float f31 = f29 * fSqrt2;
        float fSqrt3 = ((float) Math.sqrt((r3 * f28) / (f27 + 4.0f))) * 50.0f;
        float f32 = (1.7f * fPow4) / ((0.007f * fPow4) + 1.0f);
        float fLog = ((float) Math.log((0.0228f * f31) + 1.0f)) * 43.85965f;
        double d12 = f25;
        float fCos = ((float) Math.cos(d12)) * fLog;
        float fSin = fLog * ((float) Math.sin(d12));
        fArr2[0] = fAtan2;
        fArr2[1] = fSqrt2;
        if (fArr != null) {
            fArr[0] = fPow4;
            fArr[1] = f30;
            fArr[2] = f31;
            fArr[3] = fSqrt3;
            fArr[4] = f32;
            fArr[5] = fCos;
            fArr[6] = fSin;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:8:0x001f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int d(t tVar) {
        float fSqrt;
        float f10 = this.f26477b;
        double d10 = f10;
        float f11 = this.f26478c;
        if (d10 != 0.0d) {
            double d11 = f11;
            fSqrt = d11 == 0.0d ? 0.0f : f10 / ((float) Math.sqrt(d11 / 100.0d));
        }
        float fPow = (float) Math.pow(((double) fSqrt) / Math.pow(1.64d - Math.pow(0.29d, tVar.f26522f), 0.73d), 1.1111111111111112d);
        double d12 = (this.f26476a * 3.1415927f) / 180.0f;
        float fCos = ((float) (Math.cos(2.0d + d12) + 3.8d)) * 0.25f;
        float fPow2 = tVar.f26517a * ((float) Math.pow(((double) f11) / 100.0d, (1.0d / ((double) tVar.f26520d)) / ((double) tVar.f26526j)));
        float f12 = fCos * 3846.1538f * tVar.f26521e * tVar.f26519c;
        float f13 = fPow2 / tVar.f26518b;
        float fSin = (float) Math.sin(d12);
        float fCos2 = (float) Math.cos(d12);
        float f14 = (((0.305f + f13) * 23.0f) * fPow) / (((fPow * 108.0f) * fSin) + (((11.0f * fPow) * fCos2) + (f12 * 23.0f)));
        float f15 = fCos2 * f14;
        float f16 = f14 * fSin;
        float f17 = f13 * 460.0f;
        float f18 = ((288.0f * f16) + ((451.0f * f15) + f17)) / 1403.0f;
        float f19 = ((f17 - (891.0f * f15)) - (261.0f * f16)) / 1403.0f;
        float f20 = ((f17 - (f15 * 220.0f)) - (f16 * 6300.0f)) / 1403.0f;
        float fMax = (float) Math.max(0.0d, (((double) Math.abs(f18)) * 27.13d) / (400.0d - ((double) Math.abs(f18))));
        float fSignum = Math.signum(f18);
        float f21 = 100.0f / tVar.f26524h;
        float fPow3 = fSignum * f21 * ((float) Math.pow(fMax, 2.380952380952381d));
        float fSignum2 = Math.signum(f19) * f21 * ((float) Math.pow((float) Math.max(0.0d, (((double) Math.abs(f19)) * 27.13d) / (400.0d - ((double) Math.abs(f19)))), 2.380952380952381d));
        float fSignum3 = Math.signum(f20) * f21 * ((float) Math.pow((float) Math.max(0.0d, (((double) Math.abs(f20)) * 27.13d) / (400.0d - ((double) Math.abs(f20)))), 2.380952380952381d));
        float[] fArr = tVar.f26523g;
        float f22 = fPow3 / fArr[0];
        float f23 = fSignum2 / fArr[1];
        float f24 = fSignum3 / fArr[2];
        float[][] fArr2 = b.f26483b;
        float[] fArr3 = fArr2[0];
        float f25 = (fArr3[2] * f24) + (fArr3[1] * f23) + (fArr3[0] * f22);
        float[] fArr4 = fArr2[1];
        float f26 = (fArr4[2] * f24) + (fArr4[1] * f23) + (fArr4[0] * f22);
        float[] fArr5 = fArr2[2];
        return j0.c.a(f25, f26, (f24 * fArr5[2]) + (f23 * fArr5[1]) + (f22 * fArr5[0]));
    }
}
