![](/media/cache/profiles/98c39996bf1543e974747a2549b3107c.50x50_q85.png)
パラメータを適応変化させる事により圧縮率を向上させた動的ライス・ゴロム符号を利用した可逆圧縮方式。圧縮ソフト、圧縮率のMATLABシミュレーションは詳細はInterface誌2011年8月号に掲載されるRX62Nマイコン連動特集にて掲載予定。
Lossless_lib/_bitio.cpp@0:d920d64db582, 2011-03-30 (annotated)
- Committer:
- lynxeyed_atsu
- Date:
- Wed Mar 30 06:05:24 2011 +0000
- Revision:
- 0:d920d64db582
alpha
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lynxeyed_atsu | 0:d920d64db582 | 1 | #include "mbed.h" |
lynxeyed_atsu | 0:d920d64db582 | 2 | #include "string" |
lynxeyed_atsu | 0:d920d64db582 | 3 | #include "_bitio.h" |
lynxeyed_atsu | 0:d920d64db582 | 4 | |
lynxeyed_atsu | 0:d920d64db582 | 5 | |
lynxeyed_atsu | 0:d920d64db582 | 6 | //FILE *infp, *outfp; |
lynxeyed_atsu | 0:d920d64db582 | 7 | int getcount, putcount; |
lynxeyed_atsu | 0:d920d64db582 | 8 | int bitbuf; |
lynxeyed_atsu | 0:d920d64db582 | 9 | |
lynxeyed_atsu | 0:d920d64db582 | 10 | |
lynxeyed_atsu | 0:d920d64db582 | 11 | void init_bit_o(void) |
lynxeyed_atsu | 0:d920d64db582 | 12 | { |
lynxeyed_atsu | 0:d920d64db582 | 13 | putcount = 8; bitbuf = 0; |
lynxeyed_atsu | 0:d920d64db582 | 14 | } |
lynxeyed_atsu | 0:d920d64db582 | 15 | |
lynxeyed_atsu | 0:d920d64db582 | 16 | void init_bit_i(void) |
lynxeyed_atsu | 0:d920d64db582 | 17 | { |
lynxeyed_atsu | 0:d920d64db582 | 18 | getcount = 0; bitbuf = 0; |
lynxeyed_atsu | 0:d920d64db582 | 19 | } |
lynxeyed_atsu | 0:d920d64db582 | 20 | |
lynxeyed_atsu | 0:d920d64db582 | 21 | |
lynxeyed_atsu | 0:d920d64db582 | 22 | Uint getbit(void) |
lynxeyed_atsu | 0:d920d64db582 | 23 | { |
lynxeyed_atsu | 0:d920d64db582 | 24 | int flag; |
lynxeyed_atsu | 0:d920d64db582 | 25 | if (--getcount >= 0) return (bitbuf >> getcount) & 1U; |
lynxeyed_atsu | 0:d920d64db582 | 26 | getcount = 7; |
lynxeyed_atsu | 0:d920d64db582 | 27 | if((flag = fgetc(infp))==EOF)return OVERRUN; |
lynxeyed_atsu | 0:d920d64db582 | 28 | else bitbuf = flag; |
lynxeyed_atsu | 0:d920d64db582 | 29 | return (bitbuf >> 7) & 1U; |
lynxeyed_atsu | 0:d920d64db582 | 30 | } |
lynxeyed_atsu | 0:d920d64db582 | 31 | |
lynxeyed_atsu | 0:d920d64db582 | 32 | Uint getbits(int n) |
lynxeyed_atsu | 0:d920d64db582 | 33 | { |
lynxeyed_atsu | 0:d920d64db582 | 34 | Uint x = 0; |
lynxeyed_atsu | 0:d920d64db582 | 35 | if (n < 1 || 25 < n) return 0; |
lynxeyed_atsu | 0:d920d64db582 | 36 | while (n > getcount) { |
lynxeyed_atsu | 0:d920d64db582 | 37 | n -= getcount; |
lynxeyed_atsu | 0:d920d64db582 | 38 | x |= rightbits(getcount, bitbuf) << n; |
lynxeyed_atsu | 0:d920d64db582 | 39 | bitbuf = fgetc(infp); |
lynxeyed_atsu | 0:d920d64db582 | 40 | getcount = 8; |
lynxeyed_atsu | 0:d920d64db582 | 41 | } |
lynxeyed_atsu | 0:d920d64db582 | 42 | getcount -= n; |
lynxeyed_atsu | 0:d920d64db582 | 43 | return x | rightbits(n, bitbuf >> getcount); |
lynxeyed_atsu | 0:d920d64db582 | 44 | } |
lynxeyed_atsu | 0:d920d64db582 | 45 | |
lynxeyed_atsu | 0:d920d64db582 | 46 | |
lynxeyed_atsu | 0:d920d64db582 | 47 | void putbit(Uint bit) |
lynxeyed_atsu | 0:d920d64db582 | 48 | { |
lynxeyed_atsu | 0:d920d64db582 | 49 | putcount--; |
lynxeyed_atsu | 0:d920d64db582 | 50 | if (bit != 0) bitbuf |= (1 << putcount); |
lynxeyed_atsu | 0:d920d64db582 | 51 | if (putcount == 0) { |
lynxeyed_atsu | 0:d920d64db582 | 52 | if (fputc(bitbuf, outfp) == EOF) error("can't write\r\n"); |
lynxeyed_atsu | 0:d920d64db582 | 53 | bitbuf = 0; putcount = 8; |
lynxeyed_atsu | 0:d920d64db582 | 54 | } |
lynxeyed_atsu | 0:d920d64db582 | 55 | } |
lynxeyed_atsu | 0:d920d64db582 | 56 | |
lynxeyed_atsu | 0:d920d64db582 | 57 | |
lynxeyed_atsu | 0:d920d64db582 | 58 | void putbits(int n, Uint x) |
lynxeyed_atsu | 0:d920d64db582 | 59 | { |
lynxeyed_atsu | 0:d920d64db582 | 60 | if (n < 1 || 25 < n) return; |
lynxeyed_atsu | 0:d920d64db582 | 61 | while (n >= putcount) { |
lynxeyed_atsu | 0:d920d64db582 | 62 | n -= putcount; |
lynxeyed_atsu | 0:d920d64db582 | 63 | bitbuf |= rightbits(putcount, x >> n); |
lynxeyed_atsu | 0:d920d64db582 | 64 | if (fputc(bitbuf, outfp) == EOF) error("cant write\r\n"); |
lynxeyed_atsu | 0:d920d64db582 | 65 | bitbuf = 0U; |
lynxeyed_atsu | 0:d920d64db582 | 66 | putcount = 8; |
lynxeyed_atsu | 0:d920d64db582 | 67 | } |
lynxeyed_atsu | 0:d920d64db582 | 68 | putcount -= n; |
lynxeyed_atsu | 0:d920d64db582 | 69 | bitbuf |= rightbits(n, x) << putcount; |
lynxeyed_atsu | 0:d920d64db582 | 70 | } |
lynxeyed_atsu | 0:d920d64db582 | 71 |