GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/jpegls.h Lines: 42 45 93.3 %
Date: 2019-11-22 03:34:36 Branches: 29 32 90.6 %

Line Branch Exec Source
1
/*
2
 * JPEG-LS common code
3
 * Copyright (c) 2003 Michael Niedermayer
4
 * Copyright (c) 2006 Konstantin Shishkov
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22
23
/**
24
 * @file
25
 * JPEG-LS common code.
26
 */
27
28
#ifndef AVCODEC_JPEGLS_H
29
#define AVCODEC_JPEGLS_H
30
31
#include "libavutil/common.h"
32
#include "avcodec.h"
33
#include "internal.h"
34
35
#undef near /* This file uses struct member 'near' which in windows.h is defined as empty. */
36
37
typedef struct JpeglsContext {
38
    AVCodecContext *avctx;
39
} JpeglsContext;
40
41
typedef struct JLSState {
42
    int T1, T2, T3;
43
    int A[367], B[367], C[365], N[367];
44
    int limit, reset, bpp, qbpp, maxval, range;
45
    int near, twonear;
46
    int run_index[4];
47
} JLSState;
48
49
/**
50
 * Calculate initial JPEG-LS parameters
51
 */
52
void ff_jpegls_init_state(JLSState *state);
53
54
/**
55
 * Calculate quantized gradient value, used for context determination
56
 */
57
261946935
static inline int ff_jpegls_quantize(JLSState *s, int v)
58
{
59
261946935
    if (v == 0)
60
22609799
        return 0;
61
239337136
    if (v < 0) {
62
110161910
        if (v <= -s->T3)
63
20088936
            return -4;
64
90072974
        if (v <= -s->T2)
65
42203615
            return -3;
66
47869359
        if (v <= -s->T1)
67
24863312
            return -2;
68
23006047
        if (v < -s->near)
69
23006047
            return -1;
70
        return 0;
71
    } else {
72
129175226
        if (v <= s->near)
73
            return 0;
74
129175226
        if (v < s->T1)
75
24267848
            return 1;
76
104907378
        if (v < s->T2)
77
34074282
            return 2;
78
70833096
        if (v < s->T3)
79
52267563
            return 3;
80
18565533
        return 4;
81
    }
82
}
83
84
/**
85
 * Calculate JPEG-LS codec values
86
 */
87
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all);
88
89
88349902
static inline void ff_jpegls_downscale_state(JLSState *state, int Q)
90
{
91
88349902
    if (state->N[Q] == state->reset) {
92
2597000
        state->A[Q] >>= 1;
93
2597000
        state->B[Q] >>= 1;
94
2597000
        state->N[Q] >>= 1;
95
    }
96
88349902
    state->N[Q]++;
97
88349902
}
98
99
87315645
static inline int ff_jpegls_update_state_regular(JLSState *state,
100
                                                 int Q, int err)
101
{
102
87315645
    if(FFABS(err) > 0xFFFF)
103
        return -0x10000;
104
87315645
    state->A[Q] += FFABS(err);
105
87315645
    err         *= state->twonear;
106
87315645
    state->B[Q] += err;
107
108
87315645
    ff_jpegls_downscale_state(state, Q);
109
110
87315645
    if (state->B[Q] <= -state->N[Q]) {
111
6507442
        state->B[Q] = FFMAX(state->B[Q] + state->N[Q], 1 - state->N[Q]);
112
6507442
        if (state->C[Q] > -128)
113
6494287
            state->C[Q]--;
114
80808203
    } else if (state->B[Q] > 0) {
115
6741036
        state->B[Q] = FFMIN(state->B[Q] - state->N[Q], 0);
116
6741036
        if (state->C[Q] < 127)
117
6740978
            state->C[Q]++;
118
    }
119
120
87315645
    return err;
121
}
122
123
#define R(a, i)    (bits == 8 ?  ((uint8_t *)(a))[i]      :  ((uint16_t *)(a))[i])
124
#define W(a, i, v) (bits == 8 ? (((uint8_t *)(a))[i] = v) : (((uint16_t *)(a))[i] = v))
125
126
#endif /* AVCODEC_JPEGLS_H */