![](/media/cache/profiles/98c39996bf1543e974747a2549b3107c.50x50_q85.png)
パラメータを適応変化させる事により圧縮率を向上させた動的ライス・ゴロム符号を利用した可逆圧縮方式。圧縮ソフト、圧縮率のMATLABシミュレーションは詳細はInterface誌2011年8月号に掲載されるRX62Nマイコン連動特集にて掲載予定。
Lossless_lib/_bitio.cpp
- Committer:
- lynxeyed_atsu
- Date:
- 2011-03-30
- Revision:
- 0:d920d64db582
File content as of revision 0:d920d64db582:
#include "mbed.h" #include "string" #include "_bitio.h" //FILE *infp, *outfp; int getcount, putcount; int bitbuf; void init_bit_o(void) { putcount = 8; bitbuf = 0; } void init_bit_i(void) { getcount = 0; bitbuf = 0; } Uint getbit(void) { int flag; if (--getcount >= 0) return (bitbuf >> getcount) & 1U; getcount = 7; if((flag = fgetc(infp))==EOF)return OVERRUN; else bitbuf = flag; return (bitbuf >> 7) & 1U; } Uint getbits(int n) { Uint x = 0; if (n < 1 || 25 < n) return 0; while (n > getcount) { n -= getcount; x |= rightbits(getcount, bitbuf) << n; bitbuf = fgetc(infp); getcount = 8; } getcount -= n; return x | rightbits(n, bitbuf >> getcount); } void putbit(Uint bit) { putcount--; if (bit != 0) bitbuf |= (1 << putcount); if (putcount == 0) { if (fputc(bitbuf, outfp) == EOF) error("can't write\r\n"); bitbuf = 0; putcount = 8; } } void putbits(int n, Uint x) { if (n < 1 || 25 < n) return; while (n >= putcount) { n -= putcount; bitbuf |= rightbits(putcount, x >> n); if (fputc(bitbuf, outfp) == EOF) error("cant write\r\n"); bitbuf = 0U; putcount = 8; } putcount -= n; bitbuf |= rightbits(n, x) << putcount; }