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

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

Issue 160241: Merge 21606 - Our masker didn't account for the source image also having alph... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/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')
Property Changes:
Modified: svn:mergeinfo
Merged /trunk/src/skia/ext/image_operations_unittest.cc:r21606
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/SkColorPriv.h" 10 #include "third_party/skia/include/core/SkColorPriv.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 11 #include "third_party/skia/include/core/SkUnPreMultiply.h"
11 12
12 namespace { 13 namespace {
13 14
14 // Computes the average pixel value for the given range, inclusive. 15 // Computes the average pixel value for the given range, inclusive.
15 uint32_t AveragePixel(const SkBitmap& bmp, 16 uint32_t AveragePixel(const SkBitmap& bmp,
16 int x_min, int x_max, 17 int x_min, int x_max,
17 int y_min, int y_max) { 18 int y_min, int y_max) {
18 float accum[4] = {0, 0, 0, 0}; 19 float accum[4] = {0, 0, 0, 0};
19 int count = 0; 20 int count = 0;
20 for (int y = y_min; y <= y_max; y++) { 21 for (int y = y_min; y <= y_max; y++) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 i + 0 % 255); 212 i + 0 % 255);
212 } 213 }
213 214
214 SkBitmap masked = skia::ImageOperations::CreateMaskedBitmap(src, alpha); 215 SkBitmap masked = skia::ImageOperations::CreateMaskedBitmap(src, alpha);
215 216
216 SkAutoLockPixels src_lock(src); 217 SkAutoLockPixels src_lock(src);
217 SkAutoLockPixels masked_lock(masked); 218 SkAutoLockPixels masked_lock(masked);
218 for (int y = 0; y < src_h; y++) { 219 for (int y = 0; y < src_h; y++) {
219 for (int x = 0; x < src_w; x++) { 220 for (int x = 0; x < src_w; x++) {
220 // Test that the alpha is equal. 221 // Test that the alpha is equal.
221 SkColor src_pixel = *src.getAddr32(x, y); 222 SkColor src_pixel = SkUnPreMultiply::PMColorToColor(*src.getAddr32(x, y));
222 SkColor alpha_pixel = *alpha.getAddr32(x, y); 223 SkColor alpha_pixel =
224 SkUnPreMultiply::PMColorToColor(*alpha.getAddr32(x, y));
223 SkColor masked_pixel = *masked.getAddr32(x, y); 225 SkColor masked_pixel = *masked.getAddr32(x, y);
224 226
225 // Test that the alpha is equal. 227 int alpha_value = SkAlphaMul(SkColorGetA(src_pixel),
226 unsigned int alpha = (alpha_pixel & 0xff000000) >> SK_A32_SHIFT; 228 SkColorGetA(alpha_pixel));
227 EXPECT_EQ(alpha, (masked_pixel & 0xff000000) >> SK_A32_SHIFT); 229 SkColor expected_pixel = SkColorSetARGB(
230 alpha_value,
231 SkAlphaMul(SkColorGetR(src_pixel), alpha_value),
232 SkAlphaMul(SkColorGetG(src_pixel), alpha_value),
233 SkAlphaMul(SkColorGetB(src_pixel), alpha_value));
228 234
229 // Test that the colors are right - SkBitmaps have premultiplied alpha, 235 EXPECT_TRUE(ColorsClose(expected_pixel, masked_pixel));
230 // so we can't just do a direct comparison.
231 EXPECT_EQ(SkColorGetR(masked_pixel),
232 SkAlphaMul(SkColorGetR(src_pixel), alpha));
233 } 236 }
234 } 237 }
235 } 238 }
236 239
237 // Testing blur without reimplementing the blur algorithm here is tough, 240 // Testing blur without reimplementing the blur algorithm here is tough,
238 // so we just check to see if the pixels have moved in the direction we 241 // so we just check to see if the pixels have moved in the direction we
239 // think they should move in (and also checking the wrapping behavior). 242 // think they should move in (and also checking the wrapping behavior).
240 // This will allow us to tweak the blur algorithm to suit speed/visual 243 // This will allow us to tweak the blur algorithm to suit speed/visual
241 // needs without breaking the fundamentals. 244 // needs without breaking the fundamentals.
242 TEST(ImageOperations, CreateBlurredBitmap) { 245 TEST(ImageOperations, CreateBlurredBitmap) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 // Test multiple steps of downsampling. 508 // Test multiple steps of downsampling.
506 SkBitmap large; 509 SkBitmap large;
507 large.setConfig(SkBitmap::kARGB_8888_Config, 100, 43); 510 large.setConfig(SkBitmap::kARGB_8888_Config, 100, 43);
508 large.allocPixels(); 511 large.allocPixels();
509 result = skia::ImageOperations::DownsampleByTwoUntilSize(large, 6, 6); 512 result = skia::ImageOperations::DownsampleByTwoUntilSize(large, 6, 6);
510 513
511 // The result should be divided in half 100x43 -> 50x22 -> 25x11 514 // The result should be divided in half 100x43 -> 50x22 -> 25x11
512 EXPECT_EQ(25, result.width()); 515 EXPECT_EQ(25, result.width());
513 EXPECT_EQ(11, result.height()); 516 EXPECT_EQ(11, result.height());
514 } 517 }
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