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

Side by Side Diff: third_party/WebKit/Source/platform/image-encoders/ImageEncoder.h

Issue 2891373002: Use SkPngEncoder and SkWebpEncoder in WebKit platform (Closed)
Patch Set: Adjust comments 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 ImageEncoder_h 5 #ifndef ImageEncoder_h
6 #define ImageEncoder_h 6 #define ImageEncoder_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "platform/wtf/Vector.h" 9 #include "platform/wtf/Vector.h"
10 #include "third_party/skia/include/core/SkStream.h" 10 #include "third_party/skia/include/core/SkStream.h"
11 #include "third_party/skia/include/encode/SkJpegEncoder.h" 11 #include "third_party/skia/include/encode/SkJpegEncoder.h"
12 #include "third_party/skia/include/encode/SkPngEncoder.h" 12 #include "third_party/skia/include/encode/SkPngEncoder.h"
13 #include "third_party/skia/include/encode/SkWebpEncoder.h"
13 14
14 namespace blink { 15 namespace blink {
15 16
16 class VectorWStream : public SkWStream { 17 class VectorWStream : public SkWStream {
17 public: 18 public:
18 VectorWStream(Vector<unsigned char>* dst) : dst_(dst) { 19 VectorWStream(Vector<unsigned char>* dst) : dst_(dst) {
19 DCHECK(dst_); 20 DCHECK(dst_);
20 DCHECK_EQ(0UL, dst->size()); 21 DCHECK_EQ(0UL, dst->size());
21 } 22 }
22 23
(...skipping 12 matching lines...) Expand all
35 class PLATFORM_EXPORT ImageEncoder { 36 class PLATFORM_EXPORT ImageEncoder {
36 public: 37 public:
37 static bool Encode(Vector<unsigned char>* dst, 38 static bool Encode(Vector<unsigned char>* dst,
38 const SkPixmap& src, 39 const SkPixmap& src,
39 const SkJpegEncoder::Options&); 40 const SkJpegEncoder::Options&);
40 41
41 static bool Encode(Vector<unsigned char>* dst, 42 static bool Encode(Vector<unsigned char>* dst,
42 const SkPixmap& src, 43 const SkPixmap& src,
43 const SkPngEncoder::Options&); 44 const SkPngEncoder::Options&);
44 45
46 static bool Encode(Vector<unsigned char>* dst,
47 const SkPixmap& src,
48 const SkWebpEncoder::Options&);
49
45 static std::unique_ptr<ImageEncoder> Create(Vector<unsigned char>* dst, 50 static std::unique_ptr<ImageEncoder> Create(Vector<unsigned char>* dst,
46 const SkPixmap& src, 51 const SkPixmap& src,
47 const SkJpegEncoder::Options&); 52 const SkJpegEncoder::Options&);
48 53
49 static std::unique_ptr<ImageEncoder> Create(Vector<unsigned char>* dst, 54 static std::unique_ptr<ImageEncoder> Create(Vector<unsigned char>* dst,
50 const SkPixmap& src, 55 const SkPixmap& src,
51 const SkPngEncoder::Options&); 56 const SkPngEncoder::Options&);
52 57
53 bool encodeRows(int numRows) { return encoder_->encodeRows(numRows); } 58 bool encodeRows(int numRows) { return encoder_->encodeRows(numRows); }
54 59
55 /** 60 /**
56 * If quality is in [0, 1], this will simply convert to a [0, 100] 61 * If quality is in [0, 1], this will simply convert to a [0, 100]
57 * integer scale (which is what is used by libjpeg-turbo). 62 * integer scale (which is what is used by libjpeg-turbo).
58 * 63 *
59 * Otherwise, this will return the default value. 64 * Otherwise, this will return the default value.
60 */ 65 */
61 static int ComputeJpegQuality(double quality); 66 static int ComputeJpegQuality(double quality);
62 67
68 /**
69 * Sets Skia encoding options based on the requested quality.
70 *
71 * If quality is 1, this will signal a lossless encode.
72 *
73 * Otherwise, this will use webp lossy encoding.
74 * If quality is in [0, 1), this will simply convert to a [0, 100)
75 * float scale (which is what is used by libwebp). If the quality
76 * is out of range, this will use the default value.
scroggo_chromium 2017/05/22 13:35:04 What is the default value? Will it be lossy or los
msarett1 2017/05/22 15:33:56 Added comments.
77 */
78 static SkWebpEncoder::Options ComputeWebpOptions(
79 double quality,
80 SkTransferFunctionBehavior unpremulBehavior);
81
63 private: 82 private:
64 ImageEncoder(Vector<unsigned char>* dst) : dst_(dst) {} 83 ImageEncoder(Vector<unsigned char>* dst) : dst_(dst) {}
65 84
66 VectorWStream dst_; 85 VectorWStream dst_;
67 std::unique_ptr<SkEncoder> encoder_; 86 std::unique_ptr<SkEncoder> encoder_;
68 }; 87 };
69 }; 88 };
70 89
71 #endif 90 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698