FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/jpegls.c
Date: 2021-09-24 03:35:22
Exec Total Coverage
Lines: 40 40 100.0%
Branches: 17 42 40.5%

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 #include <stddef.h>
29 #include "libavutil/internal.h"
30 #include "libavutil/intmath.h"
31 #include "jpegls.h"
32
33 413 void ff_jpegls_init_state(JLSState *state)
34 {
35 int i;
36
37 413 state->twonear = state->near * 2 + 1;
38 413 state->range = (state->maxval + state->twonear - 1) / state->twonear + 1;
39
40 // QBPP = ceil(log2(RANGE))
41
2/2
✓ Branch 0 taken 3274 times.
✓ Branch 1 taken 413 times.
3687 for (state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++)
42 ;
43
44 413 state->bpp = FFMAX(av_log2(state->maxval) + 1, 2);
45 413 state->limit = 2*(state->bpp + FFMAX(state->bpp, 8)) - state->qbpp;
46
47
2/2
✓ Branch 0 taken 151571 times.
✓ Branch 1 taken 413 times.
151984 for (i = 0; i < 367; i++) {
48 151571 state->A[i] = FFMAX(state->range + 32 >> 6, 2);
49 151571 state->N[i] = 1;
50 }
51 413 }
52
53 /**
54 * Custom value clipping function used in T1, T2, T3 calculation
55 */
56 1839 static inline int iso_clip(int v, int vmin, int vmax)
57 {
58
3/4
✓ Branch 0 taken 1837 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1837 times.
1839 if (v > vmax || v < vmin)
59 2 return vmin;
60 else
61 1837 return v;
62 }
63
64 613 void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all)
65 {
66 613 const int basic_t1 = 3;
67 613 const int basic_t2 = 7;
68 613 const int basic_t3 = 21;
69 int factor;
70
71
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 613 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
613 if (s->maxval == 0 || reset_all)
72 613 s->maxval = (1 << s->bpp) - 1;
73
74
2/2
✓ Branch 0 taken 605 times.
✓ Branch 1 taken 8 times.
613 if (s->maxval >= 128) {
75 605 factor = FFMIN(s->maxval, 4095) + 128 >> 8;
76
77
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 605 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
605 if (s->T1 == 0 || reset_all)
78 605 s->T1 = iso_clip(factor * (basic_t1 - 2) + 2 + 3 * s->near,
79 605 s->near + 1, s->maxval);
80
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 605 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
605 if (s->T2 == 0 || reset_all)
81 605 s->T2 = iso_clip(factor * (basic_t2 - 3) + 3 + 5 * s->near,
82 s->T1, s->maxval);
83
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 605 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
605 if (s->T3 == 0 || reset_all)
84 605 s->T3 = iso_clip(factor * (basic_t3 - 4) + 4 + 7 * s->near,
85 s->T2, s->maxval);
86 } else {
87 8 factor = 256 / (s->maxval + 1);
88
89
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8 if (s->T1 == 0 || reset_all)
90 8 s->T1 = iso_clip(FFMAX(2, basic_t1 / factor + 3 * s->near),
91 8 s->near + 1, s->maxval);
92
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8 if (s->T2 == 0 || reset_all)
93 8 s->T2 = iso_clip(FFMAX(3, basic_t2 / factor + 5 * s->near),
94 s->T1, s->maxval);
95
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8 if (s->T3 == 0 || reset_all)
96 8 s->T3 = iso_clip(FFMAX(4, basic_t3 / factor + 7 * s->near),
97 s->T2, s->maxval);
98 }
99
100
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 613 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
613 if (s->reset == 0 || reset_all)
101 613 s->reset = 64;
102 ff_dlog(NULL, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3);
103 613 }
104