openMSX
ZMBVEncoder.hh
Go to the documentation of this file.
1 // Code based on DOSBox-0.65
2 
3 #ifndef ZMBVENCODER_HH
4 #define ZMBVENCODER_HH
5 
6 #include "PixelFormat.hh"
7 #include "MemBuffer.hh"
8 #include "aligned.hh"
9 #include <concepts>
10 #include <cstdint>
11 #include <span>
12 #include <zlib.h>
13 
14 namespace openmsx {
15 
16 class FrameSource;
17 template<std::unsigned_integral P> class PixelOperations;
18 
20 {
21 public:
22  static constexpr const char CODEC_4CC[5] = "ZMBV"; // 4 + zero-terminator
23 
24  ZMBVEncoder(unsigned width, unsigned height, unsigned bpp);
25 
26  [[nodiscard]] std::span<const uint8_t> compressFrame(bool keyFrame, FrameSource* frame);
27 
28 private:
29  enum Format {
30  ZMBV_FORMAT_16BPP = 6,
31  ZMBV_FORMAT_32BPP = 8
32  };
33 
34  void setupBuffers(unsigned bpp);
35  [[nodiscard]] unsigned neededSize() const;
36  template<std::unsigned_integral P> void addFullFrame(const PixelFormat& pixelFormat, unsigned& workUsed);
37  template<std::unsigned_integral P> void addXorFrame (const PixelFormat& pixelFormat, unsigned& workUsed);
38  template<std::unsigned_integral P> [[nodiscard]] unsigned possibleBlock(int vx, int vy, unsigned offset);
39  template<std::unsigned_integral P> [[nodiscard]] unsigned compareBlock(int vx, int vy, unsigned offset);
40  template<std::unsigned_integral P> void addXorBlock(
41  const PixelOperations<P>& pixelOps, int vx, int vy,
42  unsigned offset, unsigned& workUsed);
43  [[nodiscard]] const void* getScaledLine(FrameSource* frame, unsigned y, void* workBuf) const;
44 
45 private:
49  MemBuffer<uint8_t> output;
50  MemBuffer<unsigned> blockOffsets;
51  unsigned outputSize;
52 
53  z_stream zstream;
54 
55  const unsigned width;
56  const unsigned height;
57  unsigned pitch;
58  unsigned pixelSize;
59  Format format;
60 };
61 
62 } // namespace openmsx
63 
64 #endif
Interface for getting lines from a video frame.
Definition: FrameSource.hh:17
std::span< const uint8_t > compressFrame(bool keyFrame, FrameSource *frame)
Definition: ZMBVEncoder.cc:353
static constexpr const char CODEC_4CC[5]
Definition: ZMBVEncoder.hh:22
ZMBVEncoder(unsigned width, unsigned height, unsigned bpp)
Definition: ZMBVEncoder.cc:124
This file implemented 3 utility functions:
Definition: Autofire.cc:9