Go to the documentation of this file.
32 #define TOP 0x01000000
41 rc->
code = bytestream2_get_be32(gb);
49 for (j = 0; j < 4096; j++) {
50 if (
s->pixel_model[
comp][j].total_freq != 256) {
51 for (
i = 0;
i < 256;
i++)
52 s->pixel_model[
comp][j].freq[
i] = 1;
54 s->pixel_model[
comp][j].lookup[
i] = 16;
55 s->pixel_model[
comp][j].total_freq = 256;
60 for (j = 0; j < 6; j++) {
61 uint32_t *p =
s->run_model[j];
62 for (
i = 0;
i < 256;
i++)
67 for (j = 0; j < 6; j++) {
68 uint32_t *
op =
s->op_model[j];
69 for (
i = 0;
i < 6;
i++)
74 for (
i = 0;
i < 256;
i++) {
75 s->range_model[
i] = 1;
76 s->count_model[
i] = 1;
78 s->range_model[256] = 256;
79 s->count_model[256] = 256;
81 for (
i = 0;
i < 5;
i++) {
86 for (j = 0; j < 4; j++) {
87 for (
i = 0;
i < 16;
i++) {
88 s->sxy_model[j][
i] = 1;
90 s->sxy_model[j][16] = 16;
93 for (
i = 0;
i < 512;
i++) {
94 s->mv_model[0][
i] = 1;
95 s->mv_model[1][
i] = 1;
97 s->mv_model[0][512] = 512;
98 s->mv_model[1][512] = 512;
107 uint32_t
byte = bytestream2_get_byteu(gb);
137 t = rc->
range * (uint64_t)cumFreq / total_freq;
140 rc->
range = rc->
range * (uint64_t)(freq + cumFreq) / total_freq - (t + 1);
143 uint32_t
byte = bytestream2_get_byteu(gb);
157 *freq = total_freq * (uint64_t)(rc->
code - rc->
code1) / rc->
range;
166 uint32_t totfr = cnt[maxc];
168 uint32_t
c = 0, cumfr = 0, cnt_c = 0;
171 if ((
ret =
s->get_freq(rc, totfr, &
value)) < 0)
176 if (
value >= cumfr + cnt_c)
186 if ((
ret =
s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
189 cnt[
c] = cnt_c +
step;
193 for (
i = 0;
i < maxc;
i++) {
194 uint32_t nc = (cnt[
i] >> 1) + 1;
210 uint32_t totfr =
pixel->total_freq;
211 uint32_t
value, x = 0, cumfr = 0, cnt_x = 0;
212 int i, j,
ret,
c, cnt_c;
214 if ((
ret =
s->get_freq(rc, totfr, &
value)) < 0)
218 cnt_x =
pixel->lookup[x];
219 if (
value >= cumfr + cnt_x)
230 if (
value >= cumfr + cnt_c)
236 if (x >= 16 ||
c >= 256) {
240 if ((
ret =
s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
248 for (
i = 0;
i < 256;
i++) {
249 uint32_t nc = (
pixel->freq[
i] >> 1) + 1;
253 for (
i = 0;
i < 16;
i++) {
255 uint32_t i16_17 =
i << 4;
256 for (j = 0; j < 16; j++)
257 sum +=
pixel->freq[i16_17 + j];
261 pixel->total_freq = totfr;
263 *rval =
c &
s->cbits;
271 const int cxshift =
s->cxshift;
278 *cx1 = (*cx << 6) & 0xFC0;
284 *cx1 = (*cx << 6) & 0xFC0;
290 *cx1 = (*cx << 6) & 0xFC0;
300 int cx = 0, cx1 = 0, k = 0;
301 int run, off, y = 0, x = 0,
ret;
302 uint32_t clr = 0,
r,
g,
b, backstep = linesize - avctx->
width;
303 uint32_t lx, ly, ptype;
309 while (k < avctx->
width + 1) {
320 clr = (
b << 16) + (
g << 8) +
r;
326 dst[y * linesize + x] = clr;
330 if (x >= avctx->
width) {
348 clr = (
b << 16) + (
g << 8) +
r;
359 dst, linesize, &lx, &ly,
360 backstep, off, &cx, &cx1);
369 uint32_t *dst,
int linesize,
370 uint32_t *prev,
int plinesize)
375 int backstep = linesize - avctx->
width;
377 if (bytestream2_get_byte(gb) == 0)
397 memset(
s->blocks, 0,
sizeof(*
s->blocks) *
s->nbcount);
409 while (min < s->nbcount && count-- > 0) {
410 s->blocks[
min++] = fill;
418 for (y = 0; y <
s->nby; y++) {
419 for (x = 0; x <
s->nbx; x++) {
420 int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16;
422 if (
s->blocks[y *
s->nbx + x] == 0)
425 if (((
s->blocks[y *
s->nbx + x] - 1) & 1) > 0) {
436 if (((
s->blocks[y *
s->nbx + x] - 1) & 2) > 0) {
437 int i, j, by = y * 16, bx = x * 16;
448 if (by + mvy + sy1 < 0 || bx + mvx + sx1 < 0 ||
449 by + mvy + sy1 >= avctx->
height || bx + mvx + sx1 >= avctx->
width)
452 for (
i = 0;
i < sy2 - sy1 && (by + sy1 +
i) < avctx->
height && (by + mvy + sy1 +
i) < avctx->
height;
i++) {
453 for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < avctx->
width && (bx + mvx + sx1 + j) < avctx->
width; j++) {
454 dst[(by +
i + sy1) * linesize + bx + sx1 + j] = prev[(by + mvy + sy1 +
i) * plinesize + bx + sx1 + mvx + j];
458 int run, bx = x * 16 + sx1, by = y * 16 + sy1;
459 uint32_t
r,
g,
b, clr, ptype = 0;
461 if (bx >= avctx->
width)
464 for (; by < y * 16 + sy2 && by < avctx->
height;) {
473 clr = (
b << 16) + (
g << 8) +
r;
484 dst, prev, linesize, plinesize, &bx, &by,
485 backstep, sx1, sx2, &cx, &cx1);
513 type = bytestream2_peek_byte(gb);
521 s->current_frame->linesize[0] / 4);
522 }
else if (
type == 18) {
528 s->current_frame->linesize[0] / 4);
529 }
else if (
type == 34) {
533 s->current_frame->linesize[0] / 4);
534 }
else if (
type == 17 ||
type == 33) {
535 uint32_t clr, *dst = (uint32_t *)
s->current_frame->data[0];
544 uint16_t
value = bytestream2_get_le16(gb);
550 clr = (
r << 16) + (
g << 8) +
b;
552 clr = bytestream2_get_le24(gb);
554 for (y = 0; y < avctx->
height; y++) {
557 dst +=
s->current_frame->linesize[0] / 4;
559 }
else if (
type == 0 ||
type == 1) {
562 if (
s->version == 1 ||
s->version == 2)
564 s->current_frame->linesize[0] / 4,
565 (uint32_t *)
s->last_frame->data[0],
566 s->last_frame->linesize[0] / 4);
569 s->current_frame->linesize[0] / 4,
570 (uint32_t *)
s->last_frame->data[0],
571 s->last_frame->linesize[0] / 4);
597 for (y = 0; y < avctx->
height; y++) {
599 if (!(((uintptr_t)dst) & 7)) {
600 uint64_t *dst64 = (uint64_t *)dst;
602 for (x = 0; x <
w; x++) {
603 dst64[x] = (dst64[x] << 3) & 0xFCFCFCFCFCFCFCFCULL;
608 for (; x < avctx->
width * 4; x++) {
609 dst[x] = dst[x] << 3;
645 s->nbx = (avctx->
width + 15) / 16;
646 s->nby = (avctx->
height + 15) / 16;
647 s->nbcount =
s->nbx *
s->nby;
654 if (!
s->last_frame || !
s->current_frame)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
static av_cold int decode_close(AVCodecContext *avctx)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int get_freq0(RangeCoder *rc, uint32_t total_freq, uint32_t *freq)
This structure describes decoded (raw) audio or video data.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
AVCodec p
The public AVCodec.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int decompress_p(AVCodecContext *avctx, uint32_t *dst, int linesize, uint32_t *prev, int plinesize)
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
#define FF_CODEC_DECODE_CB(func)
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run, int *px, int *py, uint32_t clr, uint32_t *dst, int linesize, uint32_t *plx, uint32_t *ply, uint32_t backstep, int off, int *cx, int *cx1)
static av_cold int decode_init(AVCodecContext *avctx)
#define CODEC_LONG_NAME(str)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
@ AV_PICTURE_TYPE_I
Intra.
static int get_freq(RangeCoder *rc, uint32_t total_freq, uint32_t *freq)
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
static void reinit_tables(SCPRContext *s)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize)
enum AVPictureType pict_type
Picture type of the frame.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
const FFCodec ff_scpr_decoder
static int decode_run_p(AVCodecContext *avctx, uint32_t ptype, int run, int x, int y, uint32_t clr, uint32_t *dst, uint32_t *prev, int linesize, int plinesize, uint32_t *bx, uint32_t *by, uint32_t backstep, int sx1, int sx2, int *cx, int *cx1)
static int decode_value(SCPRContext *s, uint32_t *cnt, uint32_t maxc, uint32_t step, uint32_t *rval)
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
static int decode_units(SCPRContext *s, uint32_t *r, uint32_t *g, uint32_t *b, int *cx, int *cx1)
static int decompress_i3(AVCodecContext *avctx, uint32_t *dst, int linesize)
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
#define i(width, name, range_min, range_max)
static int decode_unit(SCPRContext *s, PixelModel *pixel, uint32_t step, uint32_t *rval)
#define av_malloc_array(a, b)
static int decompress_p3(AVCodecContext *avctx, uint32_t *dst, int linesize, uint32_t *prev, int plinesize)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
#define FFSWAP(type, a, b)
static int decode0(GetByteContext *gb, RangeCoder *rc, uint32_t cumFreq, uint32_t freq, uint32_t total_freq)
static int decode(GetByteContext *gb, RangeCoder *rc, uint32_t cumFreq, uint32_t freq, uint32_t total_freq)
main external API structure.
@ AV_PICTURE_TYPE_P
Predicted.
This structure stores compressed data.
int width
picture width / height.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void init_rangecoder(RangeCoder *rc, GetByteContext *gb)
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)