| 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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 // Makes the bitmap 50% the size as the original using a box filter. This is | 61 // Makes the bitmap 50% the size as the original using a box filter. This is |
| 62 // an easy operation that we can check the results for manually. | 62 // an easy operation that we can check the results for manually. |
| 63 TEST(ImageOperations, Halve) { | 63 TEST(ImageOperations, Halve) { |
| 64 // Make our source bitmap. | 64 // Make our source bitmap. |
| 65 int src_w = 30, src_h = 38; | 65 int src_w = 30, src_h = 38; |
| 66 SkBitmap src; | 66 SkBitmap src; |
| 67 FillDataToBitmap(src_w, src_h, &src); | 67 FillDataToBitmap(src_w, src_h, &src); |
| 68 | 68 |
| 69 // Do a halving of the full bitmap. | 69 // Do a halving of the full bitmap. |
| 70 SkBitmap actual_results = gfx::ImageOperations::Resize( | 70 SkBitmap actual_results = skia::ImageOperations::Resize( |
| 71 src, gfx::ImageOperations::RESIZE_BOX, gfx::Size(src_w / 2, src_h / 2)); | 71 src, skia::ImageOperations::RESIZE_BOX, src_w / 2, src_h / 2); |
| 72 ASSERT_EQ(src_w / 2, actual_results.width()); | 72 ASSERT_EQ(src_w / 2, actual_results.width()); |
| 73 ASSERT_EQ(src_h / 2, actual_results.height()); | 73 ASSERT_EQ(src_h / 2, actual_results.height()); |
| 74 | 74 |
| 75 // Compute the expected values & compare. | 75 // Compute the expected values & compare. |
| 76 SkAutoLockPixels lock(actual_results); | 76 SkAutoLockPixels lock(actual_results); |
| 77 for (int y = 0; y < actual_results.height(); y++) { | 77 for (int y = 0; y < actual_results.height(); y++) { |
| 78 for (int x = 0; x < actual_results.width(); x++) { | 78 for (int x = 0; x < actual_results.width(); x++) { |
| 79 int first_x = std::max(0, x * 2 - 1); | 79 int first_x = std::max(0, x * 2 - 1); |
| 80 int last_x = std::min(src_w - 1, x * 2); | 80 int last_x = std::min(src_w - 1, x * 2); |
| 81 | 81 |
| 82 int first_y = std::max(0, y * 2 - 1); | 82 int first_y = std::max(0, y * 2 - 1); |
| 83 int last_y = std::min(src_h - 1, y * 2); | 83 int last_y = std::min(src_h - 1, y * 2); |
| 84 | 84 |
| 85 uint32_t expected_color = AveragePixel(src, | 85 uint32_t expected_color = AveragePixel(src, |
| 86 first_x, last_x, first_y, last_y); | 86 first_x, last_x, first_y, last_y); |
| 87 EXPECT_TRUE(ColorsClose(expected_color, *actual_results.getAddr32(x, y))); | 87 EXPECT_TRUE(ColorsClose(expected_color, *actual_results.getAddr32(x, y))); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 TEST(ImageOperations, HalveSubset) { | 92 TEST(ImageOperations, HalveSubset) { |
| 93 // Make our source bitmap. | 93 // Make our source bitmap. |
| 94 int src_w = 16, src_h = 34; | 94 int src_w = 16, src_h = 34; |
| 95 SkBitmap src; | 95 SkBitmap src; |
| 96 FillDataToBitmap(src_w, src_h, &src); | 96 FillDataToBitmap(src_w, src_h, &src); |
| 97 | 97 |
| 98 // Do a halving of the full bitmap. | 98 // Do a halving of the full bitmap. |
| 99 SkBitmap full_results = gfx::ImageOperations::Resize( | 99 SkBitmap full_results = skia::ImageOperations::Resize( |
| 100 src, gfx::ImageOperations::RESIZE_BOX, gfx::Size(src_w / 2, src_h / 2)); | 100 src, skia::ImageOperations::RESIZE_BOX, src_w / 2, src_h / 2); |
| 101 ASSERT_EQ(src_w / 2, full_results.width()); | 101 ASSERT_EQ(src_w / 2, full_results.width()); |
| 102 ASSERT_EQ(src_h / 2, full_results.height()); | 102 ASSERT_EQ(src_h / 2, full_results.height()); |
| 103 | 103 |
| 104 // Now do a halving of a a subset, recall the destination subset is in the | 104 // Now do a halving of a a subset, recall the destination subset is in the |
| 105 // destination coordinate system (max = half of the original image size). | 105 // destination coordinate system (max = half of the original image size). |
| 106 gfx::Rect subset_rect(2, 3, 3, 6); | 106 gfx::Rect subset_rect(2, 3, 3, 6); |
| 107 SkBitmap subset_results = gfx::ImageOperations::Resize( | 107 SkBitmap subset_results = skia::ImageOperations::Resize( |
| 108 src, gfx::ImageOperations::RESIZE_BOX, | 108 src, skia::ImageOperations::RESIZE_BOX, |
| 109 gfx::Size(src_w / 2, src_h / 2), subset_rect); | 109 src_w / 2, src_h / 2, subset_rect); |
| 110 ASSERT_EQ(subset_rect.width(), subset_results.width()); | 110 ASSERT_EQ(subset_rect.width(), subset_results.width()); |
| 111 ASSERT_EQ(subset_rect.height(), subset_results.height()); | 111 ASSERT_EQ(subset_rect.height(), subset_results.height()); |
| 112 | 112 |
| 113 // The computed subset and the corresponding subset of the original image | 113 // The computed subset and the corresponding subset of the original image |
| 114 // should be the same. | 114 // should be the same. |
| 115 SkAutoLockPixels full_lock(full_results); | 115 SkAutoLockPixels full_lock(full_results); |
| 116 SkAutoLockPixels subset_lock(subset_results); | 116 SkAutoLockPixels subset_lock(subset_results); |
| 117 for (int y = 0; y < subset_rect.height(); y++) { | 117 for (int y = 0; y < subset_rect.height(); y++) { |
| 118 for (int x = 0; x < subset_rect.width(); x++) { | 118 for (int x = 0; x < subset_rect.width(); x++) { |
| 119 ASSERT_EQ( | 119 ASSERT_EQ( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 139 | 139 |
| 140 SkAutoLockPixels src_lock(src); | 140 SkAutoLockPixels src_lock(src); |
| 141 SkAutoLockPixels results_lock(results); | 141 SkAutoLockPixels results_lock(results); |
| 142 for (int y = 0; y < src_h; y++) { | 142 for (int y = 0; y < src_h; y++) { |
| 143 for (int x = 0; x < src_w; x++) { | 143 for (int x = 0; x < src_w; x++) { |
| 144 EXPECT_EQ(*src.getAddr32(x, y), *results.getAddr32(x, y)); | 144 EXPECT_EQ(*src.getAddr32(x, y), *results.getAddr32(x, y)); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| OLD | NEW |