• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.bumptech.glide.load;
2 
3 import com.bumptech.glide.load.engine.Resource;
4 
5 import java.io.IOException;
6 
7 /**
8  * An interface for decoding resources.
9  *
10  * @param <T> The type the resource will be decoded from (File, InputStream etc).
11  * @param <Z> The type of the decoded resource (Bitmap, Drawable etc).
12  */
13 public interface ResourceDecoder<T, Z> {
14 
15     /**
16      * Returns a decoded resource from the given data or null if no resource could be decoded.
17      * <p>
18      *     The {@code source} is managed by the caller, there's no need to close it.
19      *     The returned {@link Resource} will be {@link Resource#recycle() released} when the engine sees fit.
20      * </p>
21      * <p>
22      *     Note - The {@code width} and {@code height} arguments are hints only,
23      *     there is no requirement that the decoded resource exactly match the given dimensions.
24      *     A typical use case would be to use the target dimensions to determine
25      *     how much to downsample Bitmaps by to avoid overly large allocations.
26      * </p>
27      *
28      * @param source The data the resource should be decoded from.
29      * @param width The ideal width in pixels of the decoded resource.
30      * @param height The ideal height in pixels of the decoded resource.
31      * @throws IOException
32      */
decode(T source, int width, int height)33     Resource<Z> decode(T source, int width, int height) throws IOException;
34 
35     /**
36      * Returns an ID identifying any transformation this decoder may apply to the given data that will be mixed in to
37      * the cache key.
38      *
39      * <p>
40      *     If the decoder does not transform the data in a way that significantly affects the cached
41      *     result (ie performs no downsampling) an empty string is an appropriate id.
42      * </p>
43      */
getId()44     String getId();
45 }
46