summaryrefslogtreecommitdiffstats
path: root/src/H5Zshuffle.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2002-11-20 13:15:18 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2002-11-20 13:15:18 (GMT)
commitac48a23e2b72b03d60d4fdf10957ed31beb5b70d (patch)
treeffa3319c694f416086419118f3fc3bc3b1e6fca1 /src/H5Zshuffle.c
parent892cc41777c9a104e49ad6d9bac21f085dba6b95 (diff)
downloadhdf5-ac48a23e2b72b03d60d4fdf10957ed31beb5b70d.zip
hdf5-ac48a23e2b72b03d60d4fdf10957ed31beb5b70d.tar.gz
hdf5-ac48a23e2b72b03d60d4fdf10957ed31beb5b70d.tar.bz2
[svn-r6114] Purpose:
Code Cleanup & New Feature Description: H5config.h.in: Removed H5_HAVE_COMPRESSION & H5_HAVE_FILTER_GZIP flags. Added H5_HAVE_FILTER_DEFLATE flag. H5Z.c: H5Zprivate.h: H5Zpublic.h: Switched from using H5_HAVE_COMPRESSION flag in favor of H5_HAVE_FILTER_DEFLATE. Added H5Zunregister & H5Zfilter_avail API functions. Changed a numeric constant (256) to a symbolic constant (H5Z_FILTER_RESERVED). Automatically add the shuffling filter to the list of available filters (when it is enabled). Moved prototypes for H5Z_filter_deflate & H5Z_filter_shuffle from the public header into the private header. H5Zdeflate.c: Switched from using H5_HAVE_COMPRESSION & H5_HAVE_FILTER_GZIP flags in favor of H5_HAVE_FILTER_DEFLATE. Cleaned up formatting & error reporting a bit. H5Zshuffle.c: Rewrote shuffling algorithm to be more efficient. Added error checking & reporting. Added standard Pablo information. Added standard function header comment. Added FUNC_ENTER & FUNC_LEAVE macros. Platforms tested: Tested h5committest {arabica (fortran), eirene (fortran, C++) modi4 (parallel, fortran)} FreeBSD 4.7 (sleipnir)
Diffstat (limited to 'src/H5Zshuffle.c')
-rw-r--r--src/H5Zshuffle.c153
1 files changed, 93 insertions, 60 deletions
diff --git a/src/H5Zshuffle.c b/src/H5Zshuffle.c
index 61dcc4f..ffd676f 100644
--- a/src/H5Zshuffle.c
+++ b/src/H5Zshuffle.c
@@ -9,73 +9,106 @@
#include "H5Eprivate.h"
#include "H5MMprivate.h"
#include "H5Zprivate.h"
-#include <stdio.h>
#ifdef H5_HAVE_FILTER_SHUFFLE
-size_t H5Z_filter_shuffle(unsigned flags,
- size_t cd_nelmts,
- const unsigned cd_values[],
- size_t nbytes,
- size_t *buf_size,void **buf) {
-
- size_t i;
- size_t j;
- size_t k;
- size_t ret_value = 0;
- size_t byte_pos;
- size_t bytesoftype;
- void* dest = NULL;
- char* _src;
- char* _des;
- char* _dest;
- size_t numofelements;
-
- bytesoftype=cd_values[0];
- numofelements=nbytes/bytesoftype;
- _src =(char*)(*buf);
+/* Interface initialization */
+#define PABLO_MASK H5Z_shuffle_mask
+#define INTERFACE_INIT NULL
+static int interface_initialize_g = 0;
- dest = malloc((size_t)nbytes);
- _dest =(char*)dest;
+
+/*-------------------------------------------------------------------------
+ * Function: H5Z_filter_shuffle
+ *
+ * Purpose: Implement an I/O filter which "de-interlaces" a block of data
+ * by putting all the bytes in a byte-position for each element
+ * together in the block. For example, for 4-byte elements stored
+ * as: 012301230123, shuffling will store them as: 000111222333
+ * Usually, the bytes in each byte position are more related to
+ * each other and putting them together will increase compression.
+ *
+ * Return: Success:
+ *
+ * Failure:
+ *
+ * Programmer: Kent Yang
+ * Wednesday, November 13, 2002
+ *
+ * Modifications:
+ * Quincey Koziol, November 13, 2002
+ * Cleaned up code.
+ *
+ *-------------------------------------------------------------------------
+ */
+size_t
+H5Z_filter_shuffle(unsigned flags, size_t cd_nelmts,
+ const unsigned cd_values[], size_t nbytes,
+ size_t *buf_size, void **buf)
+{
+ void *dest = NULL; /* Buffer to deposit [un]shuffled bytes into */
+ unsigned char *_src; /* Alias for source buffer */
+ unsigned char *_dest; /* Alias for destination buffer */
+ unsigned bytesoftype; /* Number of bytes per element */
+ size_t numofelements; /* Number of elements in buffer */
+ size_t i,j; /* Local index variables */
+ size_t ret_value; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5Z_filter_shuffle, 0);
+
+ /* Check arguments */
+ if (cd_nelmts!=1 || cd_values[0]==0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid shuffle parameters");
+
+ /* Get the number of bytes per element from the parameter block */
+ bytesoftype=cd_values[0];
+
+ /* Don't do anything for 1-byte elements */
+ if(bytesoftype>1) {
+ /* Compute the number of elements in buffer */
+ numofelements=nbytes/bytesoftype;
+
+ /* Allocate the destination buffer */
+ if (NULL==(dest = H5MM_malloc(nbytes)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for shuffle buffer");
+
+ if(flags & H5Z_FLAG_REVERSE) {
+ /* Get the pointer to the source buffer */
+ _src =(unsigned char *)(*buf);
+
+ /* Input; unshuffle */
+ for(i=0; i<bytesoftype; i++) {
+ _dest=((unsigned char *)dest)+i;
+ for(j=0; j<numofelements; j++) {
+ *_dest=*_src++;
+ _dest+=bytesoftype;
+ } /* end for */
+ } /* end for */
+ } /* end if */
+ else {
+ /* Get the pointer to the destination buffer */
+ _dest =(unsigned char *)dest;
- j = 0;
- k = 0;
- if(flags & H5Z_FLAG_REVERSE) {
- for(i=0;i<nbytes;i++) {
- byte_pos = 1 +j *numofelements;
- if(byte_pos > nbytes) {
- k++;
- j=0;
- byte_pos=1;
- }
- *(_dest+i)=*((char*)(_src+byte_pos-1+k));
- j++;
- }
- free(*buf);
- *buf = dest;
- dest = NULL;
- *buf_size=nbytes;
- ret_value = nbytes;
- }
+ /* Output; shuffle */
+ for(i=0; i<bytesoftype; i++) {
+ _src=((unsigned char *)(*buf))+i;
+ for(j=0; j<numofelements; j++) {
+ *_dest++=*_src;
+ _src+=bytesoftype;
+ } /* end for */
+ } /* end for */
+ } /* end else */
- else {
- for (i=0;i<nbytes;i++){
- byte_pos = 1+j * bytesoftype;
- if(byte_pos >nbytes) {
- k++;
- j=0;
- byte_pos = 1;
- }
+ /* Set the buffer information to return */
+ H5MM_xfree(*buf);
+ *buf = dest;
+ *buf_size=nbytes;
+ } /* end else */
- *(_dest+i)=*(_src+byte_pos-1+k);
- j++;
- }
- free(*buf);
- *buf = dest;
- dest = NULL;
- *buf_size=nbytes;
- ret_value = nbytes;
- }
+ /* Set the return value */
+ ret_value = nbytes;
+done:
+ FUNC_LEAVE (ret_value);
}
#endif /*H5_HAVE_FILTER_SHUFFLE */