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

Unified Diff: src/images/SkImageDecoder.cpp

Issue 101973005: SkDecodingImageGenerator now uses SkStreamRewindable (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebased again Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/images/SkDecodingImageGenerator.cpp ('k') | src/ports/SkImageDecoder_empty.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/images/SkImageDecoder.cpp
diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp
index ee7ad5e035a05c9c5d7d8685c42b54c2d05f3dca..32cf087ed86514ea341f819847f5254b0ffe1476 100644
--- a/src/images/SkImageDecoder.cpp
+++ b/src/images/SkImageDecoder.cpp
@@ -282,153 +282,6 @@ bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm,
return SkImageDecoder::DecodeStream(&stream, bm, pref, mode, format);
}
-/**
- * Special allocator used by DecodeMemoryToTarget. Uses preallocated memory
- * provided if the bm is 8888. Otherwise, uses a heap allocator. The same
- * allocator will be used again for a copy to 8888, when the preallocated
- * memory will be used.
- */
-class TargetAllocator : public SkBitmap::HeapAllocator {
-
-public:
- TargetAllocator(void* target)
- : fTarget(target) {}
-
- virtual bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) SK_OVERRIDE {
- // If the config is not 8888, allocate a pixelref using the heap.
- // fTarget will be used to store the final pixels when copied to
- // 8888.
- if (bm->config() != SkBitmap::kARGB_8888_Config) {
- return INHERITED::allocPixelRef(bm, ct);
- }
- // In kARGB_8888_Config, there is no colortable.
- SkASSERT(NULL == ct);
- bm->setPixels(fTarget);
- return true;
- }
-
-private:
- void* fTarget;
- typedef SkBitmap::HeapAllocator INHERITED;
-};
-
-/**
- * Helper function for DecodeMemoryToTarget. DecodeMemoryToTarget wants
- * 8888, so set the config to it. All parameters must not be null.
- * @param decoder Decoder appropriate for this stream.
- * @param stream Rewound stream to the encoded data.
- * @param bitmap On success, will have its bounds set to the bounds of the
- * encoded data, and its config set to 8888.
- * @return True if the bounds were decoded and the bitmap is 8888 or can be
- * copied to 8888.
- */
-static bool decode_bounds_to_8888(SkImageDecoder* decoder, SkStream* stream,
- SkBitmap* bitmap) {
- SkASSERT(decoder != NULL);
- SkASSERT(stream != NULL);
- SkASSERT(bitmap != NULL);
-
- if (!decoder->decode(stream, bitmap, SkImageDecoder::kDecodeBounds_Mode)) {
- return false;
- }
-
- if (bitmap->config() == SkBitmap::kARGB_8888_Config) {
- return true;
- }
-
- if (!bitmap->canCopyTo(SkBitmap::kARGB_8888_Config)) {
- return false;
- }
-
- bitmap->setConfig(SkBitmap::kARGB_8888_Config, bitmap->width(), bitmap->height());
- return true;
-}
-
-/**
- * Helper function for DecodeMemoryToTarget. Decodes the stream into bitmap, and if
- * the bitmap is not 8888, then it is copied to 8888. Either way, the end result has
- * its pixels stored in target. All parameters must not be null.
- * @param decoder Decoder appropriate for this stream.
- * @param stream Rewound stream to the encoded data.
- * @param bitmap On success, will contain the decoded image, with its pixels stored
- * at target.
- * @param target Preallocated memory for storing pixels.
- * @return bool Whether the decode (and copy, if necessary) succeeded.
- */
-static bool decode_pixels_to_8888(SkImageDecoder* decoder, SkStream* stream,
- SkBitmap* bitmap, void* target) {
- SkASSERT(decoder != NULL);
- SkASSERT(stream != NULL);
- SkASSERT(bitmap != NULL);
- SkASSERT(target != NULL);
-
- TargetAllocator allocator(target);
- decoder->setAllocator(&allocator);
-
- bool success = decoder->decode(stream, bitmap, SkImageDecoder::kDecodePixels_Mode);
- decoder->setAllocator(NULL);
-
- if (!success) {
- return false;
- }
-
- if (bitmap->config() == SkBitmap::kARGB_8888_Config) {
- return true;
- }
-
- SkBitmap bm8888;
- if (!bitmap->copyTo(&bm8888, SkBitmap::kARGB_8888_Config, &allocator)) {
- return false;
- }
-
- bitmap->swap(bm8888);
- return true;
-}
-
-bool SkImageDecoder::DecodeMemoryToTarget(const void* buffer, size_t size,
- SkImageInfo* info,
- const SkImageDecoder::Target* target) {
- // FIXME: Just to get this working, implement in terms of existing
- // ImageDecoder calls.
- SkBitmap bm;
- SkMemoryStream stream(buffer, size);
- SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream));
- if (NULL == decoder.get()) {
- return false;
- }
-
- if (!decode_bounds_to_8888(decoder.get(), &stream, &bm)) {
- return false;
- }
-
- SkASSERT(bm.config() == SkBitmap::kARGB_8888_Config);
-
- // Now set info properly.
- // Since Config is SkBitmap::kARGB_8888_Config, SkBitmapToImageInfo
- // will always succeed.
- if (info) {
- SkAssertResult(SkBitmapToImageInfo(bm, info));
- }
-
- if (NULL == target) {
- return true;
- }
-
- if (target->fRowBytes != SkToU32(bm.rowBytes())) {
- size_t minRB = SkBitmap::ComputeRowBytes(bm.config(), bm.width());
- if (target->fRowBytes < minRB) {
- SkDEBUGFAIL("Desired row bytes is too small");
- return false;
- }
- bm.setConfig(bm.config(), bm.width(), bm.height(), target->fRowBytes);
- }
-
- // SkMemoryStream.rewind() will always return true.
- SkAssertResult(stream.rewind());
- return decode_pixels_to_8888(decoder.get(), &stream, &bm, target->fAddr);
-}
-
-
bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm,
SkBitmap::Config pref, Mode mode,
Format* format) {
« no previous file with comments | « src/images/SkDecodingImageGenerator.cpp ('k') | src/ports/SkImageDecoder_empty.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698