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 * 2) ^ (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;
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++)
180 scale_factor =
av_log2(cumul_prob);
182 if (cumul_prob & (cumul_prob - 1)) {
184 for (
i = 1;
i <= 128;
i++) {
186 scaled_cumul_prob += rac->
prob[
i];
188 if (scaled_cumul_prob <= 0) {
192 for (;
i < 257;
i++) {
194 scaled_cumul_prob += rac->
prob[
i];
198 if (scale_factor >= 32U)
200 cumulative_target = 1U << scale_factor;
202 if (scaled_cumul_prob > cumulative_target) {
204 "Scaled probabilities are larger than target!\n");
208 scaled_cumul_prob = cumulative_target - scaled_cumul_prob;
210 for (
i = 1; scaled_cumul_prob;
i = (
i & 0x7f) + 1) {
229 if (scale_factor > 23)
232 rac->
scale = scale_factor;
235 for (
i = 1;
i < 257;
i++)
255 for (
i = 0;
i <
w;
i++) {
307 const int HEAD = is_luma ? 4 : 2;
311 TL = buf[HEAD -
stride - 1];
312 for (
i = 0;
i < HEAD;
i++) {
342 memset(dst +
i, 0, count);
357 if (l->
zeros == esc_count) {
372 int width,
int esc_count)
378 uint8_t mask1 = -(esc_count < 2);
379 uint8_t mask2 = -(esc_count < 3);
384 memset(dst, 0,
width);
389 if (end - dst < count) {
394 memset(dst, 0, count);
401 while (!zero_run && dst +
i < end) {
403 if (
i+2 >= src_end -
src)
406 !(
src[
i] | (
src[
i + 1] & mask1) | (
src[
i + 2] & mask2));
423 return src - src_start;
474 "Output more bytes than length (%d of %"PRIu32
")\n", read,
476 }
else if (esc_count < 8) {
484 src_end,
width, esc_count);
498 }
else if (esc_count == 0xff) {
508 "Invalid zero run escape code! (%#x)\n", esc_count);
540 unsigned int buf_size = avpkt->
size;
545 uint32_t offset_gu = 0, offset_bv = 0, offset_ry = 9;
583 for (j = 0; j <
planes; j++)
626 if (buf_size <= offs[
i]) {
628 "Invalid frame offsets\n");
652 if (offset_ry >= buf_size ||
653 offset_gu >= buf_size ||
654 offset_bv >= buf_size) {
656 "Invalid frame offsets\n");
662 buf_size - offset_ry);
665 buf + offset_gu, buf_size - offset_gu);
668 buf + offset_bv, buf_size - offset_bv);
676 if (offset_ry >= buf_size ||
677 offset_gu >= buf_size ||
678 offset_bv >= buf_size) {
680 "Invalid frame offsets\n");
686 buf_size - offset_ry);
689 buf + offset_gu, buf_size - offset_gu);
692 buf + offset_bv, buf_size - offset_bv);
696 "Unsupported Lagarith frame type: %#"PRIx8
"\n", frametype);
static double val(void *priv, double ch)
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
#define bit(string, value)
#define prob(name, subs,...)
#define FFSWAP(type, a, b)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static float mul(float src0, float src1)
bitstream reader API header.
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_I
Intra.
static void add_lag_median_prediction(uint8_t *dst, uint8_t *src1, uint8_t *diff, int w, int *left, int *left_top)
static int lag_decode_line(LagarithContext *l, lag_rac *rac, uint8_t *dst, int width, int stride, int esc_count)
AVCodec ff_lagarith_decoder
static int lag_decode_prob(GetBitContext *gb, uint32_t *value)
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)
static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb)
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...
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)
static av_cold int lag_decode_init(AVCodecContext *avctx)
static void lag_pred_line(LagarithContext *l, uint8_t *buf, int width, int stride, int line)
static int lag_decode_arith_plane(LagarithContext *l, uint8_t *dst, int width, int height, int stride, const uint8_t *src, int src_size)
static uint64_t softfloat_reciprocal(uint32_t denom)
Compute the 52-bit mantissa of 1/(double)denom.
static int lag_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Decode a frame.
@ FRAME_ARITH_RGB24
arithmetic coded RGB24
@ FRAME_SOLID_COLOR
solid non-grayscale color frame
@ FRAME_SOLID_GRAY
solid grayscale color frame
@ FRAME_OLD_ARITH_RGB
obsolete arithmetic coded RGB (no longer encoded by upstream since version 1.1.0)
@ FRAME_ARITH_YUY2
arithmetic coded YUY2
@ FRAME_SOLID_RGBA
solid RGBA color frame
@ FRAME_ARITH_YV12
arithmetic coded YV12
@ FRAME_REDUCED_RES
reduced resolution YV12 frame
@ FRAME_U_RGB24
unaligned RGB24
@ FRAME_ARITH_RGBA
arithmetic coded RGBA
void ff_lag_rac_init(lag_rac *l, GetBitContext *gb, int length)
static uint8_t lag_get_rac(lag_rac *l)
Decode a single byte from the compressed plane described by *l.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const struct @322 planes[]
void ff_llviddsp_init(LLVidDSPContext *c)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
static int shift(int a, int b)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
void(* add_bytes)(uint8_t *dst, uint8_t *src, ptrdiff_t w)
int(* add_left_pred)(uint8_t *dst, const uint8_t *src, ptrdiff_t w, int left)
void(* add_median_pred)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, ptrdiff_t w, int *left, int *left_top)
int zeros_rem
number of zero bytes remaining to output
int zeros
number of consecutive zero bytes encountered
unsigned scale
Number of bits of precision in range.
uint32_t prob[258]
Table of cumulative probability for each symbol.
#define avpriv_request_sample(...)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static const uint8_t offset[127][2]