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 <= 128; i++) {
179 scaled_cumul_prob += rac->
prob[i];
181 if (scaled_cumul_prob <= 0) {
185 for (; i < 257; i++) {
187 scaled_cumul_prob += rac->
prob[i];
191 cumulative_target = 1 << scale_factor;
193 if (scaled_cumul_prob > cumulative_target) {
195 "Scaled probabilities are larger than target!\n");
199 scaled_cumul_prob = cumulative_target - scaled_cumul_prob;
201 for (i = 1; scaled_cumul_prob; i = (i & 0x7f) + 1) {
220 rac->
scale = scale_factor;
223 for (i = 1; i < 257; i++)
230 uint8_t *diff,
int w,
int *left,
243 for (i = 0; i < w; i++) {
244 l =
mid_pred(l, src1[i], l + src1[i] - lt) + diff[i];
264 L = buf[width - stride - 1];
272 TL = buf[width - (2 *
stride) - 1];
296 const int HEAD = is_luma ? 4 : 2;
299 L = buf[width - stride - 1];
300 TL = buf[HEAD - stride - 1];
301 for (i = 0; i < HEAD; i++) {
305 for (; i<
width; i++) {
306 L =
mid_pred(L&0xFF, buf[i-stride], (L + buf[i-stride] - TL)&0xFF) + buf[i];
311 TL = buf[width - (2 *
stride) - 1];
312 L = buf[width - stride - 1];
332 memset(dst + i, 0, count);
347 if (l->
zeros == esc_count) {
362 int width,
int esc_count)
368 uint8_t mask1 = -(esc_count < 2);
369 uint8_t mask2 = -(esc_count < 3);
375 if (end - dst < count) {
380 memset(dst, 0, count);
387 while (!zero_run && dst + i < end) {
389 if (i+2 >= src_end - src)
392 !(src[i] | (src[i + 1] & mask1) | (src[i + 2] & mask2));
409 return src - src_start;
425 const uint8_t *src_end = src + src_size;
438 if (esc_count &&
AV_RL32(src + 1) < length) {
450 for (i = 0; i <
height; i++)
456 "Output more bytes than length (%d of %d)\n", read,
458 }
else if (esc_count < 8) {
462 for (i = 0; i <
height; i++) {
464 src_end, width, esc_count);
470 if (src_size < width * height)
473 for (i = 0; i <
height; i++) {
474 memcpy(dst + (i * stride), src, width);
478 }
else if (esc_count == 0xff) {
480 for (i = 0; i <
height; i++)
481 memset(dst + i * stride, src[1], width);
488 "Invalid zero run escape code! (%#x)\n", esc_count);
493 for (i = 0; i <
height; i++) {
498 for (i = 0; i <
height; i++) {
520 unsigned int buf_size = avpkt->
size;
525 uint32_t offset_gu = 0, offset_bv = 0, offset_ry = 9;
528 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);
572 offset_gu |= 0xFF
U << 24;
579 for (j = 0; j < avctx->
height; j++) {
580 for (i = 0; i < avctx->
width; i++)
582 AV_WB24(dst + i * 3, offset_gu);
584 AV_WN32(dst + i * 4, offset_gu);
614 for (i = 0; i < planes; i++)
616 for (i = 0; i < planes; i++)
617 if (buf_size <= offs[i]) {
619 "Invalid frame offsets\n");
623 for (i = 0; i < planes; i++)
629 for (i = 0; i < planes; i++)
632 for (i = 0; i < avctx->
width; i++) {
649 for (i = 0; i < planes; i++)
659 if (offset_ry >= buf_size ||
660 offset_gu >= buf_size ||
661 offset_bv >= buf_size) {
663 "Invalid frame offsets\n");
669 buf_size - offset_ry);
672 buf + offset_gu, buf_size - offset_gu);
675 buf + offset_bv, buf_size - offset_bv);
682 if (buf_size <= offset_ry || buf_size <= offset_gu || buf_size <= offset_bv) {
686 if (offset_ry >= buf_size ||
687 offset_gu >= buf_size ||
688 offset_bv >= buf_size) {
690 "Invalid frame offsets\n");
696 buf_size - offset_ry);
699 buf + offset_gu, buf_size - offset_gu);
702 buf + offset_bv, buf_size - offset_bv);
706 "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.
const char const char void * val
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
#define AVERROR_PATCHWELCOME
static int shift(int a, int b)
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.
static av_cold int init(AVCodecContext *avctx)
packed RGB 8:8:8, 24bpp, RGBRGB...
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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 *ptr)
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 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 const uint8_t offset[511][2]
static av_cold int end(AVCodecContext *avctx)
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
const char * name
Name of the codec implementation.
#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.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
#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. ...
int(* add_hfyu_left_prediction)(uint8_t *dst, const uint8_t *src, int w, int left)
Libavcodec external API header.
static av_cold int lag_decode_init(AVCodecContext *avctx)
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 ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
int width
picture width / height.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static int lag_decode_line(LagarithContext *l, lag_rac *rac, uint8_t *dst, int width, int stride, int esc_count)
uint32_t prob[258]
Table of cumulative probability for each symbol.
#define AV_PIX_FMT_0RGB32
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...
main external API structure.
static void close(AVCodecParserContext *s)
static unsigned int get_bits1(GetBitContext *s)
BYTE int const BYTE int int int height
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
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.
#define MKBETAG(a, b, c, d)
static av_cold int lag_decode_end(AVCodecContext *avctx)
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
solid non-grayscale color frame
static uint8_t lag_calc_zero_run(int8_t x)
#define AVERROR_INVALIDDATA
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
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.