2012-08-26 14:16:07 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 Konstantin Shishkov
|
|
|
|
*
|
|
|
|
* This file is part of Libav.
|
|
|
|
*
|
|
|
|
* Libav is free software; you can redistribute it and/or
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Libav is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* License along with Libav; if not, write to the Free Software
|
|
|
|
* 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
|
|
|
|
|
2012-08-24 17:45:57 +02:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2012-08-26 14:16:07 +02:00
|
|
|
#include "avcodec.h"
|
|
|
|
#include "get_bits.h"
|
2012-08-24 17:45:57 +02:00
|
|
|
#include "bytestream.h"
|
2012-08-26 14:16:07 +02:00
|
|
|
|
|
|
|
#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 {
|
2012-09-02 12:44:21 +02:00
|
|
|
int16_t cum_prob[MODEL_MAX_SYMS + 1];
|
|
|
|
int16_t weights[MODEL_MAX_SYMS + 1];
|
|
|
|
uint8_t idx2sym[MODEL_MAX_SYMS + 1];
|
2012-08-26 14:16:07 +02:00
|
|
|
int num_syms;
|
|
|
|
int thr_weight, threshold;
|
|
|
|
} Model;
|
|
|
|
|
|
|
|
typedef struct ArithCoder {
|
|
|
|
int low, high, value;
|
2012-08-24 17:45:57 +02:00
|
|
|
union {
|
|
|
|
GetBitContext *gb;
|
|
|
|
GetByteContext *gB;
|
|
|
|
} gbc;
|
2012-08-26 14:16:07 +02:00
|
|
|
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;
|
2012-09-02 12:44:21 +02:00
|
|
|
Model sec_models[15][4];
|
2012-08-24 17:45:57 +02:00
|
|
|
int special_initial_cache;
|
2012-08-26 14:16:07 +02:00
|
|
|
} PixContext;
|
|
|
|
|
2012-08-24 17:45:57 +02:00
|
|
|
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;
|
|
|
|
|
2012-08-26 14:16:07 +02:00
|
|
|
typedef struct MSS12Context {
|
|
|
|
AVCodecContext *avctx;
|
|
|
|
uint32_t pal[256];
|
2012-08-24 17:45:57 +02:00
|
|
|
uint8_t *pal_pic;
|
|
|
|
uint8_t *last_pal_pic;
|
|
|
|
int pal_stride;
|
|
|
|
uint8_t *mask;
|
|
|
|
int mask_stride;
|
|
|
|
uint8_t *rgb_pic;
|
|
|
|
uint8_t *last_rgb_pic;
|
|
|
|
int rgb_stride;
|
2012-08-26 14:16:07 +02:00
|
|
|
int free_colours;
|
|
|
|
int keyframe;
|
2012-08-24 17:45:57 +02:00
|
|
|
int mvX, mvY;
|
2012-08-26 14:16:07 +02:00
|
|
|
int corrupted;
|
2012-08-24 17:45:57 +02:00
|
|
|
int slice_split;
|
|
|
|
int full_model_syms;
|
2012-08-26 14:16:07 +02:00
|
|
|
} MSS12Context;
|
|
|
|
|
2012-08-24 17:45:57 +02:00
|
|
|
int ff_mss12_decode_rect(SliceContext *ctx, ArithCoder *acoder,
|
2012-08-26 14:16:07 +02:00
|
|
|
int x, int y, int width, int height);
|
|
|
|
void ff_mss12_model_update(Model *m, int val);
|
2012-09-02 12:42:01 +02:00
|
|
|
void ff_mss12_slicecontext_reset(SliceContext *sc);
|
|
|
|
av_cold int ff_mss12_decode_init(MSS12Context *c, int version,
|
|
|
|
SliceContext* sc1, SliceContext *sc2);
|
2012-08-24 17:45:57 +02:00
|
|
|
av_cold int ff_mss12_decode_end(MSS12Context *ctx);
|
|
|
|
|
|
|
|
#define ARITH_GET_BIT(VERSION) \
|
|
|
|
static int arith ## VERSION ## _get_bit(ArithCoder *c) \
|
|
|
|
{ \
|
|
|
|
int range = c->high - c->low + 1; \
|
2012-09-03 17:32:01 +02:00
|
|
|
int bit = 2 * c->value - c->low >= c->high; \
|
2012-08-24 17:45:57 +02:00
|
|
|
\
|
|
|
|
if (bit) \
|
|
|
|
c->low += range >> 1; \
|
|
|
|
else \
|
|
|
|
c->high = c->low + (range >> 1) - 1; \
|
|
|
|
\
|
|
|
|
arith ## VERSION ## _normalise(c); \
|
|
|
|
\
|
|
|
|
return bit; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ARITH_GET_MODEL_SYM(VERSION) \
|
|
|
|
static int arith ## VERSION ## _get_model_sym(ArithCoder *c, Model *m) \
|
|
|
|
{ \
|
|
|
|
int idx, val; \
|
|
|
|
\
|
|
|
|
idx = arith ## VERSION ## _get_prob(c, m->cum_prob); \
|
|
|
|
\
|
|
|
|
val = m->idx2sym[idx]; \
|
|
|
|
ff_mss12_model_update(m, idx); \
|
|
|
|
\
|
|
|
|
arith ## VERSION ## _normalise(c); \
|
|
|
|
\
|
|
|
|
return val; \
|
|
|
|
}
|
2012-08-26 14:16:07 +02:00
|
|
|
|
|
|
|
#endif /* AVCODEC_MSS12_H */
|