diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2002-11-20 13:15:18 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2002-11-20 13:15:18 (GMT) |
commit | ac48a23e2b72b03d60d4fdf10957ed31beb5b70d (patch) | |
tree | ffa3319c694f416086419118f3fc3bc3b1e6fca1 /src/H5Zdeflate.c | |
parent | 892cc41777c9a104e49ad6d9bac21f085dba6b95 (diff) | |
download | hdf5-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/H5Zdeflate.c')
-rw-r--r-- | src/H5Zdeflate.c | 55 |
1 files changed, 15 insertions, 40 deletions
diff --git a/src/H5Zdeflate.c b/src/H5Zdeflate.c index b66012d..09cd7a0 100644 --- a/src/H5Zdeflate.c +++ b/src/H5Zdeflate.c @@ -10,13 +10,10 @@ #include "H5MMprivate.h" #include "H5Zprivate.h" -#ifdef H5_HAVE_FILTER_GZIP +#ifdef H5_HAVE_FILTER_DEFLATE #ifdef H5_HAVE_ZLIB_H # include "zlib.h" -#else -/* Make sure compression is disabled too. */ -#undef H5_HAVE_COMPRESSION #endif /* Interface initialization */ @@ -28,7 +25,8 @@ static int interface_initialize_g = 0; /*------------------------------------------------------------------------- * Function: H5Z_filter_deflate * - * Purpose: + * Purpose: Implement an I/O filter around the 'deflate' algorithm in + * libz * * Return: Success: * @@ -42,53 +40,40 @@ static int interface_initialize_g = 0; *------------------------------------------------------------------------- */ size_t -#if defined(H5_HAVE_COMPRESSION) H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, const unsigned cd_values[], size_t nbytes, size_t *buf_size, void **buf) -#else -H5Z_filter_deflate (unsigned UNUSED flags, size_t cd_nelmts, - const unsigned cd_values[], size_t UNUSED nbytes, - size_t * UNUSED buf_size, void ** UNUSED buf) -#endif { size_t ret_value = 0; void *outbuf = NULL; -#if defined(H5_HAVE_COMPRESSION) int aggression = 6; int status; -#endif FUNC_ENTER_NOAPI(H5Z_filter_deflate, 0); /* Check arguments */ - if (cd_nelmts!=1 || cd_values[0]>9) { - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, - "invalid deflate aggression level"); - } + if (cd_nelmts!=1 || cd_values[0]>9) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid deflate aggression level"); -#if defined(H5_HAVE_COMPRESSION) aggression = cd_values[0]; if (flags & H5Z_FLAG_REVERSE) { /* Input; uncompress */ z_stream z_strm; size_t nalloc = *buf_size; - if (NULL==(outbuf = H5MM_malloc(nalloc))) { - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, - "memory allocation failed for deflate uncompression"); - } + if (NULL==(outbuf = H5MM_malloc(nalloc))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for deflate uncompression"); HDmemset(&z_strm, 0, sizeof(z_strm)); z_strm.next_in = *buf; H5_ASSIGN_OVERFLOW(z_strm.avail_in,nbytes,size_t,uInt); z_strm.next_out = outbuf; H5_ASSIGN_OVERFLOW(z_strm.avail_out,nalloc,size_t,uInt); - if (Z_OK!=inflateInit(&z_strm)) { + if (Z_OK!=inflateInit(&z_strm)) HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "inflateInit() failed"); - } while (1) { status = inflate(&z_strm, Z_SYNC_FLUSH); - if (Z_STREAM_END==status) break; /*done*/ + if (Z_STREAM_END==status) + break; /*done*/ if (Z_OK!=status) { inflateEnd(&z_strm); HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "inflate() failed"); @@ -97,9 +82,7 @@ H5Z_filter_deflate (unsigned UNUSED flags, size_t cd_nelmts, nalloc *= 2; if (NULL==(outbuf = H5MM_realloc(outbuf, nalloc))) { inflateEnd(&z_strm); - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, - "memory allocation failed for deflate " - "uncompression"); + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for deflate uncompression"); } z_strm.next_out = (unsigned char*)outbuf + z_strm.total_out; z_strm.avail_out = (uInt)(nalloc - z_strm.total_out); @@ -112,7 +95,6 @@ H5Z_filter_deflate (unsigned UNUSED flags, size_t cd_nelmts, *buf_size = nalloc; ret_value = z_strm.total_out; inflateEnd(&z_strm); - } else { /* * Output; compress but fail if the result would be larger than the @@ -124,12 +106,9 @@ H5Z_filter_deflate (unsigned UNUSED flags, size_t cd_nelmts, uLongf z_dst_nbytes = (uLongf)nbytes; uLong z_src_nbytes = (uLong)nbytes; - if (NULL==(z_dst=outbuf=H5MM_malloc(nbytes))) { - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, - "unable to allocate deflate destination buffer"); - } - status = compress2 (z_dst, &z_dst_nbytes, z_src, z_src_nbytes, - aggression); + if (NULL==(z_dst=outbuf=H5MM_malloc(nbytes))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "unable to allocate deflate destination buffer"); + status = compress2 (z_dst, &z_dst_nbytes, z_src, z_src_nbytes, aggression); if (Z_BUF_ERROR==status) { HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "overflow"); } else if (Z_MEM_ERROR==status) { @@ -144,10 +123,6 @@ H5Z_filter_deflate (unsigned UNUSED flags, size_t cd_nelmts, ret_value = z_dst_nbytes; } } -#else - HGOTO_ERROR (H5E_PLINE, H5E_UNSUPPORTED, 0, - "hdf5 was not compiled with zlib-1.0.2 or better"); -#endif done: if(outbuf) @@ -155,4 +130,4 @@ done: FUNC_LEAVE (ret_value); } -#endif /* H5_HAVE_FILTER_GZIP */ +#endif /* H5_HAVE_FILTER_DEFLATE */ |