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 onGetEncodedFormat()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 79 private: 80 const SkFrameHolder* getFrameHolder() const override; 81 82 // Result onStartScanlineDecode( 83 // const SkImageInfo& /*dstInfo*/, const Options& /*options*/) override; 84 // Result onStartIncrementalDecode( 85 // const SkImageInfo& /*dstInfo*/, void*, size_t, const Options&) override; 86 // Result onIncrementalDecode(int*) override; 87 // bool onSkipScanlines(int /*countLines*/) override; 88 // int onGetScanlines(void* /*dst*/, int /*countLines*/, size_t /*rowBytes*/) override; 89 // SkSampler* getSampler(bool /*createIfNecessary*/) override; 90 91 // Opaque codec implementation for lightweight header file. 92 std::unique_ptr<SkJpegxlCodecPriv> fCodec; 93 sk_sp<SkData> fData; 94 95 bool scanFrames(); 96 static void imageOutCallback( 97 void* opaque, size_t x, size_t y, size_t num_pixels, const void* pixels); 98 99 SkJpegxlCodec(std::unique_ptr<SkJpegxlCodecPriv> codec, 100 SkEncodedInfo&& info, 101 std::unique_ptr<SkStream> stream, 102 sk_sp<SkData> data); 103 104 using INHERITED = SkScalingCodec; 105 }; 106 107 #endif 108