-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow chaining of arbitrary # of transformations
Also includes some other cleanup, including allowing arbitrary downsamplers.
- Loading branch information
Sam Judd
committed
Aug 19, 2013
1 parent
4b06daa
commit 7a58fe7
Showing
8 changed files
with
240 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
library/src/com/bumptech/glide/loader/transformation/MultiTransformation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.bumptech.glide.loader.transformation; | ||
|
||
import android.graphics.Bitmap; | ||
import com.bumptech.glide.resize.bitmap_recycle.BitmapPool; | ||
import com.bumptech.glide.resize.load.Transformation; | ||
|
||
/** | ||
* A transformation that applies an ordered array of one or more transformations to an image | ||
*/ | ||
public class MultiTransformation extends Transformation { | ||
private final Transformation[] transformations; | ||
|
||
public MultiTransformation(Transformation... transformations) { | ||
if (transformations.length < 1) { | ||
throw new IllegalArgumentException("MultiTransformation must contain at least one Transformation"); | ||
} | ||
this.transformations = transformations; | ||
} | ||
|
||
@Override | ||
public Bitmap transform(Bitmap bitmap, BitmapPool pool, int outWidth, int outHeight) { | ||
Bitmap current = null; //we don't want to recycle the original image since that | ||
//will be done by the ImageResizer | ||
Bitmap transformed; | ||
for (Transformation transformation : transformations) { | ||
transformed = transformation.transform(bitmap, pool, outWidth, outHeight); | ||
if (current != null && current != transformed) { | ||
pool.put(current); | ||
} | ||
|
||
current = transformed; | ||
} | ||
return current; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
StringBuilder sb = new StringBuilder(); | ||
for (Transformation transformation : transformations) { | ||
sb.append(transformation.getId()); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
library/src/com/bumptech/glide/loader/transformation/MultiTransformationLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.bumptech.glide.loader.transformation; | ||
|
||
import com.bumptech.glide.resize.load.Transformation; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* A TransformationLoader that uses an ordered list of one or more transformation loaders to produce | ||
* a single transformation that applies each of the {@link Transformation}s produced by the loaders | ||
* in order. | ||
*/ | ||
public class MultiTransformationLoader<T> implements TransformationLoader<T> { | ||
private final List<TransformationLoader<T>> transformationLoaders; | ||
|
||
@SuppressWarnings("unused") | ||
public MultiTransformationLoader(TransformationLoader<T>... transformationLoaders) { | ||
this(Arrays.asList(transformationLoaders)); | ||
} | ||
|
||
public MultiTransformationLoader(List<TransformationLoader<T>> transformationLoaders) { | ||
if (transformationLoaders.size() < 1) { | ||
throw new IllegalArgumentException("MultiTransformationLoader must contain at least one " + | ||
"TransformationLoader"); | ||
} | ||
this.transformationLoaders = transformationLoaders; | ||
} | ||
|
||
@Override | ||
public Transformation getTransformation(T model) { | ||
int num = transformationLoaders.size(); | ||
Transformation[] transformations = new Transformation[num]; | ||
for (int i = 0; i < num; i++) { | ||
transformations[i] = transformationLoaders.get(i).getTransformation(model); | ||
} | ||
|
||
return new MultiTransformation(transformations); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
StringBuilder sb = new StringBuilder(); | ||
for (TransformationLoader<T> transformationLoader : transformationLoaders) { | ||
sb.append(transformationLoader.getId()); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.