| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright 2006 The Android Open Source Project |    2  * Copyright 2006 The Android Open Source Project | 
|    3  * |    3  * | 
|    4  * Use of this source code is governed by a BSD-style license that can be |    4  * Use of this source code is governed by a BSD-style license that can be | 
|    5  * found in the LICENSE file. |    5  * found in the LICENSE file. | 
|    6  */ |    6  */ | 
|    7  |    7  | 
|    8 #ifndef SkImageDecoder_DEFINED |    8 #ifndef SkImageDecoder_DEFINED | 
|    9 #define SkImageDecoder_DEFINED |    9 #define SkImageDecoder_DEFINED | 
|   10  |   10  | 
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  218  |  218  | 
|  219     /** Passed to the decode method. If kDecodeBounds_Mode is passed, then |  219     /** Passed to the decode method. If kDecodeBounds_Mode is passed, then | 
|  220         only the bitmap's info need be set. If kDecodePixels_Mode |  220         only the bitmap's info need be set. If kDecodePixels_Mode | 
|  221         is passed, then the bitmap must have pixels or a pixelRef. |  221         is passed, then the bitmap must have pixels or a pixelRef. | 
|  222     */ |  222     */ | 
|  223     enum Mode { |  223     enum Mode { | 
|  224         kDecodeBounds_Mode, //!< only return info in bitmap |  224         kDecodeBounds_Mode, //!< only return info in bitmap | 
|  225         kDecodePixels_Mode  //!< return entire bitmap (including pixels) |  225         kDecodePixels_Mode  //!< return entire bitmap (including pixels) | 
|  226     }; |  226     }; | 
|  227  |  227  | 
 |  228     /** Result of a decode. If read as a boolean, a partial success is | 
 |  229         considered a success (true). | 
 |  230     */ | 
 |  231     enum Result { | 
 |  232         kFailure        = 0,    //!< Image failed to decode. bitmap will be | 
 |  233                                 //   unchanged. | 
 |  234         kPartialSuccess = 1,    //!< Part of the image decoded. The rest is | 
 |  235                                 //   filled in automatically | 
 |  236         kSuccess        = 2     //!< The entire image was decoded, if Mode is | 
 |  237                                 //   kDecodePixels_Mode, or the bounds were | 
 |  238                                 //   decoded, in kDecodeBounds_Mode. | 
 |  239     }; | 
 |  240  | 
|  228     /** Given a stream, decode it into the specified bitmap. |  241     /** Given a stream, decode it into the specified bitmap. | 
|  229         If the decoder can decompress the image, it calls bitmap.setInfo(), |  242         If the decoder can decompress the image, it calls bitmap.setInfo(), | 
|  230         and then if the Mode is kDecodePixels_Mode, call allocPixelRef(), |  243         and then if the Mode is kDecodePixels_Mode, call allocPixelRef(), | 
|  231         which will allocated a pixelRef. To access the pixel memory, the codec |  244         which will allocated a pixelRef. To access the pixel memory, the codec | 
|  232         needs to call lockPixels/unlockPixels on the |  245         needs to call lockPixels/unlockPixels on the | 
|  233         bitmap. It can then set the pixels with the decompressed image. |  246         bitmap. It can then set the pixels with the decompressed image. | 
|  234     *   If the image cannot be decompressed, return false. After the |  247     *   If the image cannot be decompressed, return kFailure. After the | 
|  235     *   decoding, the function converts the decoded colortype in bitmap |  248     *   decoding, the function converts the decoded colortype in bitmap | 
|  236     *   to pref if possible. Whether a conversion is feasible is |  249     *   to pref if possible. Whether a conversion is feasible is | 
|  237     *   tested by Bitmap::canCopyTo(pref). |  250     *   tested by Bitmap::canCopyTo(pref). | 
|  238  |  251  | 
|  239         If an SkBitmap::Allocator is installed via setAllocator, it will be |  252         If an SkBitmap::Allocator is installed via setAllocator, it will be | 
|  240         used to allocate the pixel memory. A clever allocator can be used |  253         used to allocate the pixel memory. A clever allocator can be used | 
|  241         to allocate the memory from a cache, volatile memory, or even from |  254         to allocate the memory from a cache, volatile memory, or even from | 
|  242         an existing bitmap's memory. |  255         an existing bitmap's memory. | 
|  243  |  256  | 
|  244         If a Peeker is installed via setPeeker, it may be used to peek into |  257         If a Peeker is installed via setPeeker, it may be used to peek into | 
|  245         meta data during the decode. |  258         meta data during the decode. | 
|  246     */ |  259     */ | 
|  247     bool decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); |  260     Result decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); | 
|  248     bool decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { |  261     Result decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { | 
|  249         return this->decode(stream, bitmap, kUnknown_SkColorType, mode); |  262         return this->decode(stream, bitmap, kUnknown_SkColorType, mode); | 
|  250     } |  263     } | 
|  251  |  264  | 
|  252     /** |  265     /** | 
|  253      * Given a stream, build an index for doing tile-based decode. |  266      * Given a stream, build an index for doing tile-based decode. | 
|  254      * The built index will be saved in the decoder, and the image size will |  267      * The built index will be saved in the decoder, and the image size will | 
|  255      * be returned in width and height. |  268      * be returned in width and height. | 
|  256      * |  269      * | 
|  257      * Return true for success or false on failure. |  270      * Return true for success or false on failure. | 
|  258      */ |  271      */ | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  327                       of the decoded stream. On failure it is ignored. |  340                       of the decoded stream. On failure it is ignored. | 
|  328      */ |  341      */ | 
|  329     static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkCol
     orType pref, Mode, |  342     static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkCol
     orType pref, Mode, | 
|  330                              Format* format = NULL); |  343                              Format* format = NULL); | 
|  331     static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) { |  344     static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) { | 
|  332         return DecodeStream(stream, bitmap, kUnknown_SkColorType, kDecodePixels_
     Mode, NULL); |  345         return DecodeStream(stream, bitmap, kUnknown_SkColorType, kDecodePixels_
     Mode, NULL); | 
|  333     } |  346     } | 
|  334  |  347  | 
|  335 protected: |  348 protected: | 
|  336     // must be overridden in subclasses. This guy is called by decode(...) |  349     // must be overridden in subclasses. This guy is called by decode(...) | 
|  337     virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; |  350     virtual Result onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; | 
|  338  |  351  | 
|  339     // If the decoder wants to support tiled based decoding, |  352     // If the decoder wants to support tiled based decoding, | 
|  340     // this method must be overridden. This guy is called by buildTileIndex(...) |  353     // this method must be overridden. This guy is called by buildTileIndex(...) | 
|  341     virtual bool onBuildTileIndex(SkStreamRewindable*, int *width, int *height) 
     { |  354     virtual bool onBuildTileIndex(SkStreamRewindable*, int *width, int *height) 
     { | 
|  342         return false; |  355         return false; | 
|  343     } |  356     } | 
|  344  |  357  | 
|  345     // If the decoder wants to support tiled based decoding, |  358     // If the decoder wants to support tiled based decoding, | 
|  346     // this method must be overridden. This guy is called by decodeRegion(...) |  359     // this method must be overridden. This guy is called by decodeRegion(...) | 
|  347     virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) { |  360     virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) { | 
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  497 DECLARE_DECODER_CREATOR(PKMImageDecoder); |  510 DECLARE_DECODER_CREATOR(PKMImageDecoder); | 
|  498 DECLARE_DECODER_CREATOR(KTXImageDecoder); |  511 DECLARE_DECODER_CREATOR(KTXImageDecoder); | 
|  499 DECLARE_DECODER_CREATOR(ASTCImageDecoder); |  512 DECLARE_DECODER_CREATOR(ASTCImageDecoder); | 
|  500  |  513  | 
|  501 // Typedefs to make registering decoder and formatter callbacks easier. |  514 // Typedefs to make registering decoder and formatter callbacks easier. | 
|  502 // These have to be defined outside SkImageDecoder. :( |  515 // These have to be defined outside SkImageDecoder. :( | 
|  503 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)>        SkImageDecod
     er_DecodeReg; |  516 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)>        SkImageDecod
     er_DecodeReg; | 
|  504 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
     er_FormatReg; |  517 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
     er_FormatReg; | 
|  505  |  518  | 
|  506 #endif |  519 #endif | 
| OLD | NEW |