Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
libavcodec
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 "
avcodec.h
"
32
33
typedef
struct
JpeglsContext
{
34
AVCodecContext
*
avctx
;
35
AVFrame
picture
;
36
}
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
51
void
ff_jpegls_init_state
(
JLSState
*
state
);
52
56
static
inline
int
ff_jpegls_quantize
(
JLSState
*s,
int
v
){
//FIXME optimize
57
if
(v==0)
return
0;
58
if
(v < 0){
59
if
(v <= -s->
T3
)
return
-4;
60
if
(v <= -s->
T2
)
return
-3;
61
if
(v <= -s->
T1
)
return
-2;
62
if
(v < -s->near)
return
-1;
63
return
0;
64
}
else
{
65
if
(v <= s->near)
return
0;
66
if
(v < s->
T1
)
return
1;
67
if
(v < s->
T2
)
return
2;
68
if
(v < s->
T3
)
return
3;
69
return
4;
70
}
71
}
72
76
void
ff_jpegls_reset_coding_parameters
(
JLSState
*s,
int
reset_all);
77
78
79
static
inline
void
ff_jpegls_downscale_state
(
JLSState
*
state
,
int
Q){
80
if
(state->
N
[Q] == state->
reset
){
81
state->
A
[Q] >>=1;
82
state->
B
[Q] >>=1;
83
state->
N
[Q] >>=1;
84
}
85
state->
N
[Q]++;
86
}
87
88
static
inline
int
ff_jpegls_update_state_regular
(
JLSState
*
state
,
int
Q,
int
err){
89
state->
A
[Q] +=
FFABS
(err);
90
err *= state->
twonear
;
91
state->
B
[Q] += err;
92
93
ff_jpegls_downscale_state
(state, Q);
94
95
if
(state->
B
[Q] <= -state->
N
[Q]) {
96
state->
B
[Q]=
FFMAX
(state->
B
[Q] + state->
N
[Q], 1-state->
N
[Q]);
97
if
(state->
C
[Q] > -128)
98
state->
C
[Q]--;
99
}
else
if
(state->
B
[Q] > 0){
100
state->
B
[Q]=
FFMIN
(state->
B
[Q] - state->
N
[Q], 0);
101
if
(state->
C
[Q] < 127)
102
state->
C
[Q]++;
103
}
104
105
return
err;
106
}
107
108
#define R(a, i ) (bits == 8 ? ((uint8_t*)(a))[i] : ((uint16_t*)(a))[i] )
109
#define W(a, i, v) (bits == 8 ? (((uint8_t*)(a))[i]=v) : (((uint16_t*)(a))[i]=v))
110
111
#endif
/* AVCODEC_JPEGLS_H */
JLSState::reset
int reset
Definition:
jpegls.h:41
JLSState::T2
int T2
Definition:
jpegls.h:39
AVFrame
Audio Video Frame.
Definition:
avcodec.h:985
JpeglsContext
Definition:
jpegls.h:33
JLSState::C
int C[365]
Definition:
jpegls.h:40
JLSState::twonear
int twonear
Definition:
jpegls.h:42
JpeglsContext::picture
AVFrame picture
Definition:
jpegls.h:35
JLSState::limit
int limit
Definition:
jpegls.h:41
ff_jpegls_init_state
void ff_jpegls_init_state(JLSState *state)
Calculate initial JPEG-LS parameters.
Definition:
jpegls.c:30
v
#define v(n)
Definition:
regs.h:34
JLSState::bpp
int bpp
Definition:
jpegls.h:41
JLSState
Definition:
jpegls.h:38
JLSState::maxval
int maxval
Definition:
jpegls.h:41
T3
#define T3
T1
#define T1
JLSState::run_index
int run_index[3]
Definition:
jpegls.h:43
ff_jpegls_update_state_regular
static int ff_jpegls_update_state_regular(JLSState *state, int Q, int err)
Definition:
jpegls.h:88
JLSState::B
int B[367]
Definition:
jpegls.h:40
FFMAX
#define FFMAX(a, b)
Definition:
common.h:53
JLSState::near
int near
Definition:
jpegls.h:42
ff_log2_run
const uint8_t ff_log2_run[32]
Definition:
bitstream.c:35
FFMIN
#define FFMIN(a, b)
Definition:
common.h:55
FFABS
#define FFABS(a)
Definition:
common.h:50
JLSState::qbpp
int qbpp
Definition:
jpegls.h:41
avcodec.h
external API header
JpeglsContext::avctx
AVCodecContext * avctx
Definition:
jpegls.h:34
ff_jpegls_reset_coding_parameters
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all)
Calculate JPEG-LS codec values.
Definition:
jpegls.c:59
AVCodecContext
main external API structure.
Definition:
avcodec.h:1329
JLSState::A
int A[367]
Definition:
jpegls.h:40
T2
#define T2
JLSState::T1
int T1
Definition:
jpegls.h:39
JLSState::range
int range
Definition:
jpegls.h:41
JLSState::N
int N[367]
Definition:
jpegls.h:40
state
static uint32_t state
Definition:
trasher.c:25
ff_jpegls_quantize
static int ff_jpegls_quantize(JLSState *s, int v)
Calculate quantized gradient value, used for context determination.
Definition:
jpegls.h:56
JLSState
struct JLSState JLSState
JLSState::T3
int T3
Definition:
jpegls.h:39
ff_jpegls_downscale_state
static void ff_jpegls_downscale_state(JLSState *state, int Q)
Definition:
jpegls.h:79
JpeglsContext
struct JpeglsContext JpeglsContext