Coverage Report

Created: 2026-05-16 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/mss12.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2012 Konstantin Shishkov
3
 *
4
 * This file is part of FFmpeg.
5
 *
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.
10
 *
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.
15
 *
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
19
 */
20
21
/**
22
 * @file
23
 * Common header for Microsoft Screen 1 and 2
24
 */
25
26
#ifndef AVCODEC_MSS12_H
27
#define AVCODEC_MSS12_H
28
29
#include "libavutil/intreadwrite.h"
30
#include "avcodec.h"
31
#include "get_bits.h"
32
#include "bytestream.h"
33
34
#define MODEL_MIN_SYMS    2
35
#define MODEL_MAX_SYMS  256
36
601M
#define THRESH_ADAPTIVE  -1
37
432k
#define THRESH_LOW       15
38
15.0k
#define THRESH_HIGH      50
39
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];
44
    int num_syms;
45
    int thr_weight, threshold;
46
} Model;
47
48
typedef struct ArithCoder {
49
    int low, high, value;
50
    int overread;
51
120M
#define MAX_OVERREAD 16
52
    union {
53
        GetBitContext *gb;
54
        GetByteContext *gB;
55
    } gbc;
56
    int (*get_model_sym)(struct ArithCoder *c, Model *m);
57
    int (*get_number)   (struct ArithCoder *c, int n);
58
} ArithCoder;
59
60
typedef struct PixContext {
61
    int cache_size, num_syms;
62
    uint8_t cache[12];
63
    Model cache_model, full_model;
64
    Model sec_models[15][4];
65
    int special_initial_cache;
66
} PixContext;
67
68
struct MSS12Context;
69
70
typedef struct SliceContext {
71
    const struct MSS12Context *c;
72
    Model      intra_region, inter_region;
73
    Model      pivot, edge_mode, split_mode;
74
    PixContext intra_pix_ctx, inter_pix_ctx;
75
} SliceContext;
76
77
typedef struct MSS12Context {
78
    AVCodecContext *avctx;
79
    uint32_t       pal[256];
80
    uint8_t        *pal_pic;
81
    uint8_t        *last_pal_pic;
82
    ptrdiff_t      pal_stride;
83
    uint8_t        *mask;
84
    ptrdiff_t      mask_stride;
85
    uint8_t        *rgb_pic;
86
    uint8_t        *last_rgb_pic;
87
    ptrdiff_t      rgb_stride;
88
    int            free_colours;
89
    int            keyframe;
90
    int            mvX, mvY;
91
    int            corrupted;
92
    int            slice_split;
93
    int            full_model_syms;
94
} MSS12Context;
95
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);
103
104
#define ARITH_GET_BIT(prefix)                                           \
105
613k
static int prefix ## _get_bit(ArithCoder *c)                            \
106
613k
{                                                                       \
107
613k
    int range = c->high - c->low + 1;                                   \
108
613k
    int bit   = 2 * c->value - c->low >= c->high;                       \
109
613k
                                                                        \
110
613k
    if (bit)                                                            \
111
613k
        c->low += range >> 1;                                           \
112
613k
    else                                                                \
113
613k
        c->high = c->low + (range >> 1) - 1;                            \
114
613k
                                                                        \
115
613k
    prefix ## _normalise(c);                                            \
116
613k
                                                                        \
117
613k
    return bit;                                                         \
118
613k
}
mss1.c:arith_get_bit
Line
Count
Source
105
337k
static int prefix ## _get_bit(ArithCoder *c)                            \
106
337k
{                                                                       \
107
337k
    int range = c->high - c->low + 1;                                   \
108
337k
    int bit   = 2 * c->value - c->low >= c->high;                       \
109
337k
                                                                        \
110
337k
    if (bit)                                                            \
111
337k
        c->low += range >> 1;                                           \
112
337k
    else                                                                \
113
337k
        c->high = c->low + (range >> 1) - 1;                            \
114
337k
                                                                        \
115
337k
    prefix ## _normalise(c);                                            \
116
337k
                                                                        \
117
337k
    return bit;                                                         \
118
337k
}
mss2.c:arith2_get_bit
Line
Count
Source
105
276k
static int prefix ## _get_bit(ArithCoder *c)                            \
106
276k
{                                                                       \
107
276k
    int range = c->high - c->low + 1;                                   \
108
276k
    int bit   = 2 * c->value - c->low >= c->high;                       \
109
276k
                                                                        \
110
276k
    if (bit)                                                            \
111
276k
        c->low += range >> 1;                                           \
112
276k
    else                                                                \
113
276k
        c->high = c->low + (range >> 1) - 1;                            \
114
276k
                                                                        \
115
276k
    prefix ## _normalise(c);                                            \
116
276k
                                                                        \
117
276k
    return bit;                                                         \
118
276k
}
119
120
#define ARITH_GET_MODEL_SYM(prefix)                                     \
121
601M
static int prefix ## _get_model_sym(ArithCoder *c, Model *m)            \
122
601M
{                                                                       \
123
601M
    int idx, val;                                                       \
124
601M
                                                                        \
125
601M
    idx = prefix ## _get_prob(c, m->cum_prob);                          \
126
601M
                                                                        \
127
601M
    val = m->idx2sym[idx];                                              \
128
601M
    ff_mss12_model_update(m, idx);                                      \
129
601M
                                                                        \
130
601M
    prefix ## _normalise(c);                                            \
131
601M
                                                                        \
132
601M
    return val;                                                         \
133
601M
}
mss1.c:arith_get_model_sym
Line
Count
Source
121
44.4M
static int prefix ## _get_model_sym(ArithCoder *c, Model *m)            \
122
44.4M
{                                                                       \
123
44.4M
    int idx, val;                                                       \
124
44.4M
                                                                        \
125
44.4M
    idx = prefix ## _get_prob(c, m->cum_prob);                          \
126
44.4M
                                                                        \
127
44.4M
    val = m->idx2sym[idx];                                              \
128
44.4M
    ff_mss12_model_update(m, idx);                                      \
129
44.4M
                                                                        \
130
44.4M
    prefix ## _normalise(c);                                            \
131
44.4M
                                                                        \
132
44.4M
    return val;                                                         \
133
44.4M
}
mss2.c:arith2_get_model_sym
Line
Count
Source
121
557M
static int prefix ## _get_model_sym(ArithCoder *c, Model *m)            \
122
557M
{                                                                       \
123
557M
    int idx, val;                                                       \
124
557M
                                                                        \
125
557M
    idx = prefix ## _get_prob(c, m->cum_prob);                          \
126
557M
                                                                        \
127
557M
    val = m->idx2sym[idx];                                              \
128
557M
    ff_mss12_model_update(m, idx);                                      \
129
557M
                                                                        \
130
557M
    prefix ## _normalise(c);                                            \
131
557M
                                                                        \
132
557M
    return val;                                                         \
133
557M
}
134
135
#endif /* AVCODEC_MSS12_H */