diff options
author | Joseph Wen <josephwen@google.com> | 2010-08-16 15:18:43 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-08-16 15:18:43 -0700 |
commit | 2d34418f00c38bfa656fe92dc6e792603260344c (patch) | |
tree | 3dc943ecdae86f151234dfb3b653b06208e89641 /include | |
parent | 5e631cf2609bc0657530e4fbd26a31e8208bfb88 (diff) | |
parent | 97fa2e455b2040c99c5b6f3e3d2ad6c9b4062081 (diff) | |
download | external_skia-2d34418f00c38bfa656fe92dc6e792603260344c.zip external_skia-2d34418f00c38bfa656fe92dc6e792603260344c.tar.gz external_skia-2d34418f00c38bfa656fe92dc6e792603260344c.tar.bz2 |
am 97fa2e45: Do JPEG tile-based decoding.
Merge commit '97fa2e455b2040c99c5b6f3e3d2ad6c9b4062081'
* commit '97fa2e455b2040c99c5b6f3e3d2ad6c9b4062081':
Do JPEG tile-based decoding.
Diffstat (limited to 'include')
-rw-r--r-- | include/images/SkImageDecoder.h | 50 | ||||
-rw-r--r-- | include/images/SkJpegUtility.h | 6 | ||||
-rw-r--r-- | include/images/SkLargeBitmap.h | 33 |
3 files changed, 87 insertions, 2 deletions
diff --git a/include/images/SkImageDecoder.h b/include/images/SkImageDecoder.h index f8a941f..be1046b 100644 --- a/include/images/SkImageDecoder.h +++ b/include/images/SkImageDecoder.h @@ -18,10 +18,17 @@ #define SkImageDecoder_DEFINED #include "SkBitmap.h" +#include "SkRect.h" #include "SkRefCnt.h" class SkStream; +class SkVMMemoryReporter : public SkRefCnt { +public: + virtual ~SkVMMemoryReporter() {} + virtual bool reportMemory(size_t memorySize); +}; + /** \class SkImageDecoder Base class for decoding compressed images into a SkBitmap @@ -30,6 +37,7 @@ class SkImageDecoder { public: virtual ~SkImageDecoder(); + // Should be consistent with kFormatName enum Format { kUnknown_Format, kBMP_Format, @@ -42,10 +50,21 @@ public: kLastKnownFormat = kWBMP_Format }; + /** Contains the image format name. + * This should be consistent with Format. + * + * The format name gives a more meaningful error message than enum. + */ + static const char *kFormatName[7]; + /** Return the compressed data's format (see Format enum) */ virtual Format getFormat() const; + /** Return the compressed data's format name. + */ + const char* getFormatName() const { return kFormatName[getFormat()]; } + /** Returns true if the decoder should try to dither the resulting image. The default setting is true. */ @@ -118,6 +137,7 @@ public: SkBitmap::Allocator* getAllocator() const { return fAllocator; } SkBitmap::Allocator* setAllocator(SkBitmap::Allocator*); + SkVMMemoryReporter* setReporter(SkVMMemoryReporter*); // sample-size, if set to > 1, tells the decoder to return a smaller than // original bitmap, sampling 1 pixel for every size pixels. e.g. if sample @@ -176,6 +196,29 @@ public: return this->decode(stream, bitmap, SkBitmap::kNo_Config, mode); } + /** + * 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, bool isShareable) { + return false; + } + + /** + * 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, 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. */ @@ -264,6 +307,11 @@ protected: // must be overridden in subclasses. This guy is called by decode(...) virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; + // must be overridden in subclasses. This guy is called by decodeRegion(...) + virtual bool onDecodeRegion(SkBitmap* bitmap, SkIRect rect) { + return false; + } + /** 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. @@ -304,6 +352,8 @@ protected: */ SkBitmap::Config getPrefConfig(SrcDepth, bool hasAlpha) const; + SkVMMemoryReporter* fReporter; + private: Peeker* fPeeker; Chooser* fChooser; diff --git a/include/images/SkJpegUtility.h b/include/images/SkJpegUtility.h index cc9d246..5dd789c 100644 --- a/include/images/SkJpegUtility.h +++ b/include/images/SkJpegUtility.h @@ -41,11 +41,13 @@ void skjpeg_error_exit(j_common_ptr cinfo); /* Our source struct for directing jpeg to our stream object. */ struct skjpeg_source_mgr : jpeg_source_mgr { - skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder); + skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder, bool copyStream, bool ownStream); + ~skjpeg_source_mgr(); SkStream* fStream; - const void* fMemoryBase; + void* fMemoryBase; size_t fMemoryBaseSize; + bool fUnrefStream; SkImageDecoder* fDecoder; enum { kBufferSize = 1024 diff --git a/include/images/SkLargeBitmap.h b/include/images/SkLargeBitmap.h new file mode 100644 index 0000000..0d19f32 --- /dev/null +++ b/include/images/SkLargeBitmap.h @@ -0,0 +1,33 @@ +#ifndef SkLargeBitmap_DEFINED +#define SkLargeBitmap_DEFINED + +#include "SkBitmap.h" +#include "SkRect.h" +#include "SkImageDecoder.h" + +class SkLargeBitmap { +public: + SkLargeBitmap(SkImageDecoder *decoder, int width, int height) { + fDecoder = decoder; + fWidth = width; + fHeight = height; + } + virtual ~SkLargeBitmap() { + delete fDecoder; + } + + virtual bool decodeRegion(SkBitmap* bitmap, SkIRect rect, + SkBitmap::Config pref, int sampleSize); + + virtual int getWidth() { return fWidth; } + virtual int getHeight() { return fHeight; } + + virtual SkImageDecoder* getDecoder() { return fDecoder; } + +private: + SkImageDecoder *fDecoder; + int fWidth; + int fHeight; +}; + +#endif |