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

import android.annotation.SuppressLint;
import android.os.Environment;
import android.util.Log;
import b.c.d.d.d;
import com.cvte.vman.VmanMiddleWare;
import d.n0.c.s;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/* JADX INFO: compiled from: RGBDataWriter982.kt */
/* JADX INFO: loaded from: classes.dex */
@d.n
public final class j implements d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final a f2171a = new a(null);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    @SuppressLint({"SdCardPath"})
    private static final String f2172b = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "3dlut.bin";

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static final String f2173c = "/mnt/vendor/factory/";

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private int f2174d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private BufferedOutputStream f2175e = new BufferedOutputStream(new FileOutputStream(new File(f2172b)));

    /* JADX INFO: compiled from: RGBDataWriter982.kt */
    @d.n
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(d.n0.c.l lVar) {
            this();
        }
    }

    private final void b() {
        File file = new File(f2172b);
        if (file.exists()) {
            file.delete();
        }
    }

    @Override // com.ifpdos.autotest.lancontrol.module.other.e.y.d
    public boolean a(g[] gVarArr, String str) throws IOException {
        boolean z;
        s.e(gVarArr, "rgbs");
        s.e(str, "spaceType");
        this.f2174d++;
        boolean z2 = false;
        int i = 0;
        int i2 = 0;
        int i3 = 0;
        for (g gVar : gVarArr) {
            int i4 = (int) gVar.f2161a;
            int i5 = (int) gVar.f2162b;
            int i6 = (int) gVar.f2163c;
            if (z2) {
                int i7 = i | (i2 << 12);
                int i8 = (i4 << 12) | i3;
                int i9 = i5 | (i6 << 12);
                this.f2175e.write(new byte[]{(byte) (i7 & 255), (byte) ((i7 >> 8) & 255), (byte) ((i7 >> 16) & 255), (byte) (i8 & 255), (byte) ((i8 >> 8) & 255), (byte) ((i8 >> 16) & 255), (byte) (i9 & 255), (byte) ((i9 >> 8) & 255), (byte) ((i9 >> 16) & 255)});
            } else {
                i2 = i5;
                i3 = i6;
                i = i4;
            }
            z2 = !z2;
        }
        Log.i("RGBDataWriter982", str + " isWrite=" + z2);
        if (z2) {
            int i10 = (i2 << 12) | i;
            z = false;
            this.f2175e.write(new byte[]{(byte) (i10 & 255), (byte) ((i10 >> 8) & 255), (byte) ((i10 >> 16) & 255), (byte) (i3 & 255), (byte) ((i3 >> 8) & 255), (byte) ((i3 >> 16) & 255), (byte) 0, (byte) 0, (byte) 0});
        } else {
            z = false;
        }
        this.f2175e.flush();
        if (this.f2174d != 6) {
            return true;
        }
        this.f2175e.close();
        if (com.ifpdos.autotest.k0.g.d.a()) {
            boolean zSync3dlutDataFile = VmanMiddleWare.getInstance().getPQCtrl().sync3dlutDataFile(f2172b, f2173c + "/3dlut.bin");
            b();
            return zSync3dlutDataFile;
        }
        d.a aVarA = b.c.d.d.d.a("cp " + f2172b + ' ' + f2173c);
        d.a aVarA2 = b.c.d.d.d.a("sync");
        b();
        if (aVarA.f1514a == 0 && aVarA2.f1514a == 0) {
            return true;
        }
        return z;
    }
}
