Chromium Code Reviews| Index: src/lazy/SkLazyPixelRef.cpp |
| diff --git a/src/lazy/SkLazyPixelRef.cpp b/src/lazy/SkLazyPixelRef.cpp |
| index dc9aef9f062dbdbbe8935795e4c820c050d44291..b9151b8022bd118ca29203ec190b0140705a2661 100644 |
| --- a/src/lazy/SkLazyPixelRef.cpp |
| +++ b/src/lazy/SkLazyPixelRef.cpp |
| @@ -145,3 +145,51 @@ SkData* SkLazyPixelRef::onRefEncodedData() { |
| fData->ref(); |
| return fData; |
| } |
| + |
| +#include "SkImagePriv.h" |
| + |
| +static bool initFromInfo(SkBitmap* bm, const SkImage::Info& info, size_t rowBytes) { |
|
scroggo
2013/09/10 21:51:41
init_from_info*
reed1
2013/09/11 14:16:36
Done.
|
| + bool isOpaque; |
| + SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); |
| + if (SkBitmap::kNo_Config == config) { |
| + return false; |
| + } |
| + |
| + bm->setConfig(config, info.fWidth, info.fHeight, rowBytes); |
| + bm->setIsOpaque(isOpaque); |
| + return bm->allocPixels(); |
| +} |
| + |
| +bool SkLazyPixelRef::onDecodeInto(int pow2, SkBitmap* bitmap) { |
| + SkASSERT(fData != NULL && fData->size() > 0); |
| + if (fErrorInDecoding) { |
| + return false; |
| + } |
| + |
| + SkImage::Info info; |
| + // Determine the size of the image in order to determine how much memory to allocate. |
| + // FIXME: As an optimization, only do this part once. |
| + fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, NULL); |
| + if (fErrorInDecoding) { |
| + return false; |
| + } |
| + |
| + SkBitmapFactory::Target target; |
| + (void)ComputeMinRowBytesAndSize(info, &target.fRowBytes); |
| + |
| + SkBitmap tmp; |
| + if (!initFromInfo(&tmp, info, target.fRowBytes)) { |
| + return false; |
| + } |
| + |
| + target.fAddr = tmp.getPixels(); |
| + fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, &target); |
| + if (fErrorInDecoding) { |
| + return false; |
| + } |
| + |
| + *bitmap = tmp; |
| + return true; |
| +} |
| + |
| + |