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

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

Issue 2878333004: Use SkJpegEncoder in WebKit platform (Closed)
Patch Set: Use default jpeg quality when input is out of range 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef ImageEncoder_h
6 #define ImageEncoder_h
7
8 #include "platform/PlatformExport.h"
9 #include "platform/wtf/Vector.h"
10 #include "third_party/skia/include/core/SkStream.h"
11 #include "third_party/skia/include/encode/SkJpegEncoder.h"
12 #include "third_party/skia/include/encode/SkPngEncoder.h"
13
14 namespace blink {
15
16 class VectorWStream : public SkWStream {
17 public:
18 VectorWStream(Vector<unsigned char>* dst) : dst_(dst) {
19 DCHECK(dst_);
20 DCHECK_EQ(0UL, dst->size());
21 }
22
23 bool write(const void* buffer, size_t size) override {
24 dst_->Append((const unsigned char*)buffer, size);
25 return true;
26 }
27
28 size_t bytesWritten() const override { return dst_->size(); }
29
30 private:
31 // Does not have ownership.
32 Vector<unsigned char>* dst_;
33 };
34
35 class PLATFORM_EXPORT ImageEncoder {
36 public:
37 static bool Encode(Vector<unsigned char>* dst,
f(malita) 2017/05/16 21:09:46 I was actually thinking encode() would be non-stat
msarett1 2017/05/17 02:26:59 Acknowledged.
38 const SkPixmap& src,
39 const SkJpegEncoder::Options&);
40
41 static bool Encode(Vector<unsigned char>* dst,
42 const SkPixmap& src,
43 const SkPngEncoder::Options&);
44
45 static std::unique_ptr<ImageEncoder> Make(Vector<unsigned char>* dst,
f(malita) 2017/05/16 21:09:46 Nit: "Create" is the common factory name in Blink.
msarett1 2017/05/17 02:26:59 Done.
46 const SkPixmap& src,
47 const SkJpegEncoder::Options&);
48
49 static std::unique_ptr<ImageEncoder> Make(Vector<unsigned char>* dst,
f(malita) 2017/05/16 21:09:46 Ditto.
msarett1 2017/05/17 02:26:59 Done.
50 const SkPixmap& src,
51 const SkPngEncoder::Options&);
52
53 bool encodeRows(int numRows) { return encoder_->encodeRows(numRows); }
54
55 /**
56 * 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).
58 *
59 * Otherwise, this will return the default value.
60 */
61 static int ComputeJpegQuality(double quality);
62
63 private:
64 ImageEncoder(Vector<unsigned char>* dst) : dst_(dst) {}
65
66 VectorWStream dst_;
67 std::unique_ptr<SkEncoder> encoder_;
68 };
69 };
70
71 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698