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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkDecodingImageGenerator_DEFINED
#define SkDecodingImageGenerator_DEFINED
#include "SkDiscardableMemory.h"
#include "SkImageGenerator.h"
#include "SkImageInfo.h"
class SkBitmap;
class SkStreamRewindable;
/**
* Calls into SkImageDecoder::DecodeMemoryToTarget to implement a
* SkImageGenerator
*/
class SkDecodingImageGenerator : public SkImageGenerator {
public:
/*
* The constructor will take a reference to the SkData. The
* destructor will unref() it.
*/
explicit SkDecodingImageGenerator(SkData* data);
/*
* The SkData version of this constructor is preferred. If the
* stream has an underlying SkData (such as a SkMemoryStream)
* pass that in.
*
* This object will unref the stream when done. Since streams
* have internal state (position), the caller should not pass a
* shared stream in. Pass either a new duplicated stream in or
* transfer ownership of the stream. In the latter case, be sure
* that there are no other consumers of the stream who will
* modify the stream's position. This constructor asserts
* stream->unique().
*
* For example:
* SkStreamRewindable* stream;
* ...
* SkImageGenerator* gen
* = SkNEW_ARGS(SkDecodingImageGenerator,
* (stream->duplicate()));
* ...
* SkDELETE(gen);
*/
explicit SkDecodingImageGenerator(SkStreamRewindable* stream);
virtual ~SkDecodingImageGenerator();
virtual SkData* refEncodedData() SK_OVERRIDE;
virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE;
virtual bool getPixels(const SkImageInfo& info,
void* pixels,
size_t rowBytes) SK_OVERRIDE;
/**
* Install the SkData into the destination bitmap, using a new
* SkDiscardablePixelRef and a new SkDecodingImageGenerator.
*
* @param data Contains the encoded image data that will be used
* by the SkDecodingImageGenerator. Will be ref()ed.
*
* @param destination Upon success, this bitmap will be
* configured and have a pixelref installed.
*
* @param factory If not NULL, this object will be used as a
* source of discardable memory when decoding. If NULL, then
* SkDiscardableMemory::Create() will be called.
*
* @return true iff successful.
*/
static bool Install(SkData* data, SkBitmap* destination,
SkDiscardableMemory::Factory* factory = NULL);
/**
* Install the stream into the destination bitmap, using a new
* SkDiscardablePixelRef and a new SkDecodingImageGenerator.
*
* The SkData version of this function is preferred. If the
* stream has an underlying SkData (such as a SkMemoryStream)
* pass that in.
*
* @param stream The source of encoded data that will be passed
* to the decoder. The installed SkDecodingImageGenerator will
* unref the stream when done. If false is returned, this
* function will perform the unref. Since streams have internal
* state (position), the caller should not pass a shared stream
* in. Pass either a new duplicated stream in or transfer
* ownership of the stream. In the latter case, be sure that
* there are no other consumers of the stream who will modify the
* stream's position. This function will fail if
* (!stream->unique()).
*
* @param destination Upon success, this bitmap will be
* configured and have a pixelref installed.
*
* @param factory If not NULL, this object will be used as a
* source of discardable memory when decoding. If NULL, then
* SkDiscardableMemory::Create() will be called.
*
* @return true iff successful.
*/
static bool Install(SkStreamRewindable* stream, SkBitmap* destination,
SkDiscardableMemory::Factory* factory = NULL);
private:
SkData* fData;
SkStreamRewindable* fStream;
SkImageInfo fInfo;
bool fHasInfo;
bool fDoCopyTo;
};
#endif // SkDecodingImageGenerator_DEFINED
|