- 论坛徽章:
- 0
|
解码函数不是我写的,但经过验证是没有问题的。
具体的解码函数如下:
static unsigned int mask[] = {0,1,3,7,15,31,63,127,255};
static unsigned int map_masks[8] = {128, 64, 32, 16, 8, 4, 2, 1};
static double shift[9] = {1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0};
void BDS_unpack(float *flt,unsigned char *bds,unsigned char *bitmap,
int n_bits,int n,double ref,double scale)
{unsigned char *bits;
int i,mask_idx,t_bits,c_bits,j_bits;
unsigned int j, map_mask, tbits, jmask, bbits;
double jj;
if(BDS_Harmonic(bds))
{bits = bds + 15;
/* fill in global mean */
*flt++ = BDS_Harmonic_RefValue(bds);
n -= 1;
}
else
bits = bds + 11;
tbits=bbits=0;
jmask = (1 << n_bits) - 1;
t_bits = 0;
/////////////// 开始解码
for(i=0;i<n;i++)
{while(t_bits < n_bits)
{tbits = (tbits * 256) + *bits++;
t_bits += 8;
}
t_bits -= n_bits;
flt = (tbits >> t_bits) & jmask;
}
/* at least this vectorizes */
for(i=0;i<n;i++)
flt = ref + scale*flt;
/////////////// 结束解码
} |
|