static void decode(VMPM *vmpm) { Arithcoder *ac; Arithmodel *am; Arithmodel *bin_am; unsigned int *index_to_symbol; int i, n; unsigned int j; //debug_message_fn("()\n"); fatal("DECODING IS INVALID. NEED REIMPLEMENTATION.\n"); ac = arithcoder_arith_create(); arithcoder_decode_init(ac, vmpm->infile); am = arithmodel_order_zero_create(); arithmodel_decode_init(am, ac); bin_am = arithmodel_order_zero_create(); arithmodel_decode_init(bin_am, ac); i = fgetc(vmpm->outfile); vmpm->token_index[i] = vmpm->blocksize / ipow(vmpm->r, i); for (; i >= 1; i--) { unsigned int nsymbols = 0; stat_message(vmpm, "D:Level %d (%d tokens, %d distinct): ", i, vmpm->token_index[i], vmpm->newtoken[i] - 1); vmpm->token_index[i - 1] = 0; if ((vmpm->tokens[i] = calloc(vmpm->token_index[i], sizeof(Token))) == NULL) memory_error(NULL, MEMORY_ERROR); /* Decode escape symbols at once. */ arithmodel_order_zero_reset(bin_am, 0, 0); arithmodel_install_symbol(bin_am, 1); arithmodel_install_symbol(bin_am, 1); for (j = 0; j < vmpm->token_index[i]; j++) { Index idx; arithmodel_decode(bin_am, &idx); if (idx) { nsymbols++; vmpm->token[i][j]->value = nsymbols; } else { vmpm->token[i][j]->value = 0; } } /* Then decode non-escape symbols. */ arithmodel_order_zero_reset(bin_am, 0, 0); arithmodel_install_symbol(bin_am, 1); arithmodel_install_symbol(bin_am, 1); for (j = 0; j < vmpm->token_index[i]; j++) { if (vmpm->token[i][j]->value == 0) { Token_value tv; arithmodel_decode_cbt(bin_am, &tv, nsymbols - 1, 0, 1); vmpm->token[i][j]->value = tv + 1; stat_message(vmpm, "%d ", tv); } else { nsymbols++; stat_message(vmpm, "e "); } } stat_message(vmpm, "\n"); vmpm->token_index[i - 1] = nsymbols * vmpm->r; } if ((index_to_symbol = calloc(vmpm->alphabetsize, sizeof(unsigned int))) == NULL) memory_error(NULL, MEMORY_ERROR); n = 0; arithmodel_order_zero_reset(am, 0, vmpm->alphabetsize - 1); stat_message(vmpm, "D:Level 0 (%d tokens): ", vmpm->token_index[0]); for (j = 0; j < vmpm->token_index[0]; j++) { Index v; if (arithmodel_decode(am, &v) == 2) { arithmodel_decode_bits(bin_am, &vmpm->tokens[0][j].value, vmpm->bits_per_symbol, 0, 1); index_to_symbol[n++] = vmpm->tokens[0][j].value; stat_message(vmpm, "e "); } else { vmpm->tokens[0][j].value = index_to_symbol[v]; stat_message(vmpm, "%d ", v); } } stat_message(vmpm, "\n"); free(index_to_symbol); arithcoder_decode_final(ac); arithmodel_destroy(am); arithcoder_destroy(ac); }
static void decode(VMPM *vmpm) { Arithcoder *ac; Arithmodel *am; Arithmodel *bin_am; unsigned int *index_to_symbol; int i, n; unsigned int j; //debug_message_fn("()\n"); fatal("DECODING IS INVALID. NEED REIMPLEMENTATION.\n"); ac = arithcoder_arith_create(); am = arithmodel_order_zero_create(); arithcoder_decode_init(ac, vmpm->infile); arithmodel_decode_init(am, ac); bin_am = arithmodel_order_zero_create(); arithmodel_decode_init(bin_am, ac); arithmodel_install_symbol(bin_am, 1); arithmodel_install_symbol(bin_am, 1); vmpm->token_index[vmpm->I] = vmpm->blocksize / ipow(vmpm->r, vmpm->I); for (i = vmpm->I; i >= 1; i--) { stat_message(vmpm, "Level %d: %d\n", i, vmpm->token_index[i]); vmpm->token_index[i - 1] = 0; if ((vmpm->tokens[i] = calloc(vmpm->token_index[i], sizeof(Token))) == NULL) memory_error(NULL, MEMORY_ERROR); /* newtoken[] will not be known by decoder without sending. */ //arithmodel_order_zero_reset(am, 1, vmpm->newtoken[i]); arithmodel_order_zero_reset(am, 1, vmpm->token_index[i] >> 2); for (j = 0; j < vmpm->token_index[i]; j++) { Index idx; arithmodel_decode(am, &idx); vmpm->tokens[i][j].value++; if (vmpm->tokens[i][j].value > vmpm->token_index[i - 1]) { if (vmpm->tokens[i][j].value == vmpm->token_index[i - 1] + 1) vmpm->token_index[i - 1]++; else generic_error((char *)"Invalid token value.\n", INVALID_TOKEN_VALUE_ERROR); } } vmpm->token_index[i - 1] *= vmpm->r; } if ((index_to_symbol = calloc(vmpm->alphabetsize, sizeof(unsigned int))) == NULL) memory_error(NULL, MEMORY_ERROR); n = 0; stat_message(vmpm, "Level 0: %d\n", vmpm->token_index[0]); for (j = 0; j < vmpm->token_index[0]; j++) { Index v; if (arithmodel_decode(am, &v) == 2) { arithmodel_decode_bits(bin_am, &vmpm->tokens[0][j].value, vmpm->bits_per_symbol, 0, 1); index_to_symbol[n++] = vmpm->tokens[0][j].value; } else { vmpm->tokens[0][j].value = index_to_symbol[v]; } } free(index_to_symbol); arithcoder_decode_final(ac); arithmodel_destroy(am); arithcoder_destroy(ac); }
static void decode(VMPM *vmpm) { Arithcoder *ac; Arithmodel *am; Arithmodel *bin_am; unsigned int *index_to_symbol; int i, n; unsigned int j; //debug_message_fn("()\n"); ac = arithcoder_arith_create(); arithcoder_decode_init(ac, vmpm->infile); am = arithmodel_order_zero_create(); arithmodel_decode_init(am, ac); bin_am = arithmodel_order_zero_create(); arithmodel_decode_init(bin_am, ac); i = fgetc(vmpm->outfile); vmpm->token_index[i] = vmpm->blocksize / ipow(vmpm->r, i); for (; i >= 1; i--) { unsigned int tmp; arithmodel_order_zero_reset(bin_am, 0, 0); arithmodel_install_symbol(bin_am, 1); arithmodel_install_symbol(bin_am, 1); arithmodel_decode_cbt(bin_am, &tmp, vmpm->token_index[i], 0, 1); vmpm->newtoken[i] = tmp + 1; stat_message(vmpm, "D:Level %d (%d tokens, %d distinct): ", i, vmpm->token_index[i], vmpm->newtoken[i] - 1); vmpm->token_index[i - 1] = 0; if ((vmpm->tokens[i] = calloc(vmpm->token_index[i], sizeof(Token))) == NULL) memory_error(NULL, MEMORY_ERROR); arithmodel_order_zero_reset(am, 0, vmpm->newtoken[i]); vmpm->tokens[i][0].value = 1; for (j = 1; j < vmpm->token_index[i]; j++) { Index idx; arithmodel_decode(am, &idx); vmpm->tokens[i][j].value = idx + 1; if (vmpm->tokens[i][j].value > vmpm->token_index[i - 1]) { if (vmpm->tokens[i][j].value == vmpm->token_index[i - 1] + 1) { stat_message(vmpm, "e "); vmpm->token_index[i - 1]++; } else generic_error((char *)"Invalid token value.\n", INVALID_TOKEN_VALUE_ERROR); } else { stat_message(vmpm, "%d ", idx); } } vmpm->token_index[i - 1] *= vmpm->r; stat_message(vmpm, "\n"); } if ((index_to_symbol = calloc(vmpm->alphabetsize, sizeof(unsigned int))) == NULL) memory_error(NULL, MEMORY_ERROR); n = 0; arithmodel_order_zero_reset(am, 0, vmpm->alphabetsize - 1); arithmodel_order_zero_reset(bin_am, 0, 0); arithmodel_install_symbol(bin_am, 1); arithmodel_install_symbol(bin_am, 1); stat_message(vmpm, "D:Level 0 (%d tokens): ", vmpm->token_index[0]); for (j = 0; j < vmpm->token_index[0]; j++) { Index v; if (arithmodel_decode(am, &v) == 2) { stat_message(vmpm, "e "); arithmodel_decode_bits(bin_am, &vmpm->tokens[0][j].value, vmpm->bits_per_symbol, 0, 1); index_to_symbol[n++] = vmpm->tokens[0][j].value; } else { vmpm->tokens[0][j].value = index_to_symbol[v]; stat_message(vmpm, "%d ", v); } } stat_message(vmpm, "\n"); free(index_to_symbol); arithcoder_decode_final(ac); arithmodel_destroy(bin_am); arithmodel_destroy(am); arithcoder_destroy(ac); }