Commit 3827bf39 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

Always pad buffer

parent 11ca2a7f
...@@ -69,7 +69,7 @@ static void deinterleave_buffer(void *dest, const void *src, ...@@ -69,7 +69,7 @@ static void deinterleave_buffer(void *dest, const void *src,
dest8[i * wordsize + j] = src8[j * (n / wordsize) + i]; dest8[i * wordsize + j] = src8[j * (n / wordsize) + i];
} }
static void add_padding(void *dest, const void *src, size_t total, static void add_padding(void *dest, const void *src, size_t src_length,
size_t line_size, size_t padding_size, size_t line_size, size_t padding_size,
int pixel_size, int pp) int pixel_size, int pp)
{ {
...@@ -80,8 +80,8 @@ static void add_padding(void *dest, const void *src, size_t total, ...@@ -80,8 +80,8 @@ static void add_padding(void *dest, const void *src, size_t total,
pixel = zero_pixel; pixel = zero_pixel;
j = 0; j = 0;
i = 0; i = 0;
while (i < total) { while (i < src_length) {
ls = MIN(total - i, line_size); ls = MIN(src_length - i, line_size);
memcpy((char *)dest + j, (char *)src + i, ls); memcpy((char *)dest + j, (char *)src + i, ls);
j += ls; j += ls;
i += ls; i += ls;
...@@ -94,7 +94,7 @@ static void add_padding(void *dest, const void *src, size_t total, ...@@ -94,7 +94,7 @@ static void add_padding(void *dest, const void *src, size_t total,
} }
} }
static void remove_padding(void *buf, size_t total, static void remove_padding(void *buf, size_t buf_length,
size_t line_size, size_t padding_size, size_t line_size, size_t padding_size,
int pixel_size) int pixel_size)
{ {
...@@ -102,7 +102,7 @@ static void remove_padding(void *buf, size_t total, ...@@ -102,7 +102,7 @@ static void remove_padding(void *buf, size_t total,
size_t padded_line_size = line_size + padding_size; size_t padded_line_size = line_size + padding_size;
i = line_size; i = line_size;
for (j = padded_line_size; j < total; j += padded_line_size) { for (j = padded_line_size; j < buf_length; j += padded_line_size) {
memmove((char *)buf + i, (char *)buf + j, line_size); memmove((char *)buf + i, (char *)buf + j, line_size);
i += line_size; i += line_size;
} }
...@@ -121,7 +121,6 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, ...@@ -121,7 +121,6 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen,
size_t scanlines; size_t scanlines;
size_t padbuf_size; size_t padbuf_size;
int pixel_size; int pixel_size;
int pad_scanline;
int interleave; int interleave;
strm.block_size = param->pixels_per_block; strm.block_size = param->pixels_per_block;
...@@ -134,7 +133,6 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, ...@@ -134,7 +133,6 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen,
padbuf = 0; padbuf = 0;
interleave = param->bits_per_pixel == 32 || param->bits_per_pixel == 64; interleave = param->bits_per_pixel == 32 || param->bits_per_pixel == 64;
pad_scanline = param->pixels_per_scanline % param->pixels_per_block;
if (interleave) { if (interleave) {
strm.bits_per_sample = 8; strm.bits_per_sample = 8;
buf = malloc(sourceLen); buf = malloc(sourceLen);
...@@ -150,30 +148,25 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, ...@@ -150,30 +148,25 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen,
pixel_size = bits_to_bytes(strm.bits_per_sample); pixel_size = bits_to_bytes(strm.bits_per_sample);
if (pad_scanline) { scanlines = (sourceLen / pixel_size + param->pixels_per_scanline - 1)
scanlines = (sourceLen / pixel_size + param->pixels_per_scanline - 1) / param->pixels_per_scanline;
/ param->pixels_per_scanline; padbuf_size = strm.rsi * strm.block_size * pixel_size * scanlines;
padbuf_size = strm.rsi * strm.block_size * pixel_size * scanlines; padbuf = malloc(padbuf_size);
padbuf = malloc(padbuf_size); if (padbuf == NULL) {
if (padbuf == NULL) { status = SZ_MEM_ERROR;
status = SZ_MEM_ERROR; goto CLEANUP;
goto CLEANUP; }
}
padding_size = padding_size =
(strm.rsi * strm.block_size - param->pixels_per_scanline) (strm.rsi * strm.block_size - param->pixels_per_scanline)
* pixel_size; * pixel_size;
add_padding(padbuf, buf, sourceLen, add_padding(padbuf, buf, sourceLen,
param->pixels_per_scanline * pixel_size, param->pixels_per_scanline * pixel_size,
padding_size, pixel_size, padding_size, pixel_size,
strm.flags & AEC_DATA_PREPROCESS); strm.flags & AEC_DATA_PREPROCESS);
strm.next_in = padbuf; strm.next_in = padbuf;
strm.avail_in = padbuf_size; strm.avail_in = padbuf_size;
} else {
strm.next_in = buf;
strm.avail_in = sourceLen;
}
aec_status = aec_buffer_encode(&strm); aec_status = aec_buffer_encode(&strm);
if (aec_status == AEC_STREAM_ERROR) if (aec_status == AEC_STREAM_ERROR)
...@@ -183,7 +176,7 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, ...@@ -183,7 +176,7 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen,
*destLen = strm.total_out; *destLen = strm.total_out;
CLEANUP: CLEANUP:
if (pad_scanline && padbuf) if (padbuf)
free(padbuf); free(padbuf);
if (interleave && buf) if (interleave && buf)
free(buf); free(buf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment