69 int shift =
av_log2(denom - 1) + 1;
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++)
223 uint8_t *diff,
int w,
int *left,
236 for (i = 0; i < w; i++) {
237 l =
mid_pred(l, src1[i], l + src1[i] - lt) + diff[i];
252 int i, align_width = (width - 1) & ~31;
255 align_width, buf[0]);
256 for (i = align_width + 1; i <
width; i++)
257 buf[i] += buf[i - 1];
260 L = buf[width - stride - 1];
268 TL = buf[width - (2 *
stride) - 1];
289 align_width = (width - 1) & ~31;
292 for (i = align_width + 1; i <
width; i++)
293 buf[i] += buf[i - 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];
313 TL = buf[width - (2 *
stride) - 1];
314 L = buf[width - stride - 1];
334 memset(dst + i, 0, count);
349 if (l->
zeros == esc_count) {
364 int width,
int esc_count)
369 const uint8_t *src_start = src;
370 uint8_t mask1 = -(esc_count < 2);
371 uint8_t mask2 = -(esc_count < 3);
372 uint8_t *end = dst + (width - 2);
377 if (end - dst < count) {
382 memset(dst, 0, count);
389 while (!zero_run && dst + i < end) {
391 if (src + i >= src_end)
394 !(src[i] | (src[i + 1] & mask1) | (src[i + 2] & mask2));
411 return src_start - src;
418 const uint8_t *src,
int src_size)
424 int esc_count = src[0];
427 const uint8_t *src_end = src + src_size;
434 if (esc_count &&
AV_RL32(src + 1) < length) {
446 for (i = 0; i <
height; i++)
452 "Output more bytes than length (%d of %d)\n", read,
454 }
else if (esc_count < 8) {
458 for (i = 0; i <
height; i++) {
460 src_end, width, esc_count);
466 if (src_size < width * height)
469 for (i = 0; i <
height; i++) {
470 memcpy(dst + (i * stride), src, width);
474 }
else if (esc_count == 0xff) {
476 for (i = 0; i <
height; i++)
477 memset(dst + i * stride, src[1], width);
484 "Invalid zero run escape code! (%#x)\n", esc_count);
489 for (i = 0; i <
height; i++) {
494 for (i = 0; i <
height; i++) {
516 int buf_size = avpkt->
size;
521 uint32_t offset_gu = 0, offset_bv = 0, offset_ry = 9;
524 int i, j, planes = 3;
543 for (j = 0; j < avctx->
height; j++) {
544 for (i = 0; i < avctx->
width; i++)
545 AV_WN32(dst + i * 4, offset_gu);
575 for (i = 0; i < planes; i++)
577 if (offset_ry >= buf_size ||
578 offset_gu >= buf_size ||
579 offset_bv >= buf_size ||
580 (planes == 4 && offs[3] >= buf_size)) {
582 "Invalid frame offsets\n");
585 for (i = 0; i < planes; i++)
591 for (i = 0; i < planes; i++)
594 for (i = 0; i < avctx->
width; i++) {
611 for (i = 0; i < planes; i++)
623 if (offset_ry >= buf_size ||
624 offset_gu >= buf_size ||
625 offset_bv >= buf_size) {
627 "Invalid frame offsets\n");
633 buf_size - offset_ry);
636 buf + offset_gu, buf_size - offset_gu);
639 buf + offset_bv, buf_size - offset_bv);
649 if (offset_ry >= buf_size ||
650 offset_gu >= buf_size ||
651 offset_bv >= buf_size) {
653 "Invalid frame offsets\n");
659 buf_size - offset_ry);
662 buf + offset_gu, buf_size - offset_gu);
665 buf + offset_bv, buf_size - offset_bv);
669 "Unsupported Lagarith frame type: %#x\n", frametype);
static uint8_t lag_get_rac(lag_rac *l)
Decode a single byte from the compressed plane described by *l.
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
void ff_lag_rac_init(lag_rac *l, GetBitContext *gb, int length)
#define AV_LOG_WARNING
Something somehow does not look correct.
packed RGB 8:8:8, 24bpp, RGBRGB...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int lag_decode_arith_plane(LagarithContext *l, uint8_t *dst, int width, int height, int stride, const uint8_t *src, int src_size)
int zeros
number of consecutive zero bytes encountered
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
AVCodec ff_lagarith_decoder
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
static int lag_decode_zero_run_line(LagarithContext *l, uint8_t *dst, const uint8_t *src, const uint8_t *src_end, int width, int esc_count)
solid grayscale color frame
static void lag_pred_line(LagarithContext *l, uint8_t *buf, int width, int stride, int line)
Multithreading support functions.
int zeros_rem
number of zero bytes remaining to output
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
unsigned scale
Number of bits of precision in range.
bitstream reader API header.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void add_lag_median_prediction(uint8_t *dst, uint8_t *src1, uint8_t *diff, int w, int *left, int *left_top)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
int(* add_hfyu_left_prediction)(uint8_t *dst, const uint8_t *src, int w, int left)
const char * name
Name of the codec implementation.
static av_cold int lag_decode_init(AVCodecContext *avctx)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void(* add_hfyu_median_prediction)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top)
static uint64_t softfloat_reciprocal(uint32_t denom)
Compute the 52bit mantissa of 1/(double)denom.
obsolete arithmetic coded RGB (no longer encoded by upstream since version 1.1.0) ...
int width
picture width / height.
static int lag_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Decode a frame.
static int lag_decode_prob(GetBitContext *gb, uint32_t *value)
static int lag_decode_line(LagarithContext *l, lag_rac *rac, uint8_t *dst, int width, int stride, int esc_count)
Libavcodec external API header.
uint32_t prob[258]
Table of cumulative probability for each symbol.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static uint32_t softfloat_mul(uint32_t x, uint64_t mantissa)
(uint32_t)(x*f), where f has the given mantissa, and exponent 0 Used in combination with softfloat_re...
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
static void close(AVCodecParserContext *s)
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static av_cold int lag_decode_end(AVCodecContext *avctx)
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
static av_cold int init(AVCodecParserContext *s)
solid non-grayscale color frame
#define MKBETAG(a, b, c, d)
static uint8_t lag_calc_zero_run(int8_t x)
static void lag_pred_line_yuy2(LagarithContext *l, uint8_t *buf, int width, int stride, int line, int is_luma)
int key_frame
1 -> keyframe, 0-> not
reduced resolution YV12 frame
This structure stores compressed data.