0de4a563 |
/*
* Copyright (c) 2012 Konstantin Shishkov
* |
416d2f7a |
* This file is part of FFmpeg. |
0de4a563 |
* |
416d2f7a |
* FFmpeg is free software; you can redistribute it and/or |
0de4a563 |
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* |
416d2f7a |
* FFmpeg is distributed in the hope that it will be useful, |
0de4a563 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public |
416d2f7a |
* License along with FFmpeg; if not, write to the Free Software |
0de4a563 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Common header for Microsoft Screen 1 and 2
*/
#ifndef AVCODEC_MSS12_H
#define AVCODEC_MSS12_H
|
ee769c6a |
#include "libavutil/intreadwrite.h" |
0de4a563 |
#include "avcodec.h"
#include "get_bits.h" |
ee769c6a |
#include "bytestream.h" |
0de4a563 |
#define MODEL_MIN_SYMS 2
#define MODEL_MAX_SYMS 256
#define THRESH_ADAPTIVE -1
#define THRESH_LOW 15
#define THRESH_HIGH 50
typedef struct Model { |
626c1a33 |
int16_t cum_prob[MODEL_MAX_SYMS + 1];
int16_t weights[MODEL_MAX_SYMS + 1];
uint8_t idx2sym[MODEL_MAX_SYMS + 1]; |
0de4a563 |
int num_syms;
int thr_weight, threshold;
} Model;
typedef struct ArithCoder {
int low, high, value; |
ee769c6a |
union {
GetBitContext *gb;
GetByteContext *gB;
} gbc; |
0de4a563 |
int (*get_model_sym)(struct ArithCoder *c, Model *m);
int (*get_number) (struct ArithCoder *c, int n);
} ArithCoder;
typedef struct PixContext {
int cache_size, num_syms;
uint8_t cache[12];
Model cache_model, full_model; |
626c1a33 |
Model sec_models[15][4]; |
ee769c6a |
int special_initial_cache; |
0de4a563 |
} PixContext;
|
ee769c6a |
struct MSS12Context;
typedef struct SliceContext {
struct MSS12Context *c;
Model intra_region, inter_region;
Model pivot, edge_mode, split_mode;
PixContext intra_pix_ctx, inter_pix_ctx;
} SliceContext;
|
0de4a563 |
typedef struct MSS12Context {
AVCodecContext *avctx;
uint32_t pal[256]; |
ee769c6a |
uint8_t *pal_pic;
uint8_t *last_pal_pic; |
15b4f494 |
ptrdiff_t pal_stride; |
ee769c6a |
uint8_t *mask; |
15b4f494 |
ptrdiff_t mask_stride; |
ee769c6a |
uint8_t *rgb_pic;
uint8_t *last_rgb_pic; |
15b4f494 |
ptrdiff_t rgb_stride; |
0de4a563 |
int free_colours;
int keyframe; |
ee769c6a |
int mvX, mvY; |
0de4a563 |
int corrupted; |
ee769c6a |
int slice_split;
int full_model_syms; |
0de4a563 |
} MSS12Context;
|
ee769c6a |
int ff_mss12_decode_rect(SliceContext *ctx, ArithCoder *acoder, |
0de4a563 |
int x, int y, int width, int height);
void ff_mss12_model_update(Model *m, int val); |
a97ee41b |
void ff_mss12_slicecontext_reset(SliceContext *sc); |
94ee7da0 |
int ff_mss12_decode_init(MSS12Context *c, int version,
SliceContext *sc1, SliceContext *sc2);
int ff_mss12_decode_end(MSS12Context *ctx); |
ee769c6a |
|
cbeaf678 |
#define ARITH_GET_BIT(prefix) \
static int prefix ## _get_bit(ArithCoder *c) \ |
ee769c6a |
{ \
int range = c->high - c->low + 1; \ |
9699b3a2 |
int bit = 2 * c->value - c->low >= c->high; \ |
ee769c6a |
\
if (bit) \
c->low += range >> 1; \
else \
c->high = c->low + (range >> 1) - 1; \
\ |
cbeaf678 |
prefix ## _normalise(c); \ |
ee769c6a |
\
return bit; \
}
|
cbeaf678 |
#define ARITH_GET_MODEL_SYM(prefix) \
static int prefix ## _get_model_sym(ArithCoder *c, Model *m) \ |
ee769c6a |
{ \
int idx, val; \
\ |
cbeaf678 |
idx = prefix ## _get_prob(c, m->cum_prob); \ |
ee769c6a |
\
val = m->idx2sym[idx]; \
ff_mss12_model_update(m, idx); \
\ |
cbeaf678 |
prefix ## _normalise(c); \ |
ee769c6a |
\
return val; \
} |
0de4a563 |
#endif /* AVCODEC_MSS12_H */ |