/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 | 38.1M | { |
54 | 38.1M | if (v == 0) |
55 | 10.0M | return 0; |
56 | 28.1M | if (v < 0) { |
57 | 15.0M | if (v <= -s->T3) |
58 | 11.1M | return -4; |
59 | 3.90M | if (v <= -s->T2) |
60 | 1.47M | return -3; |
61 | 2.43M | if (v <= -s->T1) |
62 | 989k | return -2; |
63 | 1.44M | if (v < -s->near) |
64 | 1.13M | return -1; |
65 | 311k | return 0; |
66 | 13.0M | } else { |
67 | 13.0M | if (v <= s->near) |
68 | 466k | return 0; |
69 | 12.5M | if (v < s->T1) |
70 | 876k | return 1; |
71 | 11.6M | if (v < s->T2) |
72 | 675k | return 2; |
73 | 11.0M | if (v < s->T3) |
74 | 1.24M | return 3; |
75 | 9.77M | return 4; |
76 | 11.0M | } |
77 | 28.1M | } jpeglsdec.c:ff_jpegls_quantize Line | Count | Source | 53 | 7.91M | { | 54 | 7.91M | if (v == 0) | 55 | 2.70M | return 0; | 56 | 5.21M | if (v < 0) { | 57 | 2.86M | if (v <= -s->T3) | 58 | 1.32M | return -4; | 59 | 1.53M | if (v <= -s->T2) | 60 | 372k | return -3; | 61 | 1.16M | if (v <= -s->T1) | 62 | 299k | return -2; | 63 | 861k | if (v < -s->near) | 64 | 549k | return -1; | 65 | 311k | return 0; | 66 | 2.35M | } else { | 67 | 2.35M | if (v <= s->near) | 68 | 466k | return 0; | 69 | 1.88M | if (v < s->T1) | 70 | 503k | return 1; | 71 | 1.38M | if (v < s->T2) | 72 | 201k | return 2; | 73 | 1.17M | if (v < s->T3) | 74 | 224k | return 3; | 75 | 955k | return 4; | 76 | 1.17M | } | 77 | 5.21M | } |
Unexecuted instantiation: jpegls.c:ff_jpegls_quantize jpeglsenc.c:ff_jpegls_quantize Line | Count | Source | 53 | 30.2M | { | 54 | 30.2M | if (v == 0) | 55 | 7.32M | return 0; | 56 | 22.9M | if (v < 0) { | 57 | 12.2M | if (v <= -s->T3) | 58 | 9.85M | return -4; | 59 | 2.37M | if (v <= -s->T2) | 60 | 1.09M | return -3; | 61 | 1.27M | if (v <= -s->T1) | 62 | 689k | return -2; | 63 | 587k | if (v < -s->near) | 64 | 587k | return -1; | 65 | 0 | return 0; | 66 | 10.6M | } else { | 67 | 10.6M | if (v <= s->near) | 68 | 0 | return 0; | 69 | 10.6M | if (v < s->T1) | 70 | 373k | return 1; | 71 | 10.3M | if (v < s->T2) | 72 | 473k | return 2; | 73 | 9.83M | if (v < s->T3) | 74 | 1.01M | return 3; | 75 | 8.81M | return 4; | 76 | 9.83M | } | 77 | 22.9M | } |
|
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 | 14.6M | { |
86 | 14.6M | if (state->N[Q] == state->reset) { |
87 | 477k | state->A[Q] >>= 1; |
88 | 477k | state->B[Q] >>= 1; |
89 | 477k | state->N[Q] >>= 1; |
90 | 477k | } |
91 | 14.6M | state->N[Q]++; |
92 | 14.6M | } jpeglsdec.c:ff_jpegls_downscale_state Line | Count | Source | 85 | 4.32M | { | 86 | 4.32M | if (state->N[Q] == state->reset) { | 87 | 184k | state->A[Q] >>= 1; | 88 | 184k | state->B[Q] >>= 1; | 89 | 184k | state->N[Q] >>= 1; | 90 | 184k | } | 91 | 4.32M | state->N[Q]++; | 92 | 4.32M | } |
Unexecuted instantiation: jpegls.c:ff_jpegls_downscale_state jpeglsenc.c:ff_jpegls_downscale_state Line | Count | Source | 85 | 10.3M | { | 86 | 10.3M | if (state->N[Q] == state->reset) { | 87 | 292k | state->A[Q] >>= 1; | 88 | 292k | state->B[Q] >>= 1; | 89 | 292k | state->N[Q] >>= 1; | 90 | 292k | } | 91 | 10.3M | state->N[Q]++; | 92 | 10.3M | } |
|
93 | | |
94 | | static inline int ff_jpegls_update_state_regular(JLSState *state, |
95 | | int Q, int err) |
96 | 12.7M | { |
97 | 12.7M | if(FFABS(err) > 0xFFFF || FFABS(err) > INT_MAX - state->A[Q]) |
98 | 45.6k | return -0x10000; |
99 | 12.6M | state->A[Q] += FFABS(err); |
100 | 12.6M | err *= state->twonear; |
101 | 12.6M | state->B[Q] += err; |
102 | | |
103 | 12.6M | ff_jpegls_downscale_state(state, Q); |
104 | | |
105 | 12.6M | if (state->B[Q] <= -state->N[Q]) { |
106 | 3.71M | state->B[Q] = FFMAX(state->B[Q] + state->N[Q], 1 - state->N[Q]); |
107 | 3.71M | if (state->C[Q] > -128) |
108 | 3.60M | state->C[Q]--; |
109 | 8.96M | } else if (state->B[Q] > 0) { |
110 | 4.05M | state->B[Q] = FFMIN(state->B[Q] - state->N[Q], 0); |
111 | 4.05M | if (state->C[Q] < 127) |
112 | 3.57M | state->C[Q]++; |
113 | 4.05M | } |
114 | | |
115 | 12.6M | return err; |
116 | 12.7M | } jpeglsdec.c:ff_jpegls_update_state_regular Line | Count | Source | 96 | 2.63M | { | 97 | 2.63M | if(FFABS(err) > 0xFFFF || FFABS(err) > INT_MAX - state->A[Q]) | 98 | 45.6k | return -0x10000; | 99 | 2.59M | state->A[Q] += FFABS(err); | 100 | 2.59M | err *= state->twonear; | 101 | 2.59M | state->B[Q] += err; | 102 | | | 103 | 2.59M | ff_jpegls_downscale_state(state, Q); | 104 | | | 105 | 2.59M | if (state->B[Q] <= -state->N[Q]) { | 106 | 523k | state->B[Q] = FFMAX(state->B[Q] + state->N[Q], 1 - state->N[Q]); | 107 | 523k | if (state->C[Q] > -128) | 108 | 487k | state->C[Q]--; | 109 | 2.06M | } else if (state->B[Q] > 0) { | 110 | 833k | state->B[Q] = FFMIN(state->B[Q] - state->N[Q], 0); | 111 | 833k | if (state->C[Q] < 127) | 112 | 477k | state->C[Q]++; | 113 | 833k | } | 114 | | | 115 | 2.59M | return err; | 116 | 2.63M | } |
Unexecuted instantiation: jpegls.c:ff_jpegls_update_state_regular jpeglsenc.c:ff_jpegls_update_state_regular Line | Count | Source | 96 | 10.0M | { | 97 | 10.0M | if(FFABS(err) > 0xFFFF || FFABS(err) > INT_MAX - state->A[Q]) | 98 | 0 | return -0x10000; | 99 | 10.0M | state->A[Q] += FFABS(err); | 100 | 10.0M | err *= state->twonear; | 101 | 10.0M | state->B[Q] += err; | 102 | | | 103 | 10.0M | ff_jpegls_downscale_state(state, Q); | 104 | | | 105 | 10.0M | if (state->B[Q] <= -state->N[Q]) { | 106 | 3.18M | state->B[Q] = FFMAX(state->B[Q] + state->N[Q], 1 - state->N[Q]); | 107 | 3.18M | if (state->C[Q] > -128) | 108 | 3.11M | state->C[Q]--; | 109 | 6.89M | } else if (state->B[Q] > 0) { | 110 | 3.22M | state->B[Q] = FFMIN(state->B[Q] - state->N[Q], 0); | 111 | 3.22M | if (state->C[Q] < 127) | 112 | 3.10M | state->C[Q]++; | 113 | 3.22M | } | 114 | | | 115 | 10.0M | return err; | 116 | 10.0M | } |
|
117 | | |
118 | 110M | #define R(a, i) (bits == 8 ? ((uint8_t *)(a))[i] : ((uint16_t *)(a))[i]) |
119 | 276M | #define W(a, i, v) (bits == 8 ? (((uint8_t *)(a))[i] = v) : (((uint16_t *)(a))[i] = v)) |
120 | | |
121 | | #endif /* AVCODEC_JPEGLS_H */ |