| 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/codec/SkPngRustDecoder.h" |
| 9 |
|
| 10 |
#include <utility> |
| 11 |
|
| 12 |
#include "include/core/SkStream.h" |
| 13 |
#include "src/codec/SkPngRustCodec.h" |
| 14 |
|
| 15 |
namespace SkPngRustDecoder { |
| 16 |
|
| 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 |
|
| 27 |
std::unique_ptr<SkCodec> Decode(std::unique_ptr<SkStream> stream, |
| 28 |
SkCodec::Result* result, |
| 29 |
SkCodecs::DecodeContext) { |
| 30 |
SkCodec::Result resultStorage; |
| 31 |
if (!result) { |
| 32 |
result = &resultStorage; |
| 33 |
} |
| 34 |
return SkPngRustCodec::MakeFromStream(std::move(stream), result); |
| 35 |
} |
| 36 |
|
| 37 |
} // namespace SkPngRustDecoder |