54 thr = ((thr >> 1) + 4 * m->
cum_prob[0]) / thr;
56 return FFMIN(thr, 0x3FFF);
115 for (
i =
val - 1;
i >= 0;
i--)
124 if (!
ctx->special_initial_cache)
125 for (
i = 0;
i <
ctx->cache_size;
i++)
136 for (
i = 0;
i < 15;
i++)
137 for (j = 0; j < 4; j++)
142 int full_model_syms,
int special_initial_cache)
146 ctx->cache_size = cache_size + 4;
147 ctx->num_syms = cache_size;
148 ctx->special_initial_cache = special_initial_cache;
153 for (
i = 0, idx = 0;
i < 4;
i++)
155 for (k = 0; k < 4; k++)
161 uint8_t *ngb,
int num_ngb,
int any_ngb)
174 for (j = 0; j < num_ngb; j++)
175 if (pctx->
cache[
i] == ngb[j])
203 uint8_t *
src, ptrdiff_t
stride,
int x,
int y,
206 uint8_t neighbours[4];
214 memset(neighbours,
src[-1], 4);
230 if (x >= 2 &&
src[-2] == neighbours[
LEFT])
236 ref_pix[0] = neighbours[0];
237 for (
i = 1;
i < 4;
i++) {
238 for (j = 0; j < nlen; j++)
239 if (ref_pix[j] == neighbours[
i])
242 ref_pix[nlen++] = neighbours[
i];
277 else if (neighbours[
TOP] == neighbours[
LEFT])
302 rgb_stride = rgb_dst ? rgb_stride : 0;
303 rgb_dst = rgb_dst ? rgb_dst + x * 3 + y * rgb_stride :
NULL;
306 for (j = 0; j <
height; j++) {
333 for (j = y; j < y +
height; j++) {
334 memcpy(
c->rgb_pic + j *
c->rgb_stride + x * 3,
335 c->last_rgb_pic + j *
c->rgb_stride + x * 3,
337 memcpy(
c->pal_pic + j *
c->pal_stride + x,
338 c->last_pal_pic + j *
c->pal_stride + x,
346 if (x +
c->mvX < 0 || x +
c->mvX +
width >
c->avctx->width ||
347 y +
c->mvY < 0 || y +
c->mvY +
height >
c->avctx->height ||
351 uint8_t *
dst =
c->pal_pic + x + y *
c->pal_stride;
352 uint8_t *rgb_dst =
c->rgb_pic + x * 3 + y *
c->rgb_stride;
358 if (
c->last_rgb_pic) {
359 src =
c->last_pal_pic + x + y *
c->pal_stride;
360 rgb_src =
c->last_rgb_pic + x * 3 + y *
c->rgb_stride;
362 src =
c->pal_pic + x + y *
c->pal_stride;
363 rgb_src =
c->rgb_pic + x * 3 + y *
c->rgb_stride;
365 for (j = 0; j <
height; j++) {
367 memmove(rgb_dst, rgb_src,
width * 3);
368 dst +=
c->pal_stride;
369 src +=
c->pal_stride;
370 rgb_dst +=
c->rgb_stride;
371 rgb_src +=
c->rgb_stride;
379 ptrdiff_t mask_stride,
int x,
int y,
384 uint8_t *rgb_dst =
c->rgb_pic + x * 3 + y *
c->rgb_stride;
387 mask += x + y * mask_stride;
389 for (j = 0; j <
height; j++) {
393 !
c->rgb_pic &&
mask[
i] != 0x80 &&
mask[
i] != 0xFF))
396 if (
mask[
i] == 0x02) {
398 }
else if (
mask[
i] == 0x04) {
401 }
else if (
mask[
i] != 0x80) {
416 rgb_dst +=
c->rgb_stride;
423 int version,
int full_model_syms)
434 full_model_syms,
version ? 1 : 0);
456 if ((
base + 1) / 2 - 2 <= 0)
477 int i, j,
pix, rgb_pix;
478 ptrdiff_t
stride =
c->pal_stride;
479 ptrdiff_t rgb_stride =
c->rgb_stride;
481 uint8_t *rgb_dst =
c->rgb_pic ?
c->rgb_pic + x * 3 + y * rgb_stride :
NULL;
486 rgb_pix =
c->pal[
pix];
490 for (j = 0; j <
width * 3; j += 3)
492 rgb_dst += rgb_stride;
518 (
c->rgb_pic &&
mode != 0x01 &&
mode != 0x02 &&
mode != 0x04 ||
519 !
c->rgb_pic &&
mode != 0x80 &&
mode != 0xFF))
524 else if (
mode == 0x04)
526 else if (
mode != 0x80)
534 c->pal_stride,
c->mask,
595 "Insufficient extradata size: expected %"PRIu32
" got %d\n",
618 "Header version doesn't match codec tag\n");
623 if ((
unsigned)
c->free_colours > 256) {
625 "Incorrect number of changeable palette entries: %d\n",
649 "Insufficient extradata size %d for v2\n",
658 if (
c->full_model_syms < 2 ||
c->full_model_syms > 256) {
660 "Incorrect number of used colours %d\n",
668 c->full_model_syms = 256;
671 for (
i = 0;
i < 256;
i++)
684 if (
c->slice_split) {
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
#define FF_PTR_ADD(ptr, off)
static const uint16_t mask[17]
Memory handling functions.
static void model_reset(Model *m)
static int model_calc_threshold(Model *m)
static av_cold void model_init(Model *m, int num_syms, int thr_weight)
static int decode_region_intra(SliceContext *sc, ArithCoder *acoder, int x, int y, int width, int height)
static int decode_pivot(SliceContext *sc, ArithCoder *acoder, int base)
int ff_mss12_decode_rect(SliceContext *sc, ArithCoder *acoder, int x, int y, int width, int height)
static void pixctx_reset(PixContext *ctx)
av_cold int ff_mss12_decode_end(MSS12Context *c)
static int decode_region(ArithCoder *acoder, uint8_t *dst, uint8_t *rgb_dst, int x, int y, int width, int height, ptrdiff_t stride, ptrdiff_t rgb_stride, PixContext *pctx, const uint32_t *pal)
static av_cold void slicecontext_init(SliceContext *sc, int version, int full_model_syms)
av_cold int ff_mss12_decode_init(MSS12Context *c, int version, SliceContext *sc1, SliceContext *sc2)
static int decode_region_masked(MSS12Context const *c, ArithCoder *acoder, uint8_t *dst, ptrdiff_t stride, uint8_t *mask, ptrdiff_t mask_stride, int x, int y, int width, int height, PixContext *pctx)
static void model_rescale_weights(Model *m)
static av_always_inline int decode_pixel(ArithCoder *acoder, PixContext *pctx, uint8_t *ngb, int num_ngb, int any_ngb)
static int decode_pixel_in_context(ArithCoder *acoder, PixContext *pctx, uint8_t *src, ptrdiff_t stride, int x, int y, int has_right)
static const int sec_order_sizes[4]
static av_cold void pixctx_init(PixContext *ctx, int cache_size, int full_model_syms, int special_initial_cache)
void ff_mss12_model_update(Model *m, int val)
static void copy_rectangles(MSS12Context const *c, int x, int y, int width, int height)
static int decode_region_inter(SliceContext *sc, ArithCoder *acoder, int x, int y, int width, int height)
void ff_mss12_slicecontext_reset(SliceContext *sc)
static int motion_compensation(MSS12Context const *c, int x, int y, int width, int height)
Common header for Microsoft Screen 1 and 2.
main external API structure.
int width
picture width / height.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int coded_width
Bitstream width / height, may be different from width/height e.g.
int(* get_number)(struct ArithCoder *c, int n)
int(* get_model_sym)(struct ArithCoder *c, Model *m)
int16_t cum_prob[MODEL_MAX_SYMS+1]
uint8_t idx2sym[MODEL_MAX_SYMS+1]
int16_t weights[MODEL_MAX_SYMS+1]
const struct MSS12Context * c
#define av_malloc_array(a, b)
static AVFormatContext * ctx