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

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

Issue 151097: Enable some skia unittests on linux and mac. (Closed)
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
« no previous file with comments | « no previous file | webkit/tools/test_shell/test_shell.gyp » ('j') | 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/SkColorPriv.h" 9 #include "third_party/skia/include/core/SkColorPriv.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Shift to red. 171 // Shift to red.
172 SkBitmap blended = skia::ImageOperations::CreateBlendedBitmap( 172 SkBitmap blended = skia::ImageOperations::CreateBlendedBitmap(
173 src_a, src_b, 0.5); 173 src_a, src_b, 0.5);
174 SkAutoLockPixels srca_lock(src_a); 174 SkAutoLockPixels srca_lock(src_a);
175 SkAutoLockPixels srcb_lock(src_b); 175 SkAutoLockPixels srcb_lock(src_b);
176 SkAutoLockPixels blended_lock(blended); 176 SkAutoLockPixels blended_lock(blended);
177 177
178 for (int y = 0; y < src_h; y++) { 178 for (int y = 0; y < src_h; y++) {
179 for (int x = 0; x < src_w; x++) { 179 for (int x = 0; x < src_w; x++) {
180 int i = y * src_w + x; 180 int i = y * src_w + x;
181 EXPECT_EQ((255 + ((255 - i) % 255)) / 2, 181 EXPECT_EQ(static_cast<unsigned int>((255 + ((255 - i) % 255)) / 2),
182 SkColorGetA(*blended.getAddr32(x, y))); 182 SkColorGetA(*blended.getAddr32(x, y)));
183 EXPECT_EQ(i % 255 / 2, 183 EXPECT_EQ(static_cast<unsigned int>(i % 255 / 2),
184 SkColorGetR(*blended.getAddr32(x, y))); 184 SkColorGetR(*blended.getAddr32(x, y)));
185 EXPECT_EQ(((i * 2) % 255 + (i * 4) % 255) / 2, 185 EXPECT_EQ((static_cast<unsigned int>((i * 2) % 255 + (i * 4) % 255) / 2),
186 SkColorGetG(*blended.getAddr32(x, y))); 186 SkColorGetG(*blended.getAddr32(x, y)));
187 EXPECT_EQ(i % 255 / 2, 187 EXPECT_EQ(static_cast<unsigned int>(i % 255 / 2),
188 SkColorGetB(*blended.getAddr32(x, y))); 188 SkColorGetB(*blended.getAddr32(x, y)));
189 } 189 }
190 } 190 }
191 } 191 }
192 192
193 // Test our masking functions. 193 // Test our masking functions.
194 TEST(ImageOperations, CreateMaskedBitmap) { 194 TEST(ImageOperations, CreateMaskedBitmap) {
195 int src_w = 16, src_h = 16; 195 int src_w = 16, src_h = 16;
196 196
197 SkBitmap src; 197 SkBitmap src;
(...skipping 18 matching lines...) Expand all
216 SkAutoLockPixels src_lock(src); 216 SkAutoLockPixels src_lock(src);
217 SkAutoLockPixels masked_lock(masked); 217 SkAutoLockPixels masked_lock(masked);
218 for (int y = 0; y < src_h; y++) { 218 for (int y = 0; y < src_h; y++) {
219 for (int x = 0; x < src_w; x++) { 219 for (int x = 0; x < src_w; x++) {
220 // Test that the alpha is equal. 220 // Test that the alpha is equal.
221 SkColor src_pixel = *src.getAddr32(x, y); 221 SkColor src_pixel = *src.getAddr32(x, y);
222 SkColor alpha_pixel = *alpha.getAddr32(x, y); 222 SkColor alpha_pixel = *alpha.getAddr32(x, y);
223 SkColor masked_pixel = *masked.getAddr32(x, y); 223 SkColor masked_pixel = *masked.getAddr32(x, y);
224 224
225 // Test that the alpha is equal. 225 // Test that the alpha is equal.
226 int alpha = (alpha_pixel & 0xff000000) >> SK_A32_SHIFT; 226 unsigned int alpha = (alpha_pixel & 0xff000000) >> SK_A32_SHIFT;
227 EXPECT_EQ(alpha, (masked_pixel & 0xff000000) >> SK_A32_SHIFT); 227 EXPECT_EQ(alpha, (masked_pixel & 0xff000000) >> SK_A32_SHIFT);
228 228
229 // Test that the colors are right - SkBitmaps have premultiplied alpha, 229 // Test that the colors are right - SkBitmaps have premultiplied alpha,
230 // so we can't just do a direct comparison. 230 // so we can't just do a direct comparison.
231 EXPECT_EQ(SkColorGetR(masked_pixel), 231 EXPECT_EQ(SkColorGetR(masked_pixel),
232 SkAlphaMul(SkColorGetR(src_pixel), alpha)); 232 SkAlphaMul(SkColorGetR(src_pixel), alpha));
233 } 233 }
234 } 234 }
235 } 235 }
236 236
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 504
505 // Test multiple steps of downsampling. 505 // Test multiple steps of downsampling.
506 SkBitmap large; 506 SkBitmap large;
507 large.setConfig(SkBitmap::kARGB_8888_Config, 100, 43); 507 large.setConfig(SkBitmap::kARGB_8888_Config, 100, 43);
508 large.allocPixels(); 508 large.allocPixels();
509 result = skia::ImageOperations::DownsampleByTwoUntilSize(large, 6, 6); 509 result = skia::ImageOperations::DownsampleByTwoUntilSize(large, 6, 6);
510 510
511 // The result should be divided in half 100x43 -> 50x22 -> 25x11 511 // The result should be divided in half 100x43 -> 50x22 -> 25x11
512 EXPECT_EQ(25, result.width()); 512 EXPECT_EQ(25, result.width());
513 EXPECT_EQ(11, result.height()); 513 EXPECT_EQ(11, result.height());
514 } 514 }
OLDNEW
« no previous file with comments | « no previous file | webkit/tools/test_shell/test_shell.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698