OLD | NEW |
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 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" | 5 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "third_party/skia/include/core/SkUnPreMultiply.h" | 12 #include "third_party/skia/include/core/SkUnPreMultiply.h" |
13 | 13 |
14 namespace libgtk2ui { | 14 namespace libgtk2ui { |
15 | 15 |
16 const int kSkiaToGDKMultiplier = 257; | |
17 | |
18 // GDK_COLOR_RGB multiplies by 257 (= 0x10001) to distribute the bits evenly | 16 // GDK_COLOR_RGB multiplies by 257 (= 0x10001) to distribute the bits evenly |
19 // See: http://www.mindcontrol.org/~hplus/graphics/expand-bits.html | 17 // See: http://www.mindcontrol.org/~hplus/graphics/expand-bits.html |
20 // To get back, we can just right shift by eight | 18 // To get back, we can just right shift by eight |
21 // (or, formulated differently, i == (i*257)/256 for all i < 256). | 19 // (or, formulated differently, i == (i*257)/256 for all i < 256). |
22 | 20 |
23 SkColor GdkColorToSkColor(GdkColor color) { | 21 SkColor GdkColorToSkColor(GdkColor color) { |
24 return SkColorSetRGB(color.red >> 8, color.green >> 8, color.blue >> 8); | 22 return SkColorSetRGB(color.red >> 8, color.green >> 8, color.blue >> 8); |
25 } | 23 } |
26 | 24 |
27 GdkColor SkColorToGdkColor(SkColor color) { | 25 GdkColor SkColorToGdkColor(SkColor color) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 divided[i + 3] = alpha; | 126 divided[i + 3] = alpha; |
129 } | 127 } |
130 i += kBytesPerPixel; | 128 i += kBytesPerPixel; |
131 } | 129 } |
132 } | 130 } |
133 | 131 |
134 return pixbuf; | 132 return pixbuf; |
135 } | 133 } |
136 | 134 |
137 } // namespace libgtk2ui | 135 } // namespace libgtk2ui |
OLD | NEW |