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 "ui/gfx/skia_util.h" | 5 #include "ui/gfx/skia_util.h" |
6 | 6 |
7 #include "base/i18n/char_iterator.h" | 7 #include "base/i18n/char_iterator.h" |
8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.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/SkShader.h" | 10 #include "third_party/skia/include/core/SkShader.h" |
11 #include "third_party/skia/include/core/SkUnPreMultiply.h" | |
12 #include "third_party/skia/include/effects/SkGradientShader.h" | 11 #include "third_party/skia/include/effects/SkGradientShader.h" |
13 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
14 | 13 |
15 namespace gfx { | 14 namespace gfx { |
16 | 15 |
17 SkRect RectToSkRect(const gfx::Rect& rect) { | 16 SkRect RectToSkRect(const gfx::Rect& rect) { |
18 SkRect r; | 17 SkRect r; |
19 r.iset(rect.x(), rect.y(), rect.right(), rect.bottom()); | 18 r.iset(rect.x(), rect.y(), rect.right(), rect.bottom()); |
20 return r; | 19 return r; |
21 } | 20 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 94 } |
96 | 95 |
97 if (accelerated_char_pos) | 96 if (accelerated_char_pos) |
98 *accelerated_char_pos = last_char_pos; | 97 *accelerated_char_pos = last_char_pos; |
99 if (accelerated_char_span) | 98 if (accelerated_char_span) |
100 *accelerated_char_span = last_char_span; | 99 *accelerated_char_span = last_char_span; |
101 | 100 |
102 return accelerator_removed; | 101 return accelerator_removed; |
103 } | 102 } |
104 | 103 |
105 void ConvertSkiaToRGBA(const unsigned char* skia, | |
106 int pixel_width, | |
107 unsigned char* rgba) { | |
108 int total_length = pixel_width * 4; | |
109 for (int i = 0; i < total_length; i += 4) { | |
110 const uint32_t pixel_in = *reinterpret_cast<const uint32_t*>(&skia[i]); | |
111 | |
112 // Pack the components here. | |
113 int alpha = SkGetPackedA32(pixel_in); | |
114 if (alpha != 0 && alpha != 255) { | |
115 SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel_in); | |
116 rgba[i + 0] = SkColorGetR(unmultiplied); | |
117 rgba[i + 1] = SkColorGetG(unmultiplied); | |
118 rgba[i + 2] = SkColorGetB(unmultiplied); | |
119 rgba[i + 3] = alpha; | |
120 } else { | |
121 rgba[i + 0] = SkGetPackedR32(pixel_in); | |
122 rgba[i + 1] = SkGetPackedG32(pixel_in); | |
123 rgba[i + 2] = SkGetPackedB32(pixel_in); | |
124 rgba[i + 3] = alpha; | |
125 } | |
126 } | |
127 } | |
128 | |
129 } // namespace gfx | 104 } // namespace gfx |
OLD | NEW |