110 lines
2.7 KiB
C++
110 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include <optional>
|
|
|
|
namespace RawFileTools
|
|
{
|
|
// 图像像素格式
|
|
enum ePixelType
|
|
{
|
|
ePT_RGBA32 = 1, // packed RGB 8:8:8, 24bpp, RGBRGB...
|
|
ePT_RGBA24 = 2, // packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
|
|
ePT_YUV422 = 3, // packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
|
|
ePT_YUV420P = 4, // planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
|
|
ePT_YV12 = 5, // packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
|
|
ePT_Y16U = 6, // Y , 16bpp
|
|
ePT_Y16 = 7, // Y , 16bpp
|
|
ePT_Y8 = 8, // Y , 8bpp
|
|
};
|
|
// 字节序
|
|
enum eByteOrder
|
|
{
|
|
eBO_LittleEndian = 1, // 低字节在前
|
|
eBO_BigEndian = 2, // 高字节在前
|
|
};
|
|
// 帧格式
|
|
struct GFrameFormat
|
|
{
|
|
int nImageWidth; // 图像宽度
|
|
int nImageHeight; // 图像高度
|
|
int nParamStartLine; // 参数起始行
|
|
int nParamLineCount; // 参数行数
|
|
int nFrameRate; // 帧率
|
|
int dBytesOfPixel; // 像素字节数
|
|
eByteOrder eBO; // 字节序
|
|
ePixelType ePT; // 像素类型
|
|
};
|
|
|
|
|
|
|
|
class GuideRawFileStream
|
|
{
|
|
|
|
public:
|
|
using ErrorCode = int;
|
|
|
|
explicit GuideRawFileStream(const std::string& rawPath,
|
|
const GFrameFormat& format);
|
|
|
|
~GuideRawFileStream();
|
|
|
|
/*阻塞主线程*/
|
|
bool isReadReady()const ;
|
|
|
|
size_t getTotalFrameCount()const;
|
|
ErrorCode getErrorCode()const;
|
|
std::string getErrorWhat();
|
|
std::optional<std::vector<char>> getImageDataWithParame(size_t currentFrame)const;
|
|
std::optional<std::vector<char>> getImageData(size_t currentFrame)const ;
|
|
|
|
|
|
public:
|
|
class GuideRawFileStreamIterator;
|
|
|
|
public:
|
|
GuideRawFileStreamIterator begin()const;
|
|
|
|
GuideRawFileStreamIterator end()const;
|
|
|
|
private:
|
|
void startReadFile();
|
|
struct privateData;
|
|
std::unique_ptr<privateData> impl;
|
|
|
|
};
|
|
|
|
class GuideRawFileStream::GuideRawFileStreamIterator
|
|
{
|
|
public:
|
|
|
|
GuideRawFileStreamIterator(const GuideRawFileStream* stream, size_t currentFrame = 0);
|
|
|
|
GuideRawFileStreamIterator(const GuideRawFileStreamIterator& rhs)noexcept;
|
|
std::vector<char> operator*()const = delete;
|
|
|
|
GuideRawFileStreamIterator& operator--()noexcept;
|
|
GuideRawFileStreamIterator operator--(int)noexcept;
|
|
GuideRawFileStreamIterator& operator++()noexcept;
|
|
GuideRawFileStreamIterator operator++(int)noexcept;
|
|
|
|
bool operator ==(const GuideRawFileStreamIterator& other)const;
|
|
|
|
bool operator != (const GuideRawFileStreamIterator& other)const;
|
|
|
|
[[nodiscard]] std::optional<std::vector<char>> getImageDataWithParame();
|
|
[[nodiscard]] std::optional<std::vector<char>> getImageData();
|
|
|
|
|
|
size_t getCurrentFrameCount()const;
|
|
|
|
private:
|
|
const GuideRawFileStream* stream_;
|
|
size_t current_frame;
|
|
};
|
|
|
|
|
|
|
|
}//namespace RawFileTools
|