summaryrefslogtreecommitdiff
path: root/images/SkDecodingImageGenerator.cpp
blob: 65fa6fd5612abfec9f803943a7fe1e4ab0540c18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkDecodingImageGenerator.h"

#include "SkBitmapFactory.h"
#include "SkData.h"
#include "SkDiscardablePixelRef.h"
#include "SkImageDecoder.h"

SkDecodingImageGenerator::SkDecodingImageGenerator(SkData* data)
    : fData(data) {
    SkASSERT(fData != NULL);
    fData->ref();
}

SkDecodingImageGenerator::~SkDecodingImageGenerator() {
    fData->unref();
}

SkData* SkDecodingImageGenerator::refEncodedData() {
    fData->ref();
    return fData;
}

bool SkDecodingImageGenerator::getInfo(SkImageInfo* info) {
    SkASSERT(info != NULL);
    return SkImageDecoder::DecodeMemoryToTarget(fData->data(),
                                                fData->size(),
                                                info, NULL);
}

bool SkDecodingImageGenerator::getPixels(const SkImageInfo& info,
                                         void* pixels,
                                         size_t rowBytes) {
    SkASSERT(pixels != NULL);
    SkBitmapFactory::Target target = {pixels, rowBytes};
    SkImageInfo tmpInfo = info;
    return SkImageDecoder::DecodeMemoryToTarget(fData->data(),
                                                fData->size(),
                                                &tmpInfo, &target);
}
bool SkDecodingImageGenerator::Install(SkData* data, SkBitmap* dst) {
    SkASSERT(data != NULL);
    SkASSERT(dst != NULL);
    SkImageGenerator* gen(SkNEW_ARGS(SkDecodingImageGenerator, (data)));
    return SkDiscardablePixelRef::Install(gen, dst);
}