summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathis Rosenhauer <rosenhauer@dkrz.de>2014-09-02 16:35:39 +0200
committerMathis Rosenhauer <rosenhauer@dkrz.de>2014-09-02 16:35:39 +0200
commit4de94dc23b45f30f9e8e4e79d233fc6e6f9cca97 (patch)
tree5ce2c17e52cee0d7afe2f89b0b6803c1ec901e45
parentfaf2f2716aa928fbe0f4785769f804f26849b606 (diff)
downloadlibaec-4de94dc23b45f30f9e8e4e79d233fc6e6f9cca97.tar.gz
libaec-4de94dc23b45f30f9e8e4e79d233fc6e6f9cca97.tar.bz2
libaec-4de94dc23b45f30f9e8e4e79d233fc6e6f9cca97.zip
Allow incomplete scanlines in SZ mode.
-rw-r--r--src/sz_compat.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/sz_compat.c b/src/sz_compat.c
index bfbc981..caa8582 100644
--- a/src/sz_compat.c
+++ b/src/sz_compat.c
@@ -8,6 +8,7 @@
#endif
#define NOPTS 129
+#define MIN(a, b) (((a) < (b))? (a): (b))
static int convert_options(int sz_opts)
{
@@ -72,20 +73,24 @@ static void add_padding(void *dest, const void *src, size_t total,
size_t line_size, size_t padding_size,
int pixel_size, int pp)
{
- size_t i, j, k;
+ size_t i, j, k, ls, ps;
const char *pixel;
const char zero_pixel[] = {0, 0, 0, 0};
pixel = zero_pixel;
j = 0;
- for (i = 0; i < total; i += line_size) {
- memcpy((char *)dest + j, (char *)src + i, line_size);
- j += line_size;
+ i = 0;
+ while (i < total) {
+ ls = MIN(total - i, line_size);
+ memcpy((char *)dest + j, (char *)src + i, ls);
+ j += ls;
+ i += ls;
if (pp)
- pixel = (char *)src + i + line_size - pixel_size;
- for (k = 0; k < padding_size; k += pixel_size)
+ pixel = (char *)src + i - pixel_size;
+ ps = line_size + padding_size - ls;
+ for (k = 0; k < ps; k += pixel_size)
memcpy((char *)dest + j + k, pixel, pixel_size);
- j += padding_size;
+ j += ps;
}
}
@@ -146,7 +151,8 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen,
pixel_size = bits_to_bytes(strm.bits_per_sample);
if (pad_scanline) {
- scanlines = sourceLen / param->pixels_per_scanline;
+ scanlines = (sourceLen + param->pixels_per_scanline - 1)
+ / param->pixels_per_scanline;
padbuf_size = strm.rsi * strm.block_size * pixel_size * scanlines;
padbuf = malloc(padbuf_size);
if (padbuf == NULL) {