| 212 | */ |
| 213 | |
| 214 | static void DDSGetColorBlockColors( ddsColorBlock_t *block, ddsColor_t colors[ 4 ] ) { |
| 215 | unsigned short word; |
| 216 | |
| 217 | |
| 218 | /* color 0 */ |
| 219 | word = DDSShort( block->colors[ 0 ] ); |
| 220 | colors[ 0 ].a = 0xff; |
| 221 | |
| 222 | /* extract rgb bits */ |
| 223 | colors[ 0 ].b = (unsigned char) word; |
| 224 | colors[ 0 ].b <<= 3; |
| 225 | colors[ 0 ].b |= (colors[ 0 ].b >> 5); |
| 226 | word >>= 5; |
| 227 | colors[ 0 ].g = (unsigned char) word; |
| 228 | colors[ 0 ].g <<= 2; |
| 229 | colors[ 0 ].g |= (colors[ 0 ].g >> 6); |
| 230 | word >>= 6; |
| 231 | colors[ 0 ].r = (unsigned char) word; |
| 232 | colors[ 0 ].r <<= 3; |
| 233 | colors[ 0 ].r |= (colors[ 0 ].r >> 5); |
| 234 | |
| 235 | /* same for color 1 */ |
| 236 | word = DDSShort( block->colors[ 1 ] ); |
| 237 | colors[ 1 ].a = 0xff; |
| 238 | |
| 239 | /* extract rgb bits */ |
| 240 | colors[ 1 ].b = (unsigned char) word; |
| 241 | colors[ 1 ].b <<= 3; |
| 242 | colors[ 1 ].b |= (colors[ 1 ].b >> 5); |
| 243 | word >>= 5; |
| 244 | colors[ 1 ].g = (unsigned char) word; |
| 245 | colors[ 1 ].g <<= 2; |
| 246 | colors[ 1 ].g |= (colors[ 1 ].g >> 6); |
| 247 | word >>= 6; |
| 248 | colors[ 1 ].r = (unsigned char) word; |
| 249 | colors[ 1 ].r <<= 3; |
| 250 | colors[ 1 ].r |= (colors[ 1 ].r >> 5); |
| 251 | |
| 252 | /* use this for all but the super-freak math method */ |
| 253 | if( block->colors[ 0 ] > block->colors[ 1 ] ) { |
| 254 | /* four-color block: derive the other two colors. |
| 255 | 00 = color 0, 01 = color 1, 10 = color 2, 11 = color 3 |
| 256 | these two bit codes correspond to the 2-bit fields |
| 257 | stored in the 64-bit block. */ |
| 258 | |
| 259 | word = ((unsigned short) colors[ 0 ].r * 2 + (unsigned short) colors[ 1 ].r ) / 3; |
| 260 | /* no +1 for rounding */ |
| 261 | /* as bits have been shifted to 888 */ |
| 262 | colors[ 2 ].r = (unsigned char) word; |
| 263 | word = ((unsigned short) colors[ 0 ].g * 2 + (unsigned short) colors[ 1 ].g) / 3; |
| 264 | colors[ 2 ].g = (unsigned char) word; |
| 265 | word = ((unsigned short) colors[ 0 ].b * 2 + (unsigned short) colors[ 1 ].b) / 3; |
| 266 | colors[ 2 ].b = (unsigned char) word; |
| 267 | colors[ 2 ].a = 0xff; |
| 268 | |
| 269 | word = ((unsigned short) colors[ 0 ].r + (unsigned short) colors[ 1 ].r * 2) / 3; |
| 270 | colors[ 3 ].r = (unsigned char) word; |
| 271 | word = ((unsigned short) colors[ 0 ].g + (unsigned short) colors[ 1 ].g * 2) / 3; |
no test coverage detected