blob: 449812d1bc0b99d9c87a664dab46bd684feffc40 [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
msarettb46e5e22015-07-30 11:36:40 -07008#include "SkBmpCodec.h"
scroggof24f2242015-03-03 08:59:20 -08009#include "SkCodec.h"
msarett8c8f22a2015-04-01 06:58:48 -070010#include "SkCodecPriv.h"
msarettad8bcfe2016-03-07 07:09:03 -080011#include "SkColorSpace.h"
msarett1a464672016-01-07 13:17:19 -080012#include "SkData.h"
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -040013#include "SkFrameHolder.h"
msarettf7eb6fc2016-09-13 09:04:11 -070014#include "SkHalf.h"
Leon Scroggins III04be2b52017-08-17 15:13:20 -040015#ifdef SK_HAS_HEIF_LIBRARY
16#include "SkHeifCodec.h"
17#endif
msarett1a464672016-01-07 13:17:19 -080018#include "SkIcoCodec.h"
msarette16b04a2015-04-15 07:32:19 -070019#include "SkJpegCodec.h"
msarettad3a5c62016-05-06 07:21:26 -070020#ifdef SK_HAS_PNG_LIBRARY
msarettbe1d5552016-01-21 09:05:23 -080021#include "SkPngCodec.h"
yujieqin916de9f2016-01-25 08:26:16 -080022#endif
msarett39b2d5a2016-02-17 08:26:31 -080023#include "SkRawCodec.h"
scroggof24f2242015-03-03 08:59:20 -080024#include "SkStream.h"
msarett1a464672016-01-07 13:17:19 -080025#include "SkWbmpCodec.h"
scroggo6f5e6192015-06-18 12:53:43 -070026#include "SkWebpCodec.h"
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -040027#ifdef SK_HAS_WUFFS_LIBRARY
28#include "SkWuffsCodec.h"
29#else
30#include "SkGifCodec.h"
31#endif
scroggof24f2242015-03-03 08:59:20 -080032
msarett74114382015-03-16 11:55:18 -070033struct DecoderProc {
scroggodb30be22015-12-08 18:54:13 -080034 bool (*IsFormat)(const void*, size_t);
Mike Reedede7bac2017-07-23 15:30:02 -040035 std::unique_ptr<SkCodec> (*MakeFromStream)(std::unique_ptr<SkStream>, SkCodec::Result*);
msarett74114382015-03-16 11:55:18 -070036};
37
Leon Scroggins III862c1962017-10-02 16:28:49 -040038static constexpr DecoderProc gDecoderProcs[] = {
msarettad3a5c62016-05-06 07:21:26 -070039#ifdef SK_HAS_JPEG_LIBRARY
Mike Reedede7bac2017-07-23 15:30:02 -040040 { SkJpegCodec::IsJpeg, SkJpegCodec::MakeFromStream },
msarett39b2d5a2016-02-17 08:26:31 -080041#endif
msarettad3a5c62016-05-06 07:21:26 -070042#ifdef SK_HAS_WEBP_LIBRARY
Mike Reedede7bac2017-07-23 15:30:02 -040043 { SkWebpCodec::IsWebp, SkWebpCodec::MakeFromStream },
msarett39b2d5a2016-02-17 08:26:31 -080044#endif
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -040045#ifdef SK_HAS_WUFFS_LIBRARY
46 { SkWuffsCodec_IsFormat, SkWuffsCodec_MakeFromStream },
47#else
Mike Reedede7bac2017-07-23 15:30:02 -040048 { SkGifCodec::IsGif, SkGifCodec::MakeFromStream },
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -040049#endif
msarettad3a5c62016-05-06 07:21:26 -070050#ifdef SK_HAS_PNG_LIBRARY
Mike Reedede7bac2017-07-23 15:30:02 -040051 { SkIcoCodec::IsIco, SkIcoCodec::MakeFromStream },
msarett39b2d5a2016-02-17 08:26:31 -080052#endif
Mike Reedede7bac2017-07-23 15:30:02 -040053 { SkBmpCodec::IsBmp, SkBmpCodec::MakeFromStream },
Leon Scroggins III04be2b52017-08-17 15:13:20 -040054 { SkWbmpCodec::IsWbmp, SkWbmpCodec::MakeFromStream },
55#ifdef SK_HAS_HEIF_LIBRARY
56 { SkHeifCodec::IsHeif, SkHeifCodec::MakeFromStream },
57#endif
msarett74114382015-03-16 11:55:18 -070058};
59
Mike Reedede7bac2017-07-23 15:30:02 -040060std::unique_ptr<SkCodec> SkCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
61 Result* outResult, SkPngChunkReader* chunkReader) {
Leon Scroggins III588fb042017-07-14 16:32:31 -040062 Result resultStorage;
63 if (!outResult) {
64 outResult = &resultStorage;
65 }
66
scroggof24f2242015-03-03 08:59:20 -080067 if (!stream) {
Leon Scroggins III588fb042017-07-14 16:32:31 -040068 *outResult = kInvalidInput;
halcanary96fcdcc2015-08-27 07:41:13 -070069 return nullptr;
scroggof24f2242015-03-03 08:59:20 -080070 }
scroggo0a7e69c2015-04-03 07:22:22 -070071
Leon Scroggins III04be2b52017-08-17 15:13:20 -040072 constexpr size_t bytesToRead = MinBufferedBytesNeeded();
scroggodb30be22015-12-08 18:54:13 -080073
74 char buffer[bytesToRead];
75 size_t bytesRead = stream->peek(buffer, bytesToRead);
76
77 // It is also possible to have a complete image less than bytesToRead bytes
78 // (e.g. a 1 x 1 wbmp), meaning peek() would return less than bytesToRead.
79 // Assume that if bytesRead < bytesToRead, but > 0, the stream is shorter
80 // than bytesToRead, so pass that directly to the decoder.
81 // It also is possible the stream uses too small a buffer for peeking, but
82 // we trust the caller to use a large enough buffer.
83
84 if (0 == bytesRead) {
scroggo3ab9f2e2016-01-06 09:53:34 -080085 // TODO: After implementing peek in CreateJavaOutputStreamAdaptor.cpp, this
86 // printf could be useful to notice failures.
87 // SkCodecPrintf("Encoded image data failed to peek!\n");
88
scroggodb30be22015-12-08 18:54:13 -080089 // It is possible the stream does not support peeking, but does support
90 // rewinding.
91 // Attempt to read() and pass the actual amount read to the decoder.
92 bytesRead = stream->read(buffer, bytesToRead);
93 if (!stream->rewind()) {
scroggo3ab9f2e2016-01-06 09:53:34 -080094 SkCodecPrintf("Encoded image data could not peek or rewind to determine format!\n");
Leon Scroggins III588fb042017-07-14 16:32:31 -040095 *outResult = kCouldNotRewind;
scroggodb30be22015-12-08 18:54:13 -080096 return nullptr;
97 }
98 }
99
scroggocf98fa92015-11-23 08:14:40 -0800100 // PNG is special, since we want to be able to supply an SkPngChunkReader.
101 // But this code follows the same pattern as the loop.
msarettad3a5c62016-05-06 07:21:26 -0700102#ifdef SK_HAS_PNG_LIBRARY
scroggodb30be22015-12-08 18:54:13 -0800103 if (SkPngCodec::IsPng(buffer, bytesRead)) {
Mike Reedede7bac2017-07-23 15:30:02 -0400104 return SkPngCodec::MakeFromStream(std::move(stream), outResult, chunkReader);
msarett39b2d5a2016-02-17 08:26:31 -0800105 } else
106#endif
107 {
scroggocf98fa92015-11-23 08:14:40 -0800108 for (DecoderProc proc : gDecoderProcs) {
scroggodb30be22015-12-08 18:54:13 -0800109 if (proc.IsFormat(buffer, bytesRead)) {
Mike Reedede7bac2017-07-23 15:30:02 -0400110 return proc.MakeFromStream(std::move(stream), outResult);
scroggocf98fa92015-11-23 08:14:40 -0800111 }
msarett74114382015-03-16 11:55:18 -0700112 }
yujieqin916de9f2016-01-25 08:26:16 -0800113
114#ifdef SK_CODEC_DECODES_RAW
115 // Try to treat the input as RAW if all the other checks failed.
Mike Reedede7bac2017-07-23 15:30:02 -0400116 return SkRawCodec::MakeFromStream(std::move(stream), outResult);
yujieqin916de9f2016-01-25 08:26:16 -0800117#endif
scroggof24f2242015-03-03 08:59:20 -0800118 }
msarett8c8f22a2015-04-01 06:58:48 -0700119
Leon Scroggins III588fb042017-07-14 16:32:31 -0400120 if (bytesRead < bytesToRead) {
121 *outResult = kIncompleteInput;
122 } else {
123 *outResult = kUnimplemented;
124 }
125
msarettf44631b2016-01-13 10:54:20 -0800126 return nullptr;
scroggof24f2242015-03-03 08:59:20 -0800127}
128
Mike Reedede7bac2017-07-23 15:30:02 -0400129std::unique_ptr<SkCodec> SkCodec::MakeFromData(sk_sp<SkData> data, SkPngChunkReader* reader) {
scroggof24f2242015-03-03 08:59:20 -0800130 if (!data) {
halcanary96fcdcc2015-08-27 07:41:13 -0700131 return nullptr;
scroggof24f2242015-03-03 08:59:20 -0800132 }
Mike Reed847068c2017-07-26 11:35:53 -0400133 return MakeFromStream(SkMemoryStream::Make(std::move(data)), nullptr, reader);
scroggof24f2242015-03-03 08:59:20 -0800134}
135
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400136SkCodec::SkCodec(SkEncodedInfo&& info, XformFormat srcFormat, std::unique_ptr<SkStream> stream,
137 SkEncodedOrigin origin)
138 : fEncodedInfo(std::move(info))
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400139 , fSrcXformFormat(srcFormat)
Mike Reedede7bac2017-07-23 15:30:02 -0400140 , fStream(std::move(stream))
msarett549ca322016-08-17 08:54:08 -0700141 , fNeedsRewind(false)
142 , fOrigin(origin)
143 , fDstInfo()
144 , fOptions()
145 , fCurrScanline(-1)
Ivan Afanasyev26315582017-10-09 10:09:53 +0700146 , fStartedIncrementalDecode(false)
msarett549ca322016-08-17 08:54:08 -0700147{}
148
scroggo9b2cdbf42015-07-10 12:07:02 -0700149SkCodec::~SkCodec() {}
scroggoeb602a52015-07-09 08:16:03 -0700150
Leon Scroggins III712476e2018-10-03 15:47:00 -0400151bool SkCodec::conversionSupported(const SkImageInfo& dst, bool srcIsOpaque, bool needsColorXform) {
Leon Scroggins III07418182017-08-15 12:24:02 -0400152 if (!valid_alpha(dst.alphaType(), srcIsOpaque)) {
153 return false;
154 }
155
156 switch (dst.colorType()) {
157 case kRGBA_8888_SkColorType:
158 case kBGRA_8888_SkColorType:
159 return true;
160 case kRGBA_F16_SkColorType:
Mike Kleince4cf722018-05-10 11:29:15 -0400161 return dst.colorSpace();
Leon Scroggins III07418182017-08-15 12:24:02 -0400162 case kRGB_565_SkColorType:
163 return srcIsOpaque;
164 case kGray_8_SkColorType:
Leon Scroggins III712476e2018-10-03 15:47:00 -0400165 return SkEncodedInfo::kGray_Color == fEncodedInfo.color() && srcIsOpaque;
Mike Reedd6cb11e2017-11-30 15:33:04 -0500166 case kAlpha_8_SkColorType:
167 // conceptually we can convert anything into alpha_8, but we haven't actually coded
Leon Scroggins III712476e2018-10-03 15:47:00 -0400168 // all of those other conversions yet.
169 return SkEncodedInfo::kXAlpha_Color == fEncodedInfo.color();
Leon Scroggins III07418182017-08-15 12:24:02 -0400170 default:
171 return false;
172 }
Leon Scroggins III07418182017-08-15 12:24:02 -0400173}
174
scroggob427db12015-08-12 07:24:13 -0700175bool SkCodec::rewindIfNeeded() {
scroggof24f2242015-03-03 08:59:20 -0800176 // Store the value of fNeedsRewind so we can update it. Next read will
177 // require a rewind.
halcanarya096d7a2015-03-27 12:16:53 -0700178 const bool needsRewind = fNeedsRewind;
scroggof24f2242015-03-03 08:59:20 -0800179 fNeedsRewind = true;
halcanarya096d7a2015-03-27 12:16:53 -0700180 if (!needsRewind) {
scroggob427db12015-08-12 07:24:13 -0700181 return true;
halcanarya096d7a2015-03-27 12:16:53 -0700182 }
scroggob427db12015-08-12 07:24:13 -0700183
scroggo46c57472015-09-30 08:57:13 -0700184 // startScanlineDecode will need to be called before decoding scanlines.
185 fCurrScanline = -1;
scroggo8e6c7ad2016-09-16 08:20:38 -0700186 // startIncrementalDecode will need to be called before incrementalDecode.
187 fStartedIncrementalDecode = false;
scroggo46c57472015-09-30 08:57:13 -0700188
scroggo19b91532016-10-24 09:03:26 -0700189 // Some codecs do not have a stream. They may hold onto their own data or another codec.
190 // They must handle rewinding themselves.
191 if (fStream && !fStream->rewind()) {
scroggob427db12015-08-12 07:24:13 -0700192 return false;
193 }
194
195 return this->onRewind();
scroggof24f2242015-03-03 08:59:20 -0800196}
scroggo05245902015-03-25 11:11:52 -0700197
Leon Scroggins III7916c0e2018-05-24 13:04:06 -0400198bool zero_rect(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes,
199 SkISize srcDimensions, SkIRect prevRect) {
200 const auto dimensions = dstInfo.dimensions();
201 if (dimensions != srcDimensions) {
202 SkRect src = SkRect::Make(srcDimensions);
203 SkRect dst = SkRect::Make(dimensions);
204 SkMatrix map = SkMatrix::MakeRectToRect(src, dst, SkMatrix::kCenter_ScaleToFit);
205 SkRect asRect = SkRect::Make(prevRect);
206 if (!map.mapRect(&asRect)) {
207 return false;
208 }
209 asRect.roundIn(&prevRect);
210 if (prevRect.isEmpty()) {
211 // Down-scaling shrank the empty portion to nothing,
212 // so nothing to zero.
213 return true;
214 }
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400215 }
Leon Scroggins III7916c0e2018-05-24 13:04:06 -0400216
217 if (!prevRect.intersect(dstInfo.bounds())) {
218 SkCodecPrintf("rectangles do not intersect!");
219 SkASSERT(false);
220 return true;
221 }
222
223 const SkImageInfo info = dstInfo.makeWH(prevRect.width(), prevRect.height());
Mike Reed7fcfb622018-02-09 13:26:46 -0500224 const size_t bpp = dstInfo.bytesPerPixel();
Leon Scroggins III7916c0e2018-05-24 13:04:06 -0400225 const size_t offset = prevRect.x() * bpp + prevRect.y() * rowBytes;
226 void* eraseDst = SkTAddOffset<void>(pixels, offset);
Leon Scroggins IIIe643a9e2018-08-03 16:15:04 -0400227 SkSampler::Fill(info, eraseDst, rowBytes, SkCodec::kNo_ZeroInitialized);
Leon Scroggins III7916c0e2018-05-24 13:04:06 -0400228 return true;
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400229}
230
231SkCodec::Result SkCodec::handleFrameIndex(const SkImageInfo& info, void* pixels, size_t rowBytes,
232 const Options& options) {
233 const int index = options.fFrameIndex;
234 if (0 == index) {
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400235 return this->initializeColorXform(info, fEncodedInfo.alpha(), fEncodedInfo.opaque())
236 ? kSuccess : kInvalidConversion;
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400237 }
238
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400239 if (index < 0) {
240 return kInvalidParameters;
241 }
242
Leon Scroggins III42ee2842018-01-14 14:46:51 -0500243 if (options.fSubset) {
244 // If we add support for this, we need to update the code that zeroes
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400245 // a kRestoreBGColor frame.
246 return kInvalidParameters;
247 }
248
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400249 if (index >= this->onGetFrameCount()) {
250 return kIncompleteInput;
251 }
252
253 const auto* frameHolder = this->getFrameHolder();
254 SkASSERT(frameHolder);
255
256 const auto* frame = frameHolder->getFrame(index);
257 SkASSERT(frame);
258
259 const int requiredFrame = frame->getRequiredFrame();
Nigel Tao66bc5242018-08-22 10:56:03 +1000260 if (requiredFrame != kNoFrame) {
261 if (options.fPriorFrame != kNoFrame) {
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400262 // Check for a valid frame as a starting point. Alternatively, we could
263 // treat an invalid frame as not providing one, but rejecting it will
264 // make it easier to catch the mistake.
265 if (options.fPriorFrame < requiredFrame || options.fPriorFrame >= index) {
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400266 return kInvalidParameters;
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400267 }
268 const auto* prevFrame = frameHolder->getFrame(options.fPriorFrame);
269 switch (prevFrame->getDisposalMethod()) {
270 case SkCodecAnimation::DisposalMethod::kRestorePrevious:
271 return kInvalidParameters;
272 case SkCodecAnimation::DisposalMethod::kRestoreBGColor:
273 // If a frame after the required frame is provided, there is no
274 // need to clear, since it must be covered by the desired frame.
275 if (options.fPriorFrame == requiredFrame) {
Leon Scroggins III42ee2842018-01-14 14:46:51 -0500276 SkIRect prevRect = prevFrame->frameRect();
Leon Scroggins III712476e2018-10-03 15:47:00 -0400277 if (!zero_rect(info, pixels, rowBytes, this->dimensions(), prevRect)) {
Leon Scroggins III7916c0e2018-05-24 13:04:06 -0400278 return kInternalError;
Leon Scroggins III42ee2842018-01-14 14:46:51 -0500279 }
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400280 }
281 break;
282 default:
283 break;
284 }
285 } else {
286 Options prevFrameOptions(options);
287 prevFrameOptions.fFrameIndex = requiredFrame;
288 prevFrameOptions.fZeroInitialized = kNo_ZeroInitialized;
289 const Result result = this->getPixels(info, pixels, rowBytes, &prevFrameOptions);
290 if (result != kSuccess) {
291 return result;
292 }
293 const auto* prevFrame = frameHolder->getFrame(requiredFrame);
294 const auto disposalMethod = prevFrame->getDisposalMethod();
295 if (disposalMethod == SkCodecAnimation::DisposalMethod::kRestoreBGColor) {
Leon Scroggins III7916c0e2018-05-24 13:04:06 -0400296 auto prevRect = prevFrame->frameRect();
Leon Scroggins III712476e2018-10-03 15:47:00 -0400297 if (!zero_rect(info, pixels, rowBytes, this->dimensions(), prevRect)) {
Leon Scroggins III7916c0e2018-05-24 13:04:06 -0400298 return kInternalError;
299 }
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400300 }
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400301 }
302 }
303
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400304 return this->initializeColorXform(info, frame->reportedAlpha(), !frame->hasAlpha())
305 ? kSuccess : kInvalidConversion;
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400306}
scroggo8e6c7ad2016-09-16 08:20:38 -0700307
Brian Osman84f8a612018-09-28 10:35:22 -0400308SkCodec::Result SkCodec::getPixels(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000309 const Options* options) {
Brian Osman84f8a612018-09-28 10:35:22 -0400310 SkImageInfo info = dstInfo;
311 if (!info.colorSpace()) {
312 info = info.makeColorSpace(SkColorSpace::MakeSRGB());
313 }
314
scroggoeb602a52015-07-09 08:16:03 -0700315 if (kUnknown_SkColorType == info.colorType()) {
316 return kInvalidConversion;
317 }
halcanary96fcdcc2015-08-27 07:41:13 -0700318 if (nullptr == pixels) {
scroggoeb602a52015-07-09 08:16:03 -0700319 return kInvalidParameters;
320 }
321 if (rowBytes < info.minRowBytes()) {
322 return kInvalidParameters;
323 }
324
scroggo3a7701c2015-09-30 09:15:14 -0700325 if (!this->rewindIfNeeded()) {
326 return kCouldNotRewind;
327 }
328
scroggoeb602a52015-07-09 08:16:03 -0700329 // Default options.
330 Options optsStorage;
halcanary96fcdcc2015-08-27 07:41:13 -0700331 if (nullptr == options) {
scroggoeb602a52015-07-09 08:16:03 -0700332 options = &optsStorage;
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400333 } else {
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400334 if (options->fSubset) {
335 SkIRect subset(*options->fSubset);
336 if (!this->onGetValidSubset(&subset) || subset != *options->fSubset) {
337 // FIXME: How to differentiate between not supporting subset at all
338 // and not supporting this particular subset?
339 return kUnimplemented;
340 }
scroggoe7fc14b2015-10-02 13:14:46 -0700341 }
scroggoeb602a52015-07-09 08:16:03 -0700342 }
scroggoe7fc14b2015-10-02 13:14:46 -0700343
Leon Scroggins III07418182017-08-15 12:24:02 -0400344 const Result frameIndexResult = this->handleFrameIndex(info, pixels, rowBytes,
345 *options);
346 if (frameIndexResult != kSuccess) {
347 return frameIndexResult;
348 }
349
scroggoe7fc14b2015-10-02 13:14:46 -0700350 // FIXME: Support subsets somehow? Note that this works for SkWebpCodec
351 // because it supports arbitrary scaling/subset combinations.
352 if (!this->dimensionsSupported(info.dimensions())) {
353 return kInvalidScale;
354 }
355
scroggo8e6c7ad2016-09-16 08:20:38 -0700356 fDstInfo = info;
Leon Scroggins III42886572017-01-27 13:16:28 -0500357 fOptions = *options;
scroggo8e6c7ad2016-09-16 08:20:38 -0700358
msarette6dd0042015-10-09 11:07:34 -0700359 // On an incomplete decode, the subclass will specify the number of scanlines that it decoded
360 // successfully.
361 int rowsDecoded = 0;
Leon Scroggins571b30f2017-07-11 17:35:31 +0000362 const Result result = this->onGetPixels(info, pixels, rowBytes, *options, &rowsDecoded);
msarette6dd0042015-10-09 11:07:34 -0700363
364 // A return value of kIncompleteInput indicates a truncated image stream.
365 // In this case, we will fill any uninitialized memory with a default value.
366 // Some subclasses will take care of filling any uninitialized memory on
367 // their own. They indicate that all of the memory has been filled by
368 // setting rowsDecoded equal to the height.
Leon Scroggins III674a1842017-07-06 12:26:09 -0400369 if ((kIncompleteInput == result || kErrorInInput == result) && rowsDecoded != info.height()) {
Leon Scroggins III42886572017-01-27 13:16:28 -0500370 // FIXME: (skbug.com/5772) fillIncompleteImage will fill using the swizzler's width, unless
371 // there is a subset. In that case, it will use the width of the subset. From here, the
372 // subset will only be non-null in the case of SkWebpCodec, but it treats the subset
373 // differenty from the other codecs, and it needs to use the width specified by the info.
374 // Set the subset to null so SkWebpCodec uses the correct width.
375 fOptions.fSubset = nullptr;
msarette6dd0042015-10-09 11:07:34 -0700376 this->fillIncompleteImage(info, pixels, rowBytes, options->fZeroInitialized, info.height(),
377 rowsDecoded);
378 }
379
scroggoeb602a52015-07-09 08:16:03 -0700380 return result;
381}
382
Leon Scroggins IIIfc38ba72018-10-03 16:19:10 -0400383SkCodec::Result SkCodec::startIncrementalDecode(const SkImageInfo& dstInfo, void* pixels,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000384 size_t rowBytes, const SkCodec::Options* options) {
scroggo8e6c7ad2016-09-16 08:20:38 -0700385 fStartedIncrementalDecode = false;
386
Leon Scroggins IIIfc38ba72018-10-03 16:19:10 -0400387 SkImageInfo info = dstInfo;
388 if (!info.colorSpace()) {
389 info = info.makeColorSpace(SkColorSpace::MakeSRGB());
390 }
scroggo8e6c7ad2016-09-16 08:20:38 -0700391 if (kUnknown_SkColorType == info.colorType()) {
392 return kInvalidConversion;
393 }
394 if (nullptr == pixels) {
395 return kInvalidParameters;
396 }
397
scroggo8e6c7ad2016-09-16 08:20:38 -0700398 // FIXME: If the rows come after the rows of a previous incremental decode,
399 // we might be able to skip the rewind, but only the implementation knows
400 // that. (e.g. PNG will always need to rewind, since we called longjmp, but
401 // a bottom-up BMP could skip rewinding if the new rows are above the old
402 // rows.)
403 if (!this->rewindIfNeeded()) {
404 return kCouldNotRewind;
405 }
406
407 // Set options.
408 Options optsStorage;
409 if (nullptr == options) {
410 options = &optsStorage;
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400411 } else {
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400412 if (options->fSubset) {
413 SkIRect size = SkIRect::MakeSize(info.dimensions());
414 if (!size.contains(*options->fSubset)) {
415 return kInvalidParameters;
416 }
scroggo8e6c7ad2016-09-16 08:20:38 -0700417
Leon Scroggins III1f6af6b2017-06-12 16:41:09 -0400418 const int top = options->fSubset->top();
419 const int bottom = options->fSubset->bottom();
420 if (top < 0 || top >= info.height() || top >= bottom || bottom > info.height()) {
421 return kInvalidParameters;
422 }
scroggo8e6c7ad2016-09-16 08:20:38 -0700423 }
424 }
425
Leon Scroggins III07418182017-08-15 12:24:02 -0400426 const Result frameIndexResult = this->handleFrameIndex(info, pixels, rowBytes,
427 *options);
428 if (frameIndexResult != kSuccess) {
429 return frameIndexResult;
430 }
431
scroggo8e6c7ad2016-09-16 08:20:38 -0700432 if (!this->dimensionsSupported(info.dimensions())) {
433 return kInvalidScale;
434 }
435
436 fDstInfo = info;
437 fOptions = *options;
438
Leon Scroggins571b30f2017-07-11 17:35:31 +0000439 const Result result = this->onStartIncrementalDecode(info, pixels, rowBytes, fOptions);
scroggo8e6c7ad2016-09-16 08:20:38 -0700440 if (kSuccess == result) {
441 fStartedIncrementalDecode = true;
442 } else if (kUnimplemented == result) {
443 // FIXME: This is temporarily necessary, until we transition SkCodec
444 // implementations from scanline decoding to incremental decoding.
445 // SkAndroidCodec will first attempt to use incremental decoding, but
446 // will fall back to scanline decoding if incremental returns
447 // kUnimplemented. rewindIfNeeded(), above, set fNeedsRewind to true
448 // (after potentially rewinding), but we do not want the next call to
449 // startScanlineDecode() to do a rewind.
450 fNeedsRewind = false;
451 }
452 return result;
453}
454
455
Leon Scroggins IIIfc38ba72018-10-03 16:19:10 -0400456SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000457 const SkCodec::Options* options) {
scroggo46c57472015-09-30 08:57:13 -0700458 // Reset fCurrScanline in case of failure.
459 fCurrScanline = -1;
scroggo46c57472015-09-30 08:57:13 -0700460
Leon Scroggins IIIfc38ba72018-10-03 16:19:10 -0400461 SkImageInfo info = dstInfo;
462 if (!info.colorSpace()) {
463 info = info.makeColorSpace(SkColorSpace::MakeSRGB());
464 }
465
scroggo3a7701c2015-09-30 09:15:14 -0700466 if (!this->rewindIfNeeded()) {
467 return kCouldNotRewind;
468 }
469
scroggo46c57472015-09-30 08:57:13 -0700470 // Set options.
471 Options optsStorage;
472 if (nullptr == options) {
473 options = &optsStorage;
scroggoe7fc14b2015-10-02 13:14:46 -0700474 } else if (options->fSubset) {
scroggo8e6c7ad2016-09-16 08:20:38 -0700475 SkIRect size = SkIRect::MakeSize(info.dimensions());
msarettfdb47572015-10-13 12:50:14 -0700476 if (!size.contains(*options->fSubset)) {
477 return kInvalidInput;
478 }
479
480 // We only support subsetting in the x-dimension for scanline decoder.
481 // Subsetting in the y-dimension can be accomplished using skipScanlines().
scroggo8e6c7ad2016-09-16 08:20:38 -0700482 if (options->fSubset->top() != 0 || options->fSubset->height() != info.height()) {
msarettfdb47572015-10-13 12:50:14 -0700483 return kInvalidInput;
scroggoe7fc14b2015-10-02 13:14:46 -0700484 }
485 }
486
Leon Scroggins III07418182017-08-15 12:24:02 -0400487 // Scanline decoding only supports decoding the first frame.
488 if (options->fFrameIndex != 0) {
489 return kUnimplemented;
490 }
491
492 // The void* dst and rowbytes in handleFrameIndex or only used for decoding prior
493 // frames, which is not supported here anyway, so it is safe to pass nullptr/0.
494 const Result frameIndexResult = this->handleFrameIndex(info, nullptr, 0, *options);
495 if (frameIndexResult != kSuccess) {
496 return frameIndexResult;
497 }
498
scroggoe7fc14b2015-10-02 13:14:46 -0700499 // FIXME: Support subsets somehow?
scroggo8e6c7ad2016-09-16 08:20:38 -0700500 if (!this->dimensionsSupported(info.dimensions())) {
scroggoe7fc14b2015-10-02 13:14:46 -0700501 return kInvalidScale;
scroggo46c57472015-09-30 08:57:13 -0700502 }
503
Leon Scroggins571b30f2017-07-11 17:35:31 +0000504 const Result result = this->onStartScanlineDecode(info, *options);
scroggo46c57472015-09-30 08:57:13 -0700505 if (result != SkCodec::kSuccess) {
506 return result;
507 }
508
509 fCurrScanline = 0;
scroggo8e6c7ad2016-09-16 08:20:38 -0700510 fDstInfo = info;
scroggo46c57472015-09-30 08:57:13 -0700511 fOptions = *options;
512 return kSuccess;
513}
514
msarette6dd0042015-10-09 11:07:34 -0700515int SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes) {
scroggo46c57472015-09-30 08:57:13 -0700516 if (fCurrScanline < 0) {
msarette6dd0042015-10-09 11:07:34 -0700517 return 0;
scroggo46c57472015-09-30 08:57:13 -0700518 }
519
520 SkASSERT(!fDstInfo.isEmpty());
scroggoe7fc14b2015-10-02 13:14:46 -0700521 if (countLines <= 0 || fCurrScanline + countLines > fDstInfo.height()) {
msarette6dd0042015-10-09 11:07:34 -0700522 return 0;
scroggo46c57472015-09-30 08:57:13 -0700523 }
524
msarette6dd0042015-10-09 11:07:34 -0700525 const int linesDecoded = this->onGetScanlines(dst, countLines, rowBytes);
526 if (linesDecoded < countLines) {
527 this->fillIncompleteImage(this->dstInfo(), dst, rowBytes, this->options().fZeroInitialized,
528 countLines, linesDecoded);
529 }
530 fCurrScanline += countLines;
531 return linesDecoded;
532}
533
534bool SkCodec::skipScanlines(int countLines) {
535 if (fCurrScanline < 0) {
536 return false;
537 }
538
539 SkASSERT(!fDstInfo.isEmpty());
540 if (countLines < 0 || fCurrScanline + countLines > fDstInfo.height()) {
541 // Arguably, we could just skip the scanlines which are remaining,
542 // and return true. We choose to return false so the client
543 // can catch their bug.
544 return false;
545 }
546
547 bool result = this->onSkipScanlines(countLines);
scroggo46c57472015-09-30 08:57:13 -0700548 fCurrScanline += countLines;
549 return result;
550}
551
msarette6dd0042015-10-09 11:07:34 -0700552int SkCodec::outputScanline(int inputScanline) const {
Leon Scroggins III712476e2018-10-03 15:47:00 -0400553 SkASSERT(0 <= inputScanline && inputScanline < fEncodedInfo.height());
msarette6dd0042015-10-09 11:07:34 -0700554 return this->onOutputScanline(inputScanline);
555}
scroggo46c57472015-09-30 08:57:13 -0700556
msarette6dd0042015-10-09 11:07:34 -0700557int SkCodec::onOutputScanline(int inputScanline) const {
558 switch (this->getScanlineOrder()) {
559 case kTopDown_SkScanlineOrder:
msarette6dd0042015-10-09 11:07:34 -0700560 return inputScanline;
561 case kBottomUp_SkScanlineOrder:
Leon Scroggins III712476e2018-10-03 15:47:00 -0400562 return fEncodedInfo.height() - inputScanline - 1;
msarette6dd0042015-10-09 11:07:34 -0700563 default:
564 // This case indicates an interlaced gif and is implemented by SkGifCodec.
565 SkASSERT(false);
566 return 0;
scroggo46c57472015-09-30 08:57:13 -0700567 }
msarette6dd0042015-10-09 11:07:34 -0700568}
scroggo46c57472015-09-30 08:57:13 -0700569
msarette6dd0042015-10-09 11:07:34 -0700570void SkCodec::fillIncompleteImage(const SkImageInfo& info, void* dst, size_t rowBytes,
571 ZeroInitialized zeroInit, int linesRequested, int linesDecoded) {
Leon Scroggins IIIa6161b12018-10-18 14:45:26 -0400572 if (kYes_ZeroInitialized == zeroInit) {
573 return;
574 }
msarette6dd0042015-10-09 11:07:34 -0700575
msarette6dd0042015-10-09 11:07:34 -0700576 const int linesRemaining = linesRequested - linesDecoded;
577 SkSampler* sampler = this->getSampler(false);
578
Leon Scroggins IIIa6161b12018-10-18 14:45:26 -0400579 const int fillWidth = sampler ? sampler->fillWidth() :
580 fOptions.fSubset ? fOptions.fSubset->width() :
581 info.width() ;
582 void* fillDst = this->getScanlineOrder() == kBottomUp_SkScanlineOrder ? dst :
583 SkTAddOffset<void>(dst, linesDecoded * rowBytes);
584 const auto fillInfo = info.makeWH(fillWidth, linesRemaining);
585 SkSampler::Fill(fillInfo, fillDst, rowBytes, kNo_ZeroInitialized);
scroggo46c57472015-09-30 08:57:13 -0700586}
Matt Sarett313c4632016-10-20 12:35:23 -0400587
Leon Scroggins III179559f2018-12-10 12:30:12 -0500588bool sk_select_xform_format(SkColorType colorType, bool forColorTable,
589 skcms_PixelFormat* outFormat) {
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400590 SkASSERT(outFormat);
591
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400592 switch (colorType) {
593 case kRGBA_8888_SkColorType:
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400594 *outFormat = skcms_PixelFormat_RGBA_8888;
595 break;
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400596 case kBGRA_8888_SkColorType:
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400597 *outFormat = skcms_PixelFormat_BGRA_8888;
598 break;
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400599 case kRGB_565_SkColorType:
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400600 if (forColorTable) {
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400601#ifdef SK_PMCOLOR_IS_RGBA
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400602 *outFormat = skcms_PixelFormat_RGBA_8888;
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400603#else
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400604 *outFormat = skcms_PixelFormat_BGRA_8888;
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400605#endif
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400606 break;
607 }
608 *outFormat = skcms_PixelFormat_BGR_565;
609 break;
610 case kRGBA_F16_SkColorType:
611 *outFormat = skcms_PixelFormat_RGBA_hhhh;
612 break;
Brian Osmanb3f38302018-09-07 15:24:44 -0400613 case kGray_8_SkColorType:
614 *outFormat = skcms_PixelFormat_G_8;
615 break;
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400616 default:
Leon Scroggins83988ed2018-08-24 21:41:24 +0000617 return false;
Leon Scroggins83988ed2018-08-24 21:41:24 +0000618 }
Matt Sarett313c4632016-10-20 12:35:23 -0400619 return true;
620}
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400621
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400622bool SkCodec::initializeColorXform(const SkImageInfo& dstInfo, SkEncodedInfo::Alpha encodedAlpha,
623 bool srcIsOpaque) {
624 fXformTime = kNo_XformTime;
625 bool needsColorXform = false;
626 if (this->usesColorXform() && dstInfo.colorSpace()) {
627 dstInfo.colorSpace()->toProfile(&fDstProfile);
Leon Scroggins III5dd47e42018-09-27 15:26:48 -0400628 if (kRGBA_F16_SkColorType == dstInfo.colorType()) {
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400629 needsColorXform = true;
Leon Scroggins III5dd47e42018-09-27 15:26:48 -0400630 } else {
631 const auto* srcProfile = fEncodedInfo.profile();
632 if (!srcProfile) {
633 srcProfile = skcms_sRGB_profile();
634 }
635 if (!skcms_ApproximatelyEqualProfiles(srcProfile, &fDstProfile) ) {
636 needsColorXform = true;
637 }
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400638 }
639 }
640
Leon Scroggins III712476e2018-10-03 15:47:00 -0400641 if (!this->conversionSupported(dstInfo, srcIsOpaque, needsColorXform)) {
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400642 return false;
643 }
644
645 if (needsColorXform) {
646 fXformTime = SkEncodedInfo::kPalette_Color != fEncodedInfo.color()
647 || kRGBA_F16_SkColorType == dstInfo.colorType()
648 ? kDecodeRow_XformTime : kPalette_XformTime;
Leon Scroggins III179559f2018-12-10 12:30:12 -0500649 if (!sk_select_xform_format(dstInfo.colorType(), fXformTime == kPalette_XformTime,
650 &fDstXformFormat)) {
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400651 return false;
652 }
653 if (encodedAlpha == SkEncodedInfo::kUnpremul_Alpha
654 && dstInfo.alphaType() == kPremul_SkAlphaType) {
655 fDstXformAlphaFormat = skcms_AlphaFormat_PremulAsEncoded;
656 } else {
657 fDstXformAlphaFormat = skcms_AlphaFormat_Unpremul;
658 }
659 }
660 return true;
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400661}
662
663void SkCodec::applyColorXform(void* dst, const void* src, int count) const {
Leon Scroggins III5dd47e42018-09-27 15:26:48 -0400664 // It is okay for srcProfile to be null. This will use sRGB.
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400665 const auto* srcProfile = fEncodedInfo.profile();
Leon Scroggins III36f7e322018-08-27 11:55:46 -0400666 SkAssertResult(skcms_Transform(src, fSrcXformFormat, skcms_AlphaFormat_Unpremul, srcProfile,
667 dst, fDstXformFormat, fDstXformAlphaFormat, &fDstProfile,
668 count));
Leon Scroggins IIIc6e6a5f2017-06-05 15:53:38 -0400669}
670
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400671std::vector<SkCodec::FrameInfo> SkCodec::getFrameInfo() {
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400672 const int frameCount = this->getFrameCount();
673 SkASSERT(frameCount >= 0);
674 if (frameCount <= 0) {
675 return std::vector<FrameInfo>{};
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400676 }
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400677
678 if (frameCount == 1 && !this->onGetFrameInfo(0, nullptr)) {
679 // Not animated.
680 return std::vector<FrameInfo>{};
681 }
682
683 std::vector<FrameInfo> result(frameCount);
684 for (int i = 0; i < frameCount; ++i) {
685 SkAssertResult(this->onGetFrameInfo(i, &result[i]));
686 }
687 return result;
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400688}
Leon Scroggins IIIfe3da022018-01-16 11:56:54 -0500689
690const char* SkCodec::ResultToString(Result result) {
691 switch (result) {
692 case kSuccess:
693 return "success";
694 case kIncompleteInput:
695 return "incomplete input";
696 case kErrorInInput:
697 return "error in input";
698 case kInvalidConversion:
699 return "invalid conversion";
700 case kInvalidScale:
701 return "invalid scale";
702 case kInvalidParameters:
703 return "invalid parameters";
704 case kInvalidInput:
705 return "invalid input";
706 case kCouldNotRewind:
707 return "could not rewind";
708 case kInternalError:
709 return "internal error";
710 case kUnimplemented:
711 return "unimplemented";
712 default:
713 SkASSERT(false);
714 return "bogus result value";
715 }
716}
Nigel Taoa78b6dc2018-07-28 16:48:09 +1000717
718static SkIRect frame_rect_on_screen(SkIRect frameRect,
719 const SkIRect& screenRect) {
720 if (!frameRect.intersect(screenRect)) {
721 return SkIRect::MakeEmpty();
722 }
723
724 return frameRect;
725}
726
727static bool independent(const SkFrame& frame) {
Nigel Tao66bc5242018-08-22 10:56:03 +1000728 return frame.getRequiredFrame() == SkCodec::kNoFrame;
Nigel Taoa78b6dc2018-07-28 16:48:09 +1000729}
730
731static bool restore_bg(const SkFrame& frame) {
732 return frame.getDisposalMethod() == SkCodecAnimation::DisposalMethod::kRestoreBGColor;
733}
734
735void SkFrameHolder::setAlphaAndRequiredFrame(SkFrame* frame) {
736 const bool reportsAlpha = frame->reportedAlpha() != SkEncodedInfo::kOpaque_Alpha;
737 const auto screenRect = SkIRect::MakeWH(fScreenWidth, fScreenHeight);
738 const auto frameRect = frame_rect_on_screen(frame->frameRect(), screenRect);
739
740 const int i = frame->frameId();
741 if (0 == i) {
742 frame->setHasAlpha(reportsAlpha || frameRect != screenRect);
Nigel Tao66bc5242018-08-22 10:56:03 +1000743 frame->setRequiredFrame(SkCodec::kNoFrame);
Nigel Taoa78b6dc2018-07-28 16:48:09 +1000744 return;
745 }
746
747
748 const bool blendWithPrevFrame = frame->getBlend() == SkCodecAnimation::Blend::kPriorFrame;
749 if ((!reportsAlpha || !blendWithPrevFrame) && frameRect == screenRect) {
750 frame->setHasAlpha(reportsAlpha);
Nigel Tao66bc5242018-08-22 10:56:03 +1000751 frame->setRequiredFrame(SkCodec::kNoFrame);
Nigel Taoa78b6dc2018-07-28 16:48:09 +1000752 return;
753 }
754
755 const SkFrame* prevFrame = this->getFrame(i-1);
756 while (prevFrame->getDisposalMethod() == SkCodecAnimation::DisposalMethod::kRestorePrevious) {
757 const int prevId = prevFrame->frameId();
758 if (0 == prevId) {
759 frame->setHasAlpha(true);
Nigel Tao66bc5242018-08-22 10:56:03 +1000760 frame->setRequiredFrame(SkCodec::kNoFrame);
Nigel Taoa78b6dc2018-07-28 16:48:09 +1000761 return;
762 }
763
764 prevFrame = this->getFrame(prevId - 1);
765 }
766
767 const bool clearPrevFrame = restore_bg(*prevFrame);
768 auto prevFrameRect = frame_rect_on_screen(prevFrame->frameRect(), screenRect);
769
770 if (clearPrevFrame) {
771 if (prevFrameRect == screenRect || independent(*prevFrame)) {
772 frame->setHasAlpha(true);
Nigel Tao66bc5242018-08-22 10:56:03 +1000773 frame->setRequiredFrame(SkCodec::kNoFrame);
Nigel Taoa78b6dc2018-07-28 16:48:09 +1000774 return;
775 }
776 }
777
778 if (reportsAlpha && blendWithPrevFrame) {
779 // Note: We could be more aggressive here. If prevFrame clears
780 // to background color and covers its required frame (and that
781 // frame is independent), prevFrame could be marked independent.
782 // Would this extra complexity be worth it?
783 frame->setRequiredFrame(prevFrame->frameId());
784 frame->setHasAlpha(prevFrame->hasAlpha() || clearPrevFrame);
785 return;
786 }
787
788 while (frameRect.contains(prevFrameRect)) {
789 const int prevRequiredFrame = prevFrame->getRequiredFrame();
Nigel Tao66bc5242018-08-22 10:56:03 +1000790 if (prevRequiredFrame == SkCodec::kNoFrame) {
791 frame->setRequiredFrame(SkCodec::kNoFrame);
Nigel Taoa78b6dc2018-07-28 16:48:09 +1000792 frame->setHasAlpha(true);
793 return;
794 }
795
796 prevFrame = this->getFrame(prevRequiredFrame);
797 prevFrameRect = frame_rect_on_screen(prevFrame->frameRect(), screenRect);
798 }
799
800 if (restore_bg(*prevFrame)) {
801 frame->setHasAlpha(true);
802 if (prevFrameRect == screenRect || independent(*prevFrame)) {
Nigel Tao66bc5242018-08-22 10:56:03 +1000803 frame->setRequiredFrame(SkCodec::kNoFrame);
Nigel Taoa78b6dc2018-07-28 16:48:09 +1000804 } else {
805 // Note: As above, frame could still be independent, e.g. if
806 // prevFrame covers its required frame and that frame is
807 // independent.
808 frame->setRequiredFrame(prevFrame->frameId());
809 }
810 return;
811 }
812
813 SkASSERT(prevFrame->getDisposalMethod() == SkCodecAnimation::DisposalMethod::kKeep);
814 frame->setRequiredFrame(prevFrame->frameId());
815 frame->setHasAlpha(prevFrame->hasAlpha() || (reportsAlpha && !blendWithPrevFrame));
816}
817