scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkBitmap.h" |
| 9 | #include "SkCodec.h" |
| 10 | #include "SkData.h" |
| 11 | #include "SkImageInfo.h" |
| 12 | #include "SkRWBuffer.h" |
| 13 | #include "SkString.h" |
| 14 | |
Leon Scroggins III | 932efed | 2016-12-16 11:39:51 -0500 | [diff] [blame] | 15 | #include "FakeStreams.h" |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 16 | #include "Resources.h" |
| 17 | #include "Test.h" |
| 18 | |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 19 | static SkImageInfo standardize_info(SkCodec* codec) { |
| 20 | SkImageInfo defaultInfo = codec->getInfo(); |
| 21 | // Note: This drops the SkColorSpace, allowing the equality check between two |
| 22 | // different codecs created from the same file to have the same SkImageInfo. |
| 23 | return SkImageInfo::MakeN32Premul(defaultInfo.width(), defaultInfo.height()); |
| 24 | } |
| 25 | |
| 26 | static bool create_truth(sk_sp<SkData> data, SkBitmap* dst) { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 27 | std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(std::move(data))); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 28 | if (!codec) { |
| 29 | return false; |
| 30 | } |
| 31 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 32 | const SkImageInfo info = standardize_info(codec.get()); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 33 | dst->allocPixels(info); |
| 34 | return SkCodec::kSuccess == codec->getPixels(info, dst->getPixels(), dst->rowBytes()); |
| 35 | } |
| 36 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 37 | static void compare_bitmaps(skiatest::Reporter* r, const SkBitmap& bm1, const SkBitmap& bm2) { |
| 38 | const SkImageInfo& info = bm1.info(); |
| 39 | if (info != bm2.info()) { |
| 40 | ERRORF(r, "Bitmaps have different image infos!"); |
| 41 | return; |
| 42 | } |
| 43 | const size_t rowBytes = info.minRowBytes(); |
| 44 | for (int i = 0; i < info.height(); i++) { |
| 45 | REPORTER_ASSERT(r, !memcmp(bm1.getAddr(0, 0), bm2.getAddr(0, 0), rowBytes)); |
| 46 | } |
| 47 | } |
| 48 | |
Leon Scroggins III | 4993b95 | 2016-12-08 11:54:04 -0500 | [diff] [blame] | 49 | static void test_partial(skiatest::Reporter* r, const char* name, size_t minBytes = 0) { |
Leon Scroggins III | e4ba105 | 2017-01-30 13:55:14 -0500 | [diff] [blame] | 50 | sk_sp<SkData> file = GetResourceAsData(name); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 51 | if (!file) { |
| 52 | SkDebugf("missing resource %s\n", name); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | SkBitmap truth; |
| 57 | if (!create_truth(file, &truth)) { |
| 58 | ERRORF(r, "Failed to decode %s\n", name); |
| 59 | return; |
| 60 | } |
| 61 | |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 62 | // Now decode part of the file |
Leon Scroggins III | 4993b95 | 2016-12-08 11:54:04 -0500 | [diff] [blame] | 63 | HaltingStream* stream = new HaltingStream(file, SkTMax(file->size() / 2, minBytes)); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 64 | |
| 65 | // Note that we cheat and hold on to a pointer to stream, though it is owned by |
| 66 | // partialCodec. |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 67 | std::unique_ptr<SkCodec> partialCodec(SkCodec::NewFromStream(stream)); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 68 | if (!partialCodec) { |
| 69 | // Technically, this could be a small file where half the file is not |
| 70 | // enough. |
| 71 | ERRORF(r, "Failed to create codec for %s", name); |
| 72 | return; |
| 73 | } |
| 74 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 75 | const SkImageInfo info = standardize_info(partialCodec.get()); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 76 | SkASSERT(info == truth.info()); |
| 77 | SkBitmap incremental; |
| 78 | incremental.allocPixels(info); |
| 79 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 80 | while (true) { |
| 81 | const SkCodec::Result startResult = partialCodec->startIncrementalDecode(info, |
| 82 | incremental.getPixels(), incremental.rowBytes()); |
| 83 | if (startResult == SkCodec::kSuccess) { |
| 84 | break; |
| 85 | } |
| 86 | |
| 87 | if (stream->isAllDataReceived()) { |
| 88 | ERRORF(r, "Failed to start incremental decode\n"); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | // Append some data. The size is arbitrary, but deliberately different from |
| 93 | // the buffer size used by SkPngCodec. |
| 94 | stream->addNewData(1000); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | while (true) { |
| 98 | const SkCodec::Result result = partialCodec->incrementalDecode(); |
| 99 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 100 | if (result == SkCodec::kSuccess) { |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 101 | break; |
| 102 | } |
| 103 | |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 104 | REPORTER_ASSERT(r, result == SkCodec::kIncompleteInput); |
| 105 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 106 | if (stream->isAllDataReceived()) { |
| 107 | ERRORF(r, "Failed to completely decode %s", name); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | // Append some data. The size is arbitrary, but deliberately different from |
| 112 | // the buffer size used by SkPngCodec. |
| 113 | stream->addNewData(1000); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | // compare to original |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 117 | compare_bitmaps(r, truth, incremental); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | DEF_TEST(Codec_partial, r) { |
Leon Scroggins III | 8323965 | 2017-04-21 13:47:12 -0400 | [diff] [blame^] | 121 | #if 0 |
| 122 | // FIXME (scroggo): SkPngCodec needs to use SkStreamBuffer in order to |
| 123 | // support incremental decoding. |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 124 | test_partial(r, "plane.png"); |
| 125 | test_partial(r, "plane_interlaced.png"); |
| 126 | test_partial(r, "yellow_rose.png"); |
| 127 | test_partial(r, "index8.png"); |
| 128 | test_partial(r, "color_wheel.png"); |
| 129 | test_partial(r, "mandrill_256.png"); |
| 130 | test_partial(r, "mandrill_32.png"); |
| 131 | test_partial(r, "arrow.png"); |
| 132 | test_partial(r, "randPixels.png"); |
| 133 | test_partial(r, "baby_tux.png"); |
Leon Scroggins III | 8323965 | 2017-04-21 13:47:12 -0400 | [diff] [blame^] | 134 | #endif |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 135 | test_partial(r, "box.gif"); |
Leon Scroggins III | 4993b95 | 2016-12-08 11:54:04 -0500 | [diff] [blame] | 136 | test_partial(r, "randPixels.gif", 215); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 137 | test_partial(r, "color_wheel.gif"); |
| 138 | } |
| 139 | |
Leon Scroggins III | e4ba105 | 2017-01-30 13:55:14 -0500 | [diff] [blame] | 140 | // Verify that when decoding an animated gif byte by byte we report the correct |
| 141 | // fRequiredFrame as soon as getFrameInfo reports the frame. |
| 142 | DEF_TEST(Codec_requiredFrame, r) { |
| 143 | auto path = "colorTables.gif"; |
| 144 | sk_sp<SkData> file = GetResourceAsData(path); |
| 145 | if (!file) { |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(file)); |
| 150 | if (!codec) { |
| 151 | ERRORF(r, "Failed to create codec from %s", path); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | auto frameInfo = codec->getFrameInfo(); |
| 156 | if (frameInfo.size() <= 1) { |
| 157 | ERRORF(r, "Test is uninteresting with 0 or 1 frames"); |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | HaltingStream* stream(nullptr); |
| 162 | std::unique_ptr<SkCodec> partialCodec(nullptr); |
| 163 | for (size_t i = 0; !partialCodec; i++) { |
| 164 | if (file->size() == i) { |
| 165 | ERRORF(r, "Should have created a partial codec for %s", path); |
| 166 | return; |
| 167 | } |
| 168 | stream = new HaltingStream(file, i); |
| 169 | partialCodec.reset(SkCodec::NewFromStream(stream)); |
| 170 | } |
| 171 | |
| 172 | std::vector<SkCodec::FrameInfo> partialInfo; |
| 173 | size_t frameToCompare = 0; |
| 174 | for (; stream->getLength() <= file->size(); stream->addNewData(1)) { |
| 175 | partialInfo = partialCodec->getFrameInfo(); |
| 176 | for (; frameToCompare < partialInfo.size(); frameToCompare++) { |
| 177 | REPORTER_ASSERT(r, partialInfo[frameToCompare].fRequiredFrame |
| 178 | == frameInfo[frameToCompare].fRequiredFrame); |
| 179 | } |
| 180 | |
| 181 | if (frameToCompare == frameInfo.size()) { |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 187 | DEF_TEST(Codec_partialAnim, r) { |
| 188 | auto path = "test640x479.gif"; |
Leon Scroggins III | e4ba105 | 2017-01-30 13:55:14 -0500 | [diff] [blame] | 189 | sk_sp<SkData> file = GetResourceAsData(path); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 190 | if (!file) { |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | // This stream will be owned by fullCodec, but we hang on to the pointer |
| 195 | // to determine frame offsets. |
| 196 | SkStream* stream = new SkMemoryStream(file); |
| 197 | std::unique_ptr<SkCodec> fullCodec(SkCodec::NewFromStream(stream)); |
| 198 | const auto info = standardize_info(fullCodec.get()); |
| 199 | |
| 200 | // frameByteCounts stores the number of bytes to decode a particular frame. |
| 201 | // - [0] is the number of bytes for the header |
| 202 | // - frames[i] requires frameByteCounts[i+1] bytes to decode |
| 203 | std::vector<size_t> frameByteCounts; |
| 204 | std::vector<SkBitmap> frames; |
| 205 | size_t lastOffset = 0; |
| 206 | for (size_t i = 0; true; i++) { |
| 207 | frameByteCounts.push_back(stream->getPosition() - lastOffset); |
| 208 | lastOffset = stream->getPosition(); |
| 209 | |
| 210 | SkBitmap frame; |
| 211 | frame.allocPixels(info); |
| 212 | |
| 213 | SkCodec::Options opts; |
| 214 | opts.fFrameIndex = i; |
| 215 | const SkCodec::Result result = fullCodec->getPixels(info, frame.getPixels(), |
| 216 | frame.rowBytes(), &opts, nullptr, nullptr); |
| 217 | |
Leon Scroggins III | 3fc97d7 | 2016-12-09 16:39:33 -0500 | [diff] [blame] | 218 | if (result == SkCodec::kIncompleteInput || result == SkCodec::kInvalidInput) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 219 | frameByteCounts.push_back(stream->getPosition() - lastOffset); |
| 220 | |
| 221 | // We need to distinguish between a partial frame and no more frames. |
| 222 | // getFrameInfo lets us do this, since it tells the number of frames |
| 223 | // not considering whether they are complete. |
| 224 | // FIXME: Should we use a different Result? |
| 225 | if (fullCodec->getFrameInfo().size() > i) { |
| 226 | // This is a partial frame. |
| 227 | frames.push_back(frame); |
| 228 | } |
| 229 | break; |
| 230 | } |
| 231 | |
| 232 | if (result != SkCodec::kSuccess) { |
| 233 | ERRORF(r, "Failed to decode frame %i from %s", i, path); |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | frames.push_back(frame); |
| 238 | } |
| 239 | |
| 240 | // Now decode frames partially, then completely, and compare to the original. |
| 241 | HaltingStream* haltingStream = new HaltingStream(file, frameByteCounts[0]); |
| 242 | std::unique_ptr<SkCodec> partialCodec(SkCodec::NewFromStream(haltingStream)); |
| 243 | if (!partialCodec) { |
| 244 | ERRORF(r, "Failed to create a partial codec from %s with %i bytes out of %i", |
| 245 | path, frameByteCounts[0], file->size()); |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | SkASSERT(frameByteCounts.size() > frames.size()); |
| 250 | for (size_t i = 0; i < frames.size(); i++) { |
| 251 | const size_t fullFrameBytes = frameByteCounts[i + 1]; |
| 252 | const size_t firstHalf = fullFrameBytes / 2; |
| 253 | const size_t secondHalf = fullFrameBytes - firstHalf; |
| 254 | |
| 255 | haltingStream->addNewData(firstHalf); |
Leon Scroggins III | 3639faa | 2016-12-08 11:38:58 -0500 | [diff] [blame] | 256 | auto frameInfo = partialCodec->getFrameInfo(); |
| 257 | REPORTER_ASSERT(r, frameInfo.size() == i + 1); |
| 258 | REPORTER_ASSERT(r, !frameInfo[i].fFullyReceived); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 259 | |
| 260 | SkBitmap frame; |
| 261 | frame.allocPixels(info); |
| 262 | |
| 263 | SkCodec::Options opts; |
| 264 | opts.fFrameIndex = i; |
| 265 | SkCodec::Result result = partialCodec->startIncrementalDecode(info, |
| 266 | frame.getPixels(), frame.rowBytes(), &opts); |
| 267 | if (result != SkCodec::kSuccess) { |
| 268 | ERRORF(r, "Failed to start incremental decode for %s on frame %i", |
| 269 | path, i); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | result = partialCodec->incrementalDecode(); |
| 274 | REPORTER_ASSERT(r, SkCodec::kIncompleteInput == result); |
| 275 | |
| 276 | haltingStream->addNewData(secondHalf); |
| 277 | result = partialCodec->incrementalDecode(); |
| 278 | REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
| 279 | |
Leon Scroggins III | 3639faa | 2016-12-08 11:38:58 -0500 | [diff] [blame] | 280 | frameInfo = partialCodec->getFrameInfo(); |
| 281 | REPORTER_ASSERT(r, frameInfo.size() == i + 1); |
| 282 | REPORTER_ASSERT(r, frameInfo[i].fFullyReceived); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 283 | compare_bitmaps(r, frames[i], frame); |
| 284 | } |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | // Test that calling getPixels when an incremental decode has been |
| 288 | // started (but not finished) makes the next call to incrementalDecode |
| 289 | // require a call to startIncrementalDecode. |
| 290 | static void test_interleaved(skiatest::Reporter* r, const char* name) { |
Leon Scroggins III | e4ba105 | 2017-01-30 13:55:14 -0500 | [diff] [blame] | 291 | sk_sp<SkData> file = GetResourceAsData(name); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 292 | if (!file) { |
| 293 | return; |
| 294 | } |
| 295 | const size_t halfSize = file->size() / 2; |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 296 | std::unique_ptr<SkCodec> partialCodec(SkCodec::NewFromStream( |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 297 | new HaltingStream(std::move(file), halfSize))); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 298 | if (!partialCodec) { |
| 299 | ERRORF(r, "Failed to create codec for %s", name); |
| 300 | return; |
| 301 | } |
| 302 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 303 | const SkImageInfo info = standardize_info(partialCodec.get()); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 304 | SkBitmap incremental; |
| 305 | incremental.allocPixels(info); |
| 306 | |
| 307 | const SkCodec::Result startResult = partialCodec->startIncrementalDecode(info, |
| 308 | incremental.getPixels(), incremental.rowBytes()); |
| 309 | if (startResult != SkCodec::kSuccess) { |
| 310 | ERRORF(r, "Failed to start incremental decode\n"); |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | SkCodec::Result result = partialCodec->incrementalDecode(); |
| 315 | REPORTER_ASSERT(r, result == SkCodec::kIncompleteInput); |
| 316 | |
| 317 | SkBitmap full; |
| 318 | full.allocPixels(info); |
| 319 | result = partialCodec->getPixels(info, full.getPixels(), full.rowBytes()); |
| 320 | REPORTER_ASSERT(r, result == SkCodec::kIncompleteInput); |
| 321 | |
| 322 | // Now incremental decode will fail |
| 323 | result = partialCodec->incrementalDecode(); |
| 324 | REPORTER_ASSERT(r, result == SkCodec::kInvalidParameters); |
| 325 | } |
| 326 | |
| 327 | DEF_TEST(Codec_rewind, r) { |
| 328 | test_interleaved(r, "plane.png"); |
| 329 | test_interleaved(r, "plane_interlaced.png"); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 330 | test_interleaved(r, "box.gif"); |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 331 | } |
Leon Scroggins III | 3fc97d7 | 2016-12-09 16:39:33 -0500 | [diff] [blame] | 332 | |
| 333 | // Modified version of the giflib logo, from |
| 334 | // http://giflib.sourceforge.net/whatsinagif/bits_and_bytes.html |
| 335 | // The global color map has been replaced with a local color map. |
| 336 | static unsigned char gNoGlobalColorMap[] = { |
| 337 | // Header |
| 338 | 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, |
| 339 | |
| 340 | // Logical screen descriptor |
| 341 | 0x0A, 0x00, 0x0A, 0x00, 0x11, 0x00, 0x00, |
| 342 | |
| 343 | // Image descriptor |
| 344 | 0x2C, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x0A, 0x00, 0x81, |
| 345 | |
| 346 | // Local color table |
| 347 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, |
| 348 | |
| 349 | // Image data |
| 350 | 0x02, 0x16, 0x8C, 0x2D, 0x99, 0x87, 0x2A, 0x1C, 0xDC, 0x33, 0xA0, 0x02, 0x75, |
| 351 | 0xEC, 0x95, 0xFA, 0xA8, 0xDE, 0x60, 0x8C, 0x04, 0x91, 0x4C, 0x01, 0x00, |
| 352 | |
| 353 | // Trailer |
| 354 | 0x3B, |
| 355 | }; |
| 356 | |
| 357 | // Test that a gif file truncated before its local color map behaves as expected. |
| 358 | DEF_TEST(Codec_GifPreMap, r) { |
| 359 | sk_sp<SkData> data = SkData::MakeWithoutCopy(gNoGlobalColorMap, sizeof(gNoGlobalColorMap)); |
| 360 | std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data)); |
| 361 | if (!codec) { |
| 362 | ERRORF(r, "failed to create codec"); |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | SkBitmap truth; |
| 367 | auto info = standardize_info(codec.get()); |
| 368 | truth.allocPixels(info); |
| 369 | |
| 370 | auto result = codec->getPixels(info, truth.getPixels(), truth.rowBytes()); |
| 371 | REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 372 | |
| 373 | // Truncate to 23 bytes, just before the color map. This should fail to decode. |
| 374 | codec.reset(SkCodec::NewFromData(SkData::MakeWithoutCopy(gNoGlobalColorMap, 23))); |
| 375 | REPORTER_ASSERT(r, codec); |
| 376 | if (codec) { |
| 377 | SkBitmap bm; |
| 378 | bm.allocPixels(info); |
| 379 | result = codec->getPixels(info, bm.getPixels(), bm.rowBytes()); |
| 380 | REPORTER_ASSERT(r, result == SkCodec::kInvalidInput); |
| 381 | } |
| 382 | |
| 383 | // Again, truncate to 23 bytes, this time for an incremental decode. We |
| 384 | // cannot start an incremental decode until we have more data. If we did, |
| 385 | // we would be using the wrong color table. |
| 386 | HaltingStream* stream = new HaltingStream(data, 23); |
| 387 | codec.reset(SkCodec::NewFromStream(stream)); |
| 388 | REPORTER_ASSERT(r, codec); |
| 389 | if (codec) { |
| 390 | SkBitmap bm; |
| 391 | bm.allocPixels(info); |
| 392 | result = codec->startIncrementalDecode(info, bm.getPixels(), bm.rowBytes()); |
| 393 | REPORTER_ASSERT(r, result == SkCodec::kIncompleteInput); |
| 394 | |
| 395 | stream->addNewData(data->size()); |
| 396 | result = codec->startIncrementalDecode(info, bm.getPixels(), bm.rowBytes()); |
| 397 | REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 398 | |
| 399 | result = codec->incrementalDecode(); |
| 400 | REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 401 | compare_bitmaps(r, truth, bm); |
| 402 | } |
| 403 | } |