Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: skia/ext/image_operations_unittest.cc

Issue 159381: Attempt to fix the ImageOperations::CreateMaskedBitmap UMR by bringing the un... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « skia/ext/image_operations.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 TEST(ImageOperations, CreateMaskedBitmap) { 195 TEST(ImageOperations, CreateMaskedBitmap) {
196 int src_w = 16, src_h = 16; 196 int src_w = 16, src_h = 16;
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 205 for (int y = 0, i = 0; y < src_h; y++) {
206 unsigned char* src_data = 206 for (int x = 0; x < src_w; x++) {
207 reinterpret_cast<unsigned char*>(alpha.getAddr32(0, 0)); 207 *alpha.getAddr32(x, y) = SkColorSetARGB(i + 128 % 255,
208 for (int i = 0; i < src_w * src_h; i++) { 208 i + 128 % 255,
209 src_data[i * 4] = SkColorSetARGB(i + 128 % 255, 209 i + 64 % 255,
210 i + 128 % 255, 210 i + 0 % 255);
211 i + 64 % 255, 211 i++;
212 i + 0 % 255); 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 masked_lock(masked); 219 SkAutoLockPixels masked_lock(masked);
219 for (int y = 0; y < src_h; y++) { 220 for (int y = 0; y < src_h; y++) {
220 for (int x = 0; x < src_w; x++) { 221 for (int x = 0; x < src_w; x++) {
221 // Test that the alpha is equal. 222 // Test that the alpha is equal.
222 SkColor src_pixel = SkUnPreMultiply::PMColorToColor(*src.getAddr32(x, y)); 223 SkColor src_pixel = SkUnPreMultiply::PMColorToColor(*src.getAddr32(x, y));
223 SkColor alpha_pixel = 224 SkColor alpha_pixel =
224 SkUnPreMultiply::PMColorToColor(*alpha.getAddr32(x, y)); 225 SkUnPreMultiply::PMColorToColor(*alpha.getAddr32(x, y));
225 SkColor masked_pixel = *masked.getAddr32(x, y); 226 SkColor masked_pixel = *masked.getAddr32(x, y);
226 227
227 int alpha_value = SkAlphaMul(SkColorGetA(src_pixel), 228 int alpha_value = SkAlphaMul(SkColorGetA(src_pixel),
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 // Test multiple steps of downsampling. 509 // Test multiple steps of downsampling.
509 SkBitmap large; 510 SkBitmap large;
510 large.setConfig(SkBitmap::kARGB_8888_Config, 100, 43); 511 large.setConfig(SkBitmap::kARGB_8888_Config, 100, 43);
511 large.allocPixels(); 512 large.allocPixels();
512 result = skia::ImageOperations::DownsampleByTwoUntilSize(large, 6, 6); 513 result = skia::ImageOperations::DownsampleByTwoUntilSize(large, 6, 6);
513 514
514 // The result should be divided in half 100x43 -> 50x22 -> 25x11 515 // The result should be divided in half 100x43 -> 50x22 -> 25x11
515 EXPECT_EQ(25, result.width()); 516 EXPECT_EQ(25, result.width());
516 EXPECT_EQ(11, result.height()); 517 EXPECT_EQ(11, result.height());
517 } 518 }
OLDNEW
« no previous file with comments | « skia/ext/image_operations.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698