michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: #include "entropy.h" michael@0: #include "blockd.h" michael@0: #include "onyxc_int.h" michael@0: #include "vpx_mem/vpx_mem.h" michael@0: michael@0: #include "coefupdateprobs.h" michael@0: michael@0: DECLARE_ALIGNED(16, const unsigned char, vp8_norm[256]) = michael@0: { michael@0: 0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, michael@0: 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, michael@0: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, michael@0: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, michael@0: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, michael@0: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, michael@0: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, michael@0: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, michael@0: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, michael@0: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, michael@0: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, michael@0: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, michael@0: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, michael@0: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, michael@0: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, michael@0: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 michael@0: }; michael@0: michael@0: DECLARE_ALIGNED(16, const unsigned char, vp8_coef_bands[16]) = michael@0: { 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7}; michael@0: michael@0: DECLARE_ALIGNED(16, const unsigned char, michael@0: vp8_prev_token_class[MAX_ENTROPY_TOKENS]) = michael@0: { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0}; michael@0: michael@0: DECLARE_ALIGNED(16, const int, vp8_default_zig_zag1d[16]) = michael@0: { michael@0: 0, 1, 4, 8, michael@0: 5, 2, 3, 6, michael@0: 9, 12, 13, 10, michael@0: 7, 11, 14, 15, michael@0: }; michael@0: michael@0: DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]) = michael@0: { michael@0: 1, 2, 6, 7, michael@0: 3, 5, 8, 13, michael@0: 4, 9, 12, 14, michael@0: 10, 11, 15, 16 michael@0: }; michael@0: michael@0: /* vp8_default_zig_zag_mask generated with: michael@0: michael@0: void vp8_init_scan_order_mask() michael@0: { michael@0: int i; michael@0: michael@0: for (i = 0; i < 16; i++) michael@0: { michael@0: vp8_default_zig_zag_mask[vp8_default_zig_zag1d[i]] = 1 << i; michael@0: } michael@0: michael@0: } michael@0: */ michael@0: DECLARE_ALIGNED(16, const short, vp8_default_zig_zag_mask[16]) = michael@0: { michael@0: 1, 2, 32, 64, michael@0: 4, 16, 128, 4096, michael@0: 8, 256, 2048, 8192, michael@0: 512, 1024, 16384, -32768 michael@0: }; michael@0: michael@0: const int vp8_mb_feature_data_bits[MB_LVL_MAX] = {7, 6}; michael@0: michael@0: /* Array indices are identical to previously-existing CONTEXT_NODE indices */ michael@0: michael@0: const vp8_tree_index vp8_coef_tree[ 22] = /* corresponding _CONTEXT_NODEs */ michael@0: { michael@0: -DCT_EOB_TOKEN, 2, /* 0 = EOB */ michael@0: -ZERO_TOKEN, 4, /* 1 = ZERO */ michael@0: -ONE_TOKEN, 6, /* 2 = ONE */ michael@0: 8, 12, /* 3 = LOW_VAL */ michael@0: -TWO_TOKEN, 10, /* 4 = TWO */ michael@0: -THREE_TOKEN, -FOUR_TOKEN, /* 5 = THREE */ michael@0: 14, 16, /* 6 = HIGH_LOW */ michael@0: -DCT_VAL_CATEGORY1, -DCT_VAL_CATEGORY2, /* 7 = CAT_ONE */ michael@0: 18, 20, /* 8 = CAT_THREEFOUR */ michael@0: -DCT_VAL_CATEGORY3, -DCT_VAL_CATEGORY4, /* 9 = CAT_THREE */ michael@0: -DCT_VAL_CATEGORY5, -DCT_VAL_CATEGORY6 /* 10 = CAT_FIVE */ michael@0: }; michael@0: michael@0: /* vp8_coef_encodings generated with: michael@0: vp8_tokens_from_tree(vp8_coef_encodings, vp8_coef_tree); michael@0: */ michael@0: vp8_token vp8_coef_encodings[MAX_ENTROPY_TOKENS] = michael@0: { michael@0: {2, 2}, michael@0: {6, 3}, michael@0: {28, 5}, michael@0: {58, 6}, michael@0: {59, 6}, michael@0: {60, 6}, michael@0: {61, 6}, michael@0: {124, 7}, michael@0: {125, 7}, michael@0: {126, 7}, michael@0: {127, 7}, michael@0: {0, 1} michael@0: }; michael@0: michael@0: /* Trees for extra bits. Probabilities are constant and michael@0: do not depend on previously encoded bits */ michael@0: michael@0: static const vp8_prob Pcat1[] = { 159}; michael@0: static const vp8_prob Pcat2[] = { 165, 145}; michael@0: static const vp8_prob Pcat3[] = { 173, 148, 140}; michael@0: static const vp8_prob Pcat4[] = { 176, 155, 140, 135}; michael@0: static const vp8_prob Pcat5[] = { 180, 157, 141, 134, 130}; michael@0: static const vp8_prob Pcat6[] = michael@0: { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129}; michael@0: michael@0: michael@0: /* tree index tables generated with: michael@0: michael@0: void init_bit_tree(vp8_tree_index *p, int n) michael@0: { michael@0: int i = 0; michael@0: michael@0: while (++i < n) michael@0: { michael@0: p[0] = p[1] = i << 1; michael@0: p += 2; michael@0: } michael@0: michael@0: p[0] = p[1] = 0; michael@0: } michael@0: michael@0: void init_bit_trees() michael@0: { michael@0: init_bit_tree(cat1, 1); michael@0: init_bit_tree(cat2, 2); michael@0: init_bit_tree(cat3, 3); michael@0: init_bit_tree(cat4, 4); michael@0: init_bit_tree(cat5, 5); michael@0: init_bit_tree(cat6, 11); michael@0: } michael@0: */ michael@0: michael@0: static const vp8_tree_index cat1[2] = { 0, 0 }; michael@0: static const vp8_tree_index cat2[4] = { 2, 2, 0, 0 }; michael@0: static const vp8_tree_index cat3[6] = { 2, 2, 4, 4, 0, 0 }; michael@0: static const vp8_tree_index cat4[8] = { 2, 2, 4, 4, 6, 6, 0, 0 }; michael@0: static const vp8_tree_index cat5[10] = { 2, 2, 4, 4, 6, 6, 8, 8, 0, 0 }; michael@0: static const vp8_tree_index cat6[22] = { 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, michael@0: 14, 14, 16, 16, 18, 18, 20, 20, 0, 0 }; michael@0: michael@0: const vp8_extra_bit_struct vp8_extra_bits[12] = michael@0: { michael@0: { 0, 0, 0, 0}, michael@0: { 0, 0, 0, 1}, michael@0: { 0, 0, 0, 2}, michael@0: { 0, 0, 0, 3}, michael@0: { 0, 0, 0, 4}, michael@0: { cat1, Pcat1, 1, 5}, michael@0: { cat2, Pcat2, 2, 7}, michael@0: { cat3, Pcat3, 3, 11}, michael@0: { cat4, Pcat4, 4, 19}, michael@0: { cat5, Pcat5, 5, 35}, michael@0: { cat6, Pcat6, 11, 67}, michael@0: { 0, 0, 0, 0} michael@0: }; michael@0: michael@0: #include "default_coef_probs.h" michael@0: michael@0: void vp8_default_coef_probs(VP8_COMMON *pc) michael@0: { michael@0: vpx_memcpy(pc->fc.coef_probs, default_coef_probs, michael@0: sizeof(default_coef_probs)); michael@0: } michael@0: