1
0
mirror of https://github.com/wasabeef/glide-transformations.git synced 2025-10-04 09:53:21 +08:00

22 Commits
2.0.1 ... 3.1.1

Author SHA1 Message Date
Daichi Furiya
9b00767304 3.1.1 (#116)
* update gradle wrapeer

* fix proguard settings

* update glide

* bump up 3.1.1
2018-02-13 16:32:10 +09:00
Frederic Ye
a5f7017f57 Added TV Time as application (#114) 2018-02-13 15:26:41 +09:00
wasabeef
9e85b0b759 update sample codes 2018-02-01 16:48:27 +09:00
Daichi Furiya
51f7b515fa For Glide 4.5.0 (#112) 2018-01-26 17:08:27 +09:00
CrabeMan
43f38cc4b3 Implement equals() and hashCode() methods (#105)
* Implement equals() and hashCode() methods

* Oops: Replace by static final to prevent String class name generation for every call on hashCodes() & updateDiskCacheKey() methods
2018-01-25 17:15:27 +09:00
Daichi Furiya
970afc35fe Fixed Proguard settings (#88)
* Issue #86 - Deleted a setting for DexGuard
2017-09-08 17:18:50 -07:00
Daichi Furiya
f6cbe2722d Support Glide 4.0.0 (#83) 2017-09-07 00:47:27 -05:00
wasabeef
1264e01f6e fix format 2017-03-21 11:55:30 -07:00
wasabeef
1a474cdd8c update gradle wrapper 2017-03-21 11:53:41 -07:00
wasabeef
311bcde37f Merge branch 'master' of github.com:wasabeef/glide-transformations 2017-03-17 18:35:44 -07:00
wasabeef
945e5a8063 updated icon 2017-03-17 18:35:05 -07:00
Daichi Furiya
30b41fa167 Update README.md 2017-03-17 18:29:47 -07:00
Daichi Furiya
2a720df48d Update README.md 2017-03-17 17:47:58 -07:00
wasabeef
06db3295a1 updated art 2017-03-17 17:45:28 -07:00
Daichi Furiya
34cc92f7a4 Merge pull request #66 from wasabeef/dev
2.0.2
2017-03-17 17:41:49 -07:00
wasabeef
5715d7a999 bump up 2.0.2 2017-03-17 17:35:48 -07:00
wasabeef
36c0d00ae9 updated libs 2017-03-17 17:35:29 -07:00
wasabeef
a29346e8d2 updated sdks 2017-03-17 17:20:28 -07:00
wasabeef
c3f2ce75a4 updated gradle 2017-03-17 17:19:53 -07:00
wasabeef
4d47793f79 updated copyright 2017-03-17 17:17:37 -07:00
Daichi Furiya
45c2e3bcfe Merge pull request #45 from timusus/master
Additional resource cleanup in RSBlur
2017-03-17 15:27:20 -07:00
Tim Malseed
a139c21d31 Additional resource cleanup in RSBlur
When the blur is finished, the input, output, and blur are all destroyed, along with the renderscript instance.

This resolves a strictmode 'resource acquired but never released' violation.
2016-06-12 23:55:52 +10:00
47 changed files with 1040 additions and 833 deletions

View File

@@ -1,6 +1,57 @@
Change Log
==========
Version 3.1.1 *(2018-02-13)*
----------------------------
Update:
- Glide 4.5.0 -> 4.6.1
Bug Fix:
- Fix settings fot proguard.
Version 3.1.0 *(2018-01-26)*
----------------------------
Update:
- Compile & Target SDK Version 25 -> 27
- Build Tools 26.0.1 -> 27.0.3
- Support Library 25.3.1 -> 27.0.2
- Glide 4.0.0 -> 4.5.0
Bug Fix:
- [Implement equals() and hashCode() methods #105](https://github.com/wasabeef/glide-transformations/pull/105)
- Use RenderScript#releaseAllContexts
Version 3.0.1 *(2017-09-08)*
----------------------------
Bug Fix:
- [Deleted a setting for DexGuard #86](https://github.com/wasabeef/glide-transformations/issues/86)
Version 3.0.0 *(2017-09-06)*
----------------------------
Update:
- Build Tools 25.0.2 -> 26.0.1
- Min SDK Version 11 -> 14
- Glide 3.7.0 -> 4.0.0
Feature:
- Supported Glide 4.0.0
Version 2.0.2 *(2017-03-17)*
----------------------------
Update:
- Compile & Target SDK Version 23 -> 25
- Build Tools 23.0.2 -> 25.0.2
- Support Library 23.2.1 -> 25.3.0
- GPUImage for Android 1.3.0 -> 1.4.1
Bug Fix:
- [Additional resource cleanup in RSBlur #45](https://github.com/wasabeef/glide-transformations/pull/45)
Version 2.0.1 *(2016-04-21)*
----------------------------

View File

@@ -29,13 +29,12 @@ Please feel free to use this.
```groovy
repositories {
jcenter()
mavenCentral() // GPUImage for Android
}
dependencies {
compile 'jp.wasabeef:glide-transformations:2.0.1'
implementation 'jp.wasabeef:glide-transformations:3.1.1'
// If you want to use the GPU Filters
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
implementation 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
}
```
@@ -45,8 +44,8 @@ Set Glide Transform.
```java
Glide.with(this).load(R.drawable.demo)
.bitmapTransform(new BlurTransformation(context))
.into((ImageView) findViewById(R.id.image));
.apply(bitmapTransform(new BlurTransformation(25)))
.into((ImageView) findViewById(R.id.image));
```
## Advanced Step 3
@@ -54,8 +53,11 @@ Glide.with(this).load(R.drawable.demo)
You can set a multiple transformations.
```java
MultiTransformation multi = new MultiTransformation(
new BlurTransformation(25),
new RoundedCornersTransformation(128, 0, RoundedCornersTransformation.CornerType.BOTTOM))))
Glide.with(this).load(R.drawable.demo)
.bitmapTransform(new BlurTransformation(context, 25), new CropCircleTransformation(context))
.apply(bitmapTransform(multi))
.into((ImageView) findViewById(R.id.image));
```
@@ -91,6 +93,8 @@ Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you w
Icon | Application
------------ | -------------
<img src="https://lh6.ggpht.com/6zKH_uQY1bxCwXL4DLo_uoFEOXdShi3BgmN6XRHlaJ-oA1svmq6y1PZkmO50nWQn2Lg=w300-rw" width="48" height="48" /> | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid)
<img src="https://lh3.googleusercontent.com/ZOrekp-ho-ecWG1TyvuOs0LoB5M4QYWCCLS5lFbAHhp_SklSd06544ENG3uC97zGWes=w300-rw" width="48" height="48" /> | [AbemaTV](https://play.google.com/store/apps/details?id=tv.abema)
<img src="https://lh3.googleusercontent.com/eikxMAKKMU2O-rV-oUg04dGp-O4Aoje91kffDlnCB_3DCIPDzzADxdBOdPCW18Lmqw=w300-rw" width="48" height="48" /> | [TV Time](https://play.google.com/store/apps/details?id=com.tozelabs.tvshowtime)
Developed By
-------
@@ -119,7 +123,7 @@ Thanks
License
-------
Copyright 2015 Wasabeef
Copyright 2018 Wasabeef
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 MiB

After

Width:  |  Height:  |  Size: 3.9 MiB

View File

@@ -3,15 +3,17 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.novoda:bintray-release:0.3.4'
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.novoda:bintray-release:0.8.0'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}

View File

@@ -28,6 +28,9 @@ android {
release {
debuggable false
zipAlignEnabled true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
shrinkResources true
signingConfig signingConfigs.release
}
}
@@ -50,9 +53,11 @@ def getKeyAliasPasswordProperty() {
}
dependencies {
compile project(':transformations')
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
compile "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
compile "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}"
implementation project(':transformations')
implementation "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
implementation "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
implementation "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
implementation "com.android.support:recyclerview-v7:${SUPPORT_PACKAGE_VERSION}"
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta4'
}

0
example/proguard-rules.pro vendored Normal file
View File

View File

@@ -2,7 +2,7 @@ package jp.wasabeef.example.glide;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
@@ -15,7 +15,7 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
recyclerView.setLayoutManager(new LinearLayoutManager(this));
List<Type> dataSet = new ArrayList<>();
dataSet.add(Type.Mask);

View File

@@ -10,6 +10,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import java.util.List;
import jp.wasabeef.glide.transformations.BlurTransformation;
@@ -17,6 +18,7 @@ import jp.wasabeef.glide.transformations.ColorFilterTransformation;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
import jp.wasabeef.glide.transformations.CropSquareTransformation;
import jp.wasabeef.glide.transformations.CropTransformation;
import jp.wasabeef.glide.transformations.CropTransformation.CropType;
import jp.wasabeef.glide.transformations.GrayscaleTransformation;
import jp.wasabeef.glide.transformations.MaskTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
@@ -31,13 +33,16 @@ import jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation;
import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation;
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
import static com.bumptech.glide.request.RequestOptions.overrideOf;
/**
* Created by Wasabeef on 2015/01/11.
*/
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
private Context mContext;
private List<Type> mDataSet;
private Context context;
private List<Type> dataSet;
enum Type {
Mask,
@@ -64,165 +69,168 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
}
public MainAdapter(Context context, List<Type> dataSet) {
mContext = context;
mDataSet = dataSet;
this.context = context;
this.dataSet = dataSet;
}
@Override public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mContext).inflate(R.layout.layout_list_item, parent, false);
View v = LayoutInflater.from(context).inflate(R.layout.layout_list_item, parent, false);
return new ViewHolder(v);
}
@Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
switch (mDataSet.get(position)) {
switch (dataSet.get(position)) {
case Mask: {
int width = Utils.dip2px(mContext, 133.33f);
int height = Utils.dip2px(mContext, 126.33f);
Glide.with(mContext)
int width = Utils.dip2px(context, 266.66f);
int height = Utils.dip2px(context, 252.66f);
Glide.with(context)
.load(R.drawable.check)
.override(width, height)
.bitmapTransform(new CenterCrop(mContext),
new MaskTransformation(mContext, R.drawable.mask_starfish))
.apply(overrideOf(width, height))
.apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(),
new MaskTransformation(R.drawable.mask_starfish))))
.into(holder.image);
break;
}
case NinePatchMask: {
int width = Utils.dip2px(mContext, 150.0f);
int height = Utils.dip2px(mContext, 100.0f);
Glide.with(mContext)
int width = Utils.dip2px(context, 300.0f);
int height = Utils.dip2px(context, 200.0f);
Glide.with(context)
.load(R.drawable.check)
.override(width, height)
.bitmapTransform(new CenterCrop(mContext),
new MaskTransformation(mContext, R.drawable.mask_chat_right))
.apply(overrideOf(width, height))
.apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(),
new MaskTransformation(R.drawable.mask_chat_right))))
.into(holder.image);
break;
}
case CropTop:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.demo)
.bitmapTransform(
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP))
.apply(bitmapTransform(
new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100),
CropType.TOP)))
.into(holder.image);
break;
case CropCenter:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.demo)
.bitmapTransform(new CropTransformation(mContext, 300, 100))
.apply(bitmapTransform(
new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100), CropType.CENTER)))
.into(holder.image);
break;
case CropBottom:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.demo)
.bitmapTransform(
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM))
.apply(bitmapTransform(
new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100),
CropType.BOTTOM)))
.into(holder.image);
break;
case CropSquare:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.demo)
.bitmapTransform(new CropSquareTransformation(mContext))
.apply(bitmapTransform(new CropSquareTransformation()))
.into(holder.image);
break;
case CropCircle:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.demo)
.bitmapTransform(new CropCircleTransformation(mContext))
.apply(bitmapTransform(new CropCircleTransformation()))
.into(holder.image);
break;
case ColorFilter:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.demo)
.bitmapTransform(new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0)))
.apply(bitmapTransform(new ColorFilterTransformation(Color.argb(80, 255, 0, 0))))
.into(holder.image);
break;
case Grayscale:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.demo)
.bitmapTransform(new GrayscaleTransformation(mContext))
.apply(bitmapTransform(new GrayscaleTransformation()))
.into(holder.image);
break;
case RoundedCorners:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.demo)
.bitmapTransform(new RoundedCornersTransformation(mContext, 30, 0,
RoundedCornersTransformation.CornerType.BOTTOM))
.apply(bitmapTransform(new RoundedCornersTransformation(45, 0,
RoundedCornersTransformation.CornerType.BOTTOM)))
.into(holder.image);
break;
case Blur:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.check)
.bitmapTransform(new BlurTransformation(mContext, 25))
.apply(bitmapTransform(new BlurTransformation(25)))
.into(holder.image);
break;
case Toon:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.demo)
.bitmapTransform(new ToonFilterTransformation(mContext))
.apply(bitmapTransform(new ToonFilterTransformation()))
.into(holder.image);
break;
case Sepia:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.check)
.bitmapTransform(new SepiaFilterTransformation(mContext))
.apply(bitmapTransform(new SepiaFilterTransformation()))
.into(holder.image);
break;
case Contrast:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.check)
.bitmapTransform(new ContrastFilterTransformation(mContext, 2.0f))
.apply(bitmapTransform(new ContrastFilterTransformation(2.0f)))
.into(holder.image);
break;
case Invert:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.check)
.bitmapTransform(new InvertFilterTransformation(mContext))
.apply(bitmapTransform(new InvertFilterTransformation()))
.into(holder.image);
break;
case Pixel:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.check)
.bitmapTransform(new PixelationFilterTransformation(mContext, 20))
.apply(bitmapTransform(new PixelationFilterTransformation(20)))
.into(holder.image);
break;
case Sketch:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.check)
.bitmapTransform(new SketchFilterTransformation(mContext))
.apply(bitmapTransform(new SketchFilterTransformation()))
.into(holder.image);
break;
case Swirl:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.check)
.bitmapTransform(
new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f)))
.apply(bitmapTransform(
new SwirlFilterTransformation(0.5f, 1.0f, new PointF(0.5f, 0.5f))).dontAnimate())
.into(holder.image);
break;
case Brightness:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.check)
.bitmapTransform(new BrightnessFilterTransformation(mContext, 0.5f))
.apply(bitmapTransform(new BrightnessFilterTransformation(0.5f)).dontAnimate())
.into(holder.image);
break;
case Kuawahara:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.check)
.bitmapTransform(new KuwaharaFilterTransformation(mContext, 25))
.apply(bitmapTransform(new KuwaharaFilterTransformation(25)).dontAnimate())
.into(holder.image);
break;
case Vignette:
Glide.with(mContext)
Glide.with(context)
.load(R.drawable.check)
.bitmapTransform(new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f))
.apply(bitmapTransform(new VignetteFilterTransformation(new PointF(0.5f, 0.5f),
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f)).dontAnimate())
.into(holder.image);
break;
}
holder.title.setText(mDataSet.get(position).name());
holder.title.setText(dataSet.get(position).name());
}
@Override public int getItemCount() {
return mDataSet.size();
return dataSet.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.example.glide;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@@ -1,15 +1,22 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CC000000"
tools:context=".MainActivity"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>

View File

@@ -1,26 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:contentDescription="@null"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:cropToPadding="false"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textColor="@android:color/white"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

View File

@@ -3,6 +3,9 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
</resources>

View File

@@ -1,11 +1,11 @@
VERSION_NAME=2.0.1
VERSION_NAME=3.1.1
GROUP=jp.wasabeef
ARTIFACT_ID=glide-transformations
COMPILE_SDK_VERSION=23
BUILD_TOOLS_VERSION=23.0.2
TARGET_SDK_VERSION=23
MIN_SDK_VERSION=11
COMPILE_SDK_VERSION=27
BUILD_TOOLS_VERSION=27.0.3
TARGET_SDK_VERSION=27
MIN_SDK_VERSION=14
POM_DESCRIPTION=which provides simple Tranformations to Glide
POM_URL=https://github.com/wasabeef/glide-transformations
@@ -21,6 +21,6 @@ POM_DEVELOPER_EMAIL=dadadada.chop@gmail.com
POM_DEVELOPER_URL=wasabeef.jp
ISSUE_URL=https://github.com/wasabeef/glide-transformations/issues
SUPPORT_PACKAGE_VERSION=23.2.1
GLIDE_VERSION=3.7.0
GPUIMAGE_VERSION=1.3.0
SUPPORT_PACKAGE_VERSION=27.0.2
GLIDE_VERSION=4.6.1
GPUIMAGE_VERSION=1.4.1

Binary file not shown.

View File

@@ -1,7 +1,5 @@
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-bin.zip

110
gradlew vendored
View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
##############################################################################
##
@@ -6,47 +6,6 @@
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
@@ -61,9 +20,49 @@ while [ -h "$PRG" ] ; do
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@@ -90,7 +89,7 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -114,6 +113,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
@@ -154,11 +154,19 @@ if $cygwin ; then
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

14
gradlew.bat vendored
View File

@@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
@@ -46,10 +46,9 @@ echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
@@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line

View File

@@ -16,28 +16,9 @@ android {
}
dependencies {
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
provided "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
implementation "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
compileOnly "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
}
publish {
@@ -47,4 +28,7 @@ publish {
publishVersion = VERSION_NAME
desc = POM_DESCRIPTION
website = POM_URL
bintrayUser = BINTRAY_USER
bintrayKey = BINTRAY_API_KEY
autoPublish = false
}

View File

@@ -1 +1,8 @@
-dontwarn jp.co.cyberagent.android.gpuimage.**
-dontwarn jp.co.cyberagent.android.gpuimage.**
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}

View File

@@ -0,0 +1,65 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2018 Wasabeef
* Copyright 2014 Google, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.util.Util;
import java.security.MessageDigest;
public abstract class BitmapTransformation implements Transformation<Bitmap> {
@Override
public final Resource<Bitmap> transform(Context context, Resource<Bitmap> resource, int outWidth,
int outHeight) {
if (!Util.isValidDimensions(outWidth, outHeight)) {
throw new IllegalArgumentException(
"Cannot apply transformation on width: " + outWidth + " or height: " + outHeight
+ " less than or equal to zero and not Target.SIZE_ORIGINAL");
}
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
Bitmap toTransform = resource.get();
int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth;
int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight;
Bitmap transformed = transform(context.getApplicationContext(), bitmapPool, toTransform, targetWidth, targetHeight);
final Resource<Bitmap> result;
if (toTransform.equals(transformed)) {
result = resource;
} else {
result = BitmapResource.obtain(transformed, bitmapPool);
}
return result;
}
protected abstract Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight);
@Override public abstract void updateDiskCacheKey(MessageDigest messageDigest);
@Override public abstract boolean equals(Object o);
@Override public abstract int hashCode();
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,86 +22,80 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.renderscript.RSRuntimeException;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import java.security.MessageDigest;
import jp.wasabeef.glide.transformations.internal.FastBlur;
import jp.wasabeef.glide.transformations.internal.RSBlur;
public class BlurTransformation implements Transformation<Bitmap> {
public class BlurTransformation extends BitmapTransformation {
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.BlurTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private static int MAX_RADIUS = 25;
private static int DEFAULT_DOWN_SAMPLING = 1;
private Context mContext;
private BitmapPool mBitmapPool;
private int radius;
private int sampling;
private int mRadius;
private int mSampling;
public BlurTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool(), MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
public BlurTransformation() {
this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
}
public BlurTransformation(Context context, BitmapPool pool) {
this(context, pool, MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
public BlurTransformation(int radius) {
this(radius, DEFAULT_DOWN_SAMPLING);
}
public BlurTransformation(Context context, BitmapPool pool, int radius) {
this(context, pool, radius, DEFAULT_DOWN_SAMPLING);
public BlurTransformation(int radius, int sampling) {
this.radius = radius;
this.sampling = sampling;
}
public BlurTransformation(Context context, int radius) {
this(context, Glide.get(context).getBitmapPool(), radius, DEFAULT_DOWN_SAMPLING);
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
public BlurTransformation(Context context, int radius, int sampling) {
this(context, Glide.get(context).getBitmapPool(), radius, sampling);
}
int width = toTransform.getWidth();
int height = toTransform.getHeight();
int scaledWidth = width / sampling;
int scaledHeight = height / sampling;
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
mContext = context.getApplicationContext();
mBitmapPool = pool;
mRadius = radius;
mSampling = sampling;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
int scaledWidth = width / mSampling;
int scaledHeight = height / mSampling;
Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
}
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(source, 0, 0, paint);
canvas.drawBitmap(toTransform, 0, 0, paint);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try {
bitmap = RSBlur.blur(mContext, bitmap, mRadius);
bitmap = RSBlur.blur(context, bitmap, radius);
} catch (RSRuntimeException e) {
bitmap = FastBlur.blur(bitmap, mRadius, true);
bitmap = FastBlur.blur(bitmap, radius, true);
}
} else {
bitmap = FastBlur.blur(bitmap, mRadius, true);
bitmap = FastBlur.blur(bitmap, radius, true);
}
return BitmapResource.obtain(bitmap, mBitmapPool);
return bitmap;
}
@Override public String getId() {
return "BlurTransformation(radius=" + mRadius + ", sampling=" + mSampling + ")";
@Override public String toString() {
return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
}
@Override public boolean equals(Object o) {
return o instanceof BlurTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,51 +22,54 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import java.security.MessageDigest;
public class ColorFilterTransformation implements Transformation<Bitmap> {
public class ColorFilterTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.ColorFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private int mColor;
private int color;
public ColorFilterTransformation(Context context, int color) {
this(Glide.get(context).getBitmapPool(), color);
public ColorFilterTransformation(int color) {
this.color = color;
}
public ColorFilterTransformation(BitmapPool pool, int color) {
mBitmapPool = pool;
mColor = color;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, config);
}
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = pool.get(width, height, config);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(source, 0, 0, paint);
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(toTransform, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
return bitmap;
}
@Override public String getId() {
return "ColorFilterTransformation(color=" + mColor + ")";
@Override public String toString() {
return "ColorFilterTransformation(color=" + color + ")";
}
@Override public boolean equals(Object o) {
return o instanceof ColorFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,61 +18,41 @@ package jp.wasabeef.glide.transformations;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
import com.bumptech.glide.request.RequestOptions;
import java.security.MessageDigest;
public class CropCircleTransformation implements Transformation<Bitmap> {
/**
* @deprecated Use {@link RequestOptions#circleCrop()}.
*/
@Deprecated
public class CropCircleTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.CropCircleTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public CropCircleTransformation(Context context) {
this(Glide.get(context).getBitmapPool());
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
return TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
}
public CropCircleTransformation(BitmapPool pool) {
this.mBitmapPool = pool;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int size = Math.min(source.getWidth(), source.getHeight());
int width = (source.getWidth() - size) / 2;
int height = (source.getHeight() - size) / 2;
Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader =
new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
if (width != 0 || height != 0) {
// source isn't square, move viewport to center
Matrix matrix = new Matrix();
matrix.setTranslate(-width, -height);
shader.setLocalMatrix(matrix);
}
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override public String getId() {
@Override public String toString() {
return "CropCircleTransformation()";
}
@Override public boolean equals(Object o) {
return o instanceof CropCircleTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,45 +18,39 @@ package jp.wasabeef.glide.transformations;
import android.content.Context;
import android.graphics.Bitmap;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
import java.security.MessageDigest;
public class CropSquareTransformation implements Transformation<Bitmap> {
public class CropSquareTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool;
private int mWidth;
private int mHeight;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.CropSquareTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public CropSquareTransformation(Context context) {
this(Glide.get(context).getBitmapPool());
private int size;
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
this.size = Math.max(outWidth, outHeight);
return TransformationUtils.centerCrop(pool, toTransform, size, size);
}
public CropSquareTransformation(BitmapPool pool) {
this.mBitmapPool = pool;
@Override public String toString() {
return "CropSquareTransformation(size=" + size + ")";
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int size = Math.min(source.getWidth(), source.getHeight());
mWidth = (source.getWidth() - size) / 2;
mHeight = (source.getHeight() - size) / 2;
Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
}
return BitmapResource.obtain(bitmap, mBitmapPool);
@Override public boolean equals(Object o) {
return o instanceof CropSquareTransformation;
}
@Override public String getId() {
return "CropSquareTransformation(width=" + mWidth + ", height=" + mHeight + ")";
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,13 +20,15 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.RectF;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import java.security.MessageDigest;
public class CropTransformation implements Transformation<Bitmap> {
public class CropTransformation extends BitmapTransformation {
private static final int VERSION = 1;
private static final String ID = "jp.wasabeef.glide.transformations.CropTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public enum CropType {
TOP,
@@ -34,81 +36,74 @@ public class CropTransformation implements Transformation<Bitmap> {
BOTTOM
}
private BitmapPool mBitmapPool;
private int mWidth;
private int mHeight;
private int width;
private int height;
private CropType mCropType = CropType.CENTER;
private CropType cropType = CropType.CENTER;
public CropTransformation(Context context) {
this(Glide.get(context).getBitmapPool());
public CropTransformation(int width, int height) {
this(width, height, CropType.CENTER);
}
public CropTransformation(BitmapPool pool) {
this(pool, 0, 0);
public CropTransformation(int width, int height, CropType cropType) {
this.width = width;
this.height = height;
this.cropType = cropType;
}
public CropTransformation(Context context, int width, int height) {
this(Glide.get(context).getBitmapPool(), width, height);
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
public CropTransformation(BitmapPool pool, int width, int height) {
this(pool, width, height, CropType.CENTER);
}
public CropTransformation(Context context, int width, int height, CropType cropType) {
this(Glide.get(context).getBitmapPool(), width, height, cropType);
}
public CropTransformation(BitmapPool pool, int width, int height, CropType cropType) {
mBitmapPool = pool;
mWidth = width;
mHeight = height;
mCropType = cropType;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
mWidth = mWidth == 0 ? source.getWidth() : mWidth;
mHeight = mHeight == 0 ? source.getHeight() : mHeight;
width = width == 0 ? toTransform.getWidth() : width;
height = height == 0 ? toTransform.getHeight() : height;
Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(mWidth, mHeight, config);
}
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = pool.get(width, height, config);
float scaleX = (float) mWidth / source.getWidth();
float scaleY = (float) mHeight / source.getHeight();
bitmap.setHasAlpha(true);
float scaleX = (float) width / toTransform.getWidth();
float scaleY = (float) height / toTransform.getHeight();
float scale = Math.max(scaleX, scaleY);
float scaledWidth = scale * source.getWidth();
float scaledHeight = scale * source.getHeight();
float left = (mWidth - scaledWidth) / 2;
float scaledWidth = scale * toTransform.getWidth();
float scaledHeight = scale * toTransform.getHeight();
float left = (width - scaledWidth) / 2;
float top = getTop(scaledHeight);
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(source, null, targetRect, null);
canvas.drawBitmap(toTransform, null, targetRect, null);
return BitmapResource.obtain(bitmap, mBitmapPool);
return bitmap;
}
@Override public String getId() {
return "CropTransformation(width=" + mWidth + ", height=" + mHeight + ", cropType=" + mCropType
@Override public String toString() {
return "CropTransformation(width=" + width + ", height=" + height + ", cropType=" + cropType
+ ")";
}
@Override public boolean equals(Object o) {
return o instanceof CropTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
private float getTop(float scaledHeight) {
switch (mCropType) {
switch (cropType) {
case TOP:
return 0;
case CENTER:
return (mHeight - scaledHeight) / 2;
return (height - scaledHeight) / 2;
case BOTTOM:
return mHeight - scaledHeight;
return height - scaledHeight;
default:
return 0;
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,49 +22,49 @@ import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import java.security.MessageDigest;
public class GrayscaleTransformation implements Transformation<Bitmap> {
public class GrayscaleTransformation extends BitmapTransformation {
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.GrayscaleTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public GrayscaleTransformation(Context context) {
this(Glide.get(context).getBitmapPool());
}
public GrayscaleTransformation(BitmapPool pool) {
mBitmapPool = pool;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
Bitmap.Config config =
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, config);
}
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = pool.get(width, height, config);
Canvas canvas = new Canvas(bitmap);
ColorMatrix saturation = new ColorMatrix();
saturation.setSaturation(0f);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
canvas.drawBitmap(source, 0, 0, paint);
canvas.drawBitmap(toTransform, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
return bitmap;
}
@Override public String getId() {
@Override public String toString() {
return "GrayscaleTransformation()";
}
@Override public boolean equals(Object o) {
return o instanceof GrayscaleTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,63 +23,65 @@ import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.Drawable;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import java.security.MessageDigest;
import jp.wasabeef.glide.transformations.internal.Utils;
public class MaskTransformation implements Transformation<Bitmap> {
public class MaskTransformation extends BitmapTransformation {
private static Paint sMaskingPaint = new Paint();
private Context mContext;
private BitmapPool mBitmapPool;
private int mMaskId;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.MaskTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private static Paint paint = new Paint();
private int maskId;
static {
sMaskingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
}
/**
* @param maskId If you change the mask file, please also rename the mask file, or Glide will get
* the cache with the old mask. Because getId() return the same values if using the
* the cache with the old mask. Because key() return the same values if using the
* same make file name. If you have a good idea please tell us, thanks.
*/
public MaskTransformation(Context context, int maskId) {
this(context, Glide.get(context).getBitmapPool(), maskId);
public MaskTransformation(int maskId) {
this.maskId = maskId;
}
public MaskTransformation(Context context, BitmapPool pool, int maskId) {
mBitmapPool = pool;
mContext = context.getApplicationContext();
mMaskId = maskId;
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
bitmap.setHasAlpha(true);
int width = source.getWidth();
int height = source.getHeight();
Drawable mask = Utils.getMaskDrawable(context.getApplicationContext(), maskId);
Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);
Canvas canvas = new Canvas(result);
Canvas canvas = new Canvas(bitmap);
mask.setBounds(0, 0, width, height);
mask.draw(canvas);
canvas.drawBitmap(source, 0, 0, sMaskingPaint);
canvas.drawBitmap(toTransform, 0, 0, paint);
return BitmapResource.obtain(result, mBitmapPool);
return bitmap;
}
@Override public String getId() {
return "MaskTransformation(maskId=" + mContext.getResources().getResourceEntryName(mMaskId)
+ ")";
@Override public String toString() {
return "MaskTransformation(maskId=" + maskId + ")";
}
@Override public boolean equals(Object o) {
return o instanceof MaskTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,13 +23,16 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
public class RoundedCornersTransformation implements Transformation<Bitmap> {
import java.security.MessageDigest;
public class RoundedCornersTransformation extends BitmapTransformation {
private static final int VERSION = 1;
private static final String ID = "jp.wasabeef.glide.transformations.RoundedCornersTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public enum CornerType {
ALL,
@@ -39,61 +42,45 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
}
private BitmapPool mBitmapPool;
private int mRadius;
private int mDiameter;
private int mMargin;
private CornerType mCornerType;
private int radius;
private int diameter;
private int margin;
private CornerType cornerType;
public RoundedCornersTransformation(Context context, int radius, int margin) {
this(context, radius, margin, CornerType.ALL);
public RoundedCornersTransformation(int radius, int margin) {
this(radius, margin, CornerType.ALL);
}
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) {
this(pool, radius, margin, CornerType.ALL);
public RoundedCornersTransformation(int radius, int margin, CornerType cornerType) {
this.radius = radius;
this.diameter = this.radius * 2;
this.margin = margin;
this.cornerType = cornerType;
}
public RoundedCornersTransformation(Context context, int radius, int margin,
CornerType cornerType) {
this(Glide.get(context).getBitmapPool(), radius, margin, cornerType);
}
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
public RoundedCornersTransformation(BitmapPool pool, int radius, int margin,
CornerType cornerType) {
mBitmapPool = pool;
mRadius = radius;
mDiameter = mRadius * 2;
mMargin = margin;
mCornerType = cornerType;
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
bitmap.setHasAlpha(true);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height);
return BitmapResource.obtain(bitmap, mBitmapPool);
return bitmap;
}
private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
float right = width - mMargin;
float bottom = height - mMargin;
float right = width - margin;
float bottom = height - margin;
switch (mCornerType) {
switch (cornerType) {
case ALL:
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
break;
case TOP_LEFT:
drawTopLeftRoundRect(canvas, paint, right, bottom);
@@ -138,118 +125,127 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
break;
default:
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint);
canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
break;
}
}
private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
mRadius, mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, mMargin + mRadius, bottom), paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin + radius, margin + radius, bottom), paint);
canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
}
private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
canvas.drawRect(new RectF(right - mRadius, mMargin + mRadius, right, bottom), paint);
canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
canvas.drawRect(new RectF(right - radius, margin + radius, right, bottom), paint);
}
private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
mRadius, mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom - mRadius), paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin, margin + diameter, bottom - radius), paint);
canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
}
private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
canvas.drawRect(new RectF(right - mRadius, mMargin, right, bottom - mRadius), paint);
canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
canvas.drawRect(new RectF(right - radius, margin, right, bottom - radius), paint);
}
private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right, bottom), paint);
canvas.drawRect(new RectF(margin, margin + radius, right, bottom), paint);
}
private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
paint);
canvas.drawRect(new RectF(mMargin, mMargin, right, bottom - mRadius), paint);
canvas.drawRect(new RectF(margin, margin, right, bottom - radius), paint);
}
private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint);
canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
}
private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint);
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
}
private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
paint);
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
}
private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
paint);
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom - mRadius), paint);
canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint);
}
private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
paint);
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mRadius, bottom), paint);
canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
canvas.drawRect(new RectF(margin, margin + radius, right - radius, bottom), paint);
}
private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
paint);
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
}
private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
mRadius, mRadius, paint);
canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mDiameter, bottom), paint);
canvas.drawRect(new RectF(mMargin + mDiameter, mMargin, right, bottom - mRadius), paint);
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius,
radius, paint);
canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin + radius, right - diameter, bottom), paint);
canvas.drawRect(new RectF(margin + diameter, margin, right, bottom - radius), paint);
}
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
mRadius, paint);
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
mRadius, mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
radius, paint);
canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
}
@Override public String getId() {
return "RoundedTransformation(radius=" + mRadius + ", margin=" + mMargin + ", diameter="
+ mDiameter + ", cornerType=" + mCornerType.name() + ")";
@Override public String toString() {
return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ", diameter="
+ diameter + ", cornerType=" + cornerType.name() + ")";
}
@Override public boolean equals(Object o) {
return o instanceof RoundedCornersTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
/**
@@ -26,28 +24,37 @@ import jp.co.cyberagent.android.gpuimage.GPUImageBrightnessFilter;
*/
public class BrightnessFilterTransformation extends GPUFilterTransformation {
private float mBrightness;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public BrightnessFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private float brightness;
public BrightnessFilterTransformation() {
this(0.0f);
}
public BrightnessFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, 0.0f);
}
public BrightnessFilterTransformation(Context context, float brightness) {
this(context, Glide.get(context).getBitmapPool(), brightness);
}
public BrightnessFilterTransformation(Context context, BitmapPool pool, float brightness) {
super(context, pool, new GPUImageBrightnessFilter());
mBrightness = brightness;
public BrightnessFilterTransformation(float brightness) {
super(new GPUImageBrightnessFilter());
this.brightness = brightness;
GPUImageBrightnessFilter filter = getFilter();
filter.setBrightness(mBrightness);
filter.setBrightness(this.brightness);
}
@Override public String getId() {
return "BrightnessFilterTransformation(brightness=" + mBrightness + ")";
@Override public String toString() {
return "BrightnessFilterTransformation(brightness=" + brightness + ")";
}
@Override public boolean equals(Object o) {
return o instanceof BrightnessFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
/**
@@ -26,28 +24,37 @@ import jp.co.cyberagent.android.gpuimage.GPUImageContrastFilter;
*/
public class ContrastFilterTransformation extends GPUFilterTransformation {
private float mContrast;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public ContrastFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private float contrast;
public ContrastFilterTransformation() {
this(1.0f);
}
public ContrastFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, 1.0f);
}
public ContrastFilterTransformation(Context context, float contrast) {
this(context, Glide.get(context).getBitmapPool(), contrast);
}
public ContrastFilterTransformation(Context context, BitmapPool pool, float contrast) {
super(context, pool, new GPUImageContrastFilter());
mContrast = contrast;
public ContrastFilterTransformation(float contrast) {
super(new GPUImageContrastFilter());
this.contrast = contrast;
GPUImageContrastFilter filter = getFilter();
filter.setContrast(mContrast);
filter.setContrast(this.contrast);
}
@Override public String getId() {
return "ContrastFilterTransformation(contrast=" + mContrast + ")";
@Override public String toString() {
return "ContrastFilterTransformation(contrast=" + contrast + ")";
}
@Override public boolean equals(Object o) {
return o instanceof ContrastFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,48 +18,52 @@ package jp.wasabeef.glide.transformations.gpu;
import android.content.Context;
import android.graphics.Bitmap;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.GPUImageFilter;
import jp.wasabeef.glide.transformations.BitmapTransformation;
public class GPUFilterTransformation implements Transformation<Bitmap> {
public class GPUFilterTransformation extends BitmapTransformation {
private Context mContext;
private BitmapPool mBitmapPool;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.GPUFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private GPUImageFilter mFilter;
private GPUImageFilter gpuImageFilter;
public GPUFilterTransformation(Context context, GPUImageFilter filter) {
this(context, Glide.get(context).getBitmapPool(), filter);
public GPUFilterTransformation(GPUImageFilter filter) {
this.gpuImageFilter = filter;
}
public GPUFilterTransformation(Context context, BitmapPool pool, GPUImageFilter filter) {
mContext = context.getApplicationContext();
mBitmapPool = pool;
mFilter = filter;
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
GPUImage gpuImage = new GPUImage(context);
gpuImage.setImage(toTransform);
gpuImage.setFilter(gpuImageFilter);
return gpuImage.getBitmapWithFilterApplied();
}
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
GPUImage gpuImage = new GPUImage(mContext);
gpuImage.setImage(source);
gpuImage.setFilter(mFilter);
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();
return BitmapResource.obtain(bitmap, mBitmapPool);
}
@Override public String getId() {
@Override public String toString() {
return getClass().getSimpleName();
}
@SuppressWarnings("unchecked") public <T> T getFilter() {
return (T) mFilter;
return (T) gpuImageFilter;
}
@Override public boolean equals(Object o) {
return o instanceof GPUFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
/**
@@ -26,15 +24,28 @@ import jp.co.cyberagent.android.gpuimage.GPUImageColorInvertFilter;
*/
public class InvertFilterTransformation extends GPUFilterTransformation {
public InvertFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public InvertFilterTransformation() {
super(new GPUImageColorInvertFilter());
}
public InvertFilterTransformation(Context context, BitmapPool pool) {
super(context, pool, new GPUImageColorInvertFilter());
}
@Override public String getId() {
@Override public String toString() {
return "InvertFilterTransformation()";
}
@Override public boolean equals(Object o) {
return o instanceof InvertFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
/**
@@ -29,28 +27,37 @@ import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
*/
public class KuwaharaFilterTransformation extends GPUFilterTransformation {
private int mRadius;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public KuwaharaFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private int radius;
public KuwaharaFilterTransformation() {
this(25);
}
public KuwaharaFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, 25);
}
public KuwaharaFilterTransformation(Context context, int radius) {
this(context, Glide.get(context).getBitmapPool(), radius);
}
public KuwaharaFilterTransformation(Context context, BitmapPool pool, int radius) {
super(context, pool, new GPUImageKuwaharaFilter());
mRadius = radius;
public KuwaharaFilterTransformation(int radius) {
super(new GPUImageKuwaharaFilter());
this.radius = radius;
GPUImageKuwaharaFilter filter = getFilter();
filter.setRadius(mRadius);
filter.setRadius(this.radius);
}
@Override public String getId() {
return "KuwaharaFilterTransformation(radius=" + mRadius + ")";
@Override public String toString() {
return "KuwaharaFilterTransformation(radius=" + radius + ")";
}
@Override public boolean equals(Object o) {
return o instanceof KuwaharaFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
/**
@@ -28,28 +26,37 @@ import jp.co.cyberagent.android.gpuimage.GPUImagePixelationFilter;
*/
public class PixelationFilterTransformation extends GPUFilterTransformation {
private float mPixel;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public PixelationFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private float pixel;
public PixelationFilterTransformation() {
this(10f);
}
public PixelationFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, 10f);
}
public PixelationFilterTransformation(Context context, float pixel) {
this(context, Glide.get(context).getBitmapPool(), pixel);
}
public PixelationFilterTransformation(Context context, BitmapPool pool, float pixel) {
super(context, pool, new GPUImagePixelationFilter());
mPixel = pixel;
public PixelationFilterTransformation(float pixel) {
super(new GPUImagePixelationFilter());
this.pixel = pixel;
GPUImagePixelationFilter filter = getFilter();
filter.setPixel(mPixel);
filter.setPixel(this.pixel);
}
@Override public String getId() {
return "PixelationFilterTransformation(pixel=" + mPixel + ")";
@Override public String toString() {
return "PixelationFilterTransformation(pixel=" + pixel + ")";
}
@Override public boolean equals(Object o) {
return o instanceof PixelationFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
/**
@@ -28,28 +26,37 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSepiaFilter;
*/
public class SepiaFilterTransformation extends GPUFilterTransformation {
private float mIntensity;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public SepiaFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private float intensity;
public SepiaFilterTransformation() {
this(1.0f);
}
public SepiaFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, 1.0f);
}
public SepiaFilterTransformation(Context context, float intensity) {
this(context, Glide.get(context).getBitmapPool(), intensity);
}
public SepiaFilterTransformation(Context context, BitmapPool pool, float intensity) {
super(context, pool, new GPUImageSepiaFilter());
mIntensity = intensity;
public SepiaFilterTransformation(float intensity) {
super(new GPUImageSepiaFilter());
this.intensity = intensity;
GPUImageSepiaFilter filter = getFilter();
filter.setIntensity(mIntensity);
filter.setIntensity(this.intensity);
}
@Override public String getId() {
return "SepiaFilterTransformation(intensity=" + mIntensity + ")";
@Override public String toString() {
return "SepiaFilterTransformation(intensity=" + intensity + ")";
}
@Override public boolean equals(Object o) {
return o instanceof SepiaFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,22 +16,33 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageSketchFilter;
public class SketchFilterTransformation extends GPUFilterTransformation {
public SketchFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public SketchFilterTransformation() {
super(new GPUImageSketchFilter());
}
public SketchFilterTransformation(Context context, BitmapPool pool) {
super(context, pool, new GPUImageSketchFilter());
}
@Override public String getId() {
@Override public String toString() {
return "SketchFilterTransformation()";
}
@Override public boolean equals(Object o) {
return o instanceof SketchFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import android.graphics.PointF;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
/**
@@ -27,20 +25,17 @@ import jp.co.cyberagent.android.gpuimage.GPUImageSwirlFilter;
*/
public class SwirlFilterTransformation extends GPUFilterTransformation {
private float mRadius;
private float mAngle;
private PointF mCenter;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public SwirlFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
}
private float radius;
private float angle;
private PointF center;
public SwirlFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, .5f, 1.0f, new PointF(0.5f, 0.5f));
}
public SwirlFilterTransformation(Context context, float radius, float angle, PointF center) {
this(context, Glide.get(context).getBitmapPool(), radius, angle, center);
public SwirlFilterTransformation() {
this(.5f, 1.0f, new PointF(0.5f, 0.5f));
}
/**
@@ -48,20 +43,31 @@ public class SwirlFilterTransformation extends GPUFilterTransformation {
* @param angle minimum 0.0, default 1.0
* @param center default (0.5, 0.5)
*/
public SwirlFilterTransformation(Context context, BitmapPool pool, float radius, float angle,
PointF center) {
super(context, pool, new GPUImageSwirlFilter());
mRadius = radius;
mAngle = angle;
mCenter = center;
public SwirlFilterTransformation(float radius, float angle, PointF center) {
super(new GPUImageSwirlFilter());
this.radius = radius;
this.angle = angle;
this.center = center;
GPUImageSwirlFilter filter = getFilter();
filter.setRadius(mRadius);
filter.setAngle(mAngle);
filter.setCenter(mCenter);
filter.setRadius(this.radius);
filter.setAngle(this.angle);
filter.setCenter(this.center);
}
@Override public String getId() {
return "SwirlFilterTransformation(radius=" + mRadius +
",angle=" + mAngle + ",center=" + mCenter.toString() + ")";
@Override public String toString() {
return "SwirlFilterTransformation(radius=" + radius + ",angle=" + angle + ",center="
+ center.toString() + ")";
}
@Override public boolean equals(Object o) {
return o instanceof SwirlFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
/**
@@ -28,33 +26,41 @@ import jp.co.cyberagent.android.gpuimage.GPUImageToonFilter;
*/
public class ToonFilterTransformation extends GPUFilterTransformation {
private float mThreshold;
private float mQuantizationLevels;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public ToonFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private float threshold;
private float quantizationLevels;
public ToonFilterTransformation() {
this(.2f, 10.0f);
}
public ToonFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, .2f, 10.0f);
}
public ToonFilterTransformation(Context context, float threshold, float quantizationLevels) {
this(context, Glide.get(context).getBitmapPool(), threshold, quantizationLevels);
}
public ToonFilterTransformation(Context context, BitmapPool pool, float threshold,
float quantizationLevels) {
super(context, pool, new GPUImageToonFilter());
mThreshold = threshold;
mQuantizationLevels = quantizationLevels;
public ToonFilterTransformation(float threshold, float quantizationLevels) {
super(new GPUImageToonFilter());
this.threshold = threshold;
this.quantizationLevels = quantizationLevels;
GPUImageToonFilter filter = getFilter();
filter.setThreshold(mThreshold);
filter.setQuantizationLevels(mQuantizationLevels);
filter.setThreshold(this.threshold);
filter.setQuantizationLevels(this.quantizationLevels);
}
@Override public String getId() {
return "ToonFilterTransformation(threshold=" + mThreshold +
",quantizationLevels=" + mQuantizationLevels + ")";
@Override public String toString() {
return "ToonFilterTransformation(threshold=" + threshold + ",quantizationLevels="
+ quantizationLevels + ")";
}
@Override public boolean equals(Object o) {
return o instanceof ToonFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -1,7 +1,7 @@
package jp.wasabeef.glide.transformations.gpu;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@ package jp.wasabeef.glide.transformations.gpu;
* limitations under the License.
*/
import android.content.Context;
import android.graphics.PointF;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.security.MessageDigest;
import java.util.Arrays;
import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
@@ -30,41 +28,47 @@ import jp.co.cyberagent.android.gpuimage.GPUImageVignetteFilter;
*/
public class VignetteFilterTransformation extends GPUFilterTransformation {
private PointF mCenter;
private float[] mVignetteColor;
private float mVignetteStart;
private float mVignetteEnd;
private static final int VERSION = 1;
private static final String ID =
"jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
public VignetteFilterTransformation(Context context) {
this(context, Glide.get(context).getBitmapPool());
private PointF center;
private float[] vignetteColor;
private float vignetteStart;
private float vignetteEnd;
public VignetteFilterTransformation() {
this(new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
}
public VignetteFilterTransformation(Context context, BitmapPool pool) {
this(context, pool, new PointF(0.5f, 0.5f), new float[] { 0.0f, 0.0f, 0.0f }, 0.0f, 0.75f);
}
public VignetteFilterTransformation(Context context, PointF center, float[] color, float start,
float end) {
this(context, Glide.get(context).getBitmapPool(), center, color, start, end);
}
public VignetteFilterTransformation(Context context, BitmapPool pool, PointF center,
float[] color, float start, float end) {
super(context, pool, new GPUImageVignetteFilter());
mCenter = center;
mVignetteColor = color;
mVignetteStart = start;
mVignetteEnd = end;
public VignetteFilterTransformation(PointF center, float[] color, float start, float end) {
super(new GPUImageVignetteFilter());
this.center = center;
vignetteColor = color;
vignetteStart = start;
vignetteEnd = end;
GPUImageVignetteFilter filter = getFilter();
filter.setVignetteCenter(mCenter);
filter.setVignetteColor(mVignetteColor);
filter.setVignetteStart(mVignetteStart);
filter.setVignetteEnd(mVignetteEnd);
filter.setVignetteCenter(this.center);
filter.setVignetteColor(vignetteColor);
filter.setVignetteStart(vignetteStart);
filter.setVignetteEnd(vignetteEnd);
}
@Override public String getId() {
return "VignetteFilterTransformation(center=" + mCenter.toString() +
",color=" + Arrays.toString(mVignetteColor) +
",start=" + mVignetteStart + ",end=" + mVignetteEnd + ")";
@Override public String toString() {
return "VignetteFilterTransformation(center=" + center.toString() + ",color=" + Arrays.toString(
vignetteColor) + ",start=" + vignetteStart + ",end=" + vignetteEnd + ")";
}
@Override public boolean equals(Object o) {
return o instanceof VignetteFilterTransformation;
}
@Override public int hashCode() {
return ID.hashCode();
}
@Override public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}

View File

@@ -3,7 +3,7 @@ package jp.wasabeef.glide.transformations.internal;
import android.graphics.Bitmap;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -11,7 +11,7 @@ import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,14 +31,16 @@ public class RSBlur {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
RenderScript rs = null;
Allocation input = null;
Allocation output = null;
ScriptIntrinsicBlur blur = null;
try {
rs = RenderScript.create(context);
rs.setMessageHandler(new RenderScript.RSMessageHandler());
Allocation input =
Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
Allocation output = Allocation.createTyped(rs, input.getType());
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
output = Allocation.createTyped(rs, input.getType());
blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
blur.setInput(input);
blur.setRadius(radius);
@@ -46,7 +48,20 @@ public class RSBlur {
output.copyTo(bitmap);
} finally {
if (rs != null) {
rs.destroy();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
RenderScript.releaseAllContexts();
} else {
rs.destroy();
}
}
if (input != null) {
input.destroy();
}
if (output != null) {
output.destroy();
}
if (blur != null) {
blur.destroy();
}
}

View File

@@ -5,7 +5,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
/**
* Copyright (C) 2015 Wasabeef
* Copyright (C) 2018 Wasabeef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.