Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: ui/gfx/codec/png_codec.h

Issue 2944633002: Use SkPngEncoder in gfx jpeg_codec (Closed)
Patch Set: Update comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/codec/jpeg_codec.cc ('k') | ui/gfx/codec/png_codec.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/gfx/codec/codec_export.h" 14 #include "ui/gfx/codec/codec_export.h"
15 15
16 class SkBitmap; 16 class SkBitmap;
17 17
18 namespace gfx { 18 namespace gfx {
19 19
20 class Size; 20 class Size;
21 21
22 // Interface for encoding and decoding PNG data. This is a wrapper around 22 // Interface for encoding and decoding PNG data. This is a wrapper around
23 // libpng, which has an inconvenient interface for callers. This is currently 23 // libpng, which has an inconvenient interface for callers. This is currently
24 // designed for use in tests only (where we control the files), so the handling 24 // designed for use in tests only (where we control the files), so the handling
25 // isn't as robust as would be required for a browser (see Decode() for more). 25 // isn't as robust as would be required for a browser (see Decode() for more).
26 // WebKit has its own more complicated PNG decoder which handles, among other 26 // WebKit has its own more complicated PNG decoder which handles, among other
27 // things, partially downloaded data. 27 // things, partially downloaded data.
28 class CODEC_EXPORT PNGCodec { 28 class CODEC_EXPORT PNGCodec {
29 public: 29 public:
30 static constexpr int DEFAULT_ZLIB_COMPRESSION = 6;
31
30 enum ColorFormat { 32 enum ColorFormat {
31 // 4 bytes per pixel, in RGBA order in memory regardless of endianness. 33 // 4 bytes per pixel, in RGBA order in memory regardless of endianness.
32 FORMAT_RGBA, 34 FORMAT_RGBA,
33 35
34 // 4 bytes per pixel, in BGRA order in memory regardless of endianness. 36 // 4 bytes per pixel, in BGRA order in memory regardless of endianness.
35 // This is the default Windows DIB order. 37 // This is the default Windows DIB order.
36 FORMAT_BGRA, 38 FORMAT_BGRA,
37 39
38 // SkBitmap format. For Encode() kARGB_8888_Config (4 bytes per pixel) and 40 // SkBitmap format. For Encode() kBGRA_8888_SkColorType (4 bytes per pixel)
scroggo_chromium 2017/07/11 19:33:09 Actually, I think this should probably be kN32_SkC
liyuqian 2017/07/11 19:59:25 Done.
39 // kA8_Config (1 byte per pixel) formats are supported. kA8_Config gets 41 // and kAlpha_8_SkColorType (1 byte per pixel) formats are supported.
40 // encoded into a grayscale PNG treating alpha as the color intensity. 42 // kAlpha_8_SkColorType gets encoded into a grayscale PNG treating alpha as
41 // For Decode() kARGB_8888_Config is always used. 43 // the color intensity. For Decode() kBGRA_8888_SkColorType is always used.
42 FORMAT_SkBitmap 44 FORMAT_SkBitmap
43 }; 45 };
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;
(...skipping 18 matching lines...) Expand all
70 // comments: comments to be written in the png's metadata. 72 // comments: comments to be written in the png's metadata.
71 static bool Encode(const unsigned char* input, 73 static bool Encode(const unsigned char* input,
72 ColorFormat format, 74 ColorFormat format,
73 const Size& size, 75 const Size& size,
74 int row_byte_width, 76 int row_byte_width,
75 bool discard_transparency, 77 bool discard_transparency,
76 const std::vector<Comment>& comments, 78 const std::vector<Comment>& comments,
77 std::vector<unsigned char>* output); 79 std::vector<unsigned char>* output);
78 80
79 // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed 81 // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed
80 // to be kARGB_8888_Config, 32 bits per pixel. The params 82 // to be kBGRA_8888_SkColorType, 32 bits per pixel. The params
scroggo_chromium 2017/07/11 19:33:09 kN32
liyuqian 2017/07/11 19:59:25 Done.
81 // |discard_transparency| and |output| are passed directly to Encode; refer to 83 // |discard_transparency| and |output| are passed directly to Encode; refer to
82 // Encode for more information. 84 // Encode for more information.
83 static bool EncodeBGRASkBitmap(const SkBitmap& input, 85 static bool EncodeBGRASkBitmap(const SkBitmap& input,
84 bool discard_transparency, 86 bool discard_transparency,
85 std::vector<unsigned char>* output); 87 std::vector<unsigned char>* output);
86 88
87 // Call PNGCodec::Encode on the supplied SkBitmap |input|. The difference 89 // Call PNGCodec::Encode on the supplied SkBitmap |input|. The difference
88 // between this and the previous method is that this restricts compression to 90 // between this and the previous method is that this restricts compression to
89 // zlib q1, which is just rle encoding. 91 // zlib q1, which is just rle encoding.
90 static bool FastEncodeBGRASkBitmap(const SkBitmap& input, 92 static bool FastEncodeBGRASkBitmap(const SkBitmap& input,
91 bool discard_transparency, 93 bool discard_transparency,
92 std::vector<unsigned char>* output); 94 std::vector<unsigned char>* output);
93 95
94 // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed 96 // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed to
95 // to be kA8_Config, 8 bits per pixel. The bitmap is encoded as a grayscale 97 // be kAlpha_8_SkColorType, 8 bits per pixel. The bitmap is encoded as a
96 // PNG with alpha used for color intensity. The |output| param is passed 98 // grayscale PNG with alpha used for color intensity. The |output| param is
97 // directly to Encode; refer to Encode for more information. 99 // passed directly to Encode; refer to Encode for more information.
98 static bool EncodeA8SkBitmap(const SkBitmap& input, 100 static bool EncodeA8SkBitmap(const SkBitmap& input,
99 std::vector<unsigned char>* output); 101 std::vector<unsigned char>* output);
100 102
101 // Decodes the PNG data contained in input of length input_size. The 103 // Decodes the PNG data contained in input of length input_size. The
102 // decoded data will be placed in *output with the dimensions in *w and *h 104 // decoded data will be placed in *output with the dimensions in *w and *h
103 // on success (returns true). This data will be written in the 'format' 105 // on success (returns true). This data will be written in the 'format'
104 // format. On failure, the values of these output variables are undefined. 106 // format. On failure, the values of these output variables are undefined.
105 // 107 //
106 // This function may not support all PNG types, and it hasn't been tested 108 // This function may not support all PNG types, and it hasn't been tested
107 // with a large number of images, so assume a new format may not work. It's 109 // with a large number of images, so assume a new format may not work. It's
(...skipping 13 matching lines...) Expand all
121 static bool Decode(const unsigned char* input, size_t input_size, 123 static bool Decode(const unsigned char* input, size_t input_size,
122 SkBitmap* bitmap); 124 SkBitmap* bitmap);
123 125
124 private: 126 private:
125 DISALLOW_COPY_AND_ASSIGN(PNGCodec); 127 DISALLOW_COPY_AND_ASSIGN(PNGCodec);
126 }; 128 };
127 129
128 } // namespace gfx 130 } // namespace gfx
129 131
130 #endif // UI_GFX_CODEC_PNG_CODEC_H_ 132 #endif // UI_GFX_CODEC_PNG_CODEC_H_
OLDNEW
« no previous file with comments | « ui/gfx/codec/jpeg_codec.cc ('k') | ui/gfx/codec/png_codec.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698