11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | *
15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | *
17 | * Unless required by applicable law or agreed to in writing, software
18 | * distributed under the License is distributed on an "AS IS" BASIS,
19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 | * See the License for the specific language governing permissions and
21 | * limitations under the License.
22 | */
23 |
24 | public final class Utils {
25 |
26 | private Utils() {
27 | // Utility class.
28 | }
29 |
30 | public static int toDp(int px) {
31 | return px * (int) Resources.getSystem().getDisplayMetrics().density;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Mac OS
2 | .DS_store
3 |
4 | # Built application files
5 | *.apk
6 | *.ap_
7 |
8 | # Files for the ART/Dalvik VM
9 | *.dex
10 |
11 | # Java class files
12 | *.class
13 |
14 | # Generated files
15 | bin/
16 | gen/
17 | out/
18 |
19 | # Gradle files
20 | .gradle/
21 | build/
22 |
23 | # Local configuration file (sdk path, etc)
24 | local.properties
25 |
26 | # Proguard folder generated by Eclipse
27 | proguard/
28 |
29 | # Log Files
30 | *.log
31 |
32 | # Android Studio Navigation editor temp files
33 | .navigation/
34 |
35 | # Android Studio captures folder
36 | captures/
37 |
38 | # IntelliJ
39 | *.iml
40 | .idea/workspace.xml
41 | .idea/tasks.xml
42 | .idea/gradle.xml
43 | .idea/assetWizardSettings.xml
44 | .idea/dictionaries
45 | .idea/libraries
46 | .idea/caches
47 | .idea/misc.xml
48 | .idea/modules.xml
49 | .idea/navEditor.xml
50 | .idea/markdown*
51 | .idea/jarRepositories.xml
52 | .idea/inspectionProfiles/Project_Default.xml
53 | .idea/compiler.xml
54 | projectFilesBackup/
55 |
56 | # Keystore files
57 | # Uncomment the following line if you do not want to check your keystore files in.
58 | #*.jks
59 |
60 | # External native build folder generated in Android Studio 2.2 and later
61 | .externalNativeBuild
62 |
63 | # Google Services (e.g. APIs or Firebase)
64 | google-services.json
65 |
66 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/layout_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *
12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageSketchFilter; 24 | 25 | public class SketchFilterTransformation extends GPUFilterTransformation { 26 | 27 | private static final int VERSION = 1; 28 | private static final String ID = 29 | "jp.wasabeef.glide.transformations.gpu.SketchFilterTransformation." + VERSION; 30 | 31 | public SketchFilterTransformation() { 32 | super(new GPUImageSketchFilter()); 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "SketchFilterTransformation()"; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object o) { 42 | return o instanceof SketchFilterTransformation; 43 | } 44 | 45 | @Override 46 | public int hashCode() { 47 | return ID.hashCode(); 48 | } 49 | 50 | @Override 51 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 52 | messageDigest.update((ID).getBytes(CHARSET)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/InvertFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *
12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageColorInvertFilter; 24 | 25 | /** 26 | * Invert all the colors in the image. 27 | */ 28 | public class InvertFilterTransformation extends GPUFilterTransformation { 29 | 30 | private static final int VERSION = 1; 31 | private static final String ID = 32 | "jp.wasabeef.glide.transformations.gpu.InvertFilterTransformation." + VERSION; 33 | 34 | public InvertFilterTransformation() { 35 | super(new GPUImageColorInvertFilter()); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "InvertFilterTransformation()"; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object o) { 45 | return o instanceof InvertFilterTransformation; 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return ID.hashCode(); 51 | } 52 | 53 | @Override 54 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 55 | messageDigest.update((ID).getBytes(CHARSET)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /transformations/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion COMPILE_SDK_VERSION as int 5 | 6 | defaultConfig { 7 | minSdkVersion MIN_SDK_VERSION as int 8 | targetSdkVersion TARGET_SDK_VERSION as int 9 | 10 | consumerProguardFiles 'proguard-rules.txt' 11 | } 12 | } 13 | 14 | dependencies { 15 | implementation "com.github.bumptech.glide:glide:$glide_version" 16 | annotationProcessor "com.github.bumptech.glide:compiler:$glide_version" 17 | compileOnly "jp.co.cyberagent.android:gpuimage:$gpuimage_version" 18 | } 19 | 20 | ext { 21 | bintrayRepo = 'maven' 22 | bintrayName = 'glide-transformations' 23 | bintrayUserOrg = 'wasabeef' 24 | publishedGroupId = 'jp.wasabeef' 25 | libraryName = 'glide-transformations' 26 | artifact = 'glide-transformations' 27 | libraryDescription = 'Which provides simple Transformations to Glide' 28 | siteUrl = 'https://github.com/wasabeef/glide-transformations' 29 | gitUrl = 'https://github.com/wasabeef/glide-transformations.git' 30 | issueUrl = 'https://github.com/wasabeef/glide-transformations/issues' 31 | libraryVersion = VERSION_NAME 32 | developerId = 'wasabeef' 33 | developerName = 'Wasabeef' 34 | developerEmail = 'dadadada.chop@gmail.com' 35 | licenseName = 'The Apache Software License, Version 2.0' 36 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 37 | allLicenses = ["Apache-2.0"] 38 | } 39 | 40 | // TODO: Close JCenter on May 1st https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/ 41 | // apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/bintray-v1.gradle' 42 | // apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/install-v1.gradle' 43 | 44 | apply from: 'https://gist.githubusercontent.com/wasabeef/2f2ae8d97b429e7d967128125dc47854/raw/maven-central-v1.gradle' 45 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/ContrastFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *
12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageContrastFilter; 24 | 25 | /** 26 | * contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level 27 | */ 28 | public class ContrastFilterTransformation extends GPUFilterTransformation { 29 | 30 | private static final int VERSION = 1; 31 | private static final String ID = 32 | "jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation." + VERSION; 33 | 34 | private final float contrast; 35 | 36 | public ContrastFilterTransformation() { 37 | this(1.0f); 38 | } 39 | 40 | public ContrastFilterTransformation(float contrast) { 41 | super(new GPUImageContrastFilter()); 42 | this.contrast = contrast; 43 | GPUImageContrastFilter filter = getFilter(); 44 | filter.setContrast(this.contrast); 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "ContrastFilterTransformation(contrast=" + contrast + ")"; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | return o instanceof ContrastFilterTransformation; 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | return ID.hashCode() + (int) (contrast * 10); 60 | } 61 | 62 | @Override 63 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 64 | messageDigest.update((ID + contrast).getBytes(CHARSET)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SepiaFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *
12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageSepiaToneFilter; 24 | 25 | /** 26 | * Applies a simple sepia effect. 27 | *
28 | * The intensity with a default of 1.0. 29 | */ 30 | public class SepiaFilterTransformation extends GPUFilterTransformation { 31 | 32 | private static final int VERSION = 1; 33 | private static final String ID = 34 | "jp.wasabeef.glide.transformations.gpu.SepiaFilterTransformation." + VERSION; 35 | 36 | private final float intensity; 37 | 38 | public SepiaFilterTransformation() { 39 | this(1.0f); 40 | } 41 | 42 | public SepiaFilterTransformation(float intensity) { 43 | super(new GPUImageSepiaToneFilter()); 44 | this.intensity = intensity; 45 | GPUImageSepiaToneFilter filter = getFilter(); 46 | filter.setIntensity(this.intensity); 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "SepiaFilterTransformation(intensity=" + intensity + ")"; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object o) { 56 | return o instanceof SepiaFilterTransformation; 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return ID.hashCode() + (int) (intensity * 10); 62 | } 63 | 64 | @Override 65 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 66 | messageDigest.update((ID + intensity).getBytes(CHARSET)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/PixelationFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *
12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImagePixelationFilter; 24 | 25 | /** 26 | * Applies a Pixelation effect to the image. 27 | *
28 | * The pixel with a default of 10.0. 29 | */ 30 | public class PixelationFilterTransformation extends GPUFilterTransformation { 31 | 32 | private static final int VERSION = 1; 33 | private static final String ID = 34 | "jp.wasabeef.glide.transformations.gpu.PixelationFilterTransformation." + VERSION; 35 | 36 | private final float pixel; 37 | 38 | public PixelationFilterTransformation() { 39 | this(10f); 40 | } 41 | 42 | public PixelationFilterTransformation(float pixel) { 43 | super(new GPUImagePixelationFilter()); 44 | this.pixel = pixel; 45 | GPUImagePixelationFilter filter = getFilter(); 46 | filter.setPixel(this.pixel); 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "PixelationFilterTransformation(pixel=" + pixel + ")"; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object o) { 56 | return o instanceof PixelationFilterTransformation; 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return ID.hashCode() + (int) (pixel * 10); 62 | } 63 | 64 | @Override 65 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 66 | messageDigest.update((ID + pixel).getBytes(CHARSET)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *
12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | 22 | import androidx.annotation.NonNull; 23 | 24 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 25 | import com.bumptech.glide.load.resource.bitmap.TransformationUtils; 26 | import com.bumptech.glide.request.RequestOptions; 27 | 28 | import java.security.MessageDigest; 29 | 30 | /** 31 | * @deprecated Use {@link RequestOptions#circleCrop()}. 32 | */ 33 | @Deprecated 34 | public class CropCircleTransformation extends BitmapTransformation { 35 | 36 | private static final int VERSION = 1; 37 | private static final String ID = 38 | "jp.wasabeef.glide.transformations.CropCircleTransformation." + VERSION; 39 | 40 | @Override 41 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 42 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 43 | return TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight); 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "CropCircleTransformation()"; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object o) { 53 | return o instanceof CropCircleTransformation; 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | return ID.hashCode(); 59 | } 60 | 61 | @Override 62 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 63 | messageDigest.update((ID).getBytes(CHARSET)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/CropSquareTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *
12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | 22 | import androidx.annotation.NonNull; 23 | 24 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 25 | import com.bumptech.glide.load.resource.bitmap.TransformationUtils; 26 | 27 | import java.security.MessageDigest; 28 | 29 | public class CropSquareTransformation extends BitmapTransformation { 30 | 31 | private static final int VERSION = 1; 32 | private static final String ID = 33 | "jp.wasabeef.glide.transformations.CropSquareTransformation." + VERSION; 34 | 35 | private int size; 36 | 37 | @Override 38 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, 39 | @NonNull Bitmap toTransform, int outWidth, int outHeight) { 40 | this.size = Math.max(outWidth, outHeight); 41 | return TransformationUtils.centerCrop(pool, toTransform, size, size); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "CropSquareTransformation(size=" + size + ")"; 47 | } 48 | 49 | @Override 50 | public boolean equals(Object o) { 51 | return o instanceof CropSquareTransformation && ((CropSquareTransformation) o).size == size; 52 | } 53 | 54 | @Override 55 | public int hashCode() { 56 | return ID.hashCode() + size * 10; 57 | } 58 | 59 | @Override 60 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 61 | messageDigest.update((ID + size).getBytes(CHARSET)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/KuwaharaFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *
12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageKuwaharaFilter; 24 | 25 | /** 26 | * Kuwahara all the colors in the image. 27 | *
28 | * The radius to sample from when creating the brush-stroke effect, with a default of 25. 29 | * The larger the radius, the slower the filter. 30 | */ 31 | public class KuwaharaFilterTransformation extends GPUFilterTransformation { 32 | 33 | private static final int VERSION = 1; 34 | private static final String ID = 35 | "jp.wasabeef.glide.transformations.gpu.KuwaharaFilterTransformation." + VERSION; 36 | 37 | private final int radius; 38 | 39 | public KuwaharaFilterTransformation() { 40 | this(25); 41 | } 42 | 43 | public KuwaharaFilterTransformation(int radius) { 44 | super(new GPUImageKuwaharaFilter()); 45 | this.radius = radius; 46 | GPUImageKuwaharaFilter filter = getFilter(); 47 | filter.setRadius(this.radius); 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "KuwaharaFilterTransformation(radius=" + radius + ")"; 53 | } 54 | 55 | @Override 56 | public boolean equals(Object o) { 57 | return o instanceof KuwaharaFilterTransformation; 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return ID.hashCode() + radius * 10; 63 | } 64 | 65 | @Override 66 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 67 | messageDigest.update((ID + radius).getBytes(CHARSET)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/BrightnessFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *
12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import androidx.annotation.NonNull; 20 | 21 | import java.security.MessageDigest; 22 | 23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageBrightnessFilter; 24 | 25 | /** 26 | * brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level 27 | */ 28 | public class BrightnessFilterTransformation extends GPUFilterTransformation { 29 | 30 | private static final int VERSION = 1; 31 | private static final String ID = 32 | "jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation." + VERSION; 33 | 34 | private final float brightness; 35 | 36 | public BrightnessFilterTransformation() { 37 | this(0.0f); 38 | } 39 | 40 | public BrightnessFilterTransformation(float brightness) { 41 | super(new GPUImageBrightnessFilter()); 42 | this.brightness = brightness; 43 | GPUImageBrightnessFilter filter = getFilter(); 44 | filter.setBrightness(this.brightness); 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "BrightnessFilterTransformation(brightness=" + brightness + ")"; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | return o instanceof BrightnessFilterTransformation && 55 | ((BrightnessFilterTransformation) o).brightness == brightness; 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | return ID.hashCode() + (int) ((brightness + 1.0f) * 10); 61 | } 62 | 63 | @Override 64 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { 65 | messageDigest.update((ID + brightness).getBytes(CHARSET)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.internal; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.graphics.Bitmap; 6 | import android.os.Build; 7 | import android.renderscript.Allocation; 8 | import android.renderscript.Element; 9 | import android.renderscript.RSRuntimeException; 10 | import android.renderscript.RenderScript; 11 | import android.renderscript.ScriptIntrinsicBlur; 12 | 13 | /** 14 | * Copyright (C) 2020 Wasabeef 15 | *
16 | * Licensed under the Apache License, Version 2.0 (the "License"); 17 | * you may not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | *
20 | * http://www.apache.org/licenses/LICENSE-2.0 21 | *
22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an "AS IS" BASIS, 24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | public class RSBlur { 30 | 31 | public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException { 32 | RenderScript rs = null; 33 | Allocation input = null; 34 | Allocation output = null; 35 | ScriptIntrinsicBlur blur = null; 36 | try { 37 | rs = RenderScript.create(context); 38 | rs.setMessageHandler(new RenderScript.RSMessageHandler()); 39 | input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE, 40 | Allocation.USAGE_SCRIPT); 41 | output = Allocation.createTyped(rs, input.getType()); 42 | blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); 43 | 44 | blur.setInput(input); 45 | blur.setRadius(radius); 46 | blur.forEach(output); 47 | output.copyTo(bitmap); 48 | } finally { 49 | if (rs != null) { 50 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 51 | RenderScript.releaseAllContexts(); 52 | } else { 53 | rs.destroy(); 54 | } 55 | } 56 | if (input != null) { 57 | input.destroy(); 58 | } 59 | if (output != null) { 60 | output.destroy(); 61 | } 62 | if (blur != null) { 63 | blur.destroy(); 64 | } 65 | } 66 | 67 | return bitmap; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/GPUFilterTransformation.java: -------------------------------------------------------------------------------- 1 | package jp.wasabeef.glide.transformations.gpu; 2 | 3 | /** 4 | * Copyright (C) 2020 Wasabeef 5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 |
22 | import androidx.annotation.NonNull;
23 |
24 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
25 |
26 | import java.security.MessageDigest;
27 |
28 | import jp.co.cyberagent.android.gpuimage.GPUImage;
29 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter;
30 | import jp.wasabeef.glide.transformations.BitmapTransformation;
31 |
32 | public class GPUFilterTransformation extends BitmapTransformation {
33 |
34 | private static final int VERSION = 1;
35 | private static final String ID =
36 | "jp.wasabeef.glide.transformations.gpu.GPUFilterTransformation." + VERSION;
37 | private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
38 |
39 | private final GPUImageFilter gpuImageFilter;
40 |
41 | public GPUFilterTransformation(GPUImageFilter filter) {
42 | this.gpuImageFilter = filter;
43 | }
44 |
45 | @Override
46 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
47 | @NonNull Bitmap toTransform, int outWidth, int outHeight) {
48 | GPUImage gpuImage = new GPUImage(context);
49 | gpuImage.setImage(toTransform);
50 | gpuImage.setFilter(gpuImageFilter);
51 |
52 | return gpuImage.getBitmapWithFilterApplied();
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return getClass().getSimpleName();
58 | }
59 |
60 | @SuppressWarnings("unchecked")
61 | public
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import java.security.MessageDigest;
22 |
23 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageToonFilter;
24 |
25 | /**
26 | * The threshold at which to apply the edges, default of 0.2.
27 | * The levels of quantization for the posterization of colors within the scene,
28 | * with a default of 10.0.
29 | */
30 | public class ToonFilterTransformation extends GPUFilterTransformation {
31 |
32 | private static final int VERSION = 1;
33 | private static final String ID =
34 | "jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation." + VERSION;
35 |
36 | private final float threshold;
37 | private final float quantizationLevels;
38 |
39 | public ToonFilterTransformation() {
40 | this(.2f, 10.0f);
41 | }
42 |
43 | public ToonFilterTransformation(float threshold, float quantizationLevels) {
44 | super(new GPUImageToonFilter());
45 | this.threshold = threshold;
46 | this.quantizationLevels = quantizationLevels;
47 | GPUImageToonFilter filter = getFilter();
48 | filter.setThreshold(this.threshold);
49 | filter.setQuantizationLevels(this.quantizationLevels);
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return "ToonFilterTransformation(threshold=" + threshold + ",quantizationLevels="
55 | + quantizationLevels + ")";
56 | }
57 |
58 | @Override
59 | public boolean equals(Object o) {
60 | return o instanceof ToonFilterTransformation &&
61 | ((ToonFilterTransformation) o).threshold == threshold &&
62 | ((ToonFilterTransformation) o).quantizationLevels == quantizationLevels;
63 | }
64 |
65 | @Override
66 | public int hashCode() {
67 | return ID.hashCode() + (int) (threshold * 1000) + (int) (quantizationLevels * 10);
68 | }
69 |
70 | @Override
71 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
72 | messageDigest.update((ID + threshold + quantizationLevels).getBytes(CHARSET));
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/GrayscaleTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2020 Wasabeef
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 | import android.graphics.Canvas;
22 | import android.graphics.ColorMatrix;
23 | import android.graphics.ColorMatrixColorFilter;
24 | import android.graphics.Paint;
25 |
26 | import androidx.annotation.NonNull;
27 |
28 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
29 |
30 | import java.security.MessageDigest;
31 |
32 | public class GrayscaleTransformation extends BitmapTransformation {
33 |
34 | private static final int VERSION = 1;
35 | private static final String ID =
36 | "jp.wasabeef.glide.transformations.GrayscaleTransformation." + VERSION;
37 |
38 | @Override
39 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
40 | @NonNull Bitmap toTransform, int outWidth, int outHeight) {
41 | int width = toTransform.getWidth();
42 | int height = toTransform.getHeight();
43 |
44 | Bitmap.Config config =
45 | toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
46 | Bitmap bitmap = pool.get(width, height, config);
47 |
48 | setCanvasBitmapDensity(toTransform, bitmap);
49 |
50 | Canvas canvas = new Canvas(bitmap);
51 | ColorMatrix saturation = new ColorMatrix();
52 | saturation.setSaturation(0f);
53 | Paint paint = new Paint();
54 | paint.setColorFilter(new ColorMatrixColorFilter(saturation));
55 | canvas.drawBitmap(toTransform, 0, 0, paint);
56 |
57 | return bitmap;
58 | }
59 |
60 | @Override
61 | public String toString() {
62 | return "GrayscaleTransformation()";
63 | }
64 |
65 | @Override
66 | public boolean equals(Object o) {
67 | return o instanceof GrayscaleTransformation;
68 | }
69 |
70 | @Override
71 | public int hashCode() {
72 | return ID.hashCode();
73 | }
74 |
75 | @Override
76 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
77 | messageDigest.update((ID).getBytes(CHARSET));
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/SwirlFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2020 Wasabeef
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.graphics.PointF;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 | import java.security.MessageDigest;
24 |
25 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageSwirlFilter;
26 |
27 | /**
28 | * Creates a swirl distortion on the image.
29 | */
30 | public class SwirlFilterTransformation extends GPUFilterTransformation {
31 |
32 | private static final int VERSION = 1;
33 | private static final String ID =
34 | "jp.wasabeef.glide.transformations.gpu.SwirlFilterTransformation." + VERSION;
35 |
36 | private final float radius;
37 | private final float angle;
38 | private final PointF center;
39 |
40 | public SwirlFilterTransformation() {
41 | this(.5f, 1.0f, new PointF(0.5f, 0.5f));
42 | }
43 |
44 | /**
45 | * @param radius from 0.0 to 1.0, default 0.5
46 | * @param angle minimum 0.0, default 1.0
47 | * @param center default (0.5, 0.5)
48 | */
49 | public SwirlFilterTransformation(float radius, float angle, PointF center) {
50 | super(new GPUImageSwirlFilter());
51 | this.radius = radius;
52 | this.angle = angle;
53 | this.center = center;
54 | GPUImageSwirlFilter filter = getFilter();
55 | filter.setRadius(this.radius);
56 | filter.setAngle(this.angle);
57 | filter.setCenter(this.center);
58 | }
59 |
60 | @Override
61 | public String toString() {
62 | return "SwirlFilterTransformation(radius=" + radius + ",angle=" + angle + ",center="
63 | + center.toString() + ")";
64 | }
65 |
66 | @Override
67 | public boolean equals(Object o) {
68 | return o instanceof SwirlFilterTransformation &&
69 | ((SwirlFilterTransformation) o).radius == radius &&
70 | ((SwirlFilterTransformation) o).angle == radius &&
71 | ((SwirlFilterTransformation) o).center.equals(center.x, center.y);
72 | }
73 |
74 | @Override
75 | public int hashCode() {
76 | return ID.hashCode() + (int) (radius * 1000) + (int) (angle * 10) + center.hashCode();
77 | }
78 |
79 | @Override
80 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
81 | messageDigest.update((ID + radius + angle + center.hashCode()).getBytes(CHARSET));
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/ColorFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2020 Wasabeef
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 | import android.graphics.Canvas;
22 | import android.graphics.Paint;
23 | import android.graphics.PorterDuff;
24 | import android.graphics.PorterDuffColorFilter;
25 |
26 | import androidx.annotation.NonNull;
27 |
28 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
29 |
30 | import java.security.MessageDigest;
31 |
32 | public class ColorFilterTransformation extends BitmapTransformation {
33 |
34 | private static final int VERSION = 1;
35 | private static final String ID =
36 | "jp.wasabeef.glide.transformations.ColorFilterTransformation." + VERSION;
37 |
38 | private final int color;
39 |
40 | public ColorFilterTransformation(int color) {
41 | this.color = color;
42 | }
43 |
44 | @Override
45 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
46 | @NonNull Bitmap toTransform, int outWidth, int outHeight) {
47 | int width = toTransform.getWidth();
48 | int height = toTransform.getHeight();
49 |
50 | Bitmap.Config config =
51 | toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
52 | Bitmap bitmap = pool.get(width, height, config);
53 |
54 | setCanvasBitmapDensity(toTransform, bitmap);
55 |
56 | Canvas canvas = new Canvas(bitmap);
57 | Paint paint = new Paint();
58 | paint.setAntiAlias(true);
59 | paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
60 | canvas.drawBitmap(toTransform, 0, 0, paint);
61 |
62 | return bitmap;
63 | }
64 |
65 | @Override
66 | public String toString() {
67 | return "ColorFilterTransformation(color=" + color + ")";
68 | }
69 |
70 | @Override
71 | public boolean equals(Object o) {
72 | return o instanceof ColorFilterTransformation &&
73 | ((ColorFilterTransformation) o).color == color;
74 | }
75 |
76 | @Override
77 | public int hashCode() {
78 | return ID.hashCode() + color * 10;
79 | }
80 |
81 | @Override
82 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
83 | messageDigest.update((ID + color).getBytes(CHARSET));
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/BitmapTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2020 Wasabeef
5 | * Copyright 2014 Google, Inc. All rights reserved.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | import android.content.Context;
21 | import android.graphics.Bitmap;
22 |
23 | import androidx.annotation.NonNull;
24 |
25 | import com.bumptech.glide.Glide;
26 | import com.bumptech.glide.load.Transformation;
27 | import com.bumptech.glide.load.engine.Resource;
28 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
29 | import com.bumptech.glide.load.resource.bitmap.BitmapResource;
30 | import com.bumptech.glide.request.target.Target;
31 | import com.bumptech.glide.util.Util;
32 |
33 | import java.security.MessageDigest;
34 |
35 | public abstract class BitmapTransformation implements Transformation
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 | import android.graphics.Canvas;
22 | import android.graphics.Paint;
23 | import android.graphics.PorterDuff;
24 | import android.graphics.PorterDuffXfermode;
25 | import android.graphics.drawable.Drawable;
26 |
27 | import androidx.annotation.NonNull;
28 |
29 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
30 |
31 | import java.security.MessageDigest;
32 |
33 | public class MaskTransformation extends BitmapTransformation {
34 |
35 | private static final int VERSION = 1;
36 | private static final String ID =
37 | "jp.wasabeef.glide.transformations.MaskTransformation." + VERSION;
38 |
39 | private static final Paint paint = new Paint();
40 | private final int maskId;
41 |
42 | static {
43 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
44 | }
45 |
46 | /**
47 | * @param maskId If you change the mask file, please also rename the mask file, or Glide will get
48 | * the cache with the old mask. Because key() return the same values if using the
49 | * same make file name. If you have a good idea please tell us, thanks.
50 | */
51 | public MaskTransformation(int maskId) {
52 | this.maskId = maskId;
53 | }
54 |
55 | @Override
56 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
57 | @NonNull Bitmap toTransform, int outWidth, int outHeight) {
58 | int width = toTransform.getWidth();
59 | int height = toTransform.getHeight();
60 |
61 | Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
62 | bitmap.setHasAlpha(true);
63 |
64 | Drawable mask = context.getDrawable(maskId);
65 |
66 | setCanvasBitmapDensity(toTransform, bitmap);
67 |
68 | Canvas canvas = new Canvas(bitmap);
69 | mask.setBounds(0, 0, width, height);
70 | mask.draw(canvas);
71 | canvas.drawBitmap(toTransform, 0, 0, paint);
72 |
73 | return bitmap;
74 | }
75 |
76 | @Override
77 | public String toString() {
78 | return "MaskTransformation(maskId=" + maskId + ")";
79 | }
80 |
81 | @Override
82 | public boolean equals(Object o) {
83 | return o instanceof MaskTransformation &&
84 | ((MaskTransformation) o).maskId == maskId;
85 | }
86 |
87 | @Override
88 | public int hashCode() {
89 | return ID.hashCode() + maskId * 10;
90 | }
91 |
92 | @Override
93 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
94 | messageDigest.update((ID + maskId).getBytes(CHARSET));
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/CropCircleWithBorderTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 |
9 | import androidx.annotation.ColorInt;
10 | import androidx.annotation.NonNull;
11 |
12 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
13 | import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
14 |
15 | import java.security.MessageDigest;
16 |
17 | import jp.wasabeef.glide.transformations.internal.Utils;
18 |
19 | /**
20 | * Copyright (C) 2020 Wasabeef
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | public class CropCircleWithBorderTransformation extends BitmapTransformation {
36 |
37 |
38 | private static final int VERSION = 1;
39 | private static final String ID = "jp.wasabeef.glide.transformations.CropCircleWithBorderTransformation." + VERSION;
40 |
41 | private final int borderSize;
42 | private final int borderColor;
43 |
44 |
45 | public CropCircleWithBorderTransformation() {
46 | this.borderSize = Utils.toDp(4);
47 | this.borderColor = Color.BLACK;
48 | }
49 |
50 | public CropCircleWithBorderTransformation(int borderSize, @ColorInt int borderColor) {
51 | this.borderSize = borderSize;
52 | this.borderColor = borderColor;
53 | }
54 |
55 | @Override
56 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
57 | @NonNull Bitmap toTransform, int outWidth, int outHeight) {
58 |
59 | Bitmap bitmap = TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
60 |
61 | setCanvasBitmapDensity(toTransform, bitmap);
62 |
63 | Paint paint = new Paint();
64 | paint.setColor(borderColor);
65 | paint.setStyle(Paint.Style.STROKE);
66 | paint.setStrokeWidth(borderSize);
67 | paint.setAntiAlias(true);
68 |
69 | Canvas canvas = new Canvas(bitmap);
70 | canvas.drawCircle(
71 | outWidth / 2f,
72 | outHeight / 2f,
73 | Math.max(outWidth, outHeight) / 2f - borderSize / 2f,
74 | paint
75 | );
76 |
77 | return bitmap;
78 | }
79 |
80 | @Override
81 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
82 | messageDigest.update((ID + borderSize + borderColor).getBytes(CHARSET));
83 | }
84 |
85 | @Override
86 | public boolean equals(Object o) {
87 | return o instanceof CropCircleWithBorderTransformation &&
88 | ((CropCircleWithBorderTransformation) o).borderSize == borderSize &&
89 | ((CropCircleWithBorderTransformation) o).borderColor == borderColor;
90 | }
91 |
92 | @Override
93 | public int hashCode() {
94 | return ID.hashCode() + borderSize * 100 + borderColor + 10;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/gpu/VignetteFilterTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations.gpu;
2 |
3 | /**
4 | * Copyright (C) 2020 Wasabeef
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.graphics.PointF;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 | import java.security.MessageDigest;
24 | import java.util.Arrays;
25 |
26 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageVignetteFilter;
27 |
28 | /**
29 | * Performs a vignetting effect, fading out the image at the edges
30 | * The directional intensity of the vignetting,
31 | * with a default of x = 0.5, y = 0.5, start = 0, end = 0.75
32 | */
33 | public class VignetteFilterTransformation extends GPUFilterTransformation {
34 |
35 | private static final int VERSION = 1;
36 | private static final String ID =
37 | "jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation." + VERSION;
38 |
39 | private final PointF center;
40 | private final float[] vignetteColor;
41 | private final float vignetteStart;
42 | private final float vignetteEnd;
43 |
44 | public VignetteFilterTransformation() {
45 | this(new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0.0f, 0.75f);
46 | }
47 |
48 | public VignetteFilterTransformation(PointF center, float[] color, float start, float end) {
49 | super(new GPUImageVignetteFilter());
50 | this.center = center;
51 | vignetteColor = color;
52 | vignetteStart = start;
53 | vignetteEnd = end;
54 | GPUImageVignetteFilter filter = getFilter();
55 | filter.setVignetteCenter(this.center);
56 | filter.setVignetteColor(vignetteColor);
57 | filter.setVignetteStart(vignetteStart);
58 | filter.setVignetteEnd(vignetteEnd);
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return "VignetteFilterTransformation(center=" + center.toString() + ",color=" + Arrays.toString(
64 | vignetteColor) + ",start=" + vignetteStart + ",end=" + vignetteEnd + ")";
65 | }
66 |
67 | @Override
68 | public boolean equals(Object o) {
69 | return o instanceof VignetteFilterTransformation &&
70 | ((VignetteFilterTransformation) o).center.equals(center.x, center.y) &&
71 | Arrays.equals(((VignetteFilterTransformation) o).vignetteColor, vignetteColor) &&
72 | ((VignetteFilterTransformation) o).vignetteStart == vignetteStart &&
73 | ((VignetteFilterTransformation) o).vignetteEnd == vignetteEnd;
74 | }
75 |
76 | @Override
77 | public int hashCode() {
78 | return ID.hashCode() + center.hashCode() + Arrays.hashCode(vignetteColor) +
79 | (int) (vignetteStart * 100) + (int) (vignetteEnd * 10);
80 | }
81 |
82 | @Override
83 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
84 | messageDigest.update((ID + center + Arrays.hashCode(vignetteColor) + vignetteStart + vignetteEnd).getBytes(CHARSET));
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/transformations/src/main/java/jp/wasabeef/glide/transformations/BlurTransformation.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.glide.transformations;
2 |
3 | /**
4 | * Copyright (C) 2020 Wasabeef
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 | import android.graphics.Canvas;
22 | import android.graphics.Paint;
23 | import android.renderscript.RSRuntimeException;
24 |
25 | import androidx.annotation.NonNull;
26 |
27 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
28 |
29 | import java.security.MessageDigest;
30 |
31 | import jp.wasabeef.glide.transformations.internal.FastBlur;
32 | import jp.wasabeef.glide.transformations.internal.RSBlur;
33 |
34 | public class BlurTransformation extends BitmapTransformation {
35 |
36 | private static final int VERSION = 1;
37 | private static final String ID =
38 | "jp.wasabeef.glide.transformations.BlurTransformation." + VERSION;
39 |
40 | private static final int MAX_RADIUS = 25;
41 | private static final int DEFAULT_DOWN_SAMPLING = 1;
42 |
43 | private final int radius;
44 | private final int sampling;
45 |
46 | public BlurTransformation() {
47 | this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
48 | }
49 |
50 | public BlurTransformation(int radius) {
51 | this(radius, DEFAULT_DOWN_SAMPLING);
52 | }
53 |
54 | public BlurTransformation(int radius, int sampling) {
55 | this.radius = radius;
56 | this.sampling = sampling;
57 | }
58 |
59 | @Override
60 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
61 | @NonNull Bitmap toTransform, int outWidth, int outHeight) {
62 |
63 | int width = toTransform.getWidth();
64 | int height = toTransform.getHeight();
65 | int scaledWidth = width / sampling;
66 | int scaledHeight = height / sampling;
67 |
68 | Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
69 |
70 | setCanvasBitmapDensity(toTransform, bitmap);
71 |
72 | Canvas canvas = new Canvas(bitmap);
73 | canvas.scale(1 / (float) sampling, 1 / (float) sampling);
74 | Paint paint = new Paint();
75 | paint.setFlags(Paint.FILTER_BITMAP_FLAG);
76 | canvas.drawBitmap(toTransform, 0, 0, paint);
77 |
78 | try {
79 | bitmap = RSBlur.blur(context, bitmap, radius);
80 | } catch (RSRuntimeException e) {
81 | bitmap = FastBlur.blur(bitmap, radius, true);
82 | }
83 |
84 | return bitmap;
85 | }
86 |
87 | @Override
88 | public String toString() {
89 | return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
90 | }
91 |
92 | @Override
93 | public boolean equals(Object o) {
94 | return o instanceof BlurTransformation &&
95 | ((BlurTransformation) o).radius == radius &&
96 | ((BlurTransformation) o).sampling == sampling;
97 | }
98 |
99 | @Override
100 | public int hashCode() {
101 | return ID.hashCode() + radius * 1000 + sampling * 10;
102 | }
103 |
104 | @Override
105 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
106 | messageDigest.update((ID + radius + sampling).getBytes(CHARSET));
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 | import android.graphics.Canvas;
22 | import android.graphics.RectF;
23 |
24 | import androidx.annotation.NonNull;
25 |
26 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
27 |
28 | import java.security.MessageDigest;
29 |
30 | public class CropTransformation extends BitmapTransformation {
31 |
32 | private static final int VERSION = 1;
33 | private static final String ID = "jp.wasabeef.glide.transformations.CropTransformation." + VERSION;
34 |
35 | public enum CropType {
36 | TOP,
37 | CENTER,
38 | BOTTOM
39 | }
40 |
41 | private int width;
42 | private int height;
43 |
44 | private CropType cropType = CropType.CENTER;
45 |
46 | public CropTransformation(int width, int height) {
47 | this(width, height, CropType.CENTER);
48 | }
49 |
50 | public CropTransformation(int width, int height, CropType cropType) {
51 | this.width = width;
52 | this.height = height;
53 | this.cropType = cropType;
54 | }
55 |
56 | @Override
57 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
58 | @NonNull Bitmap toTransform, int outWidth, int outHeight) {
59 |
60 | width = width == 0 ? toTransform.getWidth() : width;
61 | height = height == 0 ? toTransform.getHeight() : height;
62 |
63 | Bitmap.Config config =
64 | toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
65 | Bitmap bitmap = pool.get(width, height, config);
66 |
67 | bitmap.setHasAlpha(true);
68 |
69 | float scaleX = (float) width / toTransform.getWidth();
70 | float scaleY = (float) height / toTransform.getHeight();
71 | float scale = Math.max(scaleX, scaleY);
72 |
73 | float scaledWidth = scale * toTransform.getWidth();
74 | float scaledHeight = scale * toTransform.getHeight();
75 | float left = (width - scaledWidth) / 2;
76 | float top = getTop(scaledHeight);
77 | RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
78 |
79 | setCanvasBitmapDensity(toTransform, bitmap);
80 |
81 | Canvas canvas = new Canvas(bitmap);
82 | canvas.drawBitmap(toTransform, null, targetRect, null);
83 |
84 | return bitmap;
85 | }
86 |
87 | private float getTop(float scaledHeight) {
88 | switch (cropType) {
89 | case TOP:
90 | return 0;
91 | case CENTER:
92 | return (height - scaledHeight) / 2;
93 | case BOTTOM:
94 | return height - scaledHeight;
95 | default:
96 | return 0;
97 | }
98 | }
99 |
100 | @Override
101 | public String toString() {
102 | return "CropTransformation(width=" + width + ", height=" + height + ", cropType=" + cropType + ")";
103 | }
104 |
105 | @Override
106 | public boolean equals(Object o) {
107 | return o instanceof CropTransformation &&
108 | ((CropTransformation) o).width == width &&
109 | ((CropTransformation) o).height == height &&
110 | ((CropTransformation) o).cropType == cropType;
111 | }
112 |
113 | @Override
114 | public int hashCode() {
115 | return ID.hashCode() + width * 100000 + height * 1000 + cropType.ordinal() * 10;
116 | }
117 |
118 | @Override
119 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
120 | messageDigest.update((ID + width + height + cropType).getBytes(CHARSET));
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Glide Transformations
2 | ======================
3 | [](https://android-arsenal.com/details/1/1363)
4 | [](https://www.apache.org/licenses/LICENSE-2.0)
5 | [](https://search.maven.org/artifact/jp.wasabeef/glide-transformations)
6 |
7 | An Android transformation library providing a variety of image transformations for [Glide](https://github.com/bumptech/glide).
8 |
9 | Please feel free to use this.
10 |
11 |
12 | #### Are you using Picasso or Fresco?
13 | [Picasso Transformations](https://github.com/wasabeef/picasso-transformations)
14 | [Fresco Processors](https://github.com/wasabeef/fresco-processors)
15 |
16 | # Demo
17 |
18 | ### Original Image
19 |
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 |
21 | public class FastBlur {
22 |
23 | public static Bitmap blur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
24 |
25 | // Stack Blur v1.0 from
26 | // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
27 | //
28 | // Java Author: Mario Klingemann
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 | import android.graphics.BitmapShader;
22 | import android.graphics.Canvas;
23 | import android.graphics.Paint;
24 | import android.graphics.RectF;
25 | import android.graphics.Shader;
26 |
27 | import androidx.annotation.NonNull;
28 |
29 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
30 |
31 | import java.security.MessageDigest;
32 |
33 | public class RoundedCornersTransformation extends BitmapTransformation {
34 |
35 | private static final int VERSION = 1;
36 | private static final String ID = "jp.wasabeef.glide.transformations.RoundedCornersTransformation." + VERSION;
37 |
38 | public enum CornerType {
39 | ALL,
40 | TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT,
41 | TOP, BOTTOM, LEFT, RIGHT,
42 | OTHER_TOP_LEFT, OTHER_TOP_RIGHT, OTHER_BOTTOM_LEFT, OTHER_BOTTOM_RIGHT,
43 | DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT
44 | }
45 |
46 | private final int radius;
47 | private final int diameter;
48 | private final int margin;
49 | private final CornerType cornerType;
50 |
51 | public RoundedCornersTransformation(int radius, int margin) {
52 | this(radius, margin, CornerType.ALL);
53 | }
54 |
55 | public RoundedCornersTransformation(int radius, int margin, CornerType cornerType) {
56 | this.radius = radius;
57 | this.diameter = this.radius * 2;
58 | this.margin = margin;
59 | this.cornerType = cornerType;
60 | }
61 |
62 | @Override
63 | protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
64 | @NonNull Bitmap toTransform, int outWidth, int outHeight) {
65 | int width = toTransform.getWidth();
66 | int height = toTransform.getHeight();
67 |
68 | Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
69 | bitmap.setHasAlpha(true);
70 |
71 | setCanvasBitmapDensity(toTransform, bitmap);
72 |
73 | Canvas canvas = new Canvas(bitmap);
74 | Paint paint = new Paint();
75 | paint.setAntiAlias(true);
76 | paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
77 | drawRoundRect(canvas, paint, width, height);
78 | return bitmap;
79 | }
80 |
81 | private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
82 | float right = width - margin;
83 | float bottom = height - margin;
84 |
85 | switch (cornerType) {
86 | case ALL:
87 | canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
88 | break;
89 | case TOP_LEFT:
90 | drawTopLeftRoundRect(canvas, paint, right, bottom);
91 | break;
92 | case TOP_RIGHT:
93 | drawTopRightRoundRect(canvas, paint, right, bottom);
94 | break;
95 | case BOTTOM_LEFT:
96 | drawBottomLeftRoundRect(canvas, paint, right, bottom);
97 | break;
98 | case BOTTOM_RIGHT:
99 | drawBottomRightRoundRect(canvas, paint, right, bottom);
100 | break;
101 | case TOP:
102 | drawTopRoundRect(canvas, paint, right, bottom);
103 | break;
104 | case BOTTOM:
105 | drawBottomRoundRect(canvas, paint, right, bottom);
106 | break;
107 | case LEFT:
108 | drawLeftRoundRect(canvas, paint, right, bottom);
109 | break;
110 | case RIGHT:
111 | drawRightRoundRect(canvas, paint, right, bottom);
112 | break;
113 | case OTHER_TOP_LEFT:
114 | drawOtherTopLeftRoundRect(canvas, paint, right, bottom);
115 | break;
116 | case OTHER_TOP_RIGHT:
117 | drawOtherTopRightRoundRect(canvas, paint, right, bottom);
118 | break;
119 | case OTHER_BOTTOM_LEFT:
120 | drawOtherBottomLeftRoundRect(canvas, paint, right, bottom);
121 | break;
122 | case OTHER_BOTTOM_RIGHT:
123 | drawOtherBottomRightRoundRect(canvas, paint, right, bottom);
124 | break;
125 | case DIAGONAL_FROM_TOP_LEFT:
126 | drawDiagonalFromTopLeftRoundRect(canvas, paint, right, bottom);
127 | break;
128 | case DIAGONAL_FROM_TOP_RIGHT:
129 | drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom);
130 | break;
131 | default:
132 | canvas.drawRoundRect(new RectF(margin, margin, right, bottom), radius, radius, paint);
133 | break;
134 | }
135 | }
136 |
137 | private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
138 | canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius,
139 | radius, paint);
140 | canvas.drawRect(new RectF(margin, margin + radius, margin + radius, bottom), paint);
141 | canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
142 | }
143 |
144 | private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
145 | canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
146 | radius, paint);
147 | canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
148 | canvas.drawRect(new RectF(right - radius, margin + radius, right, bottom), paint);
149 | }
150 |
151 | private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
152 | canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom), radius,
153 | radius, paint);
154 | canvas.drawRect(new RectF(margin, margin, margin + diameter, bottom - radius), paint);
155 | canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
156 | }
157 |
158 | private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
159 | canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
160 | radius, paint);
161 | canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
162 | canvas.drawRect(new RectF(right - radius, margin, right, bottom - radius), paint);
163 | }
164 |
165 | private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
166 | canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
167 | paint);
168 | canvas.drawRect(new RectF(margin, margin + radius, right, bottom), paint);
169 | }
170 |
171 | private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
172 | canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
173 | paint);
174 | canvas.drawRect(new RectF(margin, margin, right, bottom - radius), paint);
175 | }
176 |
177 | private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
178 | canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
179 | paint);
180 | canvas.drawRect(new RectF(margin + radius, margin, right, bottom), paint);
181 | }
182 |
183 | private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
184 | canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
185 | canvas.drawRect(new RectF(margin, margin, right - radius, bottom), paint);
186 | }
187 |
188 | private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
189 | canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
190 | paint);
191 | canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
192 | canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
193 | }
194 |
195 | private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
196 | canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
197 | paint);
198 | canvas.drawRoundRect(new RectF(margin, bottom - diameter, right, bottom), radius, radius,
199 | paint);
200 | canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint);
201 | }
202 |
203 | private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
204 | canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
205 | paint);
206 | canvas.drawRoundRect(new RectF(right - diameter, margin, right, bottom), radius, radius, paint);
207 | canvas.drawRect(new RectF(margin, margin + radius, right - radius, bottom), paint);
208 | }
209 |
210 | private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
211 | float bottom) {
212 | canvas.drawRoundRect(new RectF(margin, margin, right, margin + diameter), radius, radius,
213 | paint);
214 | canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, bottom), radius, radius,
215 | paint);
216 | canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
217 | }
218 |
219 | private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
220 | float bottom) {
221 | canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius,
222 | radius, paint);
223 | canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
224 | radius, paint);
225 | canvas.drawRect(new RectF(margin, margin + radius, right - radius, bottom), paint);
226 | canvas.drawRect(new RectF(margin + radius, margin, right, bottom - radius), paint);
227 | }
228 |
229 | private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
230 | float bottom) {
231 | canvas.drawRoundRect(new RectF(right - diameter, margin, right, margin + diameter), radius,
232 | radius, paint);
233 | canvas.drawRoundRect(new RectF(margin, bottom - diameter, margin + diameter, bottom), radius,
234 | radius, paint);
235 | canvas.drawRect(new RectF(margin, margin, right - radius, bottom - radius), paint);
236 | canvas.drawRect(new RectF(margin + radius, margin + radius, right, bottom), paint);
237 | }
238 |
239 | @Override
240 | public String toString() {
241 | return "RoundedTransformation(radius=" + radius + ", margin=" + margin + ", diameter="
242 | + diameter + ", cornerType=" + cornerType.name() + ")";
243 | }
244 |
245 | @Override
246 | public boolean equals(Object o) {
247 | return o instanceof RoundedCornersTransformation &&
248 | ((RoundedCornersTransformation) o).radius == radius &&
249 | ((RoundedCornersTransformation) o).diameter == diameter &&
250 | ((RoundedCornersTransformation) o).margin == margin &&
251 | ((RoundedCornersTransformation) o).cornerType == cornerType;
252 | }
253 |
254 | @Override
255 | public int hashCode() {
256 | return ID.hashCode() + radius * 10000 + diameter * 1000 + margin * 100 + cornerType.ordinal() * 10;
257 | }
258 |
259 | @Override
260 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
261 | messageDigest.update((ID + radius + diameter + margin + cornerType).getBytes(CHARSET));
262 | }
263 | }
264 |
--------------------------------------------------------------------------------
20 |
21 | ### Transformations
22 |
23 |
24 | # How do I use it?
25 |
26 | ## Step 1
27 |
28 | #### Gradle
29 | ```groovy
30 | repositories {
31 | mavenCentral()
32 | }
33 |
34 | dependencies {
35 | implementation 'jp.wasabeef:glide-transformations:4.3.0'
36 | // If you want to use the GPU Filters
37 | implementation 'jp.co.cyberagent.android:gpuimage:2.1.0'
38 | }
39 | ```
40 |
41 | ## Step 2
42 |
43 | Set Glide Transform.
44 |
45 | ```kotlin
46 | Glide.with(this).load(R.drawable.demo)
47 | .apply(RequestOptions.bitmapTransform(BlurTransformation(25, 3)))
48 | .into(imageView)
49 | ```
50 |
51 | ## Advanced Step 3
52 |
53 | You can set a multiple transformations.
54 |
55 | ```kotlin
56 | val multi = MultiTransformation | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid)
106 |
| [AbemaTV](https://play.google.com/store/apps/details?id=tv.abema)
107 |
| [TV Time](https://play.google.com/store/apps/details?id=com.tozelabs.tvshowtime)
108 |
| [Christmas Radio](https://play.google.com/store/apps/details?id=nl.netwaves.christmasradio)
109 |
110 |
111 |
112 | Developed By
113 | -------
114 | Daichi Furiya (Wasabeef) -
119 |
120 |
121 | Contributions
122 | -------
123 |
124 | Any contributions are welcome!
125 |
126 | Contributors
127 | -------
128 |
129 | * [start141](https://github.com/start141)
130 | * [squeeish](https://github.com/squeeish)
131 |
132 | Thanks
133 | -------
134 |
135 | * Inspired by `Picasso Transformations` in [TannerPerrien](https://github.com/TannerPerrien).
136 |
137 | License
138 | -------
139 |
140 | Copyright (C) 2020 Wasabeef
141 |
142 | Licensed under the Apache License, Version 2.0 (the "License");
143 | you may not use this file except in compliance with the License.
144 | You may obtain a copy of the License at
145 |
146 | http://www.apache.org/licenses/LICENSE-2.0
147 |
148 | Unless required by applicable law or agreed to in writing, software
149 | distributed under the License is distributed on an "AS IS" BASIS,
150 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
151 | See the License for the specific language governing permissions and
152 | limitations under the License.
153 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 | Version 4.3.0 *(2020-09-27)*
5 | ----------------------------
6 |
7 | Feature
8 | - Remove support v8 renderscript (Please use BlurTransformation)
9 |
10 | Update
11 | - minSdkVersion -> 21
12 | - GPUImage -> 2.1.0
13 | - Cleanup codes
14 |
15 | Version 4.2.0 *(2020-09-15)*
16 | ----------------------------
17 |
18 | Update:
19 | - Compile & Target SDK Version 28 -> 30
20 | - GPUImage 2.0.3 -> 2.0.4
21 | - Glide 4.9.0 -> 4.11.0
22 |
23 | Bugfix:
24 | - RoundedCornersTransformation with DIAGONAL_FROM_TOP_LEFT does not work [#178](https://github.com/wasabeef/glide-transformations/pull/178)
25 |
26 | Version 4.1.0 *(2019-08-15)*
27 | ----------------------------
28 |
29 | Add:
30 | - Support to CropCircle with Border [#136](https://github.com/wasabeef/glide-transformations/pull/136)
31 |
32 | Update:
33 | - Glide to 4.9.0
34 | - Android Gradle plugin to 3.6.0-alpha05
35 | - Kotlin to 1.3.41
36 |
37 | Bug Fix:
38 | - Fix diffrent density [#147](https://github.com/wasabeef/glide-transformations/pull/147)
39 |
40 |
41 | Version 4.0.1 *(2018-11-20)*
42 | ----------------------------
43 |
44 | Add:
45 | - consumerProguardFiles setting
46 |
47 | Version 4.0.0 *(2018-11-16)*
48 | ----------------------------
49 |
50 | Update:
51 | - Migrate to AndroidX
52 | - Remove novoda-bintray-plugin
53 |
54 | Version 3.3.0 *(2018-04-23)*
55 | ----------------------------
56 |
57 | Update:
58 | - Support Library 27.1.0 -> 27.1.1
59 | - Glide 4.6.1 -> 4.7.1
60 |
61 | Feature:
62 | - SupportRSBlurTransformation [#125](https://github.com/wasabeef/glide-transformations/pull/125)
63 | it's using RenderScript support mode but can you choose to use or not.
64 | Thank you [@fougere-mike](https://github.com/fougere-mike)
65 |
66 | Bug Fix:
67 | - Set detail of Cache key [#119](https://github.com/wasabeef/glide-transformations/issues/119)
68 |
69 | Version 3.2.0 *(2018-04-10)*
70 | ----------------------------
71 |
72 | Update:
73 | - Support Library 27.0.2 -> 27.1.0
74 |
75 | Bug Fix:
76 | - We quit use the RenderScript [#120](https://github.com/wasabeef/glide-transformations/issues/120)
77 |
78 | Version 3.1.1 *(2018-02-13)*
79 | ----------------------------
80 |
81 | Update:
82 | - Glide 4.5.0 -> 4.6.1
83 |
84 | Bug Fix:
85 | - Fix settings fot proguard.
86 |
87 | Version 3.1.0 *(2018-01-26)*
88 | ----------------------------
89 |
90 | Update:
91 | - Compile & Target SDK Version 25 -> 27
92 | - Build Tools 26.0.1 -> 27.0.3
93 | - Support Library 25.3.1 -> 27.0.2
94 | - Glide 4.0.0 -> 4.5.0
95 |
96 | Bug Fix:
97 | - [Implement equals() and hashCode() methods #105](https://github.com/wasabeef/glide-transformations/pull/105)
98 | - Use RenderScript#releaseAllContexts
99 |
100 | Version 3.0.1 *(2017-09-08)*
101 | ----------------------------
102 |
103 | Bug Fix:
104 | - [Deleted a setting for DexGuard #86](https://github.com/wasabeef/glide-transformations/issues/86)
105 |
106 | Version 3.0.0 *(2017-09-06)*
107 | ----------------------------
108 |
109 | Update:
110 | - Build Tools 25.0.2 -> 26.0.1
111 | - Min SDK Version 11 -> 14
112 | - Glide 3.7.0 -> 4.0.0
113 |
114 | Feature:
115 | - Supported Glide 4.0.0
116 |
117 | Version 2.0.2 *(2017-03-17)*
118 | ----------------------------
119 |
120 | Update:
121 | - Compile & Target SDK Version 23 -> 25
122 | - Build Tools 23.0.2 -> 25.0.2
123 | - Support Library 23.2.1 -> 25.3.0
124 | - GPUImage for Android 1.3.0 -> 1.4.1
125 |
126 | Bug Fix:
127 | - [Additional resource cleanup in RSBlur #45](https://github.com/wasabeef/glide-transformations/pull/45)
128 |
129 | Version 2.0.1 *(2016-04-21)*
130 | ----------------------------
131 |
132 | Fix:
133 | [#35](https://github.com/wasabeef/glide-transformations/issues/35)
134 | RSInvalidStateException
135 |
136 | Version 2.0.0 *(2016-03-02)*
137 | ----------------------------
138 |
139 | Say v8.RenderScript goodbye
140 |
141 | Version 1.4.0 *(2016-02-28)*
142 | ----------------------------
143 |
144 | fix Issue [#29](https://github.com/wasabeef/glide-transformations/issues/29)
145 | Use FastBlur as a fallback upon RenderScript failure.
146 |
147 | Version 1.3.1 *(2015-11-27)*
148 | ----------------------------
149 |
150 | Change the renderscriptTargetApi down to 20.
151 | Warning:Renderscript support mode is not currently supported with renderscript target 21+
152 |
153 | fix: memory leak.
154 |
155 | Version 1.3.0 *(2015-11-10)*
156 | ----------------------------
157 |
158 | add round corner type to RoundedCornersTransformation.
159 | Thanks to [kaelaela](https://github.com/kaelaela)
160 |
161 | Version 1.2.1 *(2015-09-18)*
162 | ----------------------------
163 |
164 | Merged NinePatchMaskTransformation to MaskTransformation.
165 |
166 | Version 1.2.0 *(2015-09-16)*
167 | ----------------------------
168 |
169 | add new transformations MaskTransformation and NinePatchMaskTransformation.
170 | Thanks to [start141](https://github.com/start141)
171 |
172 | Version 1.1.0 *(2015-09-05)*
173 | ----------------------------
174 |
175 | Adjustment of default parameters.
176 |
177 | Version 1.0.8 *(2015-07-24)*
178 | ----------------------------
179 |
180 | add DownSampling to BlurTransform
181 |
182 | Version 1.0.7 *(2015-07-18)*
183 | ----------------------------
184 |
185 | Bug fix : Blur not working.
186 |
187 | Version 1.0.6 *(2015-04-23)*
188 | ----------------------------
189 |
190 | add: CropType(Top, Center, Bottom) for CropTransformation.
191 |
192 | Version 1.0.5 *(2015-03-09)*
193 | ----------------------------
194 |
195 | Bug fix: Transparency.
196 |
197 | Version 1.0.4 *(2015-02-13)*
198 | ----------------------------
199 |
200 | Bug fix : remove original bitmap resource recycling.
201 |
202 | Version 1.0.3 *(2015-02-05)*
203 | ----------------------------
204 |
205 | Bug fix
206 |
207 | Version 1.0.2 *(2015-02-04)*
208 | ----------------------------
209 |
210 | Refactor: use BimapPool
211 |
212 | Version 1.0.1 *(2015-01-21)*
213 | ----------------------------
214 |
215 | fix: Blur Transformation now woking at Android 4.3
216 | add: GPUImage to Gradle dependency
217 |
218 | Version 1.0.0 *(2015-01-12)*
219 | ----------------------------
220 |
221 | Initial release.
222 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/example/src/main/java/jp/wasabeef/example/glide/MainAdapter.kt:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.example.glide
2 |
3 | import android.content.Context
4 | import android.graphics.Bitmap
5 | import android.graphics.Color
6 | import android.graphics.PointF
7 | import android.view.LayoutInflater
8 | import android.view.View
9 | import android.view.ViewGroup
10 | import android.widget.ImageView
11 | import android.widget.TextView
12 | import androidx.recyclerview.widget.RecyclerView
13 | import com.bumptech.glide.Glide
14 | import com.bumptech.glide.load.MultiTransformation
15 | import com.bumptech.glide.load.resource.bitmap.CenterCrop
16 | import com.bumptech.glide.request.RequestOptions.bitmapTransform
17 | import com.bumptech.glide.request.RequestOptions.overrideOf
18 | import jp.wasabeef.example.glide.MainAdapter.Type.*
19 | import jp.wasabeef.glide.transformations.*
20 | import jp.wasabeef.glide.transformations.CropTransformation.CropType
21 | import jp.wasabeef.glide.transformations.gpu.*
22 | import jp.wasabeef.glide.transformations.internal.Utils
23 |
24 | /**
25 | * Created by Wasabeef on 2015/01/11.
26 | */
27 | class MainAdapter(
28 | private val context: Context,
29 | private val dataSet: MutableList