1 /* This code is part of the tng compression routines.
3 * Written by Daniel Spangberg
4 * Copyright (c) 2010, 2013, The GROMACS development team.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the Revised BSD License.
12 #include "../../include/compression/vals16.h"
14 /* Coding 32 bit ints in sequences of 16 bit ints. Worst case
15 the output is 3*nvals long. */
16 void Ptngc_comp_conv_to_vals16(unsigned int *vals,int nvals,
17 unsigned int *vals16, int *nvals16)
21 for (i=0; i<nvals; i++)
27 unsigned int lo=(vals[i]&0x7FFFU)|0x8000U;
28 unsigned int hi=vals[i]>>15;
34 unsigned int lohi=(hi&0x7FFFU)|0x8000U;
35 unsigned int hihi=hi>>15;
42 /* Test that things that detect that this is bad really works. */
48 void Ptngc_comp_conv_from_vals16(unsigned int *vals16,int nvals16,
49 unsigned int *vals, int *nvals)
55 if (vals16[i]<=0x7FFFU)
56 vals[j++]=vals16[i++];
59 unsigned int lo=vals16[i++];
60 unsigned int hi=vals16[i++];
62 vals[j++]=(lo&0x7FFFU)|(hi<<15);
65 unsigned int hihi=vals16[i++];
66 vals[j++]=(lo&0x7FFFU)|((hi&0x7FFFU)<<15)|(hihi<<30);