72 uint64_t ret = (1ULL << 52) / denom;
73 uint64_t err = (1ULL << 52) - ret * denom;
77 return ret + err / denom;
90 uint64_t l = x * (mantissa & 0xffffffff);
91 uint64_t
h = x * (mantissa >> 32);
101 return (x * 2) ^ (x >> 7);
106 static const uint8_t series[] = { 1, 2, 3, 5, 8, 13, 21 };
113 for (i = 0; i < 7; i++) {
122 if (bits < 0 || bits > 31) {
125 }
else if (bits == 0) {
140 int i, j, scale_factor;
141 unsigned prob, cumulative_target;
142 unsigned cumul_prob = 0;
143 unsigned scaled_cumul_prob = 0;
146 rac->
prob[257] = UINT_MAX;
148 for (i = 1; i < 257; i++) {
153 if ((uint64_t)cumul_prob + rac->
prob[i] > UINT_MAX) {
157 cumul_prob += rac->
prob[i];
165 for (j = 0; j < prob; j++)
176 scale_factor =
av_log2(cumul_prob);
178 if (cumul_prob & (cumul_prob - 1)) {
180 for (i = 1; i <= 128; i++) {
182 scaled_cumul_prob += rac->
prob[i];
184 if (scaled_cumul_prob <= 0) {
188 for (; i < 257; i++) {
190 scaled_cumul_prob += rac->
prob[i];
194 if (scale_factor >= 32
U)
196 cumulative_target = 1
U << scale_factor;
198 if (scaled_cumul_prob > cumulative_target) {
200 "Scaled probabilities are larger than target!\n");
204 scaled_cumul_prob = cumulative_target - scaled_cumul_prob;
206 for (i = 1; scaled_cumul_prob; i = (i & 0x7f) + 1) {
225 rac->
scale = scale_factor;
228 for (i = 1; i < 257; i++)
248 for (i = 0; i < w; i++) {
249 l =
mid_pred(l, src1[i], l + src1[i] - lt) + diff[i];
268 L = buf[width - stride - 1];
276 TL = buf[width - (2 *
stride) - 1];
300 const int HEAD = is_luma ? 4 : 2;
303 L = buf[width - stride - 1];
304 TL = buf[HEAD - stride - 1];
305 for (i = 0; i < HEAD; i++) {
309 for (; i <
width; i++) {
310 L =
mid_pred(L & 0xFF, buf[i - stride], (L + buf[i - stride] - TL) & 0xFF) + buf[i];
315 TL = buf[width - (2 *
stride) - 1];
316 L = buf[width - stride - 1];
335 memset(dst + i, 0, count);
350 if (l->
zeros == esc_count) {
365 int width,
int esc_count)
371 uint8_t mask1 = -(esc_count < 2);
372 uint8_t mask2 = -(esc_count < 3);
377 memset(dst, 0, width);
382 if (end - dst < count) {
387 memset(dst, 0, count);
394 while (!zero_run && dst + i < end) {
396 if (i+2 >= src_end - src)
399 !(src[i] | (src[i + 1] & mask1) | (src[i + 2] & mask2));
416 return src - src_start;
432 const uint8_t *src_end = src + src_size;
446 if (esc_count &&
AV_RL32(src + 1) < length) {
451 if ((ret =
init_get_bits8(&gb, src + offset, src_size - offset)) < 0)
459 for (i = 0; i <
height; i++)
465 "Output more bytes than length (%d of %"PRIu32
")\n", read,
467 }
else if (esc_count < 8) {
473 for (i = 0; i <
height; i++) {
475 src_end, width, esc_count);
481 if (src_size < width * height)
484 for (i = 0; i <
height; i++) {
485 memcpy(dst + (i * stride), src, width);
489 }
else if (esc_count == 0xff) {
491 for (i = 0; i <
height; i++)
492 memset(dst + i * stride, src[1], width);
499 "Invalid zero run escape code! (%#x)\n", esc_count);
504 for (i = 0; i <
height; i++) {
509 for (i = 0; i <
height; i++) {
531 unsigned int buf_size = avpkt->
size;
536 uint32_t offset_gu = 0, offset_bv = 0, offset_ry = 9;
539 int i, j, planes = 3;
566 for (j = 0; j < avctx->
height; j++) {
567 for (i = 0; i < avctx->
width; i++)
568 AV_WN32(dst + i * 4, offset_gu);
572 for (j = 0; j < avctx->
height; j++) {
573 memset(dst, buf[1], avctx->
width * planes);
583 offset_gu |= 0xFF
U << 24;
590 for (j = 0; j < avctx->
height; j++) {
591 for (i = 0; i < avctx->
width; i++)
593 AV_WB24(dst + i * 3, offset_gu);
595 AV_WN32(dst + i * 4, offset_gu);
624 for (i = 0; i < planes; i++)
626 for (i = 0; i < planes; i++)
627 if (buf_size <= offs[i]) {
629 "Invalid frame offsets\n");
633 for (i = 0; i < planes; i++)
639 for (i = 0; i < planes; i++)
642 for (i = 0; i < avctx->
width; i++) {
659 for (i = 0; i < planes; i++)
669 if (offset_ry >= buf_size ||
670 offset_gu >= buf_size ||
671 offset_bv >= buf_size) {
673 "Invalid frame offsets\n");
679 buf_size - offset_ry);
682 buf + offset_gu, buf_size - offset_gu);
685 buf + offset_bv, buf_size - offset_bv);
692 if (buf_size <= offset_ry || buf_size <= offset_gu || buf_size <= offset_bv) {
696 if (offset_ry >= buf_size ||
697 offset_gu >= buf_size ||
698 offset_bv >= buf_size) {
700 "Invalid frame offsets\n");
706 buf_size - offset_ry);
709 buf + offset_gu, buf_size - offset_gu);
712 buf + offset_bv, buf_size - offset_bv);
716 "Unsupported Lagarith frame type: %#"PRIx8
"\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
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
void ff_lag_rac_init(lag_rac *l, GetBitContext *gb, int length)
#define AV_LOG_WARNING
Something somehow does not look correct.
static int init_thread_copy(AVCodecContext *avctx)
packed RGB 8:8:8, 24bpp, RGBRGB...
static av_cold int init(AVCodecContext *avctx)
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
AVCodec ff_lagarith_decoder
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
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 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
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. ...
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
static av_cold int lag_decode_init(AVCodecContext *avctx)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
static uint64_t softfloat_reciprocal(uint32_t denom)
Compute the 52-bit mantissa of 1/(double)denom.
obsolete arithmetic coded RGB (no longer encoded by upstream since version 1.1.0) ...
int width
picture width / height.
GLsizei GLboolean const GLfloat * value
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)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
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 int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
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.
void ff_llviddsp_init(LLVidDSPContext *c)
static unsigned int get_bits1(GetBitContext *s)
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.
GLint GLenum GLboolean GLsizei stride
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static av_cold int lag_decode_end(AVCodecContext *avctx)
solid non-grayscale color frame
#define MKBETAG(a, b, c, d)
static uint8_t lag_calc_zero_run(int8_t x)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
int(* add_left_pred)(uint8_t *dst, const uint8_t *src, ptrdiff_t w, int left)
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
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
void(* add_median_pred)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, ptrdiff_t w, int *left, int *left_top)
#define AV_PIX_FMT_0RGB32