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