OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Resources.h" | 8 #include "Resources.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 REPORTER_ASSERT(r, codec->skipScanlines(1) | 152 REPORTER_ASSERT(r, codec->skipScanlines(1) |
153 == SkCodec::kScanlineDecodingNotStarted); | 153 == SkCodec::kScanlineDecodingNotStarted); |
154 | 154 |
155 const SkCodec::Result startResult = codec->startScanlineDecode(info); | 155 const SkCodec::Result startResult = codec->startScanlineDecode(info); |
156 if (supportsScanlineDecoding) { | 156 if (supportsScanlineDecoding) { |
157 bm.eraseColor(SK_ColorYELLOW); | 157 bm.eraseColor(SK_ColorYELLOW); |
158 | 158 |
159 REPORTER_ASSERT(r, startResult == SkCodec::kSuccess); | 159 REPORTER_ASSERT(r, startResult == SkCodec::kSuccess); |
160 | 160 |
161 for (int y = 0; y < info.height(); y++) { | 161 for (int y = 0; y < info.height(); y++) { |
162 result = codec->getScanlines(bm.getAddr(0, y), 1, 0); | 162 const uint32_t lines = codec->getScanlines(bm.getAddr(0, y), 1, 0); |
163 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 163 REPORTER_ASSERT(r, 1 == lines); |
164 } | 164 } |
165 // verify that scanline decoding gives the same result. | 165 // verify that scanline decoding gives the same result. |
166 if (SkCodec::kTopDown_SkScanlineOrder == codec->getScanlineOrder()) { | 166 if (SkCodec::kTopDown_SkScanlineOrder == codec->getScanlineOrder()) { |
167 compare_to_good_digest(r, digest, bm); | 167 compare_to_good_digest(r, digest, bm); |
168 } | 168 } |
169 | 169 |
170 // Cannot continue to decode scanlines beyond the end | 170 // Cannot continue to decode scanlines beyond the end |
171 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) | 171 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) |
172 == SkCodec::kInvalidParameters); | 172 == SkCodec::kInvalidParameters); |
173 | 173 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 SkTDivMod(height, numStripes, &stripeHeight, &remainingLines); | 314 SkTDivMod(height, numStripes, &stripeHeight, &remainingLines); |
315 | 315 |
316 bm.eraseColor(SK_ColorYELLOW); | 316 bm.eraseColor(SK_ColorYELLOW); |
317 | 317 |
318 result = codec->startScanlineDecode(info); | 318 result = codec->startScanlineDecode(info); |
319 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 319 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
320 | 320 |
321 // Odd stripes | 321 // Odd stripes |
322 for (int i = 1; i < numStripes; i += 2) { | 322 for (int i = 1; i < numStripes; i += 2) { |
323 // Skip the even stripes | 323 // Skip the even stripes |
324 result = codec->skipScanlines(stripeHeight); | 324 bool skipResult = codec->skipScanlines(stripeHeight); |
325 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 325 REPORTER_ASSERT(r, skipResult); |
326 | 326 |
327 result = codec->getScanlines(bm.getAddr(0, i * stripeHeight), stripeHeig
ht, | 327 int linesDecoded = codec->getScanlines(bm.getAddr(0, i * stripeHeight),
stripeHeight, |
328 bm.rowBytes()); | 328 bm.rowBytes()); |
329 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 329 REPORTER_ASSERT(r, linesDecoded == stripeHeight); |
330 } | 330 } |
331 | 331 |
332 // Even stripes | 332 // Even stripes |
333 result = codec->startScanlineDecode(info); | 333 result = codec->startScanlineDecode(info); |
334 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 334 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
335 | 335 |
336 for (int i = 0; i < numStripes; i += 2) { | 336 for (int i = 0; i < numStripes; i += 2) { |
337 result = codec->getScanlines(bm.getAddr(0, i * stripeHeight), stripeHeig
ht, | 337 int linesDecoded = codec->getScanlines(bm.getAddr(0, i * stripeHeight),
stripeHeight, |
338 bm.rowBytes()); | 338 bm.rowBytes()); |
339 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 339 REPORTER_ASSERT(r, linesDecoded == stripeHeight); |
340 | 340 |
341 // Skip the odd stripes | 341 // Skip the odd stripes |
342 if (i + 1 < numStripes) { | 342 if (i + 1 < numStripes) { |
343 result = codec->skipScanlines(stripeHeight); | 343 bool skipResult = codec->skipScanlines(stripeHeight); |
344 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 344 REPORTER_ASSERT(r, skipResult); |
345 } | 345 } |
346 } | 346 } |
347 | 347 |
348 // Remainder at the end | 348 // Remainder at the end |
349 if (remainingLines > 0) { | 349 if (remainingLines > 0) { |
350 result = codec->startScanlineDecode(info); | 350 result = codec->startScanlineDecode(info); |
351 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 351 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
352 | 352 |
353 result = codec->skipScanlines(height - remainingLines); | 353 bool skipResult = codec->skipScanlines(height - remainingLines); |
354 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 354 REPORTER_ASSERT(r, skipResult); |
355 | 355 |
356 result = codec->getScanlines(bm.getAddr(0, height - remainingLines), | 356 int linesDecoded = codec->getScanlines(bm.getAddr(0, height - remainingL
ines), |
357 remainingLines, bm.rowBytes()); | 357 remainingLines, bm.rowBytes()); |
358 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 358 REPORTER_ASSERT(r, linesDecoded == height - remainingLines); |
359 } | 359 } |
360 | 360 |
361 compare_to_good_digest(r, digest, bm); | 361 compare_to_good_digest(r, digest, bm); |
362 } | 362 } |
363 | 363 |
364 static void test_invalid_stream(skiatest::Reporter* r, const void* stream, size_
t len) { | 364 static void test_invalid_stream(skiatest::Reporter* r, const void* stream, size_
t len) { |
365 SkCodec* codec = SkCodec::NewFromStream(new SkMemoryStream(stream, len, fals
e)); | 365 SkCodec* codec = SkCodec::NewFromStream(new SkMemoryStream(stream, len, fals
e)); |
366 // We should not have gotten a codec. Bots should catch us if we leaked anyt
hing. | 366 // We should not have gotten a codec. Bots should catch us if we leaked anyt
hing. |
367 REPORTER_ASSERT(r, !codec); | 367 REPORTER_ASSERT(r, !codec); |
368 } | 368 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); | 499 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); |
500 result = decoder->startScanlineDecode( | 500 result = decoder->startScanlineDecode( |
501 decoder->getInfo().makeColorType(kIndex_8_SkColorType)); | 501 decoder->getInfo().makeColorType(kIndex_8_SkColorType)); |
502 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); | 502 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); |
503 } | 503 } |
504 | 504 |
505 DEF_TEST(Codec_Params, r) { | 505 DEF_TEST(Codec_Params, r) { |
506 test_invalid_parameters(r, "index8.png"); | 506 test_invalid_parameters(r, "index8.png"); |
507 test_invalid_parameters(r, "mandrill.wbmp"); | 507 test_invalid_parameters(r, "mandrill.wbmp"); |
508 } | 508 } |
OLD | NEW |