2019-02-01 12:13:06 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2018, University Corporation for Atmospheric Research
|
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-04-04 10:15:34 +08:00
|
|
|
#include "config.h"
|
2021-09-03 07:04:26 +08:00
|
|
|
#include "netcdf_filter_build.h"
|
2019-02-01 12:13:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
Common utilities related to filters.
|
|
|
|
Taken from libdispatch/dfilters.c.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
/* Byte swap an 8-byte integer in place */
|
|
|
|
static void
|
|
|
|
byteswap8(unsigned char* mem)
|
|
|
|
{
|
|
|
|
unsigned char c;
|
|
|
|
c = mem[0];
|
|
|
|
mem[0] = mem[7];
|
|
|
|
mem[7] = c;
|
|
|
|
c = mem[1];
|
|
|
|
mem[1] = mem[6];
|
|
|
|
mem[6] = c;
|
|
|
|
c = mem[2];
|
|
|
|
mem[2] = mem[5];
|
|
|
|
mem[5] = c;
|
|
|
|
c = mem[3];
|
|
|
|
mem[3] = mem[4];
|
|
|
|
mem[4] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Byte swap an 8-byte integer in place */
|
|
|
|
static void
|
|
|
|
byteswap4(unsigned char* mem)
|
|
|
|
{
|
|
|
|
unsigned char c;
|
|
|
|
c = mem[0];
|
|
|
|
mem[0] = mem[3];
|
|
|
|
mem[3] = c;
|
|
|
|
c = mem[1];
|
|
|
|
mem[1] = mem[2];
|
|
|
|
mem[2] = c;
|
|
|
|
}
|
|
|
|
#endif /*WORDS_BIGENDIAN*/
|
|
|
|
|
|
|
|
void
|
2020-09-28 02:43:46 +08:00
|
|
|
NC_h5filterspec_fix8(void* mem0, int decode)
|
2019-02-01 12:13:06 +08:00
|
|
|
{
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
2019-02-25 13:20:01 +08:00
|
|
|
unsigned char* mem = mem0;
|
|
|
|
if(decode) { /* Apply inverse of the encode case */
|
2019-02-01 12:13:06 +08:00
|
|
|
byteswap4(mem); /* step 1: byte-swap each piece */
|
|
|
|
byteswap4(mem+4);
|
|
|
|
byteswap8(mem); /* step 2: convert to little endian format */
|
|
|
|
} else { /* encode */
|
|
|
|
byteswap8(mem); /* step 1: convert to little endian format */
|
|
|
|
byteswap4(mem); /* step 2: byte-swap each piece */
|
|
|
|
byteswap4(mem+4);
|
|
|
|
}
|
|
|
|
#else /* Little endian */
|
|
|
|
/* No action is necessary */
|
2019-02-16 07:07:22 +08:00
|
|
|
#endif
|
2019-02-01 12:13:06 +08:00
|
|
|
}
|