Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mathis Rosenhauer
libaec
Commits
cb37f682
Commit
cb37f682
authored
Aug 24, 2012
by
Mathis Rosenhauer
Browse files
szip compatibility mode allows unpacking with szip
parent
647a83fc
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/aed.c
View file @
cb37f682
...
...
@@ -522,7 +522,6 @@ int ae_decode(ae_streamp strm, int flush)
zero_blocks
--
;
}
if
(
state
->
ref
)
state
->
i
=
zero_blocks
*
strm
->
block_size
-
1
;
else
...
...
src/aee.c
View file @
cb37f682
...
...
@@ -22,7 +22,6 @@
#define ROS -1
#define MIN(a, b) (((a) < (b))? (a): (b))
#define MAX(a, b) (((a) > (b))? (a): (b))
static
int
m_get_block
(
ae_streamp
strm
);
static
int
m_get_block_cautious
(
ae_streamp
strm
);
...
...
@@ -94,9 +93,9 @@ static inline void preprocess(ae_streamp strm)
int64_t
theta
,
d
,
Delta
;
encode_state
*
state
=
strm
->
state
;
/* I
f this is the
first block
between r
eference
samples then we need to insert one
.
*/
/* I
nsert reference samples into
first block
of R
eference
Sample
* Interval
.
*/
if
(
state
->
in_total_blocks
%
strm
->
rsi
==
0
)
{
state
->
ref
=
1
;
...
...
@@ -187,6 +186,7 @@ static int m_get_block(ae_streamp strm)
static
int
m_get_block_cautious
(
ae_streamp
strm
)
{
int
pad
;
encode_state
*
state
=
strm
->
state
;
do
...
...
@@ -197,8 +197,9 @@ static int m_get_block_cautious(ae_streamp strm)
{
if
(
state
->
i
>
0
)
{
/* pad block with last sample if we have
a partial block */
/* Pad block with last sample if we have a partial
* block.
*/
state
->
in_block
[
state
->
i
]
=
state
->
in_block
[
state
->
i
-
1
];
}
else
...
...
@@ -209,15 +210,30 @@ static int m_get_block_cautious(ae_streamp strm)
state
->
mode
=
m_encode_zero
;
return
M_CONTINUE
;
}
/* Pad last output byte with 0 bits
if user wants to flush, i.e. we got
all input there is.
*/
if
((
strm
->
flags
&
AE_DATA_SZ_COMPAT
)
&&
(
state
->
in_total_blocks
%
strm
->
rsi
!=
0
))
{
/* If user wants szip copatibility then we
* have to pad until but not including the
* next reference sample.
*/
pad
=
64
-
(
state
->
in_total_blocks
%
strm
->
rsi
%
64
);
state
->
in_total_blocks
+=
pad
;
state
->
zero_blocks
=
(
pad
>
4
)
?
ROS
:
pad
;
state
->
mode
=
m_encode_zero
;
return
M_CONTINUE
;
}
/* Pad last output byte with 0 bits if user wants
* to flush, i.e. we got all input there is.
*/
emit
(
state
,
0
,
state
->
bitp
);
if
(
state
->
out_direct
==
0
)
*
strm
->
next_out
++
=
*
state
->
out_bp
;
strm
->
avail_out
--
;
strm
->
total_out
++
;
return
M_EXIT
;
}
}
...
...
@@ -272,10 +288,10 @@ static inline int m_check_zero_block(ae_streamp strm)
}
else
if
(
state
->
zero_blocks
)
{
/* The current block isn't zero but we have to
emit a previous
zero block first. The
current block will be handled
later.
*/
/* The current block isn't zero but we have to
emit a previous
*
zero block first. The
current block will be handled
*
later.
*/
state
->
block_deferred
=
1
;
state
->
mode
=
m_encode_zero
;
return
M_CONTINUE
;
...
...
@@ -299,8 +315,9 @@ static inline int m_select_code_option(ae_streamp strm)
direction
=
1
;
looked_bothways
=
0
;
/* Starting with splitting position of last block look left
and possibly right to find new minimum.*/
/* Starting with splitting position of last block look left and
* possibly right to find new minimum.
*/
for
(;;)
{
fs_len
=
(
state
->
in_block
[
1
]
>>
i
)
...
...
@@ -331,7 +348,8 @@ static inline int m_select_code_option(ae_streamp strm)
if
(
split_len_min
<
INT64_MAX
)
{
/* We are moving towards the minimum so it cant be in
the other direction.*/
* the other direction.
*/
looked_bothways
=
1
;
}
split_len_min
=
split_len
;
...
...
@@ -342,9 +360,10 @@ static inline int m_select_code_option(ae_streamp strm)
if
(
fs_len
<
this_bs
)
{
/* Next can't get better because what we lose by
additional uncompressed bits isn't compensated by a
smaller FS part. Vice versa if we are coming from
the other direction.*/
* additional uncompressed bits isn't compensated
* by a smaller FS part. Vice versa if we are
* coming from the other direction.
*/
if
(
looked_bothways
)
{
break
;
...
...
@@ -368,14 +387,16 @@ static inline int m_select_code_option(ae_streamp strm)
else
if
(
fs_len
>
this_bs
)
{
/* Since we started looking the other way there is no
need to turn back.*/
* need to turn back.
*/
break
;
}
}
else
{
/* Stop looking for better option if we
don't see any improvement. */
/* Stop looking for better option if we don't see any
* improvement.
*/
if
(
looked_bothways
)
{
break
;
...
...
@@ -644,7 +665,6 @@ int ae_encode_init(ae_streamp strm)
/* Largest possible block according to specs */
state
->
out_blklen
=
(
5
+
16
*
32
)
/
8
+
3
;
/* Output buffer */
state
->
out_block
=
(
uint8_t
*
)
malloc
(
state
->
out_blklen
);
if
(
state
->
out_block
==
NULL
)
{
...
...
src/aee.h
View file @
cb37f682
...
...
@@ -35,10 +35,7 @@ typedef struct internal_state {
int64_t
zero_ref_sample
;
/* reference sample of zero block */
int
zero_blocks
;
/* number of contiguous zero blocks */
int
k
;
/* splitting position */
int
flush
;
#ifdef PROFILE
int
*
prof
;
#endif
int
flush
;
/* flush option copied from argument */
}
encode_state
;
#endif
src/libae.h
View file @
cb37f682
...
...
@@ -30,12 +30,15 @@ typedef struct _ae_stream
typedef
ae_stream
*
ae_streamp
;
/* Coder flags */
#define AE_DATA_UNSIGNED 0
#define AE_DATA_SIGNED 1
#define AE_DATA_LSB 8
#define AE_DATA_MSB 16
#define AE_DATA_PREPROCESS 32
/* Set if preprocessor should be used */
#define AE_DATA_UNSIGNED 0
#define AE_DATA_SIGNED 1
#define AE_DATA_LSB 8
#define AE_DATA_MSB 16
#define AE_DATA_PREPROCESS 32
/* Set if preprocessor should be used */
#define AE_DATA_SZ_COMPAT 256
/* Set this if you want szip to decode
* our output. Increases output
* slightly.
*/
/* Return codes of library functions */
#define AE_OK 0
...
...
@@ -49,7 +52,8 @@ typedef ae_stream *ae_streamp;
#define AE_NO_FLUSH 0
/* Do not enforce output flushing. More
* input may be provided with later
* calls. So far only relevant for
* encoding. */
* encoding.
*/
#define AE_FLUSH 1
/* Flush output and end encoding. The last
* call to ae_encode() must set AE_FLUSH to
* drain all output.
...
...
@@ -57,7 +61,8 @@ typedef ae_stream *ae_streamp;
* It is not possible to continue encoding
* of the same stream after it has been
* flushed because the last byte may be
* padded with fill bits. */
* padded with fill bits.
*/
int
ae_decode_init
(
ae_streamp
strm
);
int
ae_decode
(
ae_streamp
strm
,
int
flush
);
...
...
src/sz_compat.c
View file @
cb37f682
#include <stdio.h>
#include <stddef.h>
#include "szlib.h"
...
...
@@ -9,7 +10,7 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, const void *source, size_
strm
.
bit_per_sample
=
param
->
bits_per_pixel
;
strm
.
block_size
=
param
->
pixels_per_block
;
strm
.
rsi
=
param
->
pixels_per_scanline
/
param
->
pixels_per_block
;
strm
.
flags
=
param
->
options_mask
;
strm
.
flags
=
param
->
options_mask
|
AE_DATA_SZ_COMPAT
;
strm
.
avail_in
=
sourceLen
;
strm
.
avail_out
=
*
destLen
;
strm
.
next_out
=
dest
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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