-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
library/src/main/java/com/bumptech/glide/load/resource/bitmap/GranularRoundedCorners.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.bumptech.glide.load.resource.bitmap; | ||
|
||
import android.graphics.Bitmap; | ||
import androidx.annotation.NonNull; | ||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; | ||
import com.bumptech.glide.util.Util; | ||
import java.nio.ByteBuffer; | ||
import java.security.MessageDigest; | ||
|
||
/** A {@link BitmapTransformation} which has a different raddius for each corner of a bitmap. */ | ||
public final class GranularRoundedCorners extends BitmapTransformation { | ||
private static final String ID = "com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners"; | ||
private static final byte[] ID_BYTES = ID.getBytes(CHARSET); | ||
|
||
private final float topLeft; | ||
private final float topRight; | ||
private final float bottomRight; | ||
private final float bottomLeft; | ||
|
||
/** Provide the radii to round the corners of the bitmap. */ | ||
public GranularRoundedCorners( | ||
float topLeft, float topRight, float bottomRight, float bottomLeft) { | ||
this.topLeft = topLeft; | ||
this.topRight = topRight; | ||
this.bottomRight = bottomRight; | ||
this.bottomLeft = bottomLeft; | ||
} | ||
|
||
@Override | ||
protected Bitmap transform( | ||
@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { | ||
return TransformationUtils.roundedCorners( | ||
pool, toTransform, topLeft, topRight, bottomRight, bottomLeft); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o instanceof GranularRoundedCorners) { | ||
GranularRoundedCorners other = (GranularRoundedCorners) o; | ||
return topLeft == other.topLeft | ||
&& topRight == other.topRight | ||
&& bottomRight == other.bottomRight | ||
&& bottomLeft == other.bottomLeft; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hashCode = Util.hashCode(ID.hashCode(), Util.hashCode(topLeft)); | ||
hashCode = Util.hashCode(topRight, hashCode); | ||
hashCode = Util.hashCode(bottomRight, hashCode); | ||
return Util.hashCode(bottomLeft, hashCode); | ||
} | ||
|
||
@Override | ||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { | ||
messageDigest.update(ID_BYTES); | ||
|
||
byte[] radiusData = | ||
ByteBuffer.allocate(16) | ||
.putFloat(topLeft) | ||
.putFloat(topRight) | ||
.putFloat(bottomRight) | ||
.putFloat(bottomLeft) | ||
.array(); | ||
messageDigest.update(radiusData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters