| 1 |
/* |
| 2 |
* Copyright 2024 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
#ifndef SkPDFJPEGHelpers_DEFINED |
| 8 |
#define SkPDFJPEGHelpers_DEFINED |
| 9 |
|
| 10 |
#include "include/codec/SkJpegDecoder.h" |
| 11 |
#include "include/core/SkData.h" |
| 12 |
#include "include/core/SkRefCnt.h" |
| 13 |
#include "include/docs/SkPDFDocument.h" |
| 14 |
#include "include/encode/SkJpegEncoder.h" |
| 15 |
|
| 16 |
class SkPixmap; |
| 17 |
class SkWStream; |
| 18 |
|
| 19 |
#include <memory> |
| 20 |
|
| 21 |
namespace SkPDF::JPEG { |
| 22 |
inline std::unique_ptr<SkCodec> Decode(sk_sp<const SkData> data) { |
| 23 |
return SkJpegDecoder::Decode(data, nullptr, nullptr); |
| 24 |
} |
| 25 |
|
| 26 |
inline bool Encode(SkWStream* dst, const SkPixmap& src, int quality) { |
| 27 |
SkJpegEncoder::Options jOpts; |
| 28 |
jOpts.fQuality = quality; |
| 29 |
return SkJpegEncoder::Encode(dst, src, jOpts); |
| 30 |
} |
| 31 |
|
| 32 |
inline SkPDF::Metadata MetadataWithCallbacks() { |
| 33 |
SkPDF::Metadata m; |
| 34 |
m.jpegDecoder = SkPDF::JPEG::Decode; |
| 35 |
m.jpegEncoder = SkPDF::JPEG::Encode; |
| 36 |
return m; |
| 37 |
} |
| 38 |
|
| 39 |
} // namespace SkPDF::JPEG |
| 40 |
|
| 41 |
#endif |