Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkColor.h" | 10 #include "SkColor.h" |
| 11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 12 #include "SkData.h" | 12 #include "SkData.h" |
| 13 #include "SkDecodingImageGenerator.h" | 13 #include "SkDecodingImageGenerator.h" |
| 14 #include "SkDiscardableMemoryPool.h" | 14 #include "SkDiscardableMemoryPool.h" |
| 15 #include "SkForceLinking.h" | 15 #include "SkForceLinking.h" |
| 16 #include "SkGradientShader.h" | 16 #include "SkGradientShader.h" |
| 17 #include "SkImageDecoder.h" | 17 #include "SkImageDecoder.h" |
| 18 #include "SkImageEncoder.h" | 18 #include "SkImageEncoder.h" |
| 19 #include "SkImageGenerator.h" | 19 #include "SkImageGeneratorPriv.h" |
| 20 #include "SkImagePriv.h" | 20 #include "SkImagePriv.h" |
| 21 #include "SkOSFile.h" | 21 #include "SkOSFile.h" |
| 22 #include "SkPoint.h" | 22 #include "SkPoint.h" |
| 23 #include "SkShader.h" | 23 #include "SkShader.h" |
| 24 #include "SkStream.h" | 24 #include "SkStream.h" |
| 25 #include "SkString.h" | 25 #include "SkString.h" |
| 26 #include "Test.h" | 26 #include "Test.h" |
| 27 | 27 |
| 28 __SK_FORCE_IMAGE_DECODER_LINKING; | 28 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 29 | 29 |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 0xa7, 0xf3, 0xa3, 0xbd, 0x83, 0x8b, 0x2a, 0xc8, 0x58, 0xf5, 0xac, 0x80, | 448 0xa7, 0xf3, 0xa3, 0xbd, 0x83, 0x8b, 0x2a, 0xc8, 0x58, 0xf5, 0xac, 0x80, |
| 449 0xe3, 0xfe, 0x66, 0xa4, 0x7c, 0x1b, 0x6c, 0xd1, 0xa9, 0xd8, 0x14, 0xd0, | 449 0xe3, 0xfe, 0x66, 0xa4, 0x7c, 0x1b, 0x6c, 0xd1, 0xa9, 0xd8, 0x14, 0xd0, |
| 450 0xc5, 0xb5, 0x39, 0x71, 0x97, 0x19, 0x19, 0x1b | 450 0xc5, 0xb5, 0x39, 0x71, 0x97, 0x19, 0x19, 0x1b |
| 451 }; | 451 }; |
| 452 SkAutoDataUnref encoded(SkData::NewWithCopy(encodedWebP, | 452 SkAutoDataUnref encoded(SkData::NewWithCopy(encodedWebP, |
| 453 sizeof(encodedWebP))); | 453 sizeof(encodedWebP))); |
| 454 SkBitmap bm; | 454 SkBitmap bm; |
| 455 | 455 |
| 456 bool success = SkInstallDiscardablePixelRef( | 456 bool success = SkInstallDiscardablePixelRef( |
| 457 SkDecodingImageGenerator::Create(encoded, | 457 SkDecodingImageGenerator::Create(encoded, |
| 458 SkDecodingImageGenerator::Options()), &bm, NULL); | 458 SkDecodingImageGenerator::Options()), &bm); |
| 459 | 459 |
| 460 REPORTER_ASSERT(reporter, success); | 460 REPORTER_ASSERT(reporter, success); |
| 461 if (!success) { | 461 if (!success) { |
| 462 return; | 462 return; |
| 463 } | 463 } |
| 464 SkAutoLockPixels alp(bm); | 464 SkAutoLockPixels alp(bm); |
| 465 | 465 |
| 466 bool rightSize = ((kExpectedWidth == bm.width()) | 466 bool rightSize = ((kExpectedWidth == bm.width()) |
| 467 && (kExpectedHeight == bm.height())); | 467 && (kExpectedHeight == bm.height())); |
| 468 REPORTER_ASSERT(reporter, rightSize); | 468 REPORTER_ASSERT(reporter, rightSize); |
| 469 if (rightSize) { | 469 if (rightSize) { |
| 470 bool error = false; | 470 bool error = false; |
| 471 const SkColor* correctPixel = kExpectedPixels; | 471 const SkColor* correctPixel = kExpectedPixels; |
| 472 for (int y = 0; y < bm.height(); ++y) { | 472 for (int y = 0; y < bm.height(); ++y) { |
| 473 for (int x = 0; x < bm.width(); ++x) { | 473 for (int x = 0; x < bm.width(); ++x) { |
| 474 error |= (*correctPixel != bm.getColor(x, y)); | 474 error |= (*correctPixel != bm.getColor(x, y)); |
| 475 ++correctPixel; | 475 ++correctPixel; |
| 476 } | 476 } |
| 477 } | 477 } |
| 478 REPORTER_ASSERT(reporter, !error); | 478 REPORTER_ASSERT(reporter, !error); |
| 479 } | 479 } |
| 480 } | 480 } |
| 481 | 481 |
| 482 //////////////////////////////////////////////////////////////////////////////// | 482 //////////////////////////////////////////////////////////////////////////////// |
| 483 | 483 |
| 484 // example of how Android will do this inside their BitmapFactory | 484 // example of how Android will do this inside their BitmapFactory |
| 485 static SkPixelRef* install_pixel_ref(SkBitmap* bitmap, | 485 static SkPixelRef* install_pixel_ref(SkBitmap* bitmap, |
|
scroggo
2014/05/23 19:30:30
This function shows how Android is supposed to rep
scroggo
2014/05/23 19:57:12
Hal has a fix in https://codereview.chromium.org/2
hal.canary
2014/05/27 13:33:53
Which has landed, so you can rebase.
| |
| 486 SkStreamRewindable* stream, | 486 SkStreamRewindable* stream, |
| 487 int sampleSize, bool ditherImage) { | 487 int sampleSize, bool ditherImage) { |
| 488 SkASSERT(bitmap != NULL); | 488 SkASSERT(bitmap != NULL); |
| 489 SkASSERT(stream != NULL); | 489 SkASSERT(stream != NULL); |
| 490 SkASSERT(stream->rewind()); | 490 SkASSERT(stream->rewind()); |
| 491 SkASSERT(stream->unique()); | 491 SkASSERT(stream->unique()); |
| 492 SkColorType colorType = bitmap->colorType(); | 492 SkColorType colorType = bitmap->colorType(); |
| 493 SkDecodingImageGenerator::Options opts(sampleSize, ditherImage, colorType); | 493 SkDecodingImageGenerator::Options opts(sampleSize, ditherImage, colorType); |
| 494 SkAutoTDelete<SkImageGenerator> gen( | 494 SkAutoTDelete<SkImageGenerator> gen( |
| 495 SkDecodingImageGenerator::Create(stream, opts)); | 495 SkDecodingImageGenerator::Create(stream, opts)); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 SkData* encodedData, | 587 SkData* encodedData, |
| 588 bool useData, | 588 bool useData, |
| 589 const SkString& path) { | 589 const SkString& path) { |
| 590 SkBitmap bm; | 590 SkBitmap bm; |
| 591 bool success = false; | 591 bool success = false; |
| 592 if (useData) { | 592 if (useData) { |
| 593 if (NULL == encodedData) { | 593 if (NULL == encodedData) { |
| 594 return; | 594 return; |
| 595 } | 595 } |
| 596 success = SkInstallDiscardablePixelRef( | 596 success = SkInstallDiscardablePixelRef( |
| 597 SkDecodingImageGenerator::Create(encodedData, opts), &bm, NULL); | 597 SkDecodingImageGenerator::Create(encodedData, opts), &bm); |
| 598 } else { | 598 } else { |
| 599 if (NULL == encodedStream) { | 599 if (NULL == encodedStream) { |
| 600 return; | 600 return; |
| 601 } | 601 } |
| 602 success = SkInstallDiscardablePixelRef( | 602 success = SkInstallDiscardablePixelRef( |
| 603 SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts), | 603 SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts), &bm); |
| 604 &bm, NULL); | |
| 605 } | 604 } |
| 606 if (!success) { | 605 if (!success) { |
| 607 if (opts.fUseRequestedColorType | 606 if (opts.fUseRequestedColorType |
| 608 && (kARGB_4444_SkColorType == opts.fRequestedColorType)) { | 607 && (kARGB_4444_SkColorType == opts.fRequestedColorType)) { |
| 609 return; // Ignore known conversion inabilities. | 608 return; // Ignore known conversion inabilities. |
| 610 } | 609 } |
| 611 // If we get here, it's a failure and we will need more | 610 // If we get here, it's a failure and we will need more |
| 612 // information about why it failed. | 611 // information about why it failed. |
| 613 ERRORF(reporter, "Bounds decode failed [sampleSize=%d dither=%s " | 612 ERRORF(reporter, "Bounds decode failed [sampleSize=%d dither=%s " |
| 614 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage), | 613 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage), |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 } | 729 } |
| 731 SkDecodingImageGenerator::Options options(scaleList[i], | 730 SkDecodingImageGenerator::Options options(scaleList[i], |
| 732 ditherList[j]); | 731 ditherList[j]); |
| 733 test_options(reporter, options, encodedStream, encodedData, | 732 test_options(reporter, options, encodedStream, encodedData, |
| 734 useDataList[m], path); | 733 useDataList[m], path); |
| 735 } | 734 } |
| 736 } | 735 } |
| 737 } | 736 } |
| 738 } | 737 } |
| 739 } | 738 } |
| OLD | NEW |