package com.ifpdos.autotest.lancontrol.module.other.e;

import android.content.Context;
import android.util.Log;
import com.cvte.vman.VmanMiddleWare;
import com.ifpdos.autotest.api.IColor;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;

/* JADX INFO: compiled from: ColorImpl.java */
/* JADX INFO: loaded from: classes.dex */
public class m implements IColor {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private Context f2093a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private com.ifpdos.autotest.lancontrol.module.other.e.y.g[] f2094b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private Map<Integer, com.ifpdos.autotest.lancontrol.module.other.e.y.g> f2095c;

    public m(Context context) {
        this.f2093a = context;
        try {
            this.f2094b = com.ifpdos.autotest.lancontrol.module.other.e.y.e.a(context);
        } catch (IOException e2) {
            b.c.c.l.b.a("ColorImpl", "fail to load lut from asset");
            e2.printStackTrace();
        }
    }

    static /* synthetic */ void b(com.ifpdos.autotest.lancontrol.module.other.e.y.g[] gVarArr, Integer num, com.ifpdos.autotest.lancontrol.module.other.e.y.g gVar) {
        if (num.intValue() < 0 || num.intValue() >= gVarArr.length) {
            return;
        }
        com.ifpdos.autotest.lancontrol.module.other.e.y.g gVar2 = gVarArr[num.intValue()];
        gVarArr[num.intValue()] = gVar;
        Log.i("ColorImpl", "calculateLargrangeRGB, replace rgb, index = " + num + " origin = " + gVar2 + ", replaceAfter = " + gVar);
    }

    public boolean a(String str, String str2, int i, double d2, List<Double> list, List<Double> list2, com.ifpdos.autotest.lancontrol.module.other.e.y.d dVar) {
        Map<Integer, com.ifpdos.autotest.lancontrol.module.other.e.y.g> map;
        try {
            com.ifpdos.autotest.lancontrol.module.other.e.y.f fVar = new com.ifpdos.autotest.lancontrol.module.other.e.y.f(list);
            com.ifpdos.autotest.lancontrol.module.other.e.y.m mVar = new com.ifpdos.autotest.lancontrol.module.other.e.y.m(list2);
            b.c.c.l.b.d("ColorImpl", "receive calculateLargrangeRGB request: ");
            b.c.c.l.b.d("ColorImpl", "colorTemperature: " + str);
            b.c.c.l.b.d("ColorImpl", "spaceType: " + str2);
            b.c.c.l.b.d("ColorImpl", "interpolation: " + i);
            b.c.c.l.b.d("ColorImpl", "mapRGBLv: " + d2);
            b.c.c.l.b.d("ColorImpl", "matrix: " + list);
            b.c.c.l.b.d("ColorImpl", "map: " + mVar);
            int i2 = b.c.e.a.b.f1524a;
            int i3 = i2 == 10 ? 4095 : 1023;
            final com.ifpdos.autotest.lancontrol.module.other.e.y.g[] gVarArr = new com.ifpdos.autotest.lancontrol.module.other.e.y.g[this.f2094b.length];
            if (!str2.equals("default")) {
                int i4 = 0;
                while (true) {
                    com.ifpdos.autotest.lancontrol.module.other.e.y.g[] gVarArr2 = this.f2094b;
                    if (i4 >= gVarArr2.length) {
                        break;
                    }
                    gVarArr[i4] = mVar.d(fVar.b(com.ifpdos.autotest.lancontrol.module.other.e.y.n.u(str, str2, gVarArr2[i4].b(1023))), d2, i).d(i3);
                    i4++;
                }
                if ("srgb".equals(str2) && (map = this.f2095c) != null && map.size() > 0) {
                    this.f2095c.forEach(new BiConsumer() { // from class: com.ifpdos.autotest.lancontrol.module.other.e.a
                        @Override // java.util.function.BiConsumer
                        public final void accept(Object obj, Object obj2) {
                            m.b(gVarArr, (Integer) obj, (com.ifpdos.autotest.lancontrol.module.other.e.y.g) obj2);
                        }
                    });
                    this.f2095c.clear();
                }
                return dVar.a(gVarArr, str2);
            }
            if (i2 != 10) {
                return dVar.a(this.f2094b, str2);
            }
            int i5 = 0;
            while (true) {
                com.ifpdos.autotest.lancontrol.module.other.e.y.g[] gVarArr3 = this.f2094b;
                if (i5 >= gVarArr3.length) {
                    return dVar.a(gVarArr, str2);
                }
                gVarArr[i5] = gVarArr3[i5].b(1023).d(i3);
                i5++;
            }
        } catch (Throwable th) {
            Log.e("ColorImpl", "calculateLargrangeRGB error", th);
            return false;
        }
    }

    @Override // com.ifpdos.autotest.api.IColor
    public boolean calculateLargrangeRGB(String str, String str2, int i, double d2, List<Double> list, List<Double> list2) {
        if (this.f2094b == null) {
            return false;
        }
        com.ifpdos.autotest.lancontrol.module.other.e.y.d dVarA = com.ifpdos.autotest.lancontrol.module.other.e.y.l.a();
        String[] strArr = {"srgb", "adobergb", "display_p3", "dci_p3", "bt_2020", "default"};
        for (int i2 = 0; i2 < 6; i2++) {
            String str3 = strArr[i2];
            if (!a(str, str3, i, d2, list, list2, dVarA)) {
                b.c.c.l.b.a("ColorImpl", "fail to crate lut form space: " + str3);
                return false;
            }
        }
        return b.c.e.a.b.f1524a == 10 || (dVarA instanceof com.ifpdos.autotest.lancontrol.module.other.e.y.j) || VmanMiddleWare.getInstance(this.f2093a).getPQCtrl().setAuto3DLutConfig() == 0;
    }

    @Override // com.ifpdos.autotest.api.IColor
    public boolean patternAdjust(int i, int i2, int i3, int i4) {
        Log.i("ColorImpl", "patternAdjust, index = " + i + ", r = " + i2 + ", g = " + i3 + ", b = " + i4);
        if (this.f2095c == null) {
            this.f2095c = new HashMap();
        }
        this.f2095c.put(Integer.valueOf(i), new com.ifpdos.autotest.lancontrol.module.other.e.y.g(i2, i3, i4));
        return true;
    }
}
