scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 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 | |
Leon Scroggins | fc4fdc5 | 2020-11-09 14:18:12 -0500 | [diff] [blame^] | 8 | #include "include/codec/SkAndroidCodec.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/codec/SkCodec.h" |
| 10 | #include "include/core/SkColorSpace.h" |
| 11 | #include "include/core/SkData.h" |
| 12 | #include "include/private/SkHalf.h" |
| 13 | #include "src/codec/SkBmpCodec.h" |
| 14 | #include "src/codec/SkCodecPriv.h" |
| 15 | #include "src/codec/SkFrameHolder.h" |
Leon Scroggins III | 04be2b5 | 2017-08-17 15:13:20 -0400 | [diff] [blame] | 16 | #ifdef SK_HAS_HEIF_LIBRARY |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/codec/SkHeifCodec.h" |
Leon Scroggins III | 04be2b5 | 2017-08-17 15:13:20 -0400 | [diff] [blame] | 18 | #endif |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/codec/SkIcoCodec.h" |
| 20 | #include "src/codec/SkJpegCodec.h" |
Leon Scroggins III | a77f30c | 2020-03-09 14:23:30 -0400 | [diff] [blame] | 21 | #ifdef SK_CODEC_DECODES_PNG |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "src/codec/SkPngCodec.h" |
yujieqin | 916de9f | 2016-01-25 08:26:16 -0800 | [diff] [blame] | 23 | #endif |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "include/core/SkStream.h" |
| 25 | #include "src/codec/SkRawCodec.h" |
| 26 | #include "src/codec/SkWbmpCodec.h" |
| 27 | #include "src/codec/SkWebpCodec.h" |
Leon Scroggins III | e93ec68 | 2018-10-26 09:25:51 -0400 | [diff] [blame] | 28 | #ifdef SK_HAS_WUFFS_LIBRARY |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 29 | #include "src/codec/SkWuffsCodec.h" |
Hal Canary | 2dad990 | 2019-11-20 16:01:31 -0500 | [diff] [blame] | 30 | #elif defined(SK_USE_LIBGIFCODEC) |
Hal Canary | 1ec9a28 | 2019-11-21 10:15:50 -0500 | [diff] [blame] | 31 | #include "SkGifCodec.h" |
Leon Scroggins III | e93ec68 | 2018-10-26 09:25:51 -0400 | [diff] [blame] | 32 | #endif |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 33 | |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 34 | struct DecoderProc { |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 35 | bool (*IsFormat)(const void*, size_t); |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 36 | std::unique_ptr<SkCodec> (*MakeFromStream)(std::unique_ptr<SkStream>, SkCodec::Result*); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
Mike Klein | 159a959 | 2019-04-26 15:47:56 +0000 | [diff] [blame] | 39 | static std::vector<DecoderProc>* decoders() { |
| 40 | static auto* decoders = new std::vector<DecoderProc> { |
Leon Scroggins III | a77f30c | 2020-03-09 14:23:30 -0400 | [diff] [blame] | 41 | #ifdef SK_CODEC_DECODES_JPEG |
Mike Klein | 159a959 | 2019-04-26 15:47:56 +0000 | [diff] [blame] | 42 | { SkJpegCodec::IsJpeg, SkJpegCodec::MakeFromStream }, |
| 43 | #endif |
Leon Scroggins III | a77f30c | 2020-03-09 14:23:30 -0400 | [diff] [blame] | 44 | #ifdef SK_CODEC_DECODES_WEBP |
Mike Klein | 159a959 | 2019-04-26 15:47:56 +0000 | [diff] [blame] | 45 | { SkWebpCodec::IsWebp, SkWebpCodec::MakeFromStream }, |
| 46 | #endif |
| 47 | #ifdef SK_HAS_WUFFS_LIBRARY |
| 48 | { SkWuffsCodec_IsFormat, SkWuffsCodec_MakeFromStream }, |
Hal Canary | 2dad990 | 2019-11-20 16:01:31 -0500 | [diff] [blame] | 49 | #elif defined(SK_USE_LIBGIFCODEC) |
Mike Klein | 159a959 | 2019-04-26 15:47:56 +0000 | [diff] [blame] | 50 | { SkGifCodec::IsGif, SkGifCodec::MakeFromStream }, |
| 51 | #endif |
Leon Scroggins III | a77f30c | 2020-03-09 14:23:30 -0400 | [diff] [blame] | 52 | #ifdef SK_CODEC_DECODES_PNG |
Mike Klein | 159a959 | 2019-04-26 15:47:56 +0000 | [diff] [blame] | 53 | { SkIcoCodec::IsIco, SkIcoCodec::MakeFromStream }, |
| 54 | #endif |
| 55 | { SkBmpCodec::IsBmp, SkBmpCodec::MakeFromStream }, |
| 56 | { SkWbmpCodec::IsWbmp, SkWbmpCodec::MakeFromStream }, |
Mike Klein | 159a959 | 2019-04-26 15:47:56 +0000 | [diff] [blame] | 57 | }; |
| 58 | return decoders; |
| 59 | } |
| 60 | |
| 61 | void SkCodec::Register( |
| 62 | bool (*peek)(const void*, size_t), |
| 63 | std::unique_ptr<SkCodec> (*make)(std::unique_ptr<SkStream>, SkCodec::Result*)) { |
| 64 | decoders()->push_back(DecoderProc{peek, make}); |
| 65 | } |
| 66 | |
Leon Scroggins III | 6154ac4 | 2019-08-14 11:29:29 -0400 | [diff] [blame] | 67 | std::unique_ptr<SkCodec> SkCodec::MakeFromStream( |
| 68 | std::unique_ptr<SkStream> stream, Result* outResult, |
| 69 | SkPngChunkReader* chunkReader, SelectionPolicy selectionPolicy) { |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 70 | Result resultStorage; |
| 71 | if (!outResult) { |
| 72 | outResult = &resultStorage; |
| 73 | } |
| 74 | |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 75 | if (!stream) { |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 76 | *outResult = kInvalidInput; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 77 | return nullptr; |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 78 | } |
scroggo | 0a7e69c | 2015-04-03 07:22:22 -0700 | [diff] [blame] | 79 | |
Leon Scroggins III | 6154ac4 | 2019-08-14 11:29:29 -0400 | [diff] [blame] | 80 | if (selectionPolicy != SelectionPolicy::kPreferStillImage |
| 81 | && selectionPolicy != SelectionPolicy::kPreferAnimation) { |
| 82 | *outResult = kInvalidParameters; |
| 83 | return nullptr; |
| 84 | } |
| 85 | |
Leon Scroggins III | 04be2b5 | 2017-08-17 15:13:20 -0400 | [diff] [blame] | 86 | constexpr size_t bytesToRead = MinBufferedBytesNeeded(); |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 87 | |
| 88 | char buffer[bytesToRead]; |
| 89 | size_t bytesRead = stream->peek(buffer, bytesToRead); |
| 90 | |
| 91 | // It is also possible to have a complete image less than bytesToRead bytes |
| 92 | // (e.g. a 1 x 1 wbmp), meaning peek() would return less than bytesToRead. |
| 93 | // Assume that if bytesRead < bytesToRead, but > 0, the stream is shorter |
| 94 | // than bytesToRead, so pass that directly to the decoder. |
| 95 | // It also is possible the stream uses too small a buffer for peeking, but |
| 96 | // we trust the caller to use a large enough buffer. |
| 97 | |
| 98 | if (0 == bytesRead) { |
scroggo | 3ab9f2e | 2016-01-06 09:53:34 -0800 | [diff] [blame] | 99 | // TODO: After implementing peek in CreateJavaOutputStreamAdaptor.cpp, this |
| 100 | // printf could be useful to notice failures. |
| 101 | // SkCodecPrintf("Encoded image data failed to peek!\n"); |
| 102 | |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 103 | // It is possible the stream does not support peeking, but does support |
| 104 | // rewinding. |
| 105 | // Attempt to read() and pass the actual amount read to the decoder. |
| 106 | bytesRead = stream->read(buffer, bytesToRead); |
| 107 | if (!stream->rewind()) { |
scroggo | 3ab9f2e | 2016-01-06 09:53:34 -0800 | [diff] [blame] | 108 | SkCodecPrintf("Encoded image data could not peek or rewind to determine format!\n"); |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 109 | *outResult = kCouldNotRewind; |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 110 | return nullptr; |
| 111 | } |
| 112 | } |
| 113 | |
scroggo | cf98fa9 | 2015-11-23 08:14:40 -0800 | [diff] [blame] | 114 | // PNG is special, since we want to be able to supply an SkPngChunkReader. |
| 115 | // But this code follows the same pattern as the loop. |
Leon Scroggins III | a77f30c | 2020-03-09 14:23:30 -0400 | [diff] [blame] | 116 | #ifdef SK_CODEC_DECODES_PNG |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 117 | if (SkPngCodec::IsPng(buffer, bytesRead)) { |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 118 | return SkPngCodec::MakeFromStream(std::move(stream), outResult, chunkReader); |
msarett | 39b2d5a | 2016-02-17 08:26:31 -0800 | [diff] [blame] | 119 | } else |
| 120 | #endif |
| 121 | { |
Mike Klein | 159a959 | 2019-04-26 15:47:56 +0000 | [diff] [blame] | 122 | for (DecoderProc proc : *decoders()) { |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 123 | if (proc.IsFormat(buffer, bytesRead)) { |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 124 | return proc.MakeFromStream(std::move(stream), outResult); |
scroggo | cf98fa9 | 2015-11-23 08:14:40 -0800 | [diff] [blame] | 125 | } |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 126 | } |
yujieqin | 916de9f | 2016-01-25 08:26:16 -0800 | [diff] [blame] | 127 | |
Leon Scroggins III | 6154ac4 | 2019-08-14 11:29:29 -0400 | [diff] [blame] | 128 | #ifdef SK_HAS_HEIF_LIBRARY |
Vignesh Venkatasubramanian | eb7f960 | 2020-11-04 14:13:39 -0800 | [diff] [blame] | 129 | SkEncodedImageFormat format; |
| 130 | if (SkHeifCodec::IsSupported(buffer, bytesRead, &format)) { |
| 131 | return SkHeifCodec::MakeFromStream(std::move(stream), selectionPolicy, |
| 132 | format, outResult); |
Leon Scroggins III | 6154ac4 | 2019-08-14 11:29:29 -0400 | [diff] [blame] | 133 | } |
| 134 | #endif |
| 135 | |
yujieqin | 916de9f | 2016-01-25 08:26:16 -0800 | [diff] [blame] | 136 | #ifdef SK_CODEC_DECODES_RAW |
| 137 | // Try to treat the input as RAW if all the other checks failed. |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 138 | return SkRawCodec::MakeFromStream(std::move(stream), outResult); |
yujieqin | 916de9f | 2016-01-25 08:26:16 -0800 | [diff] [blame] | 139 | #endif |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 140 | } |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 141 | |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 142 | if (bytesRead < bytesToRead) { |
| 143 | *outResult = kIncompleteInput; |
| 144 | } else { |
| 145 | *outResult = kUnimplemented; |
| 146 | } |
| 147 | |
msarett | f44631b | 2016-01-13 10:54:20 -0800 | [diff] [blame] | 148 | return nullptr; |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 151 | std::unique_ptr<SkCodec> SkCodec::MakeFromData(sk_sp<SkData> data, SkPngChunkReader* reader) { |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 152 | if (!data) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 153 | return nullptr; |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 154 | } |
Mike Reed | 847068c | 2017-07-26 11:35:53 -0400 | [diff] [blame] | 155 | return MakeFromStream(SkMemoryStream::Make(std::move(data)), nullptr, reader); |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 158 | SkCodec::SkCodec(SkEncodedInfo&& info, XformFormat srcFormat, std::unique_ptr<SkStream> stream, |
| 159 | SkEncodedOrigin origin) |
| 160 | : fEncodedInfo(std::move(info)) |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 161 | , fSrcXformFormat(srcFormat) |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 162 | , fStream(std::move(stream)) |
msarett | 549ca32 | 2016-08-17 08:54:08 -0700 | [diff] [blame] | 163 | , fNeedsRewind(false) |
| 164 | , fOrigin(origin) |
| 165 | , fDstInfo() |
| 166 | , fOptions() |
| 167 | , fCurrScanline(-1) |
Ivan Afanasyev | 2631558 | 2017-10-09 10:09:53 +0700 | [diff] [blame] | 168 | , fStartedIncrementalDecode(false) |
Leon Scroggins | fc4fdc5 | 2020-11-09 14:18:12 -0500 | [diff] [blame^] | 169 | , fAndroidCodecHandlesFrameIndex(false) |
msarett | 549ca32 | 2016-08-17 08:54:08 -0700 | [diff] [blame] | 170 | {} |
| 171 | |
scroggo | 9b2cdbf4 | 2015-07-10 12:07:02 -0700 | [diff] [blame] | 172 | SkCodec::~SkCodec() {} |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 173 | |
Brian Salomon | 59c60b0 | 2020-09-01 15:01:15 -0400 | [diff] [blame] | 174 | bool SkCodec::queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes, |
| 175 | SkYUVAPixmapInfo* yuvaPixmapInfo) const { |
Brian Salomon | be0e42c | 2020-08-27 11:00:04 -0400 | [diff] [blame] | 176 | if (!yuvaPixmapInfo) { |
Brian Salomon | 87d42e5 | 2020-08-24 09:18:16 -0400 | [diff] [blame] | 177 | return false; |
| 178 | } |
Brian Salomon | 59c60b0 | 2020-09-01 15:01:15 -0400 | [diff] [blame] | 179 | return this->onQueryYUVAInfo(supportedDataTypes, yuvaPixmapInfo) && |
| 180 | yuvaPixmapInfo->isSupported(supportedDataTypes); |
Brian Salomon | 87d42e5 | 2020-08-24 09:18:16 -0400 | [diff] [blame] | 181 | } |
| 182 | |
Brian Salomon | be0e42c | 2020-08-27 11:00:04 -0400 | [diff] [blame] | 183 | SkCodec::Result SkCodec::getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps) { |
| 184 | if (!yuvaPixmaps.isValid()) { |
Brian Salomon | 87d42e5 | 2020-08-24 09:18:16 -0400 | [diff] [blame] | 185 | return kInvalidInput; |
| 186 | } |
| 187 | if (!this->rewindIfNeeded()) { |
| 188 | return kCouldNotRewind; |
| 189 | } |
Brian Salomon | be0e42c | 2020-08-27 11:00:04 -0400 | [diff] [blame] | 190 | return this->onGetYUVAPlanes(yuvaPixmaps); |
Brian Salomon | 87d42e5 | 2020-08-24 09:18:16 -0400 | [diff] [blame] | 191 | } |
| 192 | |
Leon Scroggins III | 712476e | 2018-10-03 15:47:00 -0400 | [diff] [blame] | 193 | bool SkCodec::conversionSupported(const SkImageInfo& dst, bool srcIsOpaque, bool needsColorXform) { |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 194 | if (!valid_alpha(dst.alphaType(), srcIsOpaque)) { |
| 195 | return false; |
| 196 | } |
| 197 | |
| 198 | switch (dst.colorType()) { |
| 199 | case kRGBA_8888_SkColorType: |
| 200 | case kBGRA_8888_SkColorType: |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 201 | case kRGBA_F16_SkColorType: |
Leon Scroggins III | 196f319 | 2020-02-03 12:39:54 -0500 | [diff] [blame] | 202 | return true; |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 203 | case kRGB_565_SkColorType: |
| 204 | return srcIsOpaque; |
| 205 | case kGray_8_SkColorType: |
Leon Scroggins III | 712476e | 2018-10-03 15:47:00 -0400 | [diff] [blame] | 206 | return SkEncodedInfo::kGray_Color == fEncodedInfo.color() && srcIsOpaque; |
Mike Reed | d6cb11e | 2017-11-30 15:33:04 -0500 | [diff] [blame] | 207 | case kAlpha_8_SkColorType: |
| 208 | // conceptually we can convert anything into alpha_8, but we haven't actually coded |
Leon Scroggins III | 712476e | 2018-10-03 15:47:00 -0400 | [diff] [blame] | 209 | // all of those other conversions yet. |
| 210 | return SkEncodedInfo::kXAlpha_Color == fEncodedInfo.color(); |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 211 | default: |
| 212 | return false; |
| 213 | } |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 214 | } |
| 215 | |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 216 | bool SkCodec::rewindIfNeeded() { |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 217 | // Store the value of fNeedsRewind so we can update it. Next read will |
| 218 | // require a rewind. |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 219 | const bool needsRewind = fNeedsRewind; |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 220 | fNeedsRewind = true; |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 221 | if (!needsRewind) { |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 222 | return true; |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 223 | } |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 224 | |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 225 | // startScanlineDecode will need to be called before decoding scanlines. |
| 226 | fCurrScanline = -1; |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 227 | // startIncrementalDecode will need to be called before incrementalDecode. |
| 228 | fStartedIncrementalDecode = false; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 229 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 230 | // Some codecs do not have a stream. They may hold onto their own data or another codec. |
| 231 | // They must handle rewinding themselves. |
| 232 | if (fStream && !fStream->rewind()) { |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 233 | return false; |
| 234 | } |
| 235 | |
| 236 | return this->onRewind(); |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 237 | } |
scroggo | 0524590 | 2015-03-25 11:11:52 -0700 | [diff] [blame] | 238 | |
Leon Scroggins III | 19e3cd4 | 2019-08-07 16:42:04 -0400 | [diff] [blame] | 239 | static SkIRect frame_rect_on_screen(SkIRect frameRect, |
| 240 | const SkIRect& screenRect) { |
| 241 | if (!frameRect.intersect(screenRect)) { |
| 242 | return SkIRect::MakeEmpty(); |
| 243 | } |
| 244 | |
| 245 | return frameRect; |
| 246 | } |
| 247 | |
Leon Scroggins III | 7916c0e | 2018-05-24 13:04:06 -0400 | [diff] [blame] | 248 | bool zero_rect(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes, |
| 249 | SkISize srcDimensions, SkIRect prevRect) { |
| 250 | const auto dimensions = dstInfo.dimensions(); |
| 251 | if (dimensions != srcDimensions) { |
| 252 | SkRect src = SkRect::Make(srcDimensions); |
| 253 | SkRect dst = SkRect::Make(dimensions); |
Leon Scroggins | fc4fdc5 | 2020-11-09 14:18:12 -0500 | [diff] [blame^] | 254 | SkMatrix map = SkMatrix::MakeRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); |
Leon Scroggins III | 7916c0e | 2018-05-24 13:04:06 -0400 | [diff] [blame] | 255 | SkRect asRect = SkRect::Make(prevRect); |
| 256 | if (!map.mapRect(&asRect)) { |
| 257 | return false; |
| 258 | } |
Leon Scroggins | fc4fdc5 | 2020-11-09 14:18:12 -0500 | [diff] [blame^] | 259 | asRect.roundOut(&prevRect); |
| 260 | } |
| 261 | |
| 262 | if (!prevRect.intersect(SkIRect::MakeSize(dimensions))) { |
| 263 | // Nothing to zero, due to scaling or bad frame rect. |
| 264 | return true; |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 265 | } |
Leon Scroggins III | 7916c0e | 2018-05-24 13:04:06 -0400 | [diff] [blame] | 266 | |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 267 | const SkImageInfo info = dstInfo.makeDimensions(prevRect.size()); |
Mike Reed | 7fcfb62 | 2018-02-09 13:26:46 -0500 | [diff] [blame] | 268 | const size_t bpp = dstInfo.bytesPerPixel(); |
Leon Scroggins III | 7916c0e | 2018-05-24 13:04:06 -0400 | [diff] [blame] | 269 | const size_t offset = prevRect.x() * bpp + prevRect.y() * rowBytes; |
| 270 | void* eraseDst = SkTAddOffset<void>(pixels, offset); |
Leon Scroggins III | e643a9e | 2018-08-03 16:15:04 -0400 | [diff] [blame] | 271 | SkSampler::Fill(info, eraseDst, rowBytes, SkCodec::kNo_ZeroInitialized); |
Leon Scroggins III | 7916c0e | 2018-05-24 13:04:06 -0400 | [diff] [blame] | 272 | return true; |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | SkCodec::Result SkCodec::handleFrameIndex(const SkImageInfo& info, void* pixels, size_t rowBytes, |
Leon Scroggins | fc4fdc5 | 2020-11-09 14:18:12 -0500 | [diff] [blame^] | 276 | const Options& options, SkAndroidCodec* androidCodec) { |
| 277 | if (androidCodec) { |
| 278 | // This is never set back to false. If SkAndroidCodec is calling this method, its fCodec |
| 279 | // should never call it directly. |
| 280 | fAndroidCodecHandlesFrameIndex = true; |
| 281 | } else if (fAndroidCodecHandlesFrameIndex) { |
| 282 | return kSuccess; |
| 283 | } |
| 284 | |
| 285 | if (!this->rewindIfNeeded()) { |
| 286 | return kCouldNotRewind; |
| 287 | } |
| 288 | |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 289 | const int index = options.fFrameIndex; |
| 290 | if (0 == index) { |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 291 | return this->initializeColorXform(info, fEncodedInfo.alpha(), fEncodedInfo.opaque()) |
| 292 | ? kSuccess : kInvalidConversion; |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 293 | } |
| 294 | |
Leon Scroggins III | ae79f32 | 2017-08-18 10:53:24 -0400 | [diff] [blame] | 295 | if (index < 0) { |
| 296 | return kInvalidParameters; |
| 297 | } |
| 298 | |
Leon Scroggins III | 42ee284 | 2018-01-14 14:46:51 -0500 | [diff] [blame] | 299 | if (options.fSubset) { |
| 300 | // If we add support for this, we need to update the code that zeroes |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 301 | // a kRestoreBGColor frame. |
| 302 | return kInvalidParameters; |
| 303 | } |
| 304 | |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 305 | if (index >= this->onGetFrameCount()) { |
| 306 | return kIncompleteInput; |
| 307 | } |
| 308 | |
| 309 | const auto* frameHolder = this->getFrameHolder(); |
| 310 | SkASSERT(frameHolder); |
| 311 | |
| 312 | const auto* frame = frameHolder->getFrame(index); |
| 313 | SkASSERT(frame); |
| 314 | |
| 315 | const int requiredFrame = frame->getRequiredFrame(); |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 316 | if (requiredFrame != kNoFrame) { |
Leon Scroggins | fc4fdc5 | 2020-11-09 14:18:12 -0500 | [diff] [blame^] | 317 | const SkFrame* preppedFrame = nullptr; |
| 318 | if (options.fPriorFrame == kNoFrame) { |
| 319 | Result result = kInternalError; |
| 320 | if (androidCodec) { |
| 321 | #ifdef SK_HAS_ANDROID_CODEC |
| 322 | SkAndroidCodec::AndroidOptions prevFrameOptions( |
| 323 | reinterpret_cast<const SkAndroidCodec::AndroidOptions&>(options)); |
| 324 | prevFrameOptions.fFrameIndex = requiredFrame; |
| 325 | result = androidCodec->getAndroidPixels(info, pixels, rowBytes, &prevFrameOptions); |
| 326 | #endif |
| 327 | } else { |
| 328 | Options prevFrameOptions(options); |
| 329 | prevFrameOptions.fFrameIndex = requiredFrame; |
| 330 | result = this->getPixels(info, pixels, rowBytes, &prevFrameOptions); |
| 331 | } |
| 332 | if (result != kSuccess) { |
| 333 | return result; |
| 334 | } |
| 335 | preppedFrame = frameHolder->getFrame(requiredFrame); |
| 336 | } else { |
Leon Scroggins III | ae79f32 | 2017-08-18 10:53:24 -0400 | [diff] [blame] | 337 | // Check for a valid frame as a starting point. Alternatively, we could |
| 338 | // treat an invalid frame as not providing one, but rejecting it will |
| 339 | // make it easier to catch the mistake. |
| 340 | if (options.fPriorFrame < requiredFrame || options.fPriorFrame >= index) { |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 341 | return kInvalidParameters; |
Leon Scroggins III | ae79f32 | 2017-08-18 10:53:24 -0400 | [diff] [blame] | 342 | } |
Leon Scroggins | fc4fdc5 | 2020-11-09 14:18:12 -0500 | [diff] [blame^] | 343 | preppedFrame = frameHolder->getFrame(options.fPriorFrame); |
| 344 | } |
| 345 | |
| 346 | SkASSERT(preppedFrame); |
| 347 | switch (preppedFrame->getDisposalMethod()) { |
| 348 | case SkCodecAnimation::DisposalMethod::kRestorePrevious: |
| 349 | SkASSERT(options.fPriorFrame != kNoFrame); |
| 350 | return kInvalidParameters; |
| 351 | case SkCodecAnimation::DisposalMethod::kRestoreBGColor: |
| 352 | // If a frame after the required frame is provided, there is no |
| 353 | // need to clear, since it must be covered by the desired frame. |
| 354 | // FIXME: If the required frame is kRestoreBGColor, we don't actually need to decode |
| 355 | // it, since we'll just clear it to transparent. Instead, we could decode *its* |
| 356 | // required frame and then clear. |
| 357 | if (preppedFrame->frameId() == requiredFrame) { |
| 358 | SkIRect preppedRect = preppedFrame->frameRect(); |
| 359 | if (!zero_rect(info, pixels, rowBytes, this->dimensions(), preppedRect)) { |
| 360 | return kInternalError; |
Leon Scroggins III | ae79f32 | 2017-08-18 10:53:24 -0400 | [diff] [blame] | 361 | } |
Leon Scroggins III | 7916c0e | 2018-05-24 13:04:06 -0400 | [diff] [blame] | 362 | } |
Leon Scroggins | fc4fdc5 | 2020-11-09 14:18:12 -0500 | [diff] [blame^] | 363 | break; |
| 364 | default: |
| 365 | break; |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 369 | return this->initializeColorXform(info, frame->reportedAlpha(), !frame->hasAlpha()) |
| 370 | ? kSuccess : kInvalidConversion; |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 371 | } |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 372 | |
Leon Scroggins III | 196f319 | 2020-02-03 12:39:54 -0500 | [diff] [blame] | 373 | SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 374 | const Options* options) { |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 375 | if (kUnknown_SkColorType == info.colorType()) { |
| 376 | return kInvalidConversion; |
| 377 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 378 | if (nullptr == pixels) { |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 379 | return kInvalidParameters; |
| 380 | } |
| 381 | if (rowBytes < info.minRowBytes()) { |
| 382 | return kInvalidParameters; |
| 383 | } |
| 384 | |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 385 | // Default options. |
| 386 | Options optsStorage; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 387 | if (nullptr == options) { |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 388 | options = &optsStorage; |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 389 | } else { |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 390 | if (options->fSubset) { |
| 391 | SkIRect subset(*options->fSubset); |
| 392 | if (!this->onGetValidSubset(&subset) || subset != *options->fSubset) { |
| 393 | // FIXME: How to differentiate between not supporting subset at all |
| 394 | // and not supporting this particular subset? |
| 395 | return kUnimplemented; |
| 396 | } |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 397 | } |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 398 | } |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 399 | |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 400 | const Result frameIndexResult = this->handleFrameIndex(info, pixels, rowBytes, |
| 401 | *options); |
| 402 | if (frameIndexResult != kSuccess) { |
| 403 | return frameIndexResult; |
| 404 | } |
| 405 | |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 406 | // FIXME: Support subsets somehow? Note that this works for SkWebpCodec |
| 407 | // because it supports arbitrary scaling/subset combinations. |
| 408 | if (!this->dimensionsSupported(info.dimensions())) { |
| 409 | return kInvalidScale; |
| 410 | } |
| 411 | |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 412 | fDstInfo = info; |
Leon Scroggins III | 4288657 | 2017-01-27 13:16:28 -0500 | [diff] [blame] | 413 | fOptions = *options; |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 414 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 415 | // On an incomplete decode, the subclass will specify the number of scanlines that it decoded |
| 416 | // successfully. |
| 417 | int rowsDecoded = 0; |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 418 | const Result result = this->onGetPixels(info, pixels, rowBytes, *options, &rowsDecoded); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 419 | |
| 420 | // A return value of kIncompleteInput indicates a truncated image stream. |
| 421 | // In this case, we will fill any uninitialized memory with a default value. |
| 422 | // Some subclasses will take care of filling any uninitialized memory on |
| 423 | // their own. They indicate that all of the memory has been filled by |
| 424 | // setting rowsDecoded equal to the height. |
Leon Scroggins III | 674a184 | 2017-07-06 12:26:09 -0400 | [diff] [blame] | 425 | if ((kIncompleteInput == result || kErrorInInput == result) && rowsDecoded != info.height()) { |
Leon Scroggins III | 4288657 | 2017-01-27 13:16:28 -0500 | [diff] [blame] | 426 | // FIXME: (skbug.com/5772) fillIncompleteImage will fill using the swizzler's width, unless |
| 427 | // there is a subset. In that case, it will use the width of the subset. From here, the |
| 428 | // subset will only be non-null in the case of SkWebpCodec, but it treats the subset |
| 429 | // differenty from the other codecs, and it needs to use the width specified by the info. |
| 430 | // Set the subset to null so SkWebpCodec uses the correct width. |
| 431 | fOptions.fSubset = nullptr; |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 432 | this->fillIncompleteImage(info, pixels, rowBytes, options->fZeroInitialized, info.height(), |
| 433 | rowsDecoded); |
| 434 | } |
| 435 | |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 436 | return result; |
| 437 | } |
| 438 | |
Leon Scroggins III | 196f319 | 2020-02-03 12:39:54 -0500 | [diff] [blame] | 439 | SkCodec::Result SkCodec::startIncrementalDecode(const SkImageInfo& info, void* pixels, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 440 | size_t rowBytes, const SkCodec::Options* options) { |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 441 | fStartedIncrementalDecode = false; |
| 442 | |
| 443 | if (kUnknown_SkColorType == info.colorType()) { |
| 444 | return kInvalidConversion; |
| 445 | } |
| 446 | if (nullptr == pixels) { |
| 447 | return kInvalidParameters; |
| 448 | } |
| 449 | |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 450 | // Set options. |
| 451 | Options optsStorage; |
| 452 | if (nullptr == options) { |
| 453 | options = &optsStorage; |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 454 | } else { |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 455 | if (options->fSubset) { |
| 456 | SkIRect size = SkIRect::MakeSize(info.dimensions()); |
| 457 | if (!size.contains(*options->fSubset)) { |
| 458 | return kInvalidParameters; |
| 459 | } |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 460 | |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 461 | const int top = options->fSubset->top(); |
| 462 | const int bottom = options->fSubset->bottom(); |
| 463 | if (top < 0 || top >= info.height() || top >= bottom || bottom > info.height()) { |
| 464 | return kInvalidParameters; |
| 465 | } |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 469 | const Result frameIndexResult = this->handleFrameIndex(info, pixels, rowBytes, |
| 470 | *options); |
| 471 | if (frameIndexResult != kSuccess) { |
| 472 | return frameIndexResult; |
| 473 | } |
| 474 | |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 475 | if (!this->dimensionsSupported(info.dimensions())) { |
| 476 | return kInvalidScale; |
| 477 | } |
| 478 | |
| 479 | fDstInfo = info; |
| 480 | fOptions = *options; |
| 481 | |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 482 | const Result result = this->onStartIncrementalDecode(info, pixels, rowBytes, fOptions); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 483 | if (kSuccess == result) { |
| 484 | fStartedIncrementalDecode = true; |
| 485 | } else if (kUnimplemented == result) { |
| 486 | // FIXME: This is temporarily necessary, until we transition SkCodec |
| 487 | // implementations from scanline decoding to incremental decoding. |
| 488 | // SkAndroidCodec will first attempt to use incremental decoding, but |
| 489 | // will fall back to scanline decoding if incremental returns |
| 490 | // kUnimplemented. rewindIfNeeded(), above, set fNeedsRewind to true |
| 491 | // (after potentially rewinding), but we do not want the next call to |
| 492 | // startScanlineDecode() to do a rewind. |
| 493 | fNeedsRewind = false; |
| 494 | } |
| 495 | return result; |
| 496 | } |
| 497 | |
| 498 | |
Leon Scroggins III | 196f319 | 2020-02-03 12:39:54 -0500 | [diff] [blame] | 499 | SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& info, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 500 | const SkCodec::Options* options) { |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 501 | // Reset fCurrScanline in case of failure. |
| 502 | fCurrScanline = -1; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 503 | |
| 504 | // Set options. |
| 505 | Options optsStorage; |
| 506 | if (nullptr == options) { |
| 507 | options = &optsStorage; |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 508 | } else if (options->fSubset) { |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 509 | SkIRect size = SkIRect::MakeSize(info.dimensions()); |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 510 | if (!size.contains(*options->fSubset)) { |
| 511 | return kInvalidInput; |
| 512 | } |
| 513 | |
| 514 | // We only support subsetting in the x-dimension for scanline decoder. |
| 515 | // Subsetting in the y-dimension can be accomplished using skipScanlines(). |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 516 | if (options->fSubset->top() != 0 || options->fSubset->height() != info.height()) { |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 517 | return kInvalidInput; |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 521 | // Scanline decoding only supports decoding the first frame. |
| 522 | if (options->fFrameIndex != 0) { |
| 523 | return kUnimplemented; |
| 524 | } |
| 525 | |
| 526 | // The void* dst and rowbytes in handleFrameIndex or only used for decoding prior |
| 527 | // frames, which is not supported here anyway, so it is safe to pass nullptr/0. |
| 528 | const Result frameIndexResult = this->handleFrameIndex(info, nullptr, 0, *options); |
| 529 | if (frameIndexResult != kSuccess) { |
| 530 | return frameIndexResult; |
| 531 | } |
| 532 | |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 533 | // FIXME: Support subsets somehow? |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 534 | if (!this->dimensionsSupported(info.dimensions())) { |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 535 | return kInvalidScale; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 538 | const Result result = this->onStartScanlineDecode(info, *options); |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 539 | if (result != SkCodec::kSuccess) { |
| 540 | return result; |
| 541 | } |
| 542 | |
Leon Scroggins | fc4fdc5 | 2020-11-09 14:18:12 -0500 | [diff] [blame^] | 543 | // FIXME: See startIncrementalDecode. That method set fNeedsRewind to false |
| 544 | // so that when onStartScanlineDecode calls rewindIfNeeded it would not |
| 545 | // rewind. But it also relies on that call to rewindIfNeeded to set |
| 546 | // fNeedsRewind to true for future decodes. When |
| 547 | // fAndroidCodecHandlesFrameIndex is true, that call to rewindIfNeeded is |
| 548 | // skipped, so this method sets it back to true. |
| 549 | SkASSERT(fAndroidCodecHandlesFrameIndex || fNeedsRewind); |
| 550 | fNeedsRewind = true; |
| 551 | |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 552 | fCurrScanline = 0; |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 553 | fDstInfo = info; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 554 | fOptions = *options; |
| 555 | return kSuccess; |
| 556 | } |
| 557 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 558 | int SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes) { |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 559 | if (fCurrScanline < 0) { |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 560 | return 0; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | SkASSERT(!fDstInfo.isEmpty()); |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 564 | if (countLines <= 0 || fCurrScanline + countLines > fDstInfo.height()) { |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 565 | return 0; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 566 | } |
| 567 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 568 | const int linesDecoded = this->onGetScanlines(dst, countLines, rowBytes); |
| 569 | if (linesDecoded < countLines) { |
| 570 | this->fillIncompleteImage(this->dstInfo(), dst, rowBytes, this->options().fZeroInitialized, |
| 571 | countLines, linesDecoded); |
| 572 | } |
| 573 | fCurrScanline += countLines; |
| 574 | return linesDecoded; |
| 575 | } |
| 576 | |
| 577 | bool SkCodec::skipScanlines(int countLines) { |
| 578 | if (fCurrScanline < 0) { |
| 579 | return false; |
| 580 | } |
| 581 | |
| 582 | SkASSERT(!fDstInfo.isEmpty()); |
| 583 | if (countLines < 0 || fCurrScanline + countLines > fDstInfo.height()) { |
| 584 | // Arguably, we could just skip the scanlines which are remaining, |
| 585 | // and return true. We choose to return false so the client |
| 586 | // can catch their bug. |
| 587 | return false; |
| 588 | } |
| 589 | |
| 590 | bool result = this->onSkipScanlines(countLines); |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 591 | fCurrScanline += countLines; |
| 592 | return result; |
| 593 | } |
| 594 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 595 | int SkCodec::outputScanline(int inputScanline) const { |
Leon Scroggins III | 712476e | 2018-10-03 15:47:00 -0400 | [diff] [blame] | 596 | SkASSERT(0 <= inputScanline && inputScanline < fEncodedInfo.height()); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 597 | return this->onOutputScanline(inputScanline); |
| 598 | } |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 599 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 600 | int SkCodec::onOutputScanline(int inputScanline) const { |
| 601 | switch (this->getScanlineOrder()) { |
| 602 | case kTopDown_SkScanlineOrder: |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 603 | return inputScanline; |
| 604 | case kBottomUp_SkScanlineOrder: |
Leon Scroggins III | 712476e | 2018-10-03 15:47:00 -0400 | [diff] [blame] | 605 | return fEncodedInfo.height() - inputScanline - 1; |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 606 | default: |
| 607 | // This case indicates an interlaced gif and is implemented by SkGifCodec. |
| 608 | SkASSERT(false); |
| 609 | return 0; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 610 | } |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 611 | } |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 612 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 613 | void SkCodec::fillIncompleteImage(const SkImageInfo& info, void* dst, size_t rowBytes, |
| 614 | ZeroInitialized zeroInit, int linesRequested, int linesDecoded) { |
Leon Scroggins III | a6161b1 | 2018-10-18 14:45:26 -0400 | [diff] [blame] | 615 | if (kYes_ZeroInitialized == zeroInit) { |
| 616 | return; |
| 617 | } |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 618 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 619 | const int linesRemaining = linesRequested - linesDecoded; |
| 620 | SkSampler* sampler = this->getSampler(false); |
| 621 | |
Leon Scroggins III | a6161b1 | 2018-10-18 14:45:26 -0400 | [diff] [blame] | 622 | const int fillWidth = sampler ? sampler->fillWidth() : |
| 623 | fOptions.fSubset ? fOptions.fSubset->width() : |
| 624 | info.width() ; |
| 625 | void* fillDst = this->getScanlineOrder() == kBottomUp_SkScanlineOrder ? dst : |
| 626 | SkTAddOffset<void>(dst, linesDecoded * rowBytes); |
| 627 | const auto fillInfo = info.makeWH(fillWidth, linesRemaining); |
| 628 | SkSampler::Fill(fillInfo, fillDst, rowBytes, kNo_ZeroInitialized); |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 629 | } |
Matt Sarett | 313c463 | 2016-10-20 12:35:23 -0400 | [diff] [blame] | 630 | |
Leon Scroggins III | 179559f | 2018-12-10 12:30:12 -0500 | [diff] [blame] | 631 | bool sk_select_xform_format(SkColorType colorType, bool forColorTable, |
| 632 | skcms_PixelFormat* outFormat) { |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 633 | SkASSERT(outFormat); |
| 634 | |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 635 | switch (colorType) { |
| 636 | case kRGBA_8888_SkColorType: |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 637 | *outFormat = skcms_PixelFormat_RGBA_8888; |
| 638 | break; |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 639 | case kBGRA_8888_SkColorType: |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 640 | *outFormat = skcms_PixelFormat_BGRA_8888; |
| 641 | break; |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 642 | case kRGB_565_SkColorType: |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 643 | if (forColorTable) { |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 644 | #ifdef SK_PMCOLOR_IS_RGBA |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 645 | *outFormat = skcms_PixelFormat_RGBA_8888; |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 646 | #else |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 647 | *outFormat = skcms_PixelFormat_BGRA_8888; |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 648 | #endif |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 649 | break; |
| 650 | } |
| 651 | *outFormat = skcms_PixelFormat_BGR_565; |
| 652 | break; |
| 653 | case kRGBA_F16_SkColorType: |
| 654 | *outFormat = skcms_PixelFormat_RGBA_hhhh; |
| 655 | break; |
Brian Osman | b3f3830 | 2018-09-07 15:24:44 -0400 | [diff] [blame] | 656 | case kGray_8_SkColorType: |
| 657 | *outFormat = skcms_PixelFormat_G_8; |
| 658 | break; |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 659 | default: |
Leon Scroggins | 83988ed | 2018-08-24 21:41:24 +0000 | [diff] [blame] | 660 | return false; |
Leon Scroggins | 83988ed | 2018-08-24 21:41:24 +0000 | [diff] [blame] | 661 | } |
Matt Sarett | 313c463 | 2016-10-20 12:35:23 -0400 | [diff] [blame] | 662 | return true; |
| 663 | } |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 664 | |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 665 | bool SkCodec::initializeColorXform(const SkImageInfo& dstInfo, SkEncodedInfo::Alpha encodedAlpha, |
| 666 | bool srcIsOpaque) { |
| 667 | fXformTime = kNo_XformTime; |
| 668 | bool needsColorXform = false; |
Leon Scroggins III | 196f319 | 2020-02-03 12:39:54 -0500 | [diff] [blame] | 669 | if (this->usesColorXform()) { |
Leon Scroggins III | 5dd47e4 | 2018-09-27 15:26:48 -0400 | [diff] [blame] | 670 | if (kRGBA_F16_SkColorType == dstInfo.colorType()) { |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 671 | needsColorXform = true; |
Leon Scroggins III | 196f319 | 2020-02-03 12:39:54 -0500 | [diff] [blame] | 672 | if (dstInfo.colorSpace()) { |
| 673 | dstInfo.colorSpace()->toProfile(&fDstProfile); |
| 674 | } else { |
| 675 | // Use the srcProfile to avoid conversion. |
| 676 | const auto* srcProfile = fEncodedInfo.profile(); |
| 677 | fDstProfile = srcProfile ? *srcProfile : *skcms_sRGB_profile(); |
| 678 | } |
| 679 | } else if (dstInfo.colorSpace()) { |
| 680 | dstInfo.colorSpace()->toProfile(&fDstProfile); |
Leon Scroggins III | 5dd47e4 | 2018-09-27 15:26:48 -0400 | [diff] [blame] | 681 | const auto* srcProfile = fEncodedInfo.profile(); |
| 682 | if (!srcProfile) { |
| 683 | srcProfile = skcms_sRGB_profile(); |
| 684 | } |
| 685 | if (!skcms_ApproximatelyEqualProfiles(srcProfile, &fDstProfile) ) { |
| 686 | needsColorXform = true; |
| 687 | } |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
Leon Scroggins III | 712476e | 2018-10-03 15:47:00 -0400 | [diff] [blame] | 691 | if (!this->conversionSupported(dstInfo, srcIsOpaque, needsColorXform)) { |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 692 | return false; |
| 693 | } |
| 694 | |
| 695 | if (needsColorXform) { |
| 696 | fXformTime = SkEncodedInfo::kPalette_Color != fEncodedInfo.color() |
| 697 | || kRGBA_F16_SkColorType == dstInfo.colorType() |
| 698 | ? kDecodeRow_XformTime : kPalette_XformTime; |
Leon Scroggins III | 179559f | 2018-12-10 12:30:12 -0500 | [diff] [blame] | 699 | if (!sk_select_xform_format(dstInfo.colorType(), fXformTime == kPalette_XformTime, |
| 700 | &fDstXformFormat)) { |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 701 | return false; |
| 702 | } |
| 703 | if (encodedAlpha == SkEncodedInfo::kUnpremul_Alpha |
| 704 | && dstInfo.alphaType() == kPremul_SkAlphaType) { |
| 705 | fDstXformAlphaFormat = skcms_AlphaFormat_PremulAsEncoded; |
| 706 | } else { |
| 707 | fDstXformAlphaFormat = skcms_AlphaFormat_Unpremul; |
| 708 | } |
| 709 | } |
| 710 | return true; |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | void SkCodec::applyColorXform(void* dst, const void* src, int count) const { |
Leon Scroggins III | 5dd47e4 | 2018-09-27 15:26:48 -0400 | [diff] [blame] | 714 | // It is okay for srcProfile to be null. This will use sRGB. |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 715 | const auto* srcProfile = fEncodedInfo.profile(); |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 716 | SkAssertResult(skcms_Transform(src, fSrcXformFormat, skcms_AlphaFormat_Unpremul, srcProfile, |
| 717 | dst, fDstXformFormat, fDstXformAlphaFormat, &fDstProfile, |
| 718 | count)); |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 719 | } |
| 720 | |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 721 | std::vector<SkCodec::FrameInfo> SkCodec::getFrameInfo() { |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 722 | const int frameCount = this->getFrameCount(); |
| 723 | SkASSERT(frameCount >= 0); |
| 724 | if (frameCount <= 0) { |
| 725 | return std::vector<FrameInfo>{}; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 726 | } |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 727 | |
| 728 | if (frameCount == 1 && !this->onGetFrameInfo(0, nullptr)) { |
| 729 | // Not animated. |
| 730 | return std::vector<FrameInfo>{}; |
| 731 | } |
| 732 | |
| 733 | std::vector<FrameInfo> result(frameCount); |
| 734 | for (int i = 0; i < frameCount; ++i) { |
| 735 | SkAssertResult(this->onGetFrameInfo(i, &result[i])); |
| 736 | } |
| 737 | return result; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 738 | } |
Leon Scroggins III | fe3da02 | 2018-01-16 11:56:54 -0500 | [diff] [blame] | 739 | |
| 740 | const char* SkCodec::ResultToString(Result result) { |
| 741 | switch (result) { |
| 742 | case kSuccess: |
| 743 | return "success"; |
| 744 | case kIncompleteInput: |
| 745 | return "incomplete input"; |
| 746 | case kErrorInInput: |
| 747 | return "error in input"; |
| 748 | case kInvalidConversion: |
| 749 | return "invalid conversion"; |
| 750 | case kInvalidScale: |
| 751 | return "invalid scale"; |
| 752 | case kInvalidParameters: |
| 753 | return "invalid parameters"; |
| 754 | case kInvalidInput: |
| 755 | return "invalid input"; |
| 756 | case kCouldNotRewind: |
| 757 | return "could not rewind"; |
| 758 | case kInternalError: |
| 759 | return "internal error"; |
| 760 | case kUnimplemented: |
| 761 | return "unimplemented"; |
| 762 | default: |
| 763 | SkASSERT(false); |
| 764 | return "bogus result value"; |
| 765 | } |
| 766 | } |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 767 | |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 768 | static bool independent(const SkFrame& frame) { |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 769 | return frame.getRequiredFrame() == SkCodec::kNoFrame; |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | static bool restore_bg(const SkFrame& frame) { |
| 773 | return frame.getDisposalMethod() == SkCodecAnimation::DisposalMethod::kRestoreBGColor; |
| 774 | } |
| 775 | |
Nigel Tao | b8ec7f1 | 2019-03-26 10:44:58 +1100 | [diff] [blame] | 776 | // As its name suggests, this method computes a frame's alpha (e.g. completely |
| 777 | // opaque, unpremul, binary) and its required frame (a preceding frame that |
| 778 | // this frame depends on, to draw the complete image at this frame's point in |
| 779 | // the animation stream), and calls this frame's setter methods with that |
| 780 | // computed information. |
| 781 | // |
| 782 | // A required frame of kNoFrame means that this frame is independent: drawing |
| 783 | // the complete image at this frame's point in the animation stream does not |
| 784 | // require first preparing the pixel buffer based on another frame. Instead, |
| 785 | // drawing can start from an uninitialized pixel buffer. |
| 786 | // |
| 787 | // "Uninitialized" is from the SkCodec's caller's point of view. In the SkCodec |
| 788 | // implementation, for independent frames, first party Skia code (in src/codec) |
| 789 | // will typically fill the buffer with a uniform background color (e.g. |
| 790 | // transparent black) before calling into third party codec-specific code (e.g. |
| 791 | // libjpeg or libpng). Pixels outside of the frame's rect will remain this |
| 792 | // background color after drawing this frame. For incomplete decodes, pixels |
| 793 | // inside that rect may be (at least temporarily) set to that background color. |
| 794 | // In an incremental decode, later passes may then overwrite that background |
| 795 | // color. |
| 796 | // |
| 797 | // Determining kNoFrame or otherwise involves testing a number of conditions |
| 798 | // sequentially. The first satisfied condition results in setting the required |
| 799 | // frame to kNoFrame (an "INDx" condition) or to a non-negative frame number (a |
| 800 | // "DEPx" condition), and the function returning early. Those "INDx" and "DEPx" |
| 801 | // labels also map to comments in the function body. |
| 802 | // |
| 803 | // - IND1: this frame is the first frame. |
| 804 | // - IND2: this frame fills out the whole image, and it is completely opaque |
| 805 | // or it overwrites (not blends with) the previous frame. |
| 806 | // - IND3: all preceding frames' disposals are kRestorePrevious. |
| 807 | // - IND4: the prevFrame's disposal is kRestoreBGColor, and it fills out the |
| 808 | // whole image or it is itself otherwise independent. |
| 809 | // - DEP5: this frame reports alpha (it is not completely opaque) and it |
| 810 | // blends with (not overwrites) the previous frame. |
| 811 | // - IND6: this frame's rect covers the rects of all preceding frames back to |
| 812 | // and including the most recent independent frame before this frame. |
| 813 | // - DEP7: unconditional. |
| 814 | // |
| 815 | // The "prevFrame" variable initially points to the previous frame (also known |
| 816 | // as the prior frame), but that variable may iterate further backwards over |
| 817 | // the course of this computation. |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 818 | void SkFrameHolder::setAlphaAndRequiredFrame(SkFrame* frame) { |
| 819 | const bool reportsAlpha = frame->reportedAlpha() != SkEncodedInfo::kOpaque_Alpha; |
| 820 | const auto screenRect = SkIRect::MakeWH(fScreenWidth, fScreenHeight); |
| 821 | const auto frameRect = frame_rect_on_screen(frame->frameRect(), screenRect); |
| 822 | |
| 823 | const int i = frame->frameId(); |
| 824 | if (0 == i) { |
| 825 | frame->setHasAlpha(reportsAlpha || frameRect != screenRect); |
Nigel Tao | b8ec7f1 | 2019-03-26 10:44:58 +1100 | [diff] [blame] | 826 | frame->setRequiredFrame(SkCodec::kNoFrame); // IND1 |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 827 | return; |
| 828 | } |
| 829 | |
| 830 | |
| 831 | const bool blendWithPrevFrame = frame->getBlend() == SkCodecAnimation::Blend::kPriorFrame; |
| 832 | if ((!reportsAlpha || !blendWithPrevFrame) && frameRect == screenRect) { |
| 833 | frame->setHasAlpha(reportsAlpha); |
Nigel Tao | b8ec7f1 | 2019-03-26 10:44:58 +1100 | [diff] [blame] | 834 | frame->setRequiredFrame(SkCodec::kNoFrame); // IND2 |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 835 | return; |
| 836 | } |
| 837 | |
| 838 | const SkFrame* prevFrame = this->getFrame(i-1); |
| 839 | while (prevFrame->getDisposalMethod() == SkCodecAnimation::DisposalMethod::kRestorePrevious) { |
| 840 | const int prevId = prevFrame->frameId(); |
| 841 | if (0 == prevId) { |
| 842 | frame->setHasAlpha(true); |
Nigel Tao | b8ec7f1 | 2019-03-26 10:44:58 +1100 | [diff] [blame] | 843 | frame->setRequiredFrame(SkCodec::kNoFrame); // IND3 |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 844 | return; |
| 845 | } |
| 846 | |
| 847 | prevFrame = this->getFrame(prevId - 1); |
| 848 | } |
| 849 | |
| 850 | const bool clearPrevFrame = restore_bg(*prevFrame); |
| 851 | auto prevFrameRect = frame_rect_on_screen(prevFrame->frameRect(), screenRect); |
| 852 | |
| 853 | if (clearPrevFrame) { |
| 854 | if (prevFrameRect == screenRect || independent(*prevFrame)) { |
| 855 | frame->setHasAlpha(true); |
Nigel Tao | b8ec7f1 | 2019-03-26 10:44:58 +1100 | [diff] [blame] | 856 | frame->setRequiredFrame(SkCodec::kNoFrame); // IND4 |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 857 | return; |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | if (reportsAlpha && blendWithPrevFrame) { |
| 862 | // Note: We could be more aggressive here. If prevFrame clears |
| 863 | // to background color and covers its required frame (and that |
| 864 | // frame is independent), prevFrame could be marked independent. |
| 865 | // Would this extra complexity be worth it? |
Nigel Tao | b8ec7f1 | 2019-03-26 10:44:58 +1100 | [diff] [blame] | 866 | frame->setRequiredFrame(prevFrame->frameId()); // DEP5 |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 867 | frame->setHasAlpha(prevFrame->hasAlpha() || clearPrevFrame); |
| 868 | return; |
| 869 | } |
| 870 | |
| 871 | while (frameRect.contains(prevFrameRect)) { |
| 872 | const int prevRequiredFrame = prevFrame->getRequiredFrame(); |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 873 | if (prevRequiredFrame == SkCodec::kNoFrame) { |
Nigel Tao | b8ec7f1 | 2019-03-26 10:44:58 +1100 | [diff] [blame] | 874 | frame->setRequiredFrame(SkCodec::kNoFrame); // IND6 |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 875 | frame->setHasAlpha(true); |
| 876 | return; |
| 877 | } |
| 878 | |
| 879 | prevFrame = this->getFrame(prevRequiredFrame); |
| 880 | prevFrameRect = frame_rect_on_screen(prevFrame->frameRect(), screenRect); |
| 881 | } |
| 882 | |
Nigel Tao | b8ec7f1 | 2019-03-26 10:44:58 +1100 | [diff] [blame] | 883 | frame->setRequiredFrame(prevFrame->frameId()); // DEP7 |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 884 | if (restore_bg(*prevFrame)) { |
| 885 | frame->setHasAlpha(true); |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 886 | return; |
| 887 | } |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 888 | SkASSERT(prevFrame->getDisposalMethod() == SkCodecAnimation::DisposalMethod::kKeep); |
Nigel Tao | a78b6dc | 2018-07-28 16:48:09 +1000 | [diff] [blame] | 889 | frame->setHasAlpha(prevFrame->hasAlpha() || (reportsAlpha && !blendWithPrevFrame)); |
| 890 | } |
| 891 | |