package r2;

import android.graphics.Color;
import android.text.TextUtils;
import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final boolean f32353g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final int f32354h;

    @Nullable
    @ColorInt
    public final Integer outlineColor;

    @Nullable
    @ColorInt
    public final Integer primaryColor;

    private e(String str, int i10, @Nullable @ColorInt Integer num, @Nullable @ColorInt Integer num2, float f10, boolean z10, boolean z11, boolean z12, boolean z13, int i11) {
        this.f32347a = str;
        this.f32348b = i10;
        this.primaryColor = num;
        this.outlineColor = num2;
        this.f32349c = f10;
        this.f32350d = z10;
        this.f32351e = z11;
        this.f32352f = z12;
        this.f32353g = z13;
        this.f32354h = i11;
    }

    public static int a(String str) {
        int i10;
        try {
            i10 = Integer.parseInt(str.trim());
        } catch (NumberFormatException unused) {
        }
        switch (i10) {
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
                return i10;
            default:
                defpackage.e.A("Ignoring unknown alignment: ", str, "SsaStyle");
                return -1;
        }
    }

    public static boolean b(String str) {
        try {
            int i10 = Integer.parseInt(str);
            return i10 == 1 || i10 == -1;
        } catch (NumberFormatException e10) {
            Log.w("SsaStyle", "Failed to parse boolean value: '" + str + "'", e10);
            return false;
        }
    }

    @Nullable
    public static e fromStyleLine(String str, c cVar) {
        float f10;
        int i10;
        Assertions.checkArgument(str.startsWith("Style:"));
        String[] strArrSplit = TextUtils.split(str.substring(6), ",");
        int length = strArrSplit.length;
        int i11 = cVar.f32341k;
        if (length != i11) {
            Log.w("SsaStyle", Util.formatInvariant("Skipping malformed 'Style:' line (expected %s values, found %s): '%s'", Integer.valueOf(i11), Integer.valueOf(strArrSplit.length), str));
            return null;
        }
        try {
            String strTrim = strArrSplit[cVar.f32331a].trim();
            int i12 = cVar.f32332b;
            int i13 = -1;
            int iA = i12 != -1 ? a(strArrSplit[i12].trim()) : -1;
            int i14 = cVar.f32333c;
            Integer color = i14 != -1 ? parseColor(strArrSplit[i14].trim()) : null;
            int i15 = cVar.f32334d;
            Integer color2 = i15 != -1 ? parseColor(strArrSplit[i15].trim()) : null;
            int i16 = cVar.f32335e;
            if (i16 != -1) {
                String strTrim2 = strArrSplit[i16].trim();
                try {
                    f10 = Float.parseFloat(strTrim2);
                } catch (NumberFormatException e10) {
                    Log.w("SsaStyle", "Failed to parse font size: '" + strTrim2 + "'", e10);
                    f10 = -3.4028235E38f;
                }
            } else {
                f10 = -3.4028235E38f;
            }
            int i17 = cVar.f32336f;
            boolean z10 = i17 != -1 && b(strArrSplit[i17].trim());
            int i18 = cVar.f32337g;
            boolean z11 = i18 != -1 && b(strArrSplit[i18].trim());
            int i19 = cVar.f32338h;
            boolean z12 = i19 != -1 && b(strArrSplit[i19].trim());
            int i20 = cVar.f32339i;
            boolean z13 = i20 != -1 && b(strArrSplit[i20].trim());
            int i21 = cVar.f32340j;
            if (i21 != -1) {
                String strTrim3 = strArrSplit[i21].trim();
                try {
                    i10 = Integer.parseInt(strTrim3.trim());
                } catch (NumberFormatException unused) {
                }
                if (i10 == 1 || i10 == 3) {
                    i13 = i10;
                } else {
                    Log.w("SsaStyle", "Ignoring unknown BorderStyle: " + strTrim3);
                }
            }
            return new e(strTrim, iA, color, color2, f10, z10, z11, z12, z13, i13);
        } catch (RuntimeException e11) {
            Log.w("SsaStyle", "Skipping malformed 'Style:' line: '" + str + "'", e11);
            return null;
        }
    }

    @Nullable
    @ColorInt
    public static Integer parseColor(String str) {
        try {
            long j10 = str.startsWith("&H") ? Long.parseLong(str.substring(2), 16) : Long.parseLong(str);
            Assertions.checkArgument(j10 <= 4294967295L);
            return Integer.valueOf(Color.argb(com.google.common.primitives.a.c(((j10 >> 24) & 255) ^ 255), com.google.common.primitives.a.c(j10 & 255), com.google.common.primitives.a.c((j10 >> 8) & 255), com.google.common.primitives.a.c((j10 >> 16) & 255)));
        } catch (IllegalArgumentException e10) {
            Log.w("SsaStyle", "Failed to parse color expression: '" + str + "'", e10);
            return null;
        }
    }
}
