407 lines
14 KiB
Java
407 lines
14 KiB
Java
package androidx.constraintlayout.utils.widget;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.ColorMatrix;
|
|
import android.graphics.ColorMatrixColorFilter;
|
|
import android.graphics.Outline;
|
|
import android.graphics.Path;
|
|
import android.graphics.RectF;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.graphics.drawable.LayerDrawable;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
import android.view.ViewOutlineProvider;
|
|
import android.widget.ImageView;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.appcompat.widget.AppCompatImageView;
|
|
import androidx.constraintlayout.widget.R;
|
|
public class ImageFilterView extends AppCompatImageView {
|
|
private float mCrossfade = 0.0f;
|
|
private ImageMatrix mImageMatrix = new ImageMatrix();
|
|
public LayerDrawable mLayer;
|
|
public Drawable[] mLayers;
|
|
private boolean mOverlay = true;
|
|
private Path mPath;
|
|
public RectF mRect;
|
|
private float mRound = Float.NaN;
|
|
private float mRoundPercent = 0.0f;
|
|
public ViewOutlineProvider mViewOutlineProvider;
|
|
|
|
/* renamed from: androidx.constraintlayout.utils.widget.ImageFilterView$1 reason: invalid class name */
|
|
public class AnonymousClass1 extends ViewOutlineProvider {
|
|
public AnonymousClass1() {
|
|
}
|
|
|
|
@Override // android.view.ViewOutlineProvider
|
|
public void getOutline(View view, Outline outline) {
|
|
int width = ImageFilterView.this.getWidth();
|
|
int height = ImageFilterView.this.getHeight();
|
|
outline.setRoundRect(0, 0, width, height, (ImageFilterView.access$000(ImageFilterView.this) * ((float) Math.min(width, height))) / 2.0f);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.constraintlayout.utils.widget.ImageFilterView$2 reason: invalid class name */
|
|
public class AnonymousClass2 extends ViewOutlineProvider {
|
|
public AnonymousClass2() {
|
|
}
|
|
|
|
@Override // android.view.ViewOutlineProvider
|
|
public void getOutline(View view, Outline outline) {
|
|
outline.setRoundRect(0, 0, ImageFilterView.this.getWidth(), ImageFilterView.this.getHeight(), ImageFilterView.access$100(ImageFilterView.this));
|
|
}
|
|
}
|
|
|
|
public static class ImageMatrix {
|
|
public float[] m = new float[20];
|
|
public float mBrightness = 1.0f;
|
|
public ColorMatrix mColorMatrix = new ColorMatrix();
|
|
public float mContrast = 1.0f;
|
|
public float mSaturation = 1.0f;
|
|
public ColorMatrix mTmpColorMatrix = new ColorMatrix();
|
|
public float mWarmth = 1.0f;
|
|
|
|
private void brightness(float f) {
|
|
float[] fArr = this.m;
|
|
fArr[0] = f;
|
|
fArr[1] = 0.0f;
|
|
fArr[2] = 0.0f;
|
|
fArr[3] = 0.0f;
|
|
fArr[4] = 0.0f;
|
|
fArr[5] = 0.0f;
|
|
fArr[6] = f;
|
|
fArr[7] = 0.0f;
|
|
fArr[8] = 0.0f;
|
|
fArr[9] = 0.0f;
|
|
fArr[10] = 0.0f;
|
|
fArr[11] = 0.0f;
|
|
fArr[12] = f;
|
|
fArr[13] = 0.0f;
|
|
fArr[14] = 0.0f;
|
|
fArr[15] = 0.0f;
|
|
fArr[16] = 0.0f;
|
|
fArr[17] = 0.0f;
|
|
fArr[18] = 1.0f;
|
|
fArr[19] = 0.0f;
|
|
}
|
|
|
|
private void saturation(float f) {
|
|
float f2 = 1.0f - f;
|
|
float f3 = 0.2999f * f2;
|
|
float f4 = 0.587f * f2;
|
|
float f5 = f2 * 0.114f;
|
|
float[] fArr = this.m;
|
|
fArr[0] = f3 + f;
|
|
fArr[1] = f4;
|
|
fArr[2] = f5;
|
|
fArr[3] = 0.0f;
|
|
fArr[4] = 0.0f;
|
|
fArr[5] = f3;
|
|
fArr[6] = f4 + f;
|
|
fArr[7] = f5;
|
|
fArr[8] = 0.0f;
|
|
fArr[9] = 0.0f;
|
|
fArr[10] = f3;
|
|
fArr[11] = f4;
|
|
fArr[12] = f5 + f;
|
|
fArr[13] = 0.0f;
|
|
fArr[14] = 0.0f;
|
|
fArr[15] = 0.0f;
|
|
fArr[16] = 0.0f;
|
|
fArr[17] = 0.0f;
|
|
fArr[18] = 1.0f;
|
|
fArr[19] = 0.0f;
|
|
}
|
|
|
|
private void warmth(float f) {
|
|
float f2;
|
|
float f3;
|
|
if (f <= 0.0f) {
|
|
f = 0.01f;
|
|
}
|
|
float f4 = (5000.0f / f) / 100.0f;
|
|
if (f4 > 66.0f) {
|
|
double d = (double) (f4 - 60.0f);
|
|
f3 = ((float) Math.pow(d, -0.13320475816726685d)) * 329.69873f;
|
|
f2 = ((float) Math.pow(d, 0.07551484555006027d)) * 288.12216f;
|
|
} else {
|
|
f2 = (((float) Math.log((double) f4)) * 99.4708f) - 161.11957f;
|
|
f3 = 255.0f;
|
|
}
|
|
float log = f4 < 66.0f ? f4 > 19.0f ? (((float) Math.log((double) (f4 - 10.0f))) * 138.51773f) - 305.0448f : 0.0f : 255.0f;
|
|
float min = Math.min(255.0f, Math.max(f3, 0.0f));
|
|
float min2 = Math.min(255.0f, Math.max(f2, 0.0f));
|
|
float min3 = Math.min(255.0f, Math.max(log, 0.0f));
|
|
float min4 = Math.min(255.0f, Math.max(255.0f, 0.0f));
|
|
float min5 = Math.min(255.0f, Math.max((((float) Math.log((double) 50.0f)) * 99.4708f) - 161.11957f, 0.0f));
|
|
float min6 = min3 / Math.min(255.0f, Math.max((((float) Math.log((double) 40.0f)) * 138.51773f) - 305.0448f, 0.0f));
|
|
float[] fArr = this.m;
|
|
fArr[0] = min / min4;
|
|
fArr[1] = 0.0f;
|
|
fArr[2] = 0.0f;
|
|
fArr[3] = 0.0f;
|
|
fArr[4] = 0.0f;
|
|
fArr[5] = 0.0f;
|
|
fArr[6] = min2 / min5;
|
|
fArr[7] = 0.0f;
|
|
fArr[8] = 0.0f;
|
|
fArr[9] = 0.0f;
|
|
fArr[10] = 0.0f;
|
|
fArr[11] = 0.0f;
|
|
fArr[12] = min6;
|
|
fArr[13] = 0.0f;
|
|
fArr[14] = 0.0f;
|
|
fArr[15] = 0.0f;
|
|
fArr[16] = 0.0f;
|
|
fArr[17] = 0.0f;
|
|
fArr[18] = 1.0f;
|
|
fArr[19] = 0.0f;
|
|
}
|
|
|
|
public void updateMatrix(ImageView imageView) {
|
|
boolean z2;
|
|
this.mColorMatrix.reset();
|
|
float f = this.mSaturation;
|
|
boolean z3 = true;
|
|
if (f != 1.0f) {
|
|
saturation(f);
|
|
this.mColorMatrix.set(this.m);
|
|
z2 = true;
|
|
} else {
|
|
z2 = false;
|
|
}
|
|
float f2 = this.mContrast;
|
|
if (f2 != 1.0f) {
|
|
this.mTmpColorMatrix.setScale(f2, f2, f2, 1.0f);
|
|
this.mColorMatrix.postConcat(this.mTmpColorMatrix);
|
|
z2 = true;
|
|
}
|
|
float f3 = this.mWarmth;
|
|
if (f3 != 1.0f) {
|
|
warmth(f3);
|
|
this.mTmpColorMatrix.set(this.m);
|
|
this.mColorMatrix.postConcat(this.mTmpColorMatrix);
|
|
z2 = true;
|
|
}
|
|
float f4 = this.mBrightness;
|
|
if (f4 != 1.0f) {
|
|
brightness(f4);
|
|
this.mTmpColorMatrix.set(this.m);
|
|
this.mColorMatrix.postConcat(this.mTmpColorMatrix);
|
|
} else {
|
|
z3 = z2;
|
|
}
|
|
if (z3) {
|
|
imageView.setColorFilter(new ColorMatrixColorFilter(this.mColorMatrix));
|
|
} else {
|
|
imageView.clearColorFilter();
|
|
}
|
|
}
|
|
}
|
|
|
|
public ImageFilterView(Context context) {
|
|
super(context);
|
|
init(context, null);
|
|
}
|
|
|
|
public ImageFilterView(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
init(context, attributeSet);
|
|
}
|
|
|
|
public ImageFilterView(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
init(context, attributeSet);
|
|
}
|
|
|
|
public static /* synthetic */ float access$000(ImageFilterView imageFilterView) {
|
|
return imageFilterView.mRoundPercent;
|
|
}
|
|
|
|
public static /* synthetic */ float access$100(ImageFilterView imageFilterView) {
|
|
return imageFilterView.mRound;
|
|
}
|
|
|
|
private void init(Context context, AttributeSet attributeSet) {
|
|
if (attributeSet != null) {
|
|
TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, R.styleable.ImageFilterView);
|
|
int indexCount = obtainStyledAttributes.getIndexCount();
|
|
Drawable drawable = obtainStyledAttributes.getDrawable(R.styleable.ImageFilterView_altSrc);
|
|
for (int i = 0; i < indexCount; i++) {
|
|
int index = obtainStyledAttributes.getIndex(i);
|
|
if (index == R.styleable.ImageFilterView_crossfade) {
|
|
this.mCrossfade = obtainStyledAttributes.getFloat(index, 0.0f);
|
|
} else if (index == R.styleable.ImageFilterView_warmth) {
|
|
setWarmth(obtainStyledAttributes.getFloat(index, 0.0f));
|
|
} else if (index == R.styleable.ImageFilterView_saturation) {
|
|
setSaturation(obtainStyledAttributes.getFloat(index, 0.0f));
|
|
} else if (index == R.styleable.ImageFilterView_contrast) {
|
|
setContrast(obtainStyledAttributes.getFloat(index, 0.0f));
|
|
} else if (index == R.styleable.ImageFilterView_round) {
|
|
setRound(obtainStyledAttributes.getDimension(index, 0.0f));
|
|
} else if (index == R.styleable.ImageFilterView_roundPercent) {
|
|
setRoundPercent(obtainStyledAttributes.getFloat(index, 0.0f));
|
|
} else if (index == R.styleable.ImageFilterView_overlay) {
|
|
setOverlay(obtainStyledAttributes.getBoolean(index, this.mOverlay));
|
|
}
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
if (drawable != null) {
|
|
Drawable[] drawableArr = new Drawable[2];
|
|
this.mLayers = drawableArr;
|
|
drawableArr[0] = getDrawable();
|
|
this.mLayers[1] = drawable;
|
|
LayerDrawable layerDrawable = new LayerDrawable(this.mLayers);
|
|
this.mLayer = layerDrawable;
|
|
layerDrawable.getDrawable(1).setAlpha((int) (this.mCrossfade * 255.0f));
|
|
super.setImageDrawable(this.mLayer);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void setOverlay(boolean z2) {
|
|
this.mOverlay = z2;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void draw(Canvas canvas) {
|
|
super.draw(canvas);
|
|
if (0 != 0) {
|
|
canvas.restore();
|
|
}
|
|
}
|
|
|
|
public float getBrightness() {
|
|
return this.mImageMatrix.mBrightness;
|
|
}
|
|
|
|
public float getContrast() {
|
|
return this.mImageMatrix.mContrast;
|
|
}
|
|
|
|
public float getCrossfade() {
|
|
return this.mCrossfade;
|
|
}
|
|
|
|
public float getRound() {
|
|
return this.mRound;
|
|
}
|
|
|
|
public float getRoundPercent() {
|
|
return this.mRoundPercent;
|
|
}
|
|
|
|
public float getSaturation() {
|
|
return this.mImageMatrix.mSaturation;
|
|
}
|
|
|
|
public float getWarmth() {
|
|
return this.mImageMatrix.mWarmth;
|
|
}
|
|
|
|
public void setBrightness(float f) {
|
|
ImageMatrix imageMatrix = this.mImageMatrix;
|
|
imageMatrix.mBrightness = f;
|
|
imageMatrix.updateMatrix(this);
|
|
}
|
|
|
|
public void setContrast(float f) {
|
|
ImageMatrix imageMatrix = this.mImageMatrix;
|
|
imageMatrix.mContrast = f;
|
|
imageMatrix.updateMatrix(this);
|
|
}
|
|
|
|
public void setCrossfade(float f) {
|
|
this.mCrossfade = f;
|
|
if (this.mLayers != null) {
|
|
if (!this.mOverlay) {
|
|
this.mLayer.getDrawable(0).setAlpha((int) ((1.0f - this.mCrossfade) * 255.0f));
|
|
}
|
|
this.mLayer.getDrawable(1).setAlpha((int) (this.mCrossfade * 255.0f));
|
|
super.setImageDrawable(this.mLayer);
|
|
}
|
|
}
|
|
|
|
@RequiresApi(21)
|
|
public void setRound(float f) {
|
|
if (Float.isNaN(f)) {
|
|
this.mRound = f;
|
|
float f2 = this.mRoundPercent;
|
|
this.mRoundPercent = -1.0f;
|
|
setRoundPercent(f2);
|
|
return;
|
|
}
|
|
boolean z2 = this.mRound != f;
|
|
this.mRound = f;
|
|
if (f != 0.0f) {
|
|
if (this.mPath == null) {
|
|
this.mPath = new Path();
|
|
}
|
|
if (this.mRect == null) {
|
|
this.mRect = new RectF();
|
|
}
|
|
if (this.mViewOutlineProvider == null) {
|
|
AnonymousClass2 r5 = new AnonymousClass2();
|
|
this.mViewOutlineProvider = r5;
|
|
setOutlineProvider(r5);
|
|
}
|
|
setClipToOutline(true);
|
|
this.mRect.set(0.0f, 0.0f, (float) getWidth(), (float) getHeight());
|
|
this.mPath.reset();
|
|
Path path = this.mPath;
|
|
RectF rectF = this.mRect;
|
|
float f3 = this.mRound;
|
|
path.addRoundRect(rectF, f3, f3, Path.Direction.CW);
|
|
} else {
|
|
setClipToOutline(false);
|
|
}
|
|
if (z2) {
|
|
invalidateOutline();
|
|
}
|
|
}
|
|
|
|
@RequiresApi(21)
|
|
public void setRoundPercent(float f) {
|
|
boolean z2 = this.mRoundPercent != f;
|
|
this.mRoundPercent = f;
|
|
if (f != 0.0f) {
|
|
if (this.mPath == null) {
|
|
this.mPath = new Path();
|
|
}
|
|
if (this.mRect == null) {
|
|
this.mRect = new RectF();
|
|
}
|
|
if (this.mViewOutlineProvider == null) {
|
|
AnonymousClass1 r6 = new AnonymousClass1();
|
|
this.mViewOutlineProvider = r6;
|
|
setOutlineProvider(r6);
|
|
}
|
|
setClipToOutline(true);
|
|
int width = getWidth();
|
|
int height = getHeight();
|
|
float min = (((float) Math.min(width, height)) * this.mRoundPercent) / 2.0f;
|
|
this.mRect.set(0.0f, 0.0f, (float) width, (float) height);
|
|
this.mPath.reset();
|
|
this.mPath.addRoundRect(this.mRect, min, min, Path.Direction.CW);
|
|
} else {
|
|
setClipToOutline(false);
|
|
}
|
|
if (z2) {
|
|
invalidateOutline();
|
|
}
|
|
}
|
|
|
|
public void setSaturation(float f) {
|
|
ImageMatrix imageMatrix = this.mImageMatrix;
|
|
imageMatrix.mSaturation = f;
|
|
imageMatrix.updateMatrix(this);
|
|
}
|
|
|
|
public void setWarmth(float f) {
|
|
ImageMatrix imageMatrix = this.mImageMatrix;
|
|
imageMatrix.mWarmth = f;
|
|
imageMatrix.updateMatrix(this);
|
|
}
|
|
}
|