summaryrefslogtreecommitdiffstats
path: root/src/H5Zszip.c
diff options
context:
space:
mode:
authorMuQun Yang <ymuqun@hdfgroup.org>2003-04-01 15:49:03 (GMT)
committerMuQun Yang <ymuqun@hdfgroup.org>2003-04-01 15:49:03 (GMT)
commit992eb8594458cf8f47a44084065bf9b5fbda1cc3 (patch)
tree08406be2b5041095df0e3347aba7953268f93230 /src/H5Zszip.c
parentf94431ce1f10d796268767121cd85269b7c0f094 (diff)
downloadhdf5-992eb8594458cf8f47a44084065bf9b5fbda1cc3.zip
hdf5-992eb8594458cf8f47a44084065bf9b5fbda1cc3.tar.gz
hdf5-992eb8594458cf8f47a44084065bf9b5fbda1cc3.tar.bz2
[svn-r6552] Purpose:
To support szip compression in HDF5 Description: This is where szip filter function is located. Solution: The filter function composes of "encode" and "decode" part, which is similar as deflate filter. One critical difference is: when szip decompresses the data, it needs to know the buffer size to hold the decompressed data in advance. Currently it's hard for HDF5 lib to give the buffer size easily. So to avoid this problem, in each chunk, we add a small header to hold the buffer size of each chunk. The code will use UINT32 ENCODE and UINT32 DECODE to finish this part of work. Platforms tested: Since there are changes of configure.in and configure,I didn't use h5committest. I tested with four platforms. 1) Linux 2.4 (eirene) 2) Solaris 2.7(arabica) 3) windows 2000(VS 6.0) 4) SGI IRIX6.5-64(modi4) For test 1)-3), only basic C tests were done For modi4 test, I tested 64-bit C,parallel and fortran. All tests passed, except a warning message from szip library when checksum is used in some order, which doesn't e any real problems. Misc. update:
Diffstat (limited to 'src/H5Zszip.c')
-rw-r--r--src/H5Zszip.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/H5Zszip.c b/src/H5Zszip.c
new file mode 100644
index 0000000..0b58b17
--- /dev/null
+++ b/src/H5Zszip.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright © 1999-2001 NCSA
+ * All rights reserved.
+ *
+ * Programmer: Robb Matzke <matzke@llnl.gov>
+ * Friday, August 27, 1999
+ */
+#include "H5private.h"
+#include "H5Eprivate.h"
+#include "H5MMprivate.h"
+#include "H5Zprivate.h"
+
+#ifdef H5_HAVE_FILTER_SZIP
+
+#ifdef H5_HAVE_SZLIB_H
+# include "szlib.h"
+#endif
+
+/* Interface initialization */
+#define PABLO_MASK H5Z_szip_mask
+#define INTERFACE_INIT NULL
+static int interface_initialize_g = 0;
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5Z_filter_szip
+ *
+ * Purpose: Implement an I/O filter around the 'rice' algorithm in
+ * libsz
+ *
+ * Return: Success:
+ *
+ * Failure:
+ *
+ * Programmer: Robb Matzke
+ * Thursday, April 16, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+size_t
+H5Z_filter_szip (unsigned flags,
+ size_t cd_nelmts,
+ const unsigned cd_values[],
+ size_t nbytes,
+ size_t *buf_size,
+ void **buf)
+{
+
+ size_t ret_value = 0;
+ size_t size_out = 0;
+ size_t size_in = 0;
+ char *outbuf = NULL;
+ char *newbuf = NULL;
+ int status;
+ SZ_com_t sz_param;
+
+ sz_param.options_mask = cd_values[0];
+ sz_param.bits_per_pixel = cd_values[1];
+ sz_param.pixels_per_block = cd_values[2];
+ sz_param.pixels_per_scanline = cd_values[3];
+
+ FUNC_ENTER_NOAPI(H5Z_filter_szip, 0);
+
+ if (flags & H5Z_FLAG_REVERSE) {
+ /* Input; uncompress */
+
+ size_t nalloc;
+
+ newbuf = *buf;
+ UINT32DECODE(newbuf,nalloc);
+
+ size_out = nalloc;
+ size_in = nbytes;
+
+ if(NULL==(outbuf = H5MM_malloc(nalloc)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for szip decompression");
+
+ status = SZ_BufftoBuffDecompress(outbuf, &size_out, newbuf, size_in-4, &sz_param);
+
+ if(status != SZ_OK) {
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "szip_filter: decompression failed");
+ }
+
+ *buf = newbuf -4;
+ H5MM_xfree(*buf);
+ *buf = outbuf;
+ outbuf = NULL;
+ *buf_size = nalloc;
+ ret_value = size_out;
+ }
+
+ else {
+
+ size_in = nbytes;
+ size_out = nbytes;
+ if(NULL==(outbuf = H5MM_malloc(size_out+4)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "unable to allocate szip destination buffer");
+
+ UINT32ENCODE(outbuf,nbytes);
+ status = SZ_BufftoBuffCompress(outbuf, &size_out, *buf, size_in, &sz_param);
+ if(SZ_OK!=status)
+ HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, 0, "szip_filter: Compression failed");
+
+ if(*buf) H5MM_xfree(*buf);
+ *buf = outbuf-4;
+ outbuf = NULL;
+ *buf_size = size_out+4;
+ ret_value = size_out+4;
+ }
+
+ done:
+ if(outbuf) H5MM_xfree(outbuf);
+ FUNC_LEAVE_NOAPI(ret_value);
+ }
+
+#endif
+
+
+