Chromium Code Reviews| OLD | NEW |
|---|---|
| (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, | |
| 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, | |
| 46 const SkPixmap& src, | |
| 47 const SkJpegEncoder::Options&); | |
| 48 | |
| 49 static std::unique_ptr<ImageEncoder> Make(Vector<unsigned char>* dst, | |
| 50 const SkPixmap& src, | |
| 51 const SkPngEncoder::Options&); | |
| 52 | |
| 53 bool encodeRows(int numRows) { return encoder_->encodeRows(numRows); } | |
| 54 | |
| 55 private: | |
| 56 ImageEncoder(Vector<unsigned char>* dst) : dst_(dst) {} | |
| 57 | |
| 58 VectorWStream dst_; | |
|
msarett1
2017/05/15 23:49:08
If I were to make this a ptr, I think I could move
| |
| 59 std::unique_ptr<SkEncoder> encoder_; | |
| 60 }; | |
| 61 }; | |
| 62 | |
| 63 #endif | |
| OLD | NEW |