ax_buffer_tool.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**********************************************************************************
  2. *
  3. * Copyright (c) 2019-2020 Beijing AXera Technology Co., Ltd. All Rights Reserved.
  4. *
  5. * This source file is the property of Beijing AXera Technology Co., Ltd. and
  6. * may not be copied or distributed in any isomorphic form without the prior
  7. * written consent of Beijing AXera Technology Co., Ltd.
  8. *
  9. **********************************************************************************/
  10. #ifndef _AX_BUFFER_TOOL_H_
  11. #define _AX_BUFFER_TOOL_H_
  12. #include "ax_base_type.h"
  13. #include "ax_comm_codec.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif /* End of #ifdef __cplusplus */
  17. #define AX_COMM_ALIGN(value, n) (((value) + (n) - 1) & ~((n) - 1))
  18. static __inline AX_U32 AX_VIN_GetImgBufferSize(AX_U32 uHeight, AX_U32 uWidth, AX_IMG_FORMAT_E eImageFormat, AX_BOOL bCompressEn)
  19. {
  20. AX_S32 width_beat = 0;
  21. AX_S32 _buf_size = 0;
  22. AX_S32 prevmask_size = 0;
  23. #if 0
  24. if(((uHeight % 16) != 0) && ((eImageFormat == AX_FORMAT_BAYER_RAW_8BPP) ||
  25. (eImageFormat == AX_FORMAT_BAYER_RAW_10BPP) || (eImageFormat == AX_FORMAT_BAYER_RAW_12BPP) ||
  26. (eImageFormat == AX_FORMAT_BAYER_RAW_14BPP) || (eImageFormat == AX_FORMAT_BAYER_RAW_16BPP)))
  27. {
  28. uHeight = ((uHeight / 16) + 1) * 16;
  29. }
  30. #endif
  31. /*prevmask*/
  32. if(bCompressEn) {
  33. prevmask_size = (uHeight * uWidth / 64) + (uHeight / 8 * 32); //NPU;
  34. } else {
  35. prevmask_size = (uHeight * uWidth / 64);
  36. }
  37. switch (eImageFormat) {
  38. case AX_FORMAT_BAYER_RAW_8BPP:
  39. if (((uWidth) % (128 / 8)) != 0) {
  40. width_beat = ((uWidth) / (128 / 8)) + 1;
  41. } else {
  42. width_beat = ((uWidth) / (128 / 8));
  43. }
  44. _buf_size = width_beat * 16 * uHeight; // per beat 16bytes
  45. break;
  46. case AX_FORMAT_BAYER_RAW_10BPP:
  47. if (((uWidth) % (128 / 10)) != 0) {
  48. width_beat = ((uWidth) / (128 / 10)) + 1;
  49. } else {
  50. width_beat = ((uWidth) / (128 / 10));
  51. }
  52. _buf_size = width_beat * 16 * uHeight; // per beat 16bytes
  53. break;
  54. case AX_FORMAT_BAYER_RAW_12BPP:
  55. if (((uWidth) % (128 / 12)) != 0) {
  56. width_beat = ((uWidth) / (128 / 12)) + 1;
  57. } else {
  58. width_beat = ((uWidth) / (128 / 12));
  59. }
  60. _buf_size = width_beat * 16 * uHeight; // per beat 16bytes
  61. break;
  62. case AX_FORMAT_BAYER_RAW_14BPP:
  63. if (((uWidth) % (128 / 14)) != 0) {
  64. width_beat = ((uWidth) / (128 / 14)) + 1;
  65. } else {
  66. width_beat = ((uWidth) / (128 / 14));
  67. }
  68. _buf_size = width_beat * 16 * uHeight; // per beat 16bytes
  69. break;
  70. case AX_FORMAT_BAYER_RAW_16BPP:
  71. if (((uWidth) % (128 / 16)) != 0) {
  72. width_beat = ((uWidth) / (128 / 16)) + 1;
  73. } else {
  74. width_beat = ((uWidth) / (128 / 16));
  75. }
  76. _buf_size = width_beat * 16 * uHeight + prevmask_size; // per beat 16bytes
  77. break;
  78. case AX_YUV420_SEMIPLANAR_VU:
  79. case AX_YUV420_SEMIPLANAR:
  80. _buf_size = uWidth * uHeight * 3 / 2;
  81. break;
  82. case AX_YUV422_INTERLEAVED_YUYV:
  83. case AX_YUV422_INTERLEAVED_UYVY:
  84. _buf_size = uWidth * uHeight * 2;
  85. break;
  86. default:
  87. _buf_size = uWidth * uHeight * 2;
  88. break;
  89. }
  90. if(bCompressEn) {
  91. switch (eImageFormat) {
  92. case AX_FORMAT_BAYER_RAW_8BPP:
  93. case AX_FORMAT_BAYER_RAW_10BPP:
  94. case AX_FORMAT_BAYER_RAW_12BPP:
  95. case AX_FORMAT_BAYER_RAW_14BPP:
  96. case AX_FORMAT_BAYER_RAW_16BPP:
  97. _buf_size += uHeight * 32; /* add the header buf for compress data */
  98. break;
  99. case AX_YUV420_SEMIPLANAR_VU:
  100. case AX_YUV420_SEMIPLANAR:
  101. _buf_size += uHeight * 96; /* add the header buf for compress data */
  102. break;
  103. case AX_YUV422_INTERLEAVED_YUYV:
  104. case AX_YUV422_INTERLEAVED_UYVY:
  105. _buf_size += 0;
  106. break;
  107. default:
  108. _buf_size += 0;
  109. break;
  110. }
  111. }
  112. return _buf_size;
  113. }
  114. static __inline AX_U32 AX_VDEC_GetPicBufferSize(AX_U32 uHeight, AX_U32 uWidth, AX_PAYLOAD_TYPE_E enType)
  115. {
  116. AX_U32 picSizeInMbs = 0;
  117. AX_U32 picSize = 0;
  118. AX_U32 dmvMemSize = 0;
  119. AX_U32 refBuffSize = 0;
  120. picSizeInMbs = (AX_COMM_ALIGN(uHeight, 16) >> 4) * (AX_COMM_ALIGN(uWidth, 16) >> 4);
  121. if (PT_H264 == enType) {
  122. picSize = (AX_COMM_ALIGN(uHeight, 16) * AX_COMM_ALIGN(uWidth, 16) * 3) >> 1;
  123. /* buffer size of dpb pic = picSize + dir_mv_size + tbl_size */
  124. dmvMemSize = picSizeInMbs * 64;
  125. refBuffSize = picSize + dmvMemSize + 32;
  126. }
  127. else if ((PT_JPEG == enType) || (PT_MJPEG == enType)) {
  128. picSize = (AX_COMM_ALIGN(uHeight, 16) * AX_COMM_ALIGN(uWidth, 16) * 3) >> 1;
  129. refBuffSize = picSize;
  130. }
  131. else {
  132. refBuffSize = 0;
  133. }
  134. return refBuffSize;
  135. }
  136. #ifdef __cplusplus
  137. }
  138. #endif /* End of #ifdef __cplusplus */
  139. #endif //_AX_BUFFER_TOOL_H_