halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkDecodingImageGenerator.h" |
| 9 | |
| 10 | #include "SkBitmapFactory.h" |
| 11 | #include "SkData.h" |
| 12 | #include "SkDiscardablePixelRef.h" |
| 13 | #include "SkImageDecoder.h" |
| 14 | |
| 15 | SkDecodingImageGenerator::SkDecodingImageGenerator(SkData* data) |
| 16 | : fData(data) { |
| 17 | SkASSERT(fData != NULL); |
| 18 | fData->ref(); |
| 19 | } |
| 20 | |
| 21 | SkDecodingImageGenerator::~SkDecodingImageGenerator() { |
| 22 | fData->unref(); |
| 23 | } |
| 24 | |
| 25 | SkData* SkDecodingImageGenerator::refEncodedData() { |
| 26 | fData->ref(); |
| 27 | return fData; |
| 28 | } |
| 29 | |
| 30 | bool SkDecodingImageGenerator::getInfo(SkImageInfo* info) { |
| 31 | SkASSERT(info != NULL); |
| 32 | return SkImageDecoder::DecodeMemoryToTarget(fData->data(), |
| 33 | fData->size(), |
| 34 | info, NULL); |
| 35 | } |
| 36 | |
| 37 | bool SkDecodingImageGenerator::getPixels(const SkImageInfo& info, |
| 38 | void* pixels, |
| 39 | size_t rowBytes) { |
| 40 | SkASSERT(pixels != NULL); |
| 41 | SkBitmapFactory::Target target = {pixels, rowBytes}; |
| 42 | SkImageInfo tmpInfo = info; |
| 43 | return SkImageDecoder::DecodeMemoryToTarget(fData->data(), |
| 44 | fData->size(), |
| 45 | &tmpInfo, &target); |
| 46 | } |
| 47 | bool SkDecodingImageGenerator::Install(SkData* data, SkBitmap* dst) { |
| 48 | SkASSERT(data != NULL); |
| 49 | SkASSERT(dst != NULL); |
| 50 | SkImageGenerator* gen(SkNEW_ARGS(SkDecodingImageGenerator, (data))); |
| 51 | return SkDiscardablePixelRef::Install(gen, dst); |
| 52 | } |