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 | |
msarett | b46e5e2 | 2015-07-30 11:36:40 -0700 | [diff] [blame] | 8 | #include "SkBmpCodec.h" |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 9 | #include "SkCodec.h" |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 10 | #include "SkCodecPriv.h" |
msarett | ad8bcfe | 2016-03-07 07:09:03 -0800 | [diff] [blame] | 11 | #include "SkColorSpace.h" |
Matt Sarett | cf3f234 | 2017-03-23 15:32:25 -0400 | [diff] [blame] | 12 | #include "SkColorSpaceXform_Base.h" |
msarett | 1a46467 | 2016-01-07 13:17:19 -0800 | [diff] [blame] | 13 | #include "SkData.h" |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 14 | #include "SkFrameHolder.h" |
msarett | 1a46467 | 2016-01-07 13:17:19 -0800 | [diff] [blame] | 15 | #include "SkGifCodec.h" |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 16 | #include "SkHalf.h" |
msarett | 1a46467 | 2016-01-07 13:17:19 -0800 | [diff] [blame] | 17 | #include "SkIcoCodec.h" |
msarett | e16b04a | 2015-04-15 07:32:19 -0700 | [diff] [blame] | 18 | #include "SkJpegCodec.h" |
msarett | ad3a5c6 | 2016-05-06 07:21:26 -0700 | [diff] [blame] | 19 | #ifdef SK_HAS_PNG_LIBRARY |
msarett | be1d555 | 2016-01-21 09:05:23 -0800 | [diff] [blame] | 20 | #include "SkPngCodec.h" |
yujieqin | 916de9f | 2016-01-25 08:26:16 -0800 | [diff] [blame] | 21 | #endif |
msarett | 39b2d5a | 2016-02-17 08:26:31 -0800 | [diff] [blame] | 22 | #include "SkRawCodec.h" |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 23 | #include "SkStream.h" |
msarett | 1a46467 | 2016-01-07 13:17:19 -0800 | [diff] [blame] | 24 | #include "SkWbmpCodec.h" |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 25 | #include "SkWebpCodec.h" |
Chong Zhang | c2a9542 | 2017-08-16 13:03:47 -0700 | [diff] [blame] | 26 | #include "SkHeifCodec.h" |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 27 | |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 28 | struct DecoderProc { |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 29 | bool (*IsFormat)(const void*, size_t); |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 30 | std::unique_ptr<SkCodec> (*MakeFromStream)(std::unique_ptr<SkStream>, SkCodec::Result*); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | static const DecoderProc gDecoderProcs[] = { |
msarett | ad3a5c6 | 2016-05-06 07:21:26 -0700 | [diff] [blame] | 34 | #ifdef SK_HAS_JPEG_LIBRARY |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 35 | { SkJpegCodec::IsJpeg, SkJpegCodec::MakeFromStream }, |
msarett | 39b2d5a | 2016-02-17 08:26:31 -0800 | [diff] [blame] | 36 | #endif |
msarett | ad3a5c6 | 2016-05-06 07:21:26 -0700 | [diff] [blame] | 37 | #ifdef SK_HAS_WEBP_LIBRARY |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 38 | { SkWebpCodec::IsWebp, SkWebpCodec::MakeFromStream }, |
msarett | 39b2d5a | 2016-02-17 08:26:31 -0800 | [diff] [blame] | 39 | #endif |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 40 | { SkGifCodec::IsGif, SkGifCodec::MakeFromStream }, |
msarett | ad3a5c6 | 2016-05-06 07:21:26 -0700 | [diff] [blame] | 41 | #ifdef SK_HAS_PNG_LIBRARY |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 42 | { SkIcoCodec::IsIco, SkIcoCodec::MakeFromStream }, |
msarett | 39b2d5a | 2016-02-17 08:26:31 -0800 | [diff] [blame] | 43 | #endif |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 44 | { SkBmpCodec::IsBmp, SkBmpCodec::MakeFromStream }, |
Chong Zhang | c2a9542 | 2017-08-16 13:03:47 -0700 | [diff] [blame] | 45 | { SkWbmpCodec::IsWbmp, SkWbmpCodec::MakeFromStream }, |
| 46 | #ifdef SK_HAS_HEIF_LIBRARY |
| 47 | { SkHeifCodec::IsHeif, SkHeifCodec::MakeFromStream }, |
| 48 | #endif |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 51 | std::unique_ptr<SkCodec> SkCodec::MakeFromStream(std::unique_ptr<SkStream> stream, |
| 52 | Result* outResult, SkPngChunkReader* chunkReader) { |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 53 | Result resultStorage; |
| 54 | if (!outResult) { |
| 55 | outResult = &resultStorage; |
| 56 | } |
| 57 | |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 58 | if (!stream) { |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 59 | *outResult = kInvalidInput; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 60 | return nullptr; |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 61 | } |
scroggo | 0a7e69c | 2015-04-03 07:22:22 -0700 | [diff] [blame] | 62 | |
Chong Zhang | c2a9542 | 2017-08-16 13:03:47 -0700 | [diff] [blame] | 63 | constexpr size_t bytesToRead = MinBufferedBytesNeeded(); |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 64 | |
| 65 | char buffer[bytesToRead]; |
| 66 | size_t bytesRead = stream->peek(buffer, bytesToRead); |
| 67 | |
| 68 | // It is also possible to have a complete image less than bytesToRead bytes |
| 69 | // (e.g. a 1 x 1 wbmp), meaning peek() would return less than bytesToRead. |
| 70 | // Assume that if bytesRead < bytesToRead, but > 0, the stream is shorter |
| 71 | // than bytesToRead, so pass that directly to the decoder. |
| 72 | // It also is possible the stream uses too small a buffer for peeking, but |
| 73 | // we trust the caller to use a large enough buffer. |
| 74 | |
| 75 | if (0 == bytesRead) { |
scroggo | 3ab9f2e | 2016-01-06 09:53:34 -0800 | [diff] [blame] | 76 | // TODO: After implementing peek in CreateJavaOutputStreamAdaptor.cpp, this |
| 77 | // printf could be useful to notice failures. |
| 78 | // SkCodecPrintf("Encoded image data failed to peek!\n"); |
| 79 | |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 80 | // It is possible the stream does not support peeking, but does support |
| 81 | // rewinding. |
| 82 | // Attempt to read() and pass the actual amount read to the decoder. |
| 83 | bytesRead = stream->read(buffer, bytesToRead); |
| 84 | if (!stream->rewind()) { |
scroggo | 3ab9f2e | 2016-01-06 09:53:34 -0800 | [diff] [blame] | 85 | 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] | 86 | *outResult = kCouldNotRewind; |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 87 | return nullptr; |
| 88 | } |
| 89 | } |
| 90 | |
scroggo | cf98fa9 | 2015-11-23 08:14:40 -0800 | [diff] [blame] | 91 | // PNG is special, since we want to be able to supply an SkPngChunkReader. |
| 92 | // But this code follows the same pattern as the loop. |
msarett | ad3a5c6 | 2016-05-06 07:21:26 -0700 | [diff] [blame] | 93 | #ifdef SK_HAS_PNG_LIBRARY |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 94 | if (SkPngCodec::IsPng(buffer, bytesRead)) { |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 95 | return SkPngCodec::MakeFromStream(std::move(stream), outResult, chunkReader); |
msarett | 39b2d5a | 2016-02-17 08:26:31 -0800 | [diff] [blame] | 96 | } else |
| 97 | #endif |
| 98 | { |
scroggo | cf98fa9 | 2015-11-23 08:14:40 -0800 | [diff] [blame] | 99 | for (DecoderProc proc : gDecoderProcs) { |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 100 | if (proc.IsFormat(buffer, bytesRead)) { |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 101 | return proc.MakeFromStream(std::move(stream), outResult); |
scroggo | cf98fa9 | 2015-11-23 08:14:40 -0800 | [diff] [blame] | 102 | } |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 103 | } |
yujieqin | 916de9f | 2016-01-25 08:26:16 -0800 | [diff] [blame] | 104 | |
| 105 | #ifdef SK_CODEC_DECODES_RAW |
| 106 | // 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] | 107 | return SkRawCodec::MakeFromStream(std::move(stream), outResult); |
yujieqin | 916de9f | 2016-01-25 08:26:16 -0800 | [diff] [blame] | 108 | #endif |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 109 | } |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 110 | |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 111 | if (bytesRead < bytesToRead) { |
| 112 | *outResult = kIncompleteInput; |
| 113 | } else { |
| 114 | *outResult = kUnimplemented; |
| 115 | } |
| 116 | |
msarett | f44631b | 2016-01-13 10:54:20 -0800 | [diff] [blame] | 117 | return nullptr; |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 120 | std::unique_ptr<SkCodec> SkCodec::MakeFromData(sk_sp<SkData> data, SkPngChunkReader* reader) { |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 121 | if (!data) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 122 | return nullptr; |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 123 | } |
Mike Reed | 847068c | 2017-07-26 11:35:53 -0400 | [diff] [blame] | 124 | return MakeFromStream(SkMemoryStream::Make(std::move(data)), nullptr, reader); |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 127 | SkCodec::SkCodec(int width, int height, const SkEncodedInfo& info, |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 128 | XformFormat srcFormat, std::unique_ptr<SkStream> stream, |
msarett | c30c418 | 2016-04-20 11:53:35 -0700 | [diff] [blame] | 129 | sk_sp<SkColorSpace> colorSpace, Origin origin) |
| 130 | : fEncodedInfo(info) |
msarett | 530c844 | 2016-07-21 11:57:49 -0700 | [diff] [blame] | 131 | , fSrcInfo(info.makeImageInfo(width, height, std::move(colorSpace))) |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 132 | , fSrcXformFormat(srcFormat) |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 133 | , fStream(std::move(stream)) |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 134 | , fNeedsRewind(false) |
msarett | 0e6274f | 2016-03-21 08:04:40 -0700 | [diff] [blame] | 135 | , fOrigin(origin) |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 136 | , fDstInfo() |
| 137 | , fOptions() |
| 138 | , fCurrScanline(-1) |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 139 | {} |
| 140 | |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 141 | SkCodec::SkCodec(const SkEncodedInfo& info, const SkImageInfo& imageInfo, |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 142 | XformFormat srcFormat, std::unique_ptr<SkStream> stream, Origin origin) |
msarett | 549ca32 | 2016-08-17 08:54:08 -0700 | [diff] [blame] | 143 | : fEncodedInfo(info) |
| 144 | , fSrcInfo(imageInfo) |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 145 | , fSrcXformFormat(srcFormat) |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 146 | , fStream(std::move(stream)) |
msarett | 549ca32 | 2016-08-17 08:54:08 -0700 | [diff] [blame] | 147 | , fNeedsRewind(false) |
| 148 | , fOrigin(origin) |
| 149 | , fDstInfo() |
| 150 | , fOptions() |
| 151 | , fCurrScanline(-1) |
| 152 | {} |
| 153 | |
scroggo | 9b2cdbf4 | 2015-07-10 12:07:02 -0700 | [diff] [blame] | 154 | SkCodec::~SkCodec() {} |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 155 | |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 156 | bool SkCodec::rewindIfNeeded() { |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 157 | // Store the value of fNeedsRewind so we can update it. Next read will |
| 158 | // require a rewind. |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 159 | const bool needsRewind = fNeedsRewind; |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 160 | fNeedsRewind = true; |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 161 | if (!needsRewind) { |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 162 | return true; |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 163 | } |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 164 | |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 165 | // startScanlineDecode will need to be called before decoding scanlines. |
| 166 | fCurrScanline = -1; |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 167 | // startIncrementalDecode will need to be called before incrementalDecode. |
| 168 | fStartedIncrementalDecode = false; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 169 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 170 | // Some codecs do not have a stream. They may hold onto their own data or another codec. |
| 171 | // They must handle rewinding themselves. |
| 172 | if (fStream && !fStream->rewind()) { |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 173 | return false; |
| 174 | } |
| 175 | |
| 176 | return this->onRewind(); |
scroggo | f24f224 | 2015-03-03 08:59:20 -0800 | [diff] [blame] | 177 | } |
scroggo | 0524590 | 2015-03-25 11:11:52 -0700 | [diff] [blame] | 178 | |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 179 | static void zero_rect(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes, |
| 180 | SkIRect frameRect) { |
| 181 | if (!frameRect.intersect(dstInfo.bounds())) { |
| 182 | return; |
| 183 | } |
| 184 | const auto info = dstInfo.makeWH(frameRect.width(), frameRect.height()); |
| 185 | const size_t bpp = SkColorTypeBytesPerPixel(dstInfo.colorType()); |
| 186 | const size_t offset = frameRect.x() * bpp + frameRect.y() * rowBytes; |
| 187 | auto* eraseDst = SkTAddOffset<void>(pixels, offset); |
| 188 | SkSampler::Fill(info, eraseDst, rowBytes, 0, SkCodec::kNo_ZeroInitialized); |
| 189 | } |
| 190 | |
| 191 | SkCodec::Result SkCodec::handleFrameIndex(const SkImageInfo& info, void* pixels, size_t rowBytes, |
| 192 | const Options& options) { |
| 193 | const int index = options.fFrameIndex; |
| 194 | if (0 == index) { |
| 195 | return kSuccess; |
| 196 | } |
| 197 | |
| 198 | if (options.fSubset || info.dimensions() != fSrcInfo.dimensions()) { |
| 199 | // If we add support for these, we need to update the code that zeroes |
| 200 | // a kRestoreBGColor frame. |
| 201 | return kInvalidParameters; |
| 202 | } |
| 203 | |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 204 | if (index >= this->onGetFrameCount()) { |
| 205 | return kIncompleteInput; |
| 206 | } |
| 207 | |
| 208 | const auto* frameHolder = this->getFrameHolder(); |
| 209 | SkASSERT(frameHolder); |
| 210 | |
| 211 | const auto* frame = frameHolder->getFrame(index); |
| 212 | SkASSERT(frame); |
| 213 | |
| 214 | const int requiredFrame = frame->getRequiredFrame(); |
| 215 | if (requiredFrame == kNone) { |
| 216 | return kSuccess; |
| 217 | } |
| 218 | |
| 219 | if (options.fPriorFrame != kNone) { |
| 220 | // Check for a valid frame as a starting point. Alternatively, we could |
| 221 | // treat an invalid frame as not providing one, but rejecting it will |
| 222 | // make it easier to catch the mistake. |
| 223 | if (options.fPriorFrame < requiredFrame || options.fPriorFrame >= index) { |
| 224 | return kInvalidParameters; |
| 225 | } |
| 226 | const auto* prevFrame = frameHolder->getFrame(options.fPriorFrame); |
| 227 | switch (prevFrame->getDisposalMethod()) { |
| 228 | case SkCodecAnimation::DisposalMethod::kRestorePrevious: |
| 229 | return kInvalidParameters; |
| 230 | case SkCodecAnimation::DisposalMethod::kRestoreBGColor: |
| 231 | // If a frame after the required frame is provided, there is no |
| 232 | // need to clear, since it must be covered by the desired frame. |
| 233 | if (options.fPriorFrame == requiredFrame) { |
| 234 | zero_rect(info, pixels, rowBytes, prevFrame->frameRect()); |
| 235 | } |
| 236 | break; |
| 237 | default: |
| 238 | break; |
| 239 | } |
| 240 | return kSuccess; |
| 241 | } |
| 242 | |
| 243 | Options prevFrameOptions(options); |
| 244 | prevFrameOptions.fFrameIndex = requiredFrame; |
| 245 | prevFrameOptions.fZeroInitialized = kNo_ZeroInitialized; |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 246 | const Result result = this->getPixels(info, pixels, rowBytes, &prevFrameOptions); |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 247 | if (result == kSuccess) { |
| 248 | const auto* prevFrame = frameHolder->getFrame(requiredFrame); |
| 249 | const auto disposalMethod = prevFrame->getDisposalMethod(); |
| 250 | if (disposalMethod == SkCodecAnimation::DisposalMethod::kRestoreBGColor) { |
| 251 | zero_rect(info, pixels, rowBytes, prevFrame->frameRect()); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | return result; |
| 256 | } |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 257 | |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 258 | SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 259 | const Options* options) { |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 260 | if (kUnknown_SkColorType == info.colorType()) { |
| 261 | return kInvalidConversion; |
| 262 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 263 | if (nullptr == pixels) { |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 264 | return kInvalidParameters; |
| 265 | } |
| 266 | if (rowBytes < info.minRowBytes()) { |
| 267 | return kInvalidParameters; |
| 268 | } |
| 269 | |
scroggo | 3a7701c | 2015-09-30 09:15:14 -0700 | [diff] [blame] | 270 | if (!this->rewindIfNeeded()) { |
| 271 | return kCouldNotRewind; |
| 272 | } |
| 273 | |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 274 | // Default options. |
| 275 | Options optsStorage; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 276 | if (nullptr == options) { |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 277 | options = &optsStorage; |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 278 | } else { |
| 279 | const Result frameIndexResult = this->handleFrameIndex(info, pixels, rowBytes, *options); |
| 280 | if (frameIndexResult != kSuccess) { |
| 281 | return frameIndexResult; |
| 282 | } |
| 283 | if (options->fSubset) { |
| 284 | SkIRect subset(*options->fSubset); |
| 285 | if (!this->onGetValidSubset(&subset) || subset != *options->fSubset) { |
| 286 | // FIXME: How to differentiate between not supporting subset at all |
| 287 | // and not supporting this particular subset? |
| 288 | return kUnimplemented; |
| 289 | } |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 290 | } |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 291 | } |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 292 | |
| 293 | // FIXME: Support subsets somehow? Note that this works for SkWebpCodec |
| 294 | // because it supports arbitrary scaling/subset combinations. |
| 295 | if (!this->dimensionsSupported(info.dimensions())) { |
| 296 | return kInvalidScale; |
| 297 | } |
| 298 | |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 299 | fDstInfo = info; |
Leon Scroggins III | 4288657 | 2017-01-27 13:16:28 -0500 | [diff] [blame] | 300 | fOptions = *options; |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 301 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 302 | // On an incomplete decode, the subclass will specify the number of scanlines that it decoded |
| 303 | // successfully. |
| 304 | int rowsDecoded = 0; |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 305 | const Result result = this->onGetPixels(info, pixels, rowBytes, *options, &rowsDecoded); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 306 | |
| 307 | // A return value of kIncompleteInput indicates a truncated image stream. |
| 308 | // In this case, we will fill any uninitialized memory with a default value. |
| 309 | // Some subclasses will take care of filling any uninitialized memory on |
| 310 | // their own. They indicate that all of the memory has been filled by |
| 311 | // setting rowsDecoded equal to the height. |
Leon Scroggins III | 674a184 | 2017-07-06 12:26:09 -0400 | [diff] [blame] | 312 | if ((kIncompleteInput == result || kErrorInInput == result) && rowsDecoded != info.height()) { |
Leon Scroggins III | 4288657 | 2017-01-27 13:16:28 -0500 | [diff] [blame] | 313 | // FIXME: (skbug.com/5772) fillIncompleteImage will fill using the swizzler's width, unless |
| 314 | // there is a subset. In that case, it will use the width of the subset. From here, the |
| 315 | // subset will only be non-null in the case of SkWebpCodec, but it treats the subset |
| 316 | // differenty from the other codecs, and it needs to use the width specified by the info. |
| 317 | // Set the subset to null so SkWebpCodec uses the correct width. |
| 318 | fOptions.fSubset = nullptr; |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 319 | this->fillIncompleteImage(info, pixels, rowBytes, options->fZeroInitialized, info.height(), |
| 320 | rowsDecoded); |
| 321 | } |
| 322 | |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 323 | return result; |
| 324 | } |
| 325 | |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 326 | SkCodec::Result SkCodec::startIncrementalDecode(const SkImageInfo& info, void* pixels, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 327 | size_t rowBytes, const SkCodec::Options* options) { |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 328 | fStartedIncrementalDecode = false; |
| 329 | |
| 330 | if (kUnknown_SkColorType == info.colorType()) { |
| 331 | return kInvalidConversion; |
| 332 | } |
| 333 | if (nullptr == pixels) { |
| 334 | return kInvalidParameters; |
| 335 | } |
| 336 | |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 337 | // FIXME: If the rows come after the rows of a previous incremental decode, |
| 338 | // we might be able to skip the rewind, but only the implementation knows |
| 339 | // that. (e.g. PNG will always need to rewind, since we called longjmp, but |
| 340 | // a bottom-up BMP could skip rewinding if the new rows are above the old |
| 341 | // rows.) |
| 342 | if (!this->rewindIfNeeded()) { |
| 343 | return kCouldNotRewind; |
| 344 | } |
| 345 | |
| 346 | // Set options. |
| 347 | Options optsStorage; |
| 348 | if (nullptr == options) { |
| 349 | options = &optsStorage; |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 350 | } else { |
| 351 | const Result frameIndexResult = this->handleFrameIndex(info, pixels, rowBytes, *options); |
| 352 | if (frameIndexResult != kSuccess) { |
| 353 | return frameIndexResult; |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 354 | } |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 355 | if (options->fSubset) { |
| 356 | SkIRect size = SkIRect::MakeSize(info.dimensions()); |
| 357 | if (!size.contains(*options->fSubset)) { |
| 358 | return kInvalidParameters; |
| 359 | } |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 360 | |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 361 | const int top = options->fSubset->top(); |
| 362 | const int bottom = options->fSubset->bottom(); |
| 363 | if (top < 0 || top >= info.height() || top >= bottom || bottom > info.height()) { |
| 364 | return kInvalidParameters; |
| 365 | } |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
| 369 | if (!this->dimensionsSupported(info.dimensions())) { |
| 370 | return kInvalidScale; |
| 371 | } |
| 372 | |
| 373 | fDstInfo = info; |
| 374 | fOptions = *options; |
| 375 | |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 376 | const Result result = this->onStartIncrementalDecode(info, pixels, rowBytes, fOptions); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 377 | if (kSuccess == result) { |
| 378 | fStartedIncrementalDecode = true; |
| 379 | } else if (kUnimplemented == result) { |
| 380 | // FIXME: This is temporarily necessary, until we transition SkCodec |
| 381 | // implementations from scanline decoding to incremental decoding. |
| 382 | // SkAndroidCodec will first attempt to use incremental decoding, but |
| 383 | // will fall back to scanline decoding if incremental returns |
| 384 | // kUnimplemented. rewindIfNeeded(), above, set fNeedsRewind to true |
| 385 | // (after potentially rewinding), but we do not want the next call to |
| 386 | // startScanlineDecode() to do a rewind. |
| 387 | fNeedsRewind = false; |
| 388 | } |
| 389 | return result; |
| 390 | } |
| 391 | |
| 392 | |
| 393 | SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& info, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 394 | const SkCodec::Options* options) { |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 395 | // Reset fCurrScanline in case of failure. |
| 396 | fCurrScanline = -1; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 397 | |
scroggo | 3a7701c | 2015-09-30 09:15:14 -0700 | [diff] [blame] | 398 | if (!this->rewindIfNeeded()) { |
| 399 | return kCouldNotRewind; |
| 400 | } |
| 401 | |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 402 | // Set options. |
| 403 | Options optsStorage; |
| 404 | if (nullptr == options) { |
| 405 | options = &optsStorage; |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 406 | } else if (options->fSubset) { |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 407 | SkIRect size = SkIRect::MakeSize(info.dimensions()); |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 408 | if (!size.contains(*options->fSubset)) { |
| 409 | return kInvalidInput; |
| 410 | } |
| 411 | |
| 412 | // We only support subsetting in the x-dimension for scanline decoder. |
| 413 | // Subsetting in the y-dimension can be accomplished using skipScanlines(). |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 414 | if (options->fSubset->top() != 0 || options->fSubset->height() != info.height()) { |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 415 | return kInvalidInput; |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
| 419 | // FIXME: Support subsets somehow? |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 420 | if (!this->dimensionsSupported(info.dimensions())) { |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 421 | return kInvalidScale; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 424 | const Result result = this->onStartScanlineDecode(info, *options); |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 425 | if (result != SkCodec::kSuccess) { |
| 426 | return result; |
| 427 | } |
| 428 | |
| 429 | fCurrScanline = 0; |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 430 | fDstInfo = info; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 431 | fOptions = *options; |
| 432 | return kSuccess; |
| 433 | } |
| 434 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 435 | int SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes) { |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 436 | if (fCurrScanline < 0) { |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 437 | return 0; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | SkASSERT(!fDstInfo.isEmpty()); |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 441 | if (countLines <= 0 || fCurrScanline + countLines > fDstInfo.height()) { |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 442 | return 0; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 443 | } |
| 444 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 445 | const int linesDecoded = this->onGetScanlines(dst, countLines, rowBytes); |
| 446 | if (linesDecoded < countLines) { |
| 447 | this->fillIncompleteImage(this->dstInfo(), dst, rowBytes, this->options().fZeroInitialized, |
| 448 | countLines, linesDecoded); |
| 449 | } |
| 450 | fCurrScanline += countLines; |
| 451 | return linesDecoded; |
| 452 | } |
| 453 | |
| 454 | bool SkCodec::skipScanlines(int countLines) { |
| 455 | if (fCurrScanline < 0) { |
| 456 | return false; |
| 457 | } |
| 458 | |
| 459 | SkASSERT(!fDstInfo.isEmpty()); |
| 460 | if (countLines < 0 || fCurrScanline + countLines > fDstInfo.height()) { |
| 461 | // Arguably, we could just skip the scanlines which are remaining, |
| 462 | // and return true. We choose to return false so the client |
| 463 | // can catch their bug. |
| 464 | return false; |
| 465 | } |
| 466 | |
| 467 | bool result = this->onSkipScanlines(countLines); |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 468 | fCurrScanline += countLines; |
| 469 | return result; |
| 470 | } |
| 471 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 472 | int SkCodec::outputScanline(int inputScanline) const { |
| 473 | SkASSERT(0 <= inputScanline && inputScanline < this->getInfo().height()); |
| 474 | return this->onOutputScanline(inputScanline); |
| 475 | } |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 476 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 477 | int SkCodec::onOutputScanline(int inputScanline) const { |
| 478 | switch (this->getScanlineOrder()) { |
| 479 | case kTopDown_SkScanlineOrder: |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 480 | return inputScanline; |
| 481 | case kBottomUp_SkScanlineOrder: |
| 482 | return this->getInfo().height() - inputScanline - 1; |
| 483 | default: |
| 484 | // This case indicates an interlaced gif and is implemented by SkGifCodec. |
| 485 | SkASSERT(false); |
| 486 | return 0; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 487 | } |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 488 | } |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 489 | |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 490 | uint64_t SkCodec::onGetFillValue(const SkImageInfo& dstInfo) const { |
| 491 | switch (dstInfo.colorType()) { |
| 492 | case kRGBA_F16_SkColorType: { |
| 493 | static constexpr uint64_t transparentColor = 0; |
| 494 | static constexpr uint64_t opaqueColor = ((uint64_t) SK_Half1) << 48; |
| 495 | return (kOpaque_SkAlphaType == fSrcInfo.alphaType()) ? opaqueColor : transparentColor; |
| 496 | } |
| 497 | default: { |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 498 | // This not only handles the kN32 case, but also k565, kGray8, since |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 499 | // the low bits are zeros. |
| 500 | return (kOpaque_SkAlphaType == fSrcInfo.alphaType()) ? |
| 501 | SK_ColorBLACK : SK_ColorTRANSPARENT; |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 506 | static void fill_proc(const SkImageInfo& info, void* dst, size_t rowBytes, |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 507 | uint64_t colorOrIndex, SkCodec::ZeroInitialized zeroInit, SkSampler* sampler) { |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 508 | if (sampler) { |
| 509 | sampler->fill(info, dst, rowBytes, colorOrIndex, zeroInit); |
| 510 | } else { |
| 511 | SkSampler::Fill(info, dst, rowBytes, colorOrIndex, zeroInit); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | void SkCodec::fillIncompleteImage(const SkImageInfo& info, void* dst, size_t rowBytes, |
| 516 | ZeroInitialized zeroInit, int linesRequested, int linesDecoded) { |
| 517 | |
| 518 | void* fillDst; |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 519 | const uint64_t fillValue = this->getFillValue(info); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 520 | const int linesRemaining = linesRequested - linesDecoded; |
| 521 | SkSampler* sampler = this->getSampler(false); |
| 522 | |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 523 | int fillWidth = info.width(); |
| 524 | if (fOptions.fSubset) { |
| 525 | fillWidth = fOptions.fSubset->width(); |
| 526 | } |
| 527 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 528 | switch (this->getScanlineOrder()) { |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 529 | case kTopDown_SkScanlineOrder: { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 530 | const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 531 | fillDst = SkTAddOffset<void>(dst, linesDecoded * rowBytes); |
| 532 | fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler); |
| 533 | break; |
| 534 | } |
| 535 | case kBottomUp_SkScanlineOrder: { |
| 536 | fillDst = dst; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 537 | const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 538 | fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler); |
| 539 | break; |
| 540 | } |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 541 | } |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 542 | } |
Matt Sarett | 313c463 | 2016-10-20 12:35:23 -0400 | [diff] [blame] | 543 | |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 544 | static inline SkColorSpaceXform::ColorFormat select_xform_format_ct(SkColorType colorType) { |
| 545 | switch (colorType) { |
| 546 | case kRGBA_8888_SkColorType: |
| 547 | return SkColorSpaceXform::kRGBA_8888_ColorFormat; |
| 548 | case kBGRA_8888_SkColorType: |
| 549 | return SkColorSpaceXform::kBGRA_8888_ColorFormat; |
| 550 | case kRGB_565_SkColorType: |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 551 | #ifdef SK_PMCOLOR_IS_RGBA |
| 552 | return SkColorSpaceXform::kRGBA_8888_ColorFormat; |
| 553 | #else |
| 554 | return SkColorSpaceXform::kBGRA_8888_ColorFormat; |
| 555 | #endif |
| 556 | default: |
| 557 | SkASSERT(false); |
| 558 | return SkColorSpaceXform::kRGBA_8888_ColorFormat; |
| 559 | } |
| 560 | } |
| 561 | |
Matt Sarett | cf3f234 | 2017-03-23 15:32:25 -0400 | [diff] [blame] | 562 | bool SkCodec::initializeColorXform(const SkImageInfo& dstInfo, |
| 563 | SkTransferFunctionBehavior premulBehavior) { |
Matt Sarett | 313c463 | 2016-10-20 12:35:23 -0400 | [diff] [blame] | 564 | fColorXform = nullptr; |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 565 | fXformOnDecode = false; |
Matt Sarett | cf3f234 | 2017-03-23 15:32:25 -0400 | [diff] [blame] | 566 | bool needsColorCorrectPremul = needs_premul(dstInfo, fEncodedInfo) && |
| 567 | SkTransferFunctionBehavior::kRespect == premulBehavior; |
| 568 | if (needs_color_xform(dstInfo, fSrcInfo, needsColorCorrectPremul)) { |
| 569 | fColorXform = SkColorSpaceXform_Base::New(fSrcInfo.colorSpace(), dstInfo.colorSpace(), |
| 570 | premulBehavior); |
Matt Sarett | 313c463 | 2016-10-20 12:35:23 -0400 | [diff] [blame] | 571 | if (!fColorXform) { |
| 572 | return false; |
| 573 | } |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 574 | |
| 575 | // We will apply the color xform when reading the color table unless F16 is requested. |
| 576 | fXformOnDecode = SkEncodedInfo::kPalette_Color != fEncodedInfo.color() |
| 577 | || kRGBA_F16_SkColorType == dstInfo.colorType(); |
| 578 | if (fXformOnDecode) { |
| 579 | fDstXformFormat = select_xform_format(dstInfo.colorType()); |
| 580 | } else { |
| 581 | fDstXformFormat = select_xform_format_ct(dstInfo.colorType()); |
| 582 | } |
Matt Sarett | 313c463 | 2016-10-20 12:35:23 -0400 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | return true; |
| 586 | } |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 587 | |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 588 | void SkCodec::applyColorXform(void* dst, const void* src, int count, SkAlphaType at) const { |
| 589 | SkASSERT(fColorXform); |
| 590 | SkAssertResult(fColorXform->apply(fDstXformFormat, dst, |
| 591 | fSrcXformFormat, src, |
| 592 | count, at)); |
| 593 | } |
| 594 | |
| 595 | void SkCodec::applyColorXform(void* dst, const void* src, int count) const { |
| 596 | auto alphaType = select_xform_alpha(fDstInfo.alphaType(), fSrcInfo.alphaType()); |
| 597 | this->applyColorXform(dst, src, count, alphaType); |
| 598 | } |
| 599 | |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 600 | std::vector<SkCodec::FrameInfo> SkCodec::getFrameInfo() { |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 601 | const int frameCount = this->getFrameCount(); |
| 602 | SkASSERT(frameCount >= 0); |
| 603 | if (frameCount <= 0) { |
| 604 | return std::vector<FrameInfo>{}; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 605 | } |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 606 | |
| 607 | if (frameCount == 1 && !this->onGetFrameInfo(0, nullptr)) { |
| 608 | // Not animated. |
| 609 | return std::vector<FrameInfo>{}; |
| 610 | } |
| 611 | |
| 612 | std::vector<FrameInfo> result(frameCount); |
| 613 | for (int i = 0; i < frameCount; ++i) { |
| 614 | SkAssertResult(this->onGetFrameInfo(i, &result[i])); |
| 615 | } |
| 616 | return result; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 617 | } |