FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/jpegls.h
Date: 2024-03-29 01:21:52
Exec Total Coverage
Lines: 42 45 93.3%
Functions: 3 3 100.0%
Branches: 30 34 88.2%

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 <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 268769721 static inline int ff_jpegls_quantize(JLSState *s, int v)
53 {
54
2/2
✓ Branch 0 taken 24686059 times.
✓ Branch 1 taken 244083662 times.
268769721 if (v == 0)
55 24686059 return 0;
56
2/2
✓ Branch 0 taken 112540144 times.
✓ Branch 1 taken 131543518 times.
244083662 if (v < 0) {
57
2/2
✓ Branch 0 taken 20713152 times.
✓ Branch 1 taken 91826992 times.
112540144 if (v <= -s->T3)
58 20713152 return -4;
59
2/2
✓ Branch 0 taken 42818369 times.
✓ Branch 1 taken 49008623 times.
91826992 if (v <= -s->T2)
60 42818369 return -3;
61
2/2
✓ Branch 0 taken 25156926 times.
✓ Branch 1 taken 23851697 times.
49008623 if (v <= -s->T1)
62 25156926 return -2;
63
1/2
✓ Branch 0 taken 23851697 times.
✗ Branch 1 not taken.
23851697 if (v < -s->near)
64 23851697 return -1;
65 return 0;
66 } else {
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 131543518 times.
131543518 if (v <= s->near)
68 return 0;
69
2/2
✓ Branch 0 taken 25104206 times.
✓ Branch 1 taken 106439312 times.
131543518 if (v < s->T1)
70 25104206 return 1;
71
2/2
✓ Branch 0 taken 34370228 times.
✓ Branch 1 taken 72069084 times.
106439312 if (v < s->T2)
72 34370228 return 2;
73
2/2
✓ Branch 0 taken 52885815 times.
✓ Branch 1 taken 19183269 times.
72069084 if (v < s->T3)
74 52885815 return 3;
75 19183269 return 4;
76 }
77 }
78
79 /**
80 * Calculate JPEG-LS codec values
81 */
82 void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all);
83
84 90884626 static inline void ff_jpegls_downscale_state(JLSState *state, int Q)
85 {
86
2/2
✓ Branch 0 taken 2673854 times.
✓ Branch 1 taken 88210772 times.
90884626 if (state->N[Q] == state->reset) {
87 2673854 state->A[Q] >>= 1;
88 2673854 state->B[Q] >>= 1;
89 2673854 state->N[Q] >>= 1;
90 }
91 90884626 state->N[Q]++;
92 90884626 }
93
94 89589907 static inline int ff_jpegls_update_state_regular(JLSState *state,
95 int Q, int err)
96 {
97
2/4
✓ Branch 0 taken 89589907 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 89589907 times.
89589907 if(FFABS(err) > 0xFFFF || FFABS(err) > INT_MAX - state->A[Q])
98 return -0x10000;
99 89589907 state->A[Q] += FFABS(err);
100 89589907 err *= state->twonear;
101 89589907 state->B[Q] += err;
102
103 89589907 ff_jpegls_downscale_state(state, Q);
104
105
2/2
✓ Branch 0 taken 6569792 times.
✓ Branch 1 taken 83020115 times.
89589907 if (state->B[Q] <= -state->N[Q]) {
106 6569792 state->B[Q] = FFMAX(state->B[Q] + state->N[Q], 1 - state->N[Q]);
107
2/2
✓ Branch 0 taken 6556637 times.
✓ Branch 1 taken 13155 times.
6569792 if (state->C[Q] > -128)
108 6556637 state->C[Q]--;
109
2/2
✓ Branch 0 taken 6805312 times.
✓ Branch 1 taken 76214803 times.
83020115 } else if (state->B[Q] > 0) {
110 6805312 state->B[Q] = FFMIN(state->B[Q] - state->N[Q], 0);
111
2/2
✓ Branch 0 taken 6805254 times.
✓ Branch 1 taken 58 times.
6805312 if (state->C[Q] < 127)
112 6805254 state->C[Q]++;
113 }
114
115 89589907 return err;
116 }
117
118 #define R(a, i) (bits == 8 ? ((uint8_t *)(a))[i] : ((uint16_t *)(a))[i])
119 #define W(a, i, v) (bits == 8 ? (((uint8_t *)(a))[i] = v) : (((uint16_t *)(a))[i] = v))
120
121 #endif /* AVCODEC_JPEGLS_H */
122