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

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

Issue 6696085: Add the ability to write comments to PNGCodec::Encode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with webkit_support function Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 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 #pragma once 7 #pragma once
8 8
9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/basictypes.h" 12 #include "base/basictypes.h"
12 13
13 class SkBitmap; 14 class SkBitmap;
14 15
15 namespace gfx { 16 namespace gfx {
16 17
18 class Size;
19
17 // Interface for encoding and decoding PNG data. This is a wrapper around 20 // Interface for encoding and decoding PNG data. This is a wrapper around
18 // libpng, which has an inconvenient interface for callers. This is currently 21 // libpng, which has an inconvenient interface for callers. This is currently
19 // designed for use in tests only (where we control the files), so the handling 22 // designed for use in tests only (where we control the files), so the handling
20 // isn't as robust as would be required for a browser (see Decode() for more). 23 // isn't as robust as would be required for a browser (see Decode() for more).
21 // WebKit has its own more complicated PNG decoder which handles, among other 24 // WebKit has its own more complicated PNG decoder which handles, among other
22 // things, partially downloaded data. 25 // things, partially downloaded data.
23 class PNGCodec { 26 class PNGCodec {
24 public: 27 public:
25 enum ColorFormat { 28 enum ColorFormat {
26 // 3 bytes per pixel (packed), in RGB order regardless of endianness. 29 // 3 bytes per pixel (packed), in RGB order regardless of endianness.
27 // This is the native JPEG format. 30 // This is the native JPEG format.
28 FORMAT_RGB, 31 FORMAT_RGB,
29 32
30 // 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.
31 FORMAT_RGBA, 34 FORMAT_RGBA,
32 35
33 // 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.
34 // This is the default Windows DIB order. 37 // This is the default Windows DIB order.
35 FORMAT_BGRA, 38 FORMAT_BGRA,
36 39
37 // 4 bytes per pixel, in pre-multiplied kARGB_8888_Config format. For use 40 // 4 bytes per pixel, in pre-multiplied kARGB_8888_Config format. For use
38 // with directly writing to a skia bitmap. 41 // with directly writing to a skia bitmap.
39 FORMAT_SkBitmap 42 FORMAT_SkBitmap
40 }; 43 };
41 44
45 // Represents a comment in the tEXt ancillary chunk of the png.
46 struct Comment {
47 std::string key;
48 std::string text;
49 Comment(const std::string& k, const std::string& t) : key(k), text(t) {}
brettw 2011/03/25 00:06:09 Wouldn't this constructor normally go first? Can
tony 2011/03/25 01:04:44 Done.
50 };
51
42 // Encodes the given raw 'input' data, with each pixel being represented as 52 // Encodes the given raw 'input' data, with each pixel being represented as
43 // given in 'format'. The encoded PNG data will be written into the supplied 53 // given in 'format'. The encoded PNG data will be written into the supplied
44 // vector and true will be returned on success. On failure (false), the 54 // vector and true will be returned on success. On failure (false), the
45 // contents of the output buffer are undefined. 55 // contents of the output buffer are undefined.
46 // 56 //
47 // When writing alpha values, the input colors are assumed to be post 57 // When writing alpha values, the input colors are assumed to be post
48 // multiplied. 58 // multiplied.
49 // 59 //
50 // w, h: dimensions of the image 60 // size: dimensions of the image
51 // row_byte_width: the width in bytes of each row. This may be greater than 61 // row_byte_width: the width in bytes of each row. This may be greater than
52 // w * bytes_per_pixel if there is extra padding at the end of each row 62 // w * bytes_per_pixel if there is extra padding at the end of each row
53 // (often, each row is padded to the next machine word). 63 // (often, each row is padded to the next machine word).
54 // discard_transparency: when true, and when the input data format includes 64 // discard_transparency: when true, and when the input data format includes
55 // alpha values, these alpha values will be discarded and only RGB will be 65 // alpha values, these alpha values will be discarded and only RGB will be
56 // written to the resulting file. Otherwise, alpha values in the input 66 // written to the resulting file. Otherwise, alpha values in the input
57 // will be preserved. 67 // will be preserved.
58 static bool Encode(const unsigned char* input, ColorFormat format, 68 // comments: comments to be written in the png's metadata.
59 int w, int h, int row_byte_width, 69 static bool Encode(const unsigned char* input,
70 ColorFormat format,
71 const Size& size,
72 int row_byte_width,
60 bool discard_transparency, 73 bool discard_transparency,
74 const std::vector<Comment>& comments,
61 std::vector<unsigned char>* output); 75 std::vector<unsigned char>* output);
62 76
63 // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed 77 // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed
64 // to be BGRA, 32 bits per pixel. The params |discard_transparency| and 78 // to be BGRA, 32 bits per pixel. The params |discard_transparency| and
65 // |output| are passed directly to Encode; refer to Encode for more 79 // |output| are passed directly to Encode; refer to Encode for more
66 // information. During the call, an SkAutoLockPixels lock is held on |input|. 80 // information. During the call, an SkAutoLockPixels lock is held on |input|.
67 static bool EncodeBGRASkBitmap(const SkBitmap& input, 81 static bool EncodeBGRASkBitmap(const SkBitmap& input,
68 bool discard_transparency, 82 bool discard_transparency,
69 std::vector<unsigned char>* output); 83 std::vector<unsigned char>* output);
70 84
(...skipping 25 matching lines...) Expand all
96 static SkBitmap* CreateSkBitmapFromBGRAFormat( 110 static SkBitmap* CreateSkBitmapFromBGRAFormat(
97 std::vector<unsigned char>& bgra, int width, int height); 111 std::vector<unsigned char>& bgra, int width, int height);
98 112
99 private: 113 private:
100 DISALLOW_COPY_AND_ASSIGN(PNGCodec); 114 DISALLOW_COPY_AND_ASSIGN(PNGCodec);
101 }; 115 };
102 116
103 } // namespace gfx 117 } // namespace gfx
104 118
105 #endif // UI_GFX_CODEC_PNG_CODEC_H_ 119 #endif // UI_GFX_CODEC_PNG_CODEC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698