72 uint64_t
ret = (1ULL << 52) / denom;
73 uint64_t err = (1ULL << 52) - ret * denom;
77 return ret + err / denom;
90 uint64_t l = x * (mantissa & 0xffffffff);
91 uint64_t h = x * (mantissa >> 32);
101 return (x << 1) ^ (x >> 7);
106 static const uint8_t series[] = { 1, 2, 3, 5, 8, 13, 21 };
113 for (i = 0; i < 7; i++) {
122 if (bits < 0 || bits > 31) {
125 }
else if (bits == 0) {
140 int i, j, scale_factor;
141 unsigned prob, cumulative_target;
142 unsigned cumul_prob = 0;
143 unsigned scaled_cumul_prob = 0;
146 rac->
prob[257] = UINT_MAX;
148 for (i = 1; i < 257; i++) {
153 if ((uint64_t)cumul_prob + rac->
prob[i] > UINT_MAX) {
157 cumul_prob += rac->
prob[i];
165 for (j = 0; j < prob; j++)
176 scale_factor =
av_log2(cumul_prob);
178 if (cumul_prob & (cumul_prob - 1)) {
180 for (i = 1; i <= 128; i++) {
182 scaled_cumul_prob += rac->
prob[i];
184 if (scaled_cumul_prob <= 0) {
188 for (; i < 257; i++) {
190 scaled_cumul_prob += rac->
prob[i];
194 cumulative_target = 1 << scale_factor;
196 if (scaled_cumul_prob > cumulative_target) {
198 "Scaled probabilities are larger than target!\n");
202 scaled_cumul_prob = cumulative_target - scaled_cumul_prob;
204 for (i = 1; scaled_cumul_prob; i = (i & 0x7f) + 1) {
223 rac->
scale = scale_factor;
226 for (i = 1; i < 257; i++)
233 uint8_t *diff,
int w,
int *left,
246 for (i = 0; i < w; i++) {
247 l =
mid_pred(l, src1[i], l + src1[i] - lt) + diff[i];
266 L = buf[width - stride - 1];
274 TL = buf[width - (2 * stride) - 1];
298 const int HEAD = is_luma ? 4 : 2;
301 L = buf[width - stride - 1];
302 TL = buf[HEAD - stride - 1];
303 for (i = 0; i < HEAD; i++) {
307 for (; i <
width; i++) {
308 L =
mid_pred(L & 0xFF, buf[i - stride], (L + buf[i - stride] - TL) & 0xFF) + buf[i];
309 TL = buf[i - stride];
313 TL = buf[width - (2 * stride) - 1];
314 L = buf[width - stride - 1];
333 memset(dst + i, 0, count);
348 if (l->
zeros == esc_count) {
363 int width,
int esc_count)
369 uint8_t mask1 = -(esc_count < 2);
370 uint8_t mask2 = -(esc_count < 3);
375 memset(dst, 0, width);
380 if (end - dst < count) {
385 memset(dst, 0, count);
392 while (!zero_run && dst + i < end) {
394 if (i+2 >= src_end - src)
397 !(src[i] | (src[i + 1] & mask1) | (src[i + 2] & mask2));
414 return src - src_start;
430 const uint8_t *src_end = src + src_size;
444 if (esc_count &&
AV_RL32(src + 1) < length) {
449 if ((ret =
init_get_bits8(&gb, src + offset, src_size - offset)) < 0)
457 for (i = 0; i <
height; i++)
463 "Output more bytes than length (%d of %"PRIu32
")\n", read,
465 }
else if (esc_count < 8) {
471 for (i = 0; i <
height; i++) {
473 src_end, width, esc_count);
479 if (src_size < width * height)
482 for (i = 0; i <
height; i++) {
483 memcpy(dst + (i * stride), src, width);
487 }
else if (esc_count == 0xff) {
489 for (i = 0; i <
height; i++)
490 memset(dst + i * stride, src[1], width);
497 "Invalid zero run escape code! (%#x)\n", esc_count);
502 for (i = 0; i <
height; i++) {
507 for (i = 0; i <
height; i++) {
529 unsigned int buf_size = avpkt->
size;
534 uint32_t offset_gu = 0, offset_bv = 0, offset_ry = 9;
537 int i, j, planes = 3;
564 for (j = 0; j < avctx->
height; j++) {
565 for (i = 0; i < avctx->
width; i++)
566 AV_WN32(dst + i * 4, offset_gu);
570 for (j = 0; j < avctx->
height; j++) {
571 memset(dst, buf[1], avctx->
width * planes);
581 offset_gu |= 0xFF
U << 24;
588 for (j = 0; j < avctx->
height; j++) {
589 for (i = 0; i < avctx->
width; i++)
591 AV_WB24(dst + i * 3, offset_gu);
593 AV_WN32(dst + i * 4, offset_gu);
622 for (i = 0; i < planes; i++)
624 for (i = 0; i < planes; i++)
625 if (buf_size <= offs[i]) {
627 "Invalid frame offsets\n");
631 for (i = 0; i < planes; i++)
637 for (i = 0; i < planes; i++)
640 for (i = 0; i < avctx->
width; i++) {
657 for (i = 0; i < planes; i++)
667 if (offset_ry >= buf_size ||
668 offset_gu >= buf_size ||
669 offset_bv >= buf_size) {
671 "Invalid frame offsets\n");
677 buf_size - offset_ry);
680 buf + offset_gu, buf_size - offset_gu);
683 buf + offset_bv, buf_size - offset_bv);
690 if (buf_size <= offset_ry || buf_size <= offset_gu || buf_size <= offset_bv) {
694 if (offset_ry >= buf_size ||
695 offset_gu >= buf_size ||
696 offset_bv >= buf_size) {
698 "Invalid frame offsets\n");
704 buf_size - offset_ry);
707 buf + offset_gu, buf_size - offset_gu);
710 buf + offset_bv, buf_size - offset_bv);
714 "Unsupported Lagarith frame type: %#"PRIx8
"\n", frametype);