Coverage Report

Created: 2026-02-14 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/jpegls.h
Line
Count
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 <limits.h>
32
#include "libavutil/common.h"
33
34
#undef near /* This file uses struct member 'near' which in windows.h is defined as empty. */
35
36
typedef struct JLSState {
37
    int T1, T2, T3;
38
    int A[367], B[367], C[365], N[367];
39
    int limit, reset, bpp, qbpp, maxval, range;
40
    int near, twonear;
41
    int run_index[4];
42
} JLSState;
43
44
/**
45
 * Calculate initial JPEG-LS parameters
46
 */
47
void ff_jpegls_init_state(JLSState *state);
48
49
/**
50
 * Calculate quantized gradient value, used for context determination
51
 */
52
static inline int ff_jpegls_quantize(JLSState *s, int v)
53
67.4M
{
54
67.4M
    if (v == 0)
55
20.1M
        return 0;
56
47.3M
    if (v < 0) {
57
25.9M
        if (v <= -s->T3)
58
17.0M
            return -4;
59
8.88M
        if (v <= -s->T2)
60
2.24M
            return -3;
61
6.63M
        if (v <= -s->T1)
62
2.41M
            return -2;
63
4.22M
        if (v < -s->near)
64
3.15M
            return -1;
65
1.06M
        return 0;
66
21.3M
    } else {
67
21.3M
        if (v <= s->near)
68
1.68M
            return 0;
69
19.6M
        if (v < s->T1)
70
2.91M
            return 1;
71
16.7M
        if (v < s->T2)
72
1.80M
            return 2;
73
14.9M
        if (v < s->T3)
74
1.83M
            return 3;
75
13.1M
        return 4;
76
14.9M
    }
77
47.3M
}
jpeglsdec.c:ff_jpegls_quantize
Line
Count
Source
53
41.4M
{
54
41.4M
    if (v == 0)
55
13.9M
        return 0;
56
27.5M
    if (v < 0) {
57
15.6M
        if (v <= -s->T3)
58
8.28M
            return -4;
59
7.35M
        if (v <= -s->T2)
60
1.37M
            return -3;
61
5.98M
        if (v <= -s->T1)
62
2.02M
            return -2;
63
3.95M
        if (v < -s->near)
64
2.89M
            return -1;
65
1.06M
        return 0;
66
11.8M
    } else {
67
11.8M
        if (v <= s->near)
68
1.68M
            return 0;
69
10.1M
        if (v < s->T1)
70
2.73M
            return 1;
71
7.44M
        if (v < s->T2)
72
1.51M
            return 2;
73
5.93M
        if (v < s->T3)
74
1.00M
            return 3;
75
4.92M
        return 4;
76
5.93M
    }
77
27.5M
}
Unexecuted instantiation: jpegls.c:ff_jpegls_quantize
jpeglsenc.c:ff_jpegls_quantize
Line
Count
Source
53
25.9M
{
54
25.9M
    if (v == 0)
55
6.16M
        return 0;
56
19.7M
    if (v < 0) {
57
10.2M
        if (v <= -s->T3)
58
8.75M
            return -4;
59
1.52M
        if (v <= -s->T2)
60
876k
            return -3;
61
651k
        if (v <= -s->T1)
62
385k
            return -2;
63
266k
        if (v < -s->near)
64
266k
            return -1;
65
0
        return 0;
66
9.50M
    } else {
67
9.50M
        if (v <= s->near)
68
0
            return 0;
69
9.50M
        if (v < s->T1)
70
182k
            return 1;
71
9.32M
        if (v < s->T2)
72
290k
            return 2;
73
9.03M
        if (v < s->T3)
74
829k
            return 3;
75
8.20M
        return 4;
76
9.03M
    }
77
19.7M
}
78
79
/**
80
 * Calculate JPEG-LS codec values
81
 */
82
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all);
83
84
static inline void ff_jpegls_downscale_state(JLSState *state, int Q)
85
26.9M
{
86
26.9M
    if (state->N[Q] == state->reset) {
87
838k
        state->A[Q] >>= 1;
88
838k
        state->B[Q] >>= 1;
89
838k
        state->N[Q] >>= 1;
90
838k
    }
91
26.9M
    state->N[Q]++;
92
26.9M
}
jpeglsdec.c:ff_jpegls_downscale_state
Line
Count
Source
85
18.1M
{
86
18.1M
    if (state->N[Q] == state->reset) {
87
583k
        state->A[Q] >>= 1;
88
583k
        state->B[Q] >>= 1;
89
583k
        state->N[Q] >>= 1;
90
583k
    }
91
18.1M
    state->N[Q]++;
92
18.1M
}
Unexecuted instantiation: jpegls.c:ff_jpegls_downscale_state
jpeglsenc.c:ff_jpegls_downscale_state
Line
Count
Source
85
8.79M
{
86
8.79M
    if (state->N[Q] == state->reset) {
87
254k
        state->A[Q] >>= 1;
88
254k
        state->B[Q] >>= 1;
89
254k
        state->N[Q] >>= 1;
90
254k
    }
91
8.79M
    state->N[Q]++;
92
8.79M
}
93
94
static inline int ff_jpegls_update_state_regular(JLSState *state,
95
                                                 int Q, int err)
96
22.4M
{
97
22.4M
    if(FFABS(err) > 0xFFFF || FFABS(err) > INT_MAX - state->A[Q])
98
155k
        return -0x10000;
99
22.3M
    state->A[Q] += FFABS(err);
100
22.3M
    err         *= state->twonear;
101
22.3M
    state->B[Q] += err;
102
103
22.3M
    ff_jpegls_downscale_state(state, Q);
104
105
22.3M
    if (state->B[Q] <= -state->N[Q]) {
106
6.08M
        state->B[Q] = FFMAX(state->B[Q] + state->N[Q], 1 - state->N[Q]);
107
6.08M
        if (state->C[Q] > -128)
108
5.80M
            state->C[Q]--;
109
16.2M
    } else if (state->B[Q] > 0) {
110
6.55M
        state->B[Q] = FFMIN(state->B[Q] - state->N[Q], 0);
111
6.55M
        if (state->C[Q] < 127)
112
5.36M
            state->C[Q]++;
113
6.55M
    }
114
115
22.3M
    return err;
116
22.4M
}
jpeglsdec.c:ff_jpegls_update_state_regular
Line
Count
Source
96
13.8M
{
97
13.8M
    if(FFABS(err) > 0xFFFF || FFABS(err) > INT_MAX - state->A[Q])
98
155k
        return -0x10000;
99
13.6M
    state->A[Q] += FFABS(err);
100
13.6M
    err         *= state->twonear;
101
13.6M
    state->B[Q] += err;
102
103
13.6M
    ff_jpegls_downscale_state(state, Q);
104
105
13.6M
    if (state->B[Q] <= -state->N[Q]) {
106
3.28M
        state->B[Q] = FFMAX(state->B[Q] + state->N[Q], 1 - state->N[Q]);
107
3.28M
        if (state->C[Q] > -128)
108
3.12M
            state->C[Q]--;
109
10.3M
    } else if (state->B[Q] > 0) {
110
3.77M
        state->B[Q] = FFMIN(state->B[Q] - state->N[Q], 0);
111
3.77M
        if (state->C[Q] < 127)
112
2.68M
            state->C[Q]++;
113
3.77M
    }
114
115
13.6M
    return err;
116
13.8M
}
Unexecuted instantiation: jpegls.c:ff_jpegls_update_state_regular
jpeglsenc.c:ff_jpegls_update_state_regular
Line
Count
Source
96
8.65M
{
97
8.65M
    if(FFABS(err) > 0xFFFF || FFABS(err) > INT_MAX - state->A[Q])
98
0
        return -0x10000;
99
8.65M
    state->A[Q] += FFABS(err);
100
8.65M
    err         *= state->twonear;
101
8.65M
    state->B[Q] += err;
102
103
8.65M
    ff_jpegls_downscale_state(state, Q);
104
105
8.65M
    if (state->B[Q] <= -state->N[Q]) {
106
2.80M
        state->B[Q] = FFMAX(state->B[Q] + state->N[Q], 1 - state->N[Q]);
107
2.80M
        if (state->C[Q] > -128)
108
2.67M
            state->C[Q]--;
109
5.85M
    } else if (state->B[Q] > 0) {
110
2.78M
        state->B[Q] = FFMIN(state->B[Q] - state->N[Q], 0);
111
2.78M
        if (state->C[Q] < 127)
112
2.68M
            state->C[Q]++;
113
2.78M
    }
114
115
8.65M
    return err;
116
8.65M
}
117
118
187M
#define R(a, i)    (bits == 8 ?  ((uint8_t *)(a))[i]      :  ((uint16_t *)(a))[i])
119
539M
#define W(a, i, v) (bits == 8 ? (((uint8_t *)(a))[i] = v) : (((uint16_t *)(a))[i] = v))
120
121
#endif /* AVCODEC_JPEGLS_H */