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_JPEG_CODEC_H_ | 5 #ifndef UI_GFX_CODEC_JPEG_CODEC_H_ |
6 #define UI_GFX_CODEC_JPEG_CODEC_H_ | 6 #define UI_GFX_CODEC_JPEG_CODEC_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
| 13 #include "third_party/skia/include/core/SkImageInfo.h" |
| 14 #include "third_party/skia/include/core/SkPixmap.h" |
13 #include "ui/gfx/codec/codec_export.h" | 15 #include "ui/gfx/codec/codec_export.h" |
14 | 16 |
15 class SkBitmap; | 17 class SkBitmap; |
16 | 18 |
17 namespace gfx { | 19 namespace gfx { |
18 | 20 |
19 // Interface for encoding/decoding JPEG data. This is a wrapper around libjpeg, | 21 // Interface for encoding/decoding JPEG data. This is a wrapper around libjpeg, |
20 // which has an inconvenient interface for callers. This is only used for UI | 22 // which has an inconvenient interface for callers. This is only used for UI |
21 // elements, WebKit has its own more complicated JPEG decoder which handles, | 23 // elements, WebKit has its own more complicated JPEG decoder which handles, |
22 // among other things, partially downloaded data. | 24 // among other things, partially downloaded data. |
23 class CODEC_EXPORT JPEGCodec { | 25 class CODEC_EXPORT JPEGCodec { |
24 public: | 26 public: |
25 enum ColorFormat { | 27 enum ColorFormat { |
26 // 4 bytes per pixel, in RGBA order in mem regardless of endianness. | 28 // 4 bytes per pixel, in RGBA order in mem regardless of endianness. |
27 FORMAT_RGBA, | 29 FORMAT_RGBA, |
28 | 30 |
29 // 4 bytes per pixel, in BGRA order in mem regardless of endianness. | 31 // 4 bytes per pixel, in BGRA order in mem regardless of endianness. |
30 // This is the default Windows DIB order. | 32 // This is the default Windows DIB order. |
31 FORMAT_BGRA, | 33 FORMAT_BGRA, |
32 | 34 |
33 // 4 bytes per pixel, it can be either RGBA or BGRA. It depends on the bit | 35 // 4 bytes per pixel, it can be either RGBA or BGRA. It depends on the bit |
34 // order in kARGB_8888_Config skia bitmap. | 36 // order in kARGB_8888_Config skia bitmap. |
35 FORMAT_SkBitmap | 37 FORMAT_SkBitmap |
36 }; | 38 }; |
37 | 39 |
38 // Encodes the given raw 'input' data, with each pixel being represented as | 40 // Encodes the given raw 'input' pixmap, which includes a pointer to pixels |
39 // given in 'format'. The encoded JPEG data will be written into the supplied | 41 // as well as information describing the pixel format. The encoded JPEG data |
40 // vector and true will be returned on success. On failure (false), the | 42 // will be written into the supplied vector and true will be returned on |
41 // contents of the output buffer are undefined. | 43 // success. On failure (false), the contents of the output buffer are |
| 44 // undefined. |
42 // | 45 // |
43 // w, h: dimensions of the image | |
44 // row_byte_width: the width in bytes of each row. This may be greater than | |
45 // w * bytes_per_pixel if there is extra padding at the end of each row | |
46 // (often, each row is padded to the next machine word). | |
47 // quality: an integer in the range 0-100, where 100 is the highest quality. | 46 // quality: an integer in the range 0-100, where 100 is the highest quality. |
48 static bool Encode(const unsigned char* input, ColorFormat format, | 47 static bool Encode(const SkPixmap& input, |
49 int w, int h, int row_byte_width, | 48 int quality, |
50 int quality, std::vector<unsigned char>* output); | 49 std::vector<unsigned char>* output); |
| 50 |
| 51 // Encodes the 'input' bitmap. The encoded JPEG data will be written into |
| 52 // the supplied vector and true will be returned on success. On failure |
| 53 // (false), the contents of the output buffer are undefined. |
| 54 // |
| 55 // quality: an integer in the range 0-100, where 100 is the highest quality. |
| 56 static bool Encode(const SkBitmap& input, |
| 57 int quality, |
| 58 std::vector<unsigned char>* output); |
51 | 59 |
52 // Decodes the JPEG data contained in input of length input_size. The | 60 // Decodes the JPEG data contained in input of length input_size. The |
53 // decoded data will be placed in *output with the dimensions in *w and *h | 61 // decoded data will be placed in *output with the dimensions in *w and *h |
54 // on success (returns true). This data will be written in the'format' | 62 // on success (returns true). This data will be written in the'format' |
55 // format. On failure, the values of these output variables is undefined. | 63 // format. On failure, the values of these output variables is undefined. |
56 static bool Decode(const unsigned char* input, size_t input_size, | 64 static bool Decode(const unsigned char* input, size_t input_size, |
57 ColorFormat format, std::vector<unsigned char>* output, | 65 ColorFormat format, std::vector<unsigned char>* output, |
58 int* w, int* h); | 66 int* w, int* h); |
59 | 67 |
60 // Decodes the JPEG data contained in input of length input_size. If | 68 // Decodes the JPEG data contained in input of length input_size. If |
61 // successful, a SkBitmap is created and returned. | 69 // successful, a SkBitmap is created and returned. |
62 static std::unique_ptr<SkBitmap> Decode(const unsigned char* input, | 70 static std::unique_ptr<SkBitmap> Decode(const unsigned char* input, |
63 size_t input_size); | 71 size_t input_size); |
64 }; | 72 }; |
65 | 73 |
66 } // namespace gfx | 74 } // namespace gfx |
67 | 75 |
68 #endif // UI_GFX_CODEC_JPEG_CODEC_H_ | 76 #endif // UI_GFX_CODEC_JPEG_CODEC_H_ |
OLD | NEW |