1 /* ----------------------------------------------------------------------------- 2 3 DDS Library 4 5 Based on code from Nvidia's DDS example: 6 http://www.nvidia.com/object/dxtc_decompression_code.html 7 8 Copyright (c) 2003 Randy Reddig 9 All rights reserved. 10 11 Redistribution and use in source and binary forms, with or without modification, 12 are permitted provided that the following conditions are met: 13 14 Redistributions of source code must retain the above copyright notice, this list 15 of conditions and the following disclaimer. 16 17 Redistributions in binary form must reproduce the above copyright notice, this 18 list of conditions and the following disclaimer in the documentation and/or 19 other materials provided with the distribution. 20 21 Neither the names of the copyright holders nor the names of its contributors may 22 be used to endorse or promote products derived from this software without 23 specific prior written permission. 24 25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 26 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 29 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 32 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 36 ----------------------------------------------------------------------------- */ 37 38 39 40 /* marker */ 41 #ifndef DDSLIB_H 42 #define DDSLIB_H 43 44 45 46 /* dependencies */ 47 #include <stdio.h> 48 #include <memory.h> 49 50 51 52 /* c++ marker */ 53 #ifdef __cplusplus 54 extern "C" 55 { 56 #endif 57 58 59 60 /* dds definition */ 61 typedef enum 62 { 63 DDS_PF_ARGB8888, 64 DDS_PF_DXT1, 65 DDS_PF_DXT2, 66 DDS_PF_DXT3, 67 DDS_PF_DXT4, 68 DDS_PF_DXT5, 69 DDS_PF_UNKNOWN 70 } 71 ddsPF_t; 72 73 74 /* 16bpp stuff */ 75 #define DDS_LOW_5 0x001F; 76 #define DDS_MID_6 0x07E0; 77 #define DDS_HIGH_5 0xF800; 78 #define DDS_MID_555 0x03E0; 79 #define DDS_HI_555 0x7C00; 80 81 82 /* structures */ 83 typedef struct ddsColorKey_s 84 { 85 unsigned int colorSpaceLowValue; 86 unsigned int colorSpaceHighValue; 87 } 88 ddsColorKey_t; 89 90 91 typedef struct ddsCaps_s 92 { 93 unsigned int caps1; 94 unsigned int caps2; 95 unsigned int caps3; 96 unsigned int caps4; 97 } 98 ddsCaps_t; 99 100 101 typedef struct ddsMultiSampleCaps_s 102 { 103 unsigned short flipMSTypes; 104 unsigned short bltMSTypes; 105 } 106 ddsMultiSampleCaps_t; 107 108 109 typedef struct ddsPixelFormat_s 110 { 111 unsigned int size; 112 unsigned int flags; 113 unsigned int fourCC; 114 union 115 { 116 unsigned int rgbBitCount; 117 unsigned int yuvBitCount; 118 unsigned int zBufferBitDepth; 119 unsigned int alphaBitDepth; 120 unsigned int luminanceBitCount; 121 unsigned int bumpBitCount; 122 unsigned int privateFormatBitCount; 123 }; 124 union 125 { 126 unsigned int rBitMask; 127 unsigned int yBitMask; 128 unsigned int stencilBitDepth; 129 unsigned int luminanceBitMask; 130 unsigned int bumpDuBitMask; 131 unsigned int operations; 132 }; 133 union 134 { 135 unsigned int gBitMask; 136 unsigned int uBitMask; 137 unsigned int zBitMask; 138 unsigned int bumpDvBitMask; 139 ddsMultiSampleCaps_t multiSampleCaps; 140 }; 141 union 142 { 143 unsigned int bBitMask; 144 unsigned int vBitMask; 145 unsigned int stencilBitMask; 146 unsigned int bumpLuminanceBitMask; 147 }; 148 union 149 { 150 unsigned int rgbAlphaBitMask; 151 unsigned int yuvAlphaBitMask; 152 unsigned int luminanceAlphaBitMask; 153 unsigned int rgbZBitMask; 154 unsigned int yuvZBitMask; 155 }; 156 } 157 ddsPixelFormat_t; 158 159 160 typedef struct ddsBuffer_s 161 { 162 /* magic: 'dds ' */ 163 char magic[ 4 ]; 164 165 /* directdraw surface */ 166 unsigned int size; 167 unsigned int flags; 168 unsigned int height; 169 unsigned int width; 170 union 171 { 172 int pitch; 173 unsigned int linearSize; 174 }; 175 unsigned int backBufferCount; 176 union 177 { 178 unsigned int mipMapCount; 179 unsigned int refreshRate; 180 unsigned int srcVBHandle; 181 }; 182 unsigned int alphaBitDepth; 183 unsigned int reserved; 184 void *surface; 185 union 186 { 187 ddsColorKey_t ckDestOverlay; 188 unsigned int emptyFaceColor; 189 }; 190 ddsColorKey_t ckDestBlt; 191 ddsColorKey_t ckSrcOverlay; 192 ddsColorKey_t ckSrcBlt; 193 union 194 { 195 ddsPixelFormat_t pixelFormat; 196 unsigned int fvf; 197 }; 198 ddsCaps_t ddsCaps; 199 unsigned int textureStage; 200 201 /* data (Varying size) */ 202 unsigned char data[ 4 ]; 203 } 204 ddsBuffer_t; 205 206 207 typedef struct ddsColorBlock_s 208 { 209 unsigned short colors[ 2 ]; 210 unsigned char row[ 4 ]; 211 } 212 ddsColorBlock_t; 213 214 215 typedef struct ddsAlphaBlockExplicit_s 216 { 217 unsigned short row[ 4 ]; 218 } 219 ddsAlphaBlockExplicit_t; 220 221 222 typedef struct ddsAlphaBlock3BitLinear_s 223 { 224 unsigned char alpha0; 225 unsigned char alpha1; 226 unsigned char stuff[ 6 ]; 227 } 228 ddsAlphaBlock3BitLinear_t; 229 230 231 typedef struct ddsColor_s 232 { 233 unsigned char r, g, b, a; 234 } 235 ddsColor_t; 236 237 238 239 /* public functions */ 240 int DDSGetInfo( ddsBuffer_t *dds, int *width, int *height, ddsPF_t *pf ); 241 int DDSDecompress( ddsBuffer_t *dds, unsigned char *pixels ); 242 243 244 245 /* end marker */ 246 #ifdef __cplusplus 247 } 248 #endif 249 250 #endif 251