diff options
Diffstat (limited to 'images/SkImageDecoder.cpp')
-rw-r--r-- | images/SkImageDecoder.cpp | 164 |
1 files changed, 0 insertions, 164 deletions
diff --git a/images/SkImageDecoder.cpp b/images/SkImageDecoder.cpp index 1ba93652..32cf087e 100644 --- a/images/SkImageDecoder.cpp +++ b/images/SkImageDecoder.cpp @@ -14,10 +14,6 @@ #include "SkTemplates.h" #include "SkCanvas.h" -SK_DEFINE_INST_COUNT(SkImageDecoder::Peeker) -SK_DEFINE_INST_COUNT(SkImageDecoder::Chooser) -SK_DEFINE_INST_COUNT(SkImageDecoderFactory) - static SkBitmap::Config gDeviceConfig = SkBitmap::kNo_Config; SkBitmap::Config SkImageDecoder::GetDeviceConfig() @@ -143,19 +139,6 @@ bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap, /////////////////////////////////////////////////////////////////////////////// -void SkImageDecoder::setPrefConfigTable(const SkBitmap::Config pref[6]) { - if (NULL == pref) { - fUsePrefTable = false; - } else { - fUsePrefTable = true; - fPrefTable.fPrefFor_8Index_NoAlpha_src = pref[0]; - fPrefTable.fPrefFor_8Index_YesAlpha_src = pref[1]; - fPrefTable.fPrefFor_8Gray_src = SkBitmap::kNo_Config; - fPrefTable.fPrefFor_8bpc_NoAlpha_src = pref[4]; - fPrefTable.fPrefFor_8bpc_YesAlpha_src = pref[5]; - } -} - void SkImageDecoder::setPrefConfigTable(const PrefConfigTable& prefTable) { fUsePrefTable = true; fPrefTable = prefTable; @@ -299,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 SkBitmapFactory::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) { |