jpuapifunc.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /* SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause */
  2. /*
  3. * Copyright (c) 2018, Chips&Media
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef JPUAPI_UTIL_H_INCLUDED
  27. #define JPUAPI_UTIL_H_INCLUDED
  28. #ifdef USE_FEEDING_METHOD_BUFFER
  29. #include "codaj12/jpuapi/jpuapi.h"
  30. #else
  31. #include "jpuapi.h"
  32. #endif
  33. #define DC_TABLE_INDEX0 0
  34. #define AC_TABLE_INDEX0 1
  35. #define DC_TABLE_INDEX1 2
  36. #define AC_TABLE_INDEX1 3
  37. #define DC_TABLE_INDEX2 4
  38. #define AC_TABLE_INDEX2 5
  39. #define DC_TABLE_INDEX3 6
  40. #define AC_TABLE_INDEX3 7
  41. #define Q_COMPONENT0 0
  42. #define Q_COMPONENT1 0x40
  43. #define Q_COMPONENT2 0x80
  44. #define THTC_LIST_CNT 8
  45. /* CODAJ12 Constraints
  46. * The minimum value of Qk is 8 for 16bit quantization element, 2 for 8bit quantization element
  47. */
  48. #define MIN_Q16_ELEMENT 8
  49. #define MIN_Q8_ELEMENT 2
  50. typedef enum {
  51. JPG_START_PIC = 0,
  52. JPG_START_INIT,
  53. JPG_START_PARTIAL,
  54. JPG_ENABLE_START_PIC = 4,
  55. JPG_DEC_SLICE_ENABLE_START_PIC = 5
  56. }JpgStartCmd;
  57. typedef enum {
  58. INST_CTRL_IDLE = 0,
  59. INST_CTRL_LOAD = 1,
  60. INST_CTRL_RUN = 2,
  61. INST_CTRL_PAUSE = 3,
  62. INST_CTRL_ENC = 4,
  63. INST_CTRL_PIC_DONE = 5,
  64. INST_CTRL_SLC_DONE = 6
  65. }InstCtrlStates;
  66. typedef struct{
  67. Uint32 tag;
  68. Uint32 type;
  69. int count;
  70. int offset;
  71. }TAG;
  72. enum {
  73. JFIF = 0,
  74. JFXX_JPG = 1,
  75. JFXX_PAL = 2,
  76. JFXX_RAW = 3,
  77. EXIF_JPG = 4
  78. };
  79. typedef struct {
  80. int PicX;
  81. int PicY;
  82. int BitPerSample[3];
  83. int Compression; // 1 for uncompressed / 6 for compressed(jpeg)
  84. int PixelComposition; // 2 for RGB / 6 for YCbCr
  85. int SamplePerPixel;
  86. int PlanrConfig; // 1 for chunky / 2 for planar
  87. int YCbCrSubSample; // 00020002 for YCbCr 4:2:0 / 00020001 for YCbCr 4:2:2
  88. Uint32 JpegOffset;
  89. Uint32 JpegThumbSize;
  90. } EXIF_INFO;
  91. typedef struct {
  92. BYTE *buffer;
  93. int index;
  94. int size;
  95. } vpu_getbit_context_t;
  96. #define init_get_bits(CTX, BUFFER, SIZE) JpuGbuInit(CTX, BUFFER, SIZE)
  97. #define show_bits(CTX, NUM) JpuGguShowBit(CTX, NUM)
  98. #define get_bits(CTX, NUM) JpuGbuGetBit(CTX, NUM)
  99. #define get_bits_left(CTX) JpuGbuGetLeftBitCount(CTX)
  100. #define get_bits_count(CTX) JpuGbuGetUsedBitCount(CTX)
  101. typedef struct {
  102. PhysicalAddress streamWrPtr;
  103. PhysicalAddress streamRdPtr;
  104. int streamEndflag;
  105. PhysicalAddress streamBufStartAddr;
  106. PhysicalAddress streamBufEndAddr;
  107. int streamBufSize;
  108. BYTE *pBitStream;
  109. int frameOffset;
  110. int consumeByte;
  111. int nextOffset;
  112. int currOffset;
  113. FrameBuffer * frameBufPool;
  114. int numFrameBuffers;
  115. int stride;
  116. int initialInfoObtained;
  117. int minFrameBufferNum;
  118. int streamEndian;
  119. int frameEndian;
  120. Uint32 chromaInterleave;
  121. Uint32 picWidth;
  122. Uint32 picHeight;
  123. Uint32 alignedWidth;
  124. Uint32 alignedHeight;
  125. int headerSize;
  126. int ecsPtr;
  127. int pagePtr;
  128. int wordPtr;
  129. int bitPtr;
  130. FrameFormat format;
  131. int rstIntval;
  132. int userHuffTab;
  133. int userqMatTab;
  134. int huffDcIdx;
  135. int huffAcIdx;
  136. int Qidx;
  137. BYTE huffVal[8][256];
  138. BYTE huffBits[8][256];
  139. short qMatTab[4][64];
  140. Uint32 huffMin[8][16];
  141. Uint32 huffMax[8][16];
  142. BYTE huffPtr[8][16];
  143. BYTE cInfoTab[4][6];
  144. int busReqNum;
  145. int compNum;
  146. int mcuBlockNum;
  147. int compInfo[3];
  148. int frameIdx;
  149. int bitEmpty;
  150. int iHorScaleMode;
  151. int iVerScaleMode;
  152. Uint32 mcuWidth;
  153. Uint32 mcuHeight;
  154. vpu_getbit_context_t gbc;
  155. //ROI
  156. Uint32 roiEnable;
  157. Uint32 roiOffsetX;
  158. Uint32 roiOffsetY;
  159. Uint32 roiWidth;
  160. Uint32 roiHeight;
  161. Uint32 roiMcuOffsetX;
  162. Uint32 roiMcuOffsetY;
  163. Uint32 roiMcuWidth;
  164. Uint32 roiMcuHeight;
  165. Uint32 roiFrameWidth;
  166. Uint32 roiFrameHeight;
  167. PackedFormat packedFormat;
  168. int jpg12bit;
  169. int q_prec0;
  170. int q_prec1;
  171. int q_prec2;
  172. int q_prec3;
  173. Uint32 pixelJustification;
  174. Uint32 ofmt;
  175. Uint32 stride_c;
  176. Uint32 bitDepth;
  177. Uint32 intrEnableBit;
  178. Uint32 decIdx;
  179. Uint32 rotationIndex; /*!<< 0: 0, 1: 90 CCW, 2: 180 CCW, 3: 270 CCW CCW(Counter Clockwise)*/
  180. JpgMirrorDirection mirrorIndex; /*!<< 0: none, 1: vertical mirror, 2: horizontal mirror, 3: both */
  181. Int32 thtc[THTC_LIST_CNT]; /*!<< Huffman table definition length and table class list : -1 indicates not exist. */
  182. Uint32 numHuffmanTable;
  183. } JpgDecInfo;
  184. typedef struct {
  185. PhysicalAddress streamRdPtr;
  186. PhysicalAddress streamWrPtr;
  187. PhysicalAddress streamBufStartAddr;
  188. PhysicalAddress streamBufEndAddr;
  189. FrameBuffer * frameBufPool;
  190. int numFrameBuffers;
  191. int stride;
  192. int initialInfoObtained;
  193. Uint32 picWidth;
  194. Uint32 picHeight;
  195. Uint32 alignedWidth;
  196. Uint32 alignedHeight;
  197. Uint32 mcuWidth;
  198. Uint32 mcuHeight;
  199. int seqInited;
  200. int frameIdx;
  201. FrameFormat format;
  202. int streamEndian;
  203. int frameEndian;
  204. Uint32 chromaInterleave;
  205. int rstIntval;
  206. int busReqNum;
  207. int mcuBlockNum;
  208. int compNum;
  209. int compInfo[3];
  210. // give command
  211. int disableAPPMarker;
  212. int quantMode;
  213. int stuffByteEnable;
  214. Uint32 huffCode[8][256];
  215. Uint32 huffSize[8][256];
  216. BYTE* pHuffVal[8];
  217. BYTE* pHuffBits[8];
  218. short* pQMatTab[4];
  219. int jpg12bit;
  220. int q_prec0;
  221. int q_prec1;
  222. BYTE *pCInfoTab[4];
  223. PackedFormat packedFormat;
  224. Uint32 pixelJustification;
  225. Int32 sliceHeight;
  226. Uint32 intrEnableBit;
  227. Uint32 encIdx;
  228. Uint32 encSlicePosY;
  229. Uint32 tiledModeEnable;
  230. Uint32 rotationIndex; /*!<< 0: 0, 1: 90 CCW, 2: 180 CCW, 3: 270 CCW CCW(Counter Clockwise)*/
  231. Uint32 mirrorIndex; /*!<< 0: none, 1: vertical mirror, 2: horizontal mirror, 3: both */
  232. } JpgEncInfo;
  233. typedef struct JpgInst {
  234. Int32 inUse;
  235. Int32 instIndex;
  236. Int32 loggingEnable;
  237. BOOL sliceInstMode;
  238. union {
  239. JpgEncInfo encInfo;
  240. JpgDecInfo decInfo;
  241. } *JpgInfo;
  242. } JpgInst;
  243. extern Uint8 sJpuCompInfoTable[5][24];
  244. extern Uint8 sJpuCompInfoTable_EX[5][24];
  245. #ifdef __cplusplus
  246. extern "C" {
  247. #endif
  248. JpgRet GetJpgInstance(JpgInst ** ppInst);
  249. void FreeJpgInstance(JpgInst * pJpgInst);
  250. JpgRet CheckJpgInstValidity(JpgInst * pci);
  251. JpgRet CheckJpgDecOpenParam(JpgDecOpenParam * pop);
  252. int JpuGbuInit(vpu_getbit_context_t *ctx, BYTE *buffer, int size);
  253. int JpuGbuGetUsedBitCount(vpu_getbit_context_t *ctx);
  254. int JpuGbuGetLeftBitCount(vpu_getbit_context_t *ctx);
  255. unsigned int JpuGbuGetBit(vpu_getbit_context_t *ctx, int bit_num);
  256. unsigned int JpuGguShowBit(vpu_getbit_context_t *ctx, int bit_num);
  257. int JpegDecodeHeader(JpgDecInfo * jpg);
  258. int JpgDecQMatTabSetUp(JpgDecInfo *jpg, int instRegIndex);
  259. int JpgDecHuffTabSetUp(JpgDecInfo *jpg, int instRegIndex);
  260. int JpgDecHuffTabSetUp_12b(JpgDecInfo *jpg, int instRegIndex);
  261. void JpgDecGramSetup(JpgDecInfo * jpg, int instRegIndex);
  262. JpgRet CheckJpgEncOpenParam(JpgEncOpenParam * pop, JPUCap* cap);
  263. JpgRet CheckJpgEncParam(JpgEncHandle handle, JpgEncParam * param);
  264. int JpgEncLoadHuffTab(JpgInst *pJpgInst, int instRegIndex);
  265. int JpgEncLoadHuffTab_12b(JpgInst *pJpgInst, int instRegIndex);
  266. int JpgEncLoadQMatTab(JpgInst *pJpgInst, int instRegIndex);
  267. int JpgEncEncodeHeader(JpgEncHandle handle, JpgEncParamSet * para);
  268. void JpgEncSetQualityFactor(JpgEncHandle handle, Uint32 level, BOOL useStdTable);
  269. JpgRet JpgEnterLock();
  270. JpgRet JpgLeaveLock();
  271. JpgRet JpgSetClockGate(Uint32 on);
  272. JpgInst *GetJpgPendingInstEx(Uint32 instIdx);
  273. void SetJpgPendingInstEx(JpgInst *inst, Uint32 instIdx);
  274. void ClearJpgPendingInstEx(Uint32 instIdx);
  275. Uint32 GetDec8bitBusReqNum(FrameFormat iFormat, PackedFormat oPackMode);
  276. Uint32 GetDec12bitBusReqNum(FrameFormat iFormat, PackedFormat oPackMode);
  277. Uint32 GetEnc8bitBusReqNum(PackedFormat iPackMode, FrameFormat oFormat);
  278. Uint32 GetEnc12bitBusReqNum(PackedFormat iPackMode, FrameFormat oFormat);
  279. #ifdef __cplusplus
  280. }
  281. #endif
  282. #endif // endif JPUAPI_UTIL_H_INCLUDED