| 1 |
/* |
| 2 |
* Copyright 2021 Google Inc. |
| 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 |
#ifndef SkJpegxlCodec_DEFINED |
| 9 |
#define SkJpegxlCodec_DEFINED |
| 10 |
|
| 11 |
#include "include/codec/SkEncodedImageFormat.h" |
| 12 |
#include "include/core/SkData.h" |
| 13 |
#include "include/core/SkRefCnt.h" |
| 14 |
#include "src/codec/SkScalingCodec.h" |
| 15 |
|
| 16 |
#include <cstddef> |
| 17 |
#include <memory> |
| 18 |
|
| 19 |
class SkCodec; |
| 20 |
class SkFrameHolder; |
| 21 |
class SkJpegxlCodecPriv; |
| 22 |
class SkStream; |
| 23 |
struct SkEncodedInfo; |
| 24 |
struct SkImageInfo; |
| 25 |
|
| 26 |
/* |
| 27 |
* |
| 28 |
* This class implements the decoding for jpegxl images |
| 29 |
* |
| 30 |
*/ |
| 31 |
class SkJpegxlCodec : public SkScalingCodec { |
| 32 |
public: |
| 33 |
static bool IsJpegxl(const void*, size_t); |
| 34 |
|
| 35 |
/* |
| 36 |
* Assumes IsJpegxl was called and returned true |
| 37 |
* Takes ownership of the stream |
| 38 |
*/ |
| 39 |
static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*); |
| 40 |
|
| 41 |
protected: |
| 42 |
/* TODO(eustas): implement when downscaling is supported. */ |
| 43 |
/* SkISize onGetScaledDimensions(float desiredScale) const override; */ |
| 44 |
|
| 45 |
/* TODO(eustas): implement when up-/down-scaling is supported. */ |
| 46 |
/* bool onDimensionsSupported(const SkISize&) override; */ |
| 47 |
|
| 48 |
SkEncodedImageFormat onGetEncodedFormat() const override { |
| 49 |
return SkEncodedImageFormat::kJPEGXL; |
| 50 |
} |
| 51 |
|
| 52 |
Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, |
| 53 |
const Options& options, int* rowsDecodedPtr) override; |
| 54 |
|
| 55 |
/* TODO(eustas): add support for transcoded JPEG images? */ |
| 56 |
/* bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes&, |
| 57 |
SkYUVAPixmapInfo*) const override; */ |
| 58 |
|
| 59 |
/* TODO(eustas): add support for transcoded JPEG images? */ |
| 60 |
/* Result onGetYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps) override; */ |
| 61 |
|
| 62 |
/* TODO(eustas): implement when cropped output is supported. */ |
| 63 |
/* bool onGetValidSubset(SkIRect* desiredSubset) const override; */ |
| 64 |
|
| 65 |
bool onRewind() override; |
| 66 |
|
| 67 |
/* TODO(eustas): top-down by default; do we need something else? */ |
| 68 |
/* SkScanlineOrder onGetScanlineOrder() const override; */ |
| 69 |
/* int onOutputScanline(int inputScanline) const override; */ |
| 70 |
|
| 71 |
bool conversionSupported(const SkImageInfo&, bool, bool) override; |
| 72 |
|
| 73 |
int onGetFrameCount() override; |
| 74 |
|
| 75 |
bool onGetFrameInfo(int, FrameInfo*) const override; |
| 76 |
|
| 77 |
int onGetRepetitionCount() override; |
| 78 |
IsAnimated onIsAnimated() override; |
| 79 |
|
| 80 |
private: |
| 81 |
const SkFrameHolder* getFrameHolder() const override; |
| 82 |
|
| 83 |
// Result onStartScanlineDecode( |
| 84 |
// const SkImageInfo& /*dstInfo*/, const Options& /*options*/) override; |
| 85 |
// Result onStartIncrementalDecode( |
| 86 |
// const SkImageInfo& /*dstInfo*/, void*, size_t, const Options&) override; |
| 87 |
// Result onIncrementalDecode(int*) override; |
| 88 |
// bool onSkipScanlines(int /*countLines*/) override; |
| 89 |
// int onGetScanlines(void* /*dst*/, int /*countLines*/, size_t /*rowBytes*/) override; |
| 90 |
// SkSampler* getSampler(bool /*createIfNecessary*/) override; |
| 91 |
|
| 92 |
// Opaque codec implementation for lightweight header file. |
| 93 |
std::unique_ptr<SkJpegxlCodecPriv> fCodec; |
| 94 |
sk_sp<const SkData> fData; |
| 95 |
|
| 96 |
bool scanFrames(); |
| 97 |
static void imageOutCallback( |
| 98 |
void* opaque, size_t x, size_t y, size_t num_pixels, const void* pixels); |
| 99 |
|
| 100 |
SkJpegxlCodec(std::unique_ptr<SkJpegxlCodecPriv> codec, |
| 101 |
SkEncodedInfo&& info, |
| 102 |
std::unique_ptr<SkStream> stream, |
| 103 |
sk_sp<const SkData> data); |
| 104 |
|
| 105 |
using INHERITED = SkScalingCodec; |
| 106 |
}; |
| 107 |
|
| 108 |
#endif |