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
33
34 #undef near /* This file uses struct member 'near' which in windows.h is defined as empty. */
35
38 int A[367],
B[367],
C[365],
N[367];
43
44 /**
45 * Calculate initial JPEG-LS parameters
46 */
48
49 /**
50 * Calculate quantized gradient value, used for context determination
51 */
53 {
54 if (v == 0)
55 return 0;
56 if (v < 0) {
57 if (v <= -s->T3)
58 return -4;
59 if (v <= -s->T2)
60 return -3;
61 if (v <= -s->T1)
62 return -2;
63 if (v < -s->near)
64 return -1;
65 return 0;
66 } else {
67 if (v <= s->near)
68 return 0;
69 if (v < s->T1)
70 return 1;
71 if (v < s->T2)
72 return 2;
73 if (v < s->T3)
74 return 3;
75 return 4;
76 }
77 }
78
79 /**
80 * Calculate JPEG-LS codec values
81 */
83
85 {
90 }
92 }
93
95 int Q, int err)
96 {
98 return -0x10000;
100 err *=
state->twonear;
102
104
107 if (
state->C[Q] > -128)
109 }
else if (
state->B[Q] > 0) {
111 if (
state->C[Q] < 127)
113 }
114
115 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 */