OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/image_util.h" | 5 #include "extensions/common/image_util.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/stringprintf.h" |
11 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
12 | 13 |
13 namespace extensions { | 14 namespace extensions { |
14 namespace image_util { | 15 namespace image_util { |
15 | 16 |
16 bool ParseCSSColorString(const std::string& color_string, SkColor* result) { | 17 bool ParseCSSColorString(const std::string& color_string, SkColor* result) { |
17 std::string formatted_color; | 18 std::string formatted_color; |
18 // Check the string for incorrect formatting. | 19 // Check the string for incorrect formatting. |
19 if (color_string.empty() || color_string[0] != '#') | 20 if (color_string.empty() || color_string[0] != '#') |
20 return false; | 21 return false; |
(...skipping 13 matching lines...) Expand all Loading... |
34 // Convert the string to an integer and make sure it is in the correct value | 35 // Convert the string to an integer and make sure it is in the correct value |
35 // range. | 36 // range. |
36 std::vector<uint8_t> color_bytes; | 37 std::vector<uint8_t> color_bytes; |
37 if (!base::HexStringToBytes(formatted_color, &color_bytes)) | 38 if (!base::HexStringToBytes(formatted_color, &color_bytes)) |
38 return false; | 39 return false; |
39 | 40 |
40 *result = SkColorSetARGB(255, color_bytes[0], color_bytes[1], color_bytes[2]); | 41 *result = SkColorSetARGB(255, color_bytes[0], color_bytes[1], color_bytes[2]); |
41 return true; | 42 return true; |
42 } | 43 } |
43 | 44 |
| 45 std::string GenerateCSSColorString(SkColor color) { |
| 46 return base::StringPrintf("#%02X%02X%02X", SkColorGetR(color), |
| 47 SkColorGetG(color), SkColorGetB(color)); |
| 48 } |
| 49 |
44 } // namespace image_util | 50 } // namespace image_util |
45 } // namespace extensions | 51 } // namespace extensions |
OLD | NEW |