d6cfb1f1创建于 4月27日历史提交
/*
 * Copyright (c) 2026 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "StreamSourceBase.h"
#include <cstdint>
#include <cstddef>

namespace apng_drawable {
/* *
 * 于内存buffer的数据读取StreamSource
 */
class StreamSourceHarmony : public StreamSourceBase {
public:
    /* *
     * 从内存buffer创建StreamSource
     * @param data 数据指针
     * @param size 数据大小
     */
    StreamSourceHarmony(const uint8_t *data, size_t size);
    StreamSourceHarmony() = delete;
    ~StreamSourceHarmony() override = default;

    /* *
     * 检查PNG签名
     */
    int32_t CheckPngSignature() override;

    /* *
     * 初始化PNG读取回调
     */
    void Init(png_structp png) override;

    /* *
     * 获取错误码
     */
    int32_t GetError() const override
    {
        return mError;
    }

    /* *
     * 重置读取位置(用于重新检查签名)
     */
    void Reset();

    /* *
     * 设置读取偏移量(用于跳过已读取的签名)
     */
    void SetOffset(size_t offset)
    {
        mOffset = offset;
    }

private:
    /* *
     * PNG读取回调函数(静态方法)
     */
    static void Reader(png_structp png, png_bytep data, png_size_t length);

private:
    const uint8_t *mData;
    size_t mSize;
    size_t mOffset;
    int32_t mError;

    // Do not copy this object.
    StreamSourceHarmony(const StreamSourceHarmony &ref);
    StreamSourceHarmony &operator = (const StreamSourceHarmony &ref);
};
}