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

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

Issue 2895953003: Use SkJpegEncoder in gfx jpeg_codec (Closed)
Patch Set: Created 3 years, 7 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"
13 #include "ui/gfx/codec/codec_export.h" 14 #include "ui/gfx/codec/codec_export.h"
14 15
15 class SkBitmap; 16 class SkBitmap;
16 17
17 namespace gfx { 18 namespace gfx {
18 19
19 // Interface for encoding/decoding JPEG data. This is a wrapper around libjpeg, 20 // 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 21 // 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, 22 // elements, WebKit has its own more complicated JPEG decoder which handles,
22 // among other things, partially downloaded data. 23 // among other things, partially downloaded data.
23 class CODEC_EXPORT JPEGCodec { 24 class CODEC_EXPORT JPEGCodec {
24 public: 25 public:
25 enum ColorFormat { 26 enum ColorFormat {
26 // 3 bytes per pixel (packed), in RGB order regardless of endianness.
27 // This is the native JPEG format.
28 FORMAT_RGB,
29
30 // 4 bytes per pixel, in RGBA order in mem regardless of endianness. 27 // 4 bytes per pixel, in RGBA order in mem regardless of endianness.
31 FORMAT_RGBA, 28 FORMAT_RGBA,
32 29
33 // 4 bytes per pixel, in BGRA order in mem regardless of endianness. 30 // 4 bytes per pixel, in BGRA order in mem regardless of endianness.
34 // This is the default Windows DIB order. 31 // This is the default Windows DIB order.
35 FORMAT_BGRA, 32 FORMAT_BGRA,
36 33
37 // 4 bytes per pixel, it can be either RGBA or BGRA. It depends on the bit 34 // 4 bytes per pixel, it can be either RGBA or BGRA. It depends on the bit
38 // order in kARGB_8888_Config skia bitmap. 35 // order in kARGB_8888_Config skia bitmap.
39 FORMAT_SkBitmap 36 FORMAT_SkBitmap
40 }; 37 };
41 38
42 enum LibraryVariant { 39 enum LibraryVariant {
43 SYSTEM_LIBJPEG = 0, 40 SYSTEM_LIBJPEG = 0,
44 LIBJPEG_TURBO, 41 LIBJPEG_TURBO,
45 IJG_LIBJPEG, 42 IJG_LIBJPEG,
46 }; 43 };
47 44
48 // This method helps identify at run time which library chromium is using. 45 // This method helps identify at run time which library chromium is using.
49 static LibraryVariant JpegLibraryVariant(); 46 static LibraryVariant JpegLibraryVariant();
50 47
51 // Encodes the given raw 'input' data, with each pixel being represented as 48 // Encodes the given raw 'input' data, with each pixel being represented as
52 // given in 'format'. The encoded JPEG data will be written into the supplied 49 // given in 'colorType'. The encoded JPEG data will be written into the
53 // vector and true will be returned on success. On failure (false), the 50 // supplied vector and true will be returned on success. On failure (false),
54 // contents of the output buffer are undefined. 51 // the contents of the output buffer are undefined.
55 // 52 //
56 // w, h: dimensions of the image 53 // w, h: dimensions of the image
57 // row_byte_width: the width in bytes of each row. This may be greater than 54 // row_byte_width: the width in bytes of each row. This may be greater than
58 // w * bytes_per_pixel if there is extra padding at the end of each row 55 // w * bytes_per_pixel if there is extra padding at the end of each row
59 // (often, each row is padded to the next machine word). 56 // (often, each row is padded to the next machine word).
60 // quality: an integer in the range 0-100, where 100 is the highest quality. 57 // quality: an integer in the range 0-100, where 100 is the highest quality.
61 static bool Encode(const unsigned char* input, ColorFormat format, 58 static bool Encode(const unsigned char* input,
62 int w, int h, int row_byte_width, 59 SkColorType colorType,
dcheng 2017/06/02 15:35:00 Nit: color_type From a symmetry perspective, it's
scroggo_chromium 2017/06/02 17:35:51 Yes. We're in the process of merging Skia's decode
msarett1 2017/06/07 18:01:14 Yes, I think this is a good future goal.
63 int quality, std::vector<unsigned char>* output); 60 int w,
61 int h,
62 int row_byte_width,
63 int quality,
64 std::vector<unsigned char>* output);
64 65
65 // Decodes the JPEG data contained in input of length input_size. The 66 // Decodes the JPEG data contained in input of length input_size. The
66 // decoded data will be placed in *output with the dimensions in *w and *h 67 // decoded data will be placed in *output with the dimensions in *w and *h
67 // on success (returns true). This data will be written in the'format' 68 // on success (returns true). This data will be written in the'format'
68 // format. On failure, the values of these output variables is undefined. 69 // format. On failure, the values of these output variables is undefined.
69 static bool Decode(const unsigned char* input, size_t input_size, 70 static bool Decode(const unsigned char* input, size_t input_size,
70 ColorFormat format, std::vector<unsigned char>* output, 71 ColorFormat format, std::vector<unsigned char>* output,
71 int* w, int* h); 72 int* w, int* h);
72 73
73 // Decodes the JPEG data contained in input of length input_size. If 74 // Decodes the JPEG data contained in input of length input_size. If
74 // successful, a SkBitmap is created and returned. 75 // successful, a SkBitmap is created and returned.
75 static std::unique_ptr<SkBitmap> Decode(const unsigned char* input, 76 static std::unique_ptr<SkBitmap> Decode(const unsigned char* input,
76 size_t input_size); 77 size_t input_size);
77 }; 78 };
78 79
79 } // namespace gfx 80 } // namespace gfx
80 81
81 #endif // UI_GFX_CODEC_JPEG_CODEC_H_ 82 #endif // UI_GFX_CODEC_JPEG_CODEC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698