DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/libs/zmbv/zmbv.h
00001 /*
00002  *  Copyright (C) 2002-2013  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
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef DOSBOX_DOSBOX_H
00020 #ifdef _MSC_VER
00021 #define INLINE __forceinline
00022 #else
00023 #define INLINE inline
00024 #endif
00025 #endif
00026 
00027 #define CODEC_4CC "ZMBV"
00028 
00029 typedef enum {
00030         ZMBV_FORMAT_NONE                = 0x00,
00031         ZMBV_FORMAT_1BPP                = 0x01,
00032         ZMBV_FORMAT_2BPP                = 0x02,
00033         ZMBV_FORMAT_4BPP                = 0x03,
00034         ZMBV_FORMAT_8BPP                = 0x04,
00035         ZMBV_FORMAT_15BPP       = 0x05,
00036         ZMBV_FORMAT_16BPP       = 0x06,
00037         ZMBV_FORMAT_24BPP       = 0x07,
00038         ZMBV_FORMAT_32BPP       = 0x08
00039 } zmbv_format_t;
00040 
00041 void Msg(const char fmt[], ...);
00042 class VideoCodec {
00043 private:
00044         struct FrameBlock {
00045                 int start;
00046                 int dx,dy;
00047         };
00048         struct CodecVector {
00049                 int x,y;
00050                 int slot;
00051         };
00052         struct KeyframeHeader {
00053                 unsigned char high_version;
00054                 unsigned char low_version;
00055                 unsigned char compression;
00056                 unsigned char format;
00057                 unsigned char blockwidth,blockheight;
00058         };
00059 
00060         struct {
00061                 int             linesDone;
00062                 int             writeSize;
00063                 int             writeDone;
00064                 unsigned char   *writeBuf;
00065         } compress;
00066 
00067         CodecVector VectorTable[512];
00068         int VectorCount;
00069 
00070         unsigned char *oldframe, *newframe;
00071         unsigned char *buf1, *buf2, *work;
00072         int bufsize;
00073 
00074         int blockcount; 
00075         FrameBlock * blocks;
00076 
00077         int workUsed, workPos;
00078 
00079         int palsize;
00080         char palette[256*4];
00081         int height, width, pitch;
00082         zmbv_format_t format;
00083         int pixelsize;
00084 
00085         z_stream zstream;
00086 
00087         // methods
00088         void FreeBuffers(void);
00089         void CreateVectorTable(void);
00090         bool SetupBuffers(zmbv_format_t format, int blockwidth, int blockheight);
00091 
00092         template<class P>
00093                 void AddXorFrame(void);
00094         template<class P>
00095                 void UnXorFrame(void);
00096         template<class P>
00097                 INLINE int PossibleBlock(int vx,int vy,FrameBlock * block);
00098         template<class P>
00099                 INLINE int CompareBlock(int vx,int vy,FrameBlock * block);
00100         template<class P>
00101                 INLINE void AddXorBlock(int vx,int vy,FrameBlock * block);
00102         template<class P>
00103                 INLINE void UnXorBlock(int vx,int vy,FrameBlock * block);
00104         template<class P>
00105                 INLINE void CopyBlock(int vx, int vy,FrameBlock * block);
00106 public:
00107         VideoCodec();
00108         bool SetupCompress( int _width, int _height);
00109         bool SetupDecompress( int _width, int _height);
00110         zmbv_format_t BPPFormat( int bpp );
00111         int NeededSize( int _width, int _height, zmbv_format_t _format);
00112 
00113         void CompressLines(int lineCount, void *lineData[]);
00114         bool PrepareCompressFrame(int flags,  zmbv_format_t _format, char * pal, void *writeBuf, int writeSize);
00115         int FinishCompressFrame( void );
00116         bool DecompressFrame(void * framedata, int size);
00117         void Output_UpsideDown_24(void * output);
00118 };