Libav
jpegls.h
Go to the documentation of this file.
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 Libav.
7  *
8  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
28 #ifndef AVCODEC_JPEGLS_H
29 #define AVCODEC_JPEGLS_H
30 
31 #include "libavutil/common.h"
32 #include "avcodec.h"
33 
34 typedef struct JpeglsContext {
37 
38 typedef struct JLSState {
39  int T1, T2, T3;
40  int A[367], B[367], C[365], N[367];
41  int limit, reset, bpp, qbpp, maxval, range;
42  int near, twonear;
43  int run_index[3];
44 } JLSState;
45 
46 extern const uint8_t ff_log2_run[32];
47 
52 
56 static inline int ff_jpegls_quantize(JLSState *s, int v)
57 {
58  if (v == 0)
59  return 0;
60  if (v < 0) {
61  if (v <= -s->T3)
62  return -4;
63  if (v <= -s->T2)
64  return -3;
65  if (v <= -s->T1)
66  return -2;
67  if (v < -s->near)
68  return -1;
69  return 0;
70  } else {
71  if (v <= s->near)
72  return 0;
73  if (v < s->T1)
74  return 1;
75  if (v < s->T2)
76  return 2;
77  if (v < s->T3)
78  return 3;
79  return 4;
80  }
81 }
82 
86 void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all);
87 
88 static inline void ff_jpegls_downscale_state(JLSState *state, int Q)
89 {
90  if (state->N[Q] == state->reset) {
91  state->A[Q] >>= 1;
92  state->B[Q] >>= 1;
93  state->N[Q] >>= 1;
94  }
95  state->N[Q]++;
96 }
97 
99  int Q, int err)
100 {
101  state->A[Q] += FFABS(err);
102  err *= state->twonear;
103  state->B[Q] += err;
104 
105  ff_jpegls_downscale_state(state, Q);
106 
107  if (state->B[Q] <= -state->N[Q]) {
108  state->B[Q] = FFMAX(state->B[Q] + state->N[Q], 1 - state->N[Q]);
109  if (state->C[Q] > -128)
110  state->C[Q]--;
111  } else if (state->B[Q] > 0) {
112  state->B[Q] = FFMIN(state->B[Q] - state->N[Q], 0);
113  if (state->C[Q] < 127)
114  state->C[Q]++;
115  }
116 
117  return err;
118 }
119 
120 #define R(a, i) (bits == 8 ? ((uint8_t *)(a))[i] : ((uint16_t *)(a))[i])
121 #define W(a, i, v) (bits == 8 ? (((uint8_t *)(a))[i] = v) : (((uint16_t *)(a))[i] = v))
122 
123 #endif /* AVCODEC_JPEGLS_H */
int reset
Definition: jpegls.h:41
int C[365]
Definition: jpegls.h:40
int twonear
Definition: jpegls.h:42
void ff_jpegls_init_state(JLSState *state)
Calculate initial JPEG-LS parameters.
Definition: jpegls.c:30
uint8_t
#define B
Definition: huffyuv.h:49
static int ff_jpegls_update_state_regular(JLSState *state, int Q, int err)
Definition: jpegls.h:98
int B[367]
Definition: jpegls.h:40
#define FFMAX(a, b)
Definition: common.h:55
const uint8_t ff_log2_run[32]
Definition: bitstream.c:36
#define FFMIN(a, b)
Definition: common.h:57
#define FFABS(a)
Definition: common.h:52
Libavcodec external API header.
AVCodecContext * avctx
Definition: jpegls.h:35
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all)
Calculate JPEG-LS codec values.
Definition: jpegls.c:63
main external API structure.
Definition: avcodec.h:1050
int A[367]
Definition: jpegls.h:40
int N[367]
Definition: jpegls.h:40
Definition: vf_drawbox.c:37
static uint32_t state
Definition: trasher.c:27
common internal and external API header
static int ff_jpegls_quantize(JLSState *s, int v)
Calculate quantized gradient value, used for context determination.
Definition: jpegls.h:56
int T3
Definition: jpegls.h:39
static void ff_jpegls_downscale_state(JLSState *state, int Q)
Definition: jpegls.h:88