 Chromium Code Reviews
 Chromium Code Reviews Issue 12604006:
  Upstream Android modifications to the image encoders/decoders.  (Closed) 
  Base URL: https://skia.googlecode.com/svn/trunk
    
  
    Issue 12604006:
  Upstream Android modifications to the image encoders/decoders.  (Closed) 
  Base URL: https://skia.googlecode.com/svn/trunk| Index: include/images/SkImageDecoder.h | 
| diff --git a/include/images/SkImageDecoder.h b/include/images/SkImageDecoder.h | 
| index 6d1bb7241d5dd3aeb44e584d02840de23e7eb678..49d6c628c126eb5d023d081e4bc741a00a614468 100644 | 
| --- a/include/images/SkImageDecoder.h | 
| +++ b/include/images/SkImageDecoder.h | 
| @@ -13,6 +13,7 @@ | 
| #include "SkBitmap.h" | 
| #include "SkBitmapFactory.h" | 
| #include "SkImage.h" | 
| +#include "SkRect.h" | 
| #include "SkRefCnt.h" | 
| class SkStream; | 
| @@ -25,6 +26,7 @@ class SkImageDecoder { | 
| public: | 
| virtual ~SkImageDecoder(); | 
| + // Should be consistent with kFormatName | 
| enum Format { | 
| kUnknown_Format, | 
| kBMP_Format, | 
| @@ -33,14 +35,26 @@ public: | 
| kJPEG_Format, | 
| kPNG_Format, | 
| kWBMP_Format, | 
| + kWEBP_Format, | 
| - kLastKnownFormat = kWBMP_Format | 
| + kLastKnownFormat = kWEBP_Format | 
| }; | 
| + /** Contains the image format name. | 
| + * This should be consistent with Format. | 
| + * | 
| + * The format name gives a more meaningful error message than enum. | 
| + */ | 
| 
robertphillips
2013/03/11 18:25:55
Can we use SK_ARRAY_COUNT here or a kNumFormats co
 
djsollen
2013/03/11 19:43:24
Done.
 | 
| + static const char *kFormatName[8]; | 
| + | 
| /** Return the compressed data's format (see Format enum) | 
| */ | 
| virtual Format getFormat() const; | 
| + /** Return the compressed data's format name. | 
| + */ | 
| 
robertphillips
2013/03/11 18:25:55
this->
 | 
| + const char* getFormatName() const { return kFormatName[getFormat()]; } | 
| + | 
| /** Returns true if the decoder should try to dither the resulting image. | 
| The default setting is true. | 
| */ | 
| @@ -51,6 +65,20 @@ public: | 
| */ | 
| void setDitherImage(bool dither) { fDitherImage = dither; } | 
| + /** Returns true if the decoder should try to decode the | 
| + resulting image to a higher quality even at the expense of | 
| + the decoding speed. | 
| + */ | 
| + bool getPreferQualityOverSpeed() const { return fPreferQualityOverSpeed; } | 
| + | 
| + /** Set to true if the the decoder should try to decode the | 
| + resulting image to a higher quality even at the expense of | 
| + the decoding speed. | 
| + */ | 
| + void setPreferQualityOverSpeed(bool qualityOverSpeed) { | 
| + fPreferQualityOverSpeed = qualityOverSpeed; | 
| + } | 
| + | 
| /** \class Peeker | 
| Base class for optional callbacks to retrieve meta/chunk data out of | 
| @@ -175,11 +203,30 @@ public: | 
| note: document use of Allocator, Peeker and Chooser | 
| */ | 
| - bool decode(SkStream*, SkBitmap* bitmap, SkBitmap::Config pref, Mode); | 
| - bool decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { | 
| - return this->decode(stream, bitmap, SkBitmap::kNo_Config, mode); | 
| + bool decode(SkStream*, SkBitmap* bitmap, SkBitmap::Config pref, Mode, bool reuseBitmap = false); | 
| + bool decode(SkStream* stream, SkBitmap* bitmap, Mode mode, bool reuseBitmap = false) { | 
| + return this->decode(stream, bitmap, SkBitmap::kNo_Config, mode, reuseBitmap); | 
| } | 
| + /** | 
| + * Given a stream, build an index for doing tile-based decode. | 
| + * The built index will be saved in the decoder, and the image size will | 
| + * be returned in width and height. | 
| + * | 
| + * Return true for success or false on failure. | 
| + */ | 
| + virtual bool buildTileIndex(SkStream*, int *width, int *height); | 
| + | 
| + /** | 
| + * Decode a rectangle region in the image specified by rect. | 
| + * The method can only be called after buildTileIndex(). | 
| + * | 
| + * Return true for success. | 
| + * Return false if the index is never built or failing in decoding. | 
| + */ | 
| + virtual bool decodeRegion(SkBitmap* bitmap, const SkIRect& rect, | 
| + SkBitmap::Config pref); | 
| + | 
| /** Given a stream, this will try to find an appropriate decoder object. | 
| If none is found, the method returns NULL. | 
| */ | 
| @@ -296,6 +343,38 @@ protected: | 
| // must be overridden in subclasses. This guy is called by decode(...) | 
| virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; | 
| + // If the decoder wants to support tiled based decoding, | 
| + // this method must be overridden. This guy is called by buildTileIndex(...) | 
| + virtual bool onBuildTileIndex(SkStream*, int *width, int *height) { | 
| + return false; | 
| + } | 
| + | 
| + // If the decoder wants to support tiled based decoding, | 
| + // this method must be overridden. This guy is called by decodeRegion(...) | 
| + virtual bool onDecodeRegion(SkBitmap* bitmap, const SkIRect& rect) { | 
| + return false; | 
| + } | 
| + | 
| + /* | 
| + * Crop a rectangle from the src Bitmap to the dest Bitmap. src and dst are | 
| + * both sampled by sampleSize from an original Bitmap. | 
| + * | 
| + * @param dst the destination Bitmap. | 
| + * @param src the source Bitmap that is sampled by sampleSize from the original | 
| + * Bitmap. | 
| + * @param sampleSize the sample size that src is sampled from the original Bitmap. | 
| 
robertphillips
2013/03/11 18:25:55
Btimap -> bitmap
 
djsollen
2013/03/11 19:43:24
Done.
 | 
| + * @param (srcX, srcY) the upper-left point of the src Btimap in terms of | 
| + * the coordinate in the original Bitmap. | 
| + * @param (width, height) the width and height of the unsampled dst. | 
| + * @param (dstX, dstY) the upper-left point of the dest Bitmap in terms of | 
| + * the coordinate in the original Bitmap. | 
| + */ | 
| + void cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, | 
| + int dstX, int dstY, int width, int height, | 
| + int srcX, int srcY); | 
| + | 
| + | 
| + | 
| /** Can be queried from within onDecode, to see if the user (possibly in | 
| a different thread) has requested the decode to cancel. If this returns | 
| true, your onDecode() should stop and return false. | 
| @@ -346,6 +425,7 @@ private: | 
| bool fDitherImage; | 
| bool fUsePrefTable; | 
| mutable bool fShouldCancelDecode; | 
| + bool fPreferQualityOverSpeed; | 
| // illegal | 
| SkImageDecoder(const SkImageDecoder&); | 
| @@ -396,5 +476,6 @@ DECLARE_DECODER_CREATOR(ICOImageDecoder); | 
| DECLARE_DECODER_CREATOR(JPEGImageDecoder); | 
| DECLARE_DECODER_CREATOR(PNGImageDecoder); | 
| DECLARE_DECODER_CREATOR(WBMPImageDecoder); | 
| +DECLARE_DECODER_CREATOR(WEBPImageDecoder); | 
| #endif |