Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mathis Rosenhauer
libaec
Commits
0c6860cf
Commit
0c6860cf
authored
Nov 13, 2012
by
Mathis Rosenhauer
Committed by
Thomas Jahns
Feb 19, 2013
Browse files
less pathetic FS getter
parent
254c9a6e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/decode.c
View file @
0c6860cf
/* Adaptive Entropy Decoder */
/**
/* CCSDS 121.0-B-1 and CCSDS 120.0-G-2 */
* @file decode.c
* @author Mathis Rosenhauer, Deutsches Klimarechenzentrum
* @section DESCRIPTION
*
* Adaptive Entropy Decoder
* Based on CCSDS documents 121.0-B-2 and 120.0-G-2
*
*/
#include
<config.h>
#include
<config.h>
...
@@ -30,7 +37,7 @@
...
@@ -30,7 +37,7 @@
if (strm->flags & AEC_DATA_SIGNED) { \
if (strm->flags & AEC_DATA_SIGNED) { \
m = 1ULL << (strm->bit_per_sample - 1); \
m = 1ULL << (strm->bit_per_sample - 1); \
/* Reference samples have to be sign extended */
\
/* Reference samples have to be sign extended */
\
state->last_out = (
state->last_out ^ m) - m; \
state->last_out = (state->last_out ^ m) - m;
\
} \
} \
\
\
data = state->last_out; \
data = state->last_out; \
...
@@ -138,7 +145,7 @@ static void put_sample(struct aec_stream *strm, uint32_t s)
...
@@ -138,7 +145,7 @@ static void put_sample(struct aec_stream *strm, uint32_t s)
}
}
}
}
static
int64_t
u
_get
(
struct
aec_stream
*
strm
,
unsigned
int
n
)
static
int64_t
direct
_get
(
struct
aec_stream
*
strm
,
unsigned
int
n
)
{
{
/**
/**
Get n bit from input stream
Get n bit from input stream
...
@@ -154,23 +161,39 @@ static int64_t u_get(struct aec_stream *strm, unsigned int n)
...
@@ -154,23 +161,39 @@ static int64_t u_get(struct aec_stream *strm, unsigned int n)
state
->
acc
=
(
state
->
acc
<<
8
)
|
*
strm
->
next_in
++
;
state
->
acc
=
(
state
->
acc
<<
8
)
|
*
strm
->
next_in
++
;
state
->
bitp
+=
8
;
state
->
bitp
+=
8
;
}
}
state
->
bitp
-=
n
;
state
->
bitp
-=
n
;
return
(
state
->
acc
>>
state
->
bitp
)
&
((
1ULL
<<
n
)
-
1
);
return
(
state
->
acc
>>
state
->
bitp
)
&
((
1ULL
<<
n
)
-
1
);
}
}
static
int64_t
u
_get_fs
(
struct
aec_stream
*
strm
)
static
int64_t
direct
_get_fs
(
struct
aec_stream
*
strm
)
{
{
/**
/**
Interpret a Fundamental Sequence from the input buffer.
Interpret a Fundamental Sequence from the input buffer.
Essentially counts the number of 0 bits until a
Essentially counts the number of 0 bits until a 1 is
1 is encountered. TODO: faster version.
encountered. The longest FS we can safely detect is 56 bits. If
no FS is found in accumulator then we top it up to at least 56
bits.
*/
*/
struct
internal_state
*
state
=
strm
->
state
;
int64_t
fs
=
0
;
int64_t
fs
=
0
;
while
(
u_get
(
strm
,
1
)
==
0
)
if
((
state
->
acc
&
((
1ULL
<<
state
->
bitp
)
-
1
))
==
0
)
while
(
state
->
bitp
<
56
)
{
strm
->
avail_in
--
;
strm
->
total_in
++
;
state
->
acc
=
(
state
->
acc
<<
8
)
|
*
strm
->
next_in
++
;
state
->
bitp
+=
8
;
}
state
->
bitp
--
;
while
((
state
->
acc
&
(
1ULL
<<
state
->
bitp
))
==
0
)
{
state
->
bitp
--
;
fs
++
;
fs
++
;
}
return
fs
;
return
fs
;
}
}
...
@@ -183,15 +206,13 @@ static void fast_split(struct aec_stream *strm)
...
@@ -183,15 +206,13 @@ static void fast_split(struct aec_stream *strm)
k
=
state
->
id
-
1
;
k
=
state
->
id
-
1
;
if
(
state
->
ref
)
if
(
state
->
ref
)
put_sample
(
strm
,
u
_get
(
strm
,
strm
->
bit_per_sample
));
put_sample
(
strm
,
direct
_get
(
strm
,
strm
->
bit_per_sample
));
for
(
i
=
state
->
ref
;
i
<
strm
->
block_size
;
i
++
)
for
(
i
=
state
->
ref
;
i
<
strm
->
block_size
;
i
++
)
state
->
block
[
i
]
=
u
_get_fs
(
strm
)
<<
k
;
state
->
block
[
i
]
=
direct
_get_fs
(
strm
)
<<
k
;
for
(
i
=
state
->
ref
;
i
<
strm
->
block_size
;
i
++
)
{
for
(
i
=
state
->
ref
;
i
<
strm
->
block_size
;
i
++
)
state
->
block
[
i
]
+=
u_get
(
strm
,
k
);
put_sample
(
strm
,
state
->
block
[
i
]
+
direct_get
(
strm
,
k
));
put_sample
(
strm
,
state
->
block
[
i
]);
}
}
}
static
void
fast_zero
(
struct
aec_stream
*
strm
)
static
void
fast_zero
(
struct
aec_stream
*
strm
)
...
@@ -211,7 +232,7 @@ static void fast_se(struct aec_stream *strm)
...
@@ -211,7 +232,7 @@ static void fast_se(struct aec_stream *strm)
i
=
state
->
ref
;
i
=
state
->
ref
;
while
(
i
<
strm
->
block_size
)
{
while
(
i
<
strm
->
block_size
)
{
m
=
u
_get_fs
(
strm
);
m
=
direct
_get_fs
(
strm
);
d1
=
m
-
state
->
se_table
[
2
*
m
+
1
];
d1
=
m
-
state
->
se_table
[
2
*
m
+
1
];
if
((
i
&
1
)
==
0
)
{
if
((
i
&
1
)
==
0
)
{
...
@@ -228,7 +249,7 @@ static void fast_uncomp(struct aec_stream *strm)
...
@@ -228,7 +249,7 @@ static void fast_uncomp(struct aec_stream *strm)
int
i
;
int
i
;
for
(
i
=
0
;
i
<
strm
->
block_size
;
i
++
)
for
(
i
=
0
;
i
<
strm
->
block_size
;
i
++
)
put_sample
(
strm
,
u
_get
(
strm
,
strm
->
bit_per_sample
));
put_sample
(
strm
,
direct
_get
(
strm
,
strm
->
bit_per_sample
));
}
}
static
uint32_t
bits_ask
(
struct
aec_stream
*
strm
,
int
n
)
static
uint32_t
bits_ask
(
struct
aec_stream
*
strm
,
int
n
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment