ZMBVEncoder.hh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Code based on DOSBox-0.65
  2. #ifndef ZMBVENCODER_HH
  3. #define ZMBVENCODER_HH
  4. #include "PixelFormat.hh"
  5. #include "MemBuffer.hh"
  6. #include <cstdint>
  7. #include <zlib.h>
  8. namespace openmsx {
  9. class FrameSource;
  10. template<class P> class PixelOperations;
  11. class ZMBVEncoder
  12. {
  13. public:
  14. static constexpr const char CODEC_4CC[5] = "ZMBV"; // 4 + zero-terminator
  15. ZMBVEncoder(unsigned width, unsigned height, unsigned bpp);
  16. void compressFrame(bool keyFrame, FrameSource* frame,
  17. void*& buffer, unsigned& written);
  18. private:
  19. enum Format {
  20. ZMBV_FORMAT_16BPP = 6,
  21. ZMBV_FORMAT_32BPP = 8
  22. };
  23. void setupBuffers(unsigned bpp);
  24. unsigned neededSize() const;
  25. template<class P> void addFullFrame(const PixelFormat& pixelFormat, unsigned& workUsed);
  26. template<class P> void addXorFrame (const PixelFormat& pixelFormat, unsigned& workUsed);
  27. template<class P> unsigned possibleBlock(int vx, int vy, unsigned offset);
  28. template<class P> unsigned compareBlock(int vx, int vy, unsigned offset);
  29. template<class P> void addXorBlock(
  30. const PixelOperations<P>& pixelOps, int vx, int vy,
  31. unsigned offset, unsigned& workUsed);
  32. const void* getScaledLine(FrameSource* frame, unsigned y, void* workBuf) const;
  33. MemBuffer<uint8_t, SSE2_ALIGNMENT> oldframe;
  34. MemBuffer<uint8_t, SSE2_ALIGNMENT> newframe;
  35. MemBuffer<uint8_t, SSE2_ALIGNMENT> work;
  36. MemBuffer<uint8_t> output;
  37. MemBuffer<unsigned> blockOffsets;
  38. unsigned outputSize;
  39. z_stream zstream;
  40. const unsigned width;
  41. const unsigned height;
  42. unsigned pitch;
  43. unsigned pixelSize;
  44. Format format;
  45. };
  46. } // namespace openmsx
  47. #endif