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

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

Issue 2895953003: Use SkJpegEncoder in gfx jpeg_codec (Closed)
Patch Set: Response to comments Created 3 years, 6 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
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_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 46 // w, h: dimensions of the image
44 // row_byte_width: the width in bytes of each row. This may be greater than 47 // 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 48 // 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). 49 // (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. 50 // quality: an integer in the range 0-100, where 100 is the highest quality.
48 static bool Encode(const unsigned char* input, ColorFormat format, 51 static bool Encode(const SkPixmap& input,
dcheng 2017/06/12 20:35:43 Any reason not to use SkBitmap? This avoids all th
msarett1 2017/06/12 20:57:56 This is a good question, especially because there
dcheng 2017/06/12 21:00:15 Adding an overload is fine. I'd be ok with SkPixma
msarett1 2017/06/12 21:43:11 Done.
49 int w, int h, int row_byte_width, 52 int quality,
50 int quality, std::vector<unsigned char>* output); 53 std::vector<unsigned char>* output);
51 54
52 // Decodes the JPEG data contained in input of length input_size. The 55 // 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 56 // 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' 57 // on success (returns true). This data will be written in the'format'
55 // format. On failure, the values of these output variables is undefined. 58 // format. On failure, the values of these output variables is undefined.
56 static bool Decode(const unsigned char* input, size_t input_size, 59 static bool Decode(const unsigned char* input, size_t input_size,
57 ColorFormat format, std::vector<unsigned char>* output, 60 ColorFormat format, std::vector<unsigned char>* output,
58 int* w, int* h); 61 int* w, int* h);
59 62
60 // Decodes the JPEG data contained in input of length input_size. If 63 // Decodes the JPEG data contained in input of length input_size. If
61 // successful, a SkBitmap is created and returned. 64 // successful, a SkBitmap is created and returned.
62 static std::unique_ptr<SkBitmap> Decode(const unsigned char* input, 65 static std::unique_ptr<SkBitmap> Decode(const unsigned char* input,
63 size_t input_size); 66 size_t input_size);
64 }; 67 };
65 68
66 } // namespace gfx 69 } // namespace gfx
67 70
68 #endif // UI_GFX_CODEC_JPEG_CODEC_H_ 71 #endif // UI_GFX_CODEC_JPEG_CODEC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698