[3745] | 1 | /**************************************************************************
|
---|
| 2 | *
|
---|
| 3 | * bitio_mem.c -- Functions for bitio to memory
|
---|
| 4 | * Copyright (C) 1994 Neil Sharman
|
---|
| 5 | *
|
---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
---|
| 7 | * it under the terms of the GNU General Public License as published by
|
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 9 | * (at your option) any later version.
|
---|
| 10 | *
|
---|
| 11 | * This program is distributed in the hope that it will be useful,
|
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | * GNU General Public License for more details.
|
---|
| 15 | *
|
---|
| 16 | * You should have received a copy of the GNU General Public License
|
---|
| 17 | * along with this program; if not, write to the Free Software
|
---|
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 19 | *
|
---|
| 20 | * $Id: bitio_mem.c 3745 2003-02-20 21:20:24Z mdewsnip $
|
---|
| 21 | *
|
---|
| 22 | **************************************************************************/
|
---|
| 23 |
|
---|
| 24 | /*
|
---|
| 25 | $Log$
|
---|
| 26 | Revision 1.1 2003/02/20 21:14:16 mdewsnip
|
---|
| 27 | Addition of MG package for search and retrieval
|
---|
| 28 |
|
---|
| 29 | Revision 1.1 1999/08/10 21:16:45 sjboddie
|
---|
| 30 | renamed mg-1.3d directory mg
|
---|
| 31 |
|
---|
| 32 | Revision 1.1 1998/11/17 09:31:47 rjmcnab
|
---|
| 33 | *** empty log message ***
|
---|
| 34 |
|
---|
| 35 | * Revision 1.1 1994/08/22 00:24:39 tes
|
---|
| 36 | * Initial placement under CVS.
|
---|
| 37 | *
|
---|
| 38 | */
|
---|
| 39 |
|
---|
| 40 | static char *RCSID = "$Id: bitio_mem.c 3745 2003-02-20 21:20:24Z mdewsnip $";
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | #include "sysfuncs.h"
|
---|
| 45 |
|
---|
| 46 | #include "bitio_m_mem.h"
|
---|
| 47 | #include "bitio_m.h"
|
---|
| 48 |
|
---|
| 49 | int fprintf (FILE *, const char *,...);
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | void
|
---|
| 54 | BIO_Mem_Encode_Start (void *buf, int rem, mem_bitio_state * bs)
|
---|
| 55 | {
|
---|
| 56 | ENCODE_START (buf, rem)
|
---|
| 57 | ENCODE_PAUSE (*bs)
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | void
|
---|
| 61 | BIO_Mem_Encode_Done (mem_bitio_state * bs)
|
---|
| 62 | {
|
---|
| 63 | ENCODE_CONTINUE (*bs)
|
---|
| 64 | ENCODE_DONE
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | void
|
---|
| 69 | BIO_Mem_Decode_Start (void *buf, int rem, mem_bitio_state * bs)
|
---|
| 70 | {
|
---|
| 71 | DECODE_START (buf, rem)
|
---|
| 72 | DECODE_PAUSE (*bs)
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | void
|
---|
| 79 | BIO_Mem_Unary_Encode (unsigned long val, mem_bitio_state * bs,
|
---|
| 80 | unsigned long *bits)
|
---|
| 81 | {
|
---|
| 82 | ENCODE_CONTINUE (*bs)
|
---|
| 83 | if (bits)
|
---|
| 84 | UNARY_ENCODE_L (val, *bits);
|
---|
| 85 | else
|
---|
| 86 | UNARY_ENCODE (val);
|
---|
| 87 | ENCODE_PAUSE (*bs)
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | unsigned long
|
---|
| 92 | BIO_Mem_Unary_Decode (mem_bitio_state * bs,
|
---|
| 93 | unsigned long *bits)
|
---|
| 94 | {
|
---|
| 95 | register unsigned long val;
|
---|
| 96 | DECODE_CONTINUE (*bs)
|
---|
| 97 | if (bits)
|
---|
| 98 | UNARY_DECODE_L (val, *bits);
|
---|
| 99 | else
|
---|
| 100 | UNARY_DECODE (val);
|
---|
| 101 | DECODE_PAUSE (*bs)
|
---|
| 102 | return (val);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | void
|
---|
| 112 | BIO_Mem_Binary_Encode (unsigned long val, unsigned long b,
|
---|
| 113 | mem_bitio_state * bs, unsigned long *bits)
|
---|
| 114 | {
|
---|
| 115 | ENCODE_CONTINUE (*bs)
|
---|
| 116 | if (bits)
|
---|
| 117 | BINARY_ENCODE_L (val, b, *bits);
|
---|
| 118 | else
|
---|
| 119 | BINARY_ENCODE (val, b);
|
---|
| 120 | ENCODE_PAUSE (*bs)
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | unsigned long
|
---|
| 125 | BIO_Mem_Binary_Decode (unsigned long b, mem_bitio_state * bs,
|
---|
| 126 | unsigned long *bits)
|
---|
| 127 | {
|
---|
| 128 | register unsigned long val;
|
---|
| 129 | DECODE_CONTINUE (*bs)
|
---|
| 130 | if (bits)
|
---|
| 131 | BINARY_DECODE_L (val, b, *bits);
|
---|
| 132 | else
|
---|
| 133 | BINARY_DECODE (val, b);
|
---|
| 134 | DECODE_PAUSE (*bs)
|
---|
| 135 | return (val);
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | void
|
---|
| 145 | BIO_Mem_Gamma_Encode (unsigned long val, mem_bitio_state * bs,
|
---|
| 146 | unsigned long *bits)
|
---|
| 147 | {
|
---|
| 148 | ENCODE_CONTINUE (*bs)
|
---|
| 149 | if (bits)
|
---|
| 150 | GAMMA_ENCODE_L (val, *bits);
|
---|
| 151 | else
|
---|
| 152 | GAMMA_ENCODE (val);
|
---|
| 153 | ENCODE_PAUSE (*bs)
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 | unsigned long
|
---|
| 158 | BIO_Mem_Gamma_Decode (mem_bitio_state * bs, unsigned long *bits)
|
---|
| 159 | {
|
---|
| 160 | register unsigned long val;
|
---|
| 161 | DECODE_CONTINUE (*bs)
|
---|
| 162 | if (bits)
|
---|
| 163 | GAMMA_DECODE_L (val, *bits);
|
---|
| 164 | else
|
---|
| 165 | GAMMA_DECODE (val);
|
---|
| 166 | DECODE_PAUSE (*bs)
|
---|
| 167 | return (val);
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 | void
|
---|
| 174 | BIO_Mem_Delta_Encode (unsigned long val, mem_bitio_state * bs,
|
---|
| 175 | unsigned long *bits)
|
---|
| 176 | {
|
---|
| 177 | ENCODE_CONTINUE (*bs)
|
---|
| 178 | if (bits)
|
---|
| 179 | DELTA_ENCODE_L (val, *bits);
|
---|
| 180 | else
|
---|
| 181 | DELTA_ENCODE (val);
|
---|
| 182 | ENCODE_PAUSE (*bs)
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 |
|
---|
| 186 | unsigned long
|
---|
| 187 | BIO_Mem_Delta_Decode (mem_bitio_state * bs, unsigned long *bits)
|
---|
| 188 | {
|
---|
| 189 | register unsigned long val;
|
---|
| 190 | DECODE_CONTINUE (*bs)
|
---|
| 191 | if (bits)
|
---|
| 192 | DELTA_DECODE_L (val, *bits);
|
---|
| 193 | else
|
---|
| 194 | DELTA_DECODE (val);
|
---|
| 195 | DECODE_PAUSE (*bs)
|
---|
| 196 | return (val);
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | void
|
---|
| 200 | BIO_Mem_Elias_Encode (unsigned long val, unsigned long b, double s,
|
---|
| 201 | mem_bitio_state * bs, unsigned long *bits)
|
---|
| 202 | {
|
---|
| 203 | ENCODE_CONTINUE (*bs)
|
---|
| 204 | if (bits)
|
---|
| 205 | ELIAS_ENCODE_L (val, b, s, *bits);
|
---|
| 206 | else
|
---|
| 207 | ELIAS_ENCODE (val, b, s);
|
---|
| 208 | ENCODE_PAUSE (*bs)
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | unsigned long
|
---|
| 213 | BIO_Mem_Elias_Decode (unsigned long b, double s,
|
---|
| 214 | mem_bitio_state * bs, unsigned long *bits)
|
---|
| 215 | {
|
---|
| 216 | register unsigned long val;
|
---|
| 217 | DECODE_CONTINUE (*bs)
|
---|
| 218 | if (bits)
|
---|
| 219 | ELIAS_DECODE_L (val, b, s, *bits);
|
---|
| 220 | else
|
---|
| 221 | ELIAS_DECODE (val, b, s);
|
---|
| 222 | DECODE_PAUSE (*bs)
|
---|
| 223 | return (val);
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | void
|
---|
| 227 | BIO_Mem_Bblock_Encode (unsigned long val, unsigned long b,
|
---|
| 228 | mem_bitio_state * bs, unsigned long *bits)
|
---|
| 229 | {
|
---|
| 230 | ENCODE_CONTINUE (*bs)
|
---|
| 231 | if (bits)
|
---|
| 232 | BBLOCK_ENCODE_L (val, b, *bits);
|
---|
| 233 | else
|
---|
| 234 | BBLOCK_ENCODE (val, b);
|
---|
| 235 | ENCODE_PAUSE (*bs)
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 | unsigned long
|
---|
| 240 | BIO_Mem_Bblock_Decode (unsigned long b, mem_bitio_state * bs,
|
---|
| 241 | unsigned long *bits)
|
---|
| 242 | {
|
---|
| 243 | register unsigned long val;
|
---|
| 244 | DECODE_CONTINUE (*bs)
|
---|
| 245 | if (bits)
|
---|
| 246 | BBLOCK_DECODE_L (val, b, *bits);
|
---|
| 247 | else
|
---|
| 248 | BBLOCK_DECODE (val, b);
|
---|
| 249 | DECODE_PAUSE (*bs)
|
---|
| 250 | return (val);
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | void
|
---|
| 254 | BIO_Mem_Decode_Seek (unsigned long pos, mem_bitio_state * bs)
|
---|
| 255 | {
|
---|
| 256 | DECODE_CONTINUE (*bs)
|
---|
| 257 | DECODE_SEEK (pos);
|
---|
| 258 | DECODE_PAUSE (*bs)
|
---|
| 259 | }
|
---|