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/codec/png_codec.h" | 5 #include "ui/gfx/codec/png_codec.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "ui/gfx/size.h" | 10 #include "ui/gfx/size.h" |
11 #include "ui/gfx/skia_util.h" | |
12 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
13 #include "third_party/skia/include/core/SkUnPreMultiply.h" | 12 #include "third_party/skia/include/core/SkUnPreMultiply.h" |
14 #include "third_party/skia/include/core/SkColorPriv.h" | 13 #include "third_party/skia/include/core/SkColorPriv.h" |
15 | 14 |
16 extern "C" { | 15 extern "C" { |
17 #if defined(USE_SYSTEM_LIBPNG) | 16 #if defined(USE_SYSTEM_LIBPNG) |
18 #include <png.h> | 17 #include <png.h> |
19 #else | 18 #else |
20 #include "third_party/libpng/png.h" | 19 #include "third_party/libpng/png.h" |
21 #endif | 20 #endif |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } else { | 69 } else { |
71 pixel_out[0] = SkGetPackedR32(pixel_in); | 70 pixel_out[0] = SkGetPackedR32(pixel_in); |
72 pixel_out[1] = SkGetPackedG32(pixel_in); | 71 pixel_out[1] = SkGetPackedG32(pixel_in); |
73 pixel_out[2] = SkGetPackedB32(pixel_in); | 72 pixel_out[2] = SkGetPackedB32(pixel_in); |
74 } | 73 } |
75 } | 74 } |
76 } | 75 } |
77 | 76 |
78 void ConvertSkiatoRGBA(const unsigned char* skia, int pixel_width, | 77 void ConvertSkiatoRGBA(const unsigned char* skia, int pixel_width, |
79 unsigned char* rgba, bool* is_opaque) { | 78 unsigned char* rgba, bool* is_opaque) { |
80 gfx::ConvertSkiaToRGBA(skia, pixel_width, rgba); | 79 int total_length = pixel_width * 4; |
| 80 for (int i = 0; i < total_length; i += 4) { |
| 81 const uint32_t pixel_in = *reinterpret_cast<const uint32_t*>(&skia[i]); |
| 82 |
| 83 // Pack the components here. |
| 84 int alpha = SkGetPackedA32(pixel_in); |
| 85 if (alpha != 0 && alpha != 255) { |
| 86 SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel_in); |
| 87 rgba[i + 0] = SkColorGetR(unmultiplied); |
| 88 rgba[i + 1] = SkColorGetG(unmultiplied); |
| 89 rgba[i + 2] = SkColorGetB(unmultiplied); |
| 90 rgba[i + 3] = alpha; |
| 91 } else { |
| 92 rgba[i + 0] = SkGetPackedR32(pixel_in); |
| 93 rgba[i + 1] = SkGetPackedG32(pixel_in); |
| 94 rgba[i + 2] = SkGetPackedB32(pixel_in); |
| 95 rgba[i + 3] = alpha; |
| 96 } |
| 97 } |
81 } | 98 } |
82 | 99 |
83 } // namespace | 100 } // namespace |
84 | 101 |
85 // Decoder -------------------------------------------------------------------- | 102 // Decoder -------------------------------------------------------------------- |
86 // | 103 // |
87 // This code is based on WebKit libpng interface (PNGImageDecoder), which is | 104 // This code is based on WebKit libpng interface (PNGImageDecoder), which is |
88 // in turn based on the Mozilla png decoder. | 105 // in turn based on the Mozilla png decoder. |
89 | 106 |
90 namespace { | 107 namespace { |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 } | 796 } |
780 | 797 |
781 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) | 798 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) |
782 : key(k), text(t) { | 799 : key(k), text(t) { |
783 } | 800 } |
784 | 801 |
785 PNGCodec::Comment::~Comment() { | 802 PNGCodec::Comment::~Comment() { |
786 } | 803 } |
787 | 804 |
788 } // namespace gfx | 805 } // namespace gfx |
OLD | NEW |