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 "experimental/rust_png/decoder/SkPngRustDecoder.h"
9
10 #include <utility>
11
12 #include "experimental/rust_png/decoder/impl/SkPngRustCodec.h"
13 #include "include/core/SkStream.h"
14
15 namespace SkPngRustDecoder {
16
IsPng(const void * buff,size_t bytesRead)17 bool IsPng(const void* buff, size_t bytesRead) {
18 static constexpr unsigned char pngSignature[] = {
19 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
20 if (bytesRead < sizeof(pngSignature)) {
21 return false;
22 }
23
24 return memcmp(buff, pngSignature, sizeof(pngSignature)) == 0;
25 }
26
Decode(std::unique_ptr<SkStream> stream,SkCodec::Result * result,SkCodecs::DecodeContext)27 std::unique_ptr<SkCodec> Decode(std::unique_ptr<SkStream> stream,
28 SkCodec::Result* result,
29 SkCodecs::DecodeContext) {
30 return SkPngRustCodec::MakeFromStream(std::move(stream), result);
31 }
32
33 } // namespace SkPngRustDecoder
34