00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #ifndef AVCODEC_MSS12_H
00027 #define AVCODEC_MSS12_H
00028
00029 #include "libavutil/intreadwrite.h"
00030 #include "avcodec.h"
00031 #include "get_bits.h"
00032 #include "bytestream.h"
00033
00034 #define MODEL_MIN_SYMS 2
00035 #define MODEL_MAX_SYMS 256
00036 #define THRESH_ADAPTIVE -1
00037 #define THRESH_LOW 15
00038 #define THRESH_HIGH 50
00039
00040 typedef struct Model {
00041 int16_t cum_prob[MODEL_MAX_SYMS + 1];
00042 int16_t weights[MODEL_MAX_SYMS + 1];
00043 uint8_t idx2sym[MODEL_MAX_SYMS + 1];
00044 int num_syms;
00045 int thr_weight, threshold;
00046 } Model;
00047
00048 typedef struct ArithCoder {
00049 int low, high, value;
00050 union {
00051 GetBitContext *gb;
00052 GetByteContext *gB;
00053 } gbc;
00054 int (*get_model_sym)(struct ArithCoder *c, Model *m);
00055 int (*get_number) (struct ArithCoder *c, int n);
00056 } ArithCoder;
00057
00058 typedef struct PixContext {
00059 int cache_size, num_syms;
00060 uint8_t cache[12];
00061 Model cache_model, full_model;
00062 Model sec_models[15][4];
00063 int special_initial_cache;
00064 } PixContext;
00065
00066 struct MSS12Context;
00067
00068 typedef struct SliceContext {
00069 struct MSS12Context *c;
00070 Model intra_region, inter_region;
00071 Model pivot, edge_mode, split_mode;
00072 PixContext intra_pix_ctx, inter_pix_ctx;
00073 } SliceContext;
00074
00075 typedef struct MSS12Context {
00076 AVCodecContext *avctx;
00077 uint32_t pal[256];
00078 uint8_t *pal_pic;
00079 uint8_t *last_pal_pic;
00080 int pal_stride;
00081 uint8_t *mask;
00082 int mask_stride;
00083 uint8_t *rgb_pic;
00084 uint8_t *last_rgb_pic;
00085 int rgb_stride;
00086 int free_colours;
00087 int keyframe;
00088 int mvX, mvY;
00089 int corrupted;
00090 int slice_split;
00091 int full_model_syms;
00092 } MSS12Context;
00093
00094 int ff_mss12_decode_rect(SliceContext *ctx, ArithCoder *acoder,
00095 int x, int y, int width, int height);
00096 void ff_mss12_model_update(Model *m, int val);
00097 void ff_mss12_slicecontext_reset(SliceContext *sc);
00098 av_cold int ff_mss12_decode_init(MSS12Context *c, int version,
00099 SliceContext* sc1, SliceContext *sc2);
00100 av_cold int ff_mss12_decode_end(MSS12Context *ctx);
00101
00102 #define ARITH_GET_BIT(VERSION) \
00103 static int arith ## VERSION ## _get_bit(ArithCoder *c) \
00104 { \
00105 int range = c->high - c->low + 1; \
00106 int bit = 2 * c->value - c->low >= c->high; \
00107 \
00108 if (bit) \
00109 c->low += range >> 1; \
00110 else \
00111 c->high = c->low + (range >> 1) - 1; \
00112 \
00113 arith ## VERSION ## _normalise(c); \
00114 \
00115 return bit; \
00116 }
00117
00118 #define ARITH_GET_MODEL_SYM(VERSION) \
00119 static int arith ## VERSION ## _get_model_sym(ArithCoder *c, Model *m) \
00120 { \
00121 int idx, val; \
00122 \
00123 idx = arith ## VERSION ## _get_prob(c, m->cum_prob); \
00124 \
00125 val = m->idx2sym[idx]; \
00126 ff_mss12_model_update(m, idx); \
00127 \
00128 arith ## VERSION ## _normalise(c); \
00129 \
00130 return val; \
00131 }
00132
00133 #endif