?? matrices.c
字號:
*/ for (row = wfa->basis_states; row <= last_row; row++) { unsigned count; /* value in the current interval */ /* * Read label 0 element */ if (isrange (*is_leaf++)) /* valid matrix index */ { count = high - ((high - low) >> *prob_ptr); if (code < count) { if (prob_ptr < last) /* model update */ prob_ptr++; /* * Decode the MPS '0' */ high = count - 1; RESCALE_INPUT_INTERVAL; } else { prob_ptr = ((prob_ptr - first) >> 1) + first; /* model update */ /* * Decode the LPS '1' */ low = count; RESCALE_INPUT_INTERVAL; /* * Restore the transition (weight = -1) */ append_edge (row, 0, -1, 0, wfa); total++; } } /* * Read label 1 element */ if (isrange (*is_leaf++)) /* valid matrix index */ { count = high - ((high - low) >> *prob_ptr); if (code < count) { if (prob_ptr < last) prob_ptr++; /* model update */ /* * Decode the MPS '0' */ high = count - 1; RESCALE_INPUT_INTERVAL; } else { prob_ptr = ((prob_ptr - first) >> 1) + first; /* model update */ /* * Decode the LPS '1' */ low = count; RESCALE_INPUT_INTERVAL; /* * Restore the transition (weight = -1) */ append_edge (row, 0, -1, 1, wfa); total++; } } } INPUT_BYTE_ALIGN (input); Free (prob); return total;}static unsignedchroma_decoding (wfa_t *wfa, bitfile_t *input)/* * Read transition matrices of 'wfa' states which are part of the * chroma channels Cb and Cr from stream 'input'. * * Return value: * number of non-zero matrix elements (WFA edges) * * Side effects: * 'wfa->into' is filled with decoded values */{ unsigned domain; /* current domain, counter */ unsigned total = 0; /* total number of chroma edges */ unsigned *prob_ptr; /* pointer to current probability */ unsigned *last; /* pointer to minimum probability */ unsigned *first; /* pointer to maximum probability */ unsigned *new_prob_ptr; /* ptr to probability of last domain */ unsigned *prob; /* probability array */ u_word_t high; /* Start of the current code range */ u_word_t low; /* End of the current code range */ u_word_t code; /* The present input code value */ word_t *y_domains; /* domain images corresponding to Y */ int save_index; /* YES: store current probabilty */ /* * Compute the asymmetric probability array * prob[] = { 1/2, 1/2, 1/4, 1/4, 1/4, 1/4, * 1/8, ... , 1/16, ..., 1/(MAXPROB+1)} */ { unsigned n; unsigned index; /* probability index */ unsigned exp; /* current exponent */ prob = Calloc (1 << (MAX_PROB + 1), sizeof (unsigned)); for (index = 0, n = MIN_PROB; n <= MAX_PROB; n++) for (exp = 0; exp < 1U << n; exp++, index++) prob [index] = n; } high = HIGH; /* 1.0 */ low = LOW; /* 0.0 */ code = get_bits (input, 16); /* * Compute list of admitted domains */ y_domains = compute_hits (wfa->basis_states, wfa->tree [wfa->tree [wfa->root_state][0]][0], wfa->wfainfo->chroma_max_states, wfa); first = prob_ptr = new_prob_ptr = prob; last = first + 1020; /* * First of all, read all matrix columns given in the list 'y_domains' * which note all admitted domains. * These matrix elements are stored with QAC (see column_0_decoding ()). */ for (domain = 0; y_domains [domain] != -1; domain++) { unsigned row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; word_t *is_leaf = wfa->tree [row]; prob_ptr = new_prob_ptr; save_index = YES; for (; row < wfa->states; row++) { unsigned count; /* value in the current interval */ /* * Read label 0 element */ if (isrange (*is_leaf++)) /* valid matrix index */ { count = high - ((high - low) >> *prob_ptr); if (code < count) { if (prob_ptr < last) prob_ptr++; /* * Decode the MPS '0' */ high = count - 1; RESCALE_INPUT_INTERVAL; } else { prob_ptr = ((prob_ptr - first) >> 1) + first; /* * Decode the LPS '1' */ low = count; RESCALE_INPUT_INTERVAL; /* * Restore the transition (weight = -1) */ append_edge (row, y_domains [domain], -1, 0, wfa); total++; } } /* * Read label 1 element */ if (isrange (*is_leaf++)) /* valid matrix index */ { count = high - ((high - low) >> *prob_ptr); if (code < count) { if (prob_ptr < last) prob_ptr++; /* * Decode the MPS '0' */ high = count - 1; RESCALE_INPUT_INTERVAL; } else { prob_ptr = ((prob_ptr - first) >> 1) + first; /* * Decode the LPS '1' */ low = count; RESCALE_INPUT_INTERVAL; /* * Restore the transition (weight = -1) */ append_edge (row, y_domains [domain], -1, 1, wfa); total++; } } if (save_index) { save_index = NO; new_prob_ptr = prob_ptr; } } } Free (y_domains); compute_y_state (wfa->tree [wfa->tree [wfa->root_state][0]][1], wfa->tree [wfa->tree [wfa->root_state][0]][0], wfa); compute_y_state (wfa->tree [wfa->tree [wfa->root_state][1]][0], wfa->tree [wfa->tree [wfa->root_state][0]][0], wfa); first = prob_ptr = new_prob_ptr = prob; /* * Decode the additional column which indicates whether there * are transitions to a state with same spatial coordinates * in the Y component. * * Again, quasi arithmetic decoding is used for this task. */ { unsigned row; for (row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; row < wfa->states; row++) { int label; /* current label */ for (label = 0; label < MAXLABELS; label++) { u_word_t count = high - ((high - low) >> *prob_ptr); if (code < count) { if (prob_ptr < last) prob_ptr++; /* * Decode the MPS '0' */ high = count - 1; RESCALE_INPUT_INTERVAL; } else { prob_ptr = ((prob_ptr - first) >> 1) + first; /* * Decode the LPS '1' */ low = count; RESCALE_INPUT_INTERVAL; /* * Restore the transition (weight = -1) */ append_edge (row, wfa->y_state [row][label], -1, label, wfa); total++; } } } } INPUT_BYTE_ALIGN (input); Free (prob); return total;}static voidcompute_y_state (int state, int y_state, wfa_t *wfa)/* * Compute the 'wfa->y_state' array which denotes those states of * the Y band that have the same spatial coordinates as the corresponding * states of the Cb and Cr bands. * The current root of the Y tree is given by 'y_state'. * The current root of the tree of the chroma channel is given by 'state'. * * No return value. * * Side effects: * 'wfa->y_state' is filled with the generated tree structure. */{ unsigned label; for (label = 0; label < MAXLABELS; label++) if (isrange (y_state)) wfa->y_state [state][label] = RANGE; else { wfa->y_state [state][label] = wfa->tree [y_state][label]; if (!isrange (wfa->tree [state][label])) compute_y_state (wfa->tree [state][label], wfa->y_state [state][label], wfa); } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -