| 1 |
97 |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#ifndef BCDEC_HEADER_INCLUDED |
| 45 |
#define BCDEC_HEADER_INCLUDED |
| 46 |
|
| 47 |
#define BCDEC_VERSION_MAJOR 0 |
| 48 |
#define BCDEC_VERSION_MINOR 97 |
| 49 |
|
| 50 |
|
| 51 |
#ifndef BCDECDEF |
| 52 |
#ifdef BCDEC_STATIC |
| 53 |
#define BCDECDEF static |
| 54 |
#else |
| 55 |
#ifdef __cplusplus |
| 56 |
#define BCDECDEF extern "C" |
| 57 |
#else |
| 58 |
#define BCDECDEF extern |
| 59 |
#endif |
| 60 |
#endif |
| 61 |
#endif |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
#define BCDEC_BC1_BLOCK_SIZE 8 |
| 83 |
#define BCDEC_BC2_BLOCK_SIZE 16 |
| 84 |
#define BCDEC_BC3_BLOCK_SIZE 16 |
| 85 |
#define BCDEC_BC4_BLOCK_SIZE 8 |
| 86 |
#define BCDEC_BC5_BLOCK_SIZE 16 |
| 87 |
#define BCDEC_BC6H_BLOCK_SIZE 16 |
| 88 |
#define BCDEC_BC7_BLOCK_SIZE 16 |
| 89 |
|
| 90 |
#define BCDEC_BC1_COMPRESSED_SIZE(w, h) ((((w)>>2)*((h)>>2))*BCDEC_BC1_BLOCK_SIZE) |
| 91 |
#define BCDEC_BC2_COMPRESSED_SIZE(w, h) ((((w)>>2)*((h)>>2))*BCDEC_BC2_BLOCK_SIZE) |
| 92 |
#define BCDEC_BC3_COMPRESSED_SIZE(w, h) ((((w)>>2)*((h)>>2))*BCDEC_BC3_BLOCK_SIZE) |
| 93 |
#define BCDEC_BC4_COMPRESSED_SIZE(w, h) ((((w)>>2)*((h)>>2))*BCDEC_BC4_BLOCK_SIZE) |
| 94 |
#define BCDEC_BC5_COMPRESSED_SIZE(w, h) ((((w)>>2)*((h)>>2))*BCDEC_BC5_BLOCK_SIZE) |
| 95 |
#define BCDEC_BC6H_COMPRESSED_SIZE(w, h) ((((w)>>2)*((h)>>2))*BCDEC_BC6H_BLOCK_SIZE) |
| 96 |
#define BCDEC_BC7_COMPRESSED_SIZE(w, h) ((((w)>>2)*((h)>>2))*BCDEC_BC7_BLOCK_SIZE) |
| 97 |
|
| 98 |
BCDECDEF void bcdec_bc1(const void* compressedBlock, void* decompressedBlock, int destinationPitch); |
| 99 |
BCDECDEF void bcdec_bc2(const void* compressedBlock, void* decompressedBlock, int destinationPitch); |
| 100 |
BCDECDEF void bcdec_bc3(const void* compressedBlock, void* decompressedBlock, int destinationPitch); |
| 101 |
BCDECDEF void bcdec_bc4(const void* compressedBlock, void* decompressedBlock, int destinationPitch); |
| 102 |
BCDECDEF void bcdec_bc5(const void* compressedBlock, void* decompressedBlock, int destinationPitch); |
| 103 |
BCDECDEF void bcdec_bc6h_float(const void* compressedBlock, void* decompressedBlock, int destinationPitch, int isSigned); |
| 104 |
BCDECDEF void bcdec_bc6h_half(const void* compressedBlock, void* decompressedBlock, int destinationPitch, int isSigned); |
| 105 |
BCDECDEF void bcdec_bc7(const void* compressedBlock, void* decompressedBlock, int destinationPitch); |
| 106 |
|
| 107 |
#endif |
| 108 |
|
| 109 |
#ifdef BCDEC_IMPLEMENTATION |
| 110 |
|
| 111 |
static void bcdec__color_block(const void* compressedBlock, void* decompressedBlock, int destinationPitch, int onlyOpaqueMode) { |
| 112 |
unsigned short c0, c1; |
| 113 |
unsigned int refColors[4]; |
| 114 |
unsigned char* dstColors; |
| 115 |
unsigned int colorIndices; |
| 116 |
int i, j, idx; |
| 117 |
unsigned int r0, g0, b0, r1, g1, b1, r, g, b; |
| 118 |
|
| 119 |
c0 = ((unsigned short*)compressedBlock)[0]; |
| 120 |
c1 = ((unsigned short*)compressedBlock)[1]; |
| 121 |
|
| 122 |
|
| 123 |
r0 = (c0 >> 11) & 0x1F; |
| 124 |
g0 = (c0 >> 5) & 0x3F; |
| 125 |
b0 = c0 & 0x1F; |
| 126 |
|
| 127 |
r1 = (c1 >> 11) & 0x1F; |
| 128 |
g1 = (c1 >> 5) & 0x3F; |
| 129 |
b1 = c1 & 0x1F; |
| 130 |
|
| 131 |
|
| 132 |
r = (r0 * 527 + 23) >> 6; |
| 133 |
g = (g0 * 259 + 33) >> 6; |
| 134 |
b = (b0 * 527 + 23) >> 6; |
| 135 |
refColors[0] = 0xFF000000 | (b << 16) | (g << 8) | r; |
| 136 |
|
| 137 |
r = (r1 * 527 + 23) >> 6; |
| 138 |
g = (g1 * 259 + 33) >> 6; |
| 139 |
b = (b1 * 527 + 23) >> 6; |
| 140 |
refColors[1] = 0xFF000000 | (b << 16) | (g << 8) | r; |
| 141 |
|
| 142 |
if (c0 > c1 || onlyOpaqueMode) { |
| 143 |
|
| 144 |
|
| 145 |
r = ((2 * r0 + r1) * 351 + 61) >> 7; |
| 146 |
g = ((2 * g0 + g1) * 2763 + 1039) >> 11; |
| 147 |
b = ((2 * b0 + b1) * 351 + 61) >> 7; |
| 148 |
refColors[2] = 0xFF000000 | (b << 16) | (g << 8) | r; |
| 149 |
|
| 150 |
r = ((r0 + r1 * 2) * 351 + 61) >> 7; |
| 151 |
g = ((g0 + g1 * 2) * 2763 + 1039) >> 11; |
| 152 |
b = ((b0 + b1 * 2) * 351 + 61) >> 7; |
| 153 |
refColors[3] = 0xFF000000 | (b << 16) | (g << 8) | r; |
| 154 |
} else { |
| 155 |
|
| 156 |
|
| 157 |
r = ((r0 + r1) * 1053 + 125) >> 8; |
| 158 |
g = ((g0 + g1) * 4145 + 1019) >> 11; |
| 159 |
b = ((b0 + b1) * 1053 + 125) >> 8; |
| 160 |
refColors[2] = 0xFF000000 | (b << 16) | (g << 8) | r; |
| 161 |
|
| 162 |
refColors[3] = 0x00000000; |
| 163 |
} |
| 164 |
|
| 165 |
colorIndices = ((unsigned int*)compressedBlock)[1]; |
| 166 |
|
| 167 |
|
| 168 |
dstColors = (unsigned char*)decompressedBlock; |
| 169 |
for (i = 0; i < 4; ++i) { |
| 170 |
for (j = 0; j < 4; ++j) { |
| 171 |
idx = colorIndices & 0x03; |
| 172 |
((unsigned int*)dstColors)[j] = refColors[idx]; |
| 173 |
colorIndices >>= 2; |
| 174 |
} |
| 175 |
|
| 176 |
dstColors += destinationPitch; |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
static void bcdec__sharp_alpha_block(const void* compressedBlock, void* decompressedBlock, int destinationPitch) { |
| 181 |
unsigned short* alpha; |
| 182 |
unsigned char* decompressed; |
| 183 |
int i, j; |
| 184 |
|
| 185 |
alpha = (unsigned short*)compressedBlock; |
| 186 |
decompressed = (unsigned char*)decompressedBlock; |
| 187 |
|
| 188 |
for (i = 0; i < 4; ++i) { |
| 189 |
for (j = 0; j < 4; ++j) { |
| 190 |
decompressed[j * 4] = ((alpha[i] >> (4 * j)) & 0x0F) * 17; |
| 191 |
} |
| 192 |
|
| 193 |
decompressed += destinationPitch; |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
static void bcdec__smooth_alpha_block(const void* compressedBlock, void* decompressedBlock, int destinationPitch, int pixelSize) { |
| 198 |
unsigned char* decompressed; |
| 199 |
unsigned char alpha[8]; |
| 200 |
int i, j; |
| 201 |
unsigned long long block, indices; |
| 202 |
|
| 203 |
block = *(unsigned long long*)compressedBlock; |
| 204 |
decompressed = (unsigned char*)decompressedBlock; |
| 205 |
|
| 206 |
alpha[0] = block & 0xFF; |
| 207 |
alpha[1] = (block >> 8) & 0xFF; |
| 208 |
|
| 209 |
if (alpha[0] > alpha[1]) { |
| 210 |
|
| 211 |
alpha[2] = (6 * alpha[0] + alpha[1] + 1) / 7; |
| 212 |
alpha[3] = (5 * alpha[0] + 2 * alpha[1] + 1) / 7; |
| 213 |
alpha[4] = (4 * alpha[0] + 3 * alpha[1] + 1) / 7; |
| 214 |
alpha[5] = (3 * alpha[0] + 4 * alpha[1] + 1) / 7; |
| 215 |
alpha[6] = (2 * alpha[0] + 5 * alpha[1] + 1) / 7; |
| 216 |
alpha[7] = ( alpha[0] + 6 * alpha[1] + 1) / 7; |
| 217 |
} |
| 218 |
else { |
| 219 |
|
| 220 |
alpha[2] = (4 * alpha[0] + alpha[1] + 1) / 5; |
| 221 |
alpha[3] = (3 * alpha[0] + 2 * alpha[1] + 1) / 5; |
| 222 |
alpha[4] = (2 * alpha[0] + 3 * alpha[1] + 1) / 5; |
| 223 |
alpha[5] = ( alpha[0] + 4 * alpha[1] + 1) / 5; |
| 224 |
alpha[6] = 0x00; |
| 225 |
alpha[7] = 0xFF; |
| 226 |
} |
| 227 |
|
| 228 |
indices = block >> 16; |
| 229 |
for (i = 0; i < 4; ++i) { |
| 230 |
for (j = 0; j < 4; ++j) { |
| 231 |
decompressed[j * pixelSize] = alpha[indices & 0x07]; |
| 232 |
indices >>= 3; |
| 233 |
} |
| 234 |
|
| 235 |
decompressed += destinationPitch; |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
typedef struct bcdec__bitstream { |
| 240 |
unsigned long long low; |
| 241 |
unsigned long long high; |
| 242 |
} bcdec__bitstream_t; |
| 243 |
|
| 244 |
static int bcdec__bitstream_read_bits(bcdec__bitstream_t* bstream, int numBits) { |
| 245 |
unsigned int mask = (1 << numBits) - 1; |
| 246 |
|
| 247 |
unsigned int bits = (bstream->low & mask); |
| 248 |
|
| 249 |
bstream->low >>= numBits; |
| 250 |
|
| 251 |
bstream->low |= (bstream->high & mask) << (sizeof(bstream->high) * 8 - numBits); |
| 252 |
bstream->high >>= numBits; |
| 253 |
|
| 254 |
return bits; |
| 255 |
} |
| 256 |
|
| 257 |
static int bcdec__bitstream_read_bit(bcdec__bitstream_t* bstream) { |
| 258 |
return bcdec__bitstream_read_bits(bstream, 1); |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
static int bcdec__bitstream_read_bits_r(bcdec__bitstream_t* bstream, int numBits) { |
| 264 |
int bits = bcdec__bitstream_read_bits(bstream, numBits); |
| 265 |
|
| 266 |
int result = 0; |
| 267 |
while (numBits--) { |
| 268 |
result <<= 1; |
| 269 |
result |= (bits & 1); |
| 270 |
bits >>= 1; |
| 271 |
} |
| 272 |
return result; |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
BCDECDEF void bcdec_bc1(const void* compressedBlock, void* decompressedBlock, int destinationPitch) { |
| 278 |
bcdec__color_block(compressedBlock, decompressedBlock, destinationPitch, 0); |
| 279 |
} |
| 280 |
|
| 281 |
BCDECDEF void bcdec_bc2(const void* compressedBlock, void* decompressedBlock, int destinationPitch) { |
| 282 |
bcdec__color_block(((char*)compressedBlock) + 8, decompressedBlock, destinationPitch, 1); |
| 283 |
bcdec__sharp_alpha_block(compressedBlock, ((char*)decompressedBlock) + 3, destinationPitch); |
| 284 |
} |
| 285 |
|
| 286 |
BCDECDEF void bcdec_bc3(const void* compressedBlock, void* decompressedBlock, int destinationPitch) { |
| 287 |
bcdec__color_block(((char*)compressedBlock) + 8, decompressedBlock, destinationPitch, 1); |
| 288 |
bcdec__smooth_alpha_block(compressedBlock, ((char*)decompressedBlock) + 3, destinationPitch, 4); |
| 289 |
} |
| 290 |
|
| 291 |
BCDECDEF void bcdec_bc4(const void* compressedBlock, void* decompressedBlock, int destinationPitch) { |
| 292 |
bcdec__smooth_alpha_block(compressedBlock, decompressedBlock, destinationPitch, 1); |
| 293 |
} |
| 294 |
|
| 295 |
BCDECDEF void bcdec_bc5(const void* compressedBlock, void* decompressedBlock, int destinationPitch) { |
| 296 |
bcdec__smooth_alpha_block(compressedBlock, decompressedBlock, destinationPitch, 2); |
| 297 |
bcdec__smooth_alpha_block(((char*)compressedBlock) + 8, ((char*)decompressedBlock) + 1, destinationPitch, 2); |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
static int bcdec__extend_sign(int val, int bits) { |
| 302 |
return (val << (32 - bits)) >> (32 - bits); |
| 303 |
} |
| 304 |
|
| 305 |
static int bcdec__transform_inverse(int val, int a0, int bits, int isSigned) { |
| 306 |
|
| 307 |
|
| 308 |
val = (val + a0) & ((1 << bits) - 1); |
| 309 |
if (isSigned) { |
| 310 |
val = bcdec__extend_sign(val, bits); |
| 311 |
} |
| 312 |
return val; |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
static int bcdec__unquantize(int val, int bits, int isSigned) { |
| 317 |
int unq, s = 0; |
| 318 |
|
| 319 |
if (!isSigned) { |
| 320 |
if (bits >= 15) { |
| 321 |
unq = val; |
| 322 |
} else if (!val) { |
| 323 |
unq = 0; |
| 324 |
} else if (val == ((1 << bits) - 1)) { |
| 325 |
unq = 0xFFFF; |
| 326 |
} else { |
| 327 |
unq = ((val << 16) + 0x8000) >> bits; |
| 328 |
} |
| 329 |
} else { |
| 330 |
if (bits >= 16) { |
| 331 |
unq = val; |
| 332 |
} else { |
| 333 |
if (val < 0) { |
| 334 |
s = 1; |
| 335 |
val = -val; |
| 336 |
} |
| 337 |
|
| 338 |
if (val == 0) { |
| 339 |
unq = 0; |
| 340 |
} else if (val >= ((1 << (bits - 1)) - 1)) { |
| 341 |
unq = 0x7FFF; |
| 342 |
} else { |
| 343 |
unq = ((val << 15) + 0x4000) >> (bits - 1); |
| 344 |
} |
| 345 |
|
| 346 |
if (s) { |
| 347 |
unq = -unq; |
| 348 |
} |
| 349 |
} |
| 350 |
} |
| 351 |
return unq; |
| 352 |
} |
| 353 |
|
| 354 |
static int bcdec__interpolate(int a, int b, int* weights, int index) { |
| 355 |
return (a * (64 - weights[index]) + b * weights[index] + 32) >> 6; |
| 356 |
} |
| 357 |
|
| 358 |
static unsigned short bcdec__finish_unquantize(int val, int isSigned) { |
| 359 |
int s; |
| 360 |
|
| 361 |
if (!isSigned) { |
| 362 |
return (unsigned short)((val * 31) >> 6); |
| 363 |
} else { |
| 364 |
val = (val < 0) ? -(((-val) * 31) >> 5) : (val * 31) >> 5; |
| 365 |
s = 0; |
| 366 |
if (val < 0) { |
| 367 |
s = 0x8000; |
| 368 |
val = -val; |
| 369 |
} |
| 370 |
return (unsigned short)(s | val); |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
static float bcdec__half_to_float_quick(unsigned short half) { |
| 376 |
typedef union { |
| 377 |
unsigned int u; |
| 378 |
float f; |
| 379 |
} FP32; |
| 380 |
|
| 381 |
static const FP32 magic = { 113 << 23 }; |
| 382 |
static const unsigned int shifted_exp = 0x7c00 << 13; |
| 383 |
FP32 o; |
| 384 |
unsigned int exp; |
| 385 |
|
| 386 |
o.u = (half & 0x7fff) << 13; |
| 387 |
exp = shifted_exp & o.u; |
| 388 |
o.u += (127 - 15) << 23; |
| 389 |
|
| 390 |
|
| 391 |
if (exp == shifted_exp) { |
| 392 |
o.u += (128 - 16) << 23; |
| 393 |
} else if (exp == 0) { |
| 394 |
o.u += 1 << 23; |
| 395 |
o.f -= magic.f; |
| 396 |
} |
| 397 |
|
| 398 |
o.u |= (half & 0x8000) << 16; |
| 399 |
return o.f; |
| 400 |
} |
| 401 |
|
| 402 |
BCDECDEF void bcdec_bc6h_half(const void* compressedBlock, void* decompressedBlock, int destinationPitch, int isSigned) { |
| 403 |
static char actual_bits_count[4][14] = { |
| 404 |
{ 10, 7, 11, 11, 11, 9, 8, 8, 8, 6, 10, 11, 12, 16 }, |
| 405 |
{ 5, 6, 5, 4, 4, 5, 6, 5, 5, 6, 10, 9, 8, 4 }, |
| 406 |
{ 5, 6, 4, 5, 4, 5, 5, 6, 5, 6, 10, 9, 8, 4 }, |
| 407 |
{ 5, 6, 4, 4, 5, 5, 5, 5, 6, 6, 10, 9, 8, 4 } |
| 408 |
}; |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
static unsigned char partition_sets[32][4][4] = { |
| 414 |
{ {128, 0, 1, 1}, {0, 0, 1, 1}, { 0, 0, 1, 1}, {0, 0, 1, 129} }, |
| 415 |
{ {128, 0, 0, 1}, {0, 0, 0, 1}, { 0, 0, 0, 1}, {0, 0, 0, 129} }, |
| 416 |
{ {128, 1, 1, 1}, {0, 1, 1, 1}, { 0, 1, 1, 1}, {0, 1, 1, 129} }, |
| 417 |
{ {128, 0, 0, 1}, {0, 0, 1, 1}, { 0, 0, 1, 1}, {0, 1, 1, 129} }, |
| 418 |
{ {128, 0, 0, 0}, {0, 0, 0, 1}, { 0, 0, 0, 1}, {0, 0, 1, 129} }, |
| 419 |
{ {128, 0, 1, 1}, {0, 1, 1, 1}, { 0, 1, 1, 1}, {1, 1, 1, 129} }, |
| 420 |
{ {128, 0, 0, 1}, {0, 0, 1, 1}, { 0, 1, 1, 1}, {1, 1, 1, 129} }, |
| 421 |
{ {128, 0, 0, 0}, {0, 0, 0, 1}, { 0, 0, 1, 1}, {0, 1, 1, 129} }, |
| 422 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, { 0, 0, 0, 1}, {0, 0, 1, 129} }, |
| 423 |
{ {128, 0, 1, 1}, {0, 1, 1, 1}, { 1, 1, 1, 1}, {1, 1, 1, 129} }, |
| 424 |
{ {128, 0, 0, 0}, {0, 0, 0, 1}, { 0, 1, 1, 1}, {1, 1, 1, 129} }, |
| 425 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, { 0, 0, 0, 1}, {0, 1, 1, 129} }, |
| 426 |
{ {128, 0, 0, 1}, {0, 1, 1, 1}, { 1, 1, 1, 1}, {1, 1, 1, 129} }, |
| 427 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, { 1, 1, 1, 1}, {1, 1, 1, 129} }, |
| 428 |
{ {128, 0, 0, 0}, {1, 1, 1, 1}, { 1, 1, 1, 1}, {1, 1, 1, 129} }, |
| 429 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, { 0, 0, 0, 0}, {1, 1, 1, 129} }, |
| 430 |
{ {128, 0, 0, 0}, {1, 0, 0, 0}, { 1, 1, 1, 0}, {1, 1, 1, 129} }, |
| 431 |
{ {128, 1, 129, 1}, {0, 0, 0, 1}, { 0, 0, 0, 0}, {0, 0, 0, 0} }, |
| 432 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, {129, 0, 0, 0}, {1, 1, 1, 0} }, |
| 433 |
{ {128, 1, 129, 1}, {0, 0, 1, 1}, { 0, 0, 0, 1}, {0, 0, 0, 0} }, |
| 434 |
{ {128, 0, 129, 1}, {0, 0, 0, 1}, { 0, 0, 0, 0}, {0, 0, 0, 0} }, |
| 435 |
{ {128, 0, 0, 0}, {1, 0, 0, 0}, {129, 1, 0, 0}, {1, 1, 1, 0} }, |
| 436 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, {129, 0, 0, 0}, {1, 1, 0, 0} }, |
| 437 |
{ {128, 1, 1, 1}, {0, 0, 1, 1}, { 0, 0, 1, 1}, {0, 0, 0, 129} }, |
| 438 |
{ {128, 0, 129, 1}, {0, 0, 0, 1}, { 0, 0, 0, 1}, {0, 0, 0, 0} }, |
| 439 |
{ {128, 0, 0, 0}, {1, 0, 0, 0}, {129, 0, 0, 0}, {1, 1, 0, 0} }, |
| 440 |
{ {128, 1, 129, 0}, {0, 1, 1, 0}, { 0, 1, 1, 0}, {0, 1, 1, 0} }, |
| 441 |
{ {128, 0, 129, 1}, {0, 1, 1, 0}, { 0, 1, 1, 0}, {1, 1, 0, 0} }, |
| 442 |
{ {128, 0, 0, 1}, {0, 1, 1, 1}, {129, 1, 1, 0}, {1, 0, 0, 0} }, |
| 443 |
{ {128, 0, 0, 0}, {1, 1, 1, 1}, {129, 1, 1, 1}, {0, 0, 0, 0} }, |
| 444 |
{ {128, 1, 129, 1}, {0, 0, 0, 1}, { 1, 0, 0, 0}, {1, 1, 1, 0} }, |
| 445 |
{ {128, 0, 129, 1}, {1, 0, 0, 1}, { 1, 0, 0, 1}, {1, 1, 0, 0} } |
| 446 |
}; |
| 447 |
|
| 448 |
static int aWeight3[8] = { 0, 9, 18, 27, 37, 46, 55, 64 }; |
| 449 |
static int aWeight4[16] = { 0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64 }; |
| 450 |
|
| 451 |
bcdec__bitstream_t bstream; |
| 452 |
int mode, partition, numPartitions, i, j, partitionSet, indexBits, index, ep_i, actualBits0Mode; |
| 453 |
int r[4], g[4], b[4]; |
| 454 |
unsigned short* decompressed; |
| 455 |
int* weights; |
| 456 |
|
| 457 |
decompressed = (unsigned short*)decompressedBlock; |
| 458 |
|
| 459 |
bstream.low = ((unsigned long long*)compressedBlock)[0]; |
| 460 |
bstream.high = ((unsigned long long*)compressedBlock)[1]; |
| 461 |
|
| 462 |
r[0] = r[1] = r[2] = r[3] = 0; |
| 463 |
g[0] = g[1] = g[2] = g[3] = 0; |
| 464 |
b[0] = b[1] = b[2] = b[3] = 0; |
| 465 |
|
| 466 |
mode = bcdec__bitstream_read_bits(&bstream, 2); |
| 467 |
if (mode > 1) { |
| 468 |
mode |= (bcdec__bitstream_read_bits(&bstream, 3) << 2); |
| 469 |
} |
| 470 |
|
| 471 |
|
| 472 |
partition = 0; |
| 473 |
|
| 474 |
switch (mode) { |
| 475 |
|
| 476 |
case 0b00: { |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
g[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 481 |
b[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 482 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 483 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 484 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 485 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 486 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 487 |
g[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 488 |
g[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 489 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 490 |
b[3] |= bcdec__bitstream_read_bit(&bstream); |
| 491 |
g[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 492 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 493 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 1; |
| 494 |
b[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 495 |
r[2] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 496 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 2; |
| 497 |
r[3] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 498 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 3; |
| 499 |
partition = bcdec__bitstream_read_bits(&bstream, 5); |
| 500 |
mode = 0; |
| 501 |
} break; |
| 502 |
|
| 503 |
|
| 504 |
case 0b01: { |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
g[2] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 509 |
g[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 510 |
g[3] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 511 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 7); |
| 512 |
b[3] |= bcdec__bitstream_read_bit(&bstream); |
| 513 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 1; |
| 514 |
b[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 515 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 7); |
| 516 |
b[2] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 517 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 2; |
| 518 |
g[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 519 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 7); |
| 520 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 3; |
| 521 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 522 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 523 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 524 |
g[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 525 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 526 |
g[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 527 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 528 |
b[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 529 |
r[2] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 530 |
r[3] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 531 |
partition = bcdec__bitstream_read_bits(&bstream, 5); |
| 532 |
mode = 1; |
| 533 |
} break; |
| 534 |
|
| 535 |
|
| 536 |
case 0b00010: { |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 541 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 542 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 543 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 544 |
r[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 545 |
g[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 546 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 547 |
g[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 548 |
b[3] |= bcdec__bitstream_read_bit(&bstream); |
| 549 |
g[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 550 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 551 |
b[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 552 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 1; |
| 553 |
b[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 554 |
r[2] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 555 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 2; |
| 556 |
r[3] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 557 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 3; |
| 558 |
partition = bcdec__bitstream_read_bits(&bstream, 5); |
| 559 |
mode = 2; |
| 560 |
} break; |
| 561 |
|
| 562 |
|
| 563 |
case 0b00110: { |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 568 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 569 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 570 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 571 |
r[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 572 |
g[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 573 |
g[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 574 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 575 |
g[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 576 |
g[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 577 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 578 |
b[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 579 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 1; |
| 580 |
b[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 581 |
r[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 582 |
b[3] |= bcdec__bitstream_read_bit(&bstream); |
| 583 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 2; |
| 584 |
r[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 585 |
g[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 586 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 3; |
| 587 |
partition = bcdec__bitstream_read_bits(&bstream, 5); |
| 588 |
mode = 3; |
| 589 |
} break; |
| 590 |
|
| 591 |
|
| 592 |
case 0b01010: { |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 597 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 598 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 599 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 600 |
r[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 601 |
b[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 602 |
g[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 603 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 604 |
g[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 605 |
b[3] |= bcdec__bitstream_read_bit(&bstream); |
| 606 |
g[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 607 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 608 |
b[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 609 |
b[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 610 |
r[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 611 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 1; |
| 612 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 2; |
| 613 |
r[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 614 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 615 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 3; |
| 616 |
partition = bcdec__bitstream_read_bits(&bstream, 5); |
| 617 |
mode = 4; |
| 618 |
} break; |
| 619 |
|
| 620 |
|
| 621 |
case 0b01110: { |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 9); |
| 626 |
b[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 627 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 9); |
| 628 |
g[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 629 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 9); |
| 630 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 631 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 632 |
g[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 633 |
g[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 634 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 635 |
b[3] |= bcdec__bitstream_read_bit(&bstream); |
| 636 |
g[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 637 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 638 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 1; |
| 639 |
b[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 640 |
r[2] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 641 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 2; |
| 642 |
r[3] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 643 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 3; |
| 644 |
partition = bcdec__bitstream_read_bits(&bstream, 5); |
| 645 |
mode = 5; |
| 646 |
} break; |
| 647 |
|
| 648 |
|
| 649 |
case 0b10010: { |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 654 |
g[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 655 |
b[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 656 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 657 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 2; |
| 658 |
g[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 659 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 660 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 3; |
| 661 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 662 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 663 |
g[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 664 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 665 |
b[3] |= bcdec__bitstream_read_bit(&bstream); |
| 666 |
g[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 667 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 668 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 1; |
| 669 |
b[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 670 |
r[2] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 671 |
r[3] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 672 |
partition = bcdec__bitstream_read_bits(&bstream, 5); |
| 673 |
mode = 6; |
| 674 |
} break; |
| 675 |
|
| 676 |
|
| 677 |
case 0b10110: { |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 682 |
b[3] |= bcdec__bitstream_read_bit(&bstream); |
| 683 |
b[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 684 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 685 |
g[2] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 686 |
g[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 687 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 688 |
g[3] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 689 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 690 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 691 |
g[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 692 |
g[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 693 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 694 |
g[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 695 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 696 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 1; |
| 697 |
b[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 698 |
r[2] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 699 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 2; |
| 700 |
r[3] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 701 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 3; |
| 702 |
partition = bcdec__bitstream_read_bits(&bstream, 5); |
| 703 |
mode = 7; |
| 704 |
} break; |
| 705 |
|
| 706 |
|
| 707 |
case 0b11010: { |
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 712 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 1; |
| 713 |
b[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 714 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 715 |
b[2] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 716 |
g[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 717 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 718 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 719 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 720 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 721 |
g[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 722 |
g[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 723 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 724 |
b[3] |= bcdec__bitstream_read_bit(&bstream); |
| 725 |
g[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 726 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 727 |
b[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 728 |
r[2] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 729 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 2; |
| 730 |
r[3] |= bcdec__bitstream_read_bits(&bstream, 5); |
| 731 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 3; |
| 732 |
partition = bcdec__bitstream_read_bits(&bstream, 5); |
| 733 |
mode = 8; |
| 734 |
} break; |
| 735 |
|
| 736 |
|
| 737 |
case 0b11110: { |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 742 |
g[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 743 |
b[3] |= bcdec__bitstream_read_bit(&bstream); |
| 744 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 1; |
| 745 |
b[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 746 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 747 |
g[2] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 748 |
b[2] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 749 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 2; |
| 750 |
g[2] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 751 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 752 |
g[3] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 753 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 3; |
| 754 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 5; |
| 755 |
b[3] |= bcdec__bitstream_read_bit(&bstream) << 4; |
| 756 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 757 |
g[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 758 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 759 |
g[3] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 760 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 761 |
b[2] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 762 |
r[2] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 763 |
r[3] |= bcdec__bitstream_read_bits(&bstream, 6); |
| 764 |
partition = bcdec__bitstream_read_bits(&bstream, 5); |
| 765 |
mode = 9; |
| 766 |
} break; |
| 767 |
|
| 768 |
|
| 769 |
case 0b00011: { |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 774 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 775 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 776 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 777 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 778 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 779 |
mode = 10; |
| 780 |
} break; |
| 781 |
|
| 782 |
|
| 783 |
case 0b00111: { |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 788 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 789 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 790 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 9); |
| 791 |
r[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 792 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 9); |
| 793 |
g[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 794 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 9); |
| 795 |
b[0] |= bcdec__bitstream_read_bit(&bstream) << 10; |
| 796 |
mode = 11; |
| 797 |
} break; |
| 798 |
|
| 799 |
|
| 800 |
case 0b01011: { |
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 805 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 806 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 807 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 808 |
r[0] |= bcdec__bitstream_read_bits_r(&bstream, 2) << 10; |
| 809 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 810 |
g[0] |= bcdec__bitstream_read_bits_r(&bstream, 2) << 10; |
| 811 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 8); |
| 812 |
b[0] |= bcdec__bitstream_read_bits_r(&bstream, 2) << 10; |
| 813 |
mode = 12; |
| 814 |
} break; |
| 815 |
|
| 816 |
|
| 817 |
case 0b01111: { |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
r[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 822 |
g[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 823 |
b[0] |= bcdec__bitstream_read_bits(&bstream, 10); |
| 824 |
r[1] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 825 |
r[0] |= bcdec__bitstream_read_bits_r(&bstream, 6) << 10; |
| 826 |
g[1] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 827 |
g[0] |= bcdec__bitstream_read_bits_r(&bstream, 6) << 10; |
| 828 |
b[1] |= bcdec__bitstream_read_bits(&bstream, 4); |
| 829 |
b[0] |= bcdec__bitstream_read_bits_r(&bstream, 6) << 10; |
| 830 |
mode = 13; |
| 831 |
} break; |
| 832 |
|
| 833 |
default: { |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
for (i = 0; i < 4; ++i) { |
| 839 |
for (j = 0; j < 4; ++j) { |
| 840 |
decompressed[j * 3 + 0] = 0; |
| 841 |
decompressed[j * 3 + 1] = 0; |
| 842 |
decompressed[j * 3 + 2] = 0; |
| 843 |
} |
| 844 |
decompressed += destinationPitch; |
| 845 |
} |
| 846 |
|
| 847 |
return; |
| 848 |
} |
| 849 |
} |
| 850 |
|
| 851 |
numPartitions = (mode >= 10) ? 0 : 1; |
| 852 |
|
| 853 |
actualBits0Mode = actual_bits_count[0][mode]; |
| 854 |
if (isSigned) { |
| 855 |
r[0] = bcdec__extend_sign(r[0], actualBits0Mode); |
| 856 |
g[0] = bcdec__extend_sign(g[0], actualBits0Mode); |
| 857 |
b[0] = bcdec__extend_sign(b[0], actualBits0Mode); |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
if ((mode != 9 && mode != 10) || isSigned) { |
| 863 |
for (i = 1; i < (numPartitions + 1) * 2; ++i) { |
| 864 |
r[i] = bcdec__extend_sign(r[i], actual_bits_count[1][mode]); |
| 865 |
g[i] = bcdec__extend_sign(g[i], actual_bits_count[2][mode]); |
| 866 |
b[i] = bcdec__extend_sign(b[i], actual_bits_count[3][mode]); |
| 867 |
} |
| 868 |
} |
| 869 |
|
| 870 |
if (mode != 9 && mode != 10) { |
| 871 |
for (i = 1; i < (numPartitions + 1) * 2; ++i) { |
| 872 |
r[i] = bcdec__transform_inverse(r[i], r[0], actualBits0Mode, isSigned); |
| 873 |
g[i] = bcdec__transform_inverse(g[i], g[0], actualBits0Mode, isSigned); |
| 874 |
b[i] = bcdec__transform_inverse(b[i], b[0], actualBits0Mode, isSigned); |
| 875 |
} |
| 876 |
} |
| 877 |
|
| 878 |
for (i = 0; i < (numPartitions + 1) * 2; ++i) { |
| 879 |
r[i] = bcdec__unquantize(r[i], actualBits0Mode, isSigned); |
| 880 |
g[i] = bcdec__unquantize(g[i], actualBits0Mode, isSigned); |
| 881 |
b[i] = bcdec__unquantize(b[i], actualBits0Mode, isSigned); |
| 882 |
} |
| 883 |
|
| 884 |
weights = (mode >= 10) ? aWeight4 : aWeight3; |
| 885 |
for (i = 0; i < 4; ++i) { |
| 886 |
for (j = 0; j < 4; ++j) { |
| 887 |
partitionSet = (mode >= 10) ? ((i|j) ? 0 : 128) : partition_sets[partition][i][j]; |
| 888 |
|
| 889 |
indexBits = (mode >= 10) ? 4 : 3; |
| 890 |
|
| 891 |
|
| 892 |
if (partitionSet & 0x80) { |
| 893 |
indexBits--; |
| 894 |
} |
| 895 |
partitionSet &= 0x01; |
| 896 |
|
| 897 |
index = bcdec__bitstream_read_bits(&bstream, indexBits); |
| 898 |
|
| 899 |
ep_i = partitionSet * 2; |
| 900 |
decompressed[j * 3 + 0] = bcdec__finish_unquantize( |
| 901 |
bcdec__interpolate(r[ep_i], r[ep_i+1], weights, index), isSigned); |
| 902 |
decompressed[j * 3 + 1] = bcdec__finish_unquantize( |
| 903 |
bcdec__interpolate(g[ep_i], g[ep_i+1], weights, index), isSigned); |
| 904 |
decompressed[j * 3 + 2] = bcdec__finish_unquantize( |
| 905 |
bcdec__interpolate(b[ep_i], b[ep_i+1], weights, index), isSigned); |
| 906 |
} |
| 907 |
|
| 908 |
decompressed += destinationPitch; |
| 909 |
} |
| 910 |
} |
| 911 |
|
| 912 |
BCDECDEF void bcdec_bc6h_float(const void* compressedBlock, void* decompressedBlock, int destinationPitch, int isSigned) { |
| 913 |
unsigned short block[16*3]; |
| 914 |
float* decompressed; |
| 915 |
const unsigned short* b; |
| 916 |
int i, j; |
| 917 |
|
| 918 |
bcdec_bc6h_half(compressedBlock, block, 4*3, isSigned); |
| 919 |
b = block; |
| 920 |
decompressed = (float*)decompressedBlock; |
| 921 |
for (i = 0; i < 4; ++i) { |
| 922 |
for (j = 0; j < 4; ++j) { |
| 923 |
decompressed[j * 3 + 0] = bcdec__half_to_float_quick(*b++); |
| 924 |
decompressed[j * 3 + 1] = bcdec__half_to_float_quick(*b++); |
| 925 |
decompressed[j * 3 + 2] = bcdec__half_to_float_quick(*b++); |
| 926 |
} |
| 927 |
decompressed += destinationPitch; |
| 928 |
} |
| 929 |
} |
| 930 |
|
| 931 |
static void bcdec__swap_values(int* a, int* b) { |
| 932 |
a[0] ^= b[0], b[0] ^= a[0], a[0] ^= b[0]; |
| 933 |
} |
| 934 |
|
| 935 |
BCDECDEF void bcdec_bc7(const void* compressedBlock, void* decompressedBlock, int destinationPitch) { |
| 936 |
static char actual_bits_count[2][8] = { |
| 937 |
{ 4, 6, 5, 7, 5, 7, 7, 5 }, |
| 938 |
{ 0, 0, 0, 0, 6, 8, 7, 5 }, |
| 939 |
}; |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
static unsigned char partition_sets[2][64][4][4] = { |
| 945 |
{ |
| 946 |
{ {128, 0, 1, 1}, {0, 0, 1, 1}, { 0, 0, 1, 1}, {0, 0, 1, 129} }, |
| 947 |
{ {128, 0, 0, 1}, {0, 0, 0, 1}, { 0, 0, 0, 1}, {0, 0, 0, 129} }, |
| 948 |
{ {128, 1, 1, 1}, {0, 1, 1, 1}, { 0, 1, 1, 1}, {0, 1, 1, 129} }, |
| 949 |
{ {128, 0, 0, 1}, {0, 0, 1, 1}, { 0, 0, 1, 1}, {0, 1, 1, 129} }, |
| 950 |
{ {128, 0, 0, 0}, {0, 0, 0, 1}, { 0, 0, 0, 1}, {0, 0, 1, 129} }, |
| 951 |
{ {128, 0, 1, 1}, {0, 1, 1, 1}, { 0, 1, 1, 1}, {1, 1, 1, 129} }, |
| 952 |
{ {128, 0, 0, 1}, {0, 0, 1, 1}, { 0, 1, 1, 1}, {1, 1, 1, 129} }, |
| 953 |
{ {128, 0, 0, 0}, {0, 0, 0, 1}, { 0, 0, 1, 1}, {0, 1, 1, 129} }, |
| 954 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, { 0, 0, 0, 1}, {0, 0, 1, 129} }, |
| 955 |
{ {128, 0, 1, 1}, {0, 1, 1, 1}, { 1, 1, 1, 1}, {1, 1, 1, 129} }, |
| 956 |
{ {128, 0, 0, 0}, {0, 0, 0, 1}, { 0, 1, 1, 1}, {1, 1, 1, 129} }, |
| 957 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, { 0, 0, 0, 1}, {0, 1, 1, 129} }, |
| 958 |
{ {128, 0, 0, 1}, {0, 1, 1, 1}, { 1, 1, 1, 1}, {1, 1, 1, 129} }, |
| 959 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, { 1, 1, 1, 1}, {1, 1, 1, 129} }, |
| 960 |
{ {128, 0, 0, 0}, {1, 1, 1, 1}, { 1, 1, 1, 1}, {1, 1, 1, 129} }, |
| 961 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, { 0, 0, 0, 0}, {1, 1, 1, 129} }, |
| 962 |
{ {128, 0, 0, 0}, {1, 0, 0, 0}, { 1, 1, 1, 0}, {1, 1, 1, 129} }, |
| 963 |
{ {128, 1, 129, 1}, {0, 0, 0, 1}, { 0, 0, 0, 0}, {0, 0, 0, 0} }, |
| 964 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, {129, 0, 0, 0}, {1, 1, 1, 0} }, |
| 965 |
{ {128, 1, 129, 1}, {0, 0, 1, 1}, { 0, 0, 0, 1}, {0, 0, 0, 0} }, |
| 966 |
{ {128, 0, 129, 1}, {0, 0, 0, 1}, { 0, 0, 0, 0}, {0, 0, 0, 0} }, |
| 967 |
{ {128, 0, 0, 0}, {1, 0, 0, 0}, {129, 1, 0, 0}, {1, 1, 1, 0} }, |
| 968 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, {129, 0, 0, 0}, {1, 1, 0, 0} }, |
| 969 |
{ {128, 1, 1, 1}, {0, 0, 1, 1}, { 0, 0, 1, 1}, {0, 0, 0, 129} }, |
| 970 |
{ {128, 0, 129, 1}, {0, 0, 0, 1}, { 0, 0, 0, 1}, {0, 0, 0, 0} }, |
| 971 |
{ {128, 0, 0, 0}, {1, 0, 0, 0}, {129, 0, 0, 0}, {1, 1, 0, 0} }, |
| 972 |
{ {128, 1, 129, 0}, {0, 1, 1, 0}, { 0, 1, 1, 0}, {0, 1, 1, 0} }, |
| 973 |
{ {128, 0, 129, 1}, {0, 1, 1, 0}, { 0, 1, 1, 0}, {1, 1, 0, 0} }, |
| 974 |
{ {128, 0, 0, 1}, {0, 1, 1, 1}, {129, 1, 1, 0}, {1, 0, 0, 0} }, |
| 975 |
{ {128, 0, 0, 0}, {1, 1, 1, 1}, {129, 1, 1, 1}, {0, 0, 0, 0} }, |
| 976 |
{ {128, 1, 129, 1}, {0, 0, 0, 1}, { 1, 0, 0, 0}, {1, 1, 1, 0} }, |
| 977 |
{ {128, 0, 129, 1}, {1, 0, 0, 1}, { 1, 0, 0, 1}, {1, 1, 0, 0} }, |
| 978 |
{ {128, 1, 0, 1}, {0, 1, 0, 1}, { 0, 1, 0, 1}, {0, 1, 0, 129} }, |
| 979 |
{ {128, 0, 0, 0}, {1, 1, 1, 1}, { 0, 0, 0, 0}, {1, 1, 1, 129} }, |
| 980 |
{ {128, 1, 0, 1}, {1, 0, 129, 0}, { 0, 1, 0, 1}, {1, 0, 1, 0} }, |
| 981 |
{ {128, 0, 1, 1}, {0, 0, 1, 1}, {129, 1, 0, 0}, {1, 1, 0, 0} }, |
| 982 |
{ {128, 0, 129, 1}, {1, 1, 0, 0}, { 0, 0, 1, 1}, {1, 1, 0, 0} }, |
| 983 |
{ {128, 1, 0, 1}, {0, 1, 0, 1}, {129, 0, 1, 0}, {1, 0, 1, 0} }, |
| 984 |
{ {128, 1, 1, 0}, {1, 0, 0, 1}, { 0, 1, 1, 0}, {1, 0, 0, 129} }, |
| 985 |
{ {128, 1, 0, 1}, {1, 0, 1, 0}, { 1, 0, 1, 0}, {0, 1, 0, 129} }, |
| 986 |
{ {128, 1, 129, 1}, {0, 0, 1, 1}, { 1, 1, 0, 0}, {1, 1, 1, 0} }, |
| 987 |
{ {128, 0, 0, 1}, {0, 0, 1, 1}, {129, 1, 0, 0}, {1, 0, 0, 0} }, |
| 988 |
{ {128, 0, 129, 1}, {0, 0, 1, 0}, { 0, 1, 0, 0}, {1, 1, 0, 0} }, |
| 989 |
{ {128, 0, 129, 1}, {1, 0, 1, 1}, { 1, 1, 0, 1}, {1, 1, 0, 0} }, |
| 990 |
{ {128, 1, 129, 0}, {1, 0, 0, 1}, { 1, 0, 0, 1}, {0, 1, 1, 0} }, |
| 991 |
{ {128, 0, 1, 1}, {1, 1, 0, 0}, { 1, 1, 0, 0}, {0, 0, 1, 129} }, |
| 992 |
{ {128, 1, 1, 0}, {0, 1, 1, 0}, { 1, 0, 0, 1}, {1, 0, 0, 129} }, |
| 993 |
{ {128, 0, 0, 0}, {0, 1, 129, 0}, { 0, 1, 1, 0}, {0, 0, 0, 0} }, |
| 994 |
{ {128, 1, 0, 0}, {1, 1, 129, 0}, { 0, 1, 0, 0}, {0, 0, 0, 0} }, |
| 995 |
{ {128, 0, 129, 0}, {0, 1, 1, 1}, { 0, 0, 1, 0}, {0, 0, 0, 0} }, |
| 996 |
{ {128, 0, 0, 0}, {0, 0, 129, 0}, { 0, 1, 1, 1}, {0, 0, 1, 0} }, |
| 997 |
{ {128, 0, 0, 0}, {0, 1, 0, 0}, {129, 1, 1, 0}, {0, 1, 0, 0} }, |
| 998 |
{ {128, 1, 1, 0}, {1, 1, 0, 0}, { 1, 0, 0, 1}, {0, 0, 1, 129} }, |
| 999 |
{ {128, 0, 1, 1}, {0, 1, 1, 0}, { 1, 1, 0, 0}, {1, 0, 0, 129} }, |
| 1000 |
{ {128, 1, 129, 0}, {0, 0, 1, 1}, { 1, 0, 0, 1}, {1, 1, 0, 0} }, |
| 1001 |
{ {128, 0, 129, 1}, {1, 0, 0, 1}, { 1, 1, 0, 0}, {0, 1, 1, 0} }, |
| 1002 |
{ {128, 1, 1, 0}, {1, 1, 0, 0}, { 1, 1, 0, 0}, {1, 0, 0, 129} }, |
| 1003 |
{ {128, 1, 1, 0}, {0, 0, 1, 1}, { 0, 0, 1, 1}, {1, 0, 0, 129} }, |
| 1004 |
{ {128, 1, 1, 1}, {1, 1, 1, 0}, { 1, 0, 0, 0}, {0, 0, 0, 129} }, |
| 1005 |
{ {128, 0, 0, 1}, {1, 0, 0, 0}, { 1, 1, 1, 0}, {0, 1, 1, 129} }, |
| 1006 |
{ {128, 0, 0, 0}, {1, 1, 1, 1}, { 0, 0, 1, 1}, {0, 0, 1, 129} }, |
| 1007 |
{ {128, 0, 129, 1}, {0, 0, 1, 1}, { 1, 1, 1, 1}, {0, 0, 0, 0} }, |
| 1008 |
{ {128, 0, 129, 0}, {0, 0, 1, 0}, { 1, 1, 1, 0}, {1, 1, 1, 0} }, |
| 1009 |
{ {128, 1, 0, 0}, {0, 1, 0, 0}, { 0, 1, 1, 1}, {0, 1, 1, 129} } |
| 1010 |
}, |
| 1011 |
{ |
| 1012 |
{ {128, 0, 1, 129}, {0, 0, 1, 1}, { 0, 2, 2, 1}, { 2, 2, 2, 130} }, |
| 1013 |
{ {128, 0, 0, 129}, {0, 0, 1, 1}, {130, 2, 1, 1}, { 2, 2, 2, 1} }, |
| 1014 |
{ {128, 0, 0, 0}, {2, 0, 0, 1}, {130, 2, 1, 1}, { 2, 2, 1, 129} }, |
| 1015 |
{ {128, 2, 2, 130}, {0, 0, 2, 2}, { 0, 0, 1, 1}, { 0, 1, 1, 129} }, |
| 1016 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, {129, 1, 2, 2}, { 1, 1, 2, 130} }, |
| 1017 |
{ {128, 0, 1, 129}, {0, 0, 1, 1}, { 0, 0, 2, 2}, { 0, 0, 2, 130} }, |
| 1018 |
{ {128, 0, 2, 130}, {0, 0, 2, 2}, { 1, 1, 1, 1}, { 1, 1, 1, 129} }, |
| 1019 |
{ {128, 0, 1, 1}, {0, 0, 1, 1}, {130, 2, 1, 1}, { 2, 2, 1, 129} }, |
| 1020 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, {129, 1, 1, 1}, { 2, 2, 2, 130} }, |
| 1021 |
{ {128, 0, 0, 0}, {1, 1, 1, 1}, {129, 1, 1, 1}, { 2, 2, 2, 130} }, |
| 1022 |
{ {128, 0, 0, 0}, {1, 1, 129, 1}, { 2, 2, 2, 2}, { 2, 2, 2, 130} }, |
| 1023 |
{ {128, 0, 1, 2}, {0, 0, 129, 2}, { 0, 0, 1, 2}, { 0, 0, 1, 130} }, |
| 1024 |
{ {128, 1, 1, 2}, {0, 1, 129, 2}, { 0, 1, 1, 2}, { 0, 1, 1, 130} }, |
| 1025 |
{ {128, 1, 2, 2}, {0, 129, 2, 2}, { 0, 1, 2, 2}, { 0, 1, 2, 130} }, |
| 1026 |
{ {128, 0, 1, 129}, {0, 1, 1, 2}, { 1, 1, 2, 2}, { 1, 2, 2, 130} }, |
| 1027 |
{ {128, 0, 1, 129}, {2, 0, 0, 1}, {130, 2, 0, 0}, { 2, 2, 2, 0} }, |
| 1028 |
{ {128, 0, 0, 129}, {0, 0, 1, 1}, { 0, 1, 1, 2}, { 1, 1, 2, 130} }, |
| 1029 |
{ {128, 1, 1, 129}, {0, 0, 1, 1}, {130, 0, 0, 1}, { 2, 2, 0, 0} }, |
| 1030 |
{ {128, 0, 0, 0}, {1, 1, 2, 2}, {129, 1, 2, 2}, { 1, 1, 2, 130} }, |
| 1031 |
{ {128, 0, 2, 130}, {0, 0, 2, 2}, { 0, 0, 2, 2}, { 1, 1, 1, 129} }, |
| 1032 |
{ {128, 1, 1, 129}, {0, 1, 1, 1}, { 0, 2, 2, 2}, { 0, 2, 2, 130} }, |
| 1033 |
{ {128, 0, 0, 129}, {0, 0, 0, 1}, {130, 2, 2, 1}, { 2, 2, 2, 1} }, |
| 1034 |
{ {128, 0, 0, 0}, {0, 0, 129, 1}, { 0, 1, 2, 2}, { 0, 1, 2, 130} }, |
| 1035 |
{ {128, 0, 0, 0}, {1, 1, 0, 0}, {130, 2, 129, 0}, { 2, 2, 1, 0} }, |
| 1036 |
{ {128, 1, 2, 130}, {0, 129, 2, 2}, { 0, 0, 1, 1}, { 0, 0, 0, 0} }, |
| 1037 |
{ {128, 0, 1, 2}, {0, 0, 1, 2}, {129, 1, 2, 2}, { 2, 2, 2, 130} }, |
| 1038 |
{ {128, 1, 1, 0}, {1, 2, 130, 1}, {129, 2, 2, 1}, { 0, 1, 1, 0} }, |
| 1039 |
{ {128, 0, 0, 0}, {0, 1, 129, 0}, { 1, 2, 130, 1}, { 1, 2, 2, 1} }, |
| 1040 |
{ {128, 0, 2, 2}, {1, 1, 0, 2}, {129, 1, 0, 2}, { 0, 0, 2, 130} }, |
| 1041 |
{ {128, 1, 1, 0}, {0, 129, 1, 0}, { 2, 0, 0, 2}, { 2, 2, 2, 130} }, |
| 1042 |
{ {128, 0, 1, 1}, {0, 1, 2, 2}, { 0, 1, 130, 2}, { 0, 0, 1, 129} }, |
| 1043 |
{ {128, 0, 0, 0}, {2, 0, 0, 0}, {130, 2, 1, 1}, { 2, 2, 2, 129} }, |
| 1044 |
{ {128, 0, 0, 0}, {0, 0, 0, 2}, {129, 1, 2, 2}, { 1, 2, 2, 130} }, |
| 1045 |
{ {128, 2, 2, 130}, {0, 0, 2, 2}, { 0, 0, 1, 2}, { 0, 0, 1, 129} }, |
| 1046 |
{ {128, 0, 1, 129}, {0, 0, 1, 2}, { 0, 0, 2, 2}, { 0, 2, 2, 130} }, |
| 1047 |
{ {128, 1, 2, 0}, {0, 129, 2, 0}, { 0, 1, 130, 0}, { 0, 1, 2, 0} }, |
| 1048 |
{ {128, 0, 0, 0}, {1, 1, 129, 1}, { 2, 2, 130, 2}, { 0, 0, 0, 0} }, |
| 1049 |
{ {128, 1, 2, 0}, {1, 2, 0, 1}, {130, 0, 129, 2}, { 0, 1, 2, 0} }, |
| 1050 |
{ {128, 1, 2, 0}, {2, 0, 1, 2}, {129, 130, 0, 1}, { 0, 1, 2, 0} }, |
| 1051 |
{ {128, 0, 1, 1}, {2, 2, 0, 0}, { 1, 1, 130, 2}, { 0, 0, 1, 129} }, |
| 1052 |
{ {128, 0, 1, 1}, {1, 1, 130, 2}, { 2, 2, 0, 0}, { 0, 0, 1, 129} }, |
| 1053 |
{ {128, 1, 0, 129}, {0, 1, 0, 1}, { 2, 2, 2, 2}, { 2, 2, 2, 130} }, |
| 1054 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, {130, 1, 2, 1}, { 2, 1, 2, 129} }, |
| 1055 |
{ {128, 0, 2, 2}, {1, 129, 2, 2}, { 0, 0, 2, 2}, { 1, 1, 2, 130} }, |
| 1056 |
{ {128, 0, 2, 130}, {0, 0, 1, 1}, { 0, 0, 2, 2}, { 0, 0, 1, 129} }, |
| 1057 |
{ {128, 2, 2, 0}, {1, 2, 130, 1}, { 0, 2, 2, 0}, { 1, 2, 2, 129} }, |
| 1058 |
{ {128, 1, 0, 1}, {2, 2, 130, 2}, { 2, 2, 2, 2}, { 0, 1, 0, 129} }, |
| 1059 |
{ {128, 0, 0, 0}, {2, 1, 2, 1}, {130, 1, 2, 1}, { 2, 1, 2, 129} }, |
| 1060 |
{ {128, 1, 0, 129}, {0, 1, 0, 1}, { 0, 1, 0, 1}, { 2, 2, 2, 130} }, |
| 1061 |
{ {128, 2, 2, 130}, {0, 1, 1, 1}, { 0, 2, 2, 2}, { 0, 1, 1, 129} }, |
| 1062 |
{ {128, 0, 0, 2}, {1, 129, 1, 2}, { 0, 0, 0, 2}, { 1, 1, 1, 130} }, |
| 1063 |
{ {128, 0, 0, 0}, {2, 129, 1, 2}, { 2, 1, 1, 2}, { 2, 1, 1, 130} }, |
| 1064 |
{ {128, 2, 2, 2}, {0, 129, 1, 1}, { 0, 1, 1, 1}, { 0, 2, 2, 130} }, |
| 1065 |
{ {128, 0, 0, 2}, {1, 1, 1, 2}, {129, 1, 1, 2}, { 0, 0, 0, 130} }, |
| 1066 |
{ {128, 1, 1, 0}, {0, 129, 1, 0}, { 0, 1, 1, 0}, { 2, 2, 2, 130} }, |
| 1067 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, { 2, 1, 129, 2}, { 2, 1, 1, 130} }, |
| 1068 |
{ {128, 1, 1, 0}, {0, 129, 1, 0}, { 2, 2, 2, 2}, { 2, 2, 2, 130} }, |
| 1069 |
{ {128, 0, 2, 2}, {0, 0, 1, 1}, { 0, 0, 129, 1}, { 0, 0, 2, 130} }, |
| 1070 |
{ {128, 0, 2, 2}, {1, 1, 2, 2}, {129, 1, 2, 2}, { 0, 0, 2, 130} }, |
| 1071 |
{ {128, 0, 0, 0}, {0, 0, 0, 0}, { 0, 0, 0, 0}, { 2, 129, 1, 130} }, |
| 1072 |
{ {128, 0, 0, 130}, {0, 0, 0, 1}, { 0, 0, 0, 2}, { 0, 0, 0, 129} }, |
| 1073 |
{ {128, 2, 2, 2}, {1, 2, 2, 2}, { 0, 2, 2, 2}, {129, 2, 2, 130} }, |
| 1074 |
{ {128, 1, 0, 129}, {2, 2, 2, 2}, { 2, 2, 2, 2}, { 2, 2, 2, 130} }, |
| 1075 |
{ {128, 1, 1, 129}, {2, 0, 1, 1}, {130, 2, 0, 1}, { 2, 2, 2, 0} } |
| 1076 |
} |
| 1077 |
}; |
| 1078 |
|
| 1079 |
static int aWeight2[] = { 0, 21, 43, 64 }; |
| 1080 |
static int aWeight3[] = { 0, 9, 18, 27, 37, 46, 55, 64 }; |
| 1081 |
static int aWeight4[] = { 0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64 }; |
| 1082 |
|
| 1083 |
static unsigned char sModeHasPBits = 0b11001011; |
| 1084 |
|
| 1085 |
bcdec__bitstream_t bstream; |
| 1086 |
int mode, partition, numPartitions, numEndpoints, i, j, k, rotation, partitionSet; |
| 1087 |
int indexSelectionBit, indexBits, indexBits2, index, index2; |
| 1088 |
int endpoints[6][4]; |
| 1089 |
char indices[4][4]; |
| 1090 |
int r, g, b, a; |
| 1091 |
int* weights, * weights2; |
| 1092 |
unsigned char* decompressed; |
| 1093 |
|
| 1094 |
decompressed = (unsigned char*)decompressedBlock; |
| 1095 |
|
| 1096 |
bstream.low = ((unsigned long long*)compressedBlock)[0]; |
| 1097 |
bstream.high = ((unsigned long long*)compressedBlock)[1]; |
| 1098 |
|
| 1099 |
for (mode = 0; mode < 8 && (0 == bcdec__bitstream_read_bit(&bstream)); ++mode); |
| 1100 |
|
| 1101 |
|
| 1102 |
if (mode >= 8) { |
| 1103 |
for (i = 0; i < 4; ++i) { |
| 1104 |
for (j = 0; j < 4; ++j) { |
| 1105 |
decompressed[j * 4 + 0] = 0; |
| 1106 |
decompressed[j * 4 + 1] = 0; |
| 1107 |
decompressed[j * 4 + 2] = 0; |
| 1108 |
decompressed[j * 4 + 3] = 0; |
| 1109 |
} |
| 1110 |
decompressed += destinationPitch; |
| 1111 |
} |
| 1112 |
|
| 1113 |
return; |
| 1114 |
} |
| 1115 |
|
| 1116 |
partition = 0; |
| 1117 |
numPartitions = 1; |
| 1118 |
rotation = 0; |
| 1119 |
indexSelectionBit = 0; |
| 1120 |
|
| 1121 |
if (mode == 0 || mode == 1 || mode == 2 || mode == 3 || mode == 7) { |
| 1122 |
numPartitions = (mode == 0 || mode == 2) ? 3 : 2; |
| 1123 |
partition = bcdec__bitstream_read_bits(&bstream, (mode == 0) ? 4 : 6); |
| 1124 |
} |
| 1125 |
|
| 1126 |
numEndpoints = numPartitions * 2; |
| 1127 |
|
| 1128 |
if (mode == 4 || mode == 5) { |
| 1129 |
rotation = bcdec__bitstream_read_bits(&bstream, 2); |
| 1130 |
|
| 1131 |
if (mode == 4) { |
| 1132 |
indexSelectionBit = bcdec__bitstream_read_bit(&bstream); |
| 1133 |
} |
| 1134 |
} |
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
for (i = 0; i < 3; ++i) { |
| 1139 |
for (j = 0; j < numEndpoints; ++j) { |
| 1140 |
endpoints[j][i] = bcdec__bitstream_read_bits(&bstream, actual_bits_count[0][mode]); |
| 1141 |
} |
| 1142 |
} |
| 1143 |
|
| 1144 |
if (actual_bits_count[1][mode] > 0) { |
| 1145 |
for (j = 0; j < numEndpoints; ++j) { |
| 1146 |
endpoints[j][3] = bcdec__bitstream_read_bits(&bstream, actual_bits_count[1][mode]); |
| 1147 |
} |
| 1148 |
} |
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
if (mode == 0 || mode == 1 || mode == 3 || mode == 6 || mode == 7) { |
| 1153 |
for (i = 0; i < numEndpoints; ++i) { |
| 1154 |
|
| 1155 |
for (j = 0; j < 4; ++j) { |
| 1156 |
endpoints[i][j] <<= 1; |
| 1157 |
} |
| 1158 |
} |
| 1159 |
|
| 1160 |
|
| 1161 |
if (mode == 1) { |
| 1162 |
i = bcdec__bitstream_read_bit(&bstream); |
| 1163 |
j = bcdec__bitstream_read_bit(&bstream); |
| 1164 |
|
| 1165 |
|
| 1166 |
for (k = 0; k < 3; ++k) { |
| 1167 |
endpoints[0][k] |= i; |
| 1168 |
endpoints[1][k] |= i; |
| 1169 |
endpoints[2][k] |= j; |
| 1170 |
endpoints[3][k] |= j; |
| 1171 |
} |
| 1172 |
} else if (sModeHasPBits & (1 << mode)) { |
| 1173 |
|
| 1174 |
for (i = 0; i < numEndpoints; ++i) { |
| 1175 |
j = bcdec__bitstream_read_bit(&bstream); |
| 1176 |
for (k = 0; k < 4; ++k) { |
| 1177 |
endpoints[i][k] |= j; |
| 1178 |
} |
| 1179 |
} |
| 1180 |
} |
| 1181 |
} |
| 1182 |
|
| 1183 |
for (i = 0; i < numEndpoints; ++i) { |
| 1184 |
|
| 1185 |
j = actual_bits_count[0][mode] + ((sModeHasPBits >> mode) & 1); |
| 1186 |
|
| 1187 |
for (k = 0; k < 3; ++k) { |
| 1188 |
|
| 1189 |
endpoints[i][k] = endpoints[i][k] << (8 - j); |
| 1190 |
|
| 1191 |
endpoints[i][k] = endpoints[i][k] | (endpoints[i][k] >> j); |
| 1192 |
} |
| 1193 |
|
| 1194 |
|
| 1195 |
j = actual_bits_count[1][mode] + ((sModeHasPBits >> mode) & 1); |
| 1196 |
|
| 1197 |
|
| 1198 |
endpoints[i][3] = endpoints[i][3] << (8 - j); |
| 1199 |
|
| 1200 |
endpoints[i][3] = endpoints[i][3] | (endpoints[i][3] >> j); |
| 1201 |
} |
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
if (!actual_bits_count[1][mode]) { |
| 1206 |
for (j = 0; j < numEndpoints; ++j) { |
| 1207 |
endpoints[j][3] = 0xFF; |
| 1208 |
} |
| 1209 |
} |
| 1210 |
|
| 1211 |
|
| 1212 |
indexBits = (mode == 0 || mode == 1) ? 3 : ((mode == 6) ? 4 : 2); |
| 1213 |
indexBits2 = (mode == 4) ? 3 : ((mode == 5) ? 2 : 0); |
| 1214 |
weights = (indexBits == 2) ? aWeight2 : ((indexBits == 3) ? aWeight3 : aWeight4); |
| 1215 |
weights2 = (indexBits2 == 2) ? aWeight2 : aWeight3; |
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
for (i = 0; i < 4; ++i) { |
| 1220 |
for (j = 0; j < 4; ++j) { |
| 1221 |
partitionSet = (numPartitions == 1) ? ((i | j) ? 0 : 128) : partition_sets[numPartitions - 2][partition][i][j]; |
| 1222 |
|
| 1223 |
indexBits = (mode == 0 || mode == 1) ? 3 : ((mode == 6) ? 4 : 2); |
| 1224 |
|
| 1225 |
|
| 1226 |
if (partitionSet & 0x80) { |
| 1227 |
indexBits--; |
| 1228 |
} |
| 1229 |
|
| 1230 |
indices[i][j] = bcdec__bitstream_read_bits(&bstream, indexBits); |
| 1231 |
} |
| 1232 |
} |
| 1233 |
|
| 1234 |
|
| 1235 |
for (i = 0; i < 4; ++i) { |
| 1236 |
for (j = 0; j < 4; ++j) { |
| 1237 |
partitionSet = (numPartitions == 1) ? ((i|j) ? 0 : 128) : partition_sets[numPartitions - 2][partition][i][j]; |
| 1238 |
partitionSet &= 0x03; |
| 1239 |
|
| 1240 |
index = indices[i][j]; |
| 1241 |
|
| 1242 |
if (!indexBits2) { |
| 1243 |
r = bcdec__interpolate(endpoints[partitionSet * 2][0], endpoints[partitionSet * 2 + 1][0], weights, index); |
| 1244 |
g = bcdec__interpolate(endpoints[partitionSet * 2][1], endpoints[partitionSet * 2 + 1][1], weights, index); |
| 1245 |
b = bcdec__interpolate(endpoints[partitionSet * 2][2], endpoints[partitionSet * 2 + 1][2], weights, index); |
| 1246 |
a = bcdec__interpolate(endpoints[partitionSet * 2][3], endpoints[partitionSet * 2 + 1][3], weights, index); |
| 1247 |
} else { |
| 1248 |
index2 = bcdec__bitstream_read_bits(&bstream, (i|j) ? indexBits2 : (indexBits2 - 1)); |
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
*/ |
| 1253 |
if (!indexSelectionBit) { |
| 1254 |
r = bcdec__interpolate(endpoints[partitionSet * 2][0], endpoints[partitionSet * 2 + 1][0], weights, index); |
| 1255 |
g = bcdec__interpolate(endpoints[partitionSet * 2][1], endpoints[partitionSet * 2 + 1][1], weights, index); |
| 1256 |
b = bcdec__interpolate(endpoints[partitionSet * 2][2], endpoints[partitionSet * 2 + 1][2], weights, index); |
| 1257 |
a = bcdec__interpolate(endpoints[partitionSet * 2][3], endpoints[partitionSet * 2 + 1][3], weights2, index2); |
| 1258 |
} else { |
| 1259 |
r = bcdec__interpolate(endpoints[partitionSet * 2][0], endpoints[partitionSet * 2 + 1][0], weights2, index2); |
| 1260 |
g = bcdec__interpolate(endpoints[partitionSet * 2][1], endpoints[partitionSet * 2 + 1][1], weights2, index2); |
| 1261 |
b = bcdec__interpolate(endpoints[partitionSet * 2][2], endpoints[partitionSet * 2 + 1][2], weights2, index2); |
| 1262 |
a = bcdec__interpolate(endpoints[partitionSet * 2][3], endpoints[partitionSet * 2 + 1][3], weights, index); |
| 1263 |
} |
| 1264 |
} |
| 1265 |
|
| 1266 |
switch (rotation) { |
| 1267 |
case 1: { */ |
| 1268 |
bcdec__swap_values(&a, &r); |
| 1269 |
} break; |
| 1270 |
case 2: { */ |
| 1271 |
bcdec__swap_values(&a, &g); |
| 1272 |
} break; |
| 1273 |
case 3: { |
| 1274 |
bcdec__swap_values(&a, &b); |
| 1275 |
} break; |
| 1276 |
} |
| 1277 |
|
| 1278 |
decompressed[j * 4 + 0] = r; |
| 1279 |
decompressed[j * 4 + 1] = g; |
| 1280 |
decompressed[j * 4 + 2] = b; |
| 1281 |
decompressed[j * 4 + 3] = a; |
| 1282 |
} |
| 1283 |
|
| 1284 |
decompressed += destinationPitch; |
| 1285 |
} |
| 1286 |
} |
| 1287 |
|
| 1288 |
#endif |
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|