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

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

Issue 10830207: Add support for PNG representation in gfx::Image (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Missed small change from previous CL. Created 8 years, 4 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"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/skia/include/core/SkBitmap.h" 12 #include "third_party/skia/include/core/SkBitmap.h"
13 13
14 #if defined(TOOLKIT_GTK) 14 #if defined(TOOLKIT_GTK)
15 #include <gtk/gtk.h>
15 #include "ui/gfx/gtk_util.h" 16 #include "ui/gfx/gtk_util.h"
16 #elif defined(OS_MACOSX) 17 #elif defined(OS_MACOSX)
17 #include "base/mac/mac_util.h" 18 #include "base/mac/mac_util.h"
18 #include "skia/ext/skia_utils_mac.h" 19 #include "skia/ext/skia_utils_mac.h"
19 #endif 20 #endif
20 21
21 namespace gfx { 22 namespace gfx {
22 namespace test { 23 namespace test {
23 24
24 #if defined(OS_MACOSX) 25 #if defined(OS_MACOSX)
25 26
26 void SetSupportedScaleFactorsTo1xAnd2x() { 27 void SetSupportedScaleFactorsTo1xAnd2x() {
27 std::vector<ui::ScaleFactor> supported_scale_factors; 28 std::vector<ui::ScaleFactor> supported_scale_factors;
28 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); 29 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
29 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P); 30 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
30 ui::test::SetSupportedScaleFactors(supported_scale_factors); 31 ui::test::SetSupportedScaleFactors(supported_scale_factors);
31 } 32 }
32 33
33 #endif // OS_MACOSX 34 #endif // OS_MACOSX
34 35
35 const SkBitmap CreateBitmap(int width, int height) { 36 const SkBitmap CreateBitmap(int width, int height) {
36 SkBitmap bitmap; 37 SkBitmap bitmap;
37 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 38 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
38 bitmap.allocPixels(); 39 bitmap.allocPixels();
39 bitmap.eraseRGB(255, 0, 0); 40 bitmap.eraseRGB(0, 255, 0);
40 return bitmap; 41 return bitmap;
41 } 42 }
42 43
43 gfx::Image CreateImage() { 44 gfx::Image CreateImage() {
44 return CreateImage(100, 50); 45 return CreateImage(100, 50);
45 } 46 }
46 47
47 gfx::Image CreateImage(int width, int height) { 48 gfx::Image CreateImage(int width, int height) {
48 return gfx::Image(CreateBitmap(width, height)); 49 return gfx::Image(CreateBitmap(width, height));
49 } 50 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 PlatformImage ToPlatformType(const gfx::Image& image) { 107 PlatformImage ToPlatformType(const gfx::Image& image) {
107 #if defined(OS_MACOSX) 108 #if defined(OS_MACOSX)
108 return image.ToNSImage(); 109 return image.ToNSImage();
109 #elif defined(TOOLKIT_GTK) 110 #elif defined(TOOLKIT_GTK)
110 return image.ToGdkPixbuf(); 111 return image.ToGdkPixbuf();
111 #else 112 #else
112 return *image.ToSkBitmap(); 113 return *image.ToSkBitmap();
113 #endif 114 #endif
114 } 115 }
115 116
117 PlatformImage CopyPlatformType(const gfx::Image& image) {
118 #if defined(OS_MACOSX)
119 return image.CopyNSImage();
120 #elif defined(TOOLKIT_GTK)
121 return image.CopyGdkPixbuf();
122 #else
123 return *image.ToSkBitmap();
124 #endif
125 }
126
127 #if defined(OS_MACOSX)
128 // Defined in image_unittest_util_mac.mm.
129 #elif defined(TOOLKIT_GTK)
130 SkColor GetPlatformImageColor(PlatformImage image) {
131 guchar* gdk_pixels = gdk_pixbuf_get_pixels(image);
132 guchar alpha = gdk_pixbuf_get_has_alpha(image) ? gdk_pixels[3] : 255;
133 return SkColorSetARGB(alpha, gdk_pixels[0], gdk_pixels[1], gdk_pixels[2]);
134 }
135 #else
136 SkColor GetPlatformImageColor(PlatformImage image) {
137 SkAutoLockPixels auto_lock(image);
138 return image.getColor(10, 10);
139 }
140 #endif
141
142 void CheckColor(SkColor color, bool is_red) {
143 // Be tolerant of floating point rounding and lossy color space conversions.
144 if (is_red) {
145 EXPECT_GT(SkColorGetR(color), 0.95);
146 EXPECT_LT(SkColorGetG(color), 0.05);
147 } else {
148 EXPECT_GT(SkColorGetG(color), 0.95);
149 EXPECT_LT(SkColorGetR(color), 0.05);
150 }
151 EXPECT_LT(SkColorGetB(color), 0.05);
152 EXPECT_GT(SkColorGetA(color), 0.95);
153 }
154
116 bool IsPlatformImageValid(PlatformImage image) { 155 bool IsPlatformImageValid(PlatformImage image) {
117 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) 156 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK)
118 return image != NULL; 157 return image != NULL;
119 #else 158 #else
120 return !image.isNull(); 159 return !image.isNull();
121 #endif 160 #endif
122 } 161 }
123 162
124 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { 163 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) {
125 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) 164 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK)
126 return image1 == image2; 165 return image1 == image2;
127 #else 166 #else
128 return image1.getPixels() == image2.getPixels(); 167 return image1.getPixels() == image2.getPixels();
129 #endif 168 #endif
130 } 169 }
131 170
132 } // namespace test 171 } // namespace test
133 } // namespace gfx 172 } // 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