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

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

Issue 12604006: Upstream Android modifications to the image encoders/decoders. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: update png Created 7 years, 9 months 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkImageDecoder_DEFINED 10 #ifndef SkImageDecoder_DEFINED
11 #define SkImageDecoder_DEFINED 11 #define SkImageDecoder_DEFINED
12 12
13 #include "SkBitmap.h" 13 #include "SkBitmap.h"
14 #include "SkBitmapFactory.h" 14 #include "SkBitmapFactory.h"
15 #include "SkImage.h" 15 #include "SkImage.h"
16 #include "SkRect.h"
16 #include "SkRefCnt.h" 17 #include "SkRefCnt.h"
17 18
18 class SkStream; 19 class SkStream;
19 20
20 /** \class SkImageDecoder 21 /** \class SkImageDecoder
21 22
22 Base class for decoding compressed images into a SkBitmap 23 Base class for decoding compressed images into a SkBitmap
23 */ 24 */
24 class SkImageDecoder { 25 class SkImageDecoder {
25 public: 26 public:
26 virtual ~SkImageDecoder(); 27 virtual ~SkImageDecoder();
27 28
29 // Should be consistent with kFormatName
28 enum Format { 30 enum Format {
29 kUnknown_Format, 31 kUnknown_Format,
30 kBMP_Format, 32 kBMP_Format,
31 kGIF_Format, 33 kGIF_Format,
32 kICO_Format, 34 kICO_Format,
33 kJPEG_Format, 35 kJPEG_Format,
34 kPNG_Format, 36 kPNG_Format,
35 kWBMP_Format, 37 kWBMP_Format,
38 kWEBP_Format,
36 39
37 kLastKnownFormat = kWBMP_Format 40 kLastKnownFormat = kWEBP_Format
38 }; 41 };
39 42
43 /** Contains the image format name.
44 * This should be consistent with Format.
45 *
46 * The format name gives a more meaningful error message than enum.
47 */
robertphillips 2013/03/13 13:41:29 So you don't think replacing the '8' with "kLastKn
djsollen 2013/03/13 16:02:48 Done.
48 static const char *kFormatName[8];
scroggo 2013/03/13 16:04:14 Why does this have a 'k' at the front? Isn't that
djsollen 2013/03/13 17:35:09 Done.
49
40 /** Return the compressed data's format (see Format enum) 50 /** Return the compressed data's format (see Format enum)
41 */ 51 */
42 virtual Format getFormat() const; 52 virtual Format getFormat() const;
43 53
54 /** Return the compressed data's format name.
55 */
56 const char* getFormatName() const {
57 SkASSERT(SK_ARRAY_COUNT(kFormatName) == kLastKnownFormat);
robertphillips 2013/03/13 13:41:29 this->getFormat()
djsollen 2013/03/13 16:02:48 Done.
58 return kFormatName[getFormat()];
59 }
60
44 /** Returns true if the decoder should try to dither the resulting image. 61 /** Returns true if the decoder should try to dither the resulting image.
45 The default setting is true. 62 The default setting is true.
46 */ 63 */
47 bool getDitherImage() const { return fDitherImage; } 64 bool getDitherImage() const { return fDitherImage; }
48 65
49 /** Set to true if the the decoder should try to dither the resulting image. 66 /** Set to true if the the decoder should try to dither the resulting image.
50 The default setting is true. 67 The default setting is true.
51 */ 68 */
52 void setDitherImage(bool dither) { fDitherImage = dither; } 69 void setDitherImage(bool dither) { fDitherImage = dither; }
53 70
71 /** Returns true if the decoder should try to decode the
72 resulting image to a higher quality even at the expense of
73 the decoding speed.
74 */
75 bool getPreferQualityOverSpeed() const { return fPreferQualityOverSpeed; }
76
77 /** Set to true if the the decoder should try to decode the
78 resulting image to a higher quality even at the expense of
79 the decoding speed.
80 */
81 void setPreferQualityOverSpeed(bool qualityOverSpeed) {
82 fPreferQualityOverSpeed = qualityOverSpeed;
83 }
84
54 /** \class Peeker 85 /** \class Peeker
55 86
56 Base class for optional callbacks to retrieve meta/chunk data out of 87 Base class for optional callbacks to retrieve meta/chunk data out of
57 an image as it is being decoded. 88 an image as it is being decoded.
58 */ 89 */
59 class Peeker : public SkRefCnt { 90 class Peeker : public SkRefCnt {
60 public: 91 public:
61 SK_DECLARE_INST_COUNT(Peeker) 92 SK_DECLARE_INST_COUNT(Peeker)
62 93
63 /** Return true to continue decoding, or false to indicate an error, whi ch 94 /** Return true to continue decoding, or false to indicate an error, whi ch
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 which will allocated a pixelRef. To access the pixel memory, the codec 199 which will allocated a pixelRef. To access the pixel memory, the codec
169 needs to call lockPixels/unlockPixels on the 200 needs to call lockPixels/unlockPixels on the
170 bitmap. It can then set the pixels with the decompressed image. 201 bitmap. It can then set the pixels with the decompressed image.
171 * If the image cannot be decompressed, return false. After the 202 * If the image cannot be decompressed, return false. After the
172 * decoding, the function converts the decoded config in bitmap 203 * decoding, the function converts the decoded config in bitmap
173 * to pref if possible. Whether a conversion is feasible is 204 * to pref if possible. Whether a conversion is feasible is
174 * tested by Bitmap::canCopyTo(pref). 205 * tested by Bitmap::canCopyTo(pref).
175 206
176 note: document use of Allocator, Peeker and Chooser 207 note: document use of Allocator, Peeker and Chooser
177 */ 208 */
178 bool decode(SkStream*, SkBitmap* bitmap, SkBitmap::Config pref, Mode); 209 bool decode(SkStream*, SkBitmap* bitmap, SkBitmap::Config pref, Mode, bool r euseBitmap = false);
scroggo 2013/03/13 16:04:14 Some thoughts on reuseBitmap: It appears to be onl
djsollen 2013/03/13 17:35:09 The lack of support is not a technical problem, ju
179 bool decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { 210 bool decode(SkStream* stream, SkBitmap* bitmap, Mode mode, bool reuseBitmap = false) {
180 return this->decode(stream, bitmap, SkBitmap::kNo_Config, mode); 211 return this->decode(stream, bitmap, SkBitmap::kNo_Config, mode, reuseBit map);
181 } 212 }
182 213
214 /**
215 * Given a stream, build an index for doing tile-based decode.
216 * The built index will be saved in the decoder, and the image size will
217 * be returned in width and height.
218 *
219 * Return true for success or false on failure.
220 */
221 virtual bool buildTileIndex(SkStream*, int *width, int *height);
222
223 /**
224 * Decode a rectangle region in the image specified by rect.
225 * The method can only be called after buildTileIndex().
226 *
227 * Return true for success.
228 * Return false if the index is never built or failing in decoding.
229 */
230 virtual bool decodeRegion(SkBitmap* bitmap, const SkIRect& rect,
scroggo 2013/03/13 16:04:14 decodeRect?
djsollen 2013/03/13 17:35:09 I don't want to change method signatures in this C
231 SkBitmap::Config pref);
232
183 /** Given a stream, this will try to find an appropriate decoder object. 233 /** Given a stream, this will try to find an appropriate decoder object.
184 If none is found, the method returns NULL. 234 If none is found, the method returns NULL.
185 */ 235 */
186 static SkImageDecoder* Factory(SkStream*); 236 static SkImageDecoder* Factory(SkStream*);
187 237
188 /** Decode the image stored in the specified file, and store the result 238 /** Decode the image stored in the specified file, and store the result
189 in bitmap. Return true for success or false on failure. 239 in bitmap. Return true for success or false on failure.
190 240
191 If pref is kNo_Config, then the decoder is free to choose the most natur al 241 If pref is kNo_Config, then the decoder is free to choose the most natur al
192 config given the image data. If pref something other than kNo_Config, 242 config given the image data. If pref something other than kNo_Config,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 */ 338 */
289 static void SetDeviceConfig(SkBitmap::Config); 339 static void SetDeviceConfig(SkBitmap::Config);
290 340
291 /** @cond UNIT_TEST */ 341 /** @cond UNIT_TEST */
292 SkDEBUGCODE(static void UnitTest();) 342 SkDEBUGCODE(static void UnitTest();)
293 /** @endcond */ 343 /** @endcond */
294 344
295 protected: 345 protected:
296 // must be overridden in subclasses. This guy is called by decode(...) 346 // must be overridden in subclasses. This guy is called by decode(...)
297 virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; 347 virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0;
298 348
robertphillips 2013/03/13 13:41:29 Isn't the pattern to have a non-virtual decodeRegi
djsollen 2013/03/13 17:35:09 Done.
349 // If the decoder wants to support tiled based decoding,
350 // this method must be overridden. This guy is called by buildTileIndex(...)
351 virtual bool onBuildTileIndex(SkStream*, int *width, int *height) {
352 return false;
353 }
354
355 // If the decoder wants to support tiled based decoding,
356 // this method must be overridden. This guy is called by decodeRegion(...)
357 virtual bool onDecodeRegion(SkBitmap* bitmap, const SkIRect& rect) {
358 return false;
359 }
360
361 /*
362 * Crop a rectangle from the src Bitmap to the dest Bitmap. src and dst are
363 * both sampled by sampleSize from an original Bitmap.
364 *
365 * @param dst the destination bitmap.
366 * @param src the source bitmap that is sampled by sampleSize from the
367 * original bitmap.
368 * @param sampleSize the sample size that src is sampled from the original b itmap.
robertphillips 2013/03/13 13:41:29 make order in the comment match the order in the f
djsollen 2013/03/13 17:35:09 Done.
369 * @param (srcX, srcY) the upper-left point of the src bitimap in terms of
370 * the coordinate in the original bitmap.
371 * @param (width, height) the width and height of the unsampled dst.
372 * @param (dstX, dstY) the upper-left point of the dest bitmap in terms of
373 * the coordinate in the original bitmap.
374 */
375 void cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize,
376 int dstX, int dstY, int width, int height,
377 int srcX, int srcY);
378
379
380
299 /** Can be queried from within onDecode, to see if the user (possibly in 381 /** Can be queried from within onDecode, to see if the user (possibly in
300 a different thread) has requested the decode to cancel. If this returns 382 a different thread) has requested the decode to cancel. If this returns
301 true, your onDecode() should stop and return false. 383 true, your onDecode() should stop and return false.
302 Each subclass needs to decide how often it can query this, to balance 384 Each subclass needs to decide how often it can query this, to balance
303 responsiveness with performance. 385 responsiveness with performance.
304 386
305 Calling this outside of onDecode() may return undefined values. 387 Calling this outside of onDecode() may return undefined values.
306 */ 388 */
307 389
308 public: 390 public:
(...skipping 30 matching lines...) Expand all
339 private: 421 private:
340 Peeker* fPeeker; 422 Peeker* fPeeker;
341 Chooser* fChooser; 423 Chooser* fChooser;
342 SkBitmap::Allocator* fAllocator; 424 SkBitmap::Allocator* fAllocator;
343 int fSampleSize; 425 int fSampleSize;
344 SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false 426 SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false
345 SkBitmap::Config fPrefTable[6]; // use if fUsePrefTable is true 427 SkBitmap::Config fPrefTable[6]; // use if fUsePrefTable is true
346 bool fDitherImage; 428 bool fDitherImage;
347 bool fUsePrefTable; 429 bool fUsePrefTable;
348 mutable bool fShouldCancelDecode; 430 mutable bool fShouldCancelDecode;
431 bool fPreferQualityOverSpeed;
349 432
350 // illegal 433 // illegal
351 SkImageDecoder(const SkImageDecoder&); 434 SkImageDecoder(const SkImageDecoder&);
352 SkImageDecoder& operator=(const SkImageDecoder&); 435 SkImageDecoder& operator=(const SkImageDecoder&);
353 }; 436 };
354 437
355 /** Calling newDecoder with a stream returns a new matching imagedecoder 438 /** Calling newDecoder with a stream returns a new matching imagedecoder
356 instance, or NULL if none can be found. The caller must manage its ownership 439 instance, or NULL if none can be found. The caller must manage its ownership
357 of the stream as usual, calling unref() when it is done, as the returned 440 of the stream as usual, calling unref() when it is done, as the returned
358 decoder may have called ref() (and if so, the decoder is responsible for 441 decoder may have called ref() (and if so, the decoder is responsible for
(...skipping 30 matching lines...) Expand all
389 } 472 }
390 473
391 // All the decoders known by Skia. Note that, depending on the compiler settings , 474 // All the decoders known by Skia. Note that, depending on the compiler settings ,
392 // not all of these will be available 475 // not all of these will be available
393 DECLARE_DECODER_CREATOR(BMPImageDecoder); 476 DECLARE_DECODER_CREATOR(BMPImageDecoder);
394 DECLARE_DECODER_CREATOR(GIFImageDecoder); 477 DECLARE_DECODER_CREATOR(GIFImageDecoder);
395 DECLARE_DECODER_CREATOR(ICOImageDecoder); 478 DECLARE_DECODER_CREATOR(ICOImageDecoder);
396 DECLARE_DECODER_CREATOR(JPEGImageDecoder); 479 DECLARE_DECODER_CREATOR(JPEGImageDecoder);
397 DECLARE_DECODER_CREATOR(PNGImageDecoder); 480 DECLARE_DECODER_CREATOR(PNGImageDecoder);
398 DECLARE_DECODER_CREATOR(WBMPImageDecoder); 481 DECLARE_DECODER_CREATOR(WBMPImageDecoder);
482 DECLARE_DECODER_CREATOR(WEBPImageDecoder);
399 483
400 #endif 484 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698