Transformation.java revision 5f4610b54d517be58105bcf73ce3291ba79f9f40
1package com.bumptech.glide.load;
2
3import com.bumptech.glide.load.engine.Resource;
4
5/**
6 * A class for performing an arbitrary transformation on a resource.
7 *
8 * @param <T> The type of the resource being transformed.
9 */
10public interface Transformation<T> {
11
12    /**
13     * Transforms the given resource and returns the transformed resource.
14     *
15     * <p>
16     *     Note - Transformations should be idempotent so if given a resource that has already been transformed by
17     *     this transformation, this method must return the given resource object.
18     * </p>
19     *
20     * <p>
21     *     Note - If the original resource object is not returned, the original resource will be recycled and it's
22     *     internal resources may be reused. This means it is not safe to rely on the original resource or any internal
23     *     state of the original resource in any new resource that is created. Usually this shouldn't occur, but if
24     *     absolutely necessary either the original resource object can be returned with modified internal state, or
25     *     the data in the original resource can be copied into the transformed resource.
26     * </p>
27     *
28     * @param resource The resource to transform.
29     * @param outWidth The width of the view or target the resource will be displayed in.
30     * @param outHeight The height of the view or target the resource will be displayed in.
31     * @return The transformed resource.
32     */
33    public abstract Resource<T> transform(Resource<T> resource, int outWidth, int outHeight);
34
35    /**
36     * A method to get a unique identifier for this particular transformation that can be used as part of a cache key.
37     * The fully qualified class name for this class is appropriate if written out, but getClass().getName() is not
38     * because the name may be changed by proguard.
39     *
40     * <p>
41     *     If this transformation does not affect the data that will be stored in cache, returning an empty string here
42     *     is acceptable.
43     * </p>
44     *
45     * @return A string that uniquely identifies this transformation.
46     */
47    public String getId();
48}
49