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

Side by Side Diff: ui/gfx/image/image_unittest_util.cc

Issue 10946031: Modifies GetPlatformImageColor() to check the color of a given point. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix compile. Created 8 years, 3 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 | « ui/gfx/image/image_unittest_util.h ('k') | ui/gfx/image/image_unittest_util_mac.mm » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Because the unit tests for gfx::Image are spread across multiple 5 // Because the unit tests for gfx::Image are spread across multiple
6 // implementation files, this header contains the reusable components. 6 // implementation files, this header contains the reusable components.
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "ui/base/layout.h" 9 #include "ui/base/layout.h"
10 #include "ui/gfx/image/image_unittest_util.h" 10 #include "ui/gfx/image/image_unittest_util.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 #elif defined(TOOLKIT_GTK) 132 #elif defined(TOOLKIT_GTK)
133 return image.CopyGdkPixbuf(); 133 return image.CopyGdkPixbuf();
134 #else 134 #else
135 return *image.ToSkBitmap(); 135 return *image.ToSkBitmap();
136 #endif 136 #endif
137 } 137 }
138 138
139 #if defined(OS_MACOSX) 139 #if defined(OS_MACOSX)
140 // Defined in image_unittest_util_mac.mm. 140 // Defined in image_unittest_util_mac.mm.
141 #elif defined(TOOLKIT_GTK) 141 #elif defined(TOOLKIT_GTK)
142 SkColor GetPlatformImageColor(PlatformImage image) { 142 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) {
143 int n_channels = gdk_pixbuf_get_n_channels(image);
144 int rowstride = gdk_pixbuf_get_rowstride(image);
143 guchar* gdk_pixels = gdk_pixbuf_get_pixels(image); 145 guchar* gdk_pixels = gdk_pixbuf_get_pixels(image);
144 guchar alpha = gdk_pixbuf_get_has_alpha(image) ? gdk_pixels[3] : 255; 146
145 return SkColorSetARGB(alpha, gdk_pixels[0], gdk_pixels[1], gdk_pixels[2]); 147 guchar* pixel = gdk_pixels + (y * rowstride) + (x * n_channels);
Elliot Glaysher 2012/09/19 17:47:11 This is probably correct everywhere. (At least you
148 guchar alpha = gdk_pixbuf_get_has_alpha(image) ? pixel[3] : 255;
149 return SkColorSetARGB(alpha, pixel[0], pixel[1], pixel[2]);
146 } 150 }
147 #else 151 #else
148 SkColor GetPlatformImageColor(PlatformImage image) { 152 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) {
149 SkAutoLockPixels auto_lock(image); 153 SkAutoLockPixels auto_lock(image);
150 return image.getColor(10, 10); 154 return image.getColor(x, y);
151 } 155 }
152 #endif 156 #endif
153 157
154 void CheckColor(SkColor color, bool is_red) { 158 void CheckColor(SkColor color, bool is_red) {
155 // Be tolerant of floating point rounding and lossy color space conversions. 159 // Be tolerant of floating point rounding and lossy color space conversions.
156 if (is_red) { 160 if (is_red) {
157 EXPECT_GT(SkColorGetR(color), 0.95); 161 EXPECT_GT(SkColorGetR(color), 0.95);
158 EXPECT_LT(SkColorGetG(color), 0.05); 162 EXPECT_LT(SkColorGetG(color), 0.05);
159 } else { 163 } else {
160 EXPECT_GT(SkColorGetG(color), 0.95); 164 EXPECT_GT(SkColorGetG(color), 0.95);
(...skipping 14 matching lines...) Expand all
175 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { 179 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) {
176 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) 180 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK)
177 return image1 == image2; 181 return image1 == image2;
178 #else 182 #else
179 return image1.getPixels() == image2.getPixels(); 183 return image1.getPixels() == image2.getPixels();
180 #endif 184 #endif
181 } 185 }
182 186
183 } // namespace test 187 } // namespace test
184 } // namespace gfx 188 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image_unittest_util.h ('k') | ui/gfx/image/image_unittest_util_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698