3 * Copyright (c) 2003 Michael Niedermayer
4 * Copyright (c) 2006 Konstantin Shishkov
6 * This file is part of FFmpeg.
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.
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.
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
25 * JPEG-LS common code.
28 #ifndef AVCODEC_JPEGLS_H
29 #define AVCODEC_JPEGLS_H
31 #include "libavutil/common.h"
35 typedef struct JpeglsContext {
36 AVCodecContext *avctx;
39 typedef struct JLSState {
41 int A[367], B[367], C[365], N[367];
42 int limit, reset, bpp, qbpp, maxval, range;
48 * Calculate initial JPEG-LS parameters
50 void ff_jpegls_init_state(JLSState *state);
53 * Calculate quantized gradient value, used for context determination
55 static inline int ff_jpegls_quantize(JLSState *s, int v)
83 * Calculate JPEG-LS codec values
85 void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all);
87 static inline void ff_jpegls_downscale_state(JLSState *state, int Q)
89 if (state->N[Q] == state->reset) {
97 static inline int ff_jpegls_update_state_regular(JLSState *state,
100 if(FFABS(err) > 0xFFFF)
102 state->A[Q] += FFABS(err);
103 err *= state->twonear;
106 ff_jpegls_downscale_state(state, Q);
108 if (state->B[Q] <= -state->N[Q]) {
109 state->B[Q] = FFMAX(state->B[Q] + state->N[Q], 1 - state->N[Q]);
110 if (state->C[Q] > -128)
112 } else if (state->B[Q] > 0) {
113 state->B[Q] = FFMIN(state->B[Q] - state->N[Q], 0);
114 if (state->C[Q] < 127)
121 #define R(a, i) (bits == 8 ? ((uint8_t *)(a))[i] : ((uint16_t *)(a))[i])
122 #define W(a, i, v) (bits == 8 ? (((uint8_t *)(a))[i] = v) : (((uint16_t *)(a))[i] = v))
124 #endif /* AVCODEC_JPEGLS_H */