/H264Dec/source/h264bsd_neighbour.c

http://github.com/mbebenita/Broadway · C · 382 lines · 108 code · 67 blank · 207 comment · 30 complexity · 46c0e59d6085830b9c7c664a83140782 MD5 · raw file

  1. /*
  2. * Copyright (C) 2009 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*------------------------------------------------------------------------------
  17. Table of contents
  18. 1. Include headers
  19. 2. External compiler flags
  20. 3. Module defines
  21. 4. Local function prototypes
  22. 5. Functions
  23. h264bsdInitMbNeighbours
  24. h264bsdGetNeighbourMb
  25. h264bsdNeighbour4x4BlockA
  26. h264bsdNeighbour4x4BlockB
  27. h264bsdNeighbour4x4BlockC
  28. h264bsdNeighbour4x4BlockD
  29. ------------------------------------------------------------------------------*/
  30. /*------------------------------------------------------------------------------
  31. 1. Include headers
  32. ------------------------------------------------------------------------------*/
  33. #include "h264bsd_neighbour.h"
  34. #include "h264bsd_util.h"
  35. /*------------------------------------------------------------------------------
  36. 2. External compiler flags
  37. --------------------------------------------------------------------------------
  38. --------------------------------------------------------------------------------
  39. 3. Module defines
  40. ------------------------------------------------------------------------------*/
  41. /* Following four tables indicate neighbours of each block of a macroblock.
  42. * First 16 values are for luma blocks, next 4 values for Cb and last 4
  43. * values for Cr. Elements of the table indicate to which macroblock the
  44. * neighbour block belongs and the index of the neighbour block in question.
  45. * Indexing of the blocks goes as follows
  46. *
  47. * Y Cb Cr
  48. * 0 1 4 5 16 17 20 21
  49. * 2 3 6 7 18 19 22 23
  50. * 8 9 12 13
  51. * 10 11 14 15
  52. */
  53. /* left neighbour for each block */
  54. static const neighbour_t N_A_4x4B[24] = {
  55. {MB_A,5}, {MB_CURR,0}, {MB_A,7}, {MB_CURR,2},
  56. {MB_CURR,1}, {MB_CURR,4}, {MB_CURR,3}, {MB_CURR,6},
  57. {MB_A,13}, {MB_CURR,8}, {MB_A,15}, {MB_CURR,10},
  58. {MB_CURR,9}, {MB_CURR,12},{MB_CURR,11},{MB_CURR,14},
  59. {MB_A,17}, {MB_CURR,16},{MB_A,19}, {MB_CURR,18},
  60. {MB_A,21}, {MB_CURR,20},{MB_A,23}, {MB_CURR,22} };
  61. /* above neighbour for each block */
  62. static const neighbour_t N_B_4x4B[24] = {
  63. {MB_B,10}, {MB_B,11}, {MB_CURR,0}, {MB_CURR,1},
  64. {MB_B,14}, {MB_B,15}, {MB_CURR,4}, {MB_CURR,5},
  65. {MB_CURR,2}, {MB_CURR,3}, {MB_CURR,8}, {MB_CURR,9},
  66. {MB_CURR,6}, {MB_CURR,7}, {MB_CURR,12},{MB_CURR,13},
  67. {MB_B,18}, {MB_B,19}, {MB_CURR,16},{MB_CURR,17},
  68. {MB_B,22}, {MB_B,23}, {MB_CURR,20},{MB_CURR,21} };
  69. /* above-right neighbour for each block */
  70. static const neighbour_t N_C_4x4B[24] = {
  71. {MB_B,11}, {MB_B,14}, {MB_CURR,1}, {MB_NA,4},
  72. {MB_B,15}, {MB_C,10}, {MB_CURR,5}, {MB_NA,0},
  73. {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_NA,12},
  74. {MB_CURR,7}, {MB_NA,2}, {MB_CURR,13},{MB_NA,8},
  75. {MB_B,19}, {MB_C,18}, {MB_CURR,17},{MB_NA,16},
  76. {MB_B,23}, {MB_C,22}, {MB_CURR,21},{MB_NA,20} };
  77. /* above-left neighbour for each block */
  78. static const neighbour_t N_D_4x4B[24] = {
  79. {MB_D,15}, {MB_B,10}, {MB_A,5}, {MB_CURR,0},
  80. {MB_B,11}, {MB_B,14}, {MB_CURR,1}, {MB_CURR,4},
  81. {MB_A,7}, {MB_CURR,2}, {MB_A,13}, {MB_CURR,8},
  82. {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_CURR,12},
  83. {MB_D,19}, {MB_B,18}, {MB_A,17}, {MB_CURR,16},
  84. {MB_D,23}, {MB_B,22}, {MB_A,21}, {MB_CURR,20} };
  85. /*------------------------------------------------------------------------------
  86. 4. Local function prototypes
  87. ------------------------------------------------------------------------------*/
  88. /*------------------------------------------------------------------------------
  89. Function: h264bsdInitMbNeighbours
  90. Functional description:
  91. Initialize macroblock neighbours. Function sets neighbour
  92. macroblock pointers in macroblock structures to point to
  93. macroblocks on the left, above, above-right and above-left.
  94. Pointers are set NULL if the neighbour does not fit into the
  95. picture.
  96. Inputs:
  97. picWidth width of the picture in macroblocks
  98. picSizeInMbs no need to clarify
  99. Outputs:
  100. pMbStorage neighbour pointers of each mbStorage structure
  101. stored here
  102. Returns:
  103. none
  104. ------------------------------------------------------------------------------*/
  105. void h264bsdInitMbNeighbours(mbStorage_t *pMbStorage, u32 picWidth,
  106. u32 picSizeInMbs)
  107. {
  108. /* Variables */
  109. u32 i, row, col;
  110. /* Code */
  111. ASSERT(pMbStorage);
  112. ASSERT(picWidth);
  113. ASSERT(picWidth <= picSizeInMbs);
  114. ASSERT(((picSizeInMbs / picWidth) * picWidth) == picSizeInMbs);
  115. row = col = 0;
  116. for (i = 0; i < picSizeInMbs; i++)
  117. {
  118. if (col)
  119. pMbStorage[i].mbA = pMbStorage + i - 1;
  120. else
  121. pMbStorage[i].mbA = NULL;
  122. if (row)
  123. pMbStorage[i].mbB = pMbStorage + i - picWidth;
  124. else
  125. pMbStorage[i].mbB = NULL;
  126. if (row && (col < picWidth - 1))
  127. pMbStorage[i].mbC = pMbStorage + i - (picWidth - 1);
  128. else
  129. pMbStorage[i].mbC = NULL;
  130. if (row && col)
  131. pMbStorage[i].mbD = pMbStorage + i - (picWidth + 1);
  132. else
  133. pMbStorage[i].mbD = NULL;
  134. col++;
  135. if (col == picWidth)
  136. {
  137. col = 0;
  138. row++;
  139. }
  140. }
  141. }
  142. /*------------------------------------------------------------------------------
  143. Function: h264bsdGetNeighbourMb
  144. Functional description:
  145. Get pointer to neighbour macroblock.
  146. Inputs:
  147. pMb pointer to macroblock structure of the macroblock
  148. whose neighbour is wanted
  149. neighbour indicates which neighbour is wanted
  150. Outputs:
  151. none
  152. Returns:
  153. pointer to neighbour macroblock
  154. NULL if not available
  155. ------------------------------------------------------------------------------*/
  156. mbStorage_t* h264bsdGetNeighbourMb(mbStorage_t *pMb, neighbourMb_e neighbour)
  157. {
  158. /* Variables */
  159. /* Code */
  160. ASSERT((neighbour <= MB_CURR) || (neighbour == MB_NA));
  161. if (neighbour == MB_A)
  162. return(pMb->mbA);
  163. else if (neighbour == MB_B)
  164. return(pMb->mbB);
  165. else if (neighbour == MB_C)
  166. return(pMb->mbC);
  167. else if (neighbour == MB_D)
  168. return(pMb->mbD);
  169. else if (neighbour == MB_CURR)
  170. return(pMb);
  171. else
  172. return(NULL);
  173. }
  174. /*------------------------------------------------------------------------------
  175. Function: h264bsdNeighbour4x4BlockA
  176. Functional description:
  177. Get left neighbour of the block. Function returns pointer to
  178. the table defined in the beginning of the file.
  179. Inputs:
  180. blockIndex indicates the block whose neighbours are wanted
  181. Outputs:
  182. Returns:
  183. pointer to neighbour structure
  184. ------------------------------------------------------------------------------*/
  185. const neighbour_t* h264bsdNeighbour4x4BlockA(u32 blockIndex)
  186. {
  187. /* Variables */
  188. /* Code */
  189. ASSERT(blockIndex < 24);
  190. return(N_A_4x4B+blockIndex);
  191. }
  192. /*------------------------------------------------------------------------------
  193. Function: h264bsdNeighbour4x4BlockB
  194. Functional description:
  195. Get above neighbour of the block. Function returns pointer to
  196. the table defined in the beginning of the file.
  197. Inputs:
  198. blockIndex indicates the block whose neighbours are wanted
  199. Outputs:
  200. Returns:
  201. pointer to neighbour structure
  202. ------------------------------------------------------------------------------*/
  203. const neighbour_t* h264bsdNeighbour4x4BlockB(u32 blockIndex)
  204. {
  205. /* Variables */
  206. /* Code */
  207. ASSERT(blockIndex < 24);
  208. return(N_B_4x4B+blockIndex);
  209. }
  210. /*------------------------------------------------------------------------------
  211. Function: h264bsdNeighbour4x4BlockC
  212. Functional description:
  213. Get above-right neighbour of the block. Function returns pointer
  214. to the table defined in the beginning of the file.
  215. Inputs:
  216. blockIndex indicates the block whose neighbours are wanted
  217. Outputs:
  218. Returns:
  219. pointer to neighbour structure
  220. ------------------------------------------------------------------------------*/
  221. const neighbour_t* h264bsdNeighbour4x4BlockC(u32 blockIndex)
  222. {
  223. /* Variables */
  224. /* Code */
  225. ASSERT(blockIndex < 24);
  226. return(N_C_4x4B+blockIndex);
  227. }
  228. /*------------------------------------------------------------------------------
  229. Function: h264bsdNeighbour4x4BlockD
  230. Functional description:
  231. Get above-left neighbour of the block. Function returns pointer to
  232. the table defined in the beginning of the file.
  233. Inputs:
  234. blockIndex indicates the block whose neighbours are wanted
  235. Outputs:
  236. Returns:
  237. pointer to neighbour structure
  238. ------------------------------------------------------------------------------*/
  239. const neighbour_t* h264bsdNeighbour4x4BlockD(u32 blockIndex)
  240. {
  241. /* Variables */
  242. /* Code */
  243. ASSERT(blockIndex < 24);
  244. return(N_D_4x4B+blockIndex);
  245. }
  246. /*------------------------------------------------------------------------------
  247. Function: h264bsdIsNeighbourAvailable
  248. Functional description:
  249. Check if neighbour macroblock is available. Neighbour macroblock
  250. is considered available if it is within the picture and belongs
  251. to the same slice as the current macroblock.
  252. Inputs:
  253. pMb pointer to the current macroblock
  254. pNeighbour pointer to the neighbour macroblock
  255. Outputs:
  256. none
  257. Returns:
  258. TRUE neighbour is available
  259. FALSE neighbour is not available
  260. ------------------------------------------------------------------------------*/
  261. u32 h264bsdIsNeighbourAvailable(mbStorage_t *pMb, mbStorage_t *pNeighbour)
  262. {
  263. /* Variables */
  264. /* Code */
  265. if ( (pNeighbour == NULL) || (pMb->sliceId != pNeighbour->sliceId) )
  266. return(HANTRO_FALSE);
  267. else
  268. return(HANTRO_TRUE);
  269. }