| 1 |
|
| 2 |
|
| 3 |
#ifndef ZMBVENCODER_HH |
| 4 |
#define ZMBVENCODER_HH |
| 5 |
|
| 6 |
#include "MemBuffer.hh" |
| 7 |
#include "aligned.hh" |
| 8 |
|
| 9 |
#include <cstdint> |
| 10 |
#include <span> |
| 11 |
#include <string_view> |
| 12 |
|
| 13 |
#include <zlib.h> |
| 14 |
|
| 15 |
namespace openmsx { |
| 16 |
|
| 17 |
class FrameSource; |
| 18 |
|
| 19 |
class ZMBVEncoder |
| 20 |
{ |
| 21 |
public: |
| 22 |
static constexpr std::string_view CODEC_4CC = "ZMBV"; |
| 23 |
using Pixel = uint32_t; |
| 24 |
|
| 25 |
ZMBVEncoder(unsigned width, unsigned height); |
| 26 |
ZMBVEncoder(const ZMBVEncoder&) = delete; |
| 27 |
ZMBVEncoder(ZMBVEncoder&&) = delete; |
| 28 |
ZMBVEncoder& operator=(const ZMBVEncoder&) = delete; |
| 29 |
ZMBVEncoder& operator=(ZMBVEncoder&&) = delete; |
| 30 |
~ZMBVEncoder() = default; |
| 31 |
|
| 32 |
[[nodiscard]] std::span<const uint8_t> compressFrame(bool keyFrame, const FrameSource* frame); |
| 33 |
|
| 34 |
private: |
| 35 |
void setupBuffers(); |
| 36 |
[[nodiscard]] unsigned neededSize() const; |
| 37 |
void addFullFrame(unsigned& workUsed); |
| 38 |
void addXorFrame (unsigned& workUsed); |
| 39 |
[[nodiscard]] unsigned possibleBlock(int vx, int vy, size_t offset); |
| 40 |
[[nodiscard]] unsigned compareBlock(int vx, int vy, size_t offset); |
| 41 |
void addXorBlock(int vx, int vy, size_t offset, unsigned& workUsed); |
| 42 |
[[nodiscard]] const Pixel* getScaledLine(const FrameSource* frame, unsigned y, Pixel* workBuf) const; |
| 43 |
|
| 44 |
private: |
| 45 |
MemBuffer<uint8_t, SSE_ALIGNMENT> oldFrame; |
| 46 |
MemBuffer<uint8_t, SSE_ALIGNMENT> newFrame; |
| 47 |
MemBuffer<uint8_t, SSE_ALIGNMENT> work; |
| 48 |
MemBuffer<uint8_t> output; |
| 49 |
MemBuffer<size_t> blockOffsets; |
| 50 |
unsigned outputSize; |
| 51 |
|
| 52 |
z_stream zstream; |
| 53 |
|
| 54 |
unsigned width; |
| 55 |
unsigned height; |
| 56 |
size_t pitch; |
| 57 |
}; |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
#endif |