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

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: strdup 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 Comment(const std::string& k, const std::string& t);
48 ~Comment();
49
50 std::string key;
51 std::string text;
52 };
53
42 // Encodes the given raw 'input' data, with each pixel being represented as 54 // 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 55 // 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 56 // vector and true will be returned on success. On failure (false), the
45 // contents of the output buffer are undefined. 57 // contents of the output buffer are undefined.
46 // 58 //
47 // When writing alpha values, the input colors are assumed to be post 59 // When writing alpha values, the input colors are assumed to be post
48 // multiplied. 60 // multiplied.
49 // 61 //
50 // w, h: dimensions of the image 62 // size: dimensions of the image
51 // row_byte_width: the width in bytes of each row. This may be greater than 63 // 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 64 // 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). 65 // (often, each row is padded to the next machine word).
54 // discard_transparency: when true, and when the input data format includes 66 // 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 67 // 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 68 // written to the resulting file. Otherwise, alpha values in the input
57 // will be preserved. 69 // will be preserved.
58 static bool Encode(const unsigned char* input, ColorFormat format, 70 // comments: comments to be written in the png's metadata.
59 int w, int h, int row_byte_width, 71 static bool Encode(const unsigned char* input,
72 ColorFormat format,
73 const Size& size,
74 int row_byte_width,
60 bool discard_transparency, 75 bool discard_transparency,
76 const std::vector<Comment>& comments,
61 std::vector<unsigned char>* output); 77 std::vector<unsigned char>* output);
62 78
63 // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed 79 // Call PNGCodec::Encode on the supplied SkBitmap |input|, which is assumed
64 // to be BGRA, 32 bits per pixel. The params |discard_transparency| and 80 // to be BGRA, 32 bits per pixel. The params |discard_transparency| and
65 // |output| are passed directly to Encode; refer to Encode for more 81 // |output| are passed directly to Encode; refer to Encode for more
66 // information. During the call, an SkAutoLockPixels lock is held on |input|. 82 // information. During the call, an SkAutoLockPixels lock is held on |input|.
67 static bool EncodeBGRASkBitmap(const SkBitmap& input, 83 static bool EncodeBGRASkBitmap(const SkBitmap& input,
68 bool discard_transparency, 84 bool discard_transparency,
69 std::vector<unsigned char>* output); 85 std::vector<unsigned char>* output);
70 86
(...skipping 25 matching lines...) Expand all
96 static SkBitmap* CreateSkBitmapFromBGRAFormat( 112 static SkBitmap* CreateSkBitmapFromBGRAFormat(
97 std::vector<unsigned char>& bgra, int width, int height); 113 std::vector<unsigned char>& bgra, int width, int height);
98 114
99 private: 115 private:
100 DISALLOW_COPY_AND_ASSIGN(PNGCodec); 116 DISALLOW_COPY_AND_ASSIGN(PNGCodec);
101 }; 117 };
102 118
103 } // namespace gfx 119 } // namespace gfx
104 120
105 #endif // UI_GFX_CODEC_PNG_CODEC_H_ 121 #endif // UI_GFX_CODEC_PNG_CODEC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698