00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef OPJ_MQC_INL_H
00040 #define OPJ_MQC_INL_H
00041
00042
00043 #define opj_mqc_mpsexchange_macro(d, curctx, a) \
00044 { \
00045 if (a < (*curctx)->qeval) { \
00046 d = !((*curctx)->mps); \
00047 *curctx = (*curctx)->nlps; \
00048 } else { \
00049 d = (*curctx)->mps; \
00050 *curctx = (*curctx)->nmps; \
00051 } \
00052 }
00053
00054
00055 #define opj_mqc_lpsexchange_macro(d, curctx, a) \
00056 { \
00057 if (a < (*curctx)->qeval) { \
00058 a = (*curctx)->qeval; \
00059 d = (*curctx)->mps; \
00060 *curctx = (*curctx)->nmps; \
00061 } else { \
00062 a = (*curctx)->qeval; \
00063 d = !((*curctx)->mps); \
00064 *curctx = (*curctx)->nlps; \
00065 } \
00066 }
00067
00068
00074 static INLINE OPJ_UINT32 opj_mqc_raw_decode(opj_mqc_t *mqc)
00075 {
00076 OPJ_UINT32 d;
00077 if (mqc->ct == 0) {
00078
00079
00080 if (mqc->c == 0xff) {
00081 if (*mqc->bp > 0x8f) {
00082 mqc->c = 0xff;
00083 mqc->ct = 8;
00084 } else {
00085 mqc->c = *mqc->bp;
00086 mqc->bp ++;
00087 mqc->ct = 7;
00088 }
00089 } else {
00090 mqc->c = *mqc->bp;
00091 mqc->bp ++;
00092 mqc->ct = 8;
00093 }
00094 }
00095 mqc->ct--;
00096 d = ((OPJ_UINT32)mqc->c >> mqc->ct) & 0x01U;
00097
00098 return d;
00099 }
00100
00101
00102 #define opj_mqc_bytein_macro(mqc, c, ct) \
00103 { \
00104 OPJ_UINT32 l_c; \
00105 \
00106 \
00107 l_c = *(mqc->bp + 1); \
00108 if (*mqc->bp == 0xff) { \
00109 if (l_c > 0x8f) { \
00110 c += 0xff00; \
00111 ct = 8; \
00112 mqc->end_of_byte_stream_counter ++; \
00113 } else { \
00114 mqc->bp++; \
00115 c += l_c << 9; \
00116 ct = 7; \
00117 } \
00118 } else { \
00119 mqc->bp++; \
00120 c += l_c << 8; \
00121 ct = 8; \
00122 } \
00123 }
00124
00125
00126 #define opj_mqc_renormd_macro(mqc, a, c, ct) \
00127 { \
00128 do { \
00129 if (ct == 0) { \
00130 opj_mqc_bytein_macro(mqc, c, ct); \
00131 } \
00132 a <<= 1; \
00133 c <<= 1; \
00134 ct--; \
00135 } while (a < 0x8000); \
00136 }
00137
00138 #define opj_mqc_decode_macro(d, mqc, curctx, a, c, ct) \
00139 { \
00140 \
00141 \
00142 \
00143 \
00144 a -= (*curctx)->qeval; \
00145 if ((c >> 16) < (*curctx)->qeval) { \
00146 opj_mqc_lpsexchange_macro(d, curctx, a); \
00147 opj_mqc_renormd_macro(mqc, a, c, ct); \
00148 } else { \
00149 c -= (*curctx)->qeval << 16; \
00150 if ((a & 0x8000) == 0) { \
00151 opj_mqc_mpsexchange_macro(d, curctx, a); \
00152 opj_mqc_renormd_macro(mqc, a, c, ct); \
00153 } else { \
00154 d = (*curctx)->mps; \
00155 } \
00156 } \
00157 }
00158
00159 #define DOWNLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct) \
00160 register const opj_mqc_state_t **curctx = mqc->curctx; \
00161 register OPJ_UINT32 c = mqc->c; \
00162 register OPJ_UINT32 a = mqc->a; \
00163 register OPJ_UINT32 ct = mqc->ct
00164
00165 #define UPLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct) \
00166 mqc->curctx = curctx; \
00167 mqc->c = c; \
00168 mqc->a = a; \
00169 mqc->ct = ct;
00170
00175 static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc)
00176 {
00177 opj_mqc_bytein_macro(mqc, mqc->c, mqc->ct);
00178 }
00179
00184 #define opj_mqc_renormd(mqc) \
00185 opj_mqc_renormd_macro(mqc, mqc->a, mqc->c, mqc->ct)
00186
00193 #define opj_mqc_decode(d, mqc) \
00194 opj_mqc_decode_macro(d, mqc, mqc->curctx, mqc->a, mqc->c, mqc->ct)
00195
00196 #endif