summaryrefslogtreecommitdiff
path: root/src/sz_compat.c
diff options
context:
space:
mode:
authorMathis Rosenhauer <rosenhauer@dkrz.de>2012-11-12 17:04:48 +0100
committerThomas Jahns <jahns@dkrz.de>2013-02-19 11:33:00 +0100
commit4f9895014e589422d4efad2af8e4f5f70a9a4a00 (patch)
treee44657fd6ab7c8845296cea21985ecc2c9113d33 /src/sz_compat.c
parent51bf26530fb205a4ced83a38854378d9ca8fb2b3 (diff)
downloadlibaec-4f9895014e589422d4efad2af8e4f5f70a9a4a00.tar.gz
libaec-4f9895014e589422d4efad2af8e4f5f70a9a4a00.tar.bz2
libaec-4f9895014e589422d4efad2af8e4f5f70a9a4a00.zip
Interleaving for 32 and 64 bit in sz compatibility
Diffstat (limited to 'src/sz_compat.c')
-rw-r--r--src/sz_compat.c65
1 files changed, 60 insertions, 5 deletions
diff --git a/src/sz_compat.c b/src/sz_compat.c
index b61818a..095aa13 100644
--- a/src/sz_compat.c
+++ b/src/sz_compat.c
@@ -1,5 +1,7 @@
#include <stdio.h>
#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
#include "szlib.h"
#include "libaec.h"
@@ -21,26 +23,62 @@ static int convert_options(int sz_opts)
return opts;
}
+static void interleave_buffer(unsigned char *dest, unsigned char *src,
+ size_t n, int wordsize)
+{
+ size_t i, j;
+
+ for (i = 0; i < n / wordsize; i++)
+ for (j = 0; j < wordsize; j++)
+ dest[j * (n / wordsize) + i] = src[i * wordsize + j];
+}
+
+static void deinterleave_buffer(unsigned char *dest, unsigned char *src,
+ size_t n, int wordsize)
+{
+ size_t i, j;
+
+ for (i = 0; i < n / wordsize; i++)
+ for (j = 0; j < wordsize; j++)
+ dest[i * wordsize + j] = src[j * (n / wordsize) + i];
+}
+
int SZ_BufftoBuffCompress(void *dest, size_t *destLen,
const void *source, size_t sourceLen,
SZ_com_t *param)
{
int status;
struct aec_stream strm;
+ unsigned char *buf;
+
+ if (param->bits_per_pixel == 32 || param->bits_per_pixel == 64) {
+ buf = (unsigned char *)malloc(sourceLen);
+ if (buf == NULL)
+ return SZ_MEM_ERROR;
+
+ interleave_buffer(buf, source, sourceLen, param->bits_per_pixel / 8);
+ strm.bit_per_sample = 8;
+ strm.next_in = buf;
+ } else {
+ strm.next_in = source;
+ strm.bit_per_sample = param->bits_per_pixel;
+ }
- strm.bit_per_sample = param->bits_per_pixel;
+ strm.avail_in = sourceLen;
strm.block_size = param->pixels_per_block;
strm.rsi = param->pixels_per_scanline / param->pixels_per_block;
strm.flags = convert_options(param->options_mask);
- strm.avail_in = sourceLen;
strm.avail_out = *destLen;
strm.next_out = dest;
- strm.next_in = source;
status = aec_buffer_encode(&strm);
if (status != AEC_OK)
return status;
+ if (param->bits_per_pixel == 32 || param->bits_per_pixel == 64) {
+ free(buf);
+ }
+
*destLen = strm.total_out;
return SZ_OK;
}
@@ -51,14 +89,25 @@ int SZ_BufftoBuffDecompress(void *dest, size_t *destLen,
{
int status;
struct aec_stream strm;
+ unsigned char *buf;
+
+ if (param->bits_per_pixel == 32 || param->bits_per_pixel == 64) {
+ buf = (unsigned char *)malloc(*destLen);
+ if (buf == NULL)
+ return SZ_MEM_ERROR;
+
+ strm.bit_per_sample = 8;
+ strm.next_out = buf;
+ } else {
+ strm.next_out = dest;
+ strm.bit_per_sample = param->bits_per_pixel;
+ }
- 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 = convert_options(param->options_mask);
strm.avail_in = sourceLen;
strm.avail_out = *destLen;
- strm.next_out = dest;
strm.next_in = source;
status = aec_buffer_decode(&strm);
@@ -66,6 +115,12 @@ int SZ_BufftoBuffDecompress(void *dest, size_t *destLen,
return status;
*destLen = strm.total_out;
+
+ if (param->bits_per_pixel == 32 || param->bits_per_pixel == 64) {
+ deinterleave_buffer(dest, buf, *destLen, param->bits_per_pixel / 8);
+ free(buf);
+ }
+
return SZ_OK;
}