Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: include/codec/SkAndroidCodec.h

Issue 1406223002: Create an SkAndroidCodec API separate from SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Win bot fix Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/codec.gyp ('k') | include/codec/SkCodec.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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 #ifndef SkAndroidCodec_DEFINED
9 #define SkAndroidCodec_DEFINED
10
11 #include "SkCodec.h"
12 #include "SkEncodedFormat.h"
13 #include "SkStream.h"
14 #include "SkTypes.h"
15
16 /**
17 * Abstract interface defining image codec functionality that is necessary for
18 * Android.
19 */
20 class SkAndroidCodec : SkNoncopyable {
21 public:
22 /**
23 * If this stream represents an encoded image that we know how to decode,
24 * return an SkAndroidCodec that can decode it. Otherwise return NULL.
25 *
26 * If NULL is returned, the stream is deleted immediately. Otherwise, the
27 * SkCodec takes ownership of it, and will delete it when done with it.
28 */
29 static SkAndroidCodec* NewFromStream(SkStream*);
30
31 /**
32 * If this data represents an encoded image that we know how to decode,
33 * return an SkAndroidCodec that can decode it. Otherwise return NULL.
34 *
35 * Will take a ref if it returns a codec, else will not affect the data.
36 */
37 static SkAndroidCodec* NewFromData(SkData*);
38
39 virtual ~SkAndroidCodec() {}
40
41
42 const SkImageInfo& getInfo() const { return fInfo; }
43
44 /**
45 * Format of the encoded data.
46 */
47 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat() ; }
48
49 /**
50 * Returns the dimensions of the scaled output image, for an input
51 * sampleSize.
52 *
53 * When the sample size divides evenly into the original dimensions, the
54 * scaled output dimensions will simply be equal to the original
55 * dimensions divided by the sample size.
56 *
57 * When the sample size does not divide even into the original
58 * dimensions, the codec may round up or down, depending on what is most
59 * efficient to decode.
60 *
61 * Finally, the codec will always recommend a non-zero output, so the outpu t
62 * dimension will always be one if the sampleSize is greater than the
63 * original dimension.
64 */
65 SkISize getSampledDimensions(int sampleSize) const;
66
67 /**
68 * Return (via desiredSubset) a subset which can decoded from this codec,
69 * or false if the input subset is invalid.
70 *
71 * @param desiredSubset in/out parameter
72 * As input, a desired subset of the original bounds
73 * (as specified by getInfo).
74 * As output, if true is returned, desiredSubset may
75 * have been modified to a subset which is
76 * supported. Although a particular change may have
77 * been made to desiredSubset to create something
78 * supported, it is possible other changes could
79 * result in a valid subset. If false is returned,
80 * desiredSubset's value is undefined.
81 * @return true If the input desiredSubset is valid.
82 * desiredSubset may be modified to a subset
83 * supported by the codec.
84 * false If desiredSubset is invalid (NULL or not fully
85 * contained within the image).
86 */
87 bool getSupportedSubset(SkIRect* desiredSubset) const;
88 // TODO: Rename SkCodec::getValidSubset() to getSupportedSubset()
89
90 /**
91 * Returns the dimensions of the scaled, partial output image, for an
92 * input sampleSize and subset.
93 *
94 * @param sampleSize Factor to scale down by.
95 * @param subset Must be a valid subset of the original image
96 * dimensions and a subset supported by SkAndroidCodec.
97 * getSubset() can be used to obtain a subset supported
98 * by SkAndroidCodec.
99 * @return Size of the scaled partial image. Or zero size
100 * if either of the inputs is invalid.
101 */
102 SkISize getSampledSubsetDimensions(int sampleSize, const SkIRect& subset) co nst;
103
104 /**
105 * Additional options to pass to getAndroidPixels().
106 */
107 // FIXME: It's a bit redundant to name these AndroidOptions when this class is already
108 // called SkAndroidCodec. On the other hand, it's may be a bit confu sing to call
109 // these Options when SkCodec has a slightly different set of Options . Maybe these
110 // should be DecodeOptions or SamplingOptions?
111 struct AndroidOptions {
112 AndroidOptions()
113 : fZeroInitialized(SkCodec::kNo_ZeroInitialized)
114 , fSubset(nullptr)
115 , fColorPtr(nullptr)
116 , fColorCount(nullptr)
117 , fSampleSize(1)
118 {}
119
120 /**
121 * Indicates is destination pixel memory is zero initialized.
122 */
123 SkCodec::ZeroInitialized fZeroInitialized;
124
125 /**
126 * If not NULL, represents a subset of the original image to decode.
127 *
128 * Must be within the bounds returned by getInfo().
129 *
130 * If the EncodedFormat is kWEBP_SkEncodedFormat, the top and left
131 * values must be even.
132 */
133 SkIRect* fSubset;
134
135 /**
136 * If the client has requested a decode to kIndex8_SkColorType
137 * (specified in the SkImageInfo), then the caller must provide
138 * storage for up to 256 SkPMColor values in fColorPtr. On success,
139 * the codec must copy N colors into that storage, (where N is the
140 * logical number of table entries) and set fColorCount to N.
141 *
142 * If the client does not request kIndex8_SkColorType, then the last
143 * two parameters may be NULL. If fColorCount is not null, it will be
144 * set to 0.
145 */
146 SkPMColor* fColorPtr;
147 int* fColorCount;
148
149 /**
150 * The client may provide an integer downscale factor for the decode.
151 * The codec may implement this downscaling by sampling or another
152 * method if it is more efficient.
153 */
154 int fSampleSize;
155 };
156
157 /**
158 * Decode into the given pixels, a block of memory of size at
159 * least (info.fHeight - 1) * rowBytes + (info.fWidth *
160 * bytesPerPixel)
161 *
162 * Repeated calls to this function should give the same results,
163 * allowing the PixelRef to be immutable.
164 *
165 * @param info A description of the format (config, size)
166 * expected by the caller. This can simply be identical
167 * to the info returned by getInfo().
168 *
169 * This contract also allows the caller to specify
170 * different output-configs, which the implementation can
171 * decide to support or not.
172 *
173 * A size that does not match getInfo() implies a request
174 * to scale or subset. If the codec cannot perform this
175 * scaling or subsetting, it will return an error code.
176 *
177 * If info is kIndex8_SkColorType, then the caller must provide storage for up to 256
178 * SkPMColor values in options->fColorPtr. On success the codec must copy N colors into
179 * that storage, (where N is the logical number of table entries) and set
180 * options->fColorCount to N.
181 *
182 * If info is not kIndex8_SkColorType, options->fColorPtr and options->fCol orCount may
183 * be nullptr.
184 *
185 * The AndroidOptions object is also used to specify any requested scaling or subsetting
186 * using options->fSampleSize and options->fSubset.
187 *
188 * @return Result kSuccess, or another value explaining the type of failure .
189 */
190 // FIXME: It's a bit redundant to name this getAndroidPixels() when this cla ss is already
191 // called SkAndroidCodec. On the other hand, it's may be a bit confu sing to call
192 // this getPixels() when it is a slightly different API than SkCodec' s getPixels().
193 // Maybe this should be decode() or decodeSubset()?
194 SkCodec::Result getAndroidPixels(const SkImageInfo& info, void* pixels, size _t rowBytes,
195 AndroidOptions* options);
196
197 /**
198 * Simplified version of getAndroidPixels() where we supply the default And roidOptions.
199 *
200 * This will return an error if the info is kIndex_8_SkColorType and also w ill not perform
201 * any scaling or subsetting.
202 */
203 SkCodec::Result getAndroidPixels(const SkImageInfo& info, void* pixels, size _t rowBytes);
204
205 protected:
206
207 SkAndroidCodec(const SkImageInfo&);
208
209 virtual SkEncodedFormat onGetEncodedFormat() const = 0;
210
211 virtual SkISize onGetSampledDimensions(int sampleSize) const = 0;
212
213 virtual bool onGetSupportedSubset(SkIRect* desiredSubset) const = 0;
214
215 virtual SkCodec::Result onGetAndroidPixels(const SkImageInfo& info, void* pi xels,
216 size_t rowBytes, AndroidOptions& options) = 0;
217
218 private:
219
220 // This will always be a reference to the info that is contained by the
221 // embedded SkCodec.
222 const SkImageInfo& fInfo;
223 };
224 #endif // SkAndroidCodec_DEFINED
OLDNEW
« no previous file with comments | « gyp/codec.gyp ('k') | include/codec/SkCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698