* Copyright 2023 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkJpegSourceMgr_codec_DEFINED
#define SkJpegSourceMgr_codec_DEFINED
#include "include/core/SkTypes.h"
#ifdef SK_CODEC_DECODES_JPEG_GAINMAPS
#include "include/core/SkRefCnt.h"
#endif
#include <cstddef>
#include <cstdint>
#include <memory>
#ifdef SK_CODEC_DECODES_JPEG_GAINMAPS
#include <vector>
#endif
class SkStream;
#ifdef SK_CODEC_DECODES_JPEG_GAINMAPS
class SkData;
class SkJpegSegmentScanner;
struct SkJpegSegment;
#endif
* Interface to adapt an SkStream to the jpeg_source_mgr interface. This interface has different
* implementations for SkStreams with different capabilities.
*/
class SkJpegSourceMgr {
public:
static std::unique_ptr<SkJpegSourceMgr> Make(SkStream* stream, size_t bufferSize = 1024);
virtual ~SkJpegSourceMgr();
virtual void initSource(const uint8_t*& nextInputByte, size_t& bytesInBuffer) = 0;
virtual bool fillInputBuffer(const uint8_t*& nextInputByte, size_t& bytesInBuffer) = 0;
virtual bool skipInputBytes(size_t bytes,
const uint8_t*& nextInputByte,
size_t& bytesInBuffer) = 0;
#ifdef SK_CODEC_DECODES_JPEG_GAINMAPS
virtual const std::vector<SkJpegSegment>& getAllSegments() = 0;
virtual sk_sp<SkData> getSubsetData(size_t offset, size_t size, bool* wasCopied = nullptr) = 0;
virtual sk_sp<SkData> getSegmentParameters(const SkJpegSegment& segment) = 0;
#endif
protected:
explicit SkJpegSourceMgr(SkStream* stream);
SkStream* const fStream;
#ifdef SK_CODEC_DECODES_JPEG_GAINMAPS
std::unique_ptr<SkJpegSegmentScanner> fScanner;
#endif
};
#endif