Debian Codegraph @

src/encode/SkPngRustEncoder.cpp

raw
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
8 #include "include/encode/SkPngRustEncoder.h"
9
10 #include <memory>
11
12 #include "include/core/SkBitmap.h"
13 #include "include/core/SkImage.h"
14 #include "include/core/SkStream.h"
15 #include "include/encode/SkEncoder.h"
16 #include "src/encode/SkPngRustEncoderImpl.h"
17 #include "src/image/SkImage_Base.h"
18
19 namespace SkPngRustEncoder {
20
21 bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options) {
22 std::unique_ptr<SkEncoder> encoder = Make(dst, src, options);
23 return encoder && encoder->encodeRows(src.height());
24 }
25
26 sk_sp<SkData> Encode(const SkPixmap& src, const Options& options) {
27 SkDynamicMemoryWStream stream;
28 if (!Encode(&stream, src, options)) {
29 return nullptr;
30 }
31 return stream.detachAsData();
32 }
33
34 sk_sp<SkData> Encode(GrDirectContext* ctx, const SkImage* img, const Options& options) {
35 if (!img) {
36 return nullptr;
37 }
38
39 SkBitmap bm;
40 if (!as_IB(img)->getROPixels(ctx, &bm)) {
41 return nullptr;
42 }
43
44 return Encode(bm.pixmap(), options);
45 }
46
47 std::unique_ptr<SkEncoder> Make(SkWStream* dst, const SkPixmap& src, const Options& options) {
48 return SkPngRustEncoderImpl::Make(dst, src, options);
49 }
50
51 } // namespace SkPngRustEncoder