summaryrefslogtreecommitdiffstats
path: root/src/H5Zshuffle.c
blob: 61dcc4fc2016a983274861f807961d1b8c321d6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * 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"
#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);

  dest = malloc((size_t)nbytes);
  _dest =(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;
  }

  else {
    for (i=0;i<nbytes;i++){
      byte_pos = 1+j * bytesoftype; 
      if(byte_pos >nbytes) {
	k++;
	j=0;
	byte_pos = 1;
      }

      *(_dest+i)=*(_src+byte_pos-1+k);
      j++;
    }
    free(*buf);
     *buf = dest;
     dest = NULL;
     *buf_size=nbytes;
     ret_value = nbytes;
  }

}
#endif /*H5_HAVE_FILTER_SHUFFLE */