Reads and decodes a block Gilbert-Moore coded symbol */
| 510 | /** Reads and decodes a block Gilbert-Moore coded symbol |
| 511 | */ |
| 512 | void ff_bgmc_decode(GetBitContext *gb, unsigned int num, int32_t *dst, |
| 513 | unsigned int delta, unsigned int sx, |
| 514 | unsigned int *h, unsigned int *l, unsigned int *v, |
| 515 | uint8_t *cf_lut, unsigned int *cf_lut_status) |
| 516 | { |
| 517 | unsigned int i; |
| 518 | uint8_t *lut = bgmc_lut_getp(cf_lut, cf_lut_status, delta); |
| 519 | |
| 520 | // read current state |
| 521 | unsigned int high = *h; |
| 522 | unsigned int low = *l; |
| 523 | unsigned int value = *v; |
| 524 | |
| 525 | lut += sx * LUT_SIZE; |
| 526 | |
| 527 | // decode num samples |
| 528 | for (i = 0; i < num; i++) { |
| 529 | unsigned int range = high - low + 1; |
| 530 | unsigned int target = (((value - low + 1) << FREQ_BITS) - 1) / range; |
| 531 | unsigned int symbol = lut[target >> (FREQ_BITS - LUT_BITS)] << delta; |
| 532 | |
| 533 | while (cf_table[sx][symbol] > target) |
| 534 | symbol += 1 << delta; |
| 535 | |
| 536 | symbol = (symbol >> delta) - 1; |
| 537 | |
| 538 | high = low + ((range * cf_table[sx][(symbol ) << delta] - (1 << FREQ_BITS)) >> FREQ_BITS); |
| 539 | low = low + ((range * cf_table[sx][(symbol + 1) << delta] ) >> FREQ_BITS); |
| 540 | |
| 541 | while (1) { |
| 542 | if (high >= HALF) { |
| 543 | if (low >= HALF) { |
| 544 | value -= HALF; |
| 545 | low -= HALF; |
| 546 | high -= HALF; |
| 547 | } else if (low >= FIRST_QTR && high < THIRD_QTR) { |
| 548 | value -= FIRST_QTR; |
| 549 | low -= FIRST_QTR; |
| 550 | high -= FIRST_QTR; |
| 551 | } else break; |
| 552 | } |
| 553 | |
| 554 | low *= 2; |
| 555 | high = 2 * high + 1; |
| 556 | value = 2 * value + get_bits1(gb); |
| 557 | } |
| 558 | |
| 559 | *dst++ = symbol; |
| 560 | } |
| 561 | |
| 562 | // save current state |
| 563 | *h = high; |
| 564 | *l = low; |
| 565 | *v = value; |
| 566 | } |
| 567 |
no test coverage detected