Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(837)

Side by Side Diff: include/core/SkImageDecoder.h

Issue 1040453002: Add SkPngChunkReader. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update SkImageDecoder_empty Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/codec/SkCodec.h ('k') | include/core/SkPngChunkReader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkImageDecoder_DEFINED 8 #ifndef SkImageDecoder_DEFINED
9 #define SkImageDecoder_DEFINED 9 #define SkImageDecoder_DEFINED
10 10
11 #include "SkBitmap.h" 11 #include "SkBitmap.h"
12 #include "SkImage.h" 12 #include "SkImage.h"
13 #include "SkPngChunkReader.h"
13 #include "SkRect.h" 14 #include "SkRect.h"
14 #include "SkRefCnt.h" 15 #include "SkRefCnt.h"
15 #include "SkTRegistry.h" 16 #include "SkTRegistry.h"
16 #include "SkTypes.h" 17 #include "SkTypes.h"
17 18
19 //#define SK_LEGACY_PEEKER
20
18 class SkStream; 21 class SkStream;
19 class SkStreamRewindable; 22 class SkStreamRewindable;
20 23
21 /** \class SkImageDecoder 24 /** \class SkImageDecoder
22 25
23 Base class for decoding compressed images into a SkBitmap 26 Base class for decoding compressed images into a SkBitmap
24 */ 27 */
25 class SkImageDecoder : SkNoncopyable { 28 class SkImageDecoder : SkNoncopyable {
26 public: 29 public:
27 virtual ~SkImageDecoder(); 30 virtual ~SkImageDecoder();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 */ 122 */
120 void setRequireUnpremultipliedColors(bool request) { 123 void setRequireUnpremultipliedColors(bool request) {
121 fRequireUnpremultipliedColors = request; 124 fRequireUnpremultipliedColors = request;
122 } 125 }
123 126
124 /** Returns true if the decoder will only return bitmaps with unpremultiplie d 127 /** Returns true if the decoder will only return bitmaps with unpremultiplie d
125 colors. 128 colors.
126 */ 129 */
127 bool getRequireUnpremultipliedColors() const { return fRequireUnpremultiplie dColors; } 130 bool getRequireUnpremultipliedColors() const { return fRequireUnpremultiplie dColors; }
128 131
129 /** \class Peeker 132 #ifdef SK_LEGACY_PEEKER
130 133 // Android subclasses SkImageDecoder::Peeker, which has been changed into Sk PngChunkReader.
131 Base class for optional callbacks to retrieve meta/chunk data out of 134 // Temporarily use this class until Android can be updated to directly inher it from
132 an image as it is being decoded. 135 // SkPngChunkReader.
133 */ 136 class Peeker : public SkPngChunkReader {
134 class Peeker : public SkRefCnt {
135 public: 137 public:
136 /** Return true to continue decoding, or false to indicate an error, whi ch 138 bool readChunk(const char tag[], const void* data, size_t length) final {
137 will cause the decoder to not return the image. 139 return this->peek(tag, data, length);
138 */ 140 }
139 virtual bool peek(const char tag[], const void* data, size_t length) = 0 ; 141 virtual bool peek(const char tag[], const void* data, size_t length) = 0 ;
140 private:
141 typedef SkRefCnt INHERITED;
142 }; 142 };
143 143 #endif
144 Peeker* getPeeker() const { return fPeeker; } 144 SkPngChunkReader* getPeeker() const { return fPeeker; }
145 Peeker* setPeeker(Peeker*); 145 SkPngChunkReader* setPeeker(SkPngChunkReader*);
146 146
147 /** 147 /**
148 * By default, the codec will try to comply with the "pref" colortype 148 * By default, the codec will try to comply with the "pref" colortype
149 * that is passed to decode() or decodeSubset(). However, this can be calle d 149 * that is passed to decode() or decodeSubset(). However, this can be calle d
150 * to override that, causing the codec to try to match the src depth instea d 150 * to override that, causing the codec to try to match the src depth instea d
151 * (as shown below). 151 * (as shown below).
152 * 152 *
153 * src_8Index -> kIndex_8_SkColorType 153 * src_8Index -> kIndex_8_SkColorType
154 * src_8Gray -> kN32_SkColorType 154 * src_8Gray -> kN32_SkColorType
155 * src_8bpc -> kN32_SkColorType 155 * src_8bpc -> kN32_SkColorType
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 * If the image cannot be decompressed, return kFailure. After the 222 * If the image cannot be decompressed, return kFailure. After the
223 * decoding, the function converts the decoded colortype in bitmap 223 * decoding, the function converts the decoded colortype in bitmap
224 * to pref if possible. Whether a conversion is feasible is 224 * to pref if possible. Whether a conversion is feasible is
225 * tested by Bitmap::canCopyTo(pref). 225 * tested by Bitmap::canCopyTo(pref).
226 226
227 If an SkBitmap::Allocator is installed via setAllocator, it will be 227 If an SkBitmap::Allocator is installed via setAllocator, it will be
228 used to allocate the pixel memory. A clever allocator can be used 228 used to allocate the pixel memory. A clever allocator can be used
229 to allocate the memory from a cache, volatile memory, or even from 229 to allocate the memory from a cache, volatile memory, or even from
230 an existing bitmap's memory. 230 an existing bitmap's memory.
231 231
232 If a Peeker is installed via setPeeker, it may be used to peek into 232 If an SkPngChunkReader is installed via setPeeker, it may be used to
233 meta data during the decode. 233 peek into meta data during the decode.
234 */ 234 */
235 Result decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); 235 Result decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode);
236 Result decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { 236 Result decode(SkStream* stream, SkBitmap* bitmap, Mode mode) {
237 return this->decode(stream, bitmap, kUnknown_SkColorType, mode); 237 return this->decode(stream, bitmap, kUnknown_SkColorType, mode);
238 } 238 }
239 239
240 /** Given a stream, this will try to find an appropriate decoder object. 240 /** Given a stream, this will try to find an appropriate decoder object.
241 If none is found, the method returns NULL. 241 If none is found, the method returns NULL.
242 */ 242 */
243 static SkImageDecoder* Factory(SkStreamRewindable*); 243 static SkImageDecoder* Factory(SkStreamRewindable*);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 k32Bit_SrcDepth, 343 k32Bit_SrcDepth,
344 }; 344 };
345 /** The subclass, inside onDecode(), calls this to determine the colorType o f 345 /** The subclass, inside onDecode(), calls this to determine the colorType o f
346 the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the 346 the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the
347 src image. This routine returns the caller's preference given 347 src image. This routine returns the caller's preference given
348 srcDepth and hasAlpha, or kUnknown_SkColorType if there is no preference . 348 srcDepth and hasAlpha, or kUnknown_SkColorType if there is no preference .
349 */ 349 */
350 SkColorType getPrefColorType(SrcDepth, bool hasAlpha) const; 350 SkColorType getPrefColorType(SrcDepth, bool hasAlpha) const;
351 351
352 private: 352 private:
353 Peeker* fPeeker; 353 SkPngChunkReader* fPeeker;
354 SkBitmap::Allocator* fAllocator; 354 SkBitmap::Allocator* fAllocator;
355 int fSampleSize; 355 int fSampleSize;
356 SkColorType fDefaultPref; // use if fUsePrefTable is false 356 SkColorType fDefaultPref; // use if fUsePrefTable is false
357 bool fPreserveSrcDepth; 357 bool fPreserveSrcDepth;
358 bool fDitherImage; 358 bool fDitherImage;
359 bool fSkipWritingZeroes; 359 bool fSkipWritingZeroes;
360 mutable bool fShouldCancelDecode; 360 mutable bool fShouldCancelDecode;
361 bool fPreferQualityOverSpeed; 361 bool fPreferQualityOverSpeed;
362 bool fRequireUnpremultipliedColors; 362 bool fRequireUnpremultipliedColors;
363 }; 363 };
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 DECLARE_DECODER_CREATOR(PKMImageDecoder); 408 DECLARE_DECODER_CREATOR(PKMImageDecoder);
409 DECLARE_DECODER_CREATOR(KTXImageDecoder); 409 DECLARE_DECODER_CREATOR(KTXImageDecoder);
410 DECLARE_DECODER_CREATOR(ASTCImageDecoder); 410 DECLARE_DECODER_CREATOR(ASTCImageDecoder);
411 411
412 // Typedefs to make registering decoder and formatter callbacks easier. 412 // Typedefs to make registering decoder and formatter callbacks easier.
413 // These have to be defined outside SkImageDecoder. :( 413 // These have to be defined outside SkImageDecoder. :(
414 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod er_DecodeReg; 414 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod er_DecodeReg;
415 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod er_FormatReg; 415 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod er_FormatReg;
416 416
417 #endif 417 #endif
OLDNEW
« no previous file with comments | « include/codec/SkCodec.h ('k') | include/core/SkPngChunkReader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698