diff options
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/codec/png_codec.cc | 21 | ||||
-rw-r--r-- | ui/gfx/skia_util.cc | 25 | ||||
-rw-r--r-- | ui/gfx/skia_util.h | 7 |
3 files changed, 33 insertions, 20 deletions
diff --git a/ui/gfx/codec/png_codec.cc b/ui/gfx/codec/png_codec.cc index 1ca139d..da73928 100644 --- a/ui/gfx/codec/png_codec.cc +++ b/ui/gfx/codec/png_codec.cc @@ -8,6 +8,7 @@ #include "base/memory/scoped_ptr.h" #include "base/string_util.h" #include "ui/gfx/size.h" +#include "ui/gfx/skia_util.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkUnPreMultiply.h" #include "third_party/skia/include/core/SkColorPriv.h" @@ -76,25 +77,7 @@ void ConvertSkiatoRGB(const unsigned char* skia, int pixel_width, void ConvertSkiatoRGBA(const unsigned char* skia, int pixel_width, unsigned char* rgba, bool* is_opaque) { - int total_length = pixel_width * 4; - for (int i = 0; i < total_length; i += 4) { - const uint32_t pixel_in = *reinterpret_cast<const uint32_t*>(&skia[i]); - - // Pack the components here. - int alpha = SkGetPackedA32(pixel_in); - if (alpha != 0 && alpha != 255) { - SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel_in); - rgba[i + 0] = SkColorGetR(unmultiplied); - rgba[i + 1] = SkColorGetG(unmultiplied); - rgba[i + 2] = SkColorGetB(unmultiplied); - rgba[i + 3] = alpha; - } else { - rgba[i + 0] = SkGetPackedR32(pixel_in); - rgba[i + 1] = SkGetPackedG32(pixel_in); - rgba[i + 2] = SkGetPackedB32(pixel_in); - rgba[i + 3] = alpha; - } - } + gfx::ConvertSkiaToRGBA(skia, pixel_width, rgba); } } // namespace diff --git a/ui/gfx/skia_util.cc b/ui/gfx/skia_util.cc index bfee378..a459cdd 100644 --- a/ui/gfx/skia_util.cc +++ b/ui/gfx/skia_util.cc @@ -8,6 +8,7 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkColorPriv.h" #include "third_party/skia/include/core/SkShader.h" +#include "third_party/skia/include/core/SkUnPreMultiply.h" #include "third_party/skia/include/effects/SkGradientShader.h" #include "ui/gfx/rect.h" @@ -101,4 +102,28 @@ string16 RemoveAcceleratorChar(const string16& s, return accelerator_removed; } +void ConvertSkiaToRGBA(const unsigned char* skia, + int pixel_width, + unsigned char* rgba) { + int total_length = pixel_width * 4; + for (int i = 0; i < total_length; i += 4) { + const uint32_t pixel_in = *reinterpret_cast<const uint32_t*>(&skia[i]); + + // Pack the components here. + int alpha = SkGetPackedA32(pixel_in); + if (alpha != 0 && alpha != 255) { + SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel_in); + rgba[i + 0] = SkColorGetR(unmultiplied); + rgba[i + 1] = SkColorGetG(unmultiplied); + rgba[i + 2] = SkColorGetB(unmultiplied); + rgba[i + 3] = alpha; + } else { + rgba[i + 0] = SkGetPackedR32(pixel_in); + rgba[i + 1] = SkGetPackedG32(pixel_in); + rgba[i + 2] = SkGetPackedB32(pixel_in); + rgba[i + 3] = alpha; + } + } +} + } // namespace gfx diff --git a/ui/gfx/skia_util.h b/ui/gfx/skia_util.h index de7b8f4..152b731 100644 --- a/ui/gfx/skia_util.h +++ b/ui/gfx/skia_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -50,6 +50,11 @@ UI_EXPORT string16 RemoveAcceleratorChar(const string16& s, int* accelerated_char_pos, int* accelerated_char_span); +// Converts Skia ARGB format pixels in |skia| to RGBA. +UI_EXPORT void ConvertSkiaToRGBA(const unsigned char* skia, + int pixel_width, + unsigned char* rgba); + } // namespace gfx #endif // UI_GFX_SKIA_UTIL_H_ |