Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

bitwise.h

Go to the documentation of this file.
00001 /* Copyright (C) 1998 Oregon Graduate Institute of Science & Technology 00002 * 00003 * See the file COPYRIGHT, which should have been supplied with this 00004 * package, for licensing details. We may be contacted through email 00005 * at <quasar-help@cse.ogi.edu>. 00006 */ 00007 00008 #include <sys/types.h> 00009 #include <netinet/in.h> 00010 00011 #define SPEG_BW_START_RD(ptr) \ 00012 int _BWleft_##ptr = 32 - (((int)ptr & 3) << 3); \ 00013 u_int32_t _BWcur_##ptr = ntohl(*(u_int32_t*)(ptr -= (int)ptr & 3)) << (32 - _BWleft_##ptr) 00014 00015 #define SPEG_BW_END_RD(ptr) \ 00016 (ptr += (39 - _BWleft_##ptr) >> 3) 00017 00018 #define SPEG_BW_GETN(ptr, dest, n) \ 00019 do { \ 00020 dest = _BWcur_##ptr >> (32 - n); \ 00021 if ((_BWleft_##ptr -= n) <= 0) { \ 00022 ptr += 4; \ 00023 _BWcur_##ptr = ntohl(*(u_int32_t*)ptr); \ 00024 if (_BWleft_##ptr != 0) { \ 00025 dest |= _BWcur_##ptr >> (32 + _BWleft_##ptr); \ 00026 _BWcur_##ptr <<= -_BWleft_##ptr; \ 00027 } \ 00028 _BWleft_##ptr += 32; \ 00029 } \ 00030 else _BWcur_##ptr <<= n; \ 00031 } while (0) 00032 00033 #define SPEG_BW_FLUSHN(ptr, n) \ 00034 do { \ 00035 if ((_BWleft_##ptr -= n) <= 0) { \ 00036 ptr += 4; \ 00037 _BWcur_##ptr = ntohl(*(u_int32_t*)ptr); \ 00038 _BWcur_##ptr <<= -_BWleft_##ptr; \ 00039 _BWleft_##ptr += 32; \ 00040 } \ 00041 else _BWcur_##ptr <<= n; \ 00042 } while (0) 00043 00044 #define SPEG_BW_GETHUFFN(ptr, dest, sztab, szext, n) \ 00045 do { \ 00046 int _BWtmp_##ptr; \ 00047 dest = _BWcur_##ptr >> (32 - n); \ 00048 _BWtmp_##ptr = _BWleft_##ptr - sztab[dest]szext; \ 00049 if (_BWtmp_##ptr <= 0) { \ 00050 ptr += 4; \ 00051 _BWcur_##ptr = ntohl(*(u_int32_t*)ptr); \ 00052 if (_BWtmp_##ptr != 0) { \ 00053 dest |= _BWcur_##ptr >> (32 + _BWleft_##ptr - n); \ 00054 _BWleft_##ptr -= sztab[dest]szext; \ 00055 _BWcur_##ptr <<= -_BWleft_##ptr; \ 00056 _BWleft_##ptr += 32; \ 00057 } \ 00058 else _BWleft_##ptr = 32; \ 00059 } \ 00060 else { \ 00061 _BWleft_##ptr = _BWtmp_##ptr; \ 00062 _BWcur_##ptr <<= sztab[dest]szext; \ 00063 } \ 00064 } while (0) 00065 00066 00067 #define SPEG_BW_START_WR(ptr) \ 00068 int _BWleft_##ptr = 32 - (((int)ptr & 3) << 3); \ 00069 u_int32_t _BWcur_##ptr = ntohl(*(u_int32_t*)(ptr -= (int)ptr & 3)) >> _BWleft_##ptr 00070 00071 #define SPEG_BW_END_WR(ptr) \ 00072 do { \ 00073 if (_BWleft_##ptr != 32) { \ 00074 _BWcur_##ptr <<= _BWleft_##ptr; \ 00075 _BWcur_##ptr |= (ntohl(*(u_int32_t*)ptr) & (((u_int32_t)1 << _BWleft_##ptr) - 1)); \ 00076 *(u_int32_t*)ptr = htonl(_BWcur_##ptr); \ 00077 (ptr += (39 - _BWleft_##ptr) >> 3); \ 00078 } \ 00079 } while (0) 00080 00081 #define SPEG_BW_END_WR_CLEAN(ptr) \ 00082 do { \ 00083 if (_BWleft_##ptr != 32) { \ 00084 _BWcur_##ptr <<= _BWleft_##ptr; \ 00085 *(u_int32_t*)ptr = htonl(_BWcur_##ptr); \ 00086 (ptr += (39 - _BWleft_##ptr) >> 3); \ 00087 } \ 00088 } while (0) 00089 00090 #define SPEG_BW_PUTN(ptr, src, n) \ 00091 do { \ 00092 int _BWtmp_##ptr = _BWleft_##ptr; \ 00093 u_int32_t _BWsav_##ptr; \ 00094 if ((_BWleft_##ptr -= n) < 0) { \ 00095 _BWsav_##ptr = (_BWcur_##ptr << _BWtmp_##ptr) | \ 00096 (src >> -_BWleft_##ptr); \ 00097 } \ 00098 else if (n == 32) \ 00099 _BWsav_##ptr = src; \ 00100 else \ 00101 _BWsav_##ptr = (_BWcur_##ptr << n) | src; \ 00102 if (_BWleft_##ptr <= 0) { \ 00103 _BWcur_##ptr = src; \ 00104 *(u_int32_t*)ptr = htonl(_BWsav_##ptr); \ 00105 ptr += 4; \ 00106 _BWleft_##ptr += 32; \ 00107 } \ 00108 else _BWcur_##ptr = _BWsav_##ptr; \ 00109 } while (0) 00110

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8