SkImageDecoder.h revision be08aceaab724b21136d7654fa86315850e9993c
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 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Format { 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kUnknown_Format, 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kBMP_Format, 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kGIF_Format, 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kICO_Format, 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kJPEG_Format, 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPNG_Format, 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kWBMP_Format, 37a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org kWEBP_Format, 388cf81e0f4fa2a8054ac4cea1e7490028809cb893robertphillips@google.com kPKM_Format, 3999ffe24200d8940ceba20f6fbf8c460f994d3cd1krajcevski kKTX_Format, 4025e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 4199ffe24200d8940ceba20f6fbf8c460f994d3cd1krajcevski kLastKnownFormat = kKTX_Format, 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 4325e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 444c6adf9a089dbdd541f25d01d257ec05aedcb57dscroggo@google.com /** Return the format of image this decoder can decode. If this decoder can decode multiple 454c6adf9a089dbdd541f25d01d257ec05aedcb57dscroggo@google.com formats, kUnknown_Format will be returned. 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual Format getFormat() const; 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 49b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com /** Return the format of the SkStreamRewindable or kUnknown_Format if it cannot be determined. 50b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com Rewinds the stream before returning. 5139edf4cd94e6fbeb8c1187a588b314e9795c81e4scroggo@google.com */ 52b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com static Format GetStreamFormat(SkStreamRewindable*); 5339edf4cd94e6fbeb8c1187a588b314e9795c81e4scroggo@google.com 54f98118e65cbcee064bb8034f94a4faf4ea8d5536scroggo@google.com /** Return a readable string of the Format provided. 55f98118e65cbcee064bb8034f94a4faf4ea8d5536scroggo@google.com */ 56f98118e65cbcee064bb8034f94a4faf4ea8d5536scroggo@google.com static const char* GetFormatName(Format); 57f98118e65cbcee064bb8034f94a4faf4ea8d5536scroggo@google.com 584c6adf9a089dbdd541f25d01d257ec05aedcb57dscroggo@google.com /** Return a readable string of the value returned by getFormat(). 59a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 60a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org const char* getFormatName() const; 61a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 628d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com /** Whether the decoder should skip writing zeroes to output if possible. 638d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com */ 648d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com bool getSkipWritingZeroes() const { return fSkipWritingZeroes; } 658d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com 668d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com /** Set to true if the decoder should skip writing any zeroes when 678d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com creating the output image. 688d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com This is a hint that may not be respected by the decoder. 698d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com It should only be used if it is known that the memory to write 708d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com to has already been set to 0; otherwise the resulting image will 718d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com have garbage. 728d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com This is ideal for images that contain a lot of completely transparent 738d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com pixels, but may be a performance hit for an image that has only a 748d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com few transparent pixels. 758d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com The default is false. 768d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com */ 778d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com void setSkipWritingZeroes(bool skip) { fSkipWritingZeroes = skip; } 788d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the decoder should try to dither the resulting image. 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The default setting is true. 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool getDitherImage() const { return fDitherImage; } 8325e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set to true if the the decoder should try to dither the resulting image. 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The default setting is true. 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setDitherImage(bool dither) { fDitherImage = dither; } 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 89a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org /** Returns true if the decoder should try to decode the 90a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org resulting image to a higher quality even at the expense of 91a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org the decoding speed. 92a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 93a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org bool getPreferQualityOverSpeed() const { return fPreferQualityOverSpeed; } 94a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 95a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org /** Set to true if the the decoder should try to decode the 96a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org resulting image to a higher quality even at the expense of 97a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org the decoding speed. 98a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 99a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org void setPreferQualityOverSpeed(bool qualityOverSpeed) { 100a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org fPreferQualityOverSpeed = qualityOverSpeed; 101a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org } 102a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 1032bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com /** Set to true to require the decoder to return a bitmap with unpremultiplied 1042bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com colors. The default is false, meaning the resulting bitmap will have its 1052bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com colors premultiplied. 1062bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com NOTE: Passing true to this function may result in a bitmap which cannot 1072bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com be properly used by Skia. 1082bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com */ 1092bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com void setRequireUnpremultipliedColors(bool request) { 1102bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com fRequireUnpremultipliedColors = request; 1112bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com } 1122bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com 1132bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com /** Returns true if the decoder will only return bitmaps with unpremultiplied 1142bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com colors. 1152bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com */ 1162bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com bool getRequireUnpremultipliedColors() const { return fRequireUnpremultipliedColors; } 1172bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com 1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class Peeker 11925e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Base class for optional callbacks to retrieve meta/chunk data out of 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com an image as it is being decoded. 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Peeker : public SkRefCnt { 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 12515e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com SK_DECLARE_INST_COUNT(Peeker) 12615e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true to continue decoding, or false to indicate an error, which 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will cause the decoder to not return the image. 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool peek(const char tag[], const void* data, size_t length) = 0; 13115e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com private: 13215e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com typedef SkRefCnt INHERITED; 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Peeker* getPeeker() const { return fPeeker; } 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Peeker* setPeeker(Peeker*); 13725e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 1385926b86b90c68bffefbdc8639e41b5bc9102cec6reed#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER 139bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com /** \class Chooser 14025e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 141bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com Base class for optional callbacks to choose an image from a format that 142bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com contains multiple images. 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Chooser : public SkRefCnt { 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 14615e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com SK_DECLARE_INST_COUNT(Chooser) 14715e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void begin(int count) {} 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void inspect(int index, SkBitmap::Config config, int width, int height) {} 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the index of the subimage you want, or -1 to choose none of them. 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual int choose() = 0; 15315e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 15415e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com private: 15515e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com typedef SkRefCnt INHERITED; 1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Chooser* getChooser() const { return fChooser; } 1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Chooser* setChooser(Chooser*); 1605926b86b90c68bffefbdc8639e41b5bc9102cec6reed#endif 1618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 162c3b3266b7db2f1a41d41ecac010c766b7ad8eebcreed#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG 163f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com /** 164f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * Optional table describing the caller's preferred config based on 165f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * information about the src data. Each field should be set to the 166f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * preferred config for a src described in the name of the field. The 167f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * src attributes are described in terms of depth (8-index, 168f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * 8bit-grayscale, or 8-bits/component) and whether there is per-pixel 169f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * alpha (does not apply to grayscale). If the caller has no preference 170f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * for a particular src type, its slot should be set to kNo_Config. 171f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * 172f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * NOTE ABOUT PREFERRED CONFIGS: 173f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * If a config is preferred, either using a pref table or as a parameter 174f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * to some flavor of decode, it is still at the discretion of the codec 175f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * as to what output config is actually returned, as it may not be able 176f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * to support the caller's preference. 177f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * 178f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * If a bitmap is decoded into SkBitmap::A8_Config, the resulting bitmap 179f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * will either be a conversion of the grayscale in the case of a 180f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * grayscale source or the alpha channel in the case of a source with 181f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * an alpha channel. 182f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com */ 183f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com struct PrefConfigTable { 184f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com SkBitmap::Config fPrefFor_8Index_NoAlpha_src; 185f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com SkBitmap::Config fPrefFor_8Index_YesAlpha_src; 186f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com SkBitmap::Config fPrefFor_8Gray_src; 187f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com SkBitmap::Config fPrefFor_8bpc_NoAlpha_src; 188f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com SkBitmap::Config fPrefFor_8bpc_YesAlpha_src; 189f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com }; 190f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com 191f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com /** 192f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * Set an optional table for specifying the caller's preferred config 193f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * based on information about the src data. 194f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * 195f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * The default is no preference, which will assume the config set by 196f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * decode is preferred. 197f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com */ 198f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com void setPrefConfigTable(const PrefConfigTable&); 199f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com 200f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com /** 201f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * Do not use a PrefConfigTable to determine the output config. This 202f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * is the default, so there is no need to call unless a PrefConfigTable 203f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * was previously set. 204f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com */ 205f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com void resetPrefConfigTable() { fUsePrefTable = false; } 206c3b3266b7db2f1a41d41ecac010c766b7ad8eebcreed#endif 207f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com 208be08aceaab724b21136d7654fa86315850e9993creed /** 209be08aceaab724b21136d7654fa86315850e9993creed * By default, the codec will try to comply with the "pref" colortype 210be08aceaab724b21136d7654fa86315850e9993creed * that is passed to decode() or decodeSubset(). However, this can be called 211be08aceaab724b21136d7654fa86315850e9993creed * to override that, causing the codec to try to match the src depth instead 212be08aceaab724b21136d7654fa86315850e9993creed * (as shown below). 213be08aceaab724b21136d7654fa86315850e9993creed * 214be08aceaab724b21136d7654fa86315850e9993creed * src_8Index -> kIndex_8_SkColorType 215be08aceaab724b21136d7654fa86315850e9993creed * src_8Gray -> kN32_SkColorType 216be08aceaab724b21136d7654fa86315850e9993creed * src_8bpc -> kN32_SkColorType 217be08aceaab724b21136d7654fa86315850e9993creed */ 218be08aceaab724b21136d7654fa86315850e9993creed void setPreserveSrcDepth(bool preserve) { 219be08aceaab724b21136d7654fa86315850e9993creed fPreserveSrcDepth = preserve; 220be08aceaab724b21136d7654fa86315850e9993creed } 221be08aceaab724b21136d7654fa86315850e9993creed 2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap::Allocator* getAllocator() const { return fAllocator; } 2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap::Allocator* setAllocator(SkBitmap::Allocator*); 2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // sample-size, if set to > 1, tells the decoder to return a smaller than 2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // original bitmap, sampling 1 pixel for every size pixels. e.g. if sample 2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // size is set to 3, then the returned bitmap will be 1/3 as wide and high, 2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // and will contain 1/9 as many pixels as the original. 2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Note: this is a hint, and the codec may choose to ignore this, or only 2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // approximate the sample size. 2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int getSampleSize() const { return fSampleSize; } 2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setSampleSize(int size); 23325e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Reset the sampleSize to its default of 1 2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void resetSampleSize() { this->setSampleSize(1); } 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Decoding is synchronous, but for long decodes, a different thread can 2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call this method safely. This sets a state that the decoders will 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com periodically check, and if they see it changed to cancel, they will 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com cancel. This will result in decode() returning false. However, there is 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com no guarantee that the decoder will see the state change in time, so 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com it is possible that cancelDecode() will be called, but will be ignored 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and decode() will return true (assuming no other problems were 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com encountered). 24625e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This state is automatically reset at the beginning of decode(). 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void cancelDecode() { 2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now the subclass must query shouldCancelDecode() to be informed 2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // of the request 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fShouldCancelDecode = true; 2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Passed to the decode method. If kDecodeBounds_Mode is passed, then 256bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed only the bitmap's info need be set. If kDecodePixels_Mode 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is passed, then the bitmap must have pixels or a pixelRef. 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Mode { 260bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed kDecodeBounds_Mode, //!< only return info in bitmap 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kDecodePixels_Mode //!< return entire bitmap (including pixels) 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 26325e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Given a stream, decode it into the specified bitmap. 265bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed If the decoder can decompress the image, it calls bitmap.setInfo(), 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and then if the Mode is kDecodePixels_Mode, call allocPixelRef(), 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com which will allocated a pixelRef. To access the pixel memory, the codec 2688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com needs to call lockPixels/unlockPixels on the 2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap. It can then set the pixels with the decompressed image. 27025e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com * If the image cannot be decompressed, return false. After the 271bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed * decoding, the function converts the decoded colortype in bitmap 27225e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com * to pref if possible. Whether a conversion is feasible is 27325e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com * tested by Bitmap::canCopyTo(pref). 27425e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 275bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com If an SkBitmap::Allocator is installed via setAllocator, it will be 276bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com used to allocate the pixel memory. A clever allocator can be used 277bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com to allocate the memory from a cache, volatile memory, or even from 278bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com an existing bitmap's memory. 279bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com 280bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com If a Peeker is installed via setPeeker, it may be used to peek into 281bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com meta data during the decode. 2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 283bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed bool decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); 284bc69ce982f8374742ca910587485f0d741350c2dscroggo@google.com bool decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { 285bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed return this->decode(stream, bitmap, kUnknown_SkColorType, mode); 2863f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com } 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 288a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org /** 289a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * Given a stream, build an index for doing tile-based decode. 290a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * The built index will be saved in the decoder, and the image size will 291a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * be returned in width and height. 292a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * 293a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * Return true for success or false on failure. 294a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 295b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com bool buildTileIndex(SkStreamRewindable*, int *width, int *height); 296a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 297a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org /** 2987e6fceeffd250d99eff9f1dbb459a916ae4a754escroggo@google.com * Decode a rectangle subset in the image. 299a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * The method can only be called after buildTileIndex(). 300a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * 301a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * Return true for success. 302a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * Return false if the index is never built or failing in decoding. 303a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 304bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed bool decodeSubset(SkBitmap* bm, const SkIRect& subset, SkColorType pref); 3057e6fceeffd250d99eff9f1dbb459a916ae4a754escroggo@google.com 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Given a stream, this will try to find an appropriate decoder object. 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If none is found, the method returns NULL. 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 309b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com static SkImageDecoder* Factory(SkStreamRewindable*); 310a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com 3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Decode the image stored in the specified file, and store the result 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in bitmap. Return true for success or false on failure. 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 314bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed @param pref If the PrefConfigTable is not set, prefer this colortype. 315f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com See NOTE ABOUT PREFERRED CONFIGS. 31631d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com 317b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com @param format On success, if format is non-null, it is set to the format 318b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com of the decoded file. On failure it is ignored. 3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 320bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed static bool DecodeFile(const char file[], SkBitmap* bitmap, SkColorType pref, Mode, 32131d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com Format* format = NULL); 322b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com static bool DecodeFile(const char file[], SkBitmap* bitmap) { 323bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed return DecodeFile(file, bitmap, kUnknown_SkColorType, kDecodePixels_Mode, NULL); 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 325bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Decode the image stored in the specified memory buffer, and store the 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com result in bitmap. Return true for success or false on failure. 3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 329bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed @param pref If the PrefConfigTable is not set, prefer this colortype. 330f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com See NOTE ABOUT PREFERRED CONFIGS. 33131d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com 33231d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com @param format On success, if format is non-null, it is set to the format 333b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com of the decoded buffer. On failure it is ignored. 334b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com */ 335bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, SkColorType pref, 336bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed Mode, Format* format = NULL); 337b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){ 338bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed return DecodeMemory(buffer, size, bitmap, kUnknown_SkColorType, kDecodePixels_Mode, NULL); 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 340f8d7d2731318cdf510ab68e6b3f5ec68ab22c8e2scroggo@google.com 341f8d7d2731318cdf510ab68e6b3f5ec68ab22c8e2scroggo@google.com /** 3422c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com * Struct containing information about a pixel destination. 3432c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com */ 3442c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com struct Target { 3452c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com /** 3462c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com * Pre-allocated memory. 3472c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com */ 3482c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com void* fAddr; 3492c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com 3502c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com /** 3512c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com * Rowbytes of the allocated memory. 3522c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com */ 3532c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com size_t fRowBytes; 3542c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com }; 3552c7c7ee47d75e7815ea8db05e924ab55958cb402halcanary@google.com 356b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com /** Decode the image stored in the specified SkStreamRewindable, and store the result 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in bitmap. Return true for success or false on failure. 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 359bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed @param pref If the PrefConfigTable is not set, prefer this colortype. 360f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com See NOTE ABOUT PREFERRED CONFIGS. 36131d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com 362b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com @param format On success, if format is non-null, it is set to the format 363b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com of the decoded stream. On failure it is ignored. 364b3ade9d1b0a63f8f0dc3bee5785e930c8e84311dreed@android.com */ 365bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkColorType pref, Mode, 36631d1c64bd54dd2b216846a30da4cc2e96765ec5freed@android.com Format* format = NULL); 367b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) { 368bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed return DecodeStream(stream, bitmap, kUnknown_SkColorType, kDecodePixels_Mode, NULL); 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 37025e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // must be overridden in subclasses. This guy is called by decode(...) 3733f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 375a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org // If the decoder wants to support tiled based decoding, 376a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org // this method must be overridden. This guy is called by buildTileIndex(...) 377b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com virtual bool onBuildTileIndex(SkStreamRewindable*, int *width, int *height) { 378a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org return false; 379a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org } 380a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 381a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org // If the decoder wants to support tiled based decoding, 382a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org // this method must be overridden. This guy is called by decodeRegion(...) 3837e6fceeffd250d99eff9f1dbb459a916ae4a754escroggo@google.com virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) { 384a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org return false; 385a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org } 386a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 387a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org /* 388a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * Crop a rectangle from the src Bitmap to the dest Bitmap. src and dst are 389a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * both sampled by sampleSize from an original Bitmap. 390a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * 391a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * @param dst the destination bitmap. 392a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * @param src the source bitmap that is sampled by sampleSize from the 393a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * original bitmap. 394a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * @param sampleSize the sample size that src is sampled from the original bitmap. 395a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * @param (dstX, dstY) the upper-left point of the dest bitmap in terms of 396a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * the coordinate in the original bitmap. 397a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * @param (width, height) the width and height of the unsampled dst. 3987e6fceeffd250d99eff9f1dbb459a916ae4a754escroggo@google.com * @param (srcX, srcY) the upper-left point of the src bitmap in terms of 399a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org * the coordinate in the original bitmap. 4007e6fceeffd250d99eff9f1dbb459a916ae4a754escroggo@google.com * @return bool Whether or not it succeeded. 401a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org */ 4027e6fceeffd250d99eff9f1dbb459a916ae4a754escroggo@google.com bool cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, 403a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org int dstX, int dstY, int width, int height, 404a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org int srcX, int srcY); 405a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 406468142b2f50de055f00d5684515d962777da5131scroggo@google.com /** 407468142b2f50de055f00d5684515d962777da5131scroggo@google.com * Copy all fields on this decoder to the other decoder. Used by subclasses 408468142b2f50de055f00d5684515d962777da5131scroggo@google.com * to decode a subimage using a different decoder, but with the same settings. 409468142b2f50de055f00d5684515d962777da5131scroggo@google.com */ 410468142b2f50de055f00d5684515d962777da5131scroggo@google.com void copyFieldsToOther(SkImageDecoder* other); 411a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org 4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Can be queried from within onDecode, to see if the user (possibly in 4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com a different thread) has requested the decode to cancel. If this returns 4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com true, your onDecode() should stop and return false. 4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Each subclass needs to decide how often it can query this, to balance 4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com responsiveness with performance. 41725e9834c03a050afbf339f457b8c401aecb26c0bweita@google.com 4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Calling this outside of onDecode() may return undefined values. 4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool shouldCancelDecode() const { return fShouldCancelDecode; } 4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 42425e9834c03a050afbf339f457b8c401aecb26c0bweita@google.comprotected: 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkImageDecoder(); 4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 427bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed /** 428bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed * Return the default preference being used by the current or latest call to decode. 429bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed */ 430bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed SkColorType getDefaultPref() { return fDefaultPref; } 431bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed 4325926b86b90c68bffefbdc8639e41b5bc9102cec6reed#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER 4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // helper function for decoders to handle the (common) case where there is only 4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // once choice available in the image file. 4356c22573edb234ad14df947278cfed010669a39a7reed bool chooseFromOneChoice(SkColorType, int width, int height) const; 4365926b86b90c68bffefbdc8639e41b5bc9102cec6reed#endif 4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 438bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed /* Helper for subclasses. Call this to allocate the pixel memory given the bitmap's info. 439bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed Returns true on success. This method handles checking for an optional Allocator. 4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool allocPixelRef(SkBitmap*, SkColorTable*) const; 4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 443f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com /** 444f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com * The raw data of the src image. 445f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com */ 4463f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com enum SrcDepth { 447f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com // Color-indexed. 4483f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com kIndex_SrcDepth, 449f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com // Grayscale in 8 bits. 450f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com k8BitGray_SrcDepth, 451f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com // 8 bits per component. Used for 24 bit if there is no alpha. 452f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com k32Bit_SrcDepth, 4533f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com }; 4546c22573edb234ad14df947278cfed010669a39a7reed /** The subclass, inside onDecode(), calls this to determine the colorType of 4553f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the 4563f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com src image. This routine returns the caller's preference given 4576c22573edb234ad14df947278cfed010669a39a7reed srcDepth and hasAlpha, or kUnknown_SkColorType if there is no preference. 4583f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com */ 4596c22573edb234ad14df947278cfed010669a39a7reed SkColorType getPrefColorType(SrcDepth, bool hasAlpha) const; 4603f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com 4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Peeker* fPeeker; 4635926b86b90c68bffefbdc8639e41b5bc9102cec6reed#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER 4648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Chooser* fChooser; 4655926b86b90c68bffefbdc8639e41b5bc9102cec6reed#endif 4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap::Allocator* fAllocator; 4678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fSampleSize; 468bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed SkColorType fDefaultPref; // use if fUsePrefTable is false 469c3b3266b7db2f1a41d41ecac010c766b7ad8eebcreed#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG 470f698c8262df397a7015662e91b1a727e1134c418scroggo@google.com PrefConfigTable fPrefTable; // use if fUsePrefTable is true 4713f1f06a26bdb2022a5c72f93ae623a57b6659464reed@android.com bool fUsePrefTable; 472c3b3266b7db2f1a41d41ecac010c766b7ad8eebcreed#endif 473be08aceaab724b21136d7654fa86315850e9993creed bool fPreserveSrcDepth; 474c3b3266b7db2f1a41d41ecac010c766b7ad8eebcreed bool fDitherImage; 4758d2392487cd97e68c0a71da9fd5d2b42ecac5ec8scroggo@google.com bool fSkipWritingZeroes; 4768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable bool fShouldCancelDecode; 477a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.org bool fPreferQualityOverSpeed; 4782bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com bool fRequireUnpremultipliedColors; 4798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 4808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 481a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com/** Calling newDecoder with a stream returns a new matching imagedecoder 482a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com instance, or NULL if none can be found. The caller must manage its ownership 483a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com of the stream as usual, calling unref() when it is done, as the returned 484a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com decoder may have called ref() (and if so, the decoder is responsible for 485a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com balancing its ownership when it is destroyed). 486a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com */ 487a14ea0e930c82daa2364ece4bd0b06256272302areed@android.comclass SkImageDecoderFactory : public SkRefCnt { 488a14ea0e930c82daa2364ece4bd0b06256272302areed@android.compublic: 48915e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com SK_DECLARE_INST_COUNT(SkImageDecoderFactory) 49015e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 491b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com virtual SkImageDecoder* newDecoder(SkStreamRewindable*) = 0; 49215e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 49315e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.comprivate: 49415e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com typedef SkRefCnt INHERITED; 495a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com}; 496a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com 497a14ea0e930c82daa2364ece4bd0b06256272302areed@android.comclass SkDefaultImageDecoderFactory : SkImageDecoderFactory { 498a14ea0e930c82daa2364ece4bd0b06256272302areed@android.compublic: 499a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com // calls SkImageDecoder::Factory(stream) 500b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com virtual SkImageDecoder* newDecoder(SkStreamRewindable* stream) { 501a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com return SkImageDecoder::Factory(stream); 502a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com } 503a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com}; 504a14ea0e930c82daa2364ece4bd0b06256272302areed@android.com 505ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// This macro declares a global (i.e., non-class owned) creation entry point 506ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// for each decoder (e.g., CreateJPEGImageDecoder) 507ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com#define DECLARE_DECODER_CREATOR(codec) \ 508ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com SkImageDecoder *Create ## codec (); 509ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com 510ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// This macro defines the global creation entry point for each decoder. Each 511ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// decoder implementation that registers with the decoder factory must call it. 512ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com#define DEFINE_DECODER_CREATOR(codec) \ 513ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com SkImageDecoder *Create ## codec () { \ 514ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com return SkNEW( Sk ## codec ); \ 515ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com } 516ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com 517ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// All the decoders known by Skia. Note that, depending on the compiler settings, 518ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.com// not all of these will be available 519ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(BMPImageDecoder); 520ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(GIFImageDecoder); 521ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(ICOImageDecoder); 522ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(JPEGImageDecoder); 523ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(PNGImageDecoder); 524ec51cb863409e238b40c5beef458669d9a824481robertphillips@google.comDECLARE_DECODER_CREATOR(WBMPImageDecoder); 525a936e37cc76614868f5b489395bceeb340cc04cdcommit-bot@chromium.orgDECLARE_DECODER_CREATOR(WEBPImageDecoder); 5268cf81e0f4fa2a8054ac4cea1e7490028809cb893robertphillips@google.comDECLARE_DECODER_CREATOR(PKMImageDecoder); 52799ffe24200d8940ceba20f6fbf8c460f994d3cd1krajcevskiDECLARE_DECODER_CREATOR(KTXImageDecoder); 528bd6343b1d60d2a85e930f33f4b06b4502b3e8caamtklein@google.com 529bd6343b1d60d2a85e930f33f4b06b4502b3e8caamtklein@google.com// Typedefs to make registering decoder and formatter callbacks easier. 530bd6343b1d60d2a85e930f33f4b06b4502b3e8caamtklein@google.com// These have to be defined outside SkImageDecoder. :( 531b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.comtypedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecoder_DecodeReg; 532b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.comtypedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecoder_FormatReg; 533bd6343b1d60d2a85e930f33f4b06b4502b3e8caamtklein@google.com 5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 535