package com.google.android.gms.vision.face; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Color; import android.util.SparseArray; import com.google.android.gms.internal.vision.zzn; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.vision.Detector; import com.google.android.gms.vision.Frame; import com.google.android.gms.vision.face.internal.client.zze; import com.google.android.gms.vision.zzc; import java.nio.ByteBuffer; import java.util.HashSet; /* loaded from: classes2.dex */ public final class FaceDetector extends Detector { public static final int ACCURATE_MODE = 1; public static final int ALL_CLASSIFICATIONS = 1; public static final int ALL_LANDMARKS = 1; public static final int CONTOUR_LANDMARKS = 2; public static final int FAST_MODE = 0; public static final int NO_CLASSIFICATIONS = 0; public static final int NO_LANDMARKS = 0; public static final int SELFIE_MODE = 2; private final Object lock; private final zzc zzcj; private final com.google.android.gms.vision.face.internal.client.zzc zzck; private boolean zzcl; @Override // com.google.android.gms.vision.Detector public final void release() { super.release(); synchronized (this.lock) { if (this.zzcl) { this.zzck.zzp(); this.zzcl = false; } } } protected final void finalize() throws Throwable { try { synchronized (this.lock) { if (this.zzcl) { release(); } } } finally { super.finalize(); } } /* loaded from: classes2.dex */ public static class Builder { private final Context zze; private int landmarkType = 0; private boolean zzcm = false; private int zzcn = 0; private boolean trackingEnabled = true; private int mode = 0; private float proportionalMinFaceSize = -1.0f; public Builder(Context context) { this.zze = context; } public Builder setLandmarkType(int i) { if (i == 0 || i == 1 || i == 2) { this.landmarkType = i; return this; } StringBuilder sb = new StringBuilder(34); sb.append("Invalid landmark type: "); sb.append(i); throw new IllegalArgumentException(sb.toString()); } public Builder setClassificationType(int i) { if (i == 0 || i == 1) { this.zzcn = i; return this; } StringBuilder sb = new StringBuilder(40); sb.append("Invalid classification type: "); sb.append(i); throw new IllegalArgumentException(sb.toString()); } public Builder setMode(int i) { if (i == 0 || i == 1 || i == 2) { this.mode = i; return this; } StringBuilder sb = new StringBuilder(25); sb.append("Invalid mode: "); sb.append(i); throw new IllegalArgumentException(sb.toString()); } public Builder setMinFaceSize(float f) { if (f >= BitmapDescriptorFactory.HUE_RED && f <= 1.0f) { this.proportionalMinFaceSize = f; return this; } StringBuilder sb = new StringBuilder(47); sb.append("Invalid proportional face size: "); sb.append(f); throw new IllegalArgumentException(sb.toString()); } public FaceDetector build() { zze zzeVar = new zze(); zzeVar.mode = this.mode; zzeVar.landmarkType = this.landmarkType; zzeVar.zzcn = this.zzcn; zzeVar.zzcm = this.zzcm; zzeVar.trackingEnabled = this.trackingEnabled; zzeVar.proportionalMinFaceSize = this.proportionalMinFaceSize; if (!FaceDetector.zza(zzeVar)) { throw new IllegalArgumentException("Invalid build options"); } return new FaceDetector(new com.google.android.gms.vision.face.internal.client.zzc(this.zze, zzeVar)); } public Builder setTrackingEnabled(boolean z) { this.trackingEnabled = z; return this; } public Builder setProminentFaceOnly(boolean z) { this.zzcm = z; return this; } } @Override // com.google.android.gms.vision.Detector public final SparseArray detect(Frame frame) { ByteBuffer grayscaleImageData; Face[] zzb; if (frame == null) { throw new IllegalArgumentException("No frame supplied."); } if (frame.getBitmap() != null) { Bitmap bitmap = frame.getBitmap(); int width = bitmap.getWidth(); int height = bitmap.getHeight(); int i = width * height; grayscaleImageData = ByteBuffer.allocateDirect(((((width + 1) / 2) * ((height + 1) / 2)) << 1) + i); int i2 = i; for (int i3 = 0; i3 < i; i3++) { int i4 = i3 % width; int i5 = i3 / width; int pixel = bitmap.getPixel(i4, i5); float red = Color.red(pixel); float green = Color.green(pixel); float blue = Color.blue(pixel); grayscaleImageData.put(i3, (byte) ((0.299f * red) + (0.587f * green) + (0.114f * blue))); if (i5 % 2 == 0 && i4 % 2 == 0) { grayscaleImageData.put(i2, (byte) (((-0.169f) * red) + ((-0.331f) * green) + (blue * 0.5f) + 128.0f)); grayscaleImageData.put(i2 + 1, (byte) ((red * 0.5f) + (green * (-0.419f)) + (blue * (-0.081f)) + 128.0f)); i2 += 2; } } } else { grayscaleImageData = frame.getGrayscaleImageData(); } synchronized (this.lock) { if (!this.zzcl) { throw new RuntimeException("Cannot use detector after release()"); } zzb = this.zzck.zzb(grayscaleImageData, zzn.zzc(frame)); } HashSet hashSet = new HashSet(); SparseArray sparseArray = new SparseArray<>(zzb.length); int i6 = 0; for (Face face : zzb) { int id = face.getId(); i6 = Math.max(i6, id); if (hashSet.contains(Integer.valueOf(id))) { id = i6 + 1; i6 = id; } hashSet.add(Integer.valueOf(id)); sparseArray.append(this.zzcj.zzb(id), face); } return sparseArray; } @Override // com.google.android.gms.vision.Detector public final boolean setFocus(int i) { boolean zzd; int zzc = this.zzcj.zzc(i); synchronized (this.lock) { if (!this.zzcl) { throw new RuntimeException("Cannot use detector after release()"); } zzd = this.zzck.zzd(zzc); } return zzd; } @Override // com.google.android.gms.vision.Detector public final boolean isOperational() { return this.zzck.isOperational(); } private FaceDetector() { this.zzcj = new zzc(); this.lock = new Object(); this.zzcl = true; throw new IllegalStateException("Default constructor called"); } private FaceDetector(com.google.android.gms.vision.face.internal.client.zzc zzcVar) { this.zzcj = new zzc(); this.lock = new Object(); this.zzcl = true; this.zzck = zzcVar; } /* JADX INFO: Access modifiers changed from: private */ public static boolean zza(zze zzeVar) { boolean z = zzeVar.mode == 2 || zzeVar.landmarkType != 2; if (zzeVar.landmarkType == 2 && zzeVar.zzcn == 1) { return false; } return z; } }