70 uint64_t ret = (1ULL << 52) / denom;
71 uint64_t err = (1ULL << 52) - ret * denom;
75 return ret + err / denom;
88 uint64_t l = x * (mantissa & 0xffffffff);
89 uint64_t h = x * (mantissa >> 32);
99 return (x << 1) ^ (x >> 7);
104 static const uint8_t series[] = { 1, 2, 3, 5, 8, 13, 21 };
111 for (i = 0; i < 7; i++) {
120 if (bits < 0 || bits > 31) {
123 }
else if (bits == 0) {
138 int i, j, scale_factor;
139 unsigned prob, cumulative_target;
140 unsigned cumul_prob = 0;
141 unsigned scaled_cumul_prob = 0;
144 rac->
prob[257] = UINT_MAX;
146 for (i = 1; i < 257; i++) {
151 if ((uint64_t)cumul_prob + rac->
prob[i] > UINT_MAX) {
155 cumul_prob += rac->
prob[i];
163 for (j = 0; j < prob; j++)
174 scale_factor =
av_log2(cumul_prob);
176 if (cumul_prob & (cumul_prob - 1)) {
178 for (i = 1; i < 257; i++) {
180 scaled_cumul_prob += rac->
prob[i];
184 cumulative_target = 1 << scale_factor;
186 if (scaled_cumul_prob > cumulative_target) {
188 "Scaled probabilities are larger than target!\n");
192 scaled_cumul_prob = cumulative_target - scaled_cumul_prob;
194 for (i = 1; scaled_cumul_prob; i = (i & 0x7f) + 1) {
213 rac->
scale = scale_factor;
216 for (i = 1; i < 257; i++)
236 for (i = 0; i < w; i++) {
237 l =
mid_pred(l, src1[i], l + src1[i] - lt) + diff[i];
257 L = buf[width - stride - 1];
265 TL = buf[width - (2 *
stride) - 1];
289 const int HEAD = is_luma ? 4 : 2;
292 L = buf[width - stride - 1];
293 TL = buf[HEAD - stride - 1];
294 for (i = 0; i < HEAD; i++) {
298 for (; i<
width; i++) {
299 L =
mid_pred(L&0xFF, buf[i-stride], (L + buf[i-stride] - TL)&0xFF) + buf[i];
304 TL = buf[width - (2 *
stride) - 1];
305 L = buf[width - stride - 1];
325 memset(dst + i, 0, count);
340 if (l->
zeros == esc_count) {
355 int width,
int esc_count)
360 const uint8_t *src_start = src;
361 uint8_t mask1 = -(esc_count < 2);
362 uint8_t mask2 = -(esc_count < 3);
368 if (end - dst < count) {
373 memset(dst, 0, count);
380 while (!zero_run && dst + i < end) {
382 if (i+2 >= src_end - src)
385 !(src[i] | (src[i + 1] & mask1) | (src[i + 2] & mask2));
402 return src - src_start;
409 const uint8_t *src,
int src_size)
418 const uint8_t *src_end = src + src_size;
431 if (esc_count &&
AV_RL32(src + 1) < length) {
443 for (i = 0; i <
height; i++)
449 "Output more bytes than length (%d of %d)\n", read,
451 }
else if (esc_count < 8) {
455 for (i = 0; i <
height; i++) {
457 src_end, width, esc_count);
463 if (src_size < width * height)
466 for (i = 0; i <
height; i++) {
467 memcpy(dst + (i * stride), src, width);
471 }
else if (esc_count == 0xff) {
473 for (i = 0; i <
height; i++)
474 memset(dst + i * stride, src[1], width);
481 "Invalid zero run escape code! (%#x)\n", esc_count);
486 for (i = 0; i <
height; i++) {
491 for (i = 0; i <
height; i++) {
513 unsigned int buf_size = avpkt->
size;
517 uint32_t offset_gu = 0, offset_bv = 0, offset_ry = 9;
520 int i, j, planes = 3;
555 for (j = 0; j < avctx->
height; j++) {
556 for (i = 0; i < avctx->
width; i++)
557 AV_WN32(dst + i * 4, offset_gu);
561 for (j = 0; j < avctx->
height; j++) {
562 memset(dst, buf[1], avctx->
width * planes);
594 for (i = 0; i < planes; i++)
596 for (i = 0; i < planes; i++)
597 if (buf_size <= offs[i]) {
599 "Invalid frame offsets\n");
603 for (i = 0; i < planes; i++)
609 for (i = 0; i < planes; i++)
612 for (i = 0; i < avctx->
width; i++) {
629 for (i = 0; i < planes; i++)
641 if (offset_ry >= buf_size ||
642 offset_gu >= buf_size ||
643 offset_bv >= buf_size) {
645 "Invalid frame offsets\n");
651 buf_size - offset_ry);
654 buf + offset_gu, buf_size - offset_gu);
657 buf + offset_bv, buf_size - offset_bv);
666 if (buf_size <= offset_ry || buf_size <= offset_gu || buf_size <= offset_bv) {
670 if (offset_ry >= buf_size ||
671 offset_gu >= buf_size ||
672 offset_bv >= buf_size) {
674 "Invalid frame offsets\n");
680 buf_size - offset_ry);
683 buf + offset_gu, buf_size - offset_gu);
686 buf + offset_bv, buf_size - offset_bv);
690 "Unsupported Lagarith frame type: %#x\n", frametype);