Rabbit-R1/switch port/java/sources/com/google/zxing/RGBLuminanceSource.java
2024-05-21 17:08:36 -04:00

81 lines
2.7 KiB
Java

package com.google.zxing;
/* loaded from: classes3.dex */
public final class RGBLuminanceSource extends LuminanceSource {
private final int dataHeight;
private final int dataWidth;
private final int left;
private final byte[] luminances;
private final int top;
@Override // com.google.zxing.LuminanceSource
public boolean isCropSupported() {
return true;
}
public RGBLuminanceSource(int i, int i2, int[] iArr) {
super(i, i2);
this.dataWidth = i;
this.dataHeight = i2;
this.left = 0;
this.top = 0;
int i3 = i * i2;
this.luminances = new byte[i3];
for (int i4 = 0; i4 < i3; i4++) {
int i5 = iArr[i4];
this.luminances[i4] = (byte) (((((i5 >> 16) & 255) + ((i5 >> 7) & 510)) + (i5 & 255)) / 4);
}
}
private RGBLuminanceSource(byte[] bArr, int i, int i2, int i3, int i4, int i5, int i6) {
super(i5, i6);
if (i5 + i3 > i || i6 + i4 > i2) {
throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
}
this.luminances = bArr;
this.dataWidth = i;
this.dataHeight = i2;
this.left = i3;
this.top = i4;
}
@Override // com.google.zxing.LuminanceSource
public byte[] getRow(int i, byte[] bArr) {
if (i < 0 || i >= getHeight()) {
throw new IllegalArgumentException("Requested row is outside the image: ".concat(String.valueOf(i)));
}
int width = getWidth();
if (bArr == null || bArr.length < width) {
bArr = new byte[width];
}
System.arraycopy(this.luminances, ((i + this.top) * this.dataWidth) + this.left, bArr, 0, width);
return bArr;
}
@Override // com.google.zxing.LuminanceSource
public byte[] getMatrix() {
int width = getWidth();
int height = getHeight();
int i = this.dataWidth;
if (width == i && height == this.dataHeight) {
return this.luminances;
}
int i2 = width * height;
byte[] bArr = new byte[i2];
int i3 = (this.top * i) + this.left;
if (width == i) {
System.arraycopy(this.luminances, i3, bArr, 0, i2);
return bArr;
}
for (int i4 = 0; i4 < height; i4++) {
System.arraycopy(this.luminances, i3, bArr, i4 * width, width);
i3 += this.dataWidth;
}
return bArr;
}
@Override // com.google.zxing.LuminanceSource
public LuminanceSource crop(int i, int i2, int i3, int i4) {
return new RGBLuminanceSource(this.luminances, this.dataWidth, this.dataHeight, this.left + i, this.top + i2, i3, i4);
}
}