70 int shift =
av_log2(denom - 1) + 1;
71 uint64_t ret = (1ULL << 52) / denom;
72 uint64_t err = (1ULL << 52) - ret * denom;
76 return ret + err / denom;
89 uint64_t l = x * (mantissa & 0xffffffff);
90 uint64_t h = x * (mantissa >> 32);
100 return (x << 1) ^ (x >> 7);
105 static const uint8_t series[] = { 1, 2, 3, 5, 8, 13, 21 };
112 for (i = 0; i < 7; i++) {
121 if (bits < 0 || bits > 31) {
124 }
else if (bits == 0) {
139 int i, j, scale_factor;
140 unsigned prob, cumulative_target;
141 unsigned cumul_prob = 0;
142 unsigned scaled_cumul_prob = 0;
145 rac->
prob[257] = UINT_MAX;
147 for (i = 1; i < 257; i++) {
152 if ((uint64_t)cumul_prob + rac->
prob[i] > UINT_MAX) {
156 cumul_prob += rac->
prob[i];
164 for (j = 0; j < prob; j++)
175 scale_factor =
av_log2(cumul_prob);
177 if (cumul_prob & (cumul_prob - 1)) {
179 for (i = 1; i < 257; i++) {
181 scaled_cumul_prob += rac->
prob[i];
185 cumulative_target = 1 << scale_factor;
187 if (scaled_cumul_prob > cumulative_target) {
189 "Scaled probabilities are larger than target!\n");
193 scaled_cumul_prob = cumulative_target - scaled_cumul_prob;
195 for (i = 1; scaled_cumul_prob; i = (i & 0x7f) + 1) {
214 rac->
scale = scale_factor;
217 for (i = 1; i < 257; i++)
224 uint8_t *diff,
int w,
int *left,
237 for (i = 0; i < w; i++) {
238 l =
mid_pred(l, src1[i], l + src1[i] - lt) + diff[i];
258 L = buf[width - stride - 1];
266 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++) {
301 TL = buf[width - (2 *
stride) - 1];
302 L = buf[width - stride - 1];
322 memset(dst + i, 0, count);
337 if (l->
zeros == esc_count) {
352 int width,
int esc_count)
357 const uint8_t *src_start = src;
358 uint8_t mask1 = -(esc_count < 2);
359 uint8_t mask2 = -(esc_count < 3);
360 uint8_t *end = dst + (width - 2);
365 if (end - dst < count) {
370 memset(dst, 0, count);
377 while (!zero_run && dst + i < end) {
379 if (src + i >= src_end)
382 !(src[i] | (src[i + 1] & mask1) | (src[i + 2] & mask2));
399 return src_start - src;
406 const uint8_t *src,
int src_size)
412 int esc_count = src[0];
415 const uint8_t *src_end = src + src_size;
422 if (esc_count &&
AV_RL32(src + 1) < length) {
434 for (i = 0; i <
height; i++)
440 "Output more bytes than length (%d of %d)\n", read,
442 }
else if (esc_count < 8) {
446 for (i = 0; i <
height; i++) {
448 src_end, width, esc_count);
454 if (src_size < width * height)
457 for (i = 0; i <
height; i++) {
458 memcpy(dst + (i * stride), src, width);
462 }
else if (esc_count == 0xff) {
464 for (i = 0; i <
height; i++)
465 memset(dst + i * stride, src[1], width);
472 "Invalid zero run escape code! (%#x)\n", esc_count);
477 for (i = 0; i <
height; i++) {
482 for (i = 0; i <
height; i++) {
504 int buf_size = avpkt->
size;
508 uint32_t offset_gu = 0, offset_bv = 0, offset_ry = 9;
511 int i, j, planes = 3;
536 for (j = 0; j < avctx->
height; j++) {
537 for (i = 0; i < avctx->
width; i++)
538 AV_WN32(dst + i * 4, offset_gu);
568 for (i = 0; i < planes; i++)
570 if (offset_ry >= buf_size ||
571 offset_gu >= buf_size ||
572 offset_bv >= buf_size ||
573 (planes == 4 && offs[3] >= buf_size)) {
575 "Invalid frame offsets\n");
578 for (i = 0; i < planes; i++)
584 for (i = 0; i < planes; i++)
587 for (i = 0; i < avctx->
width; i++) {
604 for (i = 0; i < planes; i++)
616 if (offset_ry >= buf_size ||
617 offset_gu >= buf_size ||
618 offset_bv >= buf_size) {
620 "Invalid frame offsets\n");
626 buf_size - offset_ry);
629 buf + offset_gu, buf_size - offset_gu);
632 buf + offset_bv, buf_size - offset_bv);
642 if (offset_ry >= buf_size ||
643 offset_gu >= buf_size ||
644 offset_bv >= buf_size) {
646 "Invalid frame offsets\n");
652 buf_size - offset_ry);
655 buf + offset_gu, buf_size - offset_gu);
658 buf + offset_bv, buf_size - offset_bv);
662 "Unsupported Lagarith frame type: %#x\n", frametype);