| 230 | } |
| 231 | |
| 232 | void CompressAlphaDxt5( u8 const* rgba, int mask, void* block ) |
| 233 | { |
| 234 | // get the range for 5-alpha and 7-alpha interpolation |
| 235 | int min5 = 255; |
| 236 | int max5 = 0; |
| 237 | int min7 = 255; |
| 238 | int max7 = 0; |
| 239 | for( int i = 0; i < 16; ++i ) |
| 240 | { |
| 241 | // check this pixel is valid |
| 242 | int bit = 1 << i; |
| 243 | if( ( mask & bit ) == 0 ) |
| 244 | continue; |
| 245 | |
| 246 | // incorporate into the min/max |
| 247 | int value = rgba[4*i + 3]; |
| 248 | if( value < min7 ) |
| 249 | min7 = value; |
| 250 | if( value > max7 ) |
| 251 | max7 = value; |
| 252 | if( value != 0 && value < min5 ) |
| 253 | min5 = value; |
| 254 | if( value != 255 && value > max5 ) |
| 255 | max5 = value; |
| 256 | } |
| 257 | |
| 258 | // handle the case that no valid range was found |
| 259 | if( min5 > max5 ) |
| 260 | min5 = max5; |
| 261 | if( min7 > max7 ) |
| 262 | min7 = max7; |
| 263 | |
| 264 | // fix the range to be the minimum in each case |
| 265 | FixRange( min5, max5, 5 ); |
| 266 | FixRange( min7, max7, 7 ); |
| 267 | |
| 268 | // set up the 5-alpha code book |
| 269 | u8 codes5[8]; |
| 270 | codes5[0] = ( u8 )min5; |
| 271 | codes5[1] = ( u8 )max5; |
| 272 | for( int i = 1; i < 5; ++i ) |
| 273 | codes5[1 + i] = ( u8 )( ( ( 5 - i )*min5 + i*max5 )/5 ); |
| 274 | codes5[6] = 0; |
| 275 | codes5[7] = 255; |
| 276 | |
| 277 | // set up the 7-alpha code book |
| 278 | u8 codes7[8]; |
| 279 | codes7[0] = ( u8 )min7; |
| 280 | codes7[1] = ( u8 )max7; |
| 281 | for( int i = 1; i < 7; ++i ) |
| 282 | codes7[1 + i] = ( u8 )( ( ( 7 - i )*min7 + i*max7 )/7 ); |
| 283 | |
| 284 | // fit the data to both code books |
| 285 | u8 indices5[16]; |
| 286 | u8 indices7[16]; |
| 287 | int err5 = FitCodes( rgba, mask, codes5, indices5 ); |
| 288 | int err7 = FitCodes( rgba, mask, codes7, indices7 ); |
| 289 |
no test coverage detected