DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/libs/zmbv/zmbv.h
00001 /*
00002  *  Copyright (C) 2002-2020  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License along
00015  *  with this program; if not, write to the Free Software Foundation, Inc.,
00016  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #ifndef DOSBOX_DOSBOX_H
00020 # ifndef INLINE
00021 #  ifdef _MSC_VER
00022 #   define INLINE __forceinline
00023 #  else
00024 #   define INLINE inline
00025 #  endif
00026 # endif
00027 #endif
00028 
00029 #define CODEC_4CC "ZMBV"
00030 
00031 typedef enum {
00032         ZMBV_FORMAT_NONE                = 0x00,
00033         ZMBV_FORMAT_1BPP                = 0x01,
00034         ZMBV_FORMAT_2BPP                = 0x02,
00035         ZMBV_FORMAT_4BPP                = 0x03,
00036         ZMBV_FORMAT_8BPP                = 0x04,
00037         ZMBV_FORMAT_15BPP       = 0x05,
00038         ZMBV_FORMAT_16BPP       = 0x06,
00039         ZMBV_FORMAT_24BPP       = 0x07,
00040         ZMBV_FORMAT_32BPP       = 0x08
00041 } zmbv_format_t;
00042 
00043 void Msg(const char fmt[], ...);
00044 class VideoCodec {
00045 private:
00046         struct FrameBlock {
00047                 int start;
00048                 int dx,dy;
00049         };
00050         struct CodecVector {
00051                 int x,y;
00052                 int slot;
00053         };
00054         struct KeyframeHeader {
00055                 unsigned char high_version;
00056                 unsigned char low_version;
00057                 unsigned char compression;
00058                 unsigned char format;
00059                 unsigned char blockwidth,blockheight;
00060         };
00061 
00062         struct {
00063                 int             linesDone;
00064                 int             writeSize;
00065                 int             writeDone;
00066                 unsigned char   *writeBuf;
00067         } compress;
00068 
00069         CodecVector VectorTable[512];
00070         int VectorCount;
00071 
00072         unsigned char *oldframe, *newframe;
00073         unsigned char *buf1, *buf2, *work;
00074         int bufsize;
00075 
00076         int blockcount; 
00077         FrameBlock * blocks;
00078 
00079         int workUsed, workPos;
00080 
00081         int palsize;
00082         char palette[256*4];
00083         int height, width, pitch;
00084         zmbv_format_t format;
00085         int pixelsize;
00086 
00087         z_stream zstream;
00088 
00089         // methods
00090         void FreeBuffers(void);
00091         void CreateVectorTable(void);
00092         bool SetupBuffers(zmbv_format_t format, int blockwidth, int blockheight);
00093 
00094         template<class P>
00095                 void AddXorFrame(void);
00096         template<class P>
00097                 void UnXorFrame(void);
00098         template<class P>
00099                 INLINE int PossibleBlock(int vx,int vy,FrameBlock * block);
00100         template<class P>
00101                 INLINE int CompareBlock(int vx,int vy,FrameBlock * block);
00102         template<class P>
00103                 INLINE void AddXorBlock(int vx,int vy,FrameBlock * block);
00104         template<class P>
00105                 INLINE void UnXorBlock(int vx,int vy,FrameBlock * block);
00106         template<class P>
00107                 INLINE void CopyBlock(int vx, int vy,FrameBlock * block);
00108 public:
00109         VideoCodec();
00110         bool SetupCompress( int _width, int _height);
00111         bool SetupDecompress( int _width, int _height);
00112         zmbv_format_t BPPFormat( int bpp );
00113         int NeededSize( int _width, int _height, zmbv_format_t _format);
00114 
00115         void CompressLines(int lineCount, void *lineData[]);
00116         bool PrepareCompressFrame(int flags,  zmbv_format_t _format, char * pal, void *writeBuf, int writeSize);
00117         int FinishCompressFrame( void );
00118         bool DecompressFrame(void * framedata, int size);
00119         void Output_UpsideDown_24(void * output);
00120 };