SkImageDecoder.h revision 2766c00fc0b6a07d46e5f74cdad45da2ef625237
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkImageDecoder_DEFINED 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkImageDecoder_DEFINED 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmap.h" 12f8d7d2731318cdf510ab68e6b3f5ec68ab22c8e2scroggo@google.com#include "SkImage.h" 13a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org#include "SkRect.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h" 15bd6343b1d60d2a85e930f33f4b06b4502b3e8caamtklein@google.com#include "SkTRegistry.h" 167def5e1630d47cdbfa4b58a9c86bc060693c4d79scroggo@google.com#include "SkTypes.h" 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkStream; 19b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.comclass SkStreamRewindable; 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkImageDecoder 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Base class for decoding compressed images into a SkBitmap 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 25e3beb6bd7de7fa211681abbb0be58e80b19885e0commit-bot@chromium.orgclass SkImageDecoder : SkNoncopyable { 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkImageDecoder(); 2825e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 291dd3ea9d4523436578c86dc8d8f43d63fa188c01scroggo // TODO (scroggo): Merge with SkEncodedFormat 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Format { 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kUnknown_Format, 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kBMP_Format, 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kGIF_Format, 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kICO_Format, 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kJPEG_Format, 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPNG_Format, 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kWBMP_Format, 38a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org kWEBP_Format, 398cf81e0f4fa2a8054ac4cea1e7490028809cb893robertphillips@google.com kPKM_Format, 4099ffe24200d8940ceba20f6fbf8c460f994d3cd1krajcevski kKTX_Format, 4195b1b3d82d227141647777d83324aa570b530096krajcevski kASTC_Format, 4225e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 4399ffe24200d8940ceba20f6fbf8c460f994d3cd1krajcevski kLastKnownFormat = kKTX_Format, 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 4525e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 464c6adf9a089dbdd541f25d01d257ec05aedcb57dscroggo@google.com /** Return the format of image this decoder can decode. If this decoder can decode multiple 474c6adf9a089dbdd541f25d01d257ec05aedcb57dscroggo@google.com formats, kUnknown_Format will be returned. 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual Format getFormat() const; 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 51b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi /** If planes or rowBytes is NULL, decodes the header and computes componentSizes 52b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi for memory allocation. 53b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi Otherwise, decodes the YUV planes into the provided image planes and 54b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi updates componentSizes to the final image size. 55b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi Returns whether the decoding was successful. 56b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi */ 57b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi bool decodeYUV8Planes(SkStream* stream, SkISize componentSizes[3], void* planes[3], 58b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi size_t rowBytes[3], SkYUVColorSpace*); 59b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi 60b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com /** Return the format of the SkStreamRewindable or kUnknown_Format if it cannot be determined. 61b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com Rewinds the stream before returning. 6239edf4cd94e6fbeb8c1187a588b314e9795c81e4scroggo@google.com */ 63b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com static Format GetStreamFormat(SkStreamRewindable*); 6439edf4cd94e6fbeb8c1187a588b314e9795c81e4scroggo@google.com 65f98118e65cbcee064bb8034f94a4faf4ea8d5536scroggo@google.com /** Return a readable string of the Format provided. 66f98118e65cbcee064bb8034f94a4faf4ea8d5536scroggo@google.com */ 67f98118e65cbcee064bb8034f94a4faf4ea8d5536scroggo@google.com static const char* GetFormatName(Format); 68f98118e65cbcee064bb8034f94a4faf4ea8d5536scroggo@google.com 694c6adf9a089dbdd541f25d01d257ec05aedcb57dscroggo@google.com /** Return a readable string of the value returned by getFormat(). 70a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 71a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org const char* getFormatName() const; 72a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 738d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com /** Whether the decoder should skip writing zeroes to output if possible. 748d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com */ 758d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com bool getSkipWritingZeroes() const { return fSkipWritingZeroes; } 768d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com 778d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com /** Set to true if the decoder should skip writing any zeroes when 788d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com creating the output image. 798d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com This is a hint that may not be respected by the decoder. 808d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com It should only be used if it is known that the memory to write 818d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com to has already been set to 0; otherwise the resulting image will 828d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com have garbage. 838d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com This is ideal for images that contain a lot of completely transparent 848d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com pixels, but may be a performance hit for an image that has only a 858d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com few transparent pixels. 868d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com The default is false. 878d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com */ 888d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com void setSkipWritingZeroes(bool skip) { fSkipWritingZeroes = skip; } 898d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the decoder should try to dither the resulting image. 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The default setting is true. 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool getDitherImage() const { return fDitherImage; } 9425e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set to true if the the decoder should try to dither the resulting image. 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The default setting is true. 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setDitherImage(bool dither) { fDitherImage = dither; } 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 100a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org /** Returns true if the decoder should try to decode the 101a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org resulting image to a higher quality even at the expense of 102a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org the decoding speed. 103a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 104a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org bool getPreferQualityOverSpeed() const { return fPreferQualityOverSpeed; } 105a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 106a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org /** Set to true if the the decoder should try to decode the 107a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org resulting image to a higher quality even at the expense of 108a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org the decoding speed. 109a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 110a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org void setPreferQualityOverSpeed(bool qualityOverSpeed) { 111a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org fPreferQualityOverSpeed = qualityOverSpeed; 112a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org } 113a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 1142bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com /** Set to true to require the decoder to return a bitmap with unpremultiplied 1152bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com colors. The default is false, meaning the resulting bitmap will have its 1162bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com colors premultiplied. 1172bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com NOTE: Passing true to this function may result in a bitmap which cannot 1182bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com be properly used by Skia. 1192bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com */ 1202bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com void setRequireUnpremultipliedColors(bool request) { 1212bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com fRequireUnpremultipliedColors = request; 1222bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com } 1232bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com 1242bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com /** Returns true if the decoder will only return bitmaps with unpremultiplied 1252bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com colors. 1262bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com */ 1272bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com bool getRequireUnpremultipliedColors() const { return fRequireUnpremultipliedColors; } 1282bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class Peeker 13025e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Base class for optional callbacks to retrieve meta/chunk data out of 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com an image as it is being decoded. 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Peeker : public SkRefCnt { 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true to continue decoding, or false to indicate an error, which 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will cause the decoder to not return the image. 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool peek(const char tag[], const void* data, size_t length) = 0; 14015e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com private: 14115e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com typedef SkRefCnt INHERITED; 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Peeker* getPeeker() const { return fPeeker; } 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Peeker* setPeeker(Peeker*); 14625e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 147be08aceaab724b21136d7654fa86315850e9993creed /** 148be08aceaab724b21136d7654fa86315850e9993creed * By default, the codec will try to comply with the "pref" colortype 149be08aceaab724b21136d7654fa86315850e9993creed * that is passed to decode() or decodeSubset(). However, this can be called 150be08aceaab724b21136d7654fa86315850e9993creed * to override that, causing the codec to try to match the src depth instead 151be08aceaab724b21136d7654fa86315850e9993creed * (as shown below). 152be08aceaab724b21136d7654fa86315850e9993creed * 153be08aceaab724b21136d7654fa86315850e9993creed * src_8Index -> kIndex_8_SkColorType 154be08aceaab724b21136d7654fa86315850e9993creed * src_8Gray -> kN32_SkColorType 155be08aceaab724b21136d7654fa86315850e9993creed * src_8bpc -> kN32_SkColorType 156be08aceaab724b21136d7654fa86315850e9993creed */ 157be08aceaab724b21136d7654fa86315850e9993creed void setPreserveSrcDepth(bool preserve) { 158be08aceaab724b21136d7654fa86315850e9993creed fPreserveSrcDepth = preserve; 159be08aceaab724b21136d7654fa86315850e9993creed } 160be08aceaab724b21136d7654fa86315850e9993creed 1618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap::Allocator* getAllocator() const { return fAllocator; } 1628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap::Allocator* setAllocator(SkBitmap::Allocator*); 1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // sample-size, if set to > 1, tells the decoder to return a smaller than 1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // original bitmap, sampling 1 pixel for every size pixels. e.g. if sample 1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // size is set to 3, then the returned bitmap will be 1/3 as wide and high, 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // and will contain 1/9 as many pixels as the original. 1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Note: this is a hint, and the codec may choose to ignore this, or only 1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // approximate the sample size. 1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int getSampleSize() const { return fSampleSize; } 1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setSampleSize(int size); 17225e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Reset the sampleSize to its default of 1 1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void resetSampleSize() { this->setSampleSize(1); } 1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Decoding is synchronous, but for long decodes, a different thread can 1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call this method safely. This sets a state that the decoders will 1798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com periodically check, and if they see it changed to cancel, they will 1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com cancel. This will result in decode() returning false. However, there is 1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com no guarantee that the decoder will see the state change in time, so 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com it is possible that cancelDecode() will be called, but will be ignored 1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and decode() will return true (assuming no other problems were 1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com encountered). 18525e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This state is automatically reset at the beginning of decode(). 1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void cancelDecode() { 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now the subclass must query shouldCancelDecode() to be informed 1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // of the request 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fShouldCancelDecode = true; 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Passed to the decode method. If kDecodeBounds_Mode is passed, then 195bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed only the bitmap's info need be set. If kDecodePixels_Mode 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is passed, then the bitmap must have pixels or a pixelRef. 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Mode { 199bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed kDecodeBounds_Mode, //!< only return info in bitmap 2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kDecodePixels_Mode //!< return entire bitmap (including pixels) 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 20225e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 2032a1208017dd676f94a53bbb228197c3978dbdd8ascroggo /** Result of a decode. If read as a boolean, a partial success is 2042a1208017dd676f94a53bbb228197c3978dbdd8ascroggo considered a success (true). 2052a1208017dd676f94a53bbb228197c3978dbdd8ascroggo */ 2062a1208017dd676f94a53bbb228197c3978dbdd8ascroggo enum Result { 2072a1208017dd676f94a53bbb228197c3978dbdd8ascroggo kFailure = 0, //!< Image failed to decode. bitmap will be 2082a1208017dd676f94a53bbb228197c3978dbdd8ascroggo // unchanged. 2092a1208017dd676f94a53bbb228197c3978dbdd8ascroggo kPartialSuccess = 1, //!< Part of the image decoded. The rest is 2102a1208017dd676f94a53bbb228197c3978dbdd8ascroggo // filled in automatically 2112a1208017dd676f94a53bbb228197c3978dbdd8ascroggo kSuccess = 2 //!< The entire image was decoded, if Mode is 2122a1208017dd676f94a53bbb228197c3978dbdd8ascroggo // kDecodePixels_Mode, or the bounds were 2132a1208017dd676f94a53bbb228197c3978dbdd8ascroggo // decoded, in kDecodeBounds_Mode. 2142a1208017dd676f94a53bbb228197c3978dbdd8ascroggo }; 2152a1208017dd676f94a53bbb228197c3978dbdd8ascroggo 2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Given a stream, decode it into the specified bitmap. 217bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed If the decoder can decompress the image, it calls bitmap.setInfo(), 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and then if the Mode is kDecodePixels_Mode, call allocPixelRef(), 2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com which will allocated a pixelRef. To access the pixel memory, the codec 2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com needs to call lockPixels/unlockPixels on the 2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap. It can then set the pixels with the decompressed image. 2222a1208017dd676f94a53bbb228197c3978dbdd8ascroggo * If the image cannot be decompressed, return kFailure. After the 223bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed * decoding, the function converts the decoded colortype in bitmap 22425e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com * to pref if possible. Whether a conversion is feasible is 22525e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com * tested by Bitmap::canCopyTo(pref). 22625e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 227bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com If an SkBitmap::Allocator is installed via setAllocator, it will be 228bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com used to allocate the pixel memory. A clever allocator can be used 229bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com to allocate the memory from a cache, volatile memory, or even from 230bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com an existing bitmap's memory. 231bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com 232bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com If a Peeker is installed via setPeeker, it may be used to peek into 233bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com meta data during the decode. 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2352a1208017dd676f94a53bbb228197c3978dbdd8ascroggo Result decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); 2362a1208017dd676f94a53bbb228197c3978dbdd8ascroggo Result decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { 237bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed return this->decode(stream, bitmap, kUnknown_SkColorType, mode); 2383f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com } 2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 240a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org /** 241a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * Given a stream, build an index for doing tile-based decode. 242a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * The built index will be saved in the decoder, and the image size will 243a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * be returned in width and height. 244a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * 245a1193e4b0e34a7e4e1bd33e9708d7341679f8321scroggo * Takes ownership of the SkStreamRewindable, on success or failure. 246a1193e4b0e34a7e4e1bd33e9708d7341679f8321scroggo * 247a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * Return true for success or false on failure. 248a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 249b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com bool buildTileIndex(SkStreamRewindable*, int *width, int *height); 250a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 251a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org /** 2527e6fceeffd250d99eff9f1dbb459a916ae4a754escroggo@google.com * Decode a rectangle subset in the image. 253a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * The method can only be called after buildTileIndex(). 254a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * 255a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * Return true for success. 256a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * Return false if the index is never built or failing in decoding. 257a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 258bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed bool decodeSubset(SkBitmap* bm, const SkIRect& subset, SkColorType pref); 2597e6fceeffd250d99eff9f1dbb459a916ae4a754escroggo@google.com 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Given a stream, this will try to find an appropriate decoder object. 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If none is found, the method returns NULL. 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 263b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com static SkImageDecoder* Factory(SkStreamRewindable*); 264a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com 2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Decode the image stored in the specified file, and store the result 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in bitmap. Return true for success or false on failure. 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 268207a1c96ee789cc25a43e797b0729dd94dc747a5scroggo @param pref Prefer this colortype. 26931d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com 270b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com @param format On success, if format is non-null, it is set to the format 271b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com of the decoded file. On failure it is ignored. 2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 273bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed static bool DecodeFile(const char file[], SkBitmap* bitmap, SkColorType pref, Mode, 27431d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com Format* format = NULL); 275b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com static bool DecodeFile(const char file[], SkBitmap* bitmap) { 276bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed return DecodeFile(file, bitmap, kUnknown_SkColorType, kDecodePixels_Mode, NULL); 2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 278bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed 2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Decode the image stored in the specified memory buffer, and store the 2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com result in bitmap. Return true for success or false on failure. 2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 282207a1c96ee789cc25a43e797b0729dd94dc747a5scroggo @param pref Prefer this colortype. 28331d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com 28431d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com @param format On success, if format is non-null, it is set to the format 285b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com of the decoded buffer. On failure it is ignored. 286b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com */ 287bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, SkColorType pref, 288bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed Mode, Format* format = NULL); 289b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){ 290bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed return DecodeMemory(buffer, size, bitmap, kUnknown_SkColorType, kDecodePixels_Mode, NULL); 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 292f8d7d2731318cdf510ab68e6b3f5ec68ab22c8e2scroggo@google.com 293b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com /** Decode the image stored in the specified SkStreamRewindable, and store the result 2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in bitmap. Return true for success or false on failure. 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 296207a1c96ee789cc25a43e797b0729dd94dc747a5scroggo @param pref Prefer this colortype. 29731d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com 298b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com @param format On success, if format is non-null, it is set to the format 299b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com of the decoded stream. On failure it is ignored. 300b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com */ 301bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkColorType pref, Mode, 30231d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com Format* format = NULL); 303b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) { 304bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed return DecodeStream(stream, bitmap, kUnknown_SkColorType, kDecodePixels_Mode, NULL); 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 30625e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // must be overridden in subclasses. This guy is called by decode(...) 3092a1208017dd676f94a53bbb228197c3978dbdd8ascroggo virtual Result onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; 3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 311a1193e4b0e34a7e4e1bd33e9708d7341679f8321scroggo // If the decoder wants to support tiled based decoding, this method must be overridden. 312a1193e4b0e34a7e4e1bd33e9708d7341679f8321scroggo // This is called by buildTileIndex(...) 313a1193e4b0e34a7e4e1bd33e9708d7341679f8321scroggo virtual bool onBuildTileIndex(SkStreamRewindable*, int* /*width*/, int* /*height*/); 314a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 315a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org // If the decoder wants to support tiled based decoding, 316a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org // this method must be overridden. This guy is called by decodeRegion(...) 317c87dd2ce965cd1bbc8a74abe0c141658a469d7f2djsollen virtual bool onDecodeSubset(SkBitmap*, const SkIRect&) { 318a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org return false; 319a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org } 320a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 321b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi /** If planes or rowBytes is NULL, decodes the header and computes componentSizes 322b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi for memory allocation. 323b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi Otherwise, decodes the YUV planes into the provided image planes and 324b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi updates componentSizes to the final image size. 325b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi Returns whether the decoding was successful. 326b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi */ 327c87dd2ce965cd1bbc8a74abe0c141658a469d7f2djsollen virtual bool onDecodeYUV8Planes(SkStream*, SkISize[3] /*componentSizes*/, 328c87dd2ce965cd1bbc8a74abe0c141658a469d7f2djsollen void*[3] /*planes*/, size_t[3] /*rowBytes*/, 329c87dd2ce965cd1bbc8a74abe0c141658a469d7f2djsollen SkYUVColorSpace*) { 330b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi return false; 331b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi } 332b227e37eae36ccf630c4baef00b1354d42b40fd1sugoi 333a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org /* 334a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * Crop a rectangle from the src Bitmap to the dest Bitmap. src and dst are 335a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * both sampled by sampleSize from an original Bitmap. 336a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * 337a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * @param dst the destination bitmap. 338a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * @param src the source bitmap that is sampled by sampleSize from the 339a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * original bitmap. 340a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * @param sampleSize the sample size that src is sampled from the original bitmap. 341a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * @param (dstX, dstY) the upper-left point of the dest bitmap in terms of 342a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * the coordinate in the original bitmap. 343a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * @param (width, height) the width and height of the unsampled dst. 3447e6fceeffd250d99eff9f1dbb459a916ae4a754escroggo@google.com * @param (srcX, srcY) the upper-left point of the src bitmap in terms of 345a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * the coordinate in the original bitmap. 3467e6fceeffd250d99eff9f1dbb459a916ae4a754escroggo@google.com * @return bool Whether or not it succeeded. 347a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 3487e6fceeffd250d99eff9f1dbb459a916ae4a754escroggo@google.com bool cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, 349a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org int dstX, int dstY, int width, int height, 350a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org int srcX, int srcY); 351a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 352468142b2f50de055f00d5684515d962777da5131scroggo@google.com /** 353468142b2f50de055f00d5684515d962777da5131scroggo@google.com * Copy all fields on this decoder to the other decoder. Used by subclasses 354468142b2f50de055f00d5684515d962777da5131scroggo@google.com * to decode a subimage using a different decoder, but with the same settings. 355468142b2f50de055f00d5684515d962777da5131scroggo@google.com */ 356468142b2f50de055f00d5684515d962777da5131scroggo@google.com void copyFieldsToOther(SkImageDecoder* other); 357a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Can be queried from within onDecode, to see if the user (possibly in 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com a different thread) has requested the decode to cancel. If this returns 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com true, your onDecode() should stop and return false. 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Each subclass needs to decide how often it can query this, to balance 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com responsiveness with performance. 36325e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Calling this outside of onDecode() may return undefined values. 3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool shouldCancelDecode() const { return fShouldCancelDecode; } 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 37025e9834c03a050afbf339f457b8c401aecb26c0bweita@google.comprotected: 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkImageDecoder(); 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 373bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed /** 374bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed * Return the default preference being used by the current or latest call to decode. 375bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed */ 376bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed SkColorType getDefaultPref() { return fDefaultPref; } 3772766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein 378bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed /* Helper for subclasses. Call this to allocate the pixel memory given the bitmap's info. 379bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed Returns true on success. This method handles checking for an optional Allocator. 3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool allocPixelRef(SkBitmap*, SkColorTable*) const; 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 383f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com /** 384f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * The raw data of the src image. 385f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com */ 3863f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com enum SrcDepth { 387f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com // Color-indexed. 3883f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com kIndex_SrcDepth, 389f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com // Grayscale in 8 bits. 390f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com k8BitGray_SrcDepth, 391f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com // 8 bits per component. Used for 24 bit if there is no alpha. 392f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com k32Bit_SrcDepth, 3933f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com }; 3946c22573edb234ad14df947278cfed010669a39a7reed /** The subclass, inside onDecode(), calls this to determine the colorType of 3953f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the 3963f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com src image. This routine returns the caller's preference given 3976c22573edb234ad14df947278cfed010669a39a7reed srcDepth and hasAlpha, or kUnknown_SkColorType if there is no preference. 3983f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com */ 3996c22573edb234ad14df947278cfed010669a39a7reed SkColorType getPrefColorType(SrcDepth, bool hasAlpha) const; 4003f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com 4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Peeker* fPeeker; 4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap::Allocator* fAllocator; 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fSampleSize; 405bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed SkColorType fDefaultPref; // use if fUsePrefTable is false 406be08aceaab724b21136d7654fa86315850e9993creed bool fPreserveSrcDepth; 407c3b3266b7db2f1a41d41ecac010c766b7ad8eebcreed bool fDitherImage; 4088d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com bool fSkipWritingZeroes; 4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable bool fShouldCancelDecode; 410a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org bool fPreferQualityOverSpeed; 4112bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com bool fRequireUnpremultipliedColors; 4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 414a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com/** Calling newDecoder with a stream returns a new matching imagedecoder 415a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com instance, or NULL if none can be found. The caller must manage its ownership 416a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com of the stream as usual, calling unref() when it is done, as the returned 417a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com decoder may have called ref() (and if so, the decoder is responsible for 418a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com balancing its ownership when it is destroyed). 419a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com */ 420a14ea0e930c82daa2364ece4bd0b06256272302areed@android.comclass SkImageDecoderFactory : public SkRefCnt { 421a14ea0e930c82daa2364ece4bd0b06256272302areed@android.compublic: 4222766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein 42315e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 424b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com virtual SkImageDecoder* newDecoder(SkStreamRewindable*) = 0; 42515e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 42615e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.comprivate: 42715e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com typedef SkRefCnt INHERITED; 428a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com}; 429a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com 430a14ea0e930c82daa2364ece4bd0b06256272302areed@android.comclass SkDefaultImageDecoderFactory : SkImageDecoderFactory { 431a14ea0e930c82daa2364ece4bd0b06256272302areed@android.compublic: 432a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com // calls SkImageDecoder::Factory(stream) 433b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com virtual SkImageDecoder* newDecoder(SkStreamRewindable* stream) { 434a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com return SkImageDecoder::Factory(stream); 435a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com } 436a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com}; 437a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com 438ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// This macro declares a global (i.e., non-class owned) creation entry point 439ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// for each decoder (e.g., CreateJPEGImageDecoder) 440ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com#define DECLARE_DECODER_CREATOR(codec) \ 441ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com SkImageDecoder *Create ## codec (); 442ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com 443ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// This macro defines the global creation entry point for each decoder. Each 444ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// decoder implementation that registers with the decoder factory must call it. 445ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com#define DEFINE_DECODER_CREATOR(codec) \ 446ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com SkImageDecoder *Create ## codec () { \ 447ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com return SkNEW( Sk ## codec ); \ 448ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com } 449ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com 450ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// All the decoders known by Skia. Note that, depending on the compiler settings, 451ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// not all of these will be available 452ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(BMPImageDecoder); 453ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(GIFImageDecoder); 454ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(ICOImageDecoder); 455ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(JPEGImageDecoder); 456ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(PNGImageDecoder); 457ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(WBMPImageDecoder); 458a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.orgDECLARE_DECODER_CREATOR(WEBPImageDecoder); 4598cf81e0f4fa2a8054ac4cea1e7490028809cb893robertphillips@google.comDECLARE_DECODER_CREATOR(PKMImageDecoder); 46099ffe24200d8940ceba20f6fbf8c460f994d3cd1krajcevskiDECLARE_DECODER_CREATOR(KTXImageDecoder); 46195b1b3d82d227141647777d83324aa570b530096krajcevskiDECLARE_DECODER_CREATOR(ASTCImageDecoder); 462bd6343b1d60d2a85e930f33f4b06b4502b3e8caamtklein@google.com 463bd6343b1d60d2a85e930f33f4b06b4502b3e8caamtklein@google.com// Typedefs to make registering decoder and formatter callbacks easier. 464bd6343b1d60d2a85e930f33f4b06b4502b3e8caamtklein@google.com// These have to be defined outside SkImageDecoder. :( 465b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.comtypedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecoder_DecodeReg; 466b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.comtypedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecoder_FormatReg; 467bd6343b1d60d2a85e930f33f4b06b4502b3e8caamtklein@google.com 4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 469