33 #define TOP 0x01000000 42 rc->
code = bytestream2_get_be32(gb);
49 for (comp = 0; comp < 3; comp++) {
50 for (j = 0; j < 4096; j++) {
52 for (i = 0; i < 256; i++)
54 for (i = 0; i < 16; i++)
61 for (j = 0; j < 6; j++) {
63 for (i = 0; i < 256; i++)
68 for (j = 0; j < 6; j++) {
70 for (i = 0; i < 6; i++)
75 for (i = 0; i < 256; i++) {
82 for (i = 0; i < 5; i++) {
87 for (j = 0; j < 4; j++) {
88 for (i = 0; i < 16; i++) {
94 for (i = 0; i < 512; i++) {
108 uint32_t byte = bytestream2_get_byteu(gb);
138 t = rc->
range * (uint64_t)cumFreq / total_freq;
141 rc->
range = rc->
range * (uint64_t)(freq + cumFreq) / total_freq - (t + 1);
144 uint32_t byte = bytestream2_get_byteu(gb);
158 *freq = total_freq * (uint64_t)(rc->
code - rc->
code1) / rc->
range;
167 uint32_t totfr = cnt[maxc];
169 uint32_t
c = 0, cumfr = 0, cnt_c = 0;
172 if ((ret = s->
get_freq(rc, totfr, &value)) < 0)
177 if (value >= cumfr + cnt_c)
187 if ((ret = s->
decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
190 cnt[
c] = cnt_c + step;
194 for (i = 0; i < maxc; i++) {
195 uint32_t nc = (cnt[
i] >> 1) + 1;
212 uint32_t
value, x = 0, cumfr = 0, cnt_x = 0;
213 int i, j, ret,
c, cnt_c;
215 if ((ret = s->
get_freq(rc, totfr, &value)) < 0)
220 if (value >= cumfr + cnt_x)
230 cnt_c = pixel->
freq[
c];
231 if (value >= cumfr + cnt_c)
237 if (x >= 16 || c >= 256) {
241 if ((ret = s->
decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
244 pixel->
freq[
c] = cnt_c + step;
245 pixel->
lookup[x] = cnt_x + step;
249 for (i = 0; i < 256; i++) {
250 uint32_t nc = (pixel->
freq[
i] >> 1) + 1;
254 for (i = 0; i < 16; i++) {
256 uint32_t i16_17 = i << 4;
257 for (j = 0; j < 16; j++)
258 sum += pixel->
freq[i16_17 + j];
264 *rval = c & s->
cbits;
272 const int cxshift = s->
cxshift;
279 *cx1 = (*cx << 6) & 0xFC0;
285 *cx1 = (*cx << 6) & 0xFC0;
291 *cx1 = (*cx << 6) & 0xFC0;
301 int cx = 0, cx1 = 0, k = 0;
302 int run, off, y = 0, x = 0, ret;
303 uint32_t clr = 0,
r,
g,
b, backstep = linesize - avctx->
width;
304 uint32_t lx, ly, ptype;
310 while (k < avctx->
width + 1) {
321 clr = (b << 16) + (g << 8) +
r;
327 dst[y * linesize + x] = clr;
331 if (x >= avctx->
width) {
349 clr = (b << 16) + (g << 8) +
r;
360 dst, linesize, &lx, &ly,
361 backstep, off, &cx, &cx1);
370 uint32_t *dst,
int linesize,
371 uint32_t *prev,
int plinesize)
375 int ret,
temp = 0,
min,
max, x, y, cx = 0, cx1 = 0;
376 int backstep = linesize - avctx->
width;
378 if (bytestream2_get_byte(gb) == 0)
410 while (min < s->nbcount && count-- > 0) {
419 for (y = 0; y < s->
nby; y++) {
420 for (x = 0; x < s->
nbx; x++) {
421 int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16;
426 if (((s->
blocks[y * s->
nbx + x] - 1) & 1) > 0) {
437 if (((s->
blocks[y * s->
nbx + x] - 1) & 2) > 0) {
438 int i, j, by = y * 16, bx = x * 16;
449 if (by + mvy + sy1 < 0 || bx + mvx + sx1 < 0 ||
450 by + mvy + sy1 >= avctx->
height || bx + mvx + sx1 >= avctx->
width)
453 for (i = 0; i < sy2 - sy1 && (by + sy1 +
i) < avctx->
height && (by + mvy + sy1 + i) < avctx->
height; i++) {
454 for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < avctx->
width && (bx + mvx + sx1 + j) < avctx->
width; j++) {
455 dst[(by + i + sy1) * linesize + bx + sx1 + j] = prev[(by + mvy + sy1 + i) * plinesize + bx + sx1 + mvx + j];
459 int run, bx = x * 16 + sx1, by = y * 16 + sy1;
460 uint32_t
r,
g,
b, clr, ptype = 0;
462 for (; by < y * 16 + sy2 && by < avctx->
height;) {
471 clr = (b << 16) + (g << 8) +
r;
482 dst, prev, linesize, plinesize, &bx, &by,
483 backstep, sx1, sx2, &cx, &cx1);
512 type = bytestream2_peek_byte(gb);
521 }
else if (type == 18) {
528 }
else if (type == 34) {
533 }
else if (type == 17 || type == 33) {
543 uint16_t
value = bytestream2_get_le16(gb);
547 g = (value >> 5) & 31;
548 b = (value >> 10) & 31;
549 clr = (r << 16) + (g << 8) +
b;
551 clr = bytestream2_get_le24(gb);
553 for (y = 0; y < avctx->
height; y++) {
558 }
else if (type == 0 || type == 1) {
596 for (y = 0; y < avctx->
height; y++) {
598 if (!(((uintptr_t)dst) & 7)) {
599 uint64_t *dst64 = (uint64_t *)dst;
601 for (x = 0; x <
w; x++) {
602 dst64[x] = (dst64[x] << 3) & 0xFCFCFCFCFCFCFCFCULL;
607 for (; x < avctx->
width * 4; x++) {
608 dst[x] = dst[x] << 3;
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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 int decode_value(SCPRContext *s, uint32_t *cnt, uint32_t maxc, uint32_t step, uint32_t *rval)
static av_cold int decode_init(AVCodecContext *avctx)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
PixelModel pixel_model[3][4096]
static av_cold int init(AVCodecContext *avctx)
static int decode_unit(SCPRContext *s, PixelModel *pixel, uint32_t step, uint32_t *rval)
static void reinit_tables(SCPRContext *s)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int(* get_freq)(RangeCoder *rc, uint32_t total_freq, uint32_t *freq)
static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize)
static int decompress_p(AVCodecContext *avctx, uint32_t *dst, int linesize, uint32_t *prev, int plinesize)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
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_p3(AVCodecContext *avctx, uint32_t *dst, int linesize, uint32_t *prev, int plinesize)
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
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_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
uint32_t sxy_model[4][17]
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int decode_close(AVCodecContext *avctx)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
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...
const char * name
Name of the codec implementation.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
enum AVPictureType pict_type
Picture type of the frame.
uint32_t run_model[6][257]
int width
picture width / height.
uint32_t count_model[257]
static int decode(GetByteContext *gb, RangeCoder *rc, uint32_t cumFreq, uint32_t freq, uint32_t total_freq)
static void init_rangecoder(RangeCoder *rc, GetByteContext *gb)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
uint32_t mv_model[2][513]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Libavcodec external API header.
static int decode0(GetByteContext *gb, RangeCoder *rc, uint32_t cumFreq, uint32_t freq, uint32_t total_freq)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
uint32_t range_model[257]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int get_freq(RangeCoder *rc, uint32_t total_freq, uint32_t *freq)
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.
common internal api header.
static int get_freq0(RangeCoder *rc, uint32_t total_freq, uint32_t *freq)
int(* decode)(GetByteContext *gb, RangeCoder *rc, uint32_t cumFreq, uint32_t freq, uint32_t total_freq)
int key_frame
1 -> keyframe, 0-> not
static int decompress_i3(AVCodecContext *avctx, uint32_t *dst, int linesize)
#define av_malloc_array(a, b)
#define FFSWAP(type, a, b)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.