1 /*
2 * Copyright(c) 2019 Intel Corporation
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at https://www.aomedia.org/license/software-license. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at https://www.aomedia.org/license/patent-license.
10 */
11 
12 #include <stdio.h>
13 
14 #ifdef _WIN32
15 #include <windows.h>
16 #else
17 #include <stdlib.h>
18 #include <sys/time.h>
19 #endif
20 
21 #include "EbUtility.h"
22 #include "EbLog.h"
23 #include <math.h>
24 
25 /* assert a certain condition and report err if condition not met */
assert_err(uint32_t condition,char * err_msg)26 void assert_err(uint32_t condition, char * err_msg) {
27     assert(condition);
28     if (!condition)
29         SVT_ERROR("\n %s \n", err_msg);
30 }
31 
32 /********************************************************************************************
33 * faster memcopy for <= 64B blocks, great w/ inlining and size known at compile time (or w/ PGO)
34 * THIS NEEDS TO STAY IN A HEADER FOR BEST PERFORMANCE
35 ********************************************************************************************/
36 #ifdef ARCH_X86_64
37 #include <immintrin.h>
38 #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC__)
39 __attribute__((optimize("unroll-loops")))
40 #endif
41 static void
svt_memcpy_small(void * dst_ptr,const void * src_ptr,size_t size)42 svt_memcpy_small(void* dst_ptr, const void* src_ptr, size_t size) {
43     const unsigned char* src = src_ptr;
44     unsigned char*       dst = dst_ptr;
45     size_t               i   = 0;
46 
47 #ifdef _INTEL_COMPILER
48 #pragma unroll
49 #endif
50     while ((i + 16) <= size) {
51         _mm_storeu_ps((float*)(void*)(dst + i), _mm_loadu_ps((const float*)(const void*)(src + i)));
52         i += 16;
53     }
54 
55     if ((i + 8) <= size) {
56         _mm_store_sd((double*)(void*)(dst + i), _mm_load_sd((const double*)(const void*)(src + i)));
57         i += 8;
58     }
59 
60     for (; i < size; ++i) dst[i] = src[i];
61 }
62 #define EB_MIN(a, b) (((a) < (b)) ? (a) : (b))
svt_memcpy_sse(void * dst_ptr,const void * src_ptr,size_t size)63 static void svt_memcpy_sse(void* dst_ptr, const void* src_ptr, size_t size) {
64     const unsigned char* src       = src_ptr;
65     unsigned char*       dst       = dst_ptr;
66     size_t               i         = 0;
67     size_t               align_cnt = EB_MIN((64 - ((size_t)dst & 63)), size);
68 
69     // align dest to a $line
70     if (align_cnt != 64) {
71         svt_memcpy_small(dst, src, align_cnt);
72         dst += align_cnt;
73         src += align_cnt;
74         size -= align_cnt;
75     }
76 
77     // copy a $line at a time
78     // dst aligned to a $line
79     size_t cline_cnt = (size & ~(size_t)63);
80     for (i = 0; i < cline_cnt; i += 64) {
81         __m128 c0 = _mm_loadu_ps((const float*)(const void*)(src + i));
82         __m128 c1 = _mm_loadu_ps((const float*)(const void*)(src + i + sizeof(c0)));
83         __m128 c2 = _mm_loadu_ps((const float*)(const void*)(src + i + sizeof(c0) * 2));
84         __m128 c3 = _mm_loadu_ps((const float*)(const void*)(src + i + sizeof(c0) * 3));
85 
86         _mm_storeu_ps((float*)(void*)(dst + i), c0);
87         _mm_storeu_ps((float*)(void*)(dst + i + sizeof(c0)), c1);
88         _mm_storeu_ps((float*)(void*)(dst + i + sizeof(c0) * 2), c2);
89         _mm_storeu_ps((float*)(void*)(dst + i + sizeof(c0) * 3), c3);
90     }
91 
92     // copy the remainder
93     if (i < size)
94         svt_memcpy_small(dst + i, src + i, size - i);
95 }
svt_memcpy_app(void * dst_ptr,const void * src_ptr,size_t size)96 void svt_memcpy_app(void* dst_ptr, const void* src_ptr, size_t size) {
97     if (size > 64)
98         svt_memcpy_sse(dst_ptr, src_ptr, size);
99     else
100         svt_memcpy_small(dst_ptr, src_ptr, size);
101 }
102 #endif
103 /*****************************************
104  * Z-Order
105  *****************************************/
106 static TxSize blocksize_to_txsize[BlockSizeS_ALL] = {
107     TX_4X4, // BLOCK_4X4
108     TX_4X8, // BLOCK_4X8
109     TX_8X4, // BLOCK_8X4
110     TX_8X8, // BLOCK_8X8
111     TX_8X16, // BLOCK_8X16
112     TX_16X8, // BLOCK_16X8
113     TX_16X16, // BLOCK_16X16
114     TX_16X32, // BLOCK_16X32
115     TX_32X16, // BLOCK_32X16
116     TX_32X32, // BLOCK_32X32
117     TX_32X64, // BLOCK_32X64
118     TX_64X32, // BLOCK_64X32
119     TX_64X64, // BLOCK_64X64
120     TX_64X64, // BLOCK_64X128
121     TX_64X64, // BLOCK_128X64
122     TX_64X64, // BLOCK_128X128
123     TX_4X16, // BLOCK_4X16
124     TX_16X4, // BLOCK_16X4
125     TX_8X32, // BLOCK_8X32
126     TX_32X8, // BLOCK_32X8
127     TX_16X64, // BLOCK_16X64
128     TX_64X16 // BLOCK_64X16
129 };
130 
131 static CodedBlockStats coded_unit_stats_array[] = {
132     //   Depth       Size      SizeLog2     OriginX    OriginY   cu_num_in_depth   Index
133     {0, 64, 6, 0, 0, 0, 0}, // 0
134     {1, 32, 5, 0, 0, 0, 1}, // 1
135     {2, 16, 4, 0, 0, 0, 1}, // 2
136     {3, 8, 3, 0, 0, 0, 1}, // 3
137     {3, 8, 3, 8, 0, 1, 1}, // 4
138     {3, 8, 3, 0, 8, 8, 1}, // 5
139     {3, 8, 3, 8, 8, 9, 1}, // 6
140     {2, 16, 4, 16, 0, 1, 1}, // 7
141     {3, 8, 3, 16, 0, 2, 1}, // 8
142     {3, 8, 3, 24, 0, 3, 1}, // 9
143     {3, 8, 3, 16, 8, 10, 1}, // 10
144     {3, 8, 3, 24, 8, 11, 1}, // 11
145     {2, 16, 4, 0, 16, 4, 1}, // 12
146     {3, 8, 3, 0, 16, 16, 1}, // 13
147     {3, 8, 3, 8, 16, 17, 1}, // 14
148     {3, 8, 3, 0, 24, 24, 1}, // 15
149     {3, 8, 3, 8, 24, 25, 1}, // 16
150     {2, 16, 4, 16, 16, 5, 1}, // 17
151     {3, 8, 3, 16, 16, 18, 1}, // 18
152     {3, 8, 3, 24, 16, 19, 1}, // 19
153     {3, 8, 3, 16, 24, 26, 1}, // 20
154     {3, 8, 3, 24, 24, 27, 1}, // 21
155     {1, 32, 5, 32, 0, 1, 2}, // 22
156     {2, 16, 4, 32, 0, 2, 2}, // 23
157     {3, 8, 3, 32, 0, 4, 2}, // 24
158     {3, 8, 3, 40, 0, 5, 2}, // 25
159     {3, 8, 3, 32, 8, 12, 2}, // 26
160     {3, 8, 3, 40, 8, 13, 2}, // 27
161     {2, 16, 4, 48, 0, 3, 2}, // 28
162     {3, 8, 3, 48, 0, 6, 2}, // 29
163     {3, 8, 3, 56, 0, 7, 2}, // 30
164     {3, 8, 3, 48, 8, 14, 2}, // 31
165     {3, 8, 3, 56, 8, 15, 2}, // 32
166     {2, 16, 4, 32, 16, 6, 2}, // 33
167     {3, 8, 3, 32, 16, 20, 2}, // 34
168     {3, 8, 3, 40, 16, 21, 2}, // 35
169     {3, 8, 3, 32, 24, 28, 2}, // 36
170     {3, 8, 3, 40, 24, 29, 2}, // 37
171     {2, 16, 4, 48, 16, 7, 2}, // 38
172     {3, 8, 3, 48, 16, 22, 2}, // 39
173     {3, 8, 3, 56, 16, 23, 2}, // 40
174     {3, 8, 3, 48, 24, 30, 2}, // 41
175     {3, 8, 3, 56, 24, 31, 2}, // 42
176     {1, 32, 5, 0, 32, 2, 3}, // 43
177     {2, 16, 4, 0, 32, 8, 3}, // 44
178     {3, 8, 3, 0, 32, 32, 3}, // 45
179     {3, 8, 3, 8, 32, 33, 3}, // 46
180     {3, 8, 3, 0, 40, 40, 3}, // 47
181     {3, 8, 3, 8, 40, 41, 3}, // 48
182     {2, 16, 4, 16, 32, 9, 3}, // 49
183     {3, 8, 3, 16, 32, 34, 3}, // 50
184     {3, 8, 3, 24, 32, 35, 3}, // 51
185     {3, 8, 3, 16, 40, 42, 3}, // 52
186     {3, 8, 3, 24, 40, 43, 3}, // 53
187     {2, 16, 4, 0, 48, 12, 3}, // 54
188     {3, 8, 3, 0, 48, 48, 3}, // 55
189     {3, 8, 3, 8, 48, 49, 3}, // 56
190     {3, 8, 3, 0, 56, 56, 3}, // 57
191     {3, 8, 3, 8, 56, 57, 3}, // 58
192     {2, 16, 4, 16, 48, 13, 3}, // 59
193     {3, 8, 3, 16, 48, 50, 3}, // 60
194     {3, 8, 3, 24, 48, 51, 3}, // 61
195     {3, 8, 3, 16, 56, 58, 3}, // 62
196     {3, 8, 3, 24, 56, 59, 3}, // 63
197     {1, 32, 5, 32, 32, 3, 4}, // 64
198     {2, 16, 4, 32, 32, 10, 4}, // 65
199     {3, 8, 3, 32, 32, 36, 4}, // 66
200     {3, 8, 3, 40, 32, 37, 4}, // 67
201     {3, 8, 3, 32, 40, 44, 4}, // 68
202     {3, 8, 3, 40, 40, 45, 4}, // 69
203     {2, 16, 4, 48, 32, 11, 4}, // 70
204     {3, 8, 3, 48, 32, 38, 4}, // 71
205     {3, 8, 3, 56, 32, 39, 4}, // 72
206     {3, 8, 3, 48, 40, 46, 4}, // 73
207     {3, 8, 3, 56, 40, 47, 4}, // 74
208     {2, 16, 4, 32, 48, 14, 4}, // 75
209     {3, 8, 3, 32, 48, 52, 4}, // 76
210     {3, 8, 3, 40, 48, 53, 4}, // 77
211     {3, 8, 3, 32, 56, 60, 4}, // 78
212     {3, 8, 3, 40, 56, 61, 4}, // 79
213     {2, 16, 4, 48, 48, 15, 4}, // 80
214     {3, 8, 3, 48, 48, 54, 4}, // 81
215     {3, 8, 3, 56, 48, 55, 4}, // 82
216     {3, 8, 3, 48, 56, 62, 4}, // 83
217     {3, 8, 3, 56, 56, 63, 4} // 84
218 };
219 
220 /**************************************************************
221  * Get Coded Unit Statistics
222  **************************************************************/
get_coded_blk_stats(const uint32_t cu_idx)223 const CodedBlockStats* get_coded_blk_stats(const uint32_t cu_idx) {
224     return &coded_unit_stats_array[cu_idx];
225 }
226 
227 /*****************************************
228   * Long Log 2
229   *  This is a quick adaptation of a Number
230   *  Leading Zeros (NLZ) algorithm to get
231   *  the log2f of a 64-bit number
232   *****************************************/
log2f_32(uint32_t x)233 uint32_t log2f_32(uint32_t x) {
234     //return (x > 1) ? 1 + log2(x >> 1) : 0;
235     uint32_t log = (uint32_t)log2(x);
236     return log;
237 }
238 // concatenate two linked list, and return the pointer to the new concatenated list
concat_eb_linked_list(EbLinkedListNode * a,EbLinkedListNode * b)239 EbLinkedListNode* concat_eb_linked_list(EbLinkedListNode* a, EbLinkedListNode* b) {
240     if (a) {
241         while (a->next) a = a->next;
242         a->next = b;
243         return a;
244     } else
245         return b;
246 }
247 
248 // split a linked list
split_eb_linked_list(EbLinkedListNode * input,EbLinkedListNode ** restLL,EbBool (* predicate_func)(EbLinkedListNode *))249 EbLinkedListNode* split_eb_linked_list(EbLinkedListNode* input, EbLinkedListNode** restLL,
250                                        EbBool (*predicate_func)(EbLinkedListNode*)) {
251     EbLinkedListNode* ll_true_ptr = (EbLinkedListNode*)
252         NULL; // list of nodes satifying predicate_func(node) == TRUE
253     EbLinkedListNode* ll_rest_ptr = (EbLinkedListNode*)
254         NULL; // list of nodes satifying predicate_func(node) != TRUE
255 
256     while (input) {
257         EbLinkedListNode* next = input->next;
258         input->next            = (EbLinkedListNode*)NULL;
259         if (predicate_func(input))
260             ll_true_ptr = concat_eb_linked_list(input, ll_true_ptr);
261         else
262             ll_rest_ptr = concat_eb_linked_list(input, ll_rest_ptr);
263         input = next;
264     }
265 
266     *restLL = ll_rest_ptr;
267     return ll_true_ptr;
268 }
269 
270 static const MiniGopStats mini_gop_stats_array[] = {
271     //    hierarchical_levels    start_index    end_index    Lenght    mini_gop_index
272     {5, 0, 31, 32}, // 0
273     {4, 0, 15, 16}, // 1
274     {3, 0, 7, 8}, // 2
275     {2, 0, 3, 4}, // 3
276     {2, 4, 7, 4}, // 4
277     {3, 8, 15, 8}, // 5
278     {2, 8, 11, 4}, // 6
279     {2, 12, 15, 4}, // 7
280     {4, 16, 31, 16}, // 8
281     {3, 16, 23, 8}, // 9
282     {2, 16, 19, 4}, // 10
283     {2, 20, 23, 4}, // 11
284     {3, 24, 31, 8}, // 12
285     {2, 24, 27, 4}, // 13
286     {2, 28, 31, 4} // 14
287 };
288 
289 /**************************************************************
290 * Get Mini GOP Statistics
291 **************************************************************/
get_mini_gop_stats(const uint32_t mini_gop_index)292 const MiniGopStats* get_mini_gop_stats(const uint32_t mini_gop_index) {
293     return &mini_gop_stats_array[mini_gop_index];
294 }
295 
296 uint32_t ns_quarter_off_mult[9 /*Up to 9 part*/][2 /*x+y*/][4 /*Up to 4 ns blocks per part*/] = {
297     //9 means not used.
298 
299     //          |   x   |     |   y   |
300 
301     /*P=0*/ {{0, 9, 9, 9}, {0, 9, 9, 9}},
302     /*P=1*/ {{0, 0, 9, 9}, {0, 2, 9, 9}},
303     /*P=2*/ {{0, 2, 9, 9}, {0, 0, 9, 9}},
304     /*P=3*/ {{0, 2, 0, 9}, {0, 0, 2, 9}},
305     /*P=4*/ {{0, 0, 2, 9}, {0, 2, 2, 9}},
306     /*P=5*/ {{0, 0, 2, 9}, {0, 2, 0, 9}},
307     /*P=6*/ {{0, 2, 2, 9}, {0, 0, 2, 9}},
308     /*P=7*/ {{0, 0, 0, 0}, {0, 1, 2, 3}},
309     /*P=8*/ {{0, 1, 2, 3}, {0, 0, 0, 0}}};
310 
311 uint32_t ns_quarter_size_mult[9 /*Up to 9 part*/][2 /*h+v*/][4 /*Up to 4 ns blocks per part*/] = {
312     //9 means not used.
313 
314     //          |   h   |     |   v   |
315 
316     /*P=0*/ {{4, 9, 9, 9}, {4, 9, 9, 9}},
317     /*P=1*/ {{4, 4, 9, 9}, {2, 2, 9, 9}},
318     /*P=2*/ {{2, 2, 9, 9}, {4, 4, 9, 9}},
319     /*P=3*/ {{2, 2, 4, 9}, {2, 2, 2, 9}},
320     /*P=4*/ {{4, 2, 2, 9}, {2, 2, 2, 9}},
321     /*P=5*/ {{2, 2, 2, 9}, {2, 2, 4, 9}},
322     /*P=6*/ {{2, 2, 2, 9}, {4, 2, 2, 9}},
323     /*P=7*/ {{4, 4, 4, 4}, {1, 1, 1, 1}},
324     /*P=8*/ {{1, 1, 1, 1}, {4, 4, 4, 4}}};
325 
326 BlockSize hvsize_to_bsize[/*H*/ 6][/*V*/ 6] = {
327     {BLOCK_4X4, BLOCK_4X8, BLOCK_4X16, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID},
328     {BLOCK_8X4, BLOCK_8X8, BLOCK_8X16, BLOCK_8X32, BLOCK_INVALID, BLOCK_INVALID},
329     {BLOCK_16X4, BLOCK_16X8, BLOCK_16X16, BLOCK_16X32, BLOCK_16X64, BLOCK_INVALID},
330     {BLOCK_INVALID, BLOCK_32X8, BLOCK_32X16, BLOCK_32X32, BLOCK_32X64, BLOCK_INVALID},
331     {BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X16, BLOCK_64X32, BLOCK_64X64, BLOCK_64X128},
332     {BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X64, BLOCK_128X128}};
333 
334 uint32_t max_sb    = 64;
335 uint32_t max_depth = 5;
336 uint32_t max_part  = 9;
337 uint32_t max_num_active_blocks;
338 
339 //data could be  organized in 2 forms: depth scan (dps) or MD scan (mds):
340 //dps: all depth0 - all depth1 - all depth2 - all depth3.
341 //     within a depth: square blk0 in raster scan (followed by all its ns blcoks),
342 //     square blk1 in raster scan (followed by all its ns blcoks), etc
343 //mds: top-down and Z scan.
344 BlockGeom blk_geom_dps
345     [MAX_NUM_BLOCKS_ALLOC]; //to access geom info of a particular block : use this table if you have the block index in depth scan
346 BlockGeom blk_geom_mds
347     [MAX_NUM_BLOCKS_ALLOC]; //to access geom info of a particular block : use this table if you have the block index in md    scan
348 
search_matching_from_dps(uint32_t depth,uint32_t part,uint32_t x,uint32_t y)349 uint32_t search_matching_from_dps(uint32_t depth, uint32_t part, uint32_t x, uint32_t y) {
350     uint32_t found = 0;
351     uint32_t it;
352     uint32_t matched = 0xFFFF;
353     for (it = 0; it < max_num_active_blocks; it++) {
354         if (blk_geom_dps[it].depth == depth && blk_geom_dps[it].shape == part &&
355             blk_geom_dps[it].origin_x == x && blk_geom_dps[it].origin_y == y) {
356             if (found == 0) {
357                 matched = it;
358                 found   = 1;
359             } else {
360                 matched = 0xFFFF;
361                 break;
362             }
363         }
364     }
365 
366     if (matched == 0xFFFF)
367         SVT_LOG(" \n\n PROBLEM\n\n ");
368 
369     return matched;
370 }
search_matching_from_mds(uint32_t depth,uint32_t part,uint32_t x,uint32_t y)371 uint32_t search_matching_from_mds(uint32_t depth, uint32_t part, uint32_t x, uint32_t y) {
372     uint32_t found = 0;
373     uint32_t it;
374     uint32_t matched = 0xFFFF;
375     for (it = 0; it < max_num_active_blocks; it++) {
376         if (blk_geom_mds[it].depth == depth && blk_geom_mds[it].shape == part &&
377             blk_geom_mds[it].origin_x == x && blk_geom_mds[it].origin_y == y) {
378             if (found == 0) {
379                 matched = it;
380                 found   = 1;
381             } else {
382                 matched = 0xFFFF;
383                 break;
384             }
385         }
386     }
387 
388     if (matched == 0xFFFF)
389         SVT_LOG(" \n\n PROBLEM\n\n ");
390 
391     return matched;
392 }
393 
av1_get_tx_size(BlockSize sb_type,int32_t plane)394 static INLINE TxSize av1_get_tx_size(BlockSize sb_type, int32_t plane /*, const MacroBlockD *xd*/) {
395     UNUSED(plane);
396     //const MbModeInfo *mbmi = xd->mi[0];
397     // if (xd->lossless[mbmi->segment_id]) return TX_4X4;
398     if (plane == 0)
399         return blocksize_to_txsize[sb_type];
400     // const MacroblockdPlane *pd = &xd->plane[plane];
401 
402     uint32_t subsampling_x = plane > 0 ? 1 : 0;
403     uint32_t subsampling_y = plane > 0 ? 1 : 0;
404     return av1_get_max_uv_txsize(/*mbmi->*/ sb_type, subsampling_x, subsampling_y);
405 }
406 
md_scan_all_blks(uint32_t * idx_mds,uint32_t sq_size,uint32_t x,uint32_t y,int32_t is_last_quadrant,uint8_t quad_it)407 void md_scan_all_blks(uint32_t* idx_mds, uint32_t sq_size, uint32_t x, uint32_t y,
408                       int32_t is_last_quadrant, uint8_t quad_it) {
409     //the input block is the parent square block of size sq_size located at pos (x,y)
410 
411     uint32_t part_it, nsq_it, d1_it, sqi_mds;
412 
413     uint32_t halfsize  = sq_size / 2;
414     uint32_t quartsize = sq_size / 4;
415 
416     uint32_t max_part_updated = sq_size == 128 ? MIN(max_part, 7)
417         : sq_size == 8                         ? MIN(max_part, 3)
418         :
419 
420         sq_size == 4 ? 1
421                      : max_part;
422 
423     d1_it   = 0;
424     sqi_mds = *idx_mds;
425 
426     for (part_it = 0; part_it < max_part_updated; part_it++) {
427         uint32_t tot_num_ns_per_part = part_it < 1 ? 1 : part_it < 3 ? 2 : part_it < 7 ? 3 : 4;
428 
429         for (nsq_it = 0; nsq_it < tot_num_ns_per_part; nsq_it++) {
430             blk_geom_mds[*idx_mds].depth = sq_size == max_sb / 1 ? 0
431                 : sq_size == max_sb / 2                          ? 1
432                 : sq_size == max_sb / 4                          ? 2
433                 : sq_size == max_sb / 8                          ? 3
434                 : sq_size == max_sb / 16                         ? 4
435                                                                  : 5;
436 
437             blk_geom_mds[*idx_mds].sq_size          = sq_size;
438             blk_geom_mds[*idx_mds].is_last_quadrant = is_last_quadrant;
439             blk_geom_mds[*idx_mds].quadi            = quad_it;
440 
441             blk_geom_mds[*idx_mds].shape    = (Part)part_it;
442             blk_geom_mds[*idx_mds].origin_x = x +
443                 quartsize * ns_quarter_off_mult[part_it][0][nsq_it];
444             blk_geom_mds[*idx_mds].origin_y = y +
445                 quartsize * ns_quarter_off_mult[part_it][1][nsq_it];
446 
447             blk_geom_mds[*idx_mds].d1i     = d1_it++;
448             blk_geom_mds[*idx_mds].sqi_mds = sqi_mds;
449             blk_geom_mds[*idx_mds].totns   = tot_num_ns_per_part;
450             blk_geom_mds[*idx_mds].nsi     = nsq_it;
451 
452             uint32_t matched = search_matching_from_dps(blk_geom_mds[*idx_mds].depth,
453                                                         blk_geom_mds[*idx_mds].shape,
454                                                         blk_geom_mds[*idx_mds].origin_x,
455                                                         blk_geom_mds[*idx_mds].origin_y);
456 
457             blk_geom_mds[*idx_mds].blkidx_dps = blk_geom_dps[matched].blkidx_dps;
458 
459             blk_geom_mds[*idx_mds].bwidth  = quartsize * ns_quarter_size_mult[part_it][0][nsq_it];
460             blk_geom_mds[*idx_mds].bheight = quartsize * ns_quarter_size_mult[part_it][1][nsq_it];
461             blk_geom_mds[*idx_mds].bwidth_log2  = svt_log2f(blk_geom_mds[*idx_mds].bwidth);
462             blk_geom_mds[*idx_mds].bheight_log2 = svt_log2f(blk_geom_mds[*idx_mds].bheight);
463             blk_geom_mds[*idx_mds].bsize = hvsize_to_bsize[blk_geom_mds[*idx_mds].bwidth_log2 - 2]
464                                                           [blk_geom_mds[*idx_mds].bheight_log2 - 2];
465             blk_geom_mds[*idx_mds].bwidth_uv  = MAX(4, blk_geom_mds[*idx_mds].bwidth >> 1);
466             blk_geom_mds[*idx_mds].bheight_uv = MAX(4, blk_geom_mds[*idx_mds].bheight >> 1);
467             blk_geom_mds[*idx_mds].has_uv     = 1;
468 
469             if (blk_geom_mds[*idx_mds].bwidth == 4 && blk_geom_mds[*idx_mds].bheight == 4)
470                 blk_geom_mds[*idx_mds].has_uv = is_last_quadrant ? 1 : 0;
471 
472             else if ((blk_geom_mds[*idx_mds].bwidth >> 1) < blk_geom_mds[*idx_mds].bwidth_uv ||
473                      (blk_geom_mds[*idx_mds].bheight >> 1) < blk_geom_mds[*idx_mds].bheight_uv) {
474                 int32_t num_blk_same_uv = 1;
475                 if (blk_geom_mds[*idx_mds].bwidth >> 1 < 4)
476                     num_blk_same_uv *= 2;
477                 if (blk_geom_mds[*idx_mds].bheight >> 1 < 4)
478                     num_blk_same_uv *= 2;
479                 //if (blk_geom_mds[*idx_mds].nsi % 2 == 0)
480                 //if (blk_geom_mds[*idx_mds].nsi != (blk_geom_mds[*idx_mds].totns-1) )
481                 if (blk_geom_mds[*idx_mds].nsi != (num_blk_same_uv - 1) &&
482                     blk_geom_mds[*idx_mds].nsi != (2 * num_blk_same_uv - 1))
483                     blk_geom_mds[*idx_mds].has_uv = 0;
484             }
485 
486             blk_geom_mds[*idx_mds].bsize_uv = get_plane_block_size(
487                 blk_geom_mds[*idx_mds].bsize, 1, 1);
488             uint16_t txb_itr = 0;
489             // tx_depth 1 geom settings
490             uint8_t tx_depth                           = 0;
491             blk_geom_mds[*idx_mds].txb_count[tx_depth] = blk_geom_mds[*idx_mds].bsize ==
492                     BLOCK_128X128
493                 ? 4
494                 : blk_geom_mds[*idx_mds].bsize == BLOCK_128X64 ||
495                     blk_geom_mds[*idx_mds].bsize == BLOCK_64X128
496                 ? 2
497                 : 1;
498             for (txb_itr = 0; txb_itr < blk_geom_mds[*idx_mds].txb_count[tx_depth]; txb_itr++) {
499                 blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(
500                     blk_geom_mds[*idx_mds].bsize, 0);
501                 blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] = av1_get_tx_size(
502                     blk_geom_mds[*idx_mds].bsize, 1);
503                 if (blk_geom_mds[*idx_mds].bsize == BLOCK_128X128) {
504                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
505                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] = (txb_itr == 0 ||
506                                                                                  txb_itr == 2)
507                         ? blk_geom_mds[*idx_mds].origin_x
508                         : blk_geom_mds[*idx_mds].origin_x + 64;
509                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
510                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] = (txb_itr == 0 ||
511                                                                                  txb_itr == 1)
512                         ? blk_geom_mds[*idx_mds].origin_y
513                         : blk_geom_mds[*idx_mds].origin_y + 64;
514                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_128X64) {
515                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
516                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] = (txb_itr == 0)
517                         ? blk_geom_mds[*idx_mds].origin_x
518                         : blk_geom_mds[*idx_mds].origin_x + 64;
519                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
520                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
521                             blk_geom_mds[*idx_mds].origin_y;
522                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X128) {
523                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
524                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
525                             blk_geom_mds[*idx_mds].origin_x;
526                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
527                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] = (txb_itr == 0)
528                         ? blk_geom_mds[*idx_mds].origin_y
529                         : blk_geom_mds[*idx_mds].origin_y + 64;
530                 } else {
531                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
532                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
533                             blk_geom_mds[*idx_mds].origin_x;
534                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
535                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
536                             blk_geom_mds[*idx_mds].origin_y;
537                 }
538                 /*if (blk_geom_mds[*idx_mds].bsize == BLOCK_16X8)
539                     SVT_LOG("");*/
540                 blk_geom_mds[*idx_mds].tx_width[tx_depth][txb_itr] =
541                     tx_size_wide[blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr]];
542                 blk_geom_mds[*idx_mds].tx_height[tx_depth][txb_itr] =
543                     tx_size_high[blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr]];
544                 blk_geom_mds[*idx_mds].tx_width_uv[tx_depth][txb_itr] =
545                     tx_size_wide[blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr]];
546                 blk_geom_mds[*idx_mds].tx_height_uv[tx_depth][txb_itr] =
547                     tx_size_high[blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr]];
548             }
549             // tx_depth 1 geom settings
550             tx_depth                                   = 1;
551             blk_geom_mds[*idx_mds].txb_count[tx_depth] = blk_geom_mds[*idx_mds].bsize ==
552                     BLOCK_128X128
553                 ? 4
554                 : blk_geom_mds[*idx_mds].bsize == BLOCK_128X64 ||
555                     blk_geom_mds[*idx_mds].bsize == BLOCK_64X128
556                 ? 2
557                 : 1;
558 
559             if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X64 ||
560                 blk_geom_mds[*idx_mds].bsize == BLOCK_32X32 ||
561                 blk_geom_mds[*idx_mds].bsize == BLOCK_16X16 ||
562                 blk_geom_mds[*idx_mds].bsize == BLOCK_8X8) {
563                 blk_geom_mds[*idx_mds].txb_count[tx_depth] = 4;
564             }
565 
566             if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X32 ||
567                 blk_geom_mds[*idx_mds].bsize == BLOCK_32X64 ||
568                 blk_geom_mds[*idx_mds].bsize == BLOCK_32X16 ||
569                 blk_geom_mds[*idx_mds].bsize == BLOCK_16X32 ||
570                 blk_geom_mds[*idx_mds].bsize == BLOCK_16X8 ||
571                 blk_geom_mds[*idx_mds].bsize == BLOCK_8X16) {
572                 blk_geom_mds[*idx_mds].txb_count[tx_depth] = 2;
573             }
574             if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X16 ||
575                 blk_geom_mds[*idx_mds].bsize == BLOCK_16X64 ||
576                 blk_geom_mds[*idx_mds].bsize == BLOCK_32X8 ||
577                 blk_geom_mds[*idx_mds].bsize == BLOCK_8X32 ||
578                 blk_geom_mds[*idx_mds].bsize == BLOCK_16X4 ||
579                 blk_geom_mds[*idx_mds].bsize == BLOCK_4X16) {
580                 blk_geom_mds[*idx_mds].txb_count[tx_depth] = 2;
581             }
582             for (txb_itr = 0; txb_itr < blk_geom_mds[*idx_mds].txb_count[tx_depth]; txb_itr++) {
583                 if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X64) {
584                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_32X32,
585                                                                                        0);
586                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
587                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
588                     uint8_t offsetx[4] = {0, 32, 0, 32};
589                     uint8_t offsety[4] = {0, 0, 32, 32};
590                     //   0  1
591                     //   2  3
592                     uint8_t tbx = offsetx[txb_itr];
593                     uint8_t tby = offsety[txb_itr];
594 
595                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
596                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
597                             blk_geom_mds[*idx_mds].origin_x + tbx;
598                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
599                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
600                             blk_geom_mds[*idx_mds].origin_y + tby;
601                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X32) {
602                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_32X32,
603                                                                                        0);
604                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
605                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
606                     uint8_t offsetx[2] = {0, 32};
607                     uint8_t offsety[2] = {0, 0};
608                     //   0  1
609                     uint8_t tbx = offsetx[txb_itr];
610                     uint8_t tby = offsety[txb_itr];
611 
612                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
613                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
614                             blk_geom_mds[*idx_mds].origin_x + tbx;
615                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
616                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
617                             blk_geom_mds[*idx_mds].origin_y + tby;
618                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_32X64) {
619                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_32X32,
620                                                                                        0);
621                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
622                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
623                     uint8_t offsetx[2] = {0, 0};
624                     uint8_t offsety[2] = {0, 32};
625                     //   0  1
626                     uint8_t tbx = offsetx[txb_itr];
627                     uint8_t tby = offsety[txb_itr];
628 
629                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
630                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
631                             blk_geom_mds[*idx_mds].origin_x + tbx;
632                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
633                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
634                             blk_geom_mds[*idx_mds].origin_y + tby;
635                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_32X32) {
636                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_16X16,
637                                                                                        0);
638                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
639                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
640                     uint8_t offsetx[4] = {0, 16, 0, 16};
641                     uint8_t offsety[4] = {0, 0, 16, 16};
642                     //   0  1
643                     //   2  3
644                     uint8_t tbx = offsetx[txb_itr];
645                     uint8_t tby = offsety[txb_itr];
646 
647                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
648                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
649                             blk_geom_mds[*idx_mds].origin_x + tbx;
650                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
651                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
652                             blk_geom_mds[*idx_mds].origin_y + tby;
653                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_32X16) {
654                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_16X16,
655                                                                                        0);
656                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
657                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
658                     uint8_t offsetx[2] = {0, 16};
659                     uint8_t offsety[2] = {0, 0};
660                     //   0  1
661                     uint8_t tbx = offsetx[txb_itr];
662                     uint8_t tby = offsety[txb_itr];
663 
664                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
665                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
666                             blk_geom_mds[*idx_mds].origin_x + tbx;
667                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
668                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
669                             blk_geom_mds[*idx_mds].origin_y + tby;
670                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_16X32) {
671                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_16X16,
672                                                                                        0);
673                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
674                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
675                     uint8_t offsetx[2] = {0, 0};
676                     uint8_t offsety[2] = {0, 16};
677                     //   0  1
678                     uint8_t tbx = offsetx[txb_itr];
679                     uint8_t tby = offsety[txb_itr];
680 
681                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
682                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
683                             blk_geom_mds[*idx_mds].origin_x + tbx;
684                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
685                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
686                             blk_geom_mds[*idx_mds].origin_y + tby;
687                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_16X16) {
688                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_8X8,
689                                                                                        0);
690                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
691                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
692                     uint8_t offsetx[4] = {0, 8, 0, 8};
693                     uint8_t offsety[4] = {0, 0, 8, 8};
694                     //   0  1
695                     //   2  3
696                     uint8_t tbx = offsetx[txb_itr];
697                     uint8_t tby = offsety[txb_itr];
698 
699                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
700                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
701                             blk_geom_mds[*idx_mds].origin_x + tbx;
702                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
703                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
704                             blk_geom_mds[*idx_mds].origin_y + tby;
705                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_16X8) {
706                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_8X8,
707                                                                                        0);
708                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
709                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
710                     uint8_t offsetx[2] = {0, 8};
711                     uint8_t offsety[2] = {0, 0};
712                     //   0  1
713                     uint8_t tbx = offsetx[txb_itr];
714                     uint8_t tby = offsety[txb_itr];
715 
716                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
717                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
718                             blk_geom_mds[*idx_mds].origin_x + tbx;
719                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
720                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
721                             blk_geom_mds[*idx_mds].origin_y + tby;
722                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_8X16) {
723                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_8X8,
724                                                                                        0);
725                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
726                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
727                     uint8_t offsetx[2] = {0, 0};
728                     uint8_t offsety[2] = {0, 8};
729                     //   0  1
730                     uint8_t tbx = offsetx[txb_itr];
731                     uint8_t tby = offsety[txb_itr];
732 
733                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
734                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
735                             blk_geom_mds[*idx_mds].origin_x + tbx;
736                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
737                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
738                             blk_geom_mds[*idx_mds].origin_y + tby;
739                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_8X8) {
740                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_4X4,
741                                                                                        0);
742                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
743                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
744                     uint8_t offsetx[4] = {0, 4, 0, 4};
745                     uint8_t offsety[4] = {0, 0, 4, 4};
746                     //   0  1
747                     //   2  3
748                     uint8_t tbx = offsetx[txb_itr];
749                     uint8_t tby = offsety[txb_itr];
750 
751                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
752                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
753                             blk_geom_mds[*idx_mds].origin_x + tbx;
754                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
755                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
756                             blk_geom_mds[*idx_mds].origin_y + tby;
757                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X16) {
758                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_32X16,
759                                                                                        0);
760                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
761                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
762 
763                     uint8_t offsetx[2] = {0, 32};
764                     uint8_t offsety[2] = {0, 0};
765                     uint8_t tbx        = offsetx[txb_itr];
766                     uint8_t tby        = offsety[txb_itr];
767 
768                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
769                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
770                             blk_geom_mds[*idx_mds].origin_x + tbx;
771                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
772                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
773                             blk_geom_mds[*idx_mds].origin_y + tby;
774                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_16X64) {
775                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_16X32,
776                                                                                        0);
777                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
778                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
779 
780                     uint8_t offsetx[2] = {0, 0};
781                     uint8_t offsety[2] = {0, 32};
782                     uint8_t tbx        = offsetx[txb_itr];
783                     uint8_t tby        = offsety[txb_itr];
784 
785                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
786                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
787                             blk_geom_mds[*idx_mds].origin_x + tbx;
788                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
789                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
790                             blk_geom_mds[*idx_mds].origin_y + tby;
791                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_32X8) {
792                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_16X8,
793                                                                                        0);
794                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
795                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
796 
797                     uint8_t offsetx[2] = {0, 16};
798                     uint8_t offsety[2] = {0, 0};
799                     uint8_t tbx        = offsetx[txb_itr];
800                     uint8_t tby        = offsety[txb_itr];
801 
802                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
803                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
804                             blk_geom_mds[*idx_mds].origin_x + tbx;
805                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
806                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
807                             blk_geom_mds[*idx_mds].origin_y + tby;
808                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_8X32) {
809                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_8X16,
810                                                                                        0);
811                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
812                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
813                     //   0  1 2 3
814                     uint8_t offsetx[2] = {0, 0};
815                     uint8_t offsety[2] = {0, 16};
816                     uint8_t tbx        = offsetx[txb_itr];
817                     uint8_t tby        = offsety[txb_itr];
818 
819                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
820                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
821                             blk_geom_mds[*idx_mds].origin_x + tbx;
822                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
823                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
824                             blk_geom_mds[*idx_mds].origin_y + tby;
825                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_16X4) {
826                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_8X4,
827                                                                                        0);
828                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
829                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
830 
831                     uint8_t offsetx[2] = {0, 8};
832                     uint8_t offsety[2] = {0, 0};
833 
834                     uint8_t tbx = offsetx[txb_itr];
835                     uint8_t tby = offsety[txb_itr];
836 
837                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
838                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
839                             blk_geom_mds[*idx_mds].origin_x + tbx;
840                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
841                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
842                             blk_geom_mds[*idx_mds].origin_y + tby;
843                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_4X16) {
844                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_4X8,
845                                                                                        0);
846                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
847                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
848 
849                     uint8_t offsetx[2] = {0, 0};
850                     uint8_t offsety[2] = {0, 8};
851                     uint8_t tbx        = offsetx[txb_itr];
852                     uint8_t tby        = offsety[txb_itr];
853 
854                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
855                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
856                             blk_geom_mds[*idx_mds].origin_x + tbx;
857                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
858                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
859                             blk_geom_mds[*idx_mds].origin_y + tby;
860                 } else {
861                     if (blk_geom_mds[*idx_mds].bsize == BLOCK_128X128) {
862                         blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(
863                             blk_geom_mds[*idx_mds].bsize, 0);
864                         blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
865                             blk_geom_mds[*idx_mds].txsize_uv[0][0];
866 
867                         blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
868                             blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] = (txb_itr == 0 ||
869                                                                                      txb_itr == 2)
870                             ? blk_geom_mds[*idx_mds].origin_x
871                             : blk_geom_mds[*idx_mds].origin_x + 64;
872                         blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
873                             blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] = (txb_itr == 0 ||
874                                                                                      txb_itr == 1)
875                             ? blk_geom_mds[*idx_mds].origin_y
876                             : blk_geom_mds[*idx_mds].origin_y + 64;
877                     } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_128X64) {
878                         blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(
879                             blk_geom_mds[*idx_mds].bsize, 0);
880                         blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
881                             blk_geom_mds[*idx_mds].txsize_uv[0][0];
882 
883                         blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
884                             blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] = (txb_itr == 0)
885                             ? blk_geom_mds[*idx_mds].origin_x
886                             : blk_geom_mds[*idx_mds].origin_x + 64;
887                         blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
888                             blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
889                                 blk_geom_mds[*idx_mds].origin_y;
890                     } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X128) {
891                         blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(
892                             blk_geom_mds[*idx_mds].bsize, 0);
893                         blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
894                             blk_geom_mds[*idx_mds].txsize_uv[0][0];
895                         blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
896                             blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
897                                 blk_geom_mds[*idx_mds].origin_x;
898                         blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
899                             blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] = (txb_itr == 0)
900                             ? blk_geom_mds[*idx_mds].origin_y
901                             : blk_geom_mds[*idx_mds].origin_y + 64;
902                     } else {
903                         blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(
904                             blk_geom_mds[*idx_mds].bsize, 0);
905                         blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
906                             blk_geom_mds[*idx_mds].txsize_uv[0][0];
907                         blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
908                             blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
909                                 blk_geom_mds[*idx_mds].origin_x;
910                         blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
911                             blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
912                                 blk_geom_mds[*idx_mds].origin_y;
913                     }
914                 }
915                 blk_geom_mds[*idx_mds].tx_width[tx_depth][txb_itr] =
916                     tx_size_wide[blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr]];
917                 blk_geom_mds[*idx_mds].tx_height[tx_depth][txb_itr] =
918                     tx_size_high[blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr]];
919                 blk_geom_mds[*idx_mds].tx_width_uv[tx_depth][txb_itr] =
920                     blk_geom_mds[*idx_mds].tx_width_uv[0][0];
921                 blk_geom_mds[*idx_mds].tx_height_uv[tx_depth][txb_itr] =
922                     blk_geom_mds[*idx_mds].tx_height_uv[0][0];
923             }
924             // tx_depth 2 geom settings
925             tx_depth = 2;
926 
927             blk_geom_mds[*idx_mds].txb_count[tx_depth] = blk_geom_mds[*idx_mds].bsize ==
928                     BLOCK_128X128
929                 ? 4
930                 : blk_geom_mds[*idx_mds].bsize == BLOCK_128X64 ||
931                     blk_geom_mds[*idx_mds].bsize == BLOCK_64X128
932                 ? 2
933                 : 1;
934 
935             if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X64 ||
936                 blk_geom_mds[*idx_mds].bsize == BLOCK_32X32 ||
937                 blk_geom_mds[*idx_mds].bsize == BLOCK_16X16) {
938                 blk_geom_mds[*idx_mds].txb_count[tx_depth] = 16;
939             }
940             if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X32 ||
941                 blk_geom_mds[*idx_mds].bsize == BLOCK_32X64 ||
942                 blk_geom_mds[*idx_mds].bsize == BLOCK_32X16 ||
943                 blk_geom_mds[*idx_mds].bsize == BLOCK_16X32 ||
944                 blk_geom_mds[*idx_mds].bsize == BLOCK_16X8 ||
945                 blk_geom_mds[*idx_mds].bsize == BLOCK_8X16) {
946                 blk_geom_mds[*idx_mds].txb_count[tx_depth] = 8;
947             }
948             if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X16 ||
949                 blk_geom_mds[*idx_mds].bsize == BLOCK_16X64 ||
950                 blk_geom_mds[*idx_mds].bsize == BLOCK_32X8 ||
951                 blk_geom_mds[*idx_mds].bsize == BLOCK_8X32 ||
952                 blk_geom_mds[*idx_mds].bsize == BLOCK_16X4 ||
953                 blk_geom_mds[*idx_mds].bsize == BLOCK_4X16) {
954                 blk_geom_mds[*idx_mds].txb_count[tx_depth] = 4;
955             }
956 
957             for (txb_itr = 0; txb_itr < blk_geom_mds[*idx_mds].txb_count[tx_depth]; txb_itr++) {
958                 if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X64) {
959                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_16X16,
960                                                                                        0);
961                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
962                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
963 
964                     uint8_t offsetx_intra[16] = {
965                         0, 16, 32, 48, 0, 16, 32, 48, 0, 16, 32, 48, 0, 16, 32, 48};
966                     uint8_t offsety_intra[16] = {
967                         0, 0, 0, 0, 16, 16, 16, 16, 32, 32, 32, 32, 48, 48, 48, 48};
968 
969                     uint8_t offsetx_inter[16] = {
970                         0, 16, 0, 16, 32, 48, 32, 48, 0, 16, 0, 16, 32, 48, 32, 48};
971                     uint8_t offsety_inter[16] = {
972                         0, 0, 16, 16, 0, 0, 16, 16, 32, 32, 48, 48, 32, 32, 48, 48};
973 
974                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
975                         blk_geom_mds[*idx_mds].origin_x + offsetx_intra[txb_itr];
976                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
977                         blk_geom_mds[*idx_mds].origin_y + offsety_intra[txb_itr];
978 
979                     blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
980                         blk_geom_mds[*idx_mds].origin_x + offsetx_inter[txb_itr];
981                     blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
982                         blk_geom_mds[*idx_mds].origin_y + offsety_inter[txb_itr];
983 
984                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X32) {
985                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_16X16,
986                                                                                        0);
987                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
988                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
989 
990                     uint8_t offsetx_intra[8] = {0, 16, 32, 48, 0, 16, 32, 48};
991                     uint8_t offsety_intra[8] = {0, 0, 0, 0, 16, 16, 16, 16};
992 
993                     uint8_t offsetx_inter[8] = {0, 16, 0, 16, 32, 48, 32, 48};
994                     uint8_t offsety_inter[8] = {0, 0, 16, 16, 0, 0, 16, 16};
995 
996                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
997                         blk_geom_mds[*idx_mds].origin_x + offsetx_intra[txb_itr];
998                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
999                         blk_geom_mds[*idx_mds].origin_y + offsety_intra[txb_itr];
1000 
1001                     blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1002                         blk_geom_mds[*idx_mds].origin_x + offsetx_inter[txb_itr];
1003                     blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1004                         blk_geom_mds[*idx_mds].origin_y + offsety_inter[txb_itr];
1005                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_32X64) {
1006                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_16X16,
1007                                                                                        0);
1008                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1009                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1010 
1011                     uint8_t offsetx_intra[8] = {0, 16, 0, 16, 0, 16, 0, 16};
1012                     uint8_t offsety_intra[8] = {0, 0, 16, 16, 32, 32, 48, 48};
1013 
1014                     uint8_t offsetx_inter[8] = {0, 16, 0, 16, 0, 16, 0, 16};
1015                     uint8_t offsety_inter[8] = {0, 0, 16, 16, 32, 32, 48, 48};
1016 
1017                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1018                         blk_geom_mds[*idx_mds].origin_x + offsetx_intra[txb_itr];
1019                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1020                         blk_geom_mds[*idx_mds].origin_y + offsety_intra[txb_itr];
1021 
1022                     blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1023                         blk_geom_mds[*idx_mds].origin_x + offsetx_inter[txb_itr];
1024                     blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1025                         blk_geom_mds[*idx_mds].origin_y + offsety_inter[txb_itr];
1026 
1027                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_32X32) {
1028                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_8X8,
1029                                                                                        0);
1030                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1031                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1032 
1033                     uint8_t offsetx_intra[16] = {
1034                         0, 8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24};
1035                     uint8_t offsety_intra[16] = {
1036                         0, 0, 0, 0, 8, 8, 8, 8, 16, 16, 16, 16, 24, 24, 24, 24};
1037 
1038                     uint8_t offsetx_inter[16] = {
1039                         0, 8, 0, 8, 16, 24, 16, 24, 0, 8, 0, 8, 16, 24, 16, 24};
1040                     uint8_t offsety_inter[16] = {
1041                         0, 0, 8, 8, 0, 0, 8, 8, 16, 16, 24, 24, 16, 16, 24, 24};
1042 
1043                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1044                         blk_geom_mds[*idx_mds].origin_x + offsetx_intra[txb_itr];
1045                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1046                         blk_geom_mds[*idx_mds].origin_y + offsety_intra[txb_itr];
1047 
1048                     blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1049                         blk_geom_mds[*idx_mds].origin_x + offsetx_inter[txb_itr];
1050                     blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1051                         blk_geom_mds[*idx_mds].origin_y + offsety_inter[txb_itr];
1052                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_32X16) {
1053                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_8X8,
1054                                                                                        0);
1055                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1056                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1057 
1058                     uint8_t offsetx_intra[8] = {0, 8, 16, 24, 0, 8, 16, 24};
1059                     uint8_t offsety_intra[8] = {0, 0, 0, 0, 8, 8, 8, 8};
1060 
1061                     uint8_t offsetx_inter[8] = {0, 8, 0, 8, 16, 24, 16, 24};
1062                     uint8_t offsety_inter[8] = {0, 0, 8, 8, 0, 0, 8, 8};
1063 
1064                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1065                         blk_geom_mds[*idx_mds].origin_x + offsetx_intra[txb_itr];
1066                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1067                         blk_geom_mds[*idx_mds].origin_y + offsety_intra[txb_itr];
1068 
1069                     blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1070                         blk_geom_mds[*idx_mds].origin_x + offsetx_inter[txb_itr];
1071                     blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1072                         blk_geom_mds[*idx_mds].origin_y + offsety_inter[txb_itr];
1073                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_16X32) {
1074                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_8X8,
1075                                                                                        0);
1076                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1077                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1078 
1079                     uint8_t offsetx_intra[8] = {0, 8, 0, 8, 0, 8, 0, 8};
1080                     uint8_t offsety_intra[8] = {0, 0, 8, 8, 16, 16, 24, 24};
1081 
1082                     uint8_t offsetx_inter[8] = {0, 8, 0, 8, 0, 8, 0, 8};
1083                     uint8_t offsety_inter[8] = {0, 0, 8, 8, 16, 16, 24, 24};
1084 
1085                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1086                         blk_geom_mds[*idx_mds].origin_x + offsetx_intra[txb_itr];
1087                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1088                         blk_geom_mds[*idx_mds].origin_y + offsety_intra[txb_itr];
1089 
1090                     blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1091                         blk_geom_mds[*idx_mds].origin_x + offsetx_inter[txb_itr];
1092                     blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1093                         blk_geom_mds[*idx_mds].origin_y + offsety_inter[txb_itr];
1094                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_16X8) {
1095                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_4X4,
1096                                                                                        0);
1097                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1098                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1099 
1100                     uint8_t offsetx_intra[8] = {0, 4, 8, 12, 0, 4, 8, 12};
1101                     uint8_t offsety_intra[8] = {0, 0, 0, 0, 4, 4, 4, 4};
1102 
1103                     uint8_t offsetx_inter[8] = {0, 4, 0, 4, 8, 12, 8, 12};
1104                     uint8_t offsety_inter[8] = {0, 0, 4, 4, 0, 0, 4, 4};
1105 
1106                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1107                         blk_geom_mds[*idx_mds].origin_x + offsetx_intra[txb_itr];
1108                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1109                         blk_geom_mds[*idx_mds].origin_y + offsety_intra[txb_itr];
1110 
1111                     blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1112                         blk_geom_mds[*idx_mds].origin_x + offsetx_inter[txb_itr];
1113                     blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1114                         blk_geom_mds[*idx_mds].origin_y + offsety_inter[txb_itr];
1115                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_8X16) {
1116                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_4X4,
1117                                                                                        0);
1118                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1119                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1120 
1121                     uint8_t offsetx_intra[8] = {0, 4, 0, 4, 0, 4, 0, 4};
1122                     uint8_t offsety_intra[8] = {0, 0, 4, 4, 8, 8, 12, 12};
1123 
1124                     uint8_t offsetx_inter[8] = {0, 4, 0, 4, 0, 4, 0, 4};
1125                     uint8_t offsety_inter[8] = {0, 0, 4, 4, 8, 8, 12, 12};
1126 
1127                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1128                         blk_geom_mds[*idx_mds].origin_x + offsetx_intra[txb_itr];
1129                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1130                         blk_geom_mds[*idx_mds].origin_y + offsety_intra[txb_itr];
1131 
1132                     blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1133                         blk_geom_mds[*idx_mds].origin_x + offsetx_inter[txb_itr];
1134                     blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1135                         blk_geom_mds[*idx_mds].origin_y + offsety_inter[txb_itr];
1136 
1137                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_16X16) {
1138                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_4X4,
1139                                                                                        0);
1140                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1141                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1142 
1143                     uint8_t offsetx_intra[16] = {
1144                         0, 4, 8, 12, 0, 4, 8, 12, 0, 4, 8, 12, 0, 4, 8, 12};
1145                     uint8_t offsety_intra[16] = {
1146                         0, 0, 0, 0, 4, 4, 4, 4, 8, 8, 8, 8, 12, 12, 12, 12};
1147 
1148                     uint8_t offsetx_inter[16] = {
1149                         0, 4, 0, 4, 8, 12, 8, 12, 0, 4, 0, 4, 8, 12, 8, 12};
1150                     uint8_t offsety_inter[16] = {
1151                         0, 0, 4, 4, 0, 0, 4, 4, 8, 8, 12, 12, 8, 8, 12, 12};
1152 
1153                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1154                         blk_geom_mds[*idx_mds].origin_x + offsetx_intra[txb_itr];
1155                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1156                         blk_geom_mds[*idx_mds].origin_y + offsety_intra[txb_itr];
1157 
1158                     blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1159                         blk_geom_mds[*idx_mds].origin_x + offsetx_inter[txb_itr];
1160                     blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1161                         blk_geom_mds[*idx_mds].origin_y + offsety_inter[txb_itr];
1162                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X16) {
1163                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_16X16,
1164                                                                                        0);
1165                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1166                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1167                     //   0  1 2 3
1168                     uint8_t offsetx[4] = {0, 16, 32, 48};
1169                     uint8_t offsety[4] = {0, 0, 0, 0};
1170                     uint8_t tbx        = offsetx[txb_itr];
1171                     uint8_t tby        = offsety[txb_itr];
1172 
1173                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1174                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1175                             blk_geom_mds[*idx_mds].origin_x + tbx;
1176                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1177                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1178                             blk_geom_mds[*idx_mds].origin_y + tby;
1179                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_16X64) {
1180                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_16X16,
1181                                                                                        0);
1182                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1183                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1184                     //   0  1 2 3
1185                     uint8_t offsetx[4] = {0, 0, 0, 0};
1186                     uint8_t offsety[4] = {0, 16, 32, 48};
1187                     uint8_t tbx        = offsetx[txb_itr];
1188                     uint8_t tby        = offsety[txb_itr];
1189 
1190                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1191                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1192                             blk_geom_mds[*idx_mds].origin_x + tbx;
1193                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1194                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1195                             blk_geom_mds[*idx_mds].origin_y + tby;
1196                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_32X8) {
1197                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_8X8,
1198                                                                                        0);
1199                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1200                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1201                     //   0  1 2 3
1202                     uint8_t offsetx[4] = {0, 8, 16, 24};
1203                     uint8_t offsety[4] = {0, 0, 0, 0};
1204                     uint8_t tbx        = offsetx[txb_itr];
1205                     uint8_t tby        = offsety[txb_itr];
1206 
1207                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1208                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1209                             blk_geom_mds[*idx_mds].origin_x + tbx;
1210                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1211                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1212                             blk_geom_mds[*idx_mds].origin_y + tby;
1213                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_8X32) {
1214                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_8X8,
1215                                                                                        0);
1216                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1217                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1218                     //   0  1 2 3
1219                     uint8_t offsetx[4] = {0, 0, 0, 0};
1220                     uint8_t offsety[4] = {0, 8, 16, 24};
1221                     uint8_t tbx        = offsetx[txb_itr];
1222                     uint8_t tby        = offsety[txb_itr];
1223 
1224                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1225                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1226                             blk_geom_mds[*idx_mds].origin_x + tbx;
1227                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1228                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1229                             blk_geom_mds[*idx_mds].origin_y + tby;
1230                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_16X4) {
1231                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_4X4,
1232                                                                                        0);
1233                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1234                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1235                     //   0  1 2 3
1236                     uint8_t offsetx[4] = {0, 4, 8, 12};
1237                     uint8_t offsety[4] = {0, 0, 0, 0};
1238                     uint8_t tbx        = offsetx[txb_itr];
1239                     uint8_t tby        = offsety[txb_itr];
1240 
1241                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1242                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1243                             blk_geom_mds[*idx_mds].origin_x + tbx;
1244                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1245                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1246                             blk_geom_mds[*idx_mds].origin_y + tby;
1247                 } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_4X16) {
1248                     blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(BLOCK_4X4,
1249                                                                                        0);
1250                     blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1251                         blk_geom_mds[*idx_mds].txsize_uv[0][0];
1252                     //   0  1 2 3
1253                     uint8_t offsetx[4] = {0, 0, 0, 0};
1254                     uint8_t offsety[4] = {0, 4, 8, 12};
1255                     uint8_t tbx        = offsetx[txb_itr];
1256                     uint8_t tby        = offsety[txb_itr];
1257 
1258                     blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1259                         blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1260                             blk_geom_mds[*idx_mds].origin_x + tbx;
1261                     blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1262                         blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1263                             blk_geom_mds[*idx_mds].origin_y + tby;
1264                 } else {
1265                     if (blk_geom_mds[*idx_mds].bsize == BLOCK_128X128) {
1266                         blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(
1267                             blk_geom_mds[*idx_mds].bsize, 0);
1268                         blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1269                             blk_geom_mds[*idx_mds].txsize_uv[0][0];
1270                         blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1271                             blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] = (txb_itr == 0 ||
1272                                                                                      txb_itr == 2)
1273                             ? blk_geom_mds[*idx_mds].origin_x
1274                             : blk_geom_mds[*idx_mds].origin_x + 64;
1275                         blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1276                             blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] = (txb_itr == 0 ||
1277                                                                                      txb_itr == 1)
1278                             ? blk_geom_mds[*idx_mds].origin_y
1279                             : blk_geom_mds[*idx_mds].origin_y + 64;
1280                     } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_128X64) {
1281                         blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(
1282                             blk_geom_mds[*idx_mds].bsize, 0);
1283                         blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1284                             blk_geom_mds[*idx_mds].txsize_uv[0][0];
1285                         blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1286                             blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] = (txb_itr == 0)
1287                             ? blk_geom_mds[*idx_mds].origin_x
1288                             : blk_geom_mds[*idx_mds].origin_x + 64;
1289                         blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1290                             blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1291                                 blk_geom_mds[*idx_mds].origin_y;
1292                     } else if (blk_geom_mds[*idx_mds].bsize == BLOCK_64X128) {
1293                         blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(
1294                             blk_geom_mds[*idx_mds].bsize, 0);
1295                         blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1296                             blk_geom_mds[*idx_mds].txsize_uv[0][0];
1297                         blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1298                             blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1299                                 blk_geom_mds[*idx_mds].origin_x;
1300                         blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1301                             blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] = (txb_itr == 0)
1302                             ? blk_geom_mds[*idx_mds].origin_y
1303                             : blk_geom_mds[*idx_mds].origin_y + 64;
1304                     } else {
1305                         blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr] = av1_get_tx_size(
1306                             blk_geom_mds[*idx_mds].bsize, 0);
1307                         blk_geom_mds[*idx_mds].txsize_uv[tx_depth][txb_itr] =
1308                             blk_geom_mds[*idx_mds].txsize_uv[0][0];
1309                         blk_geom_mds[*idx_mds].tx_org_x[0][tx_depth][txb_itr] =
1310                             blk_geom_mds[*idx_mds].tx_org_x[1][tx_depth][txb_itr] =
1311                                 blk_geom_mds[*idx_mds].origin_x;
1312                         blk_geom_mds[*idx_mds].tx_org_y[0][tx_depth][txb_itr] =
1313                             blk_geom_mds[*idx_mds].tx_org_y[1][tx_depth][txb_itr] =
1314                                 blk_geom_mds[*idx_mds].origin_y;
1315                     }
1316                 }
1317                 blk_geom_mds[*idx_mds].tx_width[tx_depth][txb_itr] =
1318                     tx_size_wide[blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr]];
1319                 blk_geom_mds[*idx_mds].tx_height[tx_depth][txb_itr] =
1320                     tx_size_high[blk_geom_mds[*idx_mds].txsize[tx_depth][txb_itr]];
1321                 blk_geom_mds[*idx_mds].tx_width_uv[tx_depth][txb_itr] =
1322                     blk_geom_mds[*idx_mds].tx_width_uv[0][0];
1323                 blk_geom_mds[*idx_mds].tx_height_uv[tx_depth][txb_itr] =
1324                     blk_geom_mds[*idx_mds].tx_height_uv[0][0];
1325             }
1326             blk_geom_mds[*idx_mds].blkidx_mds = (*idx_mds);
1327             (*idx_mds)                        = (*idx_mds) + 1;
1328         }
1329     }
1330 
1331     uint32_t min_size = max_sb >> (max_depth - 1);
1332     if (halfsize >= min_size) {
1333         md_scan_all_blks(idx_mds, halfsize, x, y, 0, 0);
1334         md_scan_all_blks(idx_mds, halfsize, x + halfsize, y, 0, 1);
1335         md_scan_all_blks(idx_mds, halfsize, x, y + halfsize, 0, 2);
1336         md_scan_all_blks(idx_mds, halfsize, x + halfsize, y + halfsize, 1, 3);
1337     }
1338 }
1339 
depth_scan_all_blks()1340 void depth_scan_all_blks() {
1341     uint32_t depth_it, sq_it_y, sq_it_x, part_it, nsq_it;
1342     uint32_t sq_orgx, sq_orgy;
1343     uint32_t depth_scan_idx = 0;
1344 
1345     for (depth_it = 0; depth_it < max_depth; depth_it++) {
1346         uint32_t tot_num_sq = 1 << depth_it;
1347         uint32_t sq_size    = depth_it == 0 ? max_sb
1348                : depth_it == 1              ? max_sb / 2
1349                : depth_it == 2              ? max_sb / 4
1350                : depth_it == 3              ? max_sb / 8
1351                : depth_it == 4              ? max_sb / 16
1352                                             : max_sb / 32;
1353 
1354         uint32_t max_part_updated = sq_size == 128 ? MIN(max_part, 7)
1355             : sq_size == 8                         ? MIN(max_part, 3)
1356             : sq_size == 4                         ? 1
1357                                                    : max_part;
1358 
1359         for (sq_it_y = 0; sq_it_y < tot_num_sq; sq_it_y++) {
1360             sq_orgy = sq_it_y * sq_size;
1361 
1362             for (sq_it_x = 0; sq_it_x < tot_num_sq; sq_it_x++) {
1363                 sq_orgx = sq_it_x * sq_size;
1364 
1365                 for (part_it = 0; part_it < max_part_updated; part_it++) {
1366                     uint32_t tot_num_ns_per_part = part_it < 1 ? 1
1367                         : part_it < 3                          ? 2
1368                         : part_it < 7                          ? 3
1369                                                                : 4;
1370 
1371                     for (nsq_it = 0; nsq_it < tot_num_ns_per_part; nsq_it++) {
1372                         blk_geom_dps[depth_scan_idx].blkidx_dps = depth_scan_idx;
1373                         blk_geom_dps[depth_scan_idx].depth      = depth_it;
1374                         blk_geom_dps[depth_scan_idx].shape      = (Part)part_it;
1375                         blk_geom_dps[depth_scan_idx].origin_x   = sq_orgx +
1376                             (sq_size / 4) * ns_quarter_off_mult[part_it][0][nsq_it];
1377                         blk_geom_dps[depth_scan_idx].origin_y = sq_orgy +
1378                             (sq_size / 4) * ns_quarter_off_mult[part_it][1][nsq_it];
1379 
1380                         depth_scan_idx++;
1381                     }
1382                 }
1383             }
1384         }
1385     }
1386 }
1387 
finish_depth_scan_all_blks()1388 void finish_depth_scan_all_blks() {
1389     uint32_t depth_scan_idx = 0;
1390 
1391     for (uint32_t depth_it = 0; depth_it < max_depth; depth_it++) {
1392         uint32_t tot_num_sq = 1 << depth_it;
1393         uint32_t sq_size    = depth_it == 0 ? max_sb
1394                : depth_it == 1              ? max_sb / 2
1395                : depth_it == 2              ? max_sb / 4
1396                : depth_it == 3              ? max_sb / 8
1397                : depth_it == 4              ? max_sb / 16
1398                                             : max_sb / 32;
1399 
1400         uint32_t max_part_updated = sq_size == 128 ? MIN(max_part, 7)
1401             : sq_size == 8                         ? MIN(max_part, 3)
1402             : sq_size == 4                         ? 1
1403                                                    : max_part;
1404 
1405         for (uint32_t sq_it_y = 0; sq_it_y < tot_num_sq; sq_it_y++) {
1406             for (uint32_t sq_it_x = 0; sq_it_x < tot_num_sq; sq_it_x++) {
1407                 for (uint32_t part_it = 0; part_it < max_part_updated; part_it++) {
1408                     uint32_t tot_num_ns_per_part = part_it < 1 ? 1
1409                         : part_it < 3                          ? 2
1410                         : part_it < 7                          ? 3
1411                                                                : 4;
1412 
1413                     for (uint32_t nsq_it = 0; nsq_it < tot_num_ns_per_part; nsq_it++) {
1414                         uint32_t matched = search_matching_from_mds(
1415                             blk_geom_dps[depth_scan_idx].depth,
1416                             blk_geom_dps[depth_scan_idx].shape,
1417                             blk_geom_dps[depth_scan_idx].origin_x,
1418                             blk_geom_dps[depth_scan_idx].origin_y);
1419 
1420                         blk_geom_dps[depth_scan_idx].blkidx_mds = blk_geom_mds[matched].blkidx_mds;
1421                         depth_scan_idx++;
1422                     }
1423                 }
1424             }
1425         }
1426     }
1427 }
1428 
count_total_num_of_active_blks()1429 uint32_t count_total_num_of_active_blks() {
1430     uint32_t depth_it, sq_it_y, sq_it_x, part_it, nsq_it;
1431 
1432     uint32_t depth_scan_idx = 0;
1433 
1434     for (depth_it = 0; depth_it < max_depth; depth_it++) {
1435         uint32_t tot_num_sq = 1 << depth_it;
1436         uint32_t sq_size    = depth_it == 0 ? max_sb
1437                : depth_it == 1              ? max_sb / 2
1438                : depth_it == 2              ? max_sb / 4
1439                : depth_it == 3              ? max_sb / 8
1440                : depth_it == 4              ? max_sb / 16
1441                                             : max_sb / 32;
1442 
1443         uint32_t max_part_updated = sq_size == 128 ? MIN(max_part, 7)
1444             : sq_size == 8                         ? MIN(max_part, 3)
1445             : sq_size == 4                         ? 1
1446                                                    : max_part;
1447 
1448         for (sq_it_y = 0; sq_it_y < tot_num_sq; sq_it_y++) {
1449             for (sq_it_x = 0; sq_it_x < tot_num_sq; sq_it_x++) {
1450                 for (part_it = 0; part_it < max_part_updated; part_it++) {
1451                     uint32_t tot_num_ns_per_part = part_it < 1 ? 1
1452                         : part_it < 3                          ? 2
1453                         : part_it < 7                          ? 3
1454                                                                : 4;
1455 
1456                     for (nsq_it = 0; nsq_it < tot_num_ns_per_part; nsq_it++) depth_scan_idx++;
1457                 }
1458             }
1459         }
1460     }
1461 
1462     return depth_scan_idx;
1463 }
log_redundancy_similarity(uint32_t max_block_count)1464 void log_redundancy_similarity(uint32_t max_block_count) {
1465     uint32_t blk_it, s_it;
1466 
1467     for (blk_it = 0; blk_it < max_block_count; blk_it++) {
1468         BlockGeom* cur_geom              = &blk_geom_mds[blk_it];
1469         cur_geom->similar                = 0;
1470         cur_geom->redund                 = 0;
1471         cur_geom->redund_list.list_size  = 0;
1472         cur_geom->similar_list.list_size = 0;
1473 
1474         for (s_it = 0; s_it < max_block_count; s_it++) {
1475             BlockGeom* search_geom = &blk_geom_mds[s_it];
1476 
1477             if (cur_geom->bsize == search_geom->bsize &&
1478                 cur_geom->origin_x == search_geom->origin_x &&
1479                 cur_geom->origin_y == search_geom->origin_y && s_it != blk_it) {
1480                 //one block could have similar and redundant blocks
1481                 cur_geom->similar = 1;
1482                 cur_geom->similar_list.blk_mds_table[cur_geom->similar_list.list_size] =
1483                     search_geom->blkidx_mds;
1484                 cur_geom->similar_list.list_size++;
1485                 if (cur_geom->nsi == 0 && search_geom->nsi == 0) {
1486                     cur_geom->redund = 1;
1487                     cur_geom->redund_list.blk_mds_table[cur_geom->redund_list.list_size] =
1488                         search_geom->blkidx_mds;
1489                     cur_geom->redund_list.list_size++;
1490                 }
1491             }
1492         }
1493     }
1494 }
build_blk_geom(int32_t use_128x128)1495 void build_blk_geom(int32_t use_128x128) {
1496     max_sb                   = use_128x128 ? 128 : 64;
1497     max_depth                = use_128x128 ? 6 : 5;
1498     uint32_t max_block_count = use_128x128 ? BLOCK_MAX_COUNT_SB_128 : BLOCK_MAX_COUNT_SB_64;
1499 
1500     //(0)compute total number of blocks using the information provided
1501     max_num_active_blocks = count_total_num_of_active_blks();
1502     if (max_num_active_blocks != max_block_count)
1503         SVT_LOG(" \n\n Error %i blocks\n\n ", max_num_active_blocks);
1504 
1505     //(1) Construct depth scan blk_geom_dps
1506     depth_scan_all_blks();
1507 
1508     //(2) Construct md scan blk_geom_mds:  use info from dps
1509     uint32_t idx_mds = 0;
1510     md_scan_all_blks(&idx_mds, max_sb, 0, 0, 0, 0);
1511 
1512     //(3) Fill more info from mds to dps - print using dps
1513     finish_depth_scan_all_blks();
1514 
1515     log_redundancy_similarity(max_block_count);
1516 }
1517 
1518 //need to finish filling dps by inherting data from mds
get_blk_geom_mds(uint32_t bidx_mds)1519 const BlockGeom* get_blk_geom_mds(uint32_t bidx_mds) { return &blk_geom_mds[bidx_mds]; }
1520 
get_mds_idx(uint32_t orgx,uint32_t orgy,uint32_t size,uint32_t use_128x128)1521 uint32_t get_mds_idx(uint32_t orgx, uint32_t orgy, uint32_t size, uint32_t use_128x128) {
1522     uint32_t max_block_count = use_128x128 ? BLOCK_MAX_COUNT_SB_128 : BLOCK_MAX_COUNT_SB_64;
1523     uint32_t mds             = 0;
1524 
1525     for (uint32_t blk_it = 0; blk_it < max_block_count; blk_it++) {
1526         BlockGeom* cur_geom = &blk_geom_mds[blk_it];
1527 
1528         if ((uint32_t)cur_geom->sq_size == size && cur_geom->origin_x == orgx &&
1529             cur_geom->origin_y == orgy && cur_geom->shape == PART_N) {
1530             mds = cur_geom->blkidx_mds;
1531             break;
1532         }
1533     }
1534     return mds;
1535 }
1536