aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/images/SkImageDecoder.h
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-22 21:38:35 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-22 21:38:35 +0000
commitf8d7d2731318cdf510ab68e6b3f5ec68ab22c8e2 (patch)
treeb62a29fabe0b0af3f8f17ffbe8d607508c1d2c00 /include/images/SkImageDecoder.h
parent5c90e291425b2788f47679266d9584845ceefc2e (diff)
Create SkLazyPixelRef which performs lazy decoding.
The new pixel ref behaves similarly to SkImageRef, with some key differences: It does not depend on the images project. It requires an SkImageCache, which handles allocation and caching of the pixel memory. It takes a function signature for decoding which decodes into already allocated pixel memory rather than into an SkBitmap. Add two implementations of SkImageCache: SkLruImageCache and SkAshmemImageCache. Replace SkSerializationHelpers::DecodeBitmap with SkPicture::InstallPixelRefProc, and update sites that referenced it. SkBitmapFactory now sets the pixel ref to a new object of the new class SkLazyPixelRef, provided it has an SkImageCache for caching. Provide an option to do lazy decodes in render_pictures and bench_pictures. SkPicture: Eliminate the default parameters in the constructor. If a proc for decoding bitmaps is installed, use it to decode any encoded data in subpictures. When parsing deserializing subpictures, check for success. When serializing subpictures, pass the picture's bitmap encoder to the subpicture's call to serialize. Update BitmapFactoryTest to test its new behavior. BUG=https://code.google.com/p/skia/issues/detail?id=1008 BUG=https://code.google.com/p/skia/issues/detail?id=1009 Review URL: https://codereview.appspot.com/7060052 git-svn-id: http://skia.googlecode.com/svn/trunk@7835 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/images/SkImageDecoder.h')
-rw-r--r--include/images/SkImageDecoder.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/include/images/SkImageDecoder.h b/include/images/SkImageDecoder.h
index a8ec1c6518..6d1bb7241d 100644
--- a/include/images/SkImageDecoder.h
+++ b/include/images/SkImageDecoder.h
@@ -11,6 +11,8 @@
#define SkImageDecoder_DEFINED
#include "SkBitmap.h"
+#include "SkBitmapFactory.h"
+#include "SkImage.h"
#include "SkRefCnt.h"
class SkStream;
@@ -223,6 +225,34 @@ public:
return DecodeMemory(buffer, size, bitmap, SkBitmap::kNo_Config,
kDecodePixels_Mode, NULL);
}
+
+ /**
+ * Decode memory.
+ * @param info Output parameter. Returns info about the encoded image.
+ * @param target Contains the address of pixel memory to decode into
+ * (which must be large enough to hold the width in info) and
+ * the row bytes to use. If NULL, returns info and does not
+ * decode pixels.
+ * @return bool Whether the function succeeded.
+ *
+ * Sample usage:
+ * <code>
+ * // Determine the image's info: width/height/config
+ * SkImage::Info info;
+ * bool success = DecodeMemoryToTarget(src, size, &info, NULL);
+ * if (!success) return;
+ * // Allocate space for the result:
+ * SkBitmapFactory::Target target;
+ * target.fAddr = malloc/other allocation
+ * target.fRowBytes = ...
+ * // Now decode the actual pixels into target. &info is optional,
+ * // and could be NULL
+ * success = DecodeMemoryToTarget(src, size, &info, &target);
+ * </code>
+ */
+ static bool DecodeMemoryToTarget(const void* buffer, size_t size, SkImage::Info* info,
+ const SkBitmapFactory::Target* target);
+
/** Decode the image stored in the specified SkStream, and store the result
in bitmap. Return true for success or false on failure.