69 uint64_t
ret = (1ULL << 52) / denom;
70 uint64_t err = (1ULL << 52) - ret * denom;
74 return ret + err / denom;
87 uint64_t l = x * (mantissa & 0xffffffff);
88 uint64_t h = x * (mantissa >> 32);
98 return (x << 1) ^ (x >> 7);
103 static const uint8_t series[] = { 1, 2, 3, 5, 8, 13, 21 };
110 for (i = 0; i < 7; i++) {
119 if (bits < 0 || bits > 31) {
122 }
else if (bits == 0) {
137 int i, j, scale_factor;
138 unsigned prob, cumulative_target;
139 unsigned cumul_prob = 0;
140 unsigned scaled_cumul_prob = 0;
143 rac->
prob[257] = UINT_MAX;
145 for (i = 1; i < 257; i++) {
150 if ((uint64_t)cumul_prob + rac->
prob[i] > UINT_MAX) {
154 cumul_prob += rac->
prob[i];
162 for (j = 0; j < prob; j++)
173 scale_factor =
av_log2(cumul_prob);
175 if (cumul_prob & (cumul_prob - 1)) {
177 for (i = 1; i < 257; i++) {
179 scaled_cumul_prob += rac->
prob[i];
183 cumulative_target = 1 << scale_factor;
185 if (scaled_cumul_prob > cumulative_target) {
187 "Scaled probabilities are larger than target!\n");
191 scaled_cumul_prob = cumulative_target - scaled_cumul_prob;
193 for (i = 1; scaled_cumul_prob; i = (i & 0x7f) + 1) {
212 rac->
scale = scale_factor;
215 for (i = 1; i < 257; i++)
235 for (i = 0; i < w; i++) {
236 l =
mid_pred(l, src1[i], l + src1[i] - lt) + diff[i];
256 L = buf[width - stride - 1];
264 TL = buf[width - (2 *
stride) - 1];
288 const int HEAD = is_luma ? 4 : 2;
291 L = buf[width - stride - 1];
292 TL = buf[HEAD - stride - 1];
293 for (i = 0; i < HEAD; i++) {
297 for (; i<
width; i++) {
298 L =
mid_pred(L&0xFF, buf[i-stride], (L + buf[i-stride] - TL)&0xFF) + buf[i];
303 TL = buf[width - (2 *
stride) - 1];
304 L = buf[width - stride - 1];
324 memset(dst + i, 0, count);
339 if (l->
zeros == esc_count) {
354 int width,
int esc_count)
360 uint8_t mask1 = -(esc_count < 2);
361 uint8_t mask2 = -(esc_count < 3);
367 if (end - dst < count) {
372 memset(dst, 0, count);
379 while (!zero_run && dst + i < end) {
381 if (i+2 >= src_end - src)
384 !(src[i] | (src[i + 1] & mask1) | (src[i + 2] & mask2));
401 return src - src_start;
417 const uint8_t *src_end = src + src_size;
430 if (esc_count &&
AV_RL32(src + 1) < length) {
442 for (i = 0; i <
height; i++)
448 "Output more bytes than length (%d of %d)\n", read,
450 }
else if (esc_count < 8) {
454 for (i = 0; i <
height; i++) {
456 src_end, width, esc_count);
462 if (src_size < width * height)
465 for (i = 0; i <
height; i++) {
466 memcpy(dst + (i * stride), src, width);
470 }
else if (esc_count == 0xff) {
472 for (i = 0; i <
height; i++)
473 memset(dst + i * stride, src[1], width);
480 "Invalid zero run escape code! (%#x)\n", esc_count);
485 for (i = 0; i <
height; i++) {
490 for (i = 0; i <
height; i++) {
512 unsigned int buf_size = avpkt->
size;
517 uint32_t offset_gu = 0, offset_bv = 0, offset_ry = 9;
520 int i, j, planes = 3;
547 for (j = 0; j < avctx->
height; j++) {
548 for (i = 0; i < avctx->
width; i++)
549 AV_WN32(dst + i * 4, offset_gu);
553 for (j = 0; j < avctx->
height; j++) {
554 memset(dst, buf[1], avctx->
width * planes);
564 offset_gu |= 0xFF
U << 24;
571 for (j = 0; j < avctx->
height; j++) {
572 for (i = 0; i < avctx->
width; i++)
574 AV_WB24(dst + i * 3, offset_gu);
576 AV_WN32(dst + i * 4, offset_gu);
606 for (i = 0; i < planes; i++)
608 for (i = 0; i < planes; i++)
609 if (buf_size <= offs[i]) {
611 "Invalid frame offsets\n");
615 for (i = 0; i < planes; i++)
621 for (i = 0; i < planes; i++)
624 for (i = 0; i < avctx->
width; i++) {
641 for (i = 0; i < planes; i++)
651 if (offset_ry >= buf_size ||
652 offset_gu >= buf_size ||
653 offset_bv >= buf_size) {
655 "Invalid frame offsets\n");
661 buf_size - offset_ry);
664 buf + offset_gu, buf_size - offset_gu);
667 buf + offset_bv, buf_size - offset_bv);
674 if (buf_size <= offset_ry || buf_size <= offset_gu || buf_size <= offset_bv) {
678 if (offset_ry >= buf_size ||
679 offset_gu >= buf_size ||
680 offset_bv >= buf_size) {
682 "Invalid frame offsets\n");
688 buf_size - offset_ry);
691 buf + offset_gu, buf_size - offset_gu);
694 buf + offset_bv, buf_size - offset_bv);
698 "Unsupported Lagarith frame type: %#x\n", frametype);