ref: 0aa79be7d52d583aab3058e9435398c4e99f3708
parent: 70d9f116fd90f130ec7798b16c2083c9e3853050
author: Deb Mukherjee <[email protected]>
date: Mon Apr 22 06:58:49 EDT 2013
Removes the code_nonzerocount experiment This patch does not seem to give any benefits. Change-Id: I9d2b4091d6af3dfc0875f24db86c01e2de57f8db
--- a/configure
+++ b/configure
@@ -243,7 +243,6 @@
newbintramodes
comp_interintra_pred
enable_6tap
- code_nonzerocount
modelcoefprob
loop_dering
implicit_compoundinter_weight
--- a/vp9/common/vp9_blockd.h
+++ b/vp9/common/vp9_blockd.h
@@ -282,9 +282,6 @@
INTERPOLATIONFILTERTYPE interp_filter;
BLOCK_SIZE_TYPE sb_type;
-#if CONFIG_CODE_NONZEROCOUNT
- uint16_t nzcs[256+64*2];
-#endif
} MB_MODE_INFO;
typedef struct {
@@ -363,9 +360,6 @@
BLOCK_OFFSET((x)->plane[2].field, ((i) - 20), 16))
typedef struct macroblockd {
-#if CONFIG_CODE_NONZEROCOUNT
- DECLARE_ALIGNED(16, uint16_t, nzcs[256+64*2]);
-#endif
struct mb_plane plane[MAX_MB_PLANE];
/* 16 Y blocks, 4 U, 4 V, each with 16 entries. */
@@ -752,12 +746,6 @@
return size;
}
-
-#if CONFIG_CODE_NONZEROCOUNT
-static int get_nzc_used(TX_SIZE tx_size) {
- return (tx_size >= TX_16X16);
-}
-#endif
struct plane_block_idx {
int plane;
--- a/vp9/common/vp9_coefupdateprobs.h
+++ b/vp9/common/vp9_coefupdateprobs.h
@@ -18,14 +18,6 @@
252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252
};
-#if CONFIG_CODE_NONZEROCOUNT
-#define NZC_UPDATE_PROB_4X4 252
-#define NZC_UPDATE_PROB_8X8 252
-#define NZC_UPDATE_PROB_16X16 252
-#define NZC_UPDATE_PROB_32X32 252
-#define NZC_UPDATE_PROB_PCAT 252
-#endif
-
#if CONFIG_CODE_ZEROGROUP
#define ZPC_UPDATE_PROB 248
#endif
--- a/vp9/common/vp9_default_coef_probs.h
+++ b/vp9/common/vp9_default_coef_probs.h
@@ -700,302 +700,6 @@
}
};
-#if CONFIG_CODE_NONZEROCOUNT
-
-// TODO(debargha): Remove the macro and count tables after experimentation
-#define NZC_DEFAULT_COUNTS /* Uncomment to use counts as defaults */
-
-#ifdef NZC_DEFAULT_COUNTS
-static const unsigned int default_nzc_counts_4x4[MAX_NZC_CONTEXTS]
- [REF_TYPES]
- [BLOCK_TYPES]
- [NZC4X4_TOKENS] = {
- {
- {
- { 967652, 29023, 15039, 6952, 1568, 116 },
- { 289116, 22938, 4522, 1935, 520, 47 }
- }, {
- { 967652, 29023, 15039, 6952, 1568, 116 },
- { 689116, 22938, 4522, 1935, 520, 47 }
- },
- }, {
- {
- { 124684, 37167, 15270, 8483, 1777, 102 },
- { 10405, 12395, 3401, 3574, 2461, 771 }
- }, {
- { 124684, 37167, 15270, 8483, 1777, 102 },
- { 20405, 12395, 3401, 3574, 2461, 771 }
- }
- }, {
- {
- { 4100, 22976, 15627, 16137, 7982, 1793 },
- { 4249, 3084, 2131, 4081, 6439, 1653 }
- }, {
- { 21100, 22976, 15627, 16137, 7982, 1793 },
- { 4249, 3084, 2131, 4081, 2439, 1653 }
- }
- }
-};
-
-static const unsigned int default_nzc_counts_8x8[MAX_NZC_CONTEXTS]
- [REF_TYPES]
- [BLOCK_TYPES]
- [NZC8X8_TOKENS] = {
- {
- {
- { 372988, 62777, 19440, 11812, 5145, 1917, 439, 10 },
- { 72052, 30468, 6973, 3250, 1500, 750, 375, 5 },
- }, {
- { 372988, 62777, 19440, 11812, 5145, 1917, 439, 10 },
- { 192052, 30468, 6973, 3250, 1500, 750, 375, 5 },
- }
- }, {
- {
- { 121533, 33527, 15655, 11920, 5723, 2009, 315, 7 },
- { 23772, 23120, 13127, 8115, 4000, 2000, 200, 6 },
- }, {
- { 121533, 33527, 15655, 11920, 5723, 2009, 315, 7 },
- { 23772, 23120, 13127, 8115, 4000, 2000, 200, 6 },
- }
- }, {
- {
- { 29408, 11758, 8023, 10123, 6705, 2468, 369, 17 },
- { 11612, 13874, 13329, 13022, 6500, 3250, 300, 12 },
- }, {
- { 29408, 11758, 8023, 10123, 6705, 2468, 369, 17 },
- { 11612, 13874, 13329, 13022, 6500, 3250, 300, 12 },
- }
- }
-};
-
-static const unsigned int default_nzc_counts_16x16[MAX_NZC_CONTEXTS]
- [REF_TYPES]
- [BLOCK_TYPES]
- [NZC16X16_TOKENS] = {
- {
- {
- { 372988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2 },
- { 72052, 30468, 6973, 3250, 1500, 750, 375, 50, 8, 1 },
- }, {
- { 32988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2 },
- { 92052, 30468, 6973, 3250, 1500, 750, 375, 50, 8, 1 },
- }
- }, {
- {
- { 21533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2 },
- { 47772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2 },
- }, {
- { 21533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2 },
- { 27772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2 },
- }
- }, {
- {
- { 19408, 31758, 16023, 10123, 6705, 2468, 369, 17, 10, 5 },
- { 9612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3 },
- }, {
- { 22408, 11758, 8023, 10123, 6705, 2468, 369, 17, 10, 5 },
- { 9612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3 },
- }
- }
-};
-
-static const unsigned int default_nzc_counts_32x32[MAX_NZC_CONTEXTS]
- [REF_TYPES]
- [BLOCK_TYPES]
- [NZC32X32_TOKENS] = {
- {
- {
- { 72988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2, 1, 0 },
- { 52052, 30468, 6973, 3250, 1500, 750, 375, 50, 8, 1, 0, 0 },
- }, {
- { 72988, 62777, 19440, 11812, 5145, 1917, 439, 10, 5, 2, 1, 0 },
- { 72052, 30468, 6973, 3250, 1500, 750, 375, 50, 8, 1, 0, 0 },
- }
- }, {
- {
- { 21533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2, 1, 0 },
- { 27772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2, 1, 0 },
- }, {
- { 21533, 33527, 15655, 11920, 5723, 2009, 315, 7, 4, 2, 1, 0 },
- { 27772, 23120, 13127, 8115, 4000, 2000, 200, 6, 4, 2, 1, 0 },
- }
- }, {
- {
- { 19408, 11758, 8023, 10123, 6705, 2468, 369, 17, 10, 5, 2, 1 },
- { 9612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3, 2, 1 },
- }, {
- { 29408, 11758, 8023, 10123, 6705, 2468, 369, 17, 10, 5, 2, 1 },
- { 9612, 13874, 13329, 13022, 6500, 3250, 300, 12, 6, 3, 2, 1 },
- }
- }
-};
-
-#else
-
-static const vp9_prob default_nzc_probs_4x4[MAX_NZC_CONTEXTS]
- [REF_TYPES]
- [BLOCK_TYPES]
- [NZC4X4_TOKENS] = {
- {
- {
- { 219, 162, 179, 142, 242, },
- { 214, 253, 228, 246, 255, },
- }, {
- { 225, 236, 190, 229, 253, },
- { 251, 253, 240, 248, 255, },
- },
- }, {
- {
- { 106, 126, 158, 126, 244, },
- { 118, 241, 201, 240, 255, },
- }, {
- { 165, 179, 143, 189, 242, },
- { 173, 239, 192, 255, 128, },
- },
- }, {
- {
- { 42 , 78 , 153, 92 , 223, },
- { 128, 128, 128, 128, 128, },
- }, {
- { 76 , 68 , 126, 110, 216, },
- { 128, 128, 128, 128, 128, },
- },
- },
-};
-
-static const vp9_prob default_nzc_probs_8x8[MAX_NZC_CONTEXTS]
- [REF_TYPES]
- [BLOCK_TYPES]
- [NZC8X8_TOKENS] = {
- {
- {
- { 134, 139, 170, 178, 142, 197, 255, },
- { 167, 224, 199, 252, 205, 255, 128, },
- }, {
- { 181, 210, 180, 241, 190, 235, 255, },
- { 234, 251, 235, 252, 219, 255, 128, },
- },
- }, {
- {
- { 33 , 64 , 155, 143, 86 , 216, 255, },
- { 73 , 160, 167, 251, 153, 255, 128, },
- }, {
- { 79 , 104, 153, 195, 119, 246, 255, },
- { 149, 183, 186, 249, 203, 255, 128, },
- },
- }, {
- {
- { 10 , 25 , 156, 61 , 69 , 156, 254, },
- { 32 , 1 , 128, 146, 64 , 255, 128, },
- }, {
- { 37 , 48 , 143, 113, 81 , 202, 255, },
- { 1 , 255, 128, 128, 128, 128, 128, },
- },
- },
-};
-
-static const vp9_prob default_nzc_probs_16x16[MAX_NZC_CONTEXTS]
- [REF_TYPES]
- [BLOCK_TYPES]
- [NZC16X16_TOKENS] = {
- {
- {
- { 11 , 188, 210, 167, 141, 143, 152, 255, 128, },
- { 171, 201, 203, 244, 207, 255, 255, 128, 128, },
- }, {
- { 23 , 217, 207, 251, 198, 255, 219, 128, 128, },
- { 235, 249, 229, 255, 199, 128, 128, 128, 128, },
- },
- }, {
- {
- { 9 , 45 , 168, 85 , 66 , 221, 139, 246, 255, },
- { 51 , 110, 163, 238, 94 , 255, 255, 128, 128, },
- }, {
- { 4 , 149, 175, 240, 149, 255, 205, 128, 128, },
- { 141, 217, 186, 255, 128, 128, 128, 128, 128, },
- },
- }, {
- {
- { 1 , 12 , 173, 6 , 68 , 145, 41 , 204, 255, },
- { 39 , 47 , 128, 199, 110, 255, 128, 128, 128, },
- }, {
- { 1 , 121, 171, 149, 115, 242, 159, 255, 128, },
- { 1 , 255, 255, 128, 128, 128, 128, 128, 128, },
- },
- },
-};
-
-static const vp9_prob default_nzc_probs_32x32[MAX_NZC_CONTEXTS]
- [REF_TYPES]
- [BLOCK_TYPES]
- [NZC32X32_TOKENS] = {
- {
- {
- { 11 , 216, 195, 201, 160, 247, 217, 255, 255, 128, 128, },
- { 177, 240, 239, 255, 192, 128, 128, 128, 128, 128, 128, },
- }, {
- { 48 , 235, 213, 235, 199, 255, 255, 128, 128, 128, 128, },
- { 205, 255, 248, 128, 128, 128, 128, 128, 128, 128, 128, },
- },
- }, {
- {
- { 6 , 96 , 138, 99 , 125, 248, 188, 255, 128, 128, 128, },
- { 17 , 53 , 43 , 189, 1 , 255, 171, 128, 128, 128, 128, },
- }, {
- { 5 , 187, 235, 232, 117, 255, 219, 128, 128, 128, 128, },
- { 146, 255, 255, 128, 128, 128, 128, 128, 128, 128, 128, },
- },
- }, {
- {
- { 1 , 7 , 93 , 14 , 100, 30 , 85 , 65 , 81 , 210, 255, },
- { 1 , 1 , 128, 26 , 1 , 218, 78 , 255, 255, 128, 128, },
- }, {
- { 4 , 148, 206, 137, 160, 255, 255, 128, 128, 128, 128, },
- { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, },
- },
- },
-};
-#endif
-
-static const vp9_prob default_nzc_pcat_probs[MAX_NZC_CONTEXTS]
- [NZC_TOKENS_EXTRA]
- [NZC_BITS_EXTRA] = {
- // Bit probabilities are in least to most significance order
- {
- {176, 128, 128, 128, 128, 128, 128, 128, 128}, // 3 - 4
- {164, 192, 128, 128, 128, 128, 128, 128, 128}, // 5 - 8
- {154, 184, 208, 128, 128, 128, 128, 128, 128}, // 9 - 16
- {144, 176, 200, 216, 128, 128, 128, 128, 128}, // 17 - 32
- {140, 172, 192, 208, 224, 128, 128, 128, 128}, // 33 - 64
- {136, 168, 188, 200, 220, 232, 128, 128, 128}, // 65 - 128
- {132, 164, 184, 196, 216, 228, 240, 128, 128}, // 129 - 256
- {130, 162, 178, 194, 212, 226, 240, 248, 128}, // 257 - 512
- {128, 160, 176, 192, 208, 224, 240, 248, 254}, // 513 - 1024
- }, {
- {168, 128, 128, 128, 128, 128, 128, 128, 128}, // 3 - 4
- {152, 184, 128, 128, 128, 128, 128, 128, 128}, // 5 - 8
- {152, 184, 208, 128, 128, 128, 128, 128, 128}, // 9 - 16
- {144, 176, 200, 216, 128, 128, 128, 128, 128}, // 17 - 32
- {140, 172, 192, 208, 224, 128, 128, 128, 128}, // 33 - 64
- {136, 168, 188, 200, 220, 232, 128, 128, 128}, // 65 - 128
- {132, 164, 184, 196, 216, 228, 240, 128, 128}, // 129 - 256
- {130, 162, 178, 194, 212, 226, 240, 248, 128}, // 257 - 512
- {128, 160, 176, 192, 208, 224, 240, 248, 254}, // 513 - 1024
- }, {
- {160, 128, 128, 128, 128, 128, 128, 128, 128}, // 3 - 4
- {152, 176, 128, 128, 128, 128, 128, 128, 128}, // 5 - 8
- {150, 184, 208, 128, 128, 128, 128, 128, 128}, // 9 - 16
- {144, 176, 200, 216, 128, 128, 128, 128, 128}, // 17 - 32
- {140, 172, 192, 208, 224, 128, 128, 128, 128}, // 33 - 64
- {136, 168, 188, 200, 220, 232, 128, 128, 128}, // 65 - 128
- {132, 164, 184, 196, 216, 228, 240, 128, 128}, // 129 - 256
- {130, 162, 178, 194, 212, 226, 240, 248, 128}, // 257 - 512
- {128, 160, 176, 192, 208, 224, 240, 248, 254}, // 513 - 1024
- },
-};
-
-#endif // CONFIG_CODE_NONZEROCOUNT
-
#if CONFIG_CODE_ZEROGROUP
// There are two probs: the first is the prob(0) of the isolated zero bit,
--- a/vp9/common/vp9_entropy.c
+++ b/vp9/common/vp9_entropy.c
@@ -400,65 +400,6 @@
254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129
};
-#if CONFIG_CODE_NONZEROCOUNT
-const vp9_tree_index vp9_nzc4x4_tree[2 * NZC4X4_NODES] = {
- -NZC_0, 2,
- 4, 6,
- -NZC_1, -NZC_2,
- -NZC_3TO4, 8,
- -NZC_5TO8, -NZC_9TO16,
-};
-struct vp9_token vp9_nzc4x4_encodings[NZC4X4_TOKENS];
-
-const vp9_tree_index vp9_nzc8x8_tree[2 * NZC8X8_NODES] = {
- -NZC_0, 2,
- 4, 6,
- -NZC_1, -NZC_2,
- 8, 10,
- -NZC_3TO4, -NZC_5TO8,
- -NZC_9TO16, 12,
- -NZC_17TO32, -NZC_33TO64,
-};
-struct vp9_token vp9_nzc8x8_encodings[NZC8X8_TOKENS];
-
-const vp9_tree_index vp9_nzc16x16_tree[2 * NZC16X16_NODES] = {
- -NZC_0, 2,
- 4, 6,
- -NZC_1, -NZC_2,
- 8, 10,
- -NZC_3TO4, -NZC_5TO8,
- 12, 14,
- -NZC_9TO16, -NZC_17TO32,
- -NZC_33TO64, 16,
- -NZC_65TO128, -NZC_129TO256,
-};
-struct vp9_token vp9_nzc16x16_encodings[NZC16X16_TOKENS];
-
-const vp9_tree_index vp9_nzc32x32_tree[2 * NZC32X32_NODES] = {
- -NZC_0, 2,
- 4, 6,
- -NZC_1, -NZC_2,
- 8, 10,
- -NZC_3TO4, -NZC_5TO8,
- 12, 14,
- -NZC_9TO16, -NZC_17TO32,
- 16, 18,
- -NZC_33TO64, -NZC_65TO128,
- -NZC_129TO256, 20,
- -NZC_257TO512, -NZC_513TO1024,
-};
-struct vp9_token vp9_nzc32x32_encodings[NZC32X32_TOKENS];
-
-const int vp9_extranzcbits[NZC32X32_TOKENS] = {
- 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
-};
-
-const int vp9_basenzcvalue[NZC32X32_TOKENS] = {
- 0, 1, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513
-};
-
-#endif // CONFIG_CODE_NONZEROCOUNT
-
#if CONFIG_MODELCOEFPROB
#if UNCONSTRAINED_NODES == 2
@@ -1357,55 +1298,6 @@
#if CONFIG_MODELCOEFPROB
int b, r, c, p;
#endif
-#if CONFIG_CODE_NONZEROCOUNT
-#ifdef NZC_DEFAULT_COUNTS
- int h, g;
- for (h = 0; h < MAX_NZC_CONTEXTS; ++h) {
- for (g = 0; g < REF_TYPES; ++g) {
- int i;
- unsigned int branch_ct4x4[NZC4X4_NODES][2];
- unsigned int branch_ct8x8[NZC8X8_NODES][2];
- unsigned int branch_ct16x16[NZC16X16_NODES][2];
- unsigned int branch_ct32x32[NZC32X32_NODES][2];
- for (i = 0; i < BLOCK_TYPES; ++i) {
- vp9_tree_probs_from_distribution(
- vp9_nzc4x4_tree,
- pc->fc.nzc_probs_4x4[h][g][i], branch_ct4x4,
- default_nzc_counts_4x4[h][g][i], 0);
- }
- for (i = 0; i < BLOCK_TYPES; ++i) {
- vp9_tree_probs_from_distribution(
- vp9_nzc8x8_tree,
- pc->fc.nzc_probs_8x8[h][g][i], branch_ct8x8,
- default_nzc_counts_8x8[h][g][i], 0);
- }
- for (i = 0; i < BLOCK_TYPES; ++i) {
- vp9_tree_probs_from_distribution(
- vp9_nzc16x16_tree,
- pc->fc.nzc_probs_16x16[h][g][i], branch_ct16x16,
- default_nzc_counts_16x16[h][g][i], 0);
- }
- for (i = 0; i < BLOCK_TYPES; ++i) {
- vp9_tree_probs_from_distribution(
- vp9_nzc32x32_tree,
- pc->fc.nzc_probs_32x32[h][g][i], branch_ct32x32,
- default_nzc_counts_32x32[h][g][i], 0);
- }
- }
- }
-#else
- vpx_memcpy(pc->fc.nzc_probs_4x4, default_nzc_probs_4x4,
- sizeof(pc->fc.nzc_probs_4x4));
- vpx_memcpy(pc->fc.nzc_probs_8x8, default_nzc_probs_8x8,
- sizeof(pc->fc.nzc_probs_8x8));
- vpx_memcpy(pc->fc.nzc_probs_16x16, default_nzc_probs_16x16,
- sizeof(pc->fc.nzc_probs_16x16));
- vpx_memcpy(pc->fc.nzc_probs_32x32, default_nzc_probs_32x32,
- sizeof(pc->fc.nzc_probs_32x32));
-#endif
- vpx_memcpy(pc->fc.nzc_pcat_probs, default_nzc_pcat_probs,
- sizeof(pc->fc.nzc_pcat_probs));
-#endif // CONFIG_CODE_NONZEROCOUNT
#if CONFIG_MODELCOEFPROB
for (b = 0; b < BLOCK_TYPES; ++b)
for (r = 0; r < REF_TYPES; ++r)
@@ -1607,1099 +1499,8 @@
vp9_init_neighbors();
init_bit_trees();
vp9_tokens_from_tree(vp9_coef_encodings, vp9_coef_tree);
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_tokens_from_tree(vp9_nzc4x4_encodings, vp9_nzc4x4_tree);
- vp9_tokens_from_tree(vp9_nzc8x8_encodings, vp9_nzc8x8_tree);
- vp9_tokens_from_tree(vp9_nzc16x16_encodings, vp9_nzc16x16_tree);
- vp9_tokens_from_tree(vp9_nzc32x32_encodings, vp9_nzc32x32_tree);
-#endif
}
-#if CONFIG_CODE_NONZEROCOUNT
-
-#define mb_in_cur_tile(cm, mb_row, mb_col) \
- ((mb_col) >= (cm)->cur_tile_mb_col_start && \
- (mb_col) <= (cm)->cur_tile_mb_col_end && \
- (mb_row) >= 0)
-
-#define choose_nzc_context(nzc_exp, t2, t1) \
- ((nzc_exp) >= (t2) ? 2 : (nzc_exp) >= (t1) ? 1 : 0)
-
-#define NZC_T2_32X32 (16 << 6)
-#define NZC_T1_32X32 (4 << 6)
-
-#define NZC_T2_16X16 (12 << 6)
-#define NZC_T1_16X16 (3 << 6)
-
-#define NZC_T2_8X8 (8 << 6)
-#define NZC_T1_8X8 (2 << 6)
-
-#define NZC_T2_4X4 (4 << 6)
-#define NZC_T1_4X4 (1 << 6)
-
-// Transforms a mb16 block index to a sb64 block index
-static inline int mb16_to_sb64_index(int mb_row, int mb_col, int block) {
- int r = (mb_row & 3);
- int c = (mb_col & 3);
- int b;
- if (block < 16) { // Y
- int ib = block >> 2;
- int jb = block & 3;
- ib += r * 4;
- jb += c * 4;
- b = ib * 16 + jb;
- assert(b < 256);
- return b;
- } else { // UV
- int base = block - (block & 3);
- int ib = (block - base) >> 1;
- int jb = (block - base) & 1;
- ib += r * 2;
- jb += c * 2;
- b = base * 16 + ib * 8 + jb;
- assert(b >= 256 && b < 384);
- return b;
- }
-}
-
-// Transforms a mb16 block index to a sb32 block index
-static inline int mb16_to_sb32_index(int mb_row, int mb_col, int block) {
- int r = (mb_row & 1);
- int c = (mb_col & 1);
- int b;
- if (block < 16) { // Y
- int ib = block >> 2;
- int jb = block & 3;
- ib += r * 4;
- jb += c * 4;
- b = ib * 8 + jb;
- assert(b < 64);
- return b;
- } else { // UV
- int base = block - (block & 3);
- int ib = (block - base) >> 1;
- int jb = (block - base) & 1;
- ib += r * 2;
- jb += c * 2;
- b = base * 4 + ib * 4 + jb;
- assert(b >= 64 && b < 96);
- return b;
- }
-}
-
-static inline int block_to_txfm_index(int block, TX_SIZE tx_size, int s) {
- // s is the log of the number of 4x4 blocks in each row/col of larger block
- int b, ib, jb, nb;
- ib = block >> s;
- jb = block - (ib << s);
- ib >>= tx_size;
- jb >>= tx_size;
- nb = 1 << (s - tx_size);
- b = (ib * nb + jb) << (2 * tx_size);
- return b;
-}
-
-/* BEGIN - Helper functions to get the y nzcs */
-static unsigned int get_nzc_4x4_y_sb64(MB_MODE_INFO *mi, int block) {
- int b;
- assert(block < 256);
- b = block_to_txfm_index(block, mi->txfm_size, 4);
- assert(b < 256);
- return mi->nzcs[b] << (6 - 2 * mi->txfm_size);
-}
-
-static unsigned int get_nzc_4x4_y_sb32(MB_MODE_INFO *mi, int block) {
- int b;
- assert(block < 64);
- b = block_to_txfm_index(block, mi->txfm_size, 3);
- assert(b < 64);
- return mi->nzcs[b] << (6 - 2 * mi->txfm_size);
-}
-
-static unsigned int get_nzc_4x4_y_mb16(MB_MODE_INFO *mi, int block) {
- int b;
- assert(block < 16);
- b = block_to_txfm_index(block, mi->txfm_size, 2);
- assert(b < 16);
- return mi->nzcs[b] << (6 - 2 * mi->txfm_size);
-}
-/* END - Helper functions to get the y nzcs */
-
-/* Function to get y nzc where block index is in mb16 terms */
-static unsigned int get_nzc_4x4_y(VP9_COMMON *cm, MODE_INFO *m,
- int mb_row, int mb_col, int block) {
- // NOTE: All values returned are at 64 times the true value at 4x4 scale
- MB_MODE_INFO *const mi = &m->mbmi;
- const int mis = cm->mode_info_stride;
- if (mi->mb_skip_coeff || !mb_in_cur_tile(cm, mb_row, mb_col))
- return 0;
- if (mi->sb_type == BLOCK_SIZE_SB64X64) {
- int r = mb_row & 3;
- int c = mb_col & 3;
- m -= c + r * mis;
- if (m->mbmi.mb_skip_coeff || !mb_in_cur_tile(cm, mb_row - r, mb_col - c))
- return 0;
- else
- return get_nzc_4x4_y_sb64(
- &m->mbmi, mb16_to_sb64_index(mb_row, mb_col, block));
- } else if (mi->sb_type == BLOCK_SIZE_SB32X32) {
- int r = mb_row & 1;
- int c = mb_col & 1;
- m -= c + r * mis;
- if (m->mbmi.mb_skip_coeff || !mb_in_cur_tile(cm, mb_row - r, mb_col - c))
- return 0;
- else
- return get_nzc_4x4_y_sb32(
- &m->mbmi, mb16_to_sb32_index(mb_row, mb_col, block));
- } else {
- if (m->mbmi.mb_skip_coeff || !mb_in_cur_tile(cm, mb_row, mb_col))
- return 0;
- return get_nzc_4x4_y_mb16(mi, block);
- }
-}
-
-/* BEGIN - Helper functions to get the uv nzcs */
-static unsigned int get_nzc_4x4_uv_sb64(MB_MODE_INFO *mi, int block) {
- int b;
- int base, uvtxfm_size;
- assert(block >= 256 && block < 384);
- uvtxfm_size = mi->txfm_size;
- base = 256 + (block & 64);
- block -= base;
- b = base + block_to_txfm_index(block, uvtxfm_size, 3);
- assert(b >= 256 && b < 384);
- return mi->nzcs[b] << (6 - 2 * uvtxfm_size);
-}
-
-static unsigned int get_nzc_4x4_uv_sb32(MB_MODE_INFO *mi, int block) {
- int b;
- int base, uvtxfm_size;
- assert(block >= 64 && block < 96);
- if (mi->txfm_size == TX_32X32)
- uvtxfm_size = TX_16X16;
- else
- uvtxfm_size = mi->txfm_size;
- base = 64 + (block & 16);
- block -= base;
- b = base + block_to_txfm_index(block, uvtxfm_size, 2);
- assert(b >= 64 && b < 96);
- return mi->nzcs[b] << (6 - 2 * uvtxfm_size);
-}
-
-static unsigned int get_nzc_4x4_uv_mb16(MB_MODE_INFO *mi, int block) {
- int b;
- int base, uvtxfm_size;
- assert(block >= 16 && block < 24);
- if (mi->txfm_size == TX_8X8 &&
- (mi->mode == SPLITMV || mi->mode == I8X8_PRED))
- uvtxfm_size = TX_4X4;
- else if (mi->txfm_size == TX_16X16)
- uvtxfm_size = TX_8X8;
- else
- uvtxfm_size = mi->txfm_size;
- base = 16 + (block & 4);
- block -= base;
- b = base + block_to_txfm_index(block, uvtxfm_size, 1);
- assert(b >= 16 && b < 24);
- return mi->nzcs[b] << (6 - 2 * uvtxfm_size);
-}
-/* END - Helper functions to get the uv nzcs */
-
-/* Function to get uv nzc where block index is in mb16 terms */
-static unsigned int get_nzc_4x4_uv(VP9_COMMON *cm, MODE_INFO *m,
- int mb_row, int mb_col, int block) {
- // NOTE: All values returned are at 64 times the true value at 4x4 scale
- MB_MODE_INFO *const mi = &m->mbmi;
- const int mis = cm->mode_info_stride;
- if (mi->mb_skip_coeff || !mb_in_cur_tile(cm, mb_row, mb_col))
- return 0;
- if (mi->sb_type == BLOCK_SIZE_SB64X64) {
- int r = mb_row & 3;
- int c = mb_col & 3;
- m -= c + r * mis;
- if (m->mbmi.mb_skip_coeff || !mb_in_cur_tile(cm, mb_row - r, mb_col - c))
- return 0;
- else
- return get_nzc_4x4_uv_sb64(
- &m->mbmi, mb16_to_sb64_index(mb_row, mb_col, block));
- } else if (mi->sb_type == BLOCK_SIZE_SB32X32) {
- int r = mb_row & 1;
- int c = mb_col & 1;
- m -= c + r * mis;
- if (m->mbmi.mb_skip_coeff || !mb_in_cur_tile(cm, mb_row - r, mb_col - c))
- return 0;
- else
- return get_nzc_4x4_uv_sb32(
- &m->mbmi, mb16_to_sb32_index(mb_row, mb_col, block));
- } else {
- return get_nzc_4x4_uv_mb16(mi, block);
- }
-}
-
-int vp9_get_nzc_context_y_sb64(VP9_COMMON *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block) {
- // returns an index in [0, MAX_NZC_CONTEXTS - 1] to reflect how busy
- // neighboring blocks are
- int mis = cm->mode_info_stride;
- int nzc_exp = 0;
- TX_SIZE txfm_size = cur->mbmi.txfm_size;
- assert(block < 256);
- switch (txfm_size) {
- case TX_32X32:
- assert((block & 63) == 0);
- if (block < 128) {
- int o = (block >> 6) * 2;
- nzc_exp =
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 12) +
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 13) +
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 14) +
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 15) +
- get_nzc_4x4_y(cm, cur - mis + o + 1,
- mb_row - 1, mb_col + o + 1, 12) +
- get_nzc_4x4_y(cm, cur - mis + o + 1,
- mb_row - 1, mb_col + o + 1, 13) +
- get_nzc_4x4_y(cm, cur - mis + o + 1,
- mb_row - 1, mb_col + o + 1, 14) +
- get_nzc_4x4_y(cm, cur - mis + o + 1,
- mb_row - 1, mb_col + o + 1, 15);
- } else {
- nzc_exp = cur->mbmi.nzcs[block - 128] << 3;
- }
- if ((block & 127) == 0) {
- int o = (block >> 7) * 2;
- nzc_exp +=
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 3) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 7) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 11) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 15) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis + mis,
- mb_row + o + 1, mb_col - 1, 3) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis + mis,
- mb_row + o + 1, mb_col - 1, 7) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis + mis,
- mb_row + o + 1, mb_col - 1, 11) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis + mis,
- mb_row + o + 1, mb_col - 1, 15);
- } else {
- nzc_exp += cur->mbmi.nzcs[block - 64] << 3;
- }
- nzc_exp <<= 2;
- // Note nzc_exp is 64 times the average value expected at 32x32 scale
- return choose_nzc_context(nzc_exp, NZC_T2_32X32, NZC_T1_32X32);
- break;
-
- case TX_16X16:
- assert((block & 15) == 0);
- if (block < 64) {
- int o = block >> 4;
- nzc_exp =
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 12) +
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 13) +
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 14) +
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 15);
- } else {
- nzc_exp = cur->mbmi.nzcs[block - 64] << 4;
- }
- if ((block & 63) == 0) {
- int o = block >> 6;
- nzc_exp +=
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 3) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 7) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 11) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 15);
- } else {
- nzc_exp += cur->mbmi.nzcs[block - 16] << 4;
- }
- nzc_exp <<= 1;
- // Note nzc_exp is 64 times the average value expected at 16x16 scale
- return choose_nzc_context(nzc_exp, NZC_T2_16X16, NZC_T1_16X16);
- break;
-
- case TX_8X8:
- assert((block & 3) == 0);
- if (block < 32) {
- int o = block >> 3;
- int p = ((block >> 2) & 1) ? 14 : 12;
- nzc_exp =
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, p) +
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, p + 1);
- } else {
- nzc_exp = cur->mbmi.nzcs[block - 32] << 5;
- }
- if ((block & 31) == 0) {
- int o = block >> 6;
- int p = ((block >> 5) & 1) ? 11 : 3;
- nzc_exp +=
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, p) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, p + 4);
- } else {
- nzc_exp += cur->mbmi.nzcs[block - 4] << 5;
- }
- // Note nzc_exp is 64 times the average value expected at 8x8 scale
- return choose_nzc_context(nzc_exp, NZC_T2_8X8, NZC_T1_8X8);
- break;
-
- case TX_4X4:
- if (block < 16) {
- int o = block >> 2;
- int p = block & 3;
- nzc_exp = get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o,
- 12 + p);
- } else {
- nzc_exp = (cur->mbmi.nzcs[block - 16] << 6);
- }
- if ((block & 15) == 0) {
- int o = block >> 6;
- int p = (block >> 4) & 3;
- nzc_exp += get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1,
- 3 + 4 * p);
- } else {
- nzc_exp += (cur->mbmi.nzcs[block - 1] << 6);
- }
- nzc_exp >>= 1;
- // Note nzc_exp is 64 times the average value expected at 4x4 scale
- return choose_nzc_context(nzc_exp, NZC_T2_4X4, NZC_T1_4X4);
- break;
-
- default:
- return 0;
- }
-}
-
-int vp9_get_nzc_context_y_sb32(VP9_COMMON *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block) {
- // returns an index in [0, MAX_NZC_CONTEXTS - 1] to reflect how busy
- // neighboring blocks are
- int mis = cm->mode_info_stride;
- int nzc_exp = 0;
- TX_SIZE txfm_size = cur->mbmi.txfm_size;
- assert(block < 64);
- switch (txfm_size) {
- case TX_32X32:
- assert(block == 0);
- nzc_exp =
- (get_nzc_4x4_y(cm, cur - mis, mb_row - 1, mb_col, 12) +
- get_nzc_4x4_y(cm, cur - mis, mb_row - 1, mb_col, 13) +
- get_nzc_4x4_y(cm, cur - mis, mb_row - 1, mb_col, 14) +
- get_nzc_4x4_y(cm, cur - mis, mb_row - 1, mb_col, 15) +
- get_nzc_4x4_y(cm, cur - mis + 1, mb_row - 1, mb_col + 1, 12) +
- get_nzc_4x4_y(cm, cur - mis + 1, mb_row - 1, mb_col + 1, 13) +
- get_nzc_4x4_y(cm, cur - mis + 1, mb_row - 1, mb_col + 1, 14) +
- get_nzc_4x4_y(cm, cur - mis + 1, mb_row - 1, mb_col + 1, 15) +
- get_nzc_4x4_y(cm, cur - 1, mb_row, mb_col - 1, 3) +
- get_nzc_4x4_y(cm, cur - 1, mb_row, mb_col - 1, 7) +
- get_nzc_4x4_y(cm, cur - 1, mb_row, mb_col - 1, 11) +
- get_nzc_4x4_y(cm, cur - 1, mb_row, mb_col - 1, 15) +
- get_nzc_4x4_y(cm, cur - 1 + mis, mb_row + 1, mb_col - 1, 3) +
- get_nzc_4x4_y(cm, cur - 1 + mis, mb_row + 1, mb_col - 1, 7) +
- get_nzc_4x4_y(cm, cur - 1 + mis, mb_row + 1, mb_col - 1, 11) +
- get_nzc_4x4_y(cm, cur - 1 + mis, mb_row + 1, mb_col - 1, 15)) << 2;
- // Note nzc_exp is 64 times the average value expected at 32x32 scale
- return choose_nzc_context(nzc_exp, NZC_T2_32X32, NZC_T1_32X32);
- break;
-
- case TX_16X16:
- assert((block & 15) == 0);
- if (block < 32) {
- int o = (block >> 4) & 1;
- nzc_exp =
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 12) +
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 13) +
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 14) +
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, 15);
- } else {
- nzc_exp = cur->mbmi.nzcs[block - 32] << 4;
- }
- if ((block & 31) == 0) {
- int o = block >> 5;
- nzc_exp +=
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 3) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 7) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 11) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, 15);
- } else {
- nzc_exp += cur->mbmi.nzcs[block - 16] << 4;
- }
- nzc_exp <<= 1;
- // Note nzc_exp is 64 times the average value expected at 16x16 scale
- return choose_nzc_context(nzc_exp, NZC_T2_16X16, NZC_T1_16X16);
- break;
-
- case TX_8X8:
- assert((block & 3) == 0);
- if (block < 16) {
- int o = block >> 3;
- int p = ((block >> 2) & 1) ? 14 : 12;
- nzc_exp =
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, p) +
- get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o, p + 1);
- } else {
- nzc_exp = cur->mbmi.nzcs[block - 16] << 5;
- }
- if ((block & 15) == 0) {
- int o = block >> 5;
- int p = ((block >> 4) & 1) ? 11 : 3;
- nzc_exp +=
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, p) +
- get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1, p + 4);
- } else {
- nzc_exp += cur->mbmi.nzcs[block - 4] << 5;
- }
- // Note nzc_exp is 64 times the average value expected at 8x8 scale
- return choose_nzc_context(nzc_exp, NZC_T2_8X8, NZC_T1_8X8);
- break;
-
- case TX_4X4:
- if (block < 8) {
- int o = block >> 2;
- int p = block & 3;
- nzc_exp = get_nzc_4x4_y(cm, cur - mis + o, mb_row - 1, mb_col + o,
- 12 + p);
- } else {
- nzc_exp = (cur->mbmi.nzcs[block - 8] << 6);
- }
- if ((block & 7) == 0) {
- int o = block >> 5;
- int p = (block >> 3) & 3;
- nzc_exp += get_nzc_4x4_y(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1,
- 3 + 4 * p);
- } else {
- nzc_exp += (cur->mbmi.nzcs[block - 1] << 6);
- }
- nzc_exp >>= 1;
- // Note nzc_exp is 64 times the average value expected at 4x4 scale
- return choose_nzc_context(nzc_exp, NZC_T2_4X4, NZC_T1_4X4);
- break;
-
- default:
- return 0;
- break;
- }
-}
-
-int vp9_get_nzc_context_y_mb16(VP9_COMMON *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block) {
- // returns an index in [0, MAX_NZC_CONTEXTS - 1] to reflect how busy
- // neighboring blocks are
- int mis = cm->mode_info_stride;
- int nzc_exp = 0;
- TX_SIZE txfm_size = cur->mbmi.txfm_size;
- assert(block < 16);
- switch (txfm_size) {
- case TX_16X16:
- assert(block == 0);
- nzc_exp =
- get_nzc_4x4_y(cm, cur - mis, mb_row - 1, mb_col, 12) +
- get_nzc_4x4_y(cm, cur - mis, mb_row - 1, mb_col, 13) +
- get_nzc_4x4_y(cm, cur - mis, mb_row - 1, mb_col, 14) +
- get_nzc_4x4_y(cm, cur - mis, mb_row - 1, mb_col, 15) +
- get_nzc_4x4_y(cm, cur - 1, mb_row, mb_col - 1, 3) +
- get_nzc_4x4_y(cm, cur - 1, mb_row, mb_col - 1, 7) +
- get_nzc_4x4_y(cm, cur - 1, mb_row, mb_col - 1, 11) +
- get_nzc_4x4_y(cm, cur - 1, mb_row, mb_col - 1, 15);
- nzc_exp <<= 1;
- // Note nzc_exp is 64 times the average value expected at 16x16 scale
- return choose_nzc_context(nzc_exp, NZC_T2_16X16, NZC_T1_16X16);
-
- case TX_8X8:
- assert((block & 3) == 0);
- if (block < 8) {
- int p = ((block >> 2) & 1) ? 14 : 12;
- nzc_exp =
- get_nzc_4x4_y(cm, cur - mis, mb_row - 1, mb_col, p) +
- get_nzc_4x4_y(cm, cur - mis, mb_row - 1, mb_col, p + 1);
- } else {
- nzc_exp = cur->mbmi.nzcs[block - 8] << 5;
- }
- if ((block & 7) == 0) {
- int p = ((block >> 3) & 1) ? 11 : 3;
- nzc_exp +=
- get_nzc_4x4_y(cm, cur - 1, mb_row, mb_col - 1, p) +
- get_nzc_4x4_y(cm, cur - 1, mb_row, mb_col - 1, p + 4);
- } else {
- nzc_exp += cur->mbmi.nzcs[block - 4] << 5;
- }
- // Note nzc_exp is 64 times the average value expected at 8x8 scale
- return choose_nzc_context(nzc_exp, NZC_T2_8X8, NZC_T1_8X8);
-
- case TX_4X4:
- if (block < 4) {
- int p = block & 3;
- nzc_exp = get_nzc_4x4_y(cm, cur - mis, mb_row - 1, mb_col,
- 12 + p);
- } else {
- nzc_exp = (cur->mbmi.nzcs[block - 4] << 6);
- }
- if ((block & 3) == 0) {
- int p = (block >> 2) & 3;
- nzc_exp += get_nzc_4x4_y(cm, cur - 1, mb_row, mb_col - 1,
- 3 + 4 * p);
- } else {
- nzc_exp += (cur->mbmi.nzcs[block - 1] << 6);
- }
- nzc_exp >>= 1;
- // Note nzc_exp is 64 times the average value expected at 4x4 scale
- return choose_nzc_context(nzc_exp, NZC_T2_4X4, NZC_T1_4X4);
-
- default:
- return 0;
- break;
- }
-}
-
-int vp9_get_nzc_context_uv_sb64(VP9_COMMON *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block) {
- // returns an index in [0, MAX_NZC_CONTEXTS - 1] to reflect how busy
- // neighboring blocks are
- int mis = cm->mode_info_stride;
- int nzc_exp = 0;
- const int base = block - (block & 63);
- const int boff = (block & 63);
- const int base_mb16 = base >> 4;
- TX_SIZE txfm_size = cur->mbmi.txfm_size;
- TX_SIZE txfm_size_uv;
-
- assert(block >= 256 && block < 384);
- txfm_size_uv = txfm_size;
-
- switch (txfm_size_uv) {
- case TX_32X32:
- assert(block == 256 || block == 320);
- nzc_exp =
- get_nzc_4x4_uv(cm, cur - mis, mb_row - 1, mb_col,
- base_mb16 + 2) +
- get_nzc_4x4_uv(cm, cur - mis, mb_row - 1, mb_col,
- base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - mis + 1, mb_row - 1, mb_col + 1,
- base_mb16 + 2) +
- get_nzc_4x4_uv(cm, cur - mis + 1, mb_row - 1, mb_col + 1,
- base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - mis + 2, mb_row - 1, mb_col + 2,
- base_mb16 + 2) +
- get_nzc_4x4_uv(cm, cur - mis + 2, mb_row - 1, mb_col + 2,
- base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - mis + 3, mb_row - 1, mb_col + 3,
- base_mb16 + 2) +
- get_nzc_4x4_uv(cm, cur - mis + 3, mb_row - 1, mb_col + 3,
- base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - 1, mb_row, mb_col - 1,
- base_mb16 + 1) +
- get_nzc_4x4_uv(cm, cur - 1, mb_row, mb_col - 1,
- base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - 1 + mis, mb_row + 1, mb_col - 1,
- base_mb16 + 1) +
- get_nzc_4x4_uv(cm, cur - 1 + mis, mb_row + 1, mb_col - 1,
- base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - 1 + 2 * mis, mb_row + 2, mb_col - 1,
- base_mb16 + 1) +
- get_nzc_4x4_uv(cm, cur - 1 + 2 * mis, mb_row + 2, mb_col - 1,
- base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - 1 + 3 * mis, mb_row + 3, mb_col - 1,
- base_mb16 + 1) +
- get_nzc_4x4_uv(cm, cur - 1 + 3 * mis, mb_row + 3, mb_col - 1,
- base_mb16 + 3);
- nzc_exp <<= 2;
- // Note nzc_exp is 64 times the average value expected at 32x32 scale
- return choose_nzc_context(nzc_exp, NZC_T2_32X32, NZC_T1_32X32);
-
- case TX_16X16:
- // uv txfm_size 16x16
- assert((block & 15) == 0);
- if (boff < 32) {
- int o = (boff >> 4) & 1;
- nzc_exp =
- get_nzc_4x4_uv(cm, cur - mis + o, mb_row - 1, mb_col + o,
- base_mb16 + 2) +
- get_nzc_4x4_uv(cm, cur - mis + o, mb_row - 1, mb_col + o,
- base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - mis + o + 1, mb_row - 1, mb_col + o + 1,
- base_mb16 + 2) +
- get_nzc_4x4_uv(cm, cur - mis + o + 1, mb_row - 1, mb_col + o + 1,
- base_mb16 + 3);
- } else {
- nzc_exp = cur->mbmi.nzcs[block - 32] << 4;
- }
- if ((boff & 31) == 0) {
- int o = boff >> 5;
- nzc_exp +=
- get_nzc_4x4_uv(cm, cur - 1 + o * mis,
- mb_row + o, mb_col - 1, base_mb16 + 1) +
- get_nzc_4x4_uv(cm, cur - 1 + o * mis,
- mb_row + o, mb_col - 1, base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - 1 + o * mis + mis,
- mb_row + o + 1, mb_col - 1, base_mb16 + 1) +
- get_nzc_4x4_uv(cm, cur - 1 + o * mis + mis,
- mb_row + o + 1, mb_col - 1, base_mb16 + 3);
- } else {
- nzc_exp += cur->mbmi.nzcs[block - 16] << 4;
- }
- nzc_exp <<= 1;
- // Note nzc_exp is 64 times the average value expected at 16x16 scale
- return choose_nzc_context(nzc_exp, NZC_T2_16X16, NZC_T1_16X16);
-
- case TX_8X8:
- assert((block & 3) == 0);
- if (boff < 16) {
- int o = boff >> 2;
- nzc_exp =
- get_nzc_4x4_uv(cm, cur - mis + o, mb_row - 1, mb_col + o,
- base_mb16 + 2) +
- get_nzc_4x4_uv(cm, cur - mis + o, mb_row - 1, mb_col + o,
- base_mb16 + 3);
- } else {
- nzc_exp = cur->mbmi.nzcs[block - 16] << 5;
- }
- if ((boff & 15) == 0) {
- int o = boff >> 4;
- nzc_exp +=
- get_nzc_4x4_uv(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1,
- base_mb16 + 1) +
- get_nzc_4x4_uv(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1,
- base_mb16 + 3);
- } else {
- nzc_exp += cur->mbmi.nzcs[block - 4] << 5;
- }
- // Note nzc_exp is 64 times the average value expected at 8x8 scale
- return choose_nzc_context(nzc_exp, NZC_T2_8X8, NZC_T1_8X8);
-
- case TX_4X4:
- if (boff < 8) {
- int o = boff >> 1;
- int p = boff & 1;
- nzc_exp = get_nzc_4x4_uv(cm, cur - mis + o, mb_row - 1, mb_col + o,
- base_mb16 + 2 + p);
- } else {
- nzc_exp = (cur->mbmi.nzcs[block - 8] << 6);
- }
- if ((boff & 7) == 0) {
- int o = boff >> 4;
- int p = (boff >> 3) & 1;
- nzc_exp += get_nzc_4x4_uv(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1,
- base_mb16 + 1 + 2 * p);
- } else {
- nzc_exp += (cur->mbmi.nzcs[block - 1] << 6);
- }
- nzc_exp >>= 1;
- // Note nzc_exp is 64 times the average value expected at 4x4 scale
- return choose_nzc_context(nzc_exp, NZC_T2_4X4, NZC_T1_4X4);
-
- default:
- return 0;
- }
-}
-
-int vp9_get_nzc_context_uv_sb32(VP9_COMMON *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block) {
- // returns an index in [0, MAX_NZC_CONTEXTS - 1] to reflect how busy
- // neighboring blocks are
- int mis = cm->mode_info_stride;
- int nzc_exp = 0;
- const int base = block - (block & 15);
- const int boff = (block & 15);
- const int base_mb16 = base >> 2;
- TX_SIZE txfm_size = cur->mbmi.txfm_size;
- TX_SIZE txfm_size_uv;
-
- assert(block >= 64 && block < 96);
- if (txfm_size == TX_32X32)
- txfm_size_uv = TX_16X16;
- else
- txfm_size_uv = txfm_size;
-
- switch (txfm_size_uv) {
- case TX_16X16:
- // uv txfm_size 16x16
- assert(block == 64 || block == 80);
- nzc_exp =
- get_nzc_4x4_uv(cm, cur - mis, mb_row - 1, mb_col,
- base_mb16 + 2) +
- get_nzc_4x4_uv(cm, cur - mis, mb_row - 1, mb_col,
- base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - mis + 1, mb_row - 1, mb_col + 1,
- base_mb16 + 2) +
- get_nzc_4x4_uv(cm, cur - mis + 1, mb_row - 1, mb_col + 1,
- base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - 1 + mis, mb_row, mb_col - 1,
- base_mb16 + 1) +
- get_nzc_4x4_uv(cm, cur - 1 + mis, mb_row, mb_col - 1,
- base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - 1 + mis, mb_row + 1, mb_col - 1,
- base_mb16 + 1) +
- get_nzc_4x4_uv(cm, cur - 1 + mis, mb_row + 1, mb_col - 1,
- base_mb16 + 3);
- nzc_exp <<= 1;
- // Note nzc_exp is 64 times the average value expected at 16x16 scale
- return choose_nzc_context(nzc_exp, NZC_T2_16X16, NZC_T1_16X16);
- break;
-
- case TX_8X8:
- assert((block & 3) == 0);
- if (boff < 8) {
- int o = boff >> 2;
- nzc_exp =
- get_nzc_4x4_uv(cm, cur - mis + o, mb_row - 1, mb_col + o,
- base_mb16 + 2) +
- get_nzc_4x4_uv(cm, cur - mis + o, mb_row - 1, mb_col + o,
- base_mb16 + 3);
- } else {
- nzc_exp = cur->mbmi.nzcs[block - 8] << 5;
- }
- if ((boff & 7) == 0) {
- int o = boff >> 3;
- nzc_exp +=
- get_nzc_4x4_uv(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1,
- base_mb16 + 1) +
- get_nzc_4x4_uv(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1,
- base_mb16 + 3);
- } else {
- nzc_exp += cur->mbmi.nzcs[block - 4] << 5;
- }
- // Note nzc_exp is 64 times the average value expected at 8x8 scale
- return choose_nzc_context(nzc_exp, NZC_T2_8X8, NZC_T1_8X8);
-
- case TX_4X4:
- if (boff < 4) {
- int o = boff >> 1;
- int p = boff & 1;
- nzc_exp = get_nzc_4x4_uv(cm, cur - mis + o, mb_row - 1, mb_col + o,
- base_mb16 + 2 + p);
- } else {
- nzc_exp = (cur->mbmi.nzcs[block - 4] << 6);
- }
- if ((boff & 3) == 0) {
- int o = boff >> 3;
- int p = (boff >> 2) & 1;
- nzc_exp += get_nzc_4x4_uv(cm, cur - 1 + o * mis, mb_row + o, mb_col - 1,
- base_mb16 + 1 + 2 * p);
- } else {
- nzc_exp += (cur->mbmi.nzcs[block - 1] << 6);
- }
- nzc_exp >>= 1;
- // Note nzc_exp is 64 times the average value expected at 4x4 scale
- return choose_nzc_context(nzc_exp, NZC_T2_4X4, NZC_T1_4X4);
-
- default:
- return 0;
- }
-}
-
-int vp9_get_nzc_context_uv_mb16(VP9_COMMON *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block) {
- // returns an index in [0, MAX_NZC_CONTEXTS - 1] to reflect how busy
- // neighboring blocks are
- int mis = cm->mode_info_stride;
- int nzc_exp = 0;
- const int base = block - (block & 3);
- const int boff = (block & 3);
- const int base_mb16 = base;
- TX_SIZE txfm_size = cur->mbmi.txfm_size;
- TX_SIZE txfm_size_uv;
-
- assert(block >= 16 && block < 24);
- if (txfm_size == TX_16X16)
- txfm_size_uv = TX_8X8;
- else if (txfm_size == TX_8X8 &&
- (cur->mbmi.mode == I8X8_PRED || cur->mbmi.mode == SPLITMV))
- txfm_size_uv = TX_4X4;
- else
- txfm_size_uv = txfm_size;
-
- switch (txfm_size_uv) {
- case TX_8X8:
- assert((block & 3) == 0);
- nzc_exp =
- get_nzc_4x4_uv(cm, cur - mis, mb_row - 1, mb_col, base_mb16 + 2) +
- get_nzc_4x4_uv(cm, cur - mis, mb_row - 1, mb_col, base_mb16 + 3) +
- get_nzc_4x4_uv(cm, cur - 1, mb_row, mb_col - 1, base_mb16 + 1) +
- get_nzc_4x4_uv(cm, cur - 1, mb_row, mb_col - 1, base_mb16 + 3);
- // Note nzc_exp is 64 times the average value expected at 8x8 scale
- return choose_nzc_context(nzc_exp, NZC_T2_8X8, NZC_T1_8X8);
-
- case TX_4X4:
- if (boff < 2) {
- int p = boff & 1;
- nzc_exp = get_nzc_4x4_uv(cm, cur - mis, mb_row - 1, mb_col,
- base_mb16 + 2 + p);
- } else {
- nzc_exp = (cur->mbmi.nzcs[block - 2] << 6);
- }
- if ((boff & 1) == 0) {
- int p = (boff >> 1) & 1;
- nzc_exp += get_nzc_4x4_uv(cm, cur - 1, mb_row, mb_col - 1,
- base_mb16 + 1 + 2 * p);
- } else {
- nzc_exp += (cur->mbmi.nzcs[block - 1] << 6);
- }
- nzc_exp >>= 1;
- // Note nzc_exp is 64 times the average value expected at 4x4 scale
- return choose_nzc_context(nzc_exp, NZC_T2_4X4, NZC_T1_4X4);
-
- default:
- return 0;
- }
-}
-
-int vp9_get_nzc_context(VP9_COMMON *cm, MACROBLOCKD *xd, int block) {
- if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB64X64) {
- assert(block < 384);
- if (block < 256)
- return vp9_get_nzc_context_y_sb64(cm, xd->mode_info_context,
- get_mb_row(xd), get_mb_col(xd), block);
- else
- return vp9_get_nzc_context_uv_sb64(cm, xd->mode_info_context,
- get_mb_row(xd), get_mb_col(xd), block);
- } else if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB32X32) {
- assert(block < 96);
- if (block < 64)
- return vp9_get_nzc_context_y_sb32(cm, xd->mode_info_context,
- get_mb_row(xd), get_mb_col(xd), block);
- else
- return vp9_get_nzc_context_uv_sb32(cm, xd->mode_info_context,
- get_mb_row(xd), get_mb_col(xd), block);
- } else {
- assert(block < 64);
- if (block < 16)
- return vp9_get_nzc_context_y_mb16(cm, xd->mode_info_context,
- get_mb_row(xd), get_mb_col(xd), block);
- else
- return vp9_get_nzc_context_uv_mb16(cm, xd->mode_info_context,
- get_mb_row(xd), get_mb_col(xd), block);
- }
-}
-
-static void update_nzc(VP9_COMMON *cm,
- uint16_t nzc,
- int nzc_context,
- TX_SIZE tx_size,
- int ref,
- int type) {
- int e, c;
- if (!get_nzc_used(tx_size)) return;
- c = codenzc(nzc);
- if (tx_size == TX_32X32)
- cm->fc.nzc_counts_32x32[nzc_context][ref][type][c]++;
- else if (tx_size == TX_16X16)
- cm->fc.nzc_counts_16x16[nzc_context][ref][type][c]++;
- else if (tx_size == TX_8X8)
- cm->fc.nzc_counts_8x8[nzc_context][ref][type][c]++;
- else if (tx_size == TX_4X4)
- cm->fc.nzc_counts_4x4[nzc_context][ref][type][c]++;
- else
- assert(0);
-
- if ((e = vp9_extranzcbits[c])) {
- int x = nzc - vp9_basenzcvalue[c];
- while (e--) {
- int b = (x >> e) & 1;
- cm->fc.nzc_pcat_counts[nzc_context][c - NZC_TOKENS_NOEXTRA][e][b]++;
- }
- }
-}
-
-static void update_nzcs_sb64(VP9_COMMON *cm,
- MACROBLOCKD *xd,
- int mb_row,
- int mb_col) {
- MODE_INFO *m = xd->mode_info_context;
- MB_MODE_INFO *const mi = &m->mbmi;
- int j, nzc_context;
- const int ref = m->mbmi.ref_frame != INTRA_FRAME;
-
- assert(mb_col == get_mb_col(xd));
- assert(mb_row == get_mb_row(xd));
-
- if (mi->mb_skip_coeff)
- return;
-
- switch (mi->txfm_size) {
- case TX_32X32:
- for (j = 0; j < 256; j += 64) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 0);
- }
- for (j = 256; j < 384; j += 64) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 1);
- }
- break;
-
- case TX_16X16:
- for (j = 0; j < 256; j += 16) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0);
- }
- for (j = 256; j < 384; j += 16) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1);
- }
- break;
-
- case TX_8X8:
- for (j = 0; j < 256; j += 4) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0);
- }
- for (j = 256; j < 384; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1);
- }
- break;
-
- case TX_4X4:
- for (j = 0; j < 256; ++j) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0);
- }
- for (j = 256; j < 384; ++j) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1);
- }
- break;
-
- default:
- break;
- }
-}
-
-static void update_nzcs_sb32(VP9_COMMON *cm,
- MACROBLOCKD *xd,
- int mb_row,
- int mb_col) {
- MODE_INFO *m = xd->mode_info_context;
- MB_MODE_INFO *const mi = &m->mbmi;
- int j, nzc_context;
- const int ref = m->mbmi.ref_frame != INTRA_FRAME;
-
- assert(mb_col == get_mb_col(xd));
- assert(mb_row == get_mb_row(xd));
-
- if (mi->mb_skip_coeff)
- return;
-
- switch (mi->txfm_size) {
- case TX_32X32:
- for (j = 0; j < 64; j += 64) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 0);
- }
- for (j = 64; j < 96; j += 16) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1);
- }
- break;
-
- case TX_16X16:
- for (j = 0; j < 64; j += 16) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0);
- }
- for (j = 64; j < 96; j += 16) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1);
- }
- break;
-
- case TX_8X8:
- for (j = 0; j < 64; j += 4) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0);
- }
- for (j = 64; j < 96; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1);
- }
- break;
-
- case TX_4X4:
- for (j = 0; j < 64; ++j) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0);
- }
- for (j = 64; j < 96; ++j) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1);
- }
- break;
-
- default:
- break;
- }
-}
-
-static void update_nzcs_mb16(VP9_COMMON *cm,
- MACROBLOCKD *xd,
- int mb_row,
- int mb_col) {
- MODE_INFO *m = xd->mode_info_context;
- MB_MODE_INFO *const mi = &m->mbmi;
- int j, nzc_context;
- const int ref = m->mbmi.ref_frame != INTRA_FRAME;
-
- assert(mb_col == get_mb_col(xd));
- assert(mb_row == get_mb_row(xd));
-
- if (mi->mb_skip_coeff)
- return;
-
- switch (mi->txfm_size) {
- case TX_16X16:
- for (j = 0; j < 16; j += 16) {
- nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0);
- }
- for (j = 16; j < 24; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1);
- }
- break;
-
- case TX_8X8:
- for (j = 0; j < 16; j += 4) {
- nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0);
- }
- if (mi->mode == I8X8_PRED || mi->mode == SPLITMV) {
- for (j = 16; j < 24; ++j) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1);
- }
- } else {
- for (j = 16; j < 24; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1);
- }
- }
- break;
-
- case TX_4X4:
- for (j = 0; j < 16; ++j) {
- nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0);
- }
- for (j = 16; j < 24; ++j) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- update_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1);
- }
- break;
-
- default:
- break;
- }
-}
-
-void vp9_update_nzc_counts(VP9_COMMON *cm,
- MACROBLOCKD *xd,
- int mb_row,
- int mb_col) {
- if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB64X64)
- update_nzcs_sb64(cm, xd, mb_row, mb_col);
- else if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB32X32)
- update_nzcs_sb32(cm, xd, mb_row, mb_col);
- else
- update_nzcs_mb16(cm, xd, mb_row, mb_col);
-}
-#endif // CONFIG_CODE_NONZEROCOUNT
-
// #define COEF_COUNT_TESTING
#define COEF_COUNT_SAT 24
@@ -2787,131 +1588,6 @@
count_sat, update_factor);
}
-#if CONFIG_CODE_NONZEROCOUNT
-static void adapt_nzc_probs_common(VP9_COMMON *cm,
- TX_SIZE tx_size,
- int count_sat,
- int update_factor) {
- int c, r, b, n;
- int count, factor;
- unsigned int nzc_branch_ct[NZC32X32_NODES][2];
- vp9_prob nzc_probs[NZC32X32_NODES];
- int tokens, nodes;
- const vp9_tree_index *nzc_tree;
- vp9_prob *dst_nzc_probs;
- vp9_prob *pre_nzc_probs;
- unsigned int *nzc_counts;
-
- if (!get_nzc_used(tx_size)) return;
- if (tx_size == TX_32X32) {
- tokens = NZC32X32_TOKENS;
- nzc_tree = vp9_nzc32x32_tree;
- dst_nzc_probs = cm->fc.nzc_probs_32x32[0][0][0];
- pre_nzc_probs = cm->fc.pre_nzc_probs_32x32[0][0][0];
- nzc_counts = cm->fc.nzc_counts_32x32[0][0][0];
- } else if (tx_size == TX_16X16) {
- tokens = NZC16X16_TOKENS;
- nzc_tree = vp9_nzc16x16_tree;
- dst_nzc_probs = cm->fc.nzc_probs_16x16[0][0][0];
- pre_nzc_probs = cm->fc.pre_nzc_probs_16x16[0][0][0];
- nzc_counts = cm->fc.nzc_counts_16x16[0][0][0];
- } else if (tx_size == TX_8X8) {
- tokens = NZC8X8_TOKENS;
- nzc_tree = vp9_nzc8x8_tree;
- dst_nzc_probs = cm->fc.nzc_probs_8x8[0][0][0];
- pre_nzc_probs = cm->fc.pre_nzc_probs_8x8[0][0][0];
- nzc_counts = cm->fc.nzc_counts_8x8[0][0][0];
- } else {
- nzc_tree = vp9_nzc4x4_tree;
- tokens = NZC4X4_TOKENS;
- dst_nzc_probs = cm->fc.nzc_probs_4x4[0][0][0];
- pre_nzc_probs = cm->fc.pre_nzc_probs_4x4[0][0][0];
- nzc_counts = cm->fc.nzc_counts_4x4[0][0][0];
- }
- nodes = tokens - 1;
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c)
- for (r = 0; r < REF_TYPES; ++r)
- for (b = 0; b < BLOCK_TYPES; ++b) {
- int offset = c * REF_TYPES * BLOCK_TYPES + r * BLOCK_TYPES + b;
- int offset_nodes = offset * nodes;
- int offset_tokens = offset * tokens;
- vp9_tree_probs_from_distribution(nzc_tree,
- nzc_probs, nzc_branch_ct,
- nzc_counts + offset_tokens, 0);
- for (n = 0; n < nodes; ++n) {
- count = nzc_branch_ct[n][0] + nzc_branch_ct[n][1];
- count = count > count_sat ? count_sat : count;
- factor = (update_factor * count / count_sat);
- dst_nzc_probs[offset_nodes + n] =
- weighted_prob(pre_nzc_probs[offset_nodes + n],
- nzc_probs[n], factor);
- }
- }
-}
-
-static void adapt_nzc_pcat(VP9_COMMON *cm, int count_sat, int update_factor) {
- int c, t;
- int count, factor;
- if (!(get_nzc_used(TX_4X4) || get_nzc_used(TX_8X8) ||
- get_nzc_used(TX_16X16) || get_nzc_used(TX_32X32)))
- return;
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (t = 0; t < NZC_TOKENS_EXTRA; ++t) {
- int bits = vp9_extranzcbits[t + NZC_TOKENS_NOEXTRA];
- int b;
- for (b = 0; b < bits; ++b) {
- vp9_prob prob = get_binary_prob(cm->fc.nzc_pcat_counts[c][t][b][0],
- cm->fc.nzc_pcat_counts[c][t][b][1]);
- count = cm->fc.nzc_pcat_counts[c][t][b][0] +
- cm->fc.nzc_pcat_counts[c][t][b][1];
- count = count > count_sat ? count_sat : count;
- factor = (update_factor * count / count_sat);
- cm->fc.nzc_pcat_probs[c][t][b] = weighted_prob(
- cm->fc.pre_nzc_pcat_probs[c][t][b], prob, factor);
- }
- }
- }
-}
-
-// #define NZC_COUNT_TESTING
-void vp9_adapt_nzc_probs(VP9_COMMON *cm) {
- int count_sat;
- int update_factor; /* denominator 256 */
-#ifdef NZC_COUNT_TESTING
- int c, r, b, t;
- printf("\n");
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c)
- for (r = 0; r < REF_TYPES; ++r) {
- for (b = 0; b < BLOCK_TYPES; ++b) {
- printf(" {");
- for (t = 0; t < NZC4X4_TOKENS; ++t) {
- printf(" %d,", cm->fc.nzc_counts_4x4[c][r][b][t]);
- }
- printf("}\n");
- }
- printf("\n");
- }
-#endif
-
- if (cm->frame_type == KEY_FRAME) {
- update_factor = COEF_MAX_UPDATE_FACTOR_KEY;
- count_sat = COEF_COUNT_SAT_KEY;
- } else if (cm->last_frame_type == KEY_FRAME) {
- update_factor = COEF_MAX_UPDATE_FACTOR_AFTER_KEY; /* adapt quickly */
- count_sat = COEF_COUNT_SAT_AFTER_KEY;
- } else {
- update_factor = COEF_MAX_UPDATE_FACTOR;
- count_sat = COEF_COUNT_SAT;
- }
-
- adapt_nzc_probs_common(cm, TX_4X4, count_sat, update_factor);
- adapt_nzc_probs_common(cm, TX_8X8, count_sat, update_factor);
- adapt_nzc_probs_common(cm, TX_16X16, count_sat, update_factor);
- adapt_nzc_probs_common(cm, TX_32X32, count_sat, update_factor);
- adapt_nzc_pcat(cm, count_sat, update_factor);
-}
-#endif // CONFIG_CODE_NONZEROCOUNT
-
#if CONFIG_CODE_ZEROGROUP
OrientationType vp9_get_orientation(int rc, TX_SIZE tx_size) {
int i = rc >> (tx_size + 2);
@@ -3011,25 +1687,6 @@
void vp9_adapt_zpc_probs(VP9_COMMON *cm) {
int count_sat;
int update_factor; /* denominator 256 */
-#ifdef NZC_COUNT_TESTING
- int r, b, p, n;
- printf("\n");
- for (r = 0; r < REF_TYPES; ++r) {
- printf("{");
- for (b = 0; b < ZPC_BANDS; ++b) {
- printf(" {");
- for (p = 0; p < ZPC_PTOKS; ++p) {
- printf(" {");
- for (n = 0; n < ZPC_NODES; ++n) {
- printf(" %d,", cm->fc.zpc_counts_16x16[r][b][p][n]);
- }
- printf("},\n");
- }
- printf(" },\n");
- }
- printf("},\n");
- }
-#endif
if (cm->frame_type == KEY_FRAME) {
update_factor = COEF_MAX_UPDATE_FACTOR_KEY;
--- a/vp9/common/vp9_entropy.h
+++ b/vp9/common/vp9_entropy.h
@@ -167,89 +167,6 @@
int b, int r);
#endif // CONFIG_MODELCOEFPROB
-#if CONFIG_CODE_NONZEROCOUNT
-/* Alphabet for number of non-zero symbols in block */
-#define NZC_0 0 /* Used for all blocks */
-#define NZC_1 1 /* Used for all blocks */
-#define NZC_2 2 /* Used for all blocks */
-#define NZC_3TO4 3 /* Used for all blocks */
-#define NZC_5TO8 4 /* Used for all blocks */
-#define NZC_9TO16 5 /* Used for all blocks */
-#define NZC_17TO32 6 /* Used for 8x8 and larger blocks */
-#define NZC_33TO64 7 /* Used for 8x8 and larger blocks */
-#define NZC_65TO128 8 /* Used for 16x16 and larger blocks */
-#define NZC_129TO256 9 /* Used for 16x16 and larger blocks */
-#define NZC_257TO512 10 /* Used for 32x32 and larger blocks */
-#define NZC_513TO1024 11 /* Used for 32x32 and larger blocks */
-
-/* Number of tokens for each block size */
-#define NZC4X4_TOKENS 6
-#define NZC8X8_TOKENS 8
-#define NZC16X16_TOKENS 10
-#define NZC32X32_TOKENS 12
-
-/* Number of nodes for each block size */
-#define NZC4X4_NODES 5
-#define NZC8X8_NODES 7
-#define NZC16X16_NODES 9
-#define NZC32X32_NODES 11
-
-/* Max number of tokens with extra bits */
-#define NZC_TOKENS_EXTRA 9
-
-/* Max number of extra bits */
-#define NZC_BITS_EXTRA 9
-
-/* Tokens without extra bits */
-#define NZC_TOKENS_NOEXTRA (NZC32X32_TOKENS - NZC_TOKENS_EXTRA)
-
-#define MAX_NZC_CONTEXTS 3
-
-/* whether to update extra bit probabilities */
-#define NZC_PCAT_UPDATE
-
-/* nzc trees */
-extern const vp9_tree_index vp9_nzc4x4_tree[];
-extern const vp9_tree_index vp9_nzc8x8_tree[];
-extern const vp9_tree_index vp9_nzc16x16_tree[];
-extern const vp9_tree_index vp9_nzc32x32_tree[];
-
-/* nzc encodings */
-extern struct vp9_token vp9_nzc4x4_encodings[NZC4X4_TOKENS];
-extern struct vp9_token vp9_nzc8x8_encodings[NZC8X8_TOKENS];
-extern struct vp9_token vp9_nzc16x16_encodings[NZC16X16_TOKENS];
-extern struct vp9_token vp9_nzc32x32_encodings[NZC32X32_TOKENS];
-
-#define codenzc(x) (\
- (x) <= 3 ? (x) : (x) <= 4 ? 3 : (x) <= 8 ? 4 : \
- (x) <= 16 ? 5 : (x) <= 32 ? 6 : (x) <= 64 ? 7 :\
- (x) <= 128 ? 8 : (x) <= 256 ? 9 : (x) <= 512 ? 10 : 11)
-
-int vp9_get_nzc_context_y_sb64(struct VP9Common *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block);
-int vp9_get_nzc_context_y_sb32(struct VP9Common *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block);
-int vp9_get_nzc_context_y_mb16(struct VP9Common *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block);
-int vp9_get_nzc_context_uv_sb64(struct VP9Common *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block);
-int vp9_get_nzc_context_uv_sb32(struct VP9Common *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block);
-int vp9_get_nzc_context_uv_mb16(struct VP9Common *cm, MODE_INFO *cur,
- int mb_row, int mb_col, int block);
-int vp9_get_nzc_context(struct VP9Common *cm, MACROBLOCKD *xd, int block);
-void vp9_update_nzc_counts(struct VP9Common *cm, MACROBLOCKD *xd,
- int mb_row, int mb_col);
-void vp9_adapt_nzc_probs(struct VP9Common *cm);
-
-/* Extra bits array */
-extern const int vp9_extranzcbits[NZC32X32_TOKENS];
-
-/* Base nzc values */
-extern const int vp9_basenzcvalue[NZC32X32_TOKENS];
-
-#endif // CONFIG_CODE_NONZEROCOUNT
-
#if CONFIG_CODE_ZEROGROUP
#define ZPC_STATS
--- a/vp9/common/vp9_onyxc_int.h
+++ b/vp9/common/vp9_onyxc_int.h
@@ -74,18 +74,6 @@
vp9_coeff_probs coef_probs_8x8[BLOCK_TYPES];
vp9_coeff_probs coef_probs_16x16[BLOCK_TYPES];
vp9_coeff_probs coef_probs_32x32[BLOCK_TYPES];
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_prob nzc_probs_4x4[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC4X4_NODES];
- vp9_prob nzc_probs_8x8[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC8X8_NODES];
- vp9_prob nzc_probs_16x16[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC16X16_NODES];
- vp9_prob nzc_probs_32x32[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC32X32_NODES];
- vp9_prob nzc_pcat_probs[MAX_NZC_CONTEXTS]
- [NZC_TOKENS_EXTRA][NZC_BITS_EXTRA];
-#endif
#if CONFIG_CODE_ZEROGROUP
vp9_zpc_probs zpc_probs_4x4;
vp9_zpc_probs zpc_probs_8x8;
@@ -116,18 +104,6 @@
vp9_coeff_probs pre_coef_probs_8x8[BLOCK_TYPES];
vp9_coeff_probs pre_coef_probs_16x16[BLOCK_TYPES];
vp9_coeff_probs pre_coef_probs_32x32[BLOCK_TYPES];
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_prob pre_nzc_probs_4x4[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC4X4_NODES];
- vp9_prob pre_nzc_probs_8x8[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC8X8_NODES];
- vp9_prob pre_nzc_probs_16x16[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC16X16_NODES];
- vp9_prob pre_nzc_probs_32x32[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC32X32_NODES];
- vp9_prob pre_nzc_pcat_probs[MAX_NZC_CONTEXTS]
- [NZC_TOKENS_EXTRA][NZC_BITS_EXTRA];
-#endif
#if CONFIG_CODE_ZEROGROUP
vp9_zpc_probs pre_zpc_probs_4x4;
vp9_zpc_probs pre_zpc_probs_8x8;
@@ -142,18 +118,6 @@
unsigned int eob_branch_counts[TX_SIZE_MAX_SB][BLOCK_TYPES][REF_TYPES]
[COEF_BANDS][PREV_COEF_CONTEXTS];
-#if CONFIG_CODE_NONZEROCOUNT
- unsigned int nzc_counts_4x4[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC4X4_TOKENS];
- unsigned int nzc_counts_8x8[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC8X8_TOKENS];
- unsigned int nzc_counts_16x16[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC16X16_TOKENS];
- unsigned int nzc_counts_32x32[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC32X32_TOKENS];
- unsigned int nzc_pcat_counts[MAX_NZC_CONTEXTS]
- [NZC_TOKENS_EXTRA][NZC_BITS_EXTRA][2];
-#endif
#if CONFIG_CODE_ZEROGROUP
vp9_zpc_count zpc_counts_4x4;
vp9_zpc_count zpc_counts_8x8;
--- a/vp9/decoder/vp9_decodemv.c
+++ b/vp9/decoder/vp9_decodemv.c
@@ -1018,258 +1018,6 @@
mb_mode_mv_init(pbi, r);
}
-#if CONFIG_CODE_NONZEROCOUNT
-static uint16_t read_nzc(VP9_COMMON *const cm,
- int nzc_context,
- TX_SIZE tx_size,
- int ref,
- int type,
- vp9_reader *r) {
- int c, e;
- uint16_t nzc;
- if (!get_nzc_used(tx_size)) return 0;
- if (tx_size == TX_32X32) {
- c = treed_read(r, vp9_nzc32x32_tree,
- cm->fc.nzc_probs_32x32[nzc_context][ref][type]);
- cm->fc.nzc_counts_32x32[nzc_context][ref][type][c]++;
- } else if (tx_size == TX_16X16) {
- c = treed_read(r, vp9_nzc16x16_tree,
- cm->fc.nzc_probs_16x16[nzc_context][ref][type]);
- cm->fc.nzc_counts_16x16[nzc_context][ref][type][c]++;
- } else if (tx_size == TX_8X8) {
- c = treed_read(r, vp9_nzc8x8_tree,
- cm->fc.nzc_probs_8x8[nzc_context][ref][type]);
- cm->fc.nzc_counts_8x8[nzc_context][ref][type][c]++;
- } else if (tx_size == TX_4X4) {
- c = treed_read(r, vp9_nzc4x4_tree,
- cm->fc.nzc_probs_4x4[nzc_context][ref][type]);
- cm->fc.nzc_counts_4x4[nzc_context][ref][type][c]++;
- } else {
- assert(0);
- }
- nzc = vp9_basenzcvalue[c];
- if ((e = vp9_extranzcbits[c])) {
- int x = 0;
- while (e--) {
- int b = vp9_read(
- r, cm->fc.nzc_pcat_probs[nzc_context][c - NZC_TOKENS_NOEXTRA][e]);
- x |= (b << e);
- cm->fc.nzc_pcat_counts[nzc_context][c - NZC_TOKENS_NOEXTRA][e][b]++;
- }
- nzc += x;
- }
- if (tx_size == TX_32X32)
- assert(nzc <= 1024);
- else if (tx_size == TX_16X16)
- assert(nzc <= 256);
- else if (tx_size == TX_8X8)
- assert(nzc <= 64);
- else if (tx_size == TX_4X4)
- assert(nzc <= 16);
- return nzc;
-}
-
-static void read_nzcs_sb64(VP9_COMMON *const cm,
- MACROBLOCKD* xd,
- int mb_row,
- int mb_col,
- vp9_reader *r) {
- MODE_INFO *m = xd->mode_info_context;
- MB_MODE_INFO *const mi = &m->mbmi;
- int j, nzc_context;
- const int ref = m->mbmi.ref_frame != INTRA_FRAME;
-
- assert(mb_col == get_mb_col(xd));
- assert(mb_row == get_mb_row(xd));
-
- vpx_memset(m->mbmi.nzcs, 0, 384 * sizeof(m->mbmi.nzcs[0]));
-
- if (mi->mb_skip_coeff)
- return;
-
- switch (mi->txfm_size) {
- case TX_32X32:
- for (j = 0; j < 256; j += 64) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_32X32, ref, 0, r);
- }
- for (j = 256; j < 384; j += 64) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_32X32, ref, 1, r);
- }
- break;
-
- case TX_16X16:
- for (j = 0; j < 256; j += 16) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_16X16, ref, 0, r);
- }
- for (j = 256; j < 384; j += 16) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_16X16, ref, 1, r);
- }
- break;
-
- case TX_8X8:
- for (j = 0; j < 256; j += 4) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_8X8, ref, 0, r);
- }
- for (j = 256; j < 384; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_8X8, ref, 1, r);
- }
- break;
-
- case TX_4X4:
- for (j = 0; j < 256; ++j) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_4X4, ref, 0, r);
- }
- for (j = 256; j < 384; ++j) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_4X4, ref, 1, r);
- }
- break;
-
- default:
- break;
- }
-}
-
-static void read_nzcs_sb32(VP9_COMMON *const cm,
- MACROBLOCKD* xd,
- int mb_row,
- int mb_col,
- vp9_reader *r) {
- MODE_INFO *m = xd->mode_info_context;
- MB_MODE_INFO *const mi = &m->mbmi;
- int j, nzc_context;
- const int ref = m->mbmi.ref_frame != INTRA_FRAME;
-
- assert(mb_col == get_mb_col(xd));
- assert(mb_row == get_mb_row(xd));
-
- vpx_memset(m->mbmi.nzcs, 0, 384 * sizeof(m->mbmi.nzcs[0]));
-
- if (mi->mb_skip_coeff)
- return;
-
- switch (mi->txfm_size) {
- case TX_32X32:
- for (j = 0; j < 64; j += 64) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_32X32, ref, 0, r);
- }
- for (j = 64; j < 96; j += 16) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_16X16, ref, 1, r);
- }
- break;
-
- case TX_16X16:
- for (j = 0; j < 64; j += 16) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_16X16, ref, 0, r);
- }
- for (j = 64; j < 96; j += 16) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_16X16, ref, 1, r);
- }
- break;
-
- case TX_8X8:
- for (j = 0; j < 64; j += 4) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_8X8, ref, 0, r);
- }
- for (j = 64; j < 96; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_8X8, ref, 1, r);
- }
- break;
-
- case TX_4X4:
- for (j = 0; j < 64; ++j) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_4X4, ref, 0, r);
- }
- for (j = 64; j < 96; ++j) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_4X4, ref, 1, r);
- }
- break;
-
- default:
- break;
- }
-}
-
-static void read_nzcs_mb16(VP9_COMMON *const cm,
- MACROBLOCKD* xd,
- int mb_row,
- int mb_col,
- vp9_reader *r) {
- MODE_INFO *m = xd->mode_info_context;
- MB_MODE_INFO *const mi = &m->mbmi;
- int j, nzc_context;
- const int ref = m->mbmi.ref_frame != INTRA_FRAME;
-
- assert(mb_col == get_mb_col(xd));
- assert(mb_row == get_mb_row(xd));
-
- vpx_memset(m->mbmi.nzcs, 0, 384 * sizeof(m->mbmi.nzcs[0]));
-
- if (mi->mb_skip_coeff)
- return;
-
- switch (mi->txfm_size) {
- case TX_16X16:
- for (j = 0; j < 16; j += 16) {
- nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_16X16, ref, 0, r);
- }
- for (j = 16; j < 24; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_8X8, ref, 1, r);
- }
- break;
-
- case TX_8X8:
- for (j = 0; j < 16; j += 4) {
- nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_8X8, ref, 0, r);
- }
- if (mi->mode == I8X8_PRED || mi->mode == SPLITMV) {
- for (j = 16; j < 24; ++j) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_4X4, ref, 1, r);
- }
- } else {
- for (j = 16; j < 24; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_8X8, ref, 1, r);
- }
- }
- break;
-
- case TX_4X4:
- for (j = 0; j < 16; ++j) {
- nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_4X4, ref, 0, r);
- }
- for (j = 16; j < 24; ++j) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- m->mbmi.nzcs[j] = read_nzc(cm, nzc_context, TX_4X4, ref, 1, r);
- }
- break;
-
- default:
- break;
- }
-}
-#endif // CONFIG_CODE_NONZEROCOUNT
-
void vp9_decode_mb_mode_mv(VP9D_COMP* const pbi,
MACROBLOCKD* const xd,
int mb_row,
@@ -1288,14 +1036,6 @@
mi->mbmi.ref_frame - 1, mi->mbmi.second_ref_frame - 1,
cm->active_ref_scale);
}
-#if CONFIG_CODE_NONZEROCOUNT
- if (mbmi->sb_type == BLOCK_SIZE_SB64X64)
- read_nzcs_sb64(cm, xd, mb_row, mb_col, r);
- else if (mbmi->sb_type == BLOCK_SIZE_SB32X32)
- read_nzcs_sb32(cm, xd, mb_row, mb_col, r);
- else
- read_nzcs_mb16(cm, xd, mb_row, mb_col, r);
-#endif // CONFIG_CODE_NONZEROCOUNT
if (mbmi->sb_type) {
const int bw = 1 << mb_width_log2(mbmi->sb_type);
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -220,32 +220,6 @@
}
}
-#if CONFIG_CODE_NONZEROCOUNT
-static void propagate_nzcs(VP9_COMMON *cm, MACROBLOCKD *xd) {
- MODE_INFO *m = xd->mode_info_context;
- BLOCK_SIZE_TYPE sb_type = m->mbmi.sb_type;
- const int mis = cm->mode_info_stride;
- int n;
- if (sb_type == BLOCK_SIZE_SB64X64) {
- for (n = 0; n < 16; ++n) {
- int i = n >> 2;
- int j = n & 3;
- if (i == 0 && j == 0) continue;
- vpx_memcpy((m + j + mis * i)->mbmi.nzcs, m->mbmi.nzcs,
- 384 * sizeof(m->mbmi.nzcs[0]));
- }
- } else if (sb_type == BLOCK_SIZE_SB32X32) {
- for (n = 0; n < 4; ++n) {
- int i = n >> 1;
- int j = n & 1;
- if (i == 0 && j == 0) continue;
- vpx_memcpy((m + j + mis * i)->mbmi.nzcs, m->mbmi.nzcs,
- 384 * sizeof(m->mbmi.nzcs[0]));
- }
- }
-}
-#endif
-
static void decode_16x16(MACROBLOCKD *xd) {
const TX_TYPE tx_type = get_tx_type_16x16(xd, 0);
@@ -644,9 +618,6 @@
if (mi->mbmi.mb_skip_coeff) {
vp9_reset_sb_tokens_context(xd, bsize);
-#if CONFIG_CODE_NONZEROCOUNT
- vpx_memset(mi->mbmi.nzcs, 0, 384 * sizeof(mi->mbmi.nzcs[0]));
-#endif
} else {
// re-initialize macroblock dequantizer before detokenization
if (xd->segmentation_enabled)
@@ -681,10 +652,6 @@
}
}
}
-
-#if CONFIG_CODE_NONZEROCOUNT
- propagate_nzcs(&pbi->common, xd);
-#endif
}
// TODO(jingning): Need to merge SB and MB decoding. The MB decoding currently
@@ -1043,88 +1010,6 @@
}
#endif // CONFIG_CODE_ZEROGROUP
-#if CONFIG_CODE_NONZEROCOUNT
-static void read_nzc_probs_common(VP9_COMMON *cm,
- vp9_reader *rd,
- TX_SIZE tx_size) {
- int c, r, b, t;
- int tokens, nodes;
- vp9_prob *nzc_probs;
- vp9_prob upd;
-
- if (!get_nzc_used(tx_size)) return;
- if (!vp9_read_bit(rd)) return;
-
- if (tx_size == TX_32X32) {
- tokens = NZC32X32_TOKENS;
- nzc_probs = cm->fc.nzc_probs_32x32[0][0][0];
- upd = NZC_UPDATE_PROB_32X32;
- } else if (tx_size == TX_16X16) {
- tokens = NZC16X16_TOKENS;
- nzc_probs = cm->fc.nzc_probs_16x16[0][0][0];
- upd = NZC_UPDATE_PROB_16X16;
- } else if (tx_size == TX_8X8) {
- tokens = NZC8X8_TOKENS;
- nzc_probs = cm->fc.nzc_probs_8x8[0][0][0];
- upd = NZC_UPDATE_PROB_8X8;
- } else {
- tokens = NZC4X4_TOKENS;
- nzc_probs = cm->fc.nzc_probs_4x4[0][0][0];
- upd = NZC_UPDATE_PROB_4X4;
- }
- nodes = tokens - 1;
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (r = 0; r < REF_TYPES; ++r) {
- for (b = 0; b < BLOCK_TYPES; ++b) {
- int offset = c * REF_TYPES * BLOCK_TYPES + r * BLOCK_TYPES + b;
- int offset_nodes = offset * nodes;
- for (t = 0; t < nodes; ++t) {
- vp9_prob *p = &nzc_probs[offset_nodes + t];
- if (vp9_read(rd, upd)) {
- *p = read_prob_diff_update(rd, *p);
- }
- }
- }
- }
- }
-}
-
-static void read_nzc_pcat_probs(VP9_COMMON *cm, vp9_reader *r) {
- int c, t, b;
- vp9_prob upd = NZC_UPDATE_PROB_PCAT;
- if (!(get_nzc_used(TX_4X4) || get_nzc_used(TX_8X8) ||
- get_nzc_used(TX_16X16) || get_nzc_used(TX_32X32)))
- return;
- if (!vp9_read_bit(r)) {
- return;
- }
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (t = 0; t < NZC_TOKENS_EXTRA; ++t) {
- int bits = vp9_extranzcbits[t + NZC_TOKENS_NOEXTRA];
- for (b = 0; b < bits; ++b) {
- vp9_prob *p = &cm->fc.nzc_pcat_probs[c][t][b];
- if (vp9_read(r, upd)) {
- *p = read_prob_diff_update(r, *p);
- }
- }
- }
- }
-}
-
-static void read_nzc_probs(VP9_COMMON *cm, vp9_reader *r) {
- read_nzc_probs_common(cm, r, TX_4X4);
- if (cm->txfm_mode != ONLY_4X4)
- read_nzc_probs_common(cm, r, TX_8X8);
- if (cm->txfm_mode > ALLOW_8X8)
- read_nzc_probs_common(cm, r, TX_16X16);
- if (cm->txfm_mode > ALLOW_16X16)
- read_nzc_probs_common(cm, r, TX_32X32);
-#ifdef NZC_PCAT_UPDATE
- read_nzc_pcat_probs(cm, r);
-#endif
-}
-#endif // CONFIG_CODE_NONZEROCOUNT
-
static void read_coef_probs_common(VP9D_COMP *pbi,
vp9_reader *r,
vp9_coeff_probs *coef_probs,
@@ -1142,11 +1027,7 @@
for (j = 0; j < REF_TYPES; j++) {
for (k = 0; k < COEF_BANDS; k++) {
for (l = 0; l < PREV_COEF_CONTEXTS; l++) {
-#if CONFIG_CODE_NONZEROCOUNT
- const int mstart = get_nzc_used(tx_size);
-#else
const int mstart = 0;
-#endif
if (l >= 3 && k == 0)
continue;
@@ -1439,19 +1320,6 @@
vp9_zero(fc->interintra_counts);
#endif
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_copy(fc->pre_nzc_probs_4x4, fc->nzc_probs_4x4);
- vp9_copy(fc->pre_nzc_probs_8x8, fc->nzc_probs_8x8);
- vp9_copy(fc->pre_nzc_probs_16x16, fc->nzc_probs_16x16);
- vp9_copy(fc->pre_nzc_probs_32x32, fc->nzc_probs_32x32);
- vp9_copy(fc->pre_nzc_pcat_probs, fc->nzc_pcat_probs);
-
- vp9_zero(fc->nzc_counts_4x4);
- vp9_zero(fc->nzc_counts_8x8);
- vp9_zero(fc->nzc_counts_16x16);
- vp9_zero(fc->nzc_counts_32x32);
- vp9_zero(fc->nzc_pcat_counts);
-#endif
#if CONFIG_CODE_ZEROGROUP
vp9_copy(fc->pre_zpc_probs_4x4, fc->zpc_probs_4x4);
vp9_copy(fc->pre_zpc_probs_8x8, fc->zpc_probs_8x8);
@@ -1716,9 +1584,6 @@
update_frame_context(pbi);
read_coef_probs(pbi, &header_bc);
-#if CONFIG_CODE_NONZEROCOUNT
- read_nzc_probs(&pbi->common, &header_bc);
-#endif
#if CONFIG_CODE_ZEROGROUP
read_zpc_probs(&pbi->common, &header_bc);
#endif
@@ -1771,9 +1636,6 @@
if (!pc->error_resilient_mode && !pc->frame_parallel_decoding_mode) {
vp9_adapt_coef_probs(pc);
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_adapt_nzc_probs(pc);
-#endif
#if CONFIG_CODE_ZEROGROUP
vp9_adapt_zpc_probs(pc);
#endif
--- a/vp9/decoder/vp9_detokenize.c
+++ b/vp9/decoder/vp9_detokenize.c
@@ -83,16 +83,6 @@
} while (0)
#endif
-#if CONFIG_CODE_NONZEROCOUNT
-#define WRITE_COEF_CONTINUE(val, token) \
- { \
- qcoeff_ptr[scan[c]] = vp9_read_and_apply_sign(r, val); \
- INCREMENT_COUNT(token); \
- c++; \
- nzc++; \
- continue; \
- }
-#else
#define WRITE_COEF_CONTINUE(val, token) \
{ \
qcoeff_ptr[scan[c]] = vp9_read_and_apply_sign(r, val); \
@@ -100,7 +90,6 @@
c++; \
continue; \
}
-#endif // CONFIG_CODE_NONZEROCOUNT
#define WRITE_COEF_ONE() \
{ \
@@ -138,12 +127,6 @@
vp9_prob *zprobs;
int eoo = 0, use_eoo;
#endif
-#if CONFIG_CODE_NONZEROCOUNT
- const int nzc_used = get_nzc_used(txfm_size);
- uint16_t nzc = 0;
- uint16_t nzc_expected =
- nzc_used ? xd->mode_info_context->mbmi.nzcs[block_idx] : 0;
-#endif
const int *scan, *nb;
uint8_t token_cache[1024];
#if CONFIG_CODE_ZEROGROUP
@@ -309,10 +292,6 @@
const uint8_t *cat6 = cat6_prob;
if (c >= seg_eob)
break;
-#if CONFIG_CODE_NONZEROCOUNT
- if (nzc_used && nzc == nzc_expected)
- break;
-#endif
if (c)
pt = vp9_get_coef_context(scan, nb, pad, token_cache,
c, default_eob);
@@ -319,21 +298,15 @@
band = get_coef_band(scan, txfm_size, c);
prob = coef_probs[type][ref][band][pt];
fc->eob_branch_counts[txfm_size][type][ref][band][pt]++;
-#if CONFIG_CODE_NONZEROCOUNT
- if (!nzc_used) {
-#endif
- if (!vp9_read(r, prob[EOB_CONTEXT_NODE]))
- break;
+ if (!vp9_read(r, prob[EOB_CONTEXT_NODE]))
+ break;
#if CONFIG_CODE_ZEROGROUP
- rc = scan[c];
- o = vp9_get_orientation(rc, txfm_size);
- if (token_cache[rc] == ZERO_TOKEN || is_eoo[o]) {
- coef_counts[type][ref][band][pt][ZERO_TOKEN]++;
- ZEROGROUP_ADVANCE();
- goto SKIP_START;
- }
-#endif
-#if CONFIG_CODE_NONZEROCOUNT
+ rc = scan[c];
+ o = vp9_get_orientation(rc, txfm_size);
+ if (token_cache[rc] == ZERO_TOKEN || is_eoo[o]) {
+ coef_counts[type][ref][band][pt][ZERO_TOKEN]++;
+ ZEROGROUP_ADVANCE();
+ goto SKIP_START;
}
#endif
@@ -340,10 +313,6 @@
SKIP_START:
if (c >= seg_eob)
break;
-#if CONFIG_CODE_NONZEROCOUNT
- if (nzc_used && nzc == nzc_expected)
- break;
-#endif
if (c)
pt = vp9_get_coef_context(scan, nb, pad, token_cache,
c, default_eob);
@@ -360,10 +329,6 @@
[coef_to_zpc_band(band)]
[coef_to_zpc_ptok(pt)];
#endif
-#if CONFIG_CODE_NONZEROCOUNT
- // decode zero node only if there are zeros left
- if (!nzc_used || seg_eob - nzc_expected - c + nzc > 0)
-#endif
if (!vp9_read(r, prob[ZERO_CONTEXT_NODE])) {
#if CONFIG_CODE_ZEROGROUP
eoo = 0;
@@ -446,18 +411,9 @@
WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY6);
}
-#if CONFIG_CODE_NONZEROCOUNT
- if (!nzc_used)
-#endif
- if (c < seg_eob)
- coef_counts[type][ref][get_coef_band(scan, txfm_size, c)]
- [pt][DCT_EOB_TOKEN]++;
-#if CONFIG_CODE_NONZEROCOUNT
- if (!nzc_used)
- xd->mode_info_context->mbmi.nzcs[block_idx] = nzc;
- else
- assert(nzc == nzc_expected);
-#endif
+ if (c < seg_eob)
+ coef_counts[type][ref][get_coef_band(scan, txfm_size, c)]
+ [pt][DCT_EOB_TOKEN]++;
A0[aidx] = L0[lidx] = c > 0;
if (txfm_size >= TX_8X8) {
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -50,23 +50,6 @@
extern unsigned int active_section;
#endif
-#if CONFIG_CODE_NONZEROCOUNT
-#ifdef NZC_STATS
-unsigned int nzc_stats_4x4[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC4X4_TOKENS];
-unsigned int nzc_stats_8x8[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC8X8_TOKENS];
-unsigned int nzc_stats_16x16[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC16X16_TOKENS];
-unsigned int nzc_stats_32x32[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC32X32_TOKENS];
-unsigned int nzc_pcat_stats[MAX_NZC_CONTEXTS][NZC_TOKENS_EXTRA]
- [NZC_BITS_EXTRA][2];
-void init_nzcstats();
-void update_nzcstats(VP9_COMMON *const cm);
-void print_nzcstats();
-#endif
-#endif
#if CONFIG_CODE_ZEROGROUP
#ifdef ZPC_STATS
vp9_zpc_count zpc_stats_4x4;
@@ -1014,562 +997,6 @@
}
}
-#if CONFIG_CODE_NONZEROCOUNT
-static void write_nzc(VP9_COMP *const cpi,
- uint16_t nzc,
- int nzc_context,
- TX_SIZE tx_size,
- int ref,
- int type,
- vp9_writer* const bc) {
- VP9_COMMON *const cm = &cpi->common;
- int c, e;
- // if (!cpi->dummy_packing && cm->current_video_frame == 27)
- // printf("nzc: %d, tx_size: %d\n", nzc, tx_size);
- if (!get_nzc_used(tx_size)) return;
- c = codenzc(nzc);
- if (tx_size == TX_32X32) {
- write_token(bc, vp9_nzc32x32_tree,
- cm->fc.nzc_probs_32x32[nzc_context][ref][type],
- vp9_nzc32x32_encodings + c);
- // cm->fc.nzc_counts_32x32[nzc_context][ref][type][c]++;
- } else if (tx_size == TX_16X16) {
- write_token(bc, vp9_nzc16x16_tree,
- cm->fc.nzc_probs_16x16[nzc_context][ref][type],
- vp9_nzc16x16_encodings + c);
- // cm->fc.nzc_counts_16x16[nzc_context][ref][type][c]++;
- } else if (tx_size == TX_8X8) {
- write_token(bc, vp9_nzc8x8_tree,
- cm->fc.nzc_probs_8x8[nzc_context][ref][type],
- vp9_nzc8x8_encodings + c);
- // cm->fc.nzc_counts_8x8[nzc_context][ref][type][c]++;
- } else if (tx_size == TX_4X4) {
- write_token(bc, vp9_nzc4x4_tree,
- cm->fc.nzc_probs_4x4[nzc_context][ref][type],
- vp9_nzc4x4_encodings + c);
- // cm->fc.nzc_counts_4x4[nzc_context][ref][type][c]++;
- } else {
- assert(0);
- }
-
- if ((e = vp9_extranzcbits[c])) {
- int x = nzc - vp9_basenzcvalue[c];
- while (e--) {
- int b = (x >> e) & 1;
- vp9_write(bc, b,
- cm->fc.nzc_pcat_probs[nzc_context][c - NZC_TOKENS_NOEXTRA][e]);
- // cm->fc.nzc_pcat_counts[nzc_context][c - NZC_TOKENS_NOEXTRA][e][b]++;
- }
- }
-}
-
-static void write_nzcs_sb64(VP9_COMP *cpi,
- MACROBLOCKD *xd,
- int mb_row,
- int mb_col,
- vp9_writer* const bc) {
- VP9_COMMON *const cm = &cpi->common;
- MODE_INFO *m = xd->mode_info_context;
- MB_MODE_INFO *const mi = &m->mbmi;
- int j, nzc_context;
- const int ref = m->mbmi.ref_frame != INTRA_FRAME;
-
- assert(mb_col == get_mb_col(xd));
- assert(mb_row == get_mb_row(xd));
-
- if (mi->mb_skip_coeff)
- return;
-
- switch (mi->txfm_size) {
- case TX_32X32:
- for (j = 0; j < 256; j += 64) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 0, bc);
- }
- for (j = 256; j < 384; j += 64) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 1, bc);
- }
- break;
-
- case TX_16X16:
- for (j = 0; j < 256; j += 16) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0, bc);
- }
- for (j = 256; j < 384; j += 16) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1, bc);
- }
- break;
-
- case TX_8X8:
- for (j = 0; j < 256; j += 4) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0, bc);
- }
- for (j = 256; j < 384; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
- }
- break;
-
- case TX_4X4:
- for (j = 0; j < 256; ++j) {
- nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0, bc);
- }
- for (j = 256; j < 384; ++j) {
- nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
- }
- break;
-
- default:
- break;
- }
-}
-
-static void write_nzcs_sb32(VP9_COMP *cpi,
- MACROBLOCKD *xd,
- int mb_row,
- int mb_col,
- vp9_writer* const bc) {
- VP9_COMMON *const cm = &cpi->common;
- MODE_INFO *m = xd->mode_info_context;
- MB_MODE_INFO *const mi = &m->mbmi;
- int j, nzc_context;
- const int ref = m->mbmi.ref_frame != INTRA_FRAME;
-
- assert(mb_col == get_mb_col(xd));
- assert(mb_row == get_mb_row(xd));
-
- if (mi->mb_skip_coeff)
- return;
-
- switch (mi->txfm_size) {
- case TX_32X32:
- for (j = 0; j < 64; j += 64) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 0, bc);
- }
- for (j = 64; j < 96; j += 16) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1, bc);
- }
- break;
-
- case TX_16X16:
- for (j = 0; j < 64; j += 16) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0, bc);
- }
- for (j = 64; j < 96; j += 16) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1, bc);
- }
- break;
-
- case TX_8X8:
- for (j = 0; j < 64; j += 4) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0, bc);
- }
- for (j = 64; j < 96; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
- }
- break;
-
- case TX_4X4:
- for (j = 0; j < 64; ++j) {
- nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0, bc);
- }
- for (j = 64; j < 96; ++j) {
- nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
- }
- break;
-
- default:
- break;
- }
-}
-
-static void write_nzcs_mb16(VP9_COMP *cpi,
- MACROBLOCKD *xd,
- int mb_row,
- int mb_col,
- vp9_writer* const bc) {
- VP9_COMMON *const cm = &cpi->common;
- MODE_INFO *m = xd->mode_info_context;
- MB_MODE_INFO *const mi = &m->mbmi;
- int j, nzc_context;
- const int ref = m->mbmi.ref_frame != INTRA_FRAME;
-
- assert(mb_col == get_mb_col(xd));
- assert(mb_row == get_mb_row(xd));
-
- if (mi->mb_skip_coeff)
- return;
-
- switch (mi->txfm_size) {
- case TX_16X16:
- for (j = 0; j < 16; j += 16) {
- nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0, bc);
- }
- for (j = 16; j < 24; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
- }
- break;
-
- case TX_8X8:
- for (j = 0; j < 16; j += 4) {
- nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0, bc);
- }
- if (mi->mode == I8X8_PRED || mi->mode == SPLITMV) {
- for (j = 16; j < 24; ++j) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
- }
- } else {
- for (j = 16; j < 24; j += 4) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
- }
- }
- break;
-
- case TX_4X4:
- for (j = 0; j < 16; ++j) {
- nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0, bc);
- }
- for (j = 16; j < 24; ++j) {
- nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
- }
- break;
-
- default:
- break;
- }
-}
-
-#ifdef NZC_STATS
-void init_nzcstats() {
- vp9_zero(nzc_stats_4x4);
- vp9_zero(nzc_stats_8x8);
- vp9_zero(nzc_stats_16x16);
- vp9_zero(nzc_stats_32x32);
- vp9_zero(nzc_pcat_stats);
-}
-
-void update_nzcstats(VP9_COMMON *const cm) {
- int c, r, b, t;
-
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (r = 0; r < REF_TYPES; ++r) {
- for (b = 0; b < BLOCK_TYPES; ++b) {
- for (t = 0; t < NZC4X4_TOKENS; ++t) {
- nzc_stats_4x4[c][r][b][t] += cm->fc.nzc_counts_4x4[c][r][b][t];
- }
- }
- }
- }
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (r = 0; r < REF_TYPES; ++r) {
- for (b = 0; b < BLOCK_TYPES; ++b) {
- for (t = 0; t < NZC8X8_TOKENS; ++t) {
- nzc_stats_8x8[c][r][b][t] += cm->fc.nzc_counts_8x8[c][r][b][t];
- }
- }
- }
- }
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (r = 0; r < REF_TYPES; ++r) {
- for (b = 0; b < BLOCK_TYPES; ++b) {
- for (t = 0; t < NZC16X16_TOKENS; ++t) {
- nzc_stats_16x16[c][r][b][t] += cm->fc.nzc_counts_16x16[c][r][b][t];
- }
- }
- }
- }
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (r = 0; r < REF_TYPES; ++r) {
- for (b = 0; b < BLOCK_TYPES; ++b) {
- for (t = 0; t < NZC32X32_TOKENS; ++t) {
- nzc_stats_32x32[c][r][b][t] += cm->fc.nzc_counts_32x32[c][r][b][t];
- }
- }
- }
- }
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (t = 0; t < NZC_TOKENS_EXTRA; ++t) {
- int bits = vp9_extranzcbits[t + NZC_TOKENS_NOEXTRA];
- for (b = 0; b < bits; ++b) {
- nzc_pcat_stats[c][t][b][0] += cm->fc.nzc_pcat_counts[c][t][b][0];
- nzc_pcat_stats[c][t][b][1] += cm->fc.nzc_pcat_counts[c][t][b][1];
- }
- }
- }
-}
-
-void print_nzcstats() {
- int c, r, b, t;
- FILE *f;
-
- printf(
- "static const unsigned int default_nzc_counts_4x4[MAX_NZC_CONTEXTS]\n"
- " [REF_TYPES]\n"
- " [BLOCK_TYPES]\n"
- " [NZC4X4_TOKENS] = {\n");
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- printf(" {\n");
- for (r = 0; r < REF_TYPES; ++r) {
- printf(" {\n");
- for (b = 0; b < BLOCK_TYPES; ++b) {
- printf(" {");
- for (t = 0; t < NZC4X4_TOKENS; ++t) {
- printf(" %-3d,", nzc_stats_4x4[c][r][b][t]);
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf("};\n");
-
- printf(
- "static const unsigned int default_nzc_counts_8x8[MAX_NZC_CONTEXTS]\n"
- " [REF_TYPES]\n"
- " [BLOCK_TYPES]\n"
- " [NZC8X8_TOKENS] = {\n");
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- printf(" {\n");
- for (r = 0; r < REF_TYPES; ++r) {
- printf(" {\n");
- for (b = 0; b < BLOCK_TYPES; ++b) {
- printf(" {");
- for (t = 0; t < NZC8X8_TOKENS; ++t) {
- printf(" %-3d,", nzc_stats_8x8[c][r][b][t]);
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf("};\n");
-
- printf(
- "static const unsigned int default_nzc_counts_16x16[MAX_NZC_CONTEXTS]\n"
- " [REF_TYPES]\n"
- " [BLOCK_TYPES]\n"
- " [NZC16X16_TOKENS] = {"
- "\n");
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- printf(" {\n");
- for (r = 0; r < REF_TYPES; ++r) {
- printf(" {\n");
- for (b = 0; b < BLOCK_TYPES; ++b) {
- printf(" {");
- for (t = 0; t < NZC16X16_TOKENS; ++t) {
- printf(" %-3d,", nzc_stats_16x16[c][r][b][t]);
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf("};\n");
-
- printf(
- "static const unsigned int default_nzc_counts_32x32[MAX_NZC_CONTEXTS]\n"
- " [REF_TYPES]\n"
- " [BLOCK_TYPES]\n"
- " [NZC32X32_TOKENS] = {"
- "\n");
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- printf(" {\n");
- for (r = 0; r < REF_TYPES; ++r) {
- printf(" {\n");
- for (b = 0; b < BLOCK_TYPES; ++b) {
- printf(" {");
- for (t = 0; t < NZC32X32_TOKENS; ++t) {
- printf(" %-3d,", nzc_stats_32x32[c][r][b][t]);
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf("};\n");
-
- printf(
- "static const vp9_prob default_nzc_pcat_counts[MAX_NZC_CONTEXTS]\n"
- " [NZC_TOKENS_EXTRA]\n"
- " [NZC_BITS_EXTRA] = {\n");
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- printf(" {\n");
- for (t = 0; t < NZC_TOKENS_EXTRA; ++t) {
- printf(" {");
- for (b = 0; b < NZC_BITS_EXTRA; ++b) {
- printf(" %d/%d,",
- nzc_pcat_stats[c][t][b][0], nzc_pcat_stats[c][t][b][1]);
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf("};\n");
-
- printf(
- "static const vp9_prob default_nzc_probs_4x4[MAX_NZC_CONTEXTS]\n"
- " [REF_TYPES]\n"
- " [BLOCK_TYPES]\n"
- " [NZC4X4_TOKENS] = {\n");
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- printf(" {\n");
- for (r = 0; r < REF_TYPES; ++r) {
- printf(" {\n");
- for (b = 0; b < BLOCK_TYPES; ++b) {
- vp9_prob probs[NZC4X4_NODES];
- unsigned int branch_ct[NZC4X4_NODES][2];
- vp9_tree_probs_from_distribution(vp9_nzc4x4_tree,
- probs, branch_ct,
- nzc_stats_4x4[c][r][b], 0);
- printf(" {");
- for (t = 0; t < NZC4X4_NODES; ++t) {
- printf(" %-3d,", probs[t]);
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf("};\n");
-
- printf(
- "static const vp9_prob default_nzc_probs_8x8[MAX_NZC_CONTEXTS]\n"
- " [REF_TYPES]\n"
- " [BLOCK_TYPES]\n"
- " [NZC8X8_TOKENS] = {\n");
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- printf(" {\n");
- for (r = 0; r < REF_TYPES; ++r) {
- printf(" {\n");
- for (b = 0; b < BLOCK_TYPES; ++b) {
- vp9_prob probs[NZC8X8_NODES];
- unsigned int branch_ct[NZC8X8_NODES][2];
- vp9_tree_probs_from_distribution(vp9_nzc8x8_tree,
- probs, branch_ct,
- nzc_stats_8x8[c][r][b], 0);
- printf(" {");
- for (t = 0; t < NZC8X8_NODES; ++t) {
- printf(" %-3d,", probs[t]);
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf("};\n");
-
- printf(
- "static const vp9_prob default_nzc_probs_16x16[MAX_NZC_CONTEXTS]\n"
- " [REF_TYPES]\n"
- " [BLOCK_TYPES]\n"
- " [NZC16X16_TOKENS] = {\n");
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- printf(" {\n");
- for (r = 0; r < REF_TYPES; ++r) {
- printf(" {\n");
- for (b = 0; b < BLOCK_TYPES; ++b) {
- vp9_prob probs[NZC16X16_NODES];
- unsigned int branch_ct[NZC16X16_NODES][2];
- vp9_tree_probs_from_distribution(vp9_nzc16x16_tree,
- probs, branch_ct,
- nzc_stats_16x16[c][r][b], 0);
- printf(" {");
- for (t = 0; t < NZC16X16_NODES; ++t) {
- printf(" %-3d,", probs[t]);
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf("};\n");
-
- printf(
- "static const vp9_prob default_nzc_probs_32x32[MAX_NZC_CONTEXTS]\n"
- " [REF_TYPES]\n"
- " [BLOCK_TYPES]\n"
- " [NZC32X32_TOKENS] = {\n");
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- printf(" {\n");
- for (r = 0; r < REF_TYPES; ++r) {
- printf(" {\n");
- for (b = 0; b < BLOCK_TYPES; ++b) {
- vp9_prob probs[NZC32X32_NODES];
- unsigned int branch_ct[NZC32X32_NODES][2];
- vp9_tree_probs_from_distribution(vp9_nzc32x32_tree,
- probs, branch_ct,
- nzc_stats_32x32[c][r][b], 0);
- printf(" {");
- for (t = 0; t < NZC32X32_NODES; ++t) {
- printf(" %-3d,", probs[t]);
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf("};\n");
-
- printf(
- "static const vp9_prob default_nzc_pcat_probs[MAX_NZC_CONTEXTS]\n"
- " [NZC_TOKENS_EXTRA]\n"
- " [NZC_BITS_EXTRA] = {\n");
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- printf(" {\n");
- for (t = 0; t < NZC_TOKENS_EXTRA; ++t) {
- printf(" {");
- for (b = 0; b < NZC_BITS_EXTRA; ++b) {
- vp9_prob prob = get_binary_prob(nzc_pcat_stats[c][t][b][0],
- nzc_pcat_stats[c][t][b][1]);
- printf(" %-3d,", prob);
- }
- printf(" },\n");
- }
- printf(" },\n");
- }
- printf("};\n");
-
- f = fopen("nzcstats.bin", "wb");
- fwrite(nzc_stats_4x4, sizeof(nzc_stats_4x4), 1, f);
- fwrite(nzc_stats_8x8, sizeof(nzc_stats_8x8), 1, f);
- fwrite(nzc_stats_16x16, sizeof(nzc_stats_16x16), 1, f);
- fwrite(nzc_stats_32x32, sizeof(nzc_stats_32x32), 1, f);
- fwrite(nzc_pcat_stats, sizeof(nzc_pcat_stats), 1, f);
- fclose(f);
-}
-#endif
-
-#endif // CONFIG_CODE_NONZEROCOUNT
-
#if CONFIG_CODE_ZEROGROUP
#ifdef ZPC_STATS
void init_zpcstats() {
@@ -1736,14 +1163,6 @@
active_section = 1;
#endif
}
-#if CONFIG_CODE_NONZEROCOUNT
- if (m->mbmi.sb_type == BLOCK_SIZE_SB64X64)
- write_nzcs_sb64(cpi, xd, mb_row, mb_col, bc);
- else if (m->mbmi.sb_type == BLOCK_SIZE_SB32X32)
- write_nzcs_sb32(cpi, xd, mb_row, mb_col, bc);
- else
- write_nzcs_mb16(cpi, xd, mb_row, mb_col, bc);
-#endif
assert(*tok < tok_end);
pack_mb_tokens(bc, tok, tok_end);
@@ -2075,232 +1494,6 @@
}
#endif // CONFIG_CODE_ZEROGROUP
-#if CONFIG_CODE_NONZEROCOUNT
-static void update_nzc_probs_common(VP9_COMP* cpi,
- vp9_writer* const bc,
- TX_SIZE tx_size) {
- VP9_COMMON *cm = &cpi->common;
- int c, r, b, t;
- int update[2] = {0, 0};
- int savings = 0;
- int tokens, nodes;
- const vp9_tree_index *nzc_tree;
- vp9_prob *new_nzc_probs;
- vp9_prob *old_nzc_probs;
- unsigned int *nzc_counts;
- unsigned int (*nzc_branch_ct)[2];
- vp9_prob upd;
-
- if (!get_nzc_used(tx_size)) return;
- if (tx_size == TX_32X32) {
- tokens = NZC32X32_TOKENS;
- nzc_tree = vp9_nzc32x32_tree;
- old_nzc_probs = cm->fc.nzc_probs_32x32[0][0][0];
- new_nzc_probs = cpi->frame_nzc_probs_32x32[0][0][0];
- nzc_counts = cm->fc.nzc_counts_32x32[0][0][0];
- nzc_branch_ct = cpi->frame_nzc_branch_ct_32x32[0][0][0];
- upd = NZC_UPDATE_PROB_32X32;
- } else if (tx_size == TX_16X16) {
- tokens = NZC16X16_TOKENS;
- nzc_tree = vp9_nzc16x16_tree;
- old_nzc_probs = cm->fc.nzc_probs_16x16[0][0][0];
- new_nzc_probs = cpi->frame_nzc_probs_16x16[0][0][0];
- nzc_counts = cm->fc.nzc_counts_16x16[0][0][0];
- nzc_branch_ct = cpi->frame_nzc_branch_ct_16x16[0][0][0];
- upd = NZC_UPDATE_PROB_16X16;
- } else if (tx_size == TX_8X8) {
- tokens = NZC8X8_TOKENS;
- nzc_tree = vp9_nzc8x8_tree;
- old_nzc_probs = cm->fc.nzc_probs_8x8[0][0][0];
- new_nzc_probs = cpi->frame_nzc_probs_8x8[0][0][0];
- nzc_counts = cm->fc.nzc_counts_8x8[0][0][0];
- nzc_branch_ct = cpi->frame_nzc_branch_ct_8x8[0][0][0];
- upd = NZC_UPDATE_PROB_8X8;
- } else {
- nzc_tree = vp9_nzc4x4_tree;
- tokens = NZC4X4_TOKENS;
- old_nzc_probs = cm->fc.nzc_probs_4x4[0][0][0];
- new_nzc_probs = cpi->frame_nzc_probs_4x4[0][0][0];
- nzc_counts = cm->fc.nzc_counts_4x4[0][0][0];
- nzc_branch_ct = cpi->frame_nzc_branch_ct_4x4[0][0][0];
- upd = NZC_UPDATE_PROB_4X4;
- }
- nodes = tokens - 1;
- // Get the new probabilities and the branch counts
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (r = 0; r < REF_TYPES; ++r) {
- for (b = 0; b < BLOCK_TYPES; ++b) {
- int offset = c * REF_TYPES * BLOCK_TYPES + r * BLOCK_TYPES + b;
- int offset_nodes = offset * nodes;
- int offset_tokens = offset * tokens;
- vp9_tree_probs_from_distribution(nzc_tree,
- new_nzc_probs + offset_nodes,
- nzc_branch_ct + offset_nodes,
- nzc_counts + offset_tokens, 0);
- }
- }
- }
-
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (r = 0; r < REF_TYPES; ++r) {
- for (b = 0; b < BLOCK_TYPES; ++b) {
- int offset = c * REF_TYPES * BLOCK_TYPES + r * BLOCK_TYPES + b;
- int offset_nodes = offset * nodes;
- for (t = 0; t < nodes; ++t) {
- vp9_prob newp = new_nzc_probs[offset_nodes + t];
- vp9_prob oldp = old_nzc_probs[offset_nodes + t];
- int s, u = 0;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(nzc_branch_ct[offset_nodes],
- oldp, &newp, upd);
- if (s > 0 && newp != oldp)
- u = 1;
- if (u)
- savings += s - (int)(vp9_cost_zero(upd));
- else
- savings -= (int)(vp9_cost_zero(upd));
-#else
- s = prob_update_savings(nzc_branch_ct[offset_nodes],
- oldp, newp, upd);
- if (s > 0)
- u = 1;
- if (u)
- savings += s;
-#endif
- update[u]++;
- }
- }
- }
- }
- if (update[1] == 0 || savings < 0) {
- vp9_write_bit(bc, 0);
- } else {
- vp9_write_bit(bc, 1);
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (r = 0; r < REF_TYPES; ++r) {
- for (b = 0; b < BLOCK_TYPES; ++b) {
- int offset = c * REF_TYPES * BLOCK_TYPES + r * BLOCK_TYPES + b;
- int offset_nodes = offset * nodes;
- for (t = 0; t < nodes; ++t) {
- vp9_prob newp = new_nzc_probs[offset_nodes + t];
- vp9_prob *oldp = &old_nzc_probs[offset_nodes + t];
- int s, u = 0;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(nzc_branch_ct[offset_nodes],
- *oldp, &newp, upd);
- if (s > 0 && newp != *oldp)
- u = 1;
-#else
- s = prob_update_savings(nzc_branch_ct[offset_nodes],
- *oldp, newp, upd);
- if (s > 0)
- u = 1;
-#endif
- vp9_write(bc, u, upd);
- if (u) {
- /* send/use new probability */
- write_prob_diff_update(bc, newp, *oldp);
- *oldp = newp;
- }
- }
- }
- }
- }
- }
-}
-
-static void update_nzc_pcat_probs(VP9_COMP *cpi, vp9_writer* const bc) {
- VP9_COMMON *cm = &cpi->common;
- int c, t, b;
- int update[2] = {0, 0};
- int savings = 0;
- vp9_prob upd = NZC_UPDATE_PROB_PCAT;
- if (!(get_nzc_used(TX_4X4) || get_nzc_used(TX_8X8) ||
- get_nzc_used(TX_16X16) || get_nzc_used(TX_32X32)))
- return;
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (t = 0; t < NZC_TOKENS_EXTRA; ++t) {
- int bits = vp9_extranzcbits[t + NZC_TOKENS_NOEXTRA];
- for (b = 0; b < bits; ++b) {
- vp9_prob newp = get_binary_prob(cm->fc.nzc_pcat_counts[c][t][b][0],
- cm->fc.nzc_pcat_counts[c][t][b][1]);
- vp9_prob oldp = cm->fc.nzc_pcat_probs[c][t][b];
- int s, u = 0;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(cm->fc.nzc_pcat_counts[c][t][b],
- oldp, &newp, upd);
- if (s > 0 && newp != oldp)
- u = 1;
- if (u)
- savings += s - (int)(vp9_cost_zero(upd));
- else
- savings -= (int)(vp9_cost_zero(upd));
-#else
- s = prob_update_savings(cm->fc.nzc_pcat_counts[c][t][b],
- oldp, newp, upd);
- if (s > 0)
- u = 1;
- if (u)
- savings += s;
-#endif
- update[u]++;
- }
- }
- }
- if (update[1] == 0 || savings < 0) {
- vp9_write_bit(bc, 0);
- } else {
- vp9_write_bit(bc, 1);
- for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
- for (t = 0; t < NZC_TOKENS_EXTRA; ++t) {
- int bits = vp9_extranzcbits[t + NZC_TOKENS_NOEXTRA];
- for (b = 0; b < bits; ++b) {
- vp9_prob newp = get_binary_prob(cm->fc.nzc_pcat_counts[c][t][b][0],
- cm->fc.nzc_pcat_counts[c][t][b][1]);
- vp9_prob *oldp = &cm->fc.nzc_pcat_probs[c][t][b];
- int s, u = 0;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(cm->fc.nzc_pcat_counts[c][t][b],
- *oldp, &newp, upd);
- if (s > 0 && newp != *oldp)
- u = 1;
-#else
- s = prob_update_savings(cm->fc.nzc_pcat_counts[c][t][b],
- *oldp, newp, upd);
- if (s > 0)
- u = 1;
-#endif
- vp9_write(bc, u, upd);
- if (u) {
- /* send/use new probability */
- write_prob_diff_update(bc, newp, *oldp);
- *oldp = newp;
- }
- }
- }
- }
- }
-}
-
-static void update_nzc_probs(VP9_COMP* cpi,
- vp9_writer* const bc) {
- update_nzc_probs_common(cpi, bc, TX_4X4);
- if (cpi->common.txfm_mode != ONLY_4X4)
- update_nzc_probs_common(cpi, bc, TX_8X8);
- if (cpi->common.txfm_mode > ALLOW_8X8)
- update_nzc_probs_common(cpi, bc, TX_16X16);
- if (cpi->common.txfm_mode > ALLOW_16X16)
- update_nzc_probs_common(cpi, bc, TX_32X32);
-#ifdef NZC_PCAT_UPDATE
- update_nzc_pcat_probs(cpi, bc);
-#endif
-#ifdef NZC_STATS
- if (!cpi->dummy_packing)
- update_nzcstats(&cpi->common);
-#endif
-}
-#endif // CONFIG_CODE_NONZEROCOUNT
-
static void update_coef_probs_common(vp9_writer* const bc,
VP9_COMP *cpi,
#ifdef ENTROPY_STATS
@@ -2320,11 +1513,7 @@
#endif
// vp9_prob bestupd = find_coef_update_prob(cpi);
-#if CONFIG_CODE_NONZEROCOUNT
- const int tstart = get_nzc_used(tx_size);
-#else
const int tstart = 0;
-#endif
/* dry run to see if there is any udpate at all needed */
savings = 0;
for (i = 0; i < BLOCK_TYPES; ++i) {
@@ -2966,27 +2155,6 @@
cpi->common.fc.coef_probs_16x16);
vp9_copy(cpi->common.fc.pre_coef_probs_32x32,
cpi->common.fc.coef_probs_32x32);
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_copy(cpi->common.fc.pre_nzc_probs_4x4,
- cpi->common.fc.nzc_probs_4x4);
- vp9_copy(cpi->common.fc.pre_nzc_probs_8x8,
- cpi->common.fc.nzc_probs_8x8);
- vp9_copy(cpi->common.fc.pre_nzc_probs_16x16,
- cpi->common.fc.nzc_probs_16x16);
- vp9_copy(cpi->common.fc.pre_nzc_probs_32x32,
- cpi->common.fc.nzc_probs_32x32);
- vp9_copy(cpi->common.fc.pre_nzc_pcat_probs,
- cpi->common.fc.nzc_pcat_probs);
- // NOTE that if the counts are reset, we also need to uncomment
- // the count updates in the write_nzc function
- /*
- vp9_zero(cpi->common.fc.nzc_counts_4x4);
- vp9_zero(cpi->common.fc.nzc_counts_8x8);
- vp9_zero(cpi->common.fc.nzc_counts_16x16);
- vp9_zero(cpi->common.fc.nzc_counts_32x32);
- vp9_zero(cpi->common.fc.nzc_pcat_counts);
- */
-#endif
#if CONFIG_CODE_ZEROGROUP
vp9_copy(cpi->common.fc.pre_zpc_probs_4x4,
cpi->common.fc.zpc_probs_4x4);
@@ -3014,9 +2182,6 @@
vp9_zero(cpi->common.fc.mv_ref_ct);
update_coef_probs(cpi, &header_bc);
-#if CONFIG_CODE_NONZEROCOUNT
- update_nzc_probs(cpi, &header_bc);
-#endif
#if CONFIG_CODE_ZEROGROUP
update_zpc_probs(cpi, &header_bc);
#endif
--- a/vp9/encoder/vp9_block.h
+++ b/vp9/encoder/vp9_block.h
@@ -151,12 +151,6 @@
unsigned char *active_ptr;
vp9_coeff_count token_costs[TX_SIZE_MAX_SB][BLOCK_TYPES];
-#if CONFIG_CODE_NONZEROCOUNT
- unsigned int nzc_costs_4x4[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][17];
- unsigned int nzc_costs_8x8[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][65];
- unsigned int nzc_costs_16x16[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][257];
- unsigned int nzc_costs_32x32[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][1025];
-#endif
int optimize;
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -738,9 +738,6 @@
if ((mbmi->mode == ZEROMV) && (mbmi->ref_frame == LAST_FRAME))
cpi->inter_zz_count++;
}
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_update_nzc_counts(&cpi->common, xd, mb_row, mb_col);
-#endif
}
static void encode_sb(VP9_COMP *cpi,
@@ -1338,13 +1335,6 @@
vp9_zero(cpi->coef_counts_16x16);
vp9_zero(cpi->coef_counts_32x32);
vp9_zero(cm->fc.eob_branch_counts);
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_zero(cm->fc.nzc_counts_4x4);
- vp9_zero(cm->fc.nzc_counts_8x8);
- vp9_zero(cm->fc.nzc_counts_16x16);
- vp9_zero(cm->fc.nzc_counts_32x32);
- vp9_zero(cm->fc.nzc_pcat_counts);
-#endif
#if CONFIG_CODE_ZEROGROUP
vp9_zero(cm->fc.zpc_counts_4x4);
vp9_zero(cm->fc.zpc_counts_8x8);
@@ -1881,137 +1871,6 @@
#endif
}
-#if CONFIG_CODE_NONZEROCOUNT
-static void gather_nzcs_mb16(VP9_COMMON *const cm,
- MACROBLOCKD *xd) {
- int i;
- vpx_memset(xd->mode_info_context->mbmi.nzcs, 0,
- 384 * sizeof(xd->mode_info_context->mbmi.nzcs[0]));
- switch (xd->mode_info_context->mbmi.txfm_size) {
- case TX_4X4:
- for (i = 0; i < 24; ++i) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- break;
-
- case TX_8X8:
- for (i = 0; i < 16; i += 4) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- if (xd->mode_info_context->mbmi.mode == I8X8_PRED ||
- xd->mode_info_context->mbmi.mode == SPLITMV) {
- for (i = 16; i < 24; ++i) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- } else {
- for (i = 16; i < 24; i += 4) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- }
- break;
-
- case TX_16X16:
- xd->mode_info_context->mbmi.nzcs[0] = xd->nzcs[0];
- for (i = 16; i < 24; i += 4) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- break;
-
- default:
- break;
- }
-}
-
-static void gather_nzcs_sb32(VP9_COMMON *const cm,
- MACROBLOCKD *xd) {
- MODE_INFO *m = xd->mode_info_context;
- int mis = cm->mode_info_stride;
- int i, j;
-
- vpx_memset(m->mbmi.nzcs, 0,
- 384 * sizeof(xd->mode_info_context->mbmi.nzcs[0]));
- switch (xd->mode_info_context->mbmi.txfm_size) {
- case TX_4X4:
- for (i = 0; i < 96; ++i) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- break;
-
- case TX_8X8:
- for (i = 0; i < 96; i += 4) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- break;
-
- case TX_16X16:
- for (i = 0; i < 96; i += 16) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- break;
-
- case TX_32X32:
- xd->mode_info_context->mbmi.nzcs[0] = xd->nzcs[0];
- for (i = 64; i < 96; i += 16) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- break;
-
- default:
- break;
- }
- for (i = 0; i < 2; ++i)
- for (j = 0; j < 2; ++j) {
- if (i == 0 && j == 0) continue;
- vpx_memcpy((m + j + mis * i)->mbmi.nzcs, m->mbmi.nzcs,
- 384 * sizeof(m->mbmi.nzcs[0]));
- }
-}
-
-static void gather_nzcs_sb64(VP9_COMMON *const cm,
- MACROBLOCKD *xd) {
- MODE_INFO *m = xd->mode_info_context;
- int mis = cm->mode_info_stride;
- int i, j;
-
- vpx_memset(xd->mode_info_context->mbmi.nzcs, 0,
- 384 * sizeof(xd->mode_info_context->mbmi.nzcs[0]));
- switch (xd->mode_info_context->mbmi.txfm_size) {
- case TX_4X4:
- for (i = 0; i < 384; ++i) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- break;
-
- case TX_8X8:
- for (i = 0; i < 384; i += 4) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- break;
-
- case TX_16X16:
- for (i = 0; i < 384; i += 16) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- break;
-
- case TX_32X32:
- for (i = 0; i < 384; i += 64) {
- xd->mode_info_context->mbmi.nzcs[i] = xd->nzcs[i];
- }
- break;
-
- default:
- break;
- }
- for (i = 0; i < 4; ++i)
- for (j = 0; j < 4; ++j) {
- if (i == 0 && j == 0) continue;
- vpx_memcpy((m + j + mis * i)->mbmi.nzcs, m->mbmi.nzcs,
- 384 * sizeof(m->mbmi.nzcs[0]));
- }
-}
-#endif
-
static void encode_macroblock(VP9_COMP *cpi, TOKENEXTRA **t,
int output_enabled,
int mb_row, int mb_col) {
@@ -2197,9 +2056,6 @@
}
#endif
-#if CONFIG_CODE_NONZEROCOUNT
- gather_nzcs_mb16(cm, xd);
-#endif
vp9_tokenize_mb(cpi, xd, t, !output_enabled);
} else {
@@ -2419,13 +2275,6 @@
default: assert(0);
}
vp9_recon_sb_c(xd, bsize);
-#if CONFIG_CODE_NONZEROCOUNT
- if (bsize == BLOCK_SIZE_SB32X32) {
- gather_nzcs_sb32(cm, &x->e_mbd);
- } else {
- gather_nzcs_sb64(cm, &x->e_mbd);
- }
-#endif
vp9_tokenize_sb(cpi, &x->e_mbd, t, !output_enabled, bsize);
} else {
// FIXME(rbultje): not tile-aware (mi - 1)
--- a/vp9/encoder/vp9_encodemb.c
+++ b/vp9/encoder/vp9_encodemb.c
@@ -326,24 +326,6 @@
int const *scan, *nb;
const int mul = 1 + (tx_size == TX_32X32);
uint8_t token_cache[1024];
-#if CONFIG_CODE_NONZEROCOUNT
- // TODO(debargha): the dynamic programming approach used in this function
- // is not compatible with the true rate cost when nzcs are used. Note
- // the total rate is the sum of the nzc rate and the indicvidual token
- // rates. The latter part can be optimized in this function, but because
- // the nzc rate is a function of all the other tokens without a Markov
- // relationship this rate cannot be considered correctly.
- // The current implementation uses a suboptimal approach to account for
- // the nzc rates somewhat, but in reality the optimization approach needs
- // to change substantially.
- const int nzc_used = get_nzc_used(tx_size);
- uint16_t nzc = xd->nzcs[ib];
- uint16_t nzc0, nzc1;
- uint16_t final_nzc = 0, final_nzc_exp;
- int nzc_context = vp9_get_nzc_context(cm, xd, ib);
- unsigned int *nzc_cost;
- nzc0 = nzc1 = nzc;
-#endif
assert((!type && !pb_idx.plane) || (type && pb_idx.plane));
dqcoeff_ptr = BLOCK_OFFSET(xd->plane[pb_idx.plane].dqcoeff, pb_idx.block, 16);
@@ -353,9 +335,6 @@
case TX_4X4: {
const TX_TYPE tx_type = get_tx_type_4x4(xd, ib);
default_eob = 16;
-#if CONFIG_CODE_NONZEROCOUNT
- nzc_cost = mb->nzc_costs_4x4[nzc_context][ref][type];
-#endif
if (tx_type == DCT_ADST) {
scan = vp9_col_scan_4x4;
} else if (tx_type == ADST_DCT) {
@@ -378,9 +357,6 @@
scan = vp9_default_zig_zag1d_8x8;
}
default_eob = 64;
-#if CONFIG_CODE_NONZEROCOUNT
- nzc_cost = mb->nzc_costs_8x8[nzc_context][ref][type];
-#endif
break;
}
case TX_16X16: {
@@ -396,17 +372,11 @@
scan = vp9_default_zig_zag1d_16x16;
}
default_eob = 256;
-#if CONFIG_CODE_NONZEROCOUNT
- nzc_cost = mb->nzc_costs_16x16[nzc_context][ref][type];
-#endif
break;
}
case TX_32X32:
scan = vp9_default_zig_zag1d_32x32;
default_eob = 1024;
-#if CONFIG_CODE_NONZEROCOUNT
- nzc_cost = mb->nzc_costs_32x32[nzc_context][ref][type];
-#endif
break;
}
assert(eob <= default_eob);
@@ -418,11 +388,7 @@
rddiv = mb->rddiv;
memset(best_index, 0, sizeof(best_index));
/* Initialize the sentinel node of the trellis. */
-#if CONFIG_CODE_NONZEROCOUNT
- tokens[eob][0].rate = nzc_used ? nzc_cost[nzc] : 0;
-#else
tokens[eob][0].rate = 0;
-#endif
tokens[eob][0].error = 0;
tokens[eob][0].next = default_eob;
tokens[eob][0].token = DCT_EOB_TOKEN;
@@ -435,9 +401,6 @@
for (i = eob; i-- > i0;) {
int base_bits, d2, dx;
-#if CONFIG_CODE_NONZEROCOUNT
- int new_nzc0, new_nzc1;
-#endif
rc = scan[i];
x = qcoeff_ptr[rc];
@@ -472,9 +435,6 @@
tokens[i][0].token = t0;
tokens[i][0].qc = x;
best_index[i][0] = best;
-#if CONFIG_CODE_NONZEROCOUNT
- new_nzc0 = (best ? nzc1 : nzc0);
-#endif
/* Evaluate the second possibility for this state. */
rate0 = tokens[next][0].rate;
@@ -501,14 +461,6 @@
DCT_EOB_TOKEN : ZERO_TOKEN;
t1 = tokens[next][1].token == DCT_EOB_TOKEN ?
DCT_EOB_TOKEN : ZERO_TOKEN;
-#if CONFIG_CODE_NONZEROCOUNT
- // Account for rate drop because of the nzc change.
- // TODO(debargha): Find a better solution
- if (nzc_used) {
- rate0 -= nzc_cost[nzc0] - nzc_cost[nzc0 - 1];
- rate1 -= nzc_cost[nzc1] - nzc_cost[nzc1 - 1];
- }
-#endif
} else {
t0 = t1 = (vp9_dct_value_tokens_ptr + x)->token;
}
@@ -543,11 +495,6 @@
tokens[i][1].token = best ? t1 : t0;
tokens[i][1].qc = x;
best_index[i][1] = best;
-#if CONFIG_CODE_NONZEROCOUNT
- new_nzc1 = (best ? nzc1 : nzc0) - (!x);
- nzc0 = new_nzc0;
- nzc1 = new_nzc1;
-#endif
/* Finally, make this the new head of the trellis. */
next = i;
}
@@ -586,9 +533,6 @@
rate1 += mb->token_costs[tx_size][type][ref][band][pt][t1];
UPDATE_RD_COST();
best = rd_cost1 < rd_cost0;
-#if CONFIG_CODE_NONZEROCOUNT
- final_nzc_exp = (best ? nzc1 : nzc0);
-#endif
final_eob = i0 - 1;
vpx_memset(qcoeff_ptr, 0, sizeof(*qcoeff_ptr) * (16 << (tx_size * 2)));
vpx_memset(dqcoeff_ptr, 0, sizeof(*dqcoeff_ptr) * (16 << (tx_size * 2)));
@@ -596,9 +540,6 @@
x = tokens[i][best].qc;
if (x) {
final_eob = i;
-#if CONFIG_CODE_NONZEROCOUNT
- ++final_nzc;
-#endif
}
rc = scan[i];
qcoeff_ptr[rc] = x;
@@ -611,10 +552,6 @@
xd->plane[pb_idx.plane].eobs[pb_idx.block] = final_eob;
*a = *l = (final_eob > 0);
-#if CONFIG_CODE_NONZEROCOUNT
- assert(final_nzc == final_nzc_exp);
- xd->nzcs[ib] = final_nzc;
-#endif
}
void vp9_optimize_sby_32x32(VP9_COMMON *const cm, MACROBLOCK *x,
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -114,12 +114,6 @@
extern void print_nmvstats();
#endif
-#if CONFIG_CODE_NONZEROCOUNT
-#ifdef NZC_STATS
-extern void init_nzcstats();
-extern void print_nzcstats();
-#endif
-#endif
#if CONFIG_CODE_ZEROGROUP
#ifdef ZPC_STATS
extern void init_zpcstats();
@@ -1439,11 +1433,6 @@
#ifdef NMV_STATS
init_nmvstats();
#endif
-#if CONFIG_CODE_NONZEROCOUNT
-#ifdef NZC_STATS
- init_nzcstats();
-#endif
-#endif
#if CONFIG_CODE_ZEROGROUP
#ifdef ZPC_STATS
init_zpcstats();
@@ -1654,13 +1643,6 @@
cpi->common.error.setjmp = 0;
vp9_zero(cpi->y_uv_mode_count)
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_zero(cm->fc.nzc_counts_4x4);
- vp9_zero(cm->fc.nzc_counts_8x8);
- vp9_zero(cm->fc.nzc_counts_16x16);
- vp9_zero(cm->fc.nzc_counts_32x32);
- vp9_zero(cm->fc.nzc_pcat_counts);
-#endif
#if CONFIG_CODE_ZEROGROUP
vp9_zero(cm->fc.zpc_counts_4x4);
vp9_zero(cm->fc.zpc_counts_8x8);
@@ -1694,12 +1676,6 @@
if (cpi->pass != 1)
print_nmvstats();
#endif
-#if CONFIG_CODE_NONZEROCOUNT
-#ifdef NZC_STATS
- if (cpi->pass != 1)
- print_nzcstats();
-#endif
-#endif
#if CONFIG_CODE_ZEROGROUP
#ifdef ZPC_STATS
if (cpi->pass != 1)
@@ -3324,9 +3300,6 @@
if (!cpi->common.error_resilient_mode &&
!cpi->common.frame_parallel_decoding_mode) {
vp9_adapt_coef_probs(&cpi->common);
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_adapt_nzc_probs(&cpi->common);
-#endif
#if CONFIG_CODE_ZEROGROUP
vp9_adapt_zpc_probs(&cpi->common);
#endif
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -114,18 +114,6 @@
int mv_ref_ct[INTER_MODE_CONTEXTS][4][2];
int vp9_mode_contexts[INTER_MODE_CONTEXTS][4];
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_prob nzc_probs_4x4
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC4X4_NODES];
- vp9_prob nzc_probs_8x8
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC8X8_NODES];
- vp9_prob nzc_probs_16x16
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC16X16_NODES];
- vp9_prob nzc_probs_32x32
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC32X32_NODES];
- vp9_prob nzc_pcat_probs[MAX_NZC_CONTEXTS]
- [NZC_TOKENS_EXTRA][NZC_BITS_EXTRA];
-#endif
#if CONFIG_CODE_ZEROGROUP
vp9_zpc_probs zpc_probs_4x4;
vp9_zpc_probs zpc_probs_8x8;
@@ -492,25 +480,6 @@
vp9_coeff_count coef_counts_32x32[BLOCK_TYPES];
vp9_coeff_probs frame_coef_probs_32x32[BLOCK_TYPES];
vp9_coeff_stats frame_branch_ct_32x32[BLOCK_TYPES];
-
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_prob frame_nzc_probs_4x4
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC4X4_NODES];
- unsigned int frame_nzc_branch_ct_4x4
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC4X4_NODES][2];
- vp9_prob frame_nzc_probs_8x8
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC8X8_NODES];
- unsigned int frame_nzc_branch_ct_8x8
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC8X8_NODES][2];
- vp9_prob frame_nzc_probs_16x16
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC16X16_NODES];
- unsigned int frame_nzc_branch_ct_16x16
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC16X16_NODES][2];
- vp9_prob frame_nzc_probs_32x32
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC32X32_NODES];
- unsigned int frame_nzc_branch_ct_32x32
- [MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][NZC32X32_NODES][2];
-#endif
int gfu_boost;
int last_boost;
--- a/vp9/encoder/vp9_quantize.c
+++ b/vp9/encoder/vp9_quantize.c
@@ -45,9 +45,6 @@
int16_t *dequant_ptr = d->dequant;
int zbin_oq_value = b->zbin_extra;
const int *pt_scan;
-#if CONFIG_CODE_NONZEROCOUNT
- int nzc = 0;
-#endif
switch (tx_type) {
case ADST_DCT:
@@ -87,9 +84,6 @@
if (y) {
eob = i; // last nonzero coeffs
-#if CONFIG_CODE_NONZEROCOUNT
- ++nzc; // number of nonzero coeffs
-#endif
zbin_boost_ptr = b->zrun_zbin_boost; // reset zero runlength
}
}
@@ -97,9 +91,6 @@
}
xd->plane[0].eobs[b_idx] = eob + 1;
-#if CONFIG_CODE_NONZEROCOUNT
- xd->nzcs[b_idx] = nzc;
-#endif
}
void vp9_regular_quantize_b_4x4(MACROBLOCK *mb, int b_idx, int y_blocks) {
@@ -123,9 +114,6 @@
uint8_t *quant_shift_ptr = b->quant_shift;
int16_t *dequant_ptr = d->dequant;
int zbin_oq_value = b->zbin_extra;
-#if CONFIG_CODE_NONZEROCOUNT
- int nzc = 0;
-#endif
if (c_idx == 0) assert(pb_idx.plane == 0);
if (c_idx == 16) assert(pb_idx.plane == 1);
@@ -157,9 +145,6 @@
if (y) {
eob = i; // last nonzero coeffs
-#if CONFIG_CODE_NONZEROCOUNT
- ++nzc; // number of nonzero coeffs
-#endif
zbin_boost_ptr = b->zrun_zbin_boost; // reset zero runlength
}
}
@@ -167,9 +152,6 @@
}
xd->plane[pb_idx.plane].eobs[pb_idx.block] = eob + 1;
-#if CONFIG_CODE_NONZEROCOUNT
- xd->nzcs[b_idx] = nzc;
-#endif
}
void vp9_regular_quantize_b_8x8(MACROBLOCK *mb, int b_idx, TX_TYPE tx_type,
@@ -216,9 +198,6 @@
uint8_t *quant_shift_ptr = b->quant_shift;
int16_t *dequant_ptr = d->dequant;
int zbin_oq_value = b->zbin_extra;
-#if CONFIG_CODE_NONZEROCOUNT
- int nzc = 0;
-#endif
eob = -1;
@@ -242,9 +221,6 @@
if (y) {
eob = 0; // last nonzero coeffs
-#if CONFIG_CODE_NONZEROCOUNT
- ++nzc; // number of nonzero coeffs
-#endif
zero_run = 0;
}
}
@@ -271,22 +247,13 @@
if (y) {
eob = i; // last nonzero coeffs
-#if CONFIG_CODE_NONZEROCOUNT
- ++nzc; // number of nonzero coeffs
-#endif
zero_run = 0;
}
}
}
xd->plane[pb_idx.plane].eobs[pb_idx.block] = eob + 1;
-#if CONFIG_CODE_NONZEROCOUNT
- xd->nzcs[b_idx] = nzc;
-#endif
} else {
xd->plane[pb_idx.plane].eobs[pb_idx.block] = 0;
-#if CONFIG_CODE_NONZEROCOUNT
- xd->nzcs[b_idx] = 0;
-#endif
}
}
@@ -297,9 +264,6 @@
int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
int16_t *dequant_ptr, int zbin_oq_value,
uint16_t *eob_ptr,
-#if CONFIG_CODE_NONZEROCOUNT
- uint16_t *nzc_ptr,
-#endif
const int *scan, int mul) {
int i, rc, eob;
int zbin;
@@ -306,9 +270,6 @@
int x, y, z, sz;
int zero_run = 0;
int16_t *zbin_boost_ptr = zbin_boost_orig_ptr;
-#if CONFIG_CODE_NONZEROCOUNT
- int nzc = 0;
-#endif
vpx_memset(qcoeff_ptr, 0, n_coeffs*sizeof(int16_t));
vpx_memset(dqcoeff_ptr, 0, n_coeffs*sizeof(int16_t));
@@ -337,9 +298,6 @@
if (y) {
eob = i; // last nonzero coeffs
zero_run = 0;
-#if CONFIG_CODE_NONZEROCOUNT
- ++nzc; // number of nonzero coeffs
-#endif
}
}
}
@@ -346,9 +304,6 @@
}
*eob_ptr = eob + 1;
-#if CONFIG_CODE_NONZEROCOUNT
- *nzc_ptr = nzc;
-#endif
}
void vp9_regular_quantize_b_16x16(MACROBLOCK *mb, int b_idx, TX_TYPE tx_type,
@@ -384,9 +339,6 @@
d->dequant,
b->zbin_extra,
&xd->plane[pb_idx.plane].eobs[pb_idx.block],
-#if CONFIG_CODE_NONZEROCOUNT
- &xd->nzcs[b_idx],
-#endif
pt_scan, 1);
}
@@ -410,9 +362,6 @@
d->dequant,
b->zbin_extra,
&xd->plane[pb_idx.plane].eobs[pb_idx.block],
-#if CONFIG_CODE_NONZEROCOUNT
- &xd->nzcs[b_idx],
-#endif
vp9_default_zig_zag1d_32x32, 2);
}
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -172,13 +172,6 @@
#if CONFIG_COMP_INTERINTRA_PRED
cc->interintra_prob = cm->fc.interintra_prob;
#endif
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_copy(cc->nzc_probs_4x4, cm->fc.nzc_probs_4x4);
- vp9_copy(cc->nzc_probs_8x8, cm->fc.nzc_probs_8x8);
- vp9_copy(cc->nzc_probs_16x16, cm->fc.nzc_probs_16x16);
- vp9_copy(cc->nzc_probs_32x32, cm->fc.nzc_probs_32x32);
- vp9_copy(cc->nzc_pcat_probs, cm->fc.nzc_pcat_probs);
-#endif
#if CONFIG_CODE_ZEROGROUP
vp9_copy(cc->zpc_probs_4x4, cm->fc.zpc_probs_4x4);
vp9_copy(cc->zpc_probs_8x8, cm->fc.zpc_probs_8x8);
@@ -240,13 +233,6 @@
vp9_copy(cm->fc.switchable_interp_prob, cc->switchable_interp_prob);
#if CONFIG_COMP_INTERINTRA_PRED
cm->fc.interintra_prob = cc->interintra_prob;
-#endif
-#if CONFIG_CODE_NONZEROCOUNT
- vp9_copy(cm->fc.nzc_probs_4x4, cc->nzc_probs_4x4);
- vp9_copy(cm->fc.nzc_probs_8x8, cc->nzc_probs_8x8);
- vp9_copy(cm->fc.nzc_probs_16x16, cc->nzc_probs_16x16);
- vp9_copy(cm->fc.nzc_probs_32x32, cc->nzc_probs_32x32);
- vp9_copy(cm->fc.nzc_pcat_probs, cc->nzc_pcat_probs);
#endif
#if CONFIG_CODE_ZEROGROUP
vp9_copy(cm->fc.zpc_probs_4x4, cc->zpc_probs_4x4);
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -162,60 +162,6 @@
}
}
-#if CONFIG_CODE_NONZEROCOUNT
-static void fill_nzc_costs(VP9_COMP *cpi, TX_SIZE tx_size) {
- int nzc_context, r, b, nzc, values;
- int cost[16];
- values = (16 << (2 * tx_size)) + 1;
-
- for (nzc_context = 0; nzc_context < MAX_NZC_CONTEXTS; ++nzc_context) {
- for (r = 0; r < REF_TYPES; ++r) {
- for (b = 0; b < BLOCK_TYPES; ++b) {
- unsigned int *nzc_costs;
- if (tx_size == TX_4X4) {
- vp9_cost_tokens(cost,
- cpi->common.fc.nzc_probs_4x4[nzc_context][r][b],
- vp9_nzc4x4_tree);
- nzc_costs = cpi->mb.nzc_costs_4x4[nzc_context][r][b];
- } else if (tx_size == TX_8X8) {
- vp9_cost_tokens(cost,
- cpi->common.fc.nzc_probs_8x8[nzc_context][r][b],
- vp9_nzc8x8_tree);
- nzc_costs = cpi->mb.nzc_costs_8x8[nzc_context][r][b];
- } else if (tx_size == TX_16X16) {
- vp9_cost_tokens(cost,
- cpi->common.fc.nzc_probs_16x16[nzc_context][r][b],
- vp9_nzc16x16_tree);
- nzc_costs = cpi->mb.nzc_costs_16x16[nzc_context][r][b];
- } else {
- vp9_cost_tokens(cost,
- cpi->common.fc.nzc_probs_32x32[nzc_context][r][b],
- vp9_nzc32x32_tree);
- nzc_costs = cpi->mb.nzc_costs_32x32[nzc_context][r][b];
- }
-
- for (nzc = 0; nzc < values; ++nzc) {
- int e, c, totalcost = 0;
- c = codenzc(nzc);
- totalcost = cost[c];
- if ((e = vp9_extranzcbits[c])) {
- int x = nzc - vp9_basenzcvalue[c];
- while (e--) {
- totalcost += vp9_cost_bit(
- cpi->common.fc.nzc_pcat_probs[nzc_context]
- [c - NZC_TOKENS_NOEXTRA][e],
- ((x >> e) & 1));
- }
- }
- nzc_costs[nzc] = totalcost;
- }
- }
- }
- }
-}
-#endif
-
-
static int rd_iifactor[32] = { 4, 4, 3, 2, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
@@ -313,12 +259,6 @@
cpi->common.fc.coef_probs_16x16, TX_16X16);
fill_token_costs(cpi->mb.token_costs[TX_32X32],
cpi->common.fc.coef_probs_32x32, TX_32X32);
-#if CONFIG_CODE_NONZEROCOUNT
- fill_nzc_costs(cpi, TX_4X4);
- fill_nzc_costs(cpi, TX_8X8);
- fill_nzc_costs(cpi, TX_16X16);
- fill_nzc_costs(cpi, TX_32X32);
-#endif
for (i = 0; i < 2; i++)
vp9_cost_tokens(cpi->mb.partition_cost[i],
@@ -376,11 +316,6 @@
sizeof(ENTROPY_CONTEXT_PLANES)/sizeof(ENTROPY_CONTEXT);
TX_TYPE tx_type = DCT_DCT;
-#if CONFIG_CODE_NONZEROCOUNT
- const int nzc_used = get_nzc_used(tx_size);
- int nzc_context = vp9_get_nzc_context(cm, xd, ib);
- unsigned int *nzc_cost;
-#endif
#if CONFIG_CODE_ZEROGROUP
int last_nz_pos[3] = {-1, -1, -1}; // Encoder only
int is_eoo_list[3] = {0, 0, 0};
@@ -415,9 +350,6 @@
get_tx_type_4x4(xd, ib) : DCT_DCT;
a_ec = *a;
l_ec = *l;
-#if CONFIG_CODE_NONZEROCOUNT
- nzc_cost = mb->nzc_costs_4x4[nzc_context][ref][type];
-#endif
coef_probs = cm->fc.coef_probs_4x4;
seg_eob = 16;
if (tx_type == ADST_DCT) {
@@ -447,9 +379,6 @@
} else {
scan = vp9_default_zig_zag1d_8x8;
}
-#if CONFIG_CODE_NONZEROCOUNT
- nzc_cost = mb->nzc_costs_8x8[nzc_context][ref][type];
-#endif
coef_probs = cm->fc.coef_probs_8x8;
seg_eob = 64;
#if CONFIG_CODE_ZEROGROUP
@@ -470,9 +399,6 @@
} else {
scan = vp9_default_zig_zag1d_16x16;
}
-#if CONFIG_CODE_NONZEROCOUNT
- nzc_cost = mb->nzc_costs_16x16[nzc_context][ref][type];
-#endif
coef_probs = cm->fc.coef_probs_16x16;
seg_eob = 256;
if (type == PLANE_TYPE_UV) {
@@ -489,9 +415,6 @@
}
case TX_32X32:
scan = vp9_default_zig_zag1d_32x32;
-#if CONFIG_CODE_NONZEROCOUNT
- nzc_cost = mb->nzc_costs_32x32[nzc_context][ref][type];
-#endif
coef_probs = cm->fc.coef_probs_32x32;
seg_eob = 1024;
if (type == PLANE_TYPE_UV) {
@@ -524,11 +447,8 @@
nb = vp9_get_coef_neighbors_handle(scan, &pad);
default_eob = seg_eob;
-#if CONFIG_CODE_NONZEROCOUNT
- if (!nzc_used)
-#endif
- if (vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP))
- seg_eob = 0;
+ if (vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP))
+ seg_eob = 0;
/* sanity check to ensure that we do not have spurious non-zero q values */
if (eob < seg_eob)
@@ -545,16 +465,10 @@
}
#endif
{
-#if CONFIG_CODE_NONZEROCOUNT
- int nzc = 0;
-#endif
for (c = 0; c < eob; c++) {
int v = qcoeff_ptr[scan[c]];
int t = vp9_dct_value_tokens_ptr[v].token;
int band = get_coef_band(scan, tx_size, c);
-#if CONFIG_CODE_NONZEROCOUNT
- nzc += (v != 0);
-#endif
if (c)
pt = vp9_get_coef_context(scan, nb, pad, token_cache, c, default_eob);
#if CONFIG_CODE_ZEROGROUP
@@ -569,11 +483,8 @@
#else
cost += token_costs[band][pt][t] + vp9_dct_value_cost_ptr[v];
#endif
-#if CONFIG_CODE_NONZEROCOUNT
- if (!nzc_used)
-#endif
- if (!c || token_cache[scan[c - 1]])
- cost += vp9_cost_bit(coef_probs[type][ref][band][pt][0], 1);
+ if (!c || token_cache[scan[c - 1]])
+ cost += vp9_cost_bit(coef_probs[type][ref][band][pt][0], 1);
token_cache[scan[c]] = t;
#if CONFIG_CODE_ZEROGROUP
if (t == ZERO_TOKEN && !skip_coef_val) {
@@ -632,22 +543,17 @@
is_last_zero[o] = (t == ZERO_TOKEN);
#endif
}
-#if CONFIG_CODE_NONZEROCOUNT
- if (nzc_used)
- cost += nzc_cost[nzc];
- else
-#endif
- if (c < seg_eob) {
- if (c)
- pt = vp9_get_coef_context(scan, nb, pad, token_cache, c, default_eob);
- cost += mb->token_costs[tx_size][type][ref]
- [get_coef_band(scan, tx_size, c)]
- [pt][DCT_EOB_TOKEN];
- }
+ if (c < seg_eob) {
+ if (c)
+ pt = vp9_get_coef_context(scan, nb, pad, token_cache, c, default_eob);
+ cost += mb->token_costs[tx_size][type][ref]
+ [get_coef_band(scan, tx_size, c)]
+ [pt][DCT_EOB_TOKEN];
+ }
}
- // is eob first coefficient;
- pt = (c > 0);
+ // is eob first coefficient;
+ pt = (c > 0);
*a = *l = pt;
if (tx_size >= TX_8X8) {
a[1] = l[1] = pt;
--- a/vp9/encoder/vp9_tokenize.c
+++ b/vp9/encoder/vp9_tokenize.c
@@ -36,21 +36,6 @@
extern vp9_coeff_stats tree_update_hist_32x32[BLOCK_TYPES];
#endif /* ENTROPY_STATS */
-#if CONFIG_CODE_NONZEROCOUNT
-#ifdef NZC_STATS
-unsigned int nzc_counts_4x4[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC4X4_TOKENS];
-unsigned int nzc_counts_8x8[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC8X8_TOKENS];
-unsigned int nzc_counts_16x16[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC16X16_TOKENS];
-unsigned int nzc_counts_32x32[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES]
- [NZC32X32_TOKENS];
-unsigned int nzc_pcat_counts[MAX_NZC_CONTEXTS][NZC_TOKENS_EXTRA]
- [NZC_BITS_EXTRA][2];
-#endif
-#endif
-
static TOKENVALUE dct_value_tokens[DCT_MAX_VALUE * 2];
const TOKENVALUE *vp9_dct_value_tokens_ptr;
static int dct_value_cost[DCT_MAX_VALUE * 2];
@@ -147,12 +132,6 @@
vp9_zpc_count *zpc_count;
uint8_t token_cache_full[1024];
#endif
-#if CONFIG_CODE_NONZEROCOUNT
- const int nzc_used = get_nzc_used(tx_size);
- int zerosleft = 0, nzc = 0;
- if (eob == 0)
- assert(xd->nzcs[ib] == 0);
-#endif
#if CONFIG_CODE_ZEROGROUP
vpx_memset(token_cache, UNKNOWN_TOKEN, sizeof(token_cache));
#endif
@@ -343,10 +322,6 @@
rc = scan[c];
if (c)
pt = vp9_get_coef_context(scan, nb, pad, token_cache, c, default_eob);
-#if CONFIG_CODE_NONZEROCOUNT
- if (nzc_used)
- zerosleft = seg_eob - xd->nzcs[ib] - c + nzc;
-#endif
if (c < eob) {
v = qcoeff_ptr[rc];
assert(-DCT_MAX_VALUE <= v && v < DCT_MAX_VALUE);
@@ -354,22 +329,11 @@
t->extra = vp9_dct_value_tokens_ptr[v].extra;
token = vp9_dct_value_tokens_ptr[v].token;
} else {
-#if CONFIG_CODE_NONZEROCOUNT
- if (nzc_used)
- break;
- else
-#endif
- token = DCT_EOB_TOKEN;
+ token = DCT_EOB_TOKEN;
}
t->token = token;
t->context_tree = coef_probs[type][ref][band][pt];
-#if CONFIG_CODE_NONZEROCOUNT
- // Skip zero node if there are no zeros left
- if (nzc_used)
- t->skip_eob_node = 1 + (zerosleft == 0);
- else
-#endif
t->skip_eob_node = (c > 0) && (token_cache[scan[c - 1]] == 0);
assert(vp9_coef_encodings[t->token].len - t->skip_eob_node > 0);
#if CONFIG_CODE_ZEROGROUP
@@ -391,9 +355,6 @@
if (!t->skip_eob_node)
++cpi->common.fc.eob_branch_counts[tx_size][type][ref][band][pt];
}
-#if CONFIG_CODE_NONZEROCOUNT
- nzc += (v != 0);
-#endif
token_cache[scan[c]] = token;
#if CONFIG_CODE_ZEROGROUP
if (token == ZERO_TOKEN && !t->skip_coef_val) {
@@ -464,10 +425,7 @@
is_last_zero[o] = (token == ZERO_TOKEN);
#endif
++t;
-} while (c < eob && ++c < seg_eob);
-#if CONFIG_CODE_NONZEROCOUNT
-assert(nzc == xd->nzcs[ib]);
-#endif
+ } while (c < eob && ++c < seg_eob);
*tp = t;
a_ec = l_ec = (c > 0); /* 0 <-> all coeff data is zero */
@@ -860,9 +818,6 @@
TOKENEXTRA *t = *tp;
const int ref = mbmi->ref_frame != INTRA_FRAME;
ENTROPY_CONTEXT *a, *l, *a1, *l1, *a2, *l2, *a3, *l3, a_ec, l_ec;
-#if CONFIG_CODE_NONZEROCOUNT
- const int nzc_used = get_nzc_used(tx_size);
-#endif
if (sb_type == BLOCK_SIZE_SB64X64) {
a = (ENTROPY_CONTEXT *)xd->above_context +
@@ -928,26 +883,20 @@
break;
}
-#if CONFIG_CODE_NONZEROCOUNT
- if (!nzc_used) {
-#endif
- pt = combine_entropy_contexts(a_ec, l_ec);
- band = 0;
- t->token = DCT_EOB_TOKEN;
- t->context_tree = probs[type][ref][band][pt];
- t->skip_eob_node = 0;
+ pt = combine_entropy_contexts(a_ec, l_ec);
+ band = 0;
+ t->token = DCT_EOB_TOKEN;
+ t->context_tree = probs[type][ref][band][pt];
+ t->skip_eob_node = 0;
#if CONFIG_CODE_ZEROGROUP
- t->skip_coef_val = 0;
+ t->skip_coef_val = 0;
#endif
- ++t;
- *tp = t;
- if (!dry_run) {
- ++counts[type][ref][band][pt][DCT_EOB_TOKEN];
- }
-#if CONFIG_CODE_NONZEROCOUNT
+ ++t;
+ *tp = t;
+ if (!dry_run) {
+ ++counts[type][ref][band][pt][DCT_EOB_TOKEN];
}
-#endif
- *a = *l = 0;
+ *a = *l = 0;
if (tx_size == TX_8X8) {
a[1] = 0;
l[1] = 0;