| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 #include "skia/ext/image_operations.h" | 7 #include "skia/ext/image_operations.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
| 10 #include "third_party/skia/include/core/SkColorPriv.h" | 10 #include "third_party/skia/include/core/SkColorPriv.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 197 |
| 198 SkBitmap src; | 198 SkBitmap src; |
| 199 FillDataToBitmap(src_w, src_h, &src); | 199 FillDataToBitmap(src_w, src_h, &src); |
| 200 | 200 |
| 201 // Generate alpha mask | 201 // Generate alpha mask |
| 202 SkBitmap alpha; | 202 SkBitmap alpha; |
| 203 alpha.setConfig(SkBitmap::kARGB_8888_Config, src_w, src_h); | 203 alpha.setConfig(SkBitmap::kARGB_8888_Config, src_w, src_h); |
| 204 alpha.allocPixels(); | 204 alpha.allocPixels(); |
| 205 for (int y = 0, i = 0; y < src_h; y++) { | 205 for (int y = 0, i = 0; y < src_h; y++) { |
| 206 for (int x = 0; x < src_w; x++) { | 206 for (int x = 0; x < src_w; x++) { |
| 207 *alpha.getAddr32(x, y) = SkColorSetARGB(i + 128 % 255, | 207 *alpha.getAddr32(x, y) = SkColorSetARGB((i + 128) % 255, |
| 208 i + 128 % 255, | 208 (i + 128) % 255, |
| 209 i + 64 % 255, | 209 (i + 64) % 255, |
| 210 i + 0 % 255); | 210 (i + 0) % 255); |
| 211 i++; | 211 i++; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 SkBitmap masked = skia::ImageOperations::CreateMaskedBitmap(src, alpha); | 215 SkBitmap masked = skia::ImageOperations::CreateMaskedBitmap(src, alpha); |
| 216 | 216 |
| 217 SkAutoLockPixels src_lock(src); | 217 SkAutoLockPixels src_lock(src); |
| 218 SkAutoLockPixels alpha_lock(alpha); | 218 SkAutoLockPixels alpha_lock(alpha); |
| 219 SkAutoLockPixels masked_lock(masked); | 219 SkAutoLockPixels masked_lock(masked); |
| 220 for (int y = 0; y < src_h; y++) { | 220 for (int y = 0; y < src_h; y++) { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 // Test multiple steps of downsampling. | 509 // Test multiple steps of downsampling. |
| 510 SkBitmap large; | 510 SkBitmap large; |
| 511 large.setConfig(SkBitmap::kARGB_8888_Config, 100, 43); | 511 large.setConfig(SkBitmap::kARGB_8888_Config, 100, 43); |
| 512 large.allocPixels(); | 512 large.allocPixels(); |
| 513 result = skia::ImageOperations::DownsampleByTwoUntilSize(large, 6, 6); | 513 result = skia::ImageOperations::DownsampleByTwoUntilSize(large, 6, 6); |
| 514 | 514 |
| 515 // The result should be divided in half 100x43 -> 50x22 -> 25x11 | 515 // The result should be divided in half 100x43 -> 50x22 -> 25x11 |
| 516 EXPECT_EQ(25, result.width()); | 516 EXPECT_EQ(25, result.width()); |
| 517 EXPECT_EQ(11, result.height()); | 517 EXPECT_EQ(11, result.height()); |
| 518 } | 518 } |
| OLD | NEW |