#include "FrameFormat.h"

#include "OpenGLWidgetAPI.h"

#include "spdlog/spdlog.h"



Frame_YUV420P::Frame_YUV420P() : FrameBase(EFrameFormat::Frame_YUV420P)
{
    frameData = new Image_YUV420P();
}

Frame_YUV420P::~Frame_YUV420P()
{
    if(frameData != nullptr)
    {
        delete frameData;
        frameData = nullptr;
    }
}

Frame_RGBA8888::Frame_RGBA8888() : FrameBase(EFrameFormat::Frame_RGBA8888)
{
    frameData = new QImage();
}

Frame_RGBA8888::~Frame_RGBA8888()
{
    if(frameData != nullptr)
    {
        delete frameData;
        frameData = nullptr;
    }
}

/* 删除一个图片 */
bool deleteOneFrame(FrameBase* frame)
{
    if(frame == nullptr)
    {
        SPDLOG_DEBUG("传入的帧指针为空，无法删除");
        return false;
    }
    if(frame->frameFormat() == EFrameFormat::Frame_YUV420P)
    {
        Frame_YUV420P* yuvFrame = static_cast<Frame_YUV420P*>(frame);
        delete yuvFrame;
    }else if(frame->frameFormat() == EFrameFormat::Frame_RGBA8888)
    {
        Frame_RGBA8888* rgbaFrame = static_cast<Frame_RGBA8888*>(frame);
        delete rgbaFrame;
    } else {
        SPDLOG_WARN("未知的帧格式，无法删除。");
        return false;
    }

    return true;
}


