diff options
author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-10-21 07:31:05 (GMT) |
---|---|---|
committer | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-10-21 07:31:05 (GMT) |
commit | beaa92cb293a4147aef8ed03027500804535ed96 (patch) | |
tree | c8427746983418476a99b5c61847e0b4eeca5f1d /src/compression/coder.c | |
parent | 885f2782f9f48b69bc229612b0734b4de48b890b (diff) |
Fixed compiler warnings and linking errors in MSVC.
Changed tabs to spaces in tng_compression functions.
Diffstat (limited to 'src/compression/coder.c')
-rw-r--r-- | src/compression/coder.c | 338 |
1 files changed, 169 insertions, 169 deletions
diff --git a/src/compression/coder.c b/src/compression/coder.c index c12042c..9e3c880 100644 --- a/src/compression/coder.c +++ b/src/compression/coder.c @@ -32,19 +32,19 @@ #define TNG_SNPRINTF snprintf #endif -struct coder *Ptngc_coder_init(void) +struct coder DECLSPECDLLEXPORT *Ptngc_coder_init(void) { struct coder *coder_inst=warnmalloc(sizeof *coder_inst); coder_inst->pack_temporary_bits=0; return coder_inst; } -void Ptngc_coder_deinit(struct coder *coder_inst) +void DECLSPECDLLEXPORT Ptngc_coder_deinit(struct coder *coder_inst) { free(coder_inst); } -TNG_INLINE void Ptngc_out8bits(struct coder *coder_inst, unsigned char **output) +TNG_INLINE void DECLSPECDLLEXPORT Ptngc_out8bits(struct coder *coder_inst, unsigned char **output) { int pack_temporary_bits=coder_inst->pack_temporary_bits; unsigned int pack_temporary=coder_inst->pack_temporary; @@ -61,7 +61,7 @@ TNG_INLINE void Ptngc_out8bits(struct coder *coder_inst, unsigned char **output) coder_inst->pack_temporary=pack_temporary; } -void Ptngc_write_pattern(struct coder *coder_inst, unsigned int pattern, +void DECLSPECDLLEXPORT Ptngc_write_pattern(struct coder *coder_inst, unsigned int pattern, int nbits, unsigned char **output) { unsigned int mask1,mask2; @@ -71,17 +71,17 @@ void Ptngc_write_pattern(struct coder *coder_inst, unsigned int pattern, coder_inst->pack_temporary_bits+=nbits; while (nbits) { - if (pattern & mask1) - coder_inst->pack_temporary|=mask2; - nbits--; - mask1<<=1; - mask2>>=1; + if (pattern & mask1) + coder_inst->pack_temporary|=mask2; + nbits--; + mask1<<=1; + mask2>>=1; } Ptngc_out8bits(coder_inst,output); } /* Write up to 24 bits */ -TNG_INLINE void Ptngc_writebits(struct coder *coder_inst, +TNG_INLINE void DECLSPECDLLEXPORT Ptngc_writebits(struct coder *coder_inst, unsigned int value, int nbits, unsigned char **output_ptr) { @@ -93,7 +93,7 @@ TNG_INLINE void Ptngc_writebits(struct coder *coder_inst, } /* Write up to 32 bits */ -void Ptngc_write32bits(struct coder *coder_inst,unsigned int value, +void DECLSPECDLLEXPORT Ptngc_write32bits(struct coder *coder_inst,unsigned int value, int nbits, unsigned char **output_ptr) { unsigned int mask; @@ -116,15 +116,15 @@ void Ptngc_write32bits(struct coder *coder_inst,unsigned int value, } /* Write "arbitrary" number of bits */ -void Ptngc_writemanybits(struct coder *coder_inst, unsigned char *value, +void DECLSPECDLLEXPORT Ptngc_writemanybits(struct coder *coder_inst, unsigned char *value, int nbits, unsigned char **output_ptr) { int vptr=0; while (nbits>=24) { unsigned int v=((((unsigned int)value[vptr])<<16)| - (((unsigned int)value[vptr+1])<<8)| - (((unsigned int)value[vptr+2]))); + (((unsigned int)value[vptr+1])<<8)| + (((unsigned int)value[vptr+2]))); Ptngc_writebits(coder_inst,v,24,output_ptr); vptr+=3; nbits-=24; @@ -151,8 +151,8 @@ static int write_stop_bit_code(struct coder *coder_inst, unsigned int s, s>>=coding_parameter; if (s) { - this|=1U; - coder_inst->stat_overflow++; + this|=1U; + coder_inst->stat_overflow++; } coder_inst->pack_temporary<<=(coding_parameter+1); coder_inst->pack_temporary_bits+=coding_parameter+1; @@ -160,9 +160,9 @@ static int write_stop_bit_code(struct coder *coder_inst, unsigned int s, Ptngc_out8bits(coder_inst,output); if (s) { - coding_parameter>>=1; - if (coding_parameter<1) - coding_parameter=1; + coding_parameter>>=1; + if (coding_parameter<1) + coding_parameter=1; } } while (s); coder_inst->stat_numval++; @@ -175,15 +175,15 @@ static int pack_stopbits_item(struct coder *coder_inst,int item, /* Find this symbol in table. */ int s=0; if (item>0) - s=1+(item-1)*2; + s=1+(item-1)*2; else if (item<0) - s=2+(-item-1)*2; + s=2+(-item-1)*2; return write_stop_bit_code(coder_inst,s,coding_parameter,output); } static int pack_triplet(struct coder *coder_inst, unsigned int *s, unsigned char **output, int coding_parameter, - unsigned int max_base, int maxbits) + unsigned int max_base, int maxbits) { /* Determine base for this triplet. */ unsigned int min_base=1U<<coding_parameter; @@ -194,14 +194,14 @@ static int pack_triplet(struct coder *coder_inst, unsigned int *s, for (i=0; i<3; i++) while (s[i]>=this_base) { - this_base*=2; - jbase++; + this_base*=2; + jbase++; } bits_per_value=coding_parameter+jbase; if (jbase>=3) { if (this_base>max_base) - return 1; + return 1; bits_per_value=maxbits; jbase=3; } @@ -215,14 +215,14 @@ static int pack_triplet(struct coder *coder_inst, unsigned int *s, return 0; } -void Ptngc_pack_flush(struct coder *coder_inst,unsigned char **output) +void DECLSPECDLLEXPORT Ptngc_pack_flush(struct coder *coder_inst,unsigned char **output) { /* Zero-fill just enough. */ if (coder_inst->pack_temporary_bits>0) Ptngc_write_pattern(coder_inst,0,8-coder_inst->pack_temporary_bits,output); } -unsigned char *Ptngc_pack_array(struct coder *coder_inst, +unsigned char DECLSPECDLLEXPORT *Ptngc_pack_array(struct coder *coder_inst, int *input, int *length, int coding, int coding_parameter, int natoms, int speed) { @@ -235,25 +235,25 @@ unsigned char *Ptngc_pack_array(struct coder *coder_inst, int cnt=0; int most_negative=2147483647; for (i=0; i<n; i++) - if (input[i]<most_negative) - most_negative=input[i]; + if (input[i]<most_negative) + most_negative=input[i]; most_negative=-most_negative; output[0]=((unsigned int)most_negative)&0xFFU; output[1]=(((unsigned int)most_negative)>>8)&0xFFU; output[2]=(((unsigned int)most_negative)>>16)&0xFFU; output[3]=(((unsigned int)most_negative)>>24)&0xFFU; for (i=0; i<natoms; i++) - for (j=0; j<3; j++) - for (k=0; k<nframes; k++) - { - int item=input[k*3*natoms+i*3+j]; - pval[cnt++]=(unsigned int)(item+most_negative); + for (j=0; j<3; j++) + for (k=0; k<nframes; k++) + { + int item=input[k*3*natoms+i*3+j]; + pval[cnt++]=(unsigned int)(item+most_negative); - } + } if (speed>=5) - bwlzh_compress(pval,n,output+4,length); + bwlzh_compress(pval,n,output+4,length); else - bwlzh_compress_no_lz77(pval,n,output+4,length); + bwlzh_compress_no_lz77(pval,n,output+4,length); (*length)+=4; free(pval); return output; @@ -275,64 +275,64 @@ unsigned char *Ptngc_pack_array(struct coder *coder_inst, output=warnmalloc(8* *length*sizeof *output); output_ptr=output; if ((coding==TNG_COMPRESS_ALGO_TRIPLET) || - (coding==TNG_COMPRESS_ALGO_POS_TRIPLET_INTRA) || - (coding==TNG_COMPRESS_ALGO_POS_TRIPLET_ONETOONE)) - { - /* Pack triplets. */ - int ntriplets=*length/3; - /* Determine max base and maxbits */ - unsigned int max_base=1U<<coding_parameter; - unsigned int maxbits=coding_parameter; - unsigned int intmax=0; - for (i=0; i<*length; i++) - { - int item=input[i]; - unsigned int s=0; - if (item>0) - s=1+(item-1)*2; - else if (item<0) - s=2+(-item-1)*2; - if (s>intmax) - intmax=s; - } - /* Store intmax */ - coder_inst->pack_temporary_bits=32; - coder_inst->pack_temporary=intmax; - Ptngc_out8bits(coder_inst,&output_ptr); - while (intmax>=max_base) - { - max_base*=2; - maxbits++; - } - for (i=0; i<ntriplets; i++) - { - int j; - unsigned int s[3]; - for (j=0; j<3; j++) - { - int item=input[i*3+j]; - /* Find this symbol in table. */ - s[j]=0; - if (item>0) - s[j]=1+(item-1)*2; - else if (item<0) - s[j]=2+(-item-1)*2; - } - if (pack_triplet(coder_inst, s, &output_ptr, + (coding==TNG_COMPRESS_ALGO_POS_TRIPLET_INTRA) || + (coding==TNG_COMPRESS_ALGO_POS_TRIPLET_ONETOONE)) + { + /* Pack triplets. */ + int ntriplets=*length/3; + /* Determine max base and maxbits */ + unsigned int max_base=1U<<coding_parameter; + unsigned int maxbits=coding_parameter; + unsigned int intmax=0; + for (i=0; i<*length; i++) + { + int item=input[i]; + unsigned int s=0; + if (item>0) + s=1+(item-1)*2; + else if (item<0) + s=2+(-item-1)*2; + if (s>intmax) + intmax=s; + } + /* Store intmax */ + coder_inst->pack_temporary_bits=32; + coder_inst->pack_temporary=intmax; + Ptngc_out8bits(coder_inst,&output_ptr); + while (intmax>=max_base) + { + max_base*=2; + maxbits++; + } + for (i=0; i<ntriplets; i++) + { + int j; + unsigned int s[3]; + for (j=0; j<3; j++) + { + int item=input[i*3+j]; + /* Find this symbol in table. */ + s[j]=0; + if (item>0) + s[j]=1+(item-1)*2; + else if (item<0) + s[j]=2+(-item-1)*2; + } + if (pack_triplet(coder_inst, s, &output_ptr, coding_parameter, max_base,maxbits)) - { - free(output); - return NULL; - } - } - } + { + free(output); + return NULL; + } + } + } else - for (i=0; i<*length; i++) - if (pack_stopbits_item(coder_inst,input[i],&output_ptr,coding_parameter)) - { - free(output); - return NULL; - } + for (i=0; i<*length; i++) + if (pack_stopbits_item(coder_inst,input[i],&output_ptr,coding_parameter)) + { + free(output); + return NULL; + } Ptngc_pack_flush(coder_inst,&output_ptr); output_length=(int)(output_ptr-output); *length=output_length; @@ -357,39 +357,39 @@ static int unpack_array_stop_bits(struct coder *coder_inst, unsigned int insert_mask=1U<<(numbits-1); int inserted_bits=numbits; do { - for (j=0; j<numbits; j++) - { - bit=*ptr & extract_mask; - if (bit) - pattern|=insert_mask; - insert_mask>>=1; - extract_mask>>=1; - if (!extract_mask) - { - extract_mask=0x80; - ptr++; - } - } - /* Check stop bit */ - bit=*ptr & extract_mask; - extract_mask>>=1; - if (!extract_mask) - { - extract_mask=0x80; - ptr++; - } - if (bit) - { - numbits>>=1; - if (numbits<1) - numbits=1; - inserted_bits+=numbits; - insert_mask=1U<<(inserted_bits-1); - } + for (j=0; j<numbits; j++) + { + bit=*ptr & extract_mask; + if (bit) + pattern|=insert_mask; + insert_mask>>=1; + extract_mask>>=1; + if (!extract_mask) + { + extract_mask=0x80; + ptr++; + } + } + /* Check stop bit */ + bit=*ptr & extract_mask; + extract_mask>>=1; + if (!extract_mask) + { + extract_mask=0x80; + ptr++; + } + if (bit) + { + numbits>>=1; + if (numbits<1) + numbits=1; + inserted_bits+=numbits; + insert_mask=1U<<(inserted_bits-1); + } } while (bit); s=(pattern+1)/2; if ((pattern%2)==0) - s=-s; + s=-s; output[i]=s; } return 0; @@ -426,45 +426,45 @@ static int unpack_array_triplet(struct coder *coder_inst, unsigned int numbits; unsigned int bit; for (j=0; j<2; j++) - { - bit=*ptr & extract_mask; - jbase<<=1; - if (bit) - jbase|=1U; - extract_mask>>=1; - if (!extract_mask) - { - extract_mask=0x80; - ptr++; - } - } + { + bit=*ptr & extract_mask; + jbase<<=1; + if (bit) + jbase|=1U; + extract_mask>>=1; + if (!extract_mask) + { + extract_mask=0x80; + ptr++; + } + } if (jbase==3) - numbits=maxbits; + numbits=maxbits; else - numbits=coding_parameter+jbase; + numbits=coding_parameter+jbase; for (j=0; j<3; j++) - { - int s; - unsigned int jbit; - unsigned int pattern=0; - for (jbit=0; jbit<numbits; jbit++) - { - bit=*ptr & extract_mask; - pattern<<=1; - if (bit) - pattern|=1U; - extract_mask>>=1; - if (!extract_mask) - { - extract_mask=0x80; - ptr++; - } - } - s=(pattern+1)/2; - if ((pattern%2)==0) - s=-s; - output[i*3+j]=s; - } + { + int s; + unsigned int jbit; + unsigned int pattern=0; + for (jbit=0; jbit<numbits; jbit++) + { + bit=*ptr & extract_mask; + pattern<<=1; + if (bit) + pattern|=1U; + extract_mask>>=1; + if (!extract_mask) + { + extract_mask=0x80; + ptr++; + } + } + s=(pattern+1)/2; + if ((pattern%2)==0) + s=-s; + output[i*3+j]=s; + } } return 0; } @@ -478,23 +478,23 @@ static int unpack_array_bwlzh(struct coder *coder_inst, int nframes=n/natoms/3; int cnt=0; int most_negative=(int)(((unsigned int)packed[0]) | - (((unsigned int)packed[1])<<8) | - (((unsigned int)packed[2])<<16) | - (((unsigned int)packed[3])<<24)); + (((unsigned int)packed[1])<<8) | + (((unsigned int)packed[2])<<16) | + (((unsigned int)packed[3])<<24)); (void) coder_inst; bwlzh_decompress(packed+4,length,pval); for (i=0; i<natoms; i++) for (j=0; j<3; j++) for (k=0; k<nframes; k++) - { - unsigned int s=pval[cnt++]; - output[k*3*natoms+i*3+j]=(int)s-most_negative; - } + { + unsigned int s=pval[cnt++]; + output[k*3*natoms+i*3+j]=(int)s-most_negative; + } free(pval); return 0; } -int Ptngc_unpack_array(struct coder *coder_inst, +int DECLSPECDLLEXPORT Ptngc_unpack_array(struct coder *coder_inst, unsigned char *packed, int *output, int length, int coding, int coding_parameter, int natoms) @@ -503,8 +503,8 @@ int Ptngc_unpack_array(struct coder *coder_inst, (coding==TNG_COMPRESS_ALGO_VEL_STOPBIT_INTER)) return unpack_array_stop_bits(coder_inst, packed, output, length, coding_parameter); else if ((coding==TNG_COMPRESS_ALGO_TRIPLET) || - (coding==TNG_COMPRESS_ALGO_POS_TRIPLET_INTRA) || - (coding==TNG_COMPRESS_ALGO_POS_TRIPLET_ONETOONE)) + (coding==TNG_COMPRESS_ALGO_POS_TRIPLET_INTRA) || + (coding==TNG_COMPRESS_ALGO_POS_TRIPLET_ONETOONE)) return unpack_array_triplet(coder_inst, packed, output, length, coding_parameter); else if (coding==TNG_COMPRESS_ALGO_POS_XTC2) return Ptngc_unpack_array_xtc2(coder_inst, packed, output, length); |