blob: 4d47237e4bda613dc83477f2a8f17c3b7c5f58db [file] [log] [blame]
scroggof24f2242015-03-03 08:59:20 -08001/*
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 SkCodec_DEFINED
9#define SkCodec_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/codec/SkCodecAnimation.h"
12#include "include/codec/SkEncodedOrigin.h"
13#include "include/core/SkColor.h"
14#include "include/core/SkEncodedImageFormat.h"
15#include "include/core/SkImageInfo.h"
16#include "include/core/SkPixmap.h"
17#include "include/core/SkSize.h"
18#include "include/core/SkStream.h"
19#include "include/core/SkTypes.h"
Brian Salomonbe0e42c2020-08-27 11:00:04 -040020#include "include/core/SkYUVAPixmaps.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "include/private/SkEncodedInfo.h"
22#include "include/private/SkNoncopyable.h"
23#include "include/private/SkTemplates.h"
scroggof24f2242015-03-03 08:59:20 -080024
scroggo19b91532016-10-24 09:03:26 -070025#include <vector>
26
Leon Scroggins1340dbd2020-11-09 14:18:12 -050027class SkAndroidCodec;
msarettad8bcfe2016-03-07 07:09:03 -080028class SkColorSpace;
scroggof24f2242015-03-03 08:59:20 -080029class SkData;
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -040030class SkFrameHolder;
Mike Reed844beb52021-01-25 15:36:09 -050031class SkImage;
scroggocf98fa92015-11-23 08:14:40 -080032class SkPngChunkReader;
scroggoe7fc14b2015-10-02 13:14:46 -070033class SkSampler;
scroggof24f2242015-03-03 08:59:20 -080034
msarett9876ac52016-06-01 14:47:18 -070035namespace DM {
scroggo8e6c7ad2016-09-16 08:20:38 -070036class CodecSrc;
msarett9876ac52016-06-01 14:47:18 -070037class ColorCodecSrc;
John Stilesa6841be2020-08-06 14:11:56 -040038} // namespace DM
msarett9876ac52016-06-01 14:47:18 -070039
scroggof24f2242015-03-03 08:59:20 -080040/**
41 * Abstraction layer directly on top of an image codec.
42 */
Florin Malita78c212a2016-12-14 13:17:01 -050043class SK_API SkCodec : SkNoncopyable {
scroggof24f2242015-03-03 08:59:20 -080044public:
45 /**
scroggodb30be22015-12-08 18:54:13 -080046 * Minimum number of bytes that must be buffered in SkStream input.
47 *
48 * An SkStream passed to NewFromStream must be able to use this many
49 * bytes to determine the image type. Then the same SkStream must be
50 * passed to the correct decoder to read from the beginning.
51 *
52 * This can be accomplished by implementing peek() to support peeking
53 * this many bytes, or by implementing rewind() to be able to rewind()
54 * after reading this many bytes.
55 */
Leon Scroggins III04be2b52017-08-17 15:13:20 -040056 static constexpr size_t MinBufferedBytesNeeded() { return 32; }
scroggodb30be22015-12-08 18:54:13 -080057
58 /**
Leon Scroggins III588fb042017-07-14 16:32:31 -040059 * Error codes for various SkCodec methods.
60 */
61 enum Result {
62 /**
63 * General return value for success.
64 */
65 kSuccess,
66 /**
67 * The input is incomplete. A partial image was generated.
68 */
69 kIncompleteInput,
70 /**
71 * Like kIncompleteInput, except the input had an error.
72 *
73 * If returned from an incremental decode, decoding cannot continue,
74 * even with more data.
75 */
76 kErrorInInput,
77 /**
78 * The generator cannot convert to match the request, ignoring
79 * dimensions.
80 */
81 kInvalidConversion,
82 /**
83 * The generator cannot scale to requested size.
84 */
85 kInvalidScale,
86 /**
87 * Parameters (besides info) are invalid. e.g. NULL pixels, rowBytes
88 * too small, etc.
89 */
90 kInvalidParameters,
91 /**
92 * The input did not contain a valid image.
93 */
94 kInvalidInput,
95 /**
96 * Fulfilling this request requires rewinding the input, which is not
97 * supported for this input.
98 */
99 kCouldNotRewind,
100 /**
101 * An internal error, such as OOM.
102 */
103 kInternalError,
104 /**
105 * This method is not implemented by this codec.
106 * FIXME: Perhaps this should be kUnsupported?
107 */
108 kUnimplemented,
109 };
110
111 /**
Leon Scroggins IIIfe3da022018-01-16 11:56:54 -0500112 * Readable string representing the error code.
113 */
114 static const char* ResultToString(Result);
115
116 /**
Leon Scroggins III6154ac42019-08-14 11:29:29 -0400117 * For container formats that contain both still images and image sequences,
118 * instruct the decoder how the output should be selected. (Refer to comments
119 * for each value for more details.)
120 */
121 enum class SelectionPolicy {
122 /**
123 * If the container format contains both still images and image sequences,
124 * SkCodec should choose one of the still images. This is the default.
125 */
126 kPreferStillImage,
127 /**
128 * If the container format contains both still images and image sequences,
129 * SkCodec should choose one of the image sequences for animation.
130 */
131 kPreferAnimation,
132 };
133
134 /**
scroggof24f2242015-03-03 08:59:20 -0800135 * If this stream represents an encoded image that we know how to decode,
136 * return an SkCodec that can decode it. Otherwise return NULL.
137 *
scroggodb30be22015-12-08 18:54:13 -0800138 * As stated above, this call must be able to peek or read
139 * MinBufferedBytesNeeded to determine the correct format, and then start
140 * reading from the beginning. First it will attempt to peek, and it
141 * assumes that if less than MinBufferedBytesNeeded bytes (but more than
142 * zero) are returned, this is because the stream is shorter than this,
143 * so falling back to reading would not provide more data. If peek()
144 * returns zero bytes, this call will instead attempt to read(). This
145 * will require that the stream can be rewind()ed.
146 *
Leon Scroggins III588fb042017-07-14 16:32:31 -0400147 * If Result is not NULL, it will be set to either kSuccess if an SkCodec
148 * is returned or a reason for the failure if NULL is returned.
149 *
scroggodb30be22015-12-08 18:54:13 -0800150 * If SkPngChunkReader is not NULL, take a ref and pass it to libpng if
151 * the image is a png.
152 *
msarett7d5105c2015-12-02 07:02:41 -0800153 * If the SkPngChunkReader is not NULL then:
154 * If the image is not a PNG, the SkPngChunkReader will be ignored.
155 * If the image is a PNG, the SkPngChunkReader will be reffed.
156 * If the PNG has unknown chunks, the SkPngChunkReader will be used
157 * to handle these chunks. SkPngChunkReader will be called to read
158 * any unknown chunk at any point during the creation of the codec
159 * or the decode. Note that if SkPngChunkReader fails to read a
160 * chunk, this could result in a failure to create the codec or a
161 * failure to decode the image.
162 * If the PNG does not contain unknown chunks, the SkPngChunkReader
163 * will not be used or modified.
scroggocf98fa92015-11-23 08:14:40 -0800164 *
scroggof24f2242015-03-03 08:59:20 -0800165 * If NULL is returned, the stream is deleted immediately. Otherwise, the
166 * SkCodec takes ownership of it, and will delete it when done with it.
167 */
Leon Scroggins III6154ac42019-08-14 11:29:29 -0400168 static std::unique_ptr<SkCodec> MakeFromStream(
169 std::unique_ptr<SkStream>, Result* = nullptr,
170 SkPngChunkReader* = nullptr,
171 SelectionPolicy selectionPolicy = SelectionPolicy::kPreferStillImage);
scroggof24f2242015-03-03 08:59:20 -0800172
173 /**
174 * If this data represents an encoded image that we know how to decode,
175 * return an SkCodec that can decode it. Otherwise return NULL.
176 *
msarett7d5105c2015-12-02 07:02:41 -0800177 * If the SkPngChunkReader is not NULL then:
178 * If the image is not a PNG, the SkPngChunkReader will be ignored.
179 * If the image is a PNG, the SkPngChunkReader will be reffed.
180 * If the PNG has unknown chunks, the SkPngChunkReader will be used
181 * to handle these chunks. SkPngChunkReader will be called to read
182 * any unknown chunk at any point during the creation of the codec
183 * or the decode. Note that if SkPngChunkReader fails to read a
184 * chunk, this could result in a failure to create the codec or a
185 * failure to decode the image.
186 * If the PNG does not contain unknown chunks, the SkPngChunkReader
187 * will not be used or modified.
scroggof24f2242015-03-03 08:59:20 -0800188 */
Mike Reedede7bac2017-07-23 15:30:02 -0400189 static std::unique_ptr<SkCodec> MakeFromData(sk_sp<SkData>, SkPngChunkReader* = nullptr);
190
scroggoeb602a52015-07-09 08:16:03 -0700191 virtual ~SkCodec();
192
193 /**
Leon Scroggins III712476e2018-10-03 15:47:00 -0400194 * Return a reasonable SkImageInfo to decode into.
Leon Scroggins III42a604f2020-02-06 15:47:58 -0500195 *
196 * If the image has an ICC profile that does not map to an SkColorSpace,
197 * the returned SkImageInfo will use SRGB.
scroggoeb602a52015-07-09 08:16:03 -0700198 */
Leon Scroggins III712476e2018-10-03 15:47:00 -0400199 SkImageInfo getInfo() const { return fEncodedInfo.makeImageInfo(); }
200
201 SkISize dimensions() const { return {fEncodedInfo.width(), fEncodedInfo.height()}; }
202 SkIRect bounds() const {
203 return SkIRect::MakeWH(fEncodedInfo.width(), fEncodedInfo.height());
204 }
scroggoeb602a52015-07-09 08:16:03 -0700205
msarett0e6274f2016-03-21 08:04:40 -0700206 /**
Leon Scroggins III42a604f2020-02-06 15:47:58 -0500207 * Return the ICC profile of the encoded data.
208 */
209 const skcms_ICCProfile* getICCProfile() const {
210 return this->getEncodedInfo().profile();
211 }
212
213 /**
msarett0e6274f2016-03-21 08:04:40 -0700214 * Returns the image orientation stored in the EXIF data.
215 * If there is no EXIF data, or if we cannot read the EXIF data, returns kTopLeft.
216 */
Leon Scroggins IIIb6ab10f2017-10-18 14:42:43 -0400217 SkEncodedOrigin getOrigin() const { return fOrigin; }
msarett0e6274f2016-03-21 08:04:40 -0700218
msarett6a738212016-03-04 13:27:35 -0800219 /**
scroggof24f2242015-03-03 08:59:20 -0800220 * Return a size that approximately supports the desired scale factor.
221 * The codec may not be able to scale efficiently to the exact scale
222 * factor requested, so return a size that approximates that scale.
emmaleer8f4ba762015-08-14 07:44:46 -0700223 * The returned value is the codec's suggestion for the closest valid
224 * scale that it can natively support
scroggof24f2242015-03-03 08:59:20 -0800225 */
scroggofffeede2015-03-18 10:50:37 -0700226 SkISize getScaledDimensions(float desiredScale) const {
msarettb32758a2015-08-18 13:22:46 -0700227 // Negative and zero scales are errors.
228 SkASSERT(desiredScale > 0.0f);
229 if (desiredScale <= 0.0f) {
230 return SkISize::Make(0, 0);
231 }
232
233 // Upscaling is not supported. Return the original size if the client
234 // requests an upscale.
235 if (desiredScale >= 1.0f) {
Leon Scroggins III712476e2018-10-03 15:47:00 -0400236 return this->dimensions();
msarettb32758a2015-08-18 13:22:46 -0700237 }
scroggofffeede2015-03-18 10:50:37 -0700238 return this->onGetScaledDimensions(desiredScale);
239 }
scroggof24f2242015-03-03 08:59:20 -0800240
scroggo1dd3ea92015-03-20 11:55:55 -0700241 /**
scroggob636b452015-07-22 07:16:20 -0700242 * Return (via desiredSubset) a subset which can decoded from this codec,
243 * or false if this codec cannot decode subsets or anything similar to
244 * desiredSubset.
245 *
246 * @param desiredSubset In/out parameter. As input, a desired subset of
247 * the original bounds (as specified by getInfo). If true is returned,
248 * desiredSubset may have been modified to a subset which is
249 * supported. Although a particular change may have been made to
250 * desiredSubset to create something supported, it is possible other
251 * changes could result in a valid subset.
252 * If false is returned, desiredSubset's value is undefined.
253 * @return true if this codec supports decoding desiredSubset (as
254 * returned, potentially modified)
255 */
256 bool getValidSubset(SkIRect* desiredSubset) const {
257 return this->onGetValidSubset(desiredSubset);
258 }
259
260 /**
scroggo1dd3ea92015-03-20 11:55:55 -0700261 * Format of the encoded data.
262 */
Hal Canarydb683012016-11-23 08:55:18 -0700263 SkEncodedImageFormat getEncodedFormat() const { return this->onGetEncodedFormat(); }
scroggo1dd3ea92015-03-20 11:55:55 -0700264
scroggo05245902015-03-25 11:11:52 -0700265 /**
scroggoeb602a52015-07-09 08:16:03 -0700266 * Whether or not the memory passed to getPixels is zero initialized.
267 */
268 enum ZeroInitialized {
269 /**
270 * The memory passed to getPixels is zero initialized. The SkCodec
271 * may take advantage of this by skipping writing zeroes.
272 */
273 kYes_ZeroInitialized,
274 /**
275 * The memory passed to getPixels has not been initialized to zero,
276 * so the SkCodec must write all zeroes to memory.
277 *
278 * This is the default. It will be used if no Options struct is used.
279 */
280 kNo_ZeroInitialized,
281 };
282
283 /**
284 * Additional options to pass to getPixels.
285 */
286 struct Options {
287 Options()
scroggob636b452015-07-22 07:16:20 -0700288 : fZeroInitialized(kNo_ZeroInitialized)
scroggo19b91532016-10-24 09:03:26 -0700289 , fSubset(nullptr)
290 , fFrameIndex(0)
Nigel Tao66bc5242018-08-22 10:56:03 +1000291 , fPriorFrame(kNoFrame)
scroggob636b452015-07-22 07:16:20 -0700292 {}
scroggoeb602a52015-07-09 08:16:03 -0700293
Matt Sarettcf3f2342017-03-23 15:32:25 -0400294 ZeroInitialized fZeroInitialized;
scroggob636b452015-07-22 07:16:20 -0700295 /**
296 * If not NULL, represents a subset of the original image to decode.
scroggob636b452015-07-22 07:16:20 -0700297 * Must be within the bounds returned by getInfo().
Hal Canarydb683012016-11-23 08:55:18 -0700298 * If the EncodedFormat is SkEncodedImageFormat::kWEBP (the only one which
scroggob636b452015-07-22 07:16:20 -0700299 * currently supports subsets), the top and left values must be even.
msarettfdb47572015-10-13 12:50:14 -0700300 *
scroggo8e6c7ad2016-09-16 08:20:38 -0700301 * In getPixels and incremental decode, we will attempt to decode the
302 * exact rectangular subset specified by fSubset.
msarettfdb47572015-10-13 12:50:14 -0700303 *
304 * In a scanline decode, it does not make sense to specify a subset
305 * top or subset height, since the client already controls which rows
306 * to get and which rows to skip. During scanline decodes, we will
307 * require that the subset top be zero and the subset height be equal
308 * to the full height. We will, however, use the values of
309 * subset left and subset width to decode partial scanlines on calls
310 * to getScanlines().
scroggob636b452015-07-22 07:16:20 -0700311 */
Matt Sarettcf3f2342017-03-23 15:32:25 -0400312 const SkIRect* fSubset;
scroggo19b91532016-10-24 09:03:26 -0700313
314 /**
315 * The frame to decode.
316 *
317 * Only meaningful for multi-frame images.
318 */
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400319 int fFrameIndex;
scroggo19b91532016-10-24 09:03:26 -0700320
321 /**
Nigel Tao66bc5242018-08-22 10:56:03 +1000322 * If not kNoFrame, the dst already contains the prior frame at this index.
scroggo19b91532016-10-24 09:03:26 -0700323 *
324 * Only meaningful for multi-frame images.
325 *
326 * If fFrameIndex needs to be blended with a prior frame (as reported by
327 * getFrameInfo[fFrameIndex].fRequiredFrame), the client can set this to
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400328 * any non-kRestorePrevious frame in [fRequiredFrame, fFrameIndex) to
329 * indicate that that frame is already in the dst. Options.fZeroInitialized
330 * is ignored in this case.
scroggo19b91532016-10-24 09:03:26 -0700331 *
Nigel Tao66bc5242018-08-22 10:56:03 +1000332 * If set to kNoFrame, the codec will decode any necessary required frame(s) first.
scroggo19b91532016-10-24 09:03:26 -0700333 */
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400334 int fPriorFrame;
scroggoeb602a52015-07-09 08:16:03 -0700335 };
336
337 /**
338 * Decode into the given pixels, a block of memory of size at
339 * least (info.fHeight - 1) * rowBytes + (info.fWidth *
340 * bytesPerPixel)
341 *
342 * Repeated calls to this function should give the same results,
343 * allowing the PixelRef to be immutable.
344 *
345 * @param info A description of the format (config, size)
346 * expected by the caller. This can simply be identical
347 * to the info returned by getInfo().
348 *
349 * This contract also allows the caller to specify
350 * different output-configs, which the implementation can
351 * decide to support or not.
352 *
353 * A size that does not match getInfo() implies a request
354 * to scale. If the generator cannot perform this scale,
355 * it will return kInvalidScale.
356 *
msarett50ce1f22016-07-29 06:23:33 -0700357 * If the info contains a non-null SkColorSpace, the codec
358 * will perform the appropriate color space transformation.
Leon Scroggins III42a604f2020-02-06 15:47:58 -0500359 *
360 * If the caller passes in the SkColorSpace that maps to the
361 * ICC profile reported by getICCProfile(), the color space
362 * transformation is a no-op.
363 *
364 * If the caller passes a null SkColorSpace, no color space
365 * transformation will be done.
msarett50ce1f22016-07-29 06:23:33 -0700366 *
scroggo46c57472015-09-30 08:57:13 -0700367 * If a scanline decode is in progress, scanline mode will end, requiring the client to call
368 * startScanlineDecode() in order to return to decoding scanlines.
369 *
scroggoeb602a52015-07-09 08:16:03 -0700370 * @return Result kSuccess, or another value explaining the type of failure.
371 */
Leon Scroggins571b30f2017-07-11 17:35:31 +0000372 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options*);
scroggoeb602a52015-07-09 08:16:03 -0700373
374 /**
Leon Scroggins571b30f2017-07-11 17:35:31 +0000375 * Simplified version of getPixels() that uses the default Options.
scroggoeb602a52015-07-09 08:16:03 -0700376 */
Leon Scroggins571b30f2017-07-11 17:35:31 +0000377 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
378 return this->getPixels(info, pixels, rowBytes, nullptr);
379 }
scroggoeb602a52015-07-09 08:16:03 -0700380
Mike Reed43798692017-10-17 18:04:32 +0000381 Result getPixels(const SkPixmap& pm, const Options* opts = nullptr) {
382 return this->getPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), opts);
383 }
384
msarettb714fb02016-01-22 14:46:42 -0800385 /**
Mike Reed844beb52021-01-25 15:36:09 -0500386 * Return an image containing the pixels.
387 */
388 std::tuple<sk_sp<SkImage>, SkCodec::Result> getImage(const SkImageInfo& info,
389 const Options* opts = nullptr);
390 std::tuple<sk_sp<SkImage>, SkCodec::Result> getImage();
391
392 /**
Brian Salomon59c60b02020-09-01 15:01:15 -0400393 * If decoding to YUV is supported, this returns true. Otherwise, this
394 * returns false and the caller will ignore output parameter yuvaPixmapInfo.
395 *
396 * @param supportedDataTypes Indicates the data type/planar config combinations that are
397 * supported by the caller. If the generator supports decoding to
398 * YUV(A), but not as a type in supportedDataTypes, this method
399 * returns false.
400 * @param yuvaPixmapInfo Output parameter that specifies the planar configuration, subsampling,
401 * orientation, chroma siting, plane color types, and row bytes.
msarettb714fb02016-01-22 14:46:42 -0800402 */
Brian Salomon59c60b02020-09-01 15:01:15 -0400403 bool queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes,
404 SkYUVAPixmapInfo* yuvaPixmapInfo) const;
msarettb714fb02016-01-22 14:46:42 -0800405
406 /**
Brian Salomonbe0e42c2020-08-27 11:00:04 -0400407 * Returns kSuccess, or another value explaining the type of failure.
408 * This always attempts to perform a full decode. To get the planar
409 * configuration without decoding use queryYUVAInfo().
410 *
411 * @param yuvaPixmaps Contains preallocated pixmaps configured according to a successful call
412 * to queryYUVAInfo().
msarettb714fb02016-01-22 14:46:42 -0800413 */
Brian Salomonbe0e42c2020-08-27 11:00:04 -0400414 Result getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps);
msarettb714fb02016-01-22 14:46:42 -0800415
scroggoeb602a52015-07-09 08:16:03 -0700416 /**
scroggo8e6c7ad2016-09-16 08:20:38 -0700417 * Prepare for an incremental decode with the specified options.
418 *
419 * This may require a rewind.
420 *
Leon Scroggins IIIcb6b8842018-12-04 13:55:13 -0500421 * If kIncompleteInput is returned, may be called again after more data has
422 * been provided to the source SkStream.
423 *
scroggo8e6c7ad2016-09-16 08:20:38 -0700424 * @param dstInfo Info of the destination. If the dimensions do not match
425 * those of getInfo, this implies a scale.
426 * @param dst Memory to write to. Needs to be large enough to hold the subset,
427 * if present, or the full image as described in dstInfo.
428 * @param options Contains decoding options, including if memory is zero
429 * initialized and whether to decode a subset.
scroggo8e6c7ad2016-09-16 08:20:38 -0700430 * @return Enum representing success or reason for failure.
431 */
432 Result startIncrementalDecode(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000433 const Options*);
scroggo8e6c7ad2016-09-16 08:20:38 -0700434
435 Result startIncrementalDecode(const SkImageInfo& dstInfo, void* dst, size_t rowBytes) {
Leon Scroggins571b30f2017-07-11 17:35:31 +0000436 return this->startIncrementalDecode(dstInfo, dst, rowBytes, nullptr);
scroggo8e6c7ad2016-09-16 08:20:38 -0700437 }
438
439 /**
440 * Start/continue the incremental decode.
441 *
Leon Scroggins IIIcb6b8842018-12-04 13:55:13 -0500442 * Not valid to call before a call to startIncrementalDecode() returns
443 * kSuccess.
scroggo8e6c7ad2016-09-16 08:20:38 -0700444 *
Leon Scroggins IIIcb6b8842018-12-04 13:55:13 -0500445 * If kIncompleteInput is returned, may be called again after more data has
446 * been provided to the source SkStream.
scroggo8e6c7ad2016-09-16 08:20:38 -0700447 *
448 * Unlike getPixels and getScanlines, this does not do any filling. This is
449 * left up to the caller, since they may be skipping lines or continuing the
450 * decode later. In the latter case, they may choose to initialize all lines
451 * first, or only initialize the remaining lines after the first call.
452 *
453 * @param rowsDecoded Optional output variable returning the total number of
454 * lines initialized. Only meaningful if this method returns kIncompleteInput.
455 * Otherwise the implementation may not set it.
456 * Note that some implementations may have initialized this many rows, but
457 * not necessarily finished those rows (e.g. interlaced PNG). This may be
458 * useful for determining what rows the client needs to initialize.
459 * @return kSuccess if all lines requested in startIncrementalDecode have
460 * been completely decoded. kIncompleteInput otherwise.
461 */
462 Result incrementalDecode(int* rowsDecoded = nullptr) {
463 if (!fStartedIncrementalDecode) {
464 return kInvalidParameters;
465 }
466 return this->onIncrementalDecode(rowsDecoded);
467 }
468
469 /**
scroggo46c57472015-09-30 08:57:13 -0700470 * The remaining functions revolve around decoding scanlines.
471 */
472
473 /**
474 * Prepare for a scanline decode with the specified options.
475 *
476 * After this call, this class will be ready to decode the first scanline.
477 *
478 * This must be called in order to call getScanlines or skipScanlines.
479 *
480 * This may require rewinding the stream.
481 *
482 * Not all SkCodecs support this.
483 *
484 * @param dstInfo Info of the destination. If the dimensions do not match
485 * those of getInfo, this implies a scale.
486 * @param options Contains decoding options, including if memory is zero
487 * initialized.
scroggo46c57472015-09-30 08:57:13 -0700488 * @return Enum representing success or reason for failure.
489 */
Leon Scroggins571b30f2017-07-11 17:35:31 +0000490 Result startScanlineDecode(const SkImageInfo& dstInfo, const Options* options);
scroggo46c57472015-09-30 08:57:13 -0700491
492 /**
Leon Scroggins571b30f2017-07-11 17:35:31 +0000493 * Simplified version of startScanlineDecode() that uses the default Options.
scroggo46c57472015-09-30 08:57:13 -0700494 */
Leon Scroggins571b30f2017-07-11 17:35:31 +0000495 Result startScanlineDecode(const SkImageInfo& dstInfo) {
496 return this->startScanlineDecode(dstInfo, nullptr);
497 }
scroggo46c57472015-09-30 08:57:13 -0700498
499 /**
500 * Write the next countLines scanlines into dst.
501 *
502 * Not valid to call before calling startScanlineDecode().
503 *
504 * @param dst Must be non-null, and large enough to hold countLines
505 * scanlines of size rowBytes.
506 * @param countLines Number of lines to write.
507 * @param rowBytes Number of bytes per row. Must be large enough to hold
508 * a scanline based on the SkImageInfo used to create this object.
msarette6dd0042015-10-09 11:07:34 -0700509 * @return the number of lines successfully decoded. If this value is
510 * less than countLines, this will fill the remaining lines with a
511 * default value.
scroggo46c57472015-09-30 08:57:13 -0700512 */
msarette6dd0042015-10-09 11:07:34 -0700513 int getScanlines(void* dst, int countLines, size_t rowBytes);
scroggo46c57472015-09-30 08:57:13 -0700514
515 /**
516 * Skip count scanlines.
517 *
518 * Not valid to call before calling startScanlineDecode().
519 *
520 * The default version just calls onGetScanlines and discards the dst.
521 * NOTE: If skipped lines are the only lines with alpha, this default
522 * will make reallyHasAlpha return true, when it could have returned
523 * false.
msarette6dd0042015-10-09 11:07:34 -0700524 *
525 * @return true if the scanlines were successfully skipped
526 * false on failure, possible reasons for failure include:
527 * An incomplete input image stream.
528 * Calling this function before calling startScanlineDecode().
529 * If countLines is less than zero or so large that it moves
530 * the current scanline past the end of the image.
scroggo46c57472015-09-30 08:57:13 -0700531 */
msarette6dd0042015-10-09 11:07:34 -0700532 bool skipScanlines(int countLines);
scroggo46c57472015-09-30 08:57:13 -0700533
534 /**
535 * The order in which rows are output from the scanline decoder is not the
536 * same for all variations of all image types. This explains the possible
537 * output row orderings.
538 */
539 enum SkScanlineOrder {
540 /*
541 * By far the most common, this indicates that the image can be decoded
542 * reliably using the scanline decoder, and that rows will be output in
543 * the logical order.
544 */
545 kTopDown_SkScanlineOrder,
546
547 /*
548 * This indicates that the scanline decoder reliably outputs rows, but
549 * they will be returned in reverse order. If the scanline format is
550 * kBottomUp, the nextScanline() API can be used to determine the actual
551 * y-coordinate of the next output row, but the client is not forced
552 * to take advantage of this, given that it's not too tough to keep
553 * track independently.
554 *
555 * For full image decodes, it is safe to get all of the scanlines at
556 * once, since the decoder will handle inverting the rows as it
557 * decodes.
558 *
559 * For subset decodes and sampling, it is simplest to get and skip
560 * scanlines one at a time, using the nextScanline() API. It is
561 * possible to ask for larger chunks at a time, but this should be used
562 * with caution. As with full image decodes, the decoder will handle
563 * inverting the requested rows, but rows will still be delivered
564 * starting from the bottom of the image.
565 *
566 * Upside down bmps are an example.
567 */
568 kBottomUp_SkScanlineOrder,
scroggo46c57472015-09-30 08:57:13 -0700569 };
570
571 /**
572 * An enum representing the order in which scanlines will be returned by
573 * the scanline decoder.
msarettbe8216a2015-12-04 08:00:50 -0800574 *
575 * This is undefined before startScanlineDecode() is called.
scroggo46c57472015-09-30 08:57:13 -0700576 */
577 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder(); }
578
579 /**
580 * Returns the y-coordinate of the next row to be returned by the scanline
msarette6dd0042015-10-09 11:07:34 -0700581 * decoder.
582 *
583 * This will equal fCurrScanline, except in the case of strangely
scroggo19b91532016-10-24 09:03:26 -0700584 * encoded image types (bottom-up bmps).
scroggo46c57472015-09-30 08:57:13 -0700585 *
586 * Results are undefined when not in scanline decoding mode.
587 */
msarette6dd0042015-10-09 11:07:34 -0700588 int nextScanline() const { return this->outputScanline(fCurrScanline); }
589
590 /**
msarettcb0d5c92015-12-03 12:23:43 -0800591 * Returns the output y-coordinate of the row that corresponds to an input
592 * y-coordinate. The input y-coordinate represents where the scanline
593 * is located in the encoded data.
msarette6dd0042015-10-09 11:07:34 -0700594 *
595 * This will equal inputScanline, except in the case of strangely
596 * encoded image types (bottom-up bmps, interlaced gifs).
597 */
598 int outputScanline(int inputScanline) const;
scroggo46c57472015-09-30 08:57:13 -0700599
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400600 /**
601 * Return the number of frames in the image.
602 *
603 * May require reading through the stream.
604 */
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400605 int getFrameCount() {
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400606 return this->onGetFrameCount();
607 }
608
Nigel Tao66bc5242018-08-22 10:56:03 +1000609 // Sentinel value used when a frame index implies "no frame":
610 // - FrameInfo::fRequiredFrame set to this value means the frame
611 // is independent.
612 // - Options::fPriorFrame set to this value means no (relevant) prior frame
613 // is residing in dst's memory.
614 static constexpr int kNoFrame = -1;
615
Mike Kleineb4d6412018-11-12 16:08:30 +0000616 // This transitional definition was added in August 2018, and will eventually be removed.
617#ifdef SK_LEGACY_SKCODEC_NONE_ENUM
618 static constexpr int kNone = kNoFrame;
619#endif
620
scroggo19b91532016-10-24 09:03:26 -0700621 /**
622 * Information about individual frames in a multi-framed image.
623 */
624 struct FrameInfo {
625 /**
626 * The frame that this frame needs to be blended with, or
Nigel Taob8ec7f12019-03-26 10:44:58 +1100627 * kNoFrame if this frame is independent (so it can be
628 * drawn over an uninitialized buffer).
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400629 *
630 * Note that this is the *earliest* frame that can be used
631 * for blending. Any frame from [fRequiredFrame, i) can be
632 * used, unless its fDisposalMethod is kRestorePrevious.
scroggo19b91532016-10-24 09:03:26 -0700633 */
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400634 int fRequiredFrame;
scroggo19b91532016-10-24 09:03:26 -0700635
636 /**
637 * Number of milliseconds to show this frame.
638 */
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400639 int fDuration;
Leon Scroggins III3639faa2016-12-08 11:38:58 -0500640
641 /**
642 * Whether the end marker for this frame is contained in the stream.
643 *
644 * Note: this does not guarantee that an attempt to decode will be complete.
645 * There could be an error in the stream.
646 */
647 bool fFullyReceived;
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -0400648
649 /**
650 * This is conservative; it will still return non-opaque if e.g. a
651 * color index-based frame has a color with alpha but does not use it.
652 */
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500653 SkAlphaType fAlphaType;
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400654
655 /**
Leon Scroggins III469d67e2020-11-11 12:45:40 -0500656 * Whether the updated rectangle contains alpha.
657 *
658 * This is conservative; it will still be set to true if e.g. a color
659 * index-based frame has a color with alpha but does not use it. In
660 * addition, it may be set to true, even if the final frame, after
661 * blending, is opaque.
662 */
663 bool fHasAlphaWithinBounds;
664
665 /**
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400666 * How this frame should be modified before decoding the next one.
667 */
668 SkCodecAnimation::DisposalMethod fDisposalMethod;
Leon Scroggins III469d67e2020-11-11 12:45:40 -0500669
670 /**
671 * How this frame should blend with the prior frame.
672 */
673 SkCodecAnimation::Blend fBlend;
674
675 /**
676 * The rectangle updated by this frame.
677 *
678 * It may be empty, if the frame does not change the image. It will
679 * always be contained by SkCodec::dimensions().
680 */
681 SkIRect fFrameRect;
scroggo19b91532016-10-24 09:03:26 -0700682 };
683
684 /**
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400685 * Return info about a single frame.
686 *
687 * Only supported by multi-frame images. Does not read through the stream,
688 * so it should be called after getFrameCount() to parse any frames that
689 * have not already been parsed.
690 */
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400691 bool getFrameInfo(int index, FrameInfo* info) const {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400692 if (index < 0) {
693 return false;
694 }
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400695 return this->onGetFrameInfo(index, info);
696 }
697
698 /**
699 * Return info about all the frames in the image.
scroggo19b91532016-10-24 09:03:26 -0700700 *
scroggoe71b1a12016-11-01 08:28:28 -0700701 * May require reading through the stream to determine info about the
702 * frames (including the count).
scroggo19b91532016-10-24 09:03:26 -0700703 *
704 * As such, future decoding calls may require a rewind.
705 *
Nigel Tao96597c22018-08-22 10:36:12 +1000706 * For still (non-animated) image codecs, this will return an empty vector.
scroggo19b91532016-10-24 09:03:26 -0700707 */
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400708 std::vector<FrameInfo> getFrameInfo();
scroggo19b91532016-10-24 09:03:26 -0700709
scroggoe71b1a12016-11-01 08:28:28 -0700710 static constexpr int kRepetitionCountInfinite = -1;
711
712 /**
Nigel Tao96597c22018-08-22 10:36:12 +1000713 * Return the number of times to repeat, if this image is animated. This number does not
714 * include the first play through of each frame. For example, a repetition count of 4 means
715 * that each frame is played 5 times and then the animation stops.
716 *
717 * It can return kRepetitionCountInfinite, a negative number, meaning that the animation
718 * should loop forever.
scroggoe71b1a12016-11-01 08:28:28 -0700719 *
720 * May require reading the stream to find the repetition count.
721 *
722 * As such, future decoding calls may require a rewind.
723 *
Nigel Tao96597c22018-08-22 10:36:12 +1000724 * For still (non-animated) image codecs, this will return 0.
scroggoe71b1a12016-11-01 08:28:28 -0700725 */
726 int getRepetitionCount() {
727 return this->onGetRepetitionCount();
728 }
729
Mike Klein159a9592019-04-26 15:47:56 +0000730 // Register a decoder at runtime by passing two function pointers:
731 // - peek() to return true if the span of bytes appears to be your encoded format;
732 // - make() to attempt to create an SkCodec from the given stream.
733 // Not thread safe.
734 static void Register(
735 bool (*peek)(const void*, size_t),
736 std::unique_ptr<SkCodec> (*make)(std::unique_ptr<SkStream>, SkCodec::Result*));
737
scroggof24f2242015-03-03 08:59:20 -0800738protected:
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500739 const SkEncodedInfo& getEncodedInfo() const { return fEncodedInfo; }
740
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400741 using XformFormat = skcms_PixelFormat;
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400742
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400743 SkCodec(SkEncodedInfo&&,
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400744 XformFormat srcFormat,
Mike Reedede7bac2017-07-23 15:30:02 -0400745 std::unique_ptr<SkStream>,
Leon Scroggins IIIb6ab10f2017-10-18 14:42:43 -0400746 SkEncodedOrigin = kTopLeft_SkEncodedOrigin);
msarett549ca322016-08-17 08:54:08 -0700747
msarettb714fb02016-01-22 14:46:42 -0800748 virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const {
scroggof24f2242015-03-03 08:59:20 -0800749 // By default, scaling is not supported.
Leon Scroggins III712476e2018-10-03 15:47:00 -0400750 return this->dimensions();
scroggof24f2242015-03-03 08:59:20 -0800751 }
752
scroggoe7fc14b2015-10-02 13:14:46 -0700753 // FIXME: What to do about subsets??
754 /**
755 * Subclasses should override if they support dimensions other than the
756 * srcInfo's.
757 */
758 virtual bool onDimensionsSupported(const SkISize&) {
759 return false;
760 }
761
Hal Canarydb683012016-11-23 08:55:18 -0700762 virtual SkEncodedImageFormat onGetEncodedFormat() const = 0;
scroggo1dd3ea92015-03-20 11:55:55 -0700763
msarette6dd0042015-10-09 11:07:34 -0700764 /**
765 * @param rowsDecoded When the encoded image stream is incomplete, this function
766 * will return kIncompleteInput and rowsDecoded will be set to
767 * the number of scanlines that were successfully decoded.
768 * This will allow getPixels() to fill the uninitialized memory.
769 */
scroggoeb602a52015-07-09 08:16:03 -0700770 virtual Result onGetPixels(const SkImageInfo& info,
771 void* pixels, size_t rowBytes, const Options&,
msarette6dd0042015-10-09 11:07:34 -0700772 int* rowsDecoded) = 0;
scroggoeb602a52015-07-09 08:16:03 -0700773
Brian Salomon59c60b02020-09-01 15:01:15 -0400774 virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes&,
775 SkYUVAPixmapInfo*) const { return false; }
msarettb714fb02016-01-22 14:46:42 -0800776
Brian Salomonbe0e42c2020-08-27 11:00:04 -0400777 virtual Result onGetYUVAPlanes(const SkYUVAPixmaps&) { return kUnimplemented; }
msarettb714fb02016-01-22 14:46:42 -0800778
779 virtual bool onGetValidSubset(SkIRect* /*desiredSubset*/) const {
scroggob636b452015-07-22 07:16:20 -0700780 // By default, subsets are not supported.
781 return false;
782 }
783
msarett90c4d5f2015-12-10 13:09:24 -0800784 /**
scroggof24f2242015-03-03 08:59:20 -0800785 * If the stream was previously read, attempt to rewind.
scroggob427db12015-08-12 07:24:13 -0700786 *
787 * If the stream needed to be rewound, call onRewind.
788 * @returns true if the codec is at the right position and can be used.
789 * false if there was a failure to rewind.
halcanarya096d7a2015-03-27 12:16:53 -0700790 *
Nigel Tao13df9812018-08-08 14:33:58 +1000791 * This is called by getPixels(), getYUV8Planes(), startIncrementalDecode() and
792 * startScanlineDecode(). Subclasses may call if they need to rewind at another time.
scroggof24f2242015-03-03 08:59:20 -0800793 */
scroggob427db12015-08-12 07:24:13 -0700794 bool SK_WARN_UNUSED_RESULT rewindIfNeeded();
795
796 /**
797 * Called by rewindIfNeeded, if the stream needed to be rewound.
798 *
799 * Subclasses should do any set up needed after a rewind.
800 */
801 virtual bool onRewind() {
802 return true;
803 }
scroggof24f2242015-03-03 08:59:20 -0800804
msarettc0e80c12015-07-01 06:50:35 -0700805 /**
msarett74114382015-03-16 11:55:18 -0700806 * Get method for the input stream
msarett74114382015-03-16 11:55:18 -0700807 */
808 SkStream* stream() {
809 return fStream.get();
810 }
811
scroggo46c57472015-09-30 08:57:13 -0700812 /**
813 * The remaining functions revolve around decoding scanlines.
814 */
815
816 /**
817 * Most images types will be kTopDown and will not need to override this function.
818 */
819 virtual SkScanlineOrder onGetScanlineOrder() const { return kTopDown_SkScanlineOrder; }
820
scroggo46c57472015-09-30 08:57:13 -0700821 const SkImageInfo& dstInfo() const { return fDstInfo; }
822
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400823 const Options& options() const { return fOptions; }
scroggo46c57472015-09-30 08:57:13 -0700824
msarettcb0d5c92015-12-03 12:23:43 -0800825 /**
826 * Returns the number of scanlines that have been decoded so far.
827 * This is unaffected by the SkScanlineOrder.
828 *
829 * Returns -1 if we have not started a scanline decode.
830 */
831 int currScanline() const { return fCurrScanline; }
832
msarette6dd0042015-10-09 11:07:34 -0700833 virtual int onOutputScanline(int inputScanline) const;
834
Leon Scroggins III9b0ba2c2018-11-19 14:52:37 -0500835 /**
836 * Return whether we can convert to dst.
837 *
838 * Will be called for the appropriate frame, prior to initializing the colorXform.
839 */
840 virtual bool conversionSupported(const SkImageInfo& dst, bool srcIsOpaque,
841 bool needsColorXform);
842
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400843 // Some classes never need a colorXform e.g.
844 // - ICO uses its embedded codec's colorXform
845 // - WBMP is just Black/White
846 virtual bool usesColorXform() const { return true; }
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400847 void applyColorXform(void* dst, const void* src, int count) const;
848
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400849 bool colorXform() const { return fXformTime != kNo_XformTime; }
850 bool xformOnDecode() const { return fXformTime == kDecodeRow_XformTime; }
Matt Sarett313c4632016-10-20 12:35:23 -0400851
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400852 virtual int onGetFrameCount() {
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400853 return 1;
854 }
855
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400856 virtual bool onGetFrameInfo(int, FrameInfo*) const {
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400857 return false;
scroggo19b91532016-10-24 09:03:26 -0700858 }
859
scroggoe71b1a12016-11-01 08:28:28 -0700860 virtual int onGetRepetitionCount() {
861 return 0;
862 }
863
Matt Sarett313c4632016-10-20 12:35:23 -0400864private:
865 const SkEncodedInfo fEncodedInfo;
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400866 const XformFormat fSrcXformFormat;
bungeman6bd52842016-10-27 09:30:08 -0700867 std::unique_ptr<SkStream> fStream;
Matt Sarett313c4632016-10-20 12:35:23 -0400868 bool fNeedsRewind;
Leon Scroggins IIIb6ab10f2017-10-18 14:42:43 -0400869 const SkEncodedOrigin fOrigin;
Matt Sarett313c4632016-10-20 12:35:23 -0400870
871 SkImageInfo fDstInfo;
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400872 Options fOptions;
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400873
874 enum XformTime {
875 kNo_XformTime,
876 kPalette_XformTime,
877 kDecodeRow_XformTime,
878 };
879 XformTime fXformTime;
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400880 XformFormat fDstXformFormat; // Based on fDstInfo.
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400881 skcms_ICCProfile fDstProfile;
882 skcms_AlphaFormat fDstXformAlphaFormat;
scroggo8e6c7ad2016-09-16 08:20:38 -0700883
884 // Only meaningful during scanline decodes.
Matt Sarett313c4632016-10-20 12:35:23 -0400885 int fCurrScanline;
scroggo46c57472015-09-30 08:57:13 -0700886
Matt Sarett313c4632016-10-20 12:35:23 -0400887 bool fStartedIncrementalDecode;
scroggo8e6c7ad2016-09-16 08:20:38 -0700888
Leon Scroggins1340dbd2020-11-09 14:18:12 -0500889 // Allows SkAndroidCodec to call handleFrameIndex (potentially decoding a prior frame and
890 // clearing to transparent) without SkCodec calling it, too.
891 bool fAndroidCodecHandlesFrameIndex;
892
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400893 bool initializeColorXform(const SkImageInfo& dstInfo, SkEncodedInfo::Alpha, bool srcIsOpaque);
894
Leon Scroggins III07418182017-08-15 12:24:02 -0400895 /**
scroggoe7fc14b2015-10-02 13:14:46 -0700896 * Return whether these dimensions are supported as a scale.
897 *
898 * The codec may choose to cache the information about scale and subset.
899 * Either way, the same information will be passed to onGetPixels/onStart
900 * on success.
901 *
902 * This must return true for a size returned from getScaledDimensions.
903 */
904 bool dimensionsSupported(const SkISize& dim) {
Leon Scroggins III712476e2018-10-03 15:47:00 -0400905 return dim == this->dimensions() || this->onDimensionsSupported(dim);
scroggoe7fc14b2015-10-02 13:14:46 -0700906 }
907
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400908 /**
909 * For multi-framed images, return the object with information about the frames.
910 */
911 virtual const SkFrameHolder* getFrameHolder() const {
912 return nullptr;
913 }
914
915 /**
916 * Check for a valid Options.fFrameIndex, and decode prior frames if necessary.
Leon Scroggins1340dbd2020-11-09 14:18:12 -0500917 *
918 * If androidCodec is not null, that means this SkCodec is owned by an SkAndroidCodec. In that
919 * case, the Options will be treated as an AndroidOptions, and SkAndroidCodec will be used to
920 * decode a prior frame, if a prior frame is needed. When such an owned SkCodec calls
921 * handleFrameIndex, it will immediately return kSuccess, since SkAndroidCodec already handled
922 * it.
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400923 */
Leon Scroggins1340dbd2020-11-09 14:18:12 -0500924 Result handleFrameIndex(const SkImageInfo&, void* pixels, size_t rowBytes, const Options&,
925 SkAndroidCodec* androidCodec = nullptr);
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400926
scroggo46c57472015-09-30 08:57:13 -0700927 // Methods for scanline decoding.
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400928 virtual Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000929 const Options& /*options*/) {
scroggo46c57472015-09-30 08:57:13 -0700930 return kUnimplemented;
931 }
932
scroggo8e6c7ad2016-09-16 08:20:38 -0700933 virtual Result onStartIncrementalDecode(const SkImageInfo& /*dstInfo*/, void*, size_t,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000934 const Options&) {
scroggo8e6c7ad2016-09-16 08:20:38 -0700935 return kUnimplemented;
936 }
937
938 virtual Result onIncrementalDecode(int*) {
939 return kUnimplemented;
940 }
941
942
msarett9b9497e2016-02-11 13:29:36 -0800943 virtual bool onSkipScanlines(int /*countLines*/) { return false; }
scroggo46c57472015-09-30 08:57:13 -0700944
msarett33bee092015-11-11 12:43:07 -0800945 virtual int onGetScanlines(void* /*dst*/, int /*countLines*/, size_t /*rowBytes*/) { return 0; }
msarette6dd0042015-10-09 11:07:34 -0700946
947 /**
948 * On an incomplete decode, getPixels() and getScanlines() will call this function
949 * to fill any uinitialized memory.
950 *
951 * @param dstInfo Contains the destination color type
952 * Contains the destination alpha type
953 * Contains the destination width
954 * The height stored in this info is unused
955 * @param dst Pointer to the start of destination pixel memory
956 * @param rowBytes Stride length in destination pixel memory
957 * @param zeroInit Indicates if memory is zero initialized
958 * @param linesRequested Number of lines that the client requested
959 * @param linesDecoded Number of lines that were successfully decoded
960 */
961 void fillIncompleteImage(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
962 ZeroInitialized zeroInit, int linesRequested, int linesDecoded);
scroggo46c57472015-09-30 08:57:13 -0700963
scroggoe7fc14b2015-10-02 13:14:46 -0700964 /**
965 * Return an object which will allow forcing scanline decodes to sample in X.
966 *
967 * May create a sampler, if one is not currently being used. Otherwise, does
968 * not affect ownership.
969 *
scroggo19b91532016-10-24 09:03:26 -0700970 * Only valid during scanline decoding or incremental decoding.
scroggoe7fc14b2015-10-02 13:14:46 -0700971 */
msarett33bee092015-11-11 12:43:07 -0800972 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; }
scroggoe7fc14b2015-10-02 13:14:46 -0700973
scroggo8e6c7ad2016-09-16 08:20:38 -0700974 friend class DM::CodecSrc; // for fillIncompleteImage
msarett3d9d7a72015-10-21 10:27:10 -0700975 friend class SkSampledCodec;
msarettbe8216a2015-12-04 08:00:50 -0800976 friend class SkIcoCodec;
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500977 friend class SkAndroidCodec; // for fEncodedInfo
scroggof24f2242015-03-03 08:59:20 -0800978};
979#endif // SkCodec_DEFINED