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 "SkData.h" | 10 #include "SkData.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 canvas.drawRectCoords(0, 0, SkIntToScalar(W/2), | 31 canvas.drawRectCoords(0, 0, SkIntToScalar(W/2), |
32 SkIntToScalar(H/2), paint); | 32 SkIntToScalar(H/2), paint); |
33 paint.setColor(SK_ColorWHITE); | 33 paint.setColor(SK_ColorWHITE); |
34 canvas.drawRectCoords(SkIntToScalar(W/2), SkIntToScalar(H/2), | 34 canvas.drawRectCoords(SkIntToScalar(W/2), SkIntToScalar(H/2), |
35 SkIntToScalar(W), SkIntToScalar(H), paint); | 35 SkIntToScalar(W), SkIntToScalar(H), paint); |
36 } | 36 } |
37 | 37 |
38 /** | 38 /** |
39 * encode this bitmap into some data via SkImageEncoder | 39 * encode this bitmap into some data via SkImageEncoder |
40 */ | 40 */ |
41 static SkData* create_data_from_bitmap(const SkBitmap& bm, | 41 static sk_sp<SkData> create_data_from_bitmap(const SkBitmap& bm, SkImageEncoder:
:Type type) { |
42 SkImageEncoder::Type type) { | |
43 SkDynamicMemoryWStream stream; | 42 SkDynamicMemoryWStream stream; |
44 if (SkImageEncoder::EncodeStream(&stream, bm, type, 100)) { | 43 if (SkImageEncoder::EncodeStream(&stream, bm, type, 100)) { |
45 return stream.copyToData(); | 44 return stream.detachAsData(); |
46 } | 45 } |
47 return nullptr; | 46 return nullptr; |
48 } | 47 } |
49 | 48 |
50 //////////////////////////////////////////////////////////////////////////////// | 49 //////////////////////////////////////////////////////////////////////////////// |
51 | 50 |
52 static void compare_bitmaps(skiatest::Reporter* reporter, | 51 static void compare_bitmaps(skiatest::Reporter* reporter, |
53 const SkBitmap& b1, const SkBitmap& b2, | 52 const SkBitmap& b1, const SkBitmap& b2, |
54 bool pixelPerfect = true) { | 53 bool pixelPerfect = true) { |
55 REPORTER_ASSERT(reporter, b1.empty() == b2.empty()); | 54 REPORTER_ASSERT(reporter, b1.empty() == b2.empty()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 if (original.empty() || original.isNull()) { | 99 if (original.empty() || original.isNull()) { |
101 return; | 100 return; |
102 } | 101 } |
103 static const SkImageEncoder::Type types[] = { | 102 static const SkImageEncoder::Type types[] = { |
104 SkImageEncoder::kPNG_Type, | 103 SkImageEncoder::kPNG_Type, |
105 SkImageEncoder::kJPEG_Type, | 104 SkImageEncoder::kJPEG_Type, |
106 SkImageEncoder::kWEBP_Type | 105 SkImageEncoder::kWEBP_Type |
107 }; | 106 }; |
108 for (size_t i = 0; i < SK_ARRAY_COUNT(types); i++) { | 107 for (size_t i = 0; i < SK_ARRAY_COUNT(types); i++) { |
109 SkImageEncoder::Type type = types[i]; | 108 SkImageEncoder::Type type = types[i]; |
110 sk_sp<SkData> encoded(create_data_from_bitmap(original, type)); | 109 sk_sp<SkData> encoded = create_data_from_bitmap(original, type); |
111 REPORTER_ASSERT(reporter, encoded.get() != nullptr); | 110 REPORTER_ASSERT(reporter, encoded.get() != nullptr); |
112 if (nullptr == encoded.get()) { | 111 if (nullptr == encoded.get()) { |
113 continue; | 112 continue; |
114 } | 113 } |
115 SkBitmap lazy; | 114 SkBitmap lazy; |
116 bool installSuccess = install(encoded.get(), &lazy); | 115 bool installSuccess = install(encoded.get(), &lazy); |
117 REPORTER_ASSERT(reporter, installSuccess); | 116 REPORTER_ASSERT(reporter, installSuccess); |
118 if (!installSuccess) { | 117 if (!installSuccess) { |
119 continue; | 118 continue; |
120 } | 119 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 if (TestImageGenerator::kSucceedGetPixels_TestType == test) { | 338 if (TestImageGenerator::kSucceedGetPixels_TestType == test) { |
340 REPORTER_ASSERT( | 339 REPORTER_ASSERT( |
341 r, TestImageGenerator::Color() == bitmap.getColor(0, 0)); | 340 r, TestImageGenerator::Color() == bitmap.getColor(0, 0)); |
342 } | 341 } |
343 else { | 342 else { |
344 REPORTER_ASSERT(r, kDefaultColor == bitmap.getColor(0, 0)); | 343 REPORTER_ASSERT(r, kDefaultColor == bitmap.getColor(0, 0)); |
345 } | 344 } |
346 } | 345 } |
347 } | 346 } |
348 } | 347 } |
OLD | NEW |