2 * Copyright (c) 2012 Konstantin Shishkov
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Common header for Microsoft Screen 1 and 2
26 #ifndef AVCODEC_MSS12_H
27 #define AVCODEC_MSS12_H
29 #include "libavutil/intreadwrite.h"
32 #include "bytestream.h"
34 #define MODEL_MIN_SYMS 2
35 #define MODEL_MAX_SYMS 256
36 #define THRESH_ADAPTIVE -1
38 #define THRESH_HIGH 50
40 typedef struct Model {
41 int16_t cum_prob[MODEL_MAX_SYMS + 1];
42 int16_t weights[MODEL_MAX_SYMS + 1];
43 uint8_t idx2sym[MODEL_MAX_SYMS + 1];
45 int thr_weight, threshold;
48 typedef struct ArithCoder {
51 #define MAX_OVERREAD 16
56 int (*get_model_sym)(struct ArithCoder *c, Model *m);
57 int (*get_number) (struct ArithCoder *c, int n);
60 typedef struct PixContext {
61 int cache_size, num_syms;
63 Model cache_model, full_model;
64 Model sec_models[15][4];
65 int special_initial_cache;
70 typedef struct SliceContext {
71 struct MSS12Context *c;
72 Model intra_region, inter_region;
73 Model pivot, edge_mode, split_mode;
74 PixContext intra_pix_ctx, inter_pix_ctx;
77 typedef struct MSS12Context {
78 AVCodecContext *avctx;
81 uint8_t *last_pal_pic;
84 ptrdiff_t mask_stride;
86 uint8_t *last_rgb_pic;
96 int ff_mss12_decode_rect(SliceContext *ctx, ArithCoder *acoder,
97 int x, int y, int width, int height);
98 void ff_mss12_model_update(Model *m, int val);
99 void ff_mss12_slicecontext_reset(SliceContext *sc);
100 int ff_mss12_decode_init(MSS12Context *c, int version,
101 SliceContext *sc1, SliceContext *sc2);
102 int ff_mss12_decode_end(MSS12Context *ctx);
104 #define ARITH_GET_BIT(prefix) \
105 static int prefix ## _get_bit(ArithCoder *c) \
107 int range = c->high - c->low + 1; \
108 int bit = 2 * c->value - c->low >= c->high; \
111 c->low += range >> 1; \
113 c->high = c->low + (range >> 1) - 1; \
115 prefix ## _normalise(c); \
120 #define ARITH_GET_MODEL_SYM(prefix) \
121 static int prefix ## _get_model_sym(ArithCoder *c, Model *m) \
125 idx = prefix ## _get_prob(c, m->cum_prob); \
127 val = m->idx2sym[idx]; \
128 ff_mss12_model_update(m, idx); \
130 prefix ## _normalise(c); \
135 #endif /* AVCODEC_MSS12_H */