../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
43 / 43
100.0%
Branches:
19 / 44
43.2%
Functions:
3 / 3
100.0%

libavcodec/jpegls.c
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 "libavutil/log.h"
32 #include "jpegls.h"
33
34 1120 void ff_jpegls_init_state(JLSState *state)
35 {
36 int i;
37
38 1120 state->twonear = state->near * 2 + 1;
39 1120 state->range = (state->maxval + state->twonear - 1) / state->twonear + 1;
40
41 // QBPP = ceil(log2(RANGE))
42
2/2
✓ Branch 4 → 3 taken 8954 times.
✓ Branch 4 → 5 taken 1120 times.
10074 for (state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++)
43 ;
44
45
2/2
✓ Branch 5 → 6 taken 1118 times.
✓ Branch 5 → 7 taken 2 times.
1120 state->bpp = FFMAX(av_log2(state->maxval) + 1, 2);
46 1120 state->limit = 2*(state->bpp + FFMAX(state->bpp, 8)) - state->qbpp;
47
48
2/2
✓ Branch 10 → 9 taken 411040 times.
✓ Branch 10 → 11 taken 1120 times.
412160 for (i = 0; i < 367; i++) {
49 411040 state->A[i] = FFMAX(state->range + 32 >> 6, 2);
50 411040 state->N[i] = 1;
51 }
52
53 1120 memset(state->B, 0, sizeof(state->B));
54 1120 memset(state->C, 0, sizeof(state->C));
55 1120 memset(state->run_index, 0, sizeof(state->run_index));
56 1120 }
57
58 /**
59 * Custom value clipping function used in T1, T2, T3 calculation
60 */
61 1875 static inline int iso_clip(int v, int vmin, int vmax)
62 {
63
3/4
✓ Branch 2 → 3 taken 1873 times.
✓ Branch 2 → 4 taken 2 times.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1873 times.
1875 if (v > vmax || v < vmin)
64 2 return vmin;
65 else
66 1873 return v;
67 }
68
69 625 void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all)
70 {
71 625 const int basic_t1 = 3;
72 625 const int basic_t2 = 7;
73 625 const int basic_t3 = 21;
74 int factor;
75
76
1/4
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 625 times.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
625 if (s->maxval == 0 || reset_all)
77 625 s->maxval = (1 << s->bpp) - 1;
78
79
2/2
✓ Branch 5 → 6 taken 617 times.
✓ Branch 5 → 18 taken 8 times.
625 if (s->maxval >= 128) {
80 617 factor = FFMIN(s->maxval, 4095) + 128 >> 8;
81
82
1/4
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 617 times.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 10 not taken.
617 if (s->T1 == 0 || reset_all)
83 617 s->T1 = iso_clip(factor * (basic_t1 - 2) + 2 + 3 * s->near,
84 617 s->near + 1, s->maxval);
85
1/4
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 617 times.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 14 not taken.
617 if (s->T2 == 0 || reset_all)
86 617 s->T2 = iso_clip(factor * (basic_t2 - 3) + 3 + 5 * s->near,
87 s->T1, s->maxval);
88
1/4
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 617 times.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 30 not taken.
617 if (s->T3 == 0 || reset_all)
89 617 s->T3 = iso_clip(factor * (basic_t3 - 4) + 4 + 7 * s->near,
90 s->T2, s->maxval);
91 } else {
92 8 factor = 256 / (s->maxval + 1);
93
94
1/4
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 8 times.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 22 not taken.
8 if (s->T1 == 0 || reset_all)
95 8 s->T1 = iso_clip(FFMAX(2, basic_t1 / factor + 3 * s->near),
96 8 s->near + 1, s->maxval);
97
1/4
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 8 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 26 not taken.
8 if (s->T2 == 0 || reset_all)
98 8 s->T2 = iso_clip(FFMAX(3, basic_t2 / factor + 5 * s->near),
99 s->T1, s->maxval);
100
1/4
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 8 times.
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 30 not taken.
8 if (s->T3 == 0 || reset_all)
101 8 s->T3 = iso_clip(FFMAX(4, basic_t3 / factor + 7 * s->near),
102 s->T2, s->maxval);
103 }
104
105
1/4
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 625 times.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 33 not taken.
625 if (s->reset == 0 || reset_all)
106 625 s->reset = 64;
107 ff_dlog(NULL, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3);
108 625 }
109