| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef UI_GFX_CODEC_PNG_CODEC_H_ | 5 #ifndef UI_GFX_CODEC_PNG_CODEC_H_ |
| 6 #define UI_GFX_CODEC_PNG_CODEC_H_ | 6 #define UI_GFX_CODEC_PNG_CODEC_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "third_party/skia/include/core/SkImageInfo.h" |
| 15 #include "third_party/skia/include/core/SkPixmap.h" |
| 14 #include "ui/gfx/codec/codec_export.h" | 16 #include "ui/gfx/codec/codec_export.h" |
| 15 | 17 |
| 16 class SkBitmap; | 18 class SkBitmap; |
| 17 | 19 |
| 18 namespace gfx { | 20 namespace gfx { |
| 19 | 21 |
| 20 class Size; | 22 class Size; |
| 21 | 23 |
| 22 // Interface for encoding and decoding PNG data. This is a wrapper around | 24 // Interface for encoding and decoding PNG data. This is a wrapper around |
| 23 // libpng, which has an inconvenient interface for callers. This is currently | 25 // libpng, which has an inconvenient interface for callers. This is currently |
| (...skipping 20 matching lines...) Expand all Loading... |
| 44 | 46 |
| 45 // Represents a comment in the tEXt ancillary chunk of the png. | 47 // Represents a comment in the tEXt ancillary chunk of the png. |
| 46 struct CODEC_EXPORT Comment { | 48 struct CODEC_EXPORT Comment { |
| 47 Comment(const std::string& k, const std::string& t); | 49 Comment(const std::string& k, const std::string& t); |
| 48 ~Comment(); | 50 ~Comment(); |
| 49 | 51 |
| 50 std::string key; | 52 std::string key; |
| 51 std::string text; | 53 std::string text; |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 // Encodes the given raw 'input' data, with each pixel being represented as | 56 // Encodes the given raw 'input' pixmap, which includes a pointer to pixels as |
| 55 // given in 'format'. The encoded PNG data will be written into the supplied | 57 // well as information describing the pixel format. The encoded PNG data will |
| 56 // vector and true will be returned on success. On failure (false), the | 58 // be written into the supplied vector and true will be returned on success. |
| 57 // contents of the output buffer are undefined. | 59 // On failure (false), the contents of the output buffer are undefined. |
| 58 // | 60 // |
| 59 // When writing alpha values, the input colors are assumed to be post | 61 // When writing alpha values, the input colors are assumed to be post |
| 60 // multiplied. | 62 // multiplied. |
| 61 // | 63 // |
| 62 // size: dimensions of the image | |
| 63 // row_byte_width: the width in bytes of each row. This may be greater than | |
| 64 // w * bytes_per_pixel if there is extra padding at the end of each row | |
| 65 // (often, each row is padded to the next machine word). | |
| 66 // discard_transparency: when true, and when the input data format includes | |
| 67 // alpha values, these alpha values will be discarded and only RGB will be | |
| 68 // written to the resulting file. Otherwise, alpha values in the input | |
| 69 // will be preserved. | |
| 70 // comments: comments to be written in the png's metadata. | 64 // comments: comments to be written in the png's metadata. |
| 71 static bool Encode(const unsigned char* input, | 65 static bool Encode(const SkPixmap& input, |
| 72 ColorFormat format, | |
| 73 const Size& size, | |
| 74 int row_byte_width, | |
| 75 bool discard_transparency, | |
| 76 const std::vector<Comment>& comments, | 66 const std::vector<Comment>& comments, |
| 77 std::vector<unsigned char>* output); | 67 std::vector<unsigned char>* output); |
| 78 | 68 |
| 79 // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed | 69 // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed |
| 80 // to be kARGB_8888_Config, 32 bits per pixel. The params | 70 // to be kARGB_8888_Config, 32 bits per pixel. The params |
| 81 // |discard_transparency| and |output| are passed directly to Encode; refer to | 71 // |discard_transparency| and |output| are passed directly to Encode; refer to |
| 82 // Encode for more information. | 72 // Encode for more information. |
| 83 static bool EncodeBGRASkBitmap(const SkBitmap& input, | 73 static bool EncodeBGRASkBitmap(const SkBitmap& input, |
| 84 bool discard_transparency, | 74 bool discard_transparency, |
| 85 std::vector<unsigned char>* output); | 75 std::vector<unsigned char>* output); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 static bool Decode(const unsigned char* input, size_t input_size, | 111 static bool Decode(const unsigned char* input, size_t input_size, |
| 122 SkBitmap* bitmap); | 112 SkBitmap* bitmap); |
| 123 | 113 |
| 124 private: | 114 private: |
| 125 DISALLOW_COPY_AND_ASSIGN(PNGCodec); | 115 DISALLOW_COPY_AND_ASSIGN(PNGCodec); |
| 126 }; | 116 }; |
| 127 | 117 |
| 128 } // namespace gfx | 118 } // namespace gfx |
| 129 | 119 |
| 130 #endif // UI_GFX_CODEC_PNG_CODEC_H_ | 120 #endif // UI_GFX_CODEC_PNG_CODEC_H_ |
| OLD | NEW |