| 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 __EXT_TXFILTER_H__ |
| 25 | #define __EXT_TXFILTER_H__ |
| 26 | |
| 27 | #ifdef WIN32 |
| 28 | #include <windows.h> |
| 29 | #define TXHMODULE HMODULE |
| 30 | #define DLOPEN(a) LoadLibraryW(a) |
| 31 | #define DLCLOSE(a) FreeLibrary(a) |
| 32 | #define DLSYM(a, b) GetProcAddress(a, b) |
| 33 | #define GETCWD(a, b) GetCurrentDirectoryW(a, b) |
| 34 | #define CHDIR(a) SetCurrentDirectoryW(a) |
| 35 | #else |
| 36 | #include <iostream> |
| 37 | #include <dlfcn.h> |
| 38 | #define MAX_PATH 4095 |
| 39 | #define TXHMODULE void* |
| 40 | #define DLOPEN(a) dlopen(a, RTLD_LAZY|RTLD_GLOBAL) |
| 41 | #define DLCLOSE(a) dlclose(a) |
| 42 | #define DLSYM(a, b) dlsym(a, b) |
| 43 | #define GETCWD(a, b) getcwd(b, a) |
| 44 | #define CHDIR(a) chdir(a) |
| 45 | #endif |
| 46 | |
| 47 | #ifdef __MSC__ |
| 48 | typedef __int64 int64; |
| 49 | typedef unsigned __int64 uint64; |
| 50 | #else |
| 51 | #include <stdint.h> |
| 52 | typedef int64_t int64; |
| 53 | typedef uint64_t uint64; |
| 54 | typedef unsigned char boolean; |
| 55 | #endif |
| 56 | |
| 57 | #define NO_OPTIONS 0x00000000 |
| 58 | |
| 59 | #define FILTER_MASK 0x000000ff |
| 60 | #define NO_FILTER 0x00000000 |
| 61 | #define SMOOTH_FILTER_MASK 0x0000000f |
| 62 | #define NO_SMOOTH_FILTER 0x00000000 |
| 63 | #define SMOOTH_FILTER_1 0x00000001 |
| 64 | #define SMOOTH_FILTER_2 0x00000002 |
| 65 | #define SMOOTH_FILTER_3 0x00000003 |
| 66 | #define SMOOTH_FILTER_4 0x00000004 |
| 67 | #define SHARP_FILTER_MASK 0x000000f0 |
| 68 | #define NO_SHARP_FILTER 0x00000000 |
| 69 | #define SHARP_FILTER_1 0x00000010 |
| 70 | #define SHARP_FILTER_2 0x00000020 |
| 71 | |
| 72 | #define ENHANCEMENT_MASK 0x00000f00 |
| 73 | #define NO_ENHANCEMENT 0x00000000 |
| 74 | #define X2_ENHANCEMENT 0x00000100 |
| 75 | #define X2SAI_ENHANCEMENT 0x00000200 |
| 76 | #define HQ2X_ENHANCEMENT 0x00000300 |
| 77 | #define LQ2X_ENHANCEMENT 0x00000400 |
| 78 | #define HQ4X_ENHANCEMENT 0x00000500 |
| 79 | #define HQ2XS_ENHANCEMENT 0x00000600 |
| 80 | #define LQ2XS_ENHANCEMENT 0x00000700 |
| 81 | |
| 82 | #define COMPRESSION_MASK 0x0000f000 |
| 83 | #define NO_COMPRESSION 0x00000000 |
| 84 | #define FXT1_COMPRESSION 0x00001000 |
| 85 | #define NCC_COMPRESSION 0x00002000 |
| 86 | #define S3TC_COMPRESSION 0x00003000 |
| 87 | |
| 88 | #define HIRESTEXTURES_MASK 0x000f0000 |
| 89 | #define NO_HIRESTEXTURES 0x00000000 |
| 90 | #define GHQ_HIRESTEXTURES 0x00010000 |
| 91 | #define RICE_HIRESTEXTURES 0x00020000 |
| 92 | #define JABO_HIRESTEXTURES 0x00030000 |
| 93 | |
| 94 | #define COMPRESS_TEX 0x00100000 |
| 95 | #define COMPRESS_HIRESTEX 0x00200000 |
| 96 | #define GZ_TEXCACHE 0x00400000 |
| 97 | #define GZ_HIRESTEXCACHE 0x00800000 |
| 98 | #define DUMP_TEXCACHE 0x01000000 |
| 99 | #define DUMP_HIRESTEXCACHE 0x02000000 |
| 100 | #define TILE_HIRESTEX 0x04000000 |
| 101 | #define UNDEFINED_0 0x08000000 |
| 102 | #define FORCE16BPP_HIRESTEX 0x10000000 |
| 103 | #define FORCE16BPP_TEX 0x20000000 |
| 104 | #define LET_TEXARTISTS_FLY 0x40000000 /* a little freedom for texture artists */ |
| 105 | #define DUMP_TEX 0x80000000 |
| 106 | |
| 107 | #ifndef __GLIDE_H__ /* GLIDE3 */ |
| 108 | /* from 3Dfx Interactive Inc. glide.h */ |
| 109 | #define GR_TEXFMT_ALPHA_8 0x2 |
| 110 | #define GR_TEXFMT_INTENSITY_8 0x3 |
| 111 | |
| 112 | #define GR_TEXFMT_ALPHA_INTENSITY_44 0x4 |
| 113 | #define GR_TEXFMT_P_8 0x5 |
| 114 | |
| 115 | #define GR_TEXFMT_RGB_565 0xa |
| 116 | #define GR_TEXFMT_ARGB_1555 0xb |
| 117 | #define GR_TEXFMT_ARGB_4444 0xc |
| 118 | #define GR_TEXFMT_ALPHA_INTENSITY_88 0xd |
| 119 | |
| 120 | /* from 3Dfx Interactive Inc. g3ext.h */ |
| 121 | #define GR_TEXFMT_ARGB_CMP_FXT1 0x11 |
| 122 | |
| 123 | #define GR_TEXFMT_ARGB_8888 0x12 |
| 124 | |
| 125 | #define GR_TEXFMT_ARGB_CMP_DXT1 0x16 |
| 126 | #define GR_TEXFMT_ARGB_CMP_DXT3 0x18 |
| 127 | #define GR_TEXFMT_ARGB_CMP_DXT5 0x1A |
| 128 | #endif /* GLIDE3 */ |
| 129 | |
| 130 | struct GHQTexInfo { |
| 131 | |
| 132 | unsigned char *data; |
| 133 | |
| 134 | int width; |
| 135 | int height; |
| 136 | |
| 137 | int smallLodLog2; |
| 138 | int largeLodLog2; |
| 139 | int aspectRatioLog2; |
| 140 | |
| 141 | int tiles; |
| 142 | int untiled_width; |
| 143 | int untiled_height; |
| 144 | |
| 145 | unsigned short format; |
| 146 | |
| 147 | unsigned char is_hires_tex; |
| 148 | }; |
| 149 | |
| 150 | /* Callback to display hires texture info. |
| 151 | * Gonetz <gonetz(at)ngs.ru> |
| 152 | * |
| 153 | * void DispInfo(const char *format, ...) |
| 154 | * { |
| 155 | * va_list args; |
| 156 | * char buf[INFO_BUF]; |
| 157 | * |
| 158 | * va_start(args, format); |
| 159 | * vsprintf(buf, format, args); |
| 160 | * va_end(args); |
| 161 | * |
| 162 | * printf(buf); |
| 163 | * } |
| 164 | */ |
| 165 | #define INFO_BUF 4095 |
| 166 | typedef void (*dispInfoFuncExt)(const wchar_t *format, ...); |
| 167 | |
| 168 | #ifndef TXFILTER_DLL |
| 169 | boolean ext_ghq_init(int maxwidth, /* maximum texture width supported by hardware */ |
| 170 | int maxheight,/* maximum texture height supported by hardware */ |
| 171 | int maxbpp, /* maximum texture bpp supported by hardware */ |
| 172 | int options, /* options */ |
| 173 | int cachesize,/* cache textures to system memory */ |
| 174 | wchar_t *datapath, /* user data directory. must be smaller than MAX_PATH */ |
| 175 | wchar_t *cachepath, /* user cache directory. must be smaller than MAX_PATH */ |
| 176 | wchar_t *ident, /* name of ROM. must be no longer than 64 in character. */ |
| 177 | dispInfoFuncExt callback /* callback function to display info */ |
| 178 | ); |
| 179 | |
| 180 | void ext_ghq_shutdown(void); |
| 181 | |
| 182 | boolean ext_ghq_txfilter(unsigned char *src, /* input texture */ |
| 183 | int srcwidth, /* width of input texture */ |
| 184 | int srcheight, /* height of input texture */ |
| 185 | unsigned short srcformat, /* format of input texture */ |
| 186 | uint64 g64crc, /* glide64 crc */ |
| 187 | GHQTexInfo *info /* output */ |
| 188 | ); |
| 189 | |
| 190 | boolean ext_ghq_hirestex(uint64 g64crc, /* glide64 crc */ |
| 191 | uint64 r_crc64, /* checksum hi:palette low:texture */ |
| 192 | unsigned short *palette, /* palette for CI textures */ |
| 193 | GHQTexInfo *info /* output */ |
| 194 | ); |
| 195 | |
| 196 | uint64 ext_ghq_checksum(unsigned char *src, /* input texture */ |
| 197 | int width, /* width of texture */ |
| 198 | int height, /* height of texture */ |
| 199 | int size, /* type of texture pixel */ |
| 200 | int rowStride, /* row stride in bytes */ |
| 201 | unsigned char *palette /* palette */ |
| 202 | ); |
| 203 | |
| 204 | boolean ext_ghq_dmptx(unsigned char *src, /* input texture (must be in 3Dfx Glide format) */ |
| 205 | int width, /* width of texture */ |
| 206 | int height, /* height of texture */ |
| 207 | int rowStridePixel, /* row stride of input texture in pixels */ |
| 208 | unsigned short gfmt, /* glide format of input texture */ |
| 209 | unsigned short n64fmt,/* N64 format hi:format low:size */ |
| 210 | uint64 r_crc64 /* checksum hi:palette low:texture */ |
| 211 | ); |
| 212 | |
| 213 | boolean ext_ghq_reloadhirestex(); |
| 214 | #endif /* TXFILTER_DLL */ |
| 215 | |
| 216 | #endif /* __EXT_TXFILTER_H__ */ |