|
| 1 | +package com.bumptech.glide.load.resource.bitmap; |
| 2 | + |
| 3 | +import android.graphics.Bitmap; |
| 4 | +import android.support.annotation.NonNull; |
| 5 | +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; |
| 6 | +import com.bumptech.glide.util.Util; |
| 7 | +import java.nio.ByteBuffer; |
| 8 | +import java.security.MessageDigest; |
| 9 | + |
| 10 | +/** |
| 11 | + * A {@link BitmapTransformation} which rotates the bitmap. |
| 12 | + */ |
| 13 | +public class Rotate extends BitmapTransformation { |
| 14 | + private static final String ID = "com.bumptech.glide.load.resource.bitmap.Rotate"; |
| 15 | + private static final byte[] ID_BYTES = ID.getBytes(CHARSET); |
| 16 | + |
| 17 | + private final int degreesToRotate; |
| 18 | + |
| 19 | + /** |
| 20 | + * @param degreesToRotate number of degrees to rotate the image by. If zero the original image is |
| 21 | + * not modified. |
| 22 | + */ |
| 23 | + public Rotate(int degreesToRotate) { |
| 24 | + this.degreesToRotate = degreesToRotate; |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + protected Bitmap transform( |
| 29 | + @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { |
| 30 | + return TransformationUtils.rotateImage(toTransform, degreesToRotate); |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public boolean equals(Object o) { |
| 35 | + if (o instanceof Rotate) { |
| 36 | + Rotate other = (Rotate) o; |
| 37 | + return degreesToRotate == other.degreesToRotate; |
| 38 | + } |
| 39 | + return false; |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public int hashCode() { |
| 44 | + return Util.hashCode(ID.hashCode(), |
| 45 | + Util.hashCode(degreesToRotate)); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { |
| 50 | + messageDigest.update(ID_BYTES); |
| 51 | + |
| 52 | + byte[] degreesData = ByteBuffer.allocate(4).putInt(degreesToRotate).array(); |
| 53 | + messageDigest.update(degreesData); |
| 54 | + } |
| 55 | +} |
0 commit comments