15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Use of this source code is governed by a BSD-style license 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * that can be found in the LICENSE file in the root of the source 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * tree. An additional intellectual property rights grant can be found 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) * in the file PATENTS. All contributing project authors may 8f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * be found in the AUTHORS file in the root of the source tree. 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "vp9/common/vp9_blockd.h" 134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "vp9/common/vp9_common_data.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Log 2 conversion lookup tables for block width and height 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int b_width_log2_lookup[BLOCK_SIZES] = 17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch {0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4}; 18eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst int b_height_log2_lookup[BLOCK_SIZES] = 19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch {0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 4, 3, 4}; 20eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst int num_4x4_blocks_wide_lookup[BLOCK_SIZES] = 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) {1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16}; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int num_4x4_blocks_high_lookup[BLOCK_SIZES] = 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) {1, 2, 1, 2, 4, 2, 4, 8, 4, 8, 16, 8, 16}; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Log 2 conversion lookup tables for modeinfo width and height 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int mi_width_log2_lookup[BLOCK_SIZES] = 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) {0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3}; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int num_8x8_blocks_wide_lookup[BLOCK_SIZES] = 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) {1, 1, 1, 1, 1, 2, 2, 2, 4, 4, 4, 8, 8}; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int num_8x8_blocks_high_lookup[BLOCK_SIZES] = 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) {1, 1, 1, 1, 2, 1, 2, 4, 2, 4, 8, 4, 8}; 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// MIN(3, MIN(b_width_log2(bsize), b_height_log2(bsize))) 33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst int size_group_lookup[BLOCK_SIZES] = 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3}; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int num_pels_log2_lookup[BLOCK_SIZES] = 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) {4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12}; 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)const PARTITION_TYPE partition_lookup[][BLOCK_SIZES] = { 41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { // 4X4 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_NONE, PARTITION_INVALID, PARTITION_INVALID, 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID, 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID, 4668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID, 4768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) PARTITION_INVALID 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }, { // 8X8 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_SPLIT, PARTITION_VERT, PARTITION_HORZ, PARTITION_NONE, 514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID, 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID, 53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }, { // 16X16 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_VERT, PARTITION_HORZ, PARTITION_NONE, PARTITION_INVALID, 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID, 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_INVALID, PARTITION_INVALID 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }, { // 32X32 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_VERT, 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_HORZ, PARTITION_NONE, PARTITION_INVALID, 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_INVALID, PARTITION_INVALID 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }, { // 64X64 67c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, 704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_VERT, PARTITION_HORZ, 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_NONE 72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const BLOCK_SIZE subsize_lookup[PARTITION_TYPES][BLOCK_SIZES] = { 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { // PARTITION_NONE 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BLOCK_4X4, BLOCK_4X8, BLOCK_8X4, 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_8X8, BLOCK_8X16, BLOCK_16X8, 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_16X16, BLOCK_16X32, BLOCK_32X16, 804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) BLOCK_32X32, BLOCK_32X64, BLOCK_64X32, 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_64X64, 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }, { // PARTITION_HORZ 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_8X4, BLOCK_INVALID, BLOCK_INVALID, 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_16X8, BLOCK_INVALID, BLOCK_INVALID, 86effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch BLOCK_32X16, BLOCK_INVALID, BLOCK_INVALID, 87effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch BLOCK_64X32, 88f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) }, { // PARTITION_VERT 894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_4X8, BLOCK_INVALID, BLOCK_INVALID, 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_8X16, BLOCK_INVALID, BLOCK_INVALID, 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_16X32, BLOCK_INVALID, BLOCK_INVALID, 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_32X64, 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }, { // PARTITION_SPLIT 954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, 964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) BLOCK_4X4, BLOCK_INVALID, BLOCK_INVALID, 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_8X8, BLOCK_INVALID, BLOCK_INVALID, 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_16X16, BLOCK_INVALID, BLOCK_INVALID, 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) BLOCK_32X32, 100eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 101eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}; 102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 103eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst TX_SIZE max_txsize_lookup[BLOCK_SIZES] = { 104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) TX_4X4, TX_4X4, TX_4X4, 105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) TX_8X8, TX_8X8, TX_8X8, 106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) TX_16X16, TX_16X16, TX_16X16, 107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TX_32X32, TX_32X32, TX_32X32, TX_32X32 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const BLOCK_SIZE txsize_to_bsize[TX_SIZES] = { 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_4X4, // TX_4X4 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_8X8, // TX_8X8 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_16X16, // TX_16X16 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLOCK_32X32, // TX_32X32 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const TX_SIZE tx_mode_to_biggest_tx_size[TX_MODES] = { 118a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) TX_4X4, // ONLY_4X4 119a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) TX_8X8, // ALLOW_8X8 120a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) TX_16X16, // ALLOW_16X16 121a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) TX_32X32, // ALLOW_32X32 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TX_32X32, // TX_MODE_SELECT 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const BLOCK_SIZE ss_size_lookup[BLOCK_SIZES][2][2] = { 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ss_x == 0 ss_x == 0 ss_x == 1 ss_x == 1 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ss_y == 0 ss_y == 1 ss_y == 0 ss_y == 1 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) {{BLOCK_4X4, BLOCK_INVALID}, {BLOCK_INVALID, BLOCK_INVALID}}, 129f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) {{BLOCK_4X8, BLOCK_4X4}, {BLOCK_INVALID, BLOCK_INVALID}}, 130f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) {{BLOCK_8X4, BLOCK_INVALID}, {BLOCK_4X4, BLOCK_INVALID}}, 131f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) {{BLOCK_8X8, BLOCK_8X4}, {BLOCK_4X8, BLOCK_4X4}}, 1324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) {{BLOCK_8X16, BLOCK_8X8}, {BLOCK_INVALID, BLOCK_4X8}}, 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) {{BLOCK_16X8, BLOCK_INVALID}, {BLOCK_8X8, BLOCK_8X4}}, 1344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) {{BLOCK_16X16, BLOCK_16X8}, {BLOCK_8X16, BLOCK_8X8}}, 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) {{BLOCK_16X32, BLOCK_16X16}, {BLOCK_INVALID, BLOCK_8X16}}, 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) {{BLOCK_32X16, BLOCK_INVALID}, {BLOCK_16X16, BLOCK_16X8}}, 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) {{BLOCK_32X32, BLOCK_32X16}, {BLOCK_16X32, BLOCK_16X16}}, 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) {{BLOCK_32X64, BLOCK_32X32}, {BLOCK_INVALID, BLOCK_16X32}}, 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) {{BLOCK_64X32, BLOCK_INVALID}, {BLOCK_32X32, BLOCK_32X16}}, 140a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) {{BLOCK_64X64, BLOCK_64X32}, {BLOCK_32X64, BLOCK_32X32}}, 141a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}; 142f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 143f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Generates 4 bit field in which each bit set to 1 represents 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// a blocksize partition 1111 means we split 64x64, 32x32, 16x16 1454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// and 8x8. 1000 means we just split the 64x64 to 32x32 1464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)const struct { 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_CONTEXT above; 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PARTITION_CONTEXT left; 1493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} partition_context_lookup[BLOCK_SIZES]= { 1503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) {15, 15}, // 4X4 - {0b1111, 0b1111} 1513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) {15, 14}, // 4X8 - {0b1111, 0b1110} 1523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) {14, 15}, // 8X4 - {0b1110, 0b1111} 1533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) {14, 14}, // 8X8 - {0b1110, 0b1110} 1543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) {14, 12}, // 8X16 - {0b1110, 0b1100} 1553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) {12, 14}, // 16X8 - {0b1100, 0b1110} 1563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) {12, 12}, // 16X16 - {0b1100, 0b1100} 1573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) {12, 8 }, // 16X32 - {0b1100, 0b1000} 1583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) {8, 12}, // 32X16 - {0b1000, 0b1100} 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) {8, 8 }, // 32X32 - {0b1000, 0b1000} 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) {8, 0 }, // 32X64 - {0b1000, 0b0000} 1613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) {0, 8 }, // 64X32 - {0b0000, 0b1000} 1623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) {0, 0 }, // 64X64 - {0b0000, 0b0000} 1633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}; 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)