ALL: Huge upstream synch + PerRom DelaySI & CountPerOp parameters
[mupen64plus-pandora.git] / source / gles2glide64 / src / GlideHQ / TxUtil.h
1 /*
2  * Texture Filtering
3  * Version:  1.0
4  *
5  * Copyright (C) 2007  Hiroshi Morii   All Rights Reserved.
6  * Email koolsmoky(at)users.sourceforge.net
7  * Web   http://www.3dfxzone.it/koolsmoky
8  *
9  * this is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2, or (at your option)
12  * any later version.
13  *
14  * this is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with GNU Make; see the file COPYING.  If not, write to
21  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #ifndef __TXUTIL_H__
25 #define __TXUTIL_H__
26
27 /* maximum number of CPU cores allowed */
28 #define MAX_NUMCORE 8
29
30 #include "TxInternal.h"
31 #include <string>
32
33 #ifndef DXTN_DLL
34 #ifdef __cplusplus
35 extern "C"{
36 #endif
37 void tx_compress_dxtn_rgba(int srccomps, int width, int height,
38                       const void *source, int destformat, void *dest,
39                       int destRowStride);
40
41 int fxt1_encode(int width, int height, int comps,
42                 const void *source, int srcRowStride,
43                 void *dest, int destRowStride);
44 #ifdef __cplusplus
45 }
46 #endif
47 #endif /* DXTN_DLL */
48
49 typedef void (*dxtCompressTexFuncExt)(int srccomps, int width,
50                                       int height, const void *srcPixData,
51                                       int destformat, void *dest,
52                                       int dstRowStride);
53
54 typedef int (*fxtCompressTexFuncExt)(int width, int height, int comps,
55                                      const void *source, int srcRowStride,
56                                      void *dest, int destRowStride);
57
58 class TxLoadLib
59 {
60 private:
61 #ifdef DXTN_DLL
62   HMODULE _dxtnlib;
63 #endif
64   fxtCompressTexFuncExt _tx_compress_fxt1;
65   dxtCompressTexFuncExt _tx_compress_dxtn_rgba;
66   TxLoadLib();
67 public:
68   static TxLoadLib* getInstance() {
69     static TxLoadLib txLoadLib;
70     return &txLoadLib;
71   }
72   ~TxLoadLib();
73   fxtCompressTexFuncExt getfxtCompressTexFuncExt();
74   dxtCompressTexFuncExt getdxtCompressTexFuncExt();
75 };
76
77 class TxUtil
78 {
79 private:
80   uint32 Adler32(const uint8* data, int Len, uint32 Adler);
81   uint32 Adler32(const uint8* src, int width, int height, int size, int rowStride);
82   uint32 RiceCRC32(const uint8* src, int width, int height, int size, int rowStride);
83   boolean RiceCRC32_CI4(const uint8* src, int width, int height, int size, int rowStride,
84                         uint32* crc32, uint32* cimax);
85   boolean RiceCRC32_CI8(const uint8* src, int width, int height, int size, int rowStride,
86                         uint32* crc32, uint32* cimax);
87   int log2(int num);
88 public:
89   TxUtil() { }
90   ~TxUtil() { }
91   int sizeofTx(int width, int height, uint16 format);
92   uint32 checksumTx(uint8 *data, int width, int height, uint16 format);
93 #if 0 /* unused */
94   uint32 chkAlpha(uint32* src, int width, int height);
95 #endif
96   uint32 checksum(uint8 *src, int width, int height, int size, int rowStride);
97   uint64 checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
98   int grLodLog2(int w, int h);
99   int grAspectRatioLog2(int w, int h);
100   int getNumberofProcessors();
101 };
102
103 class TxMemBuf
104 {
105 private:
106   uint8 *_tex[2];
107   uint32 _size[2];
108   TxMemBuf();
109 public:
110   static TxMemBuf* getInstance() {
111     static TxMemBuf txMemBuf;
112     return &txMemBuf;
113   }
114   ~TxMemBuf();
115   boolean init(int maxwidth, int maxheight);
116   void shutdown(void);
117   uint8 *get(unsigned int num);
118   uint32 size_of(unsigned int num);
119 };
120
121 #endif /* __TXUTIL_H__ */