jpegencapi.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*------------------------------------------------------------------------------
  2. -- --
  3. -- This software is confidential and proprietary and may be used --
  4. -- only as expressly authorized by a licensing agreement from --
  5. -- --
  6. -- Hantro Products Oy. --
  7. -- --
  8. -- (C) COPYRIGHT 2006 HANTRO PRODUCTS OY --
  9. -- ALL RIGHTS RESERVED --
  10. -- --
  11. -- The entire notice above must be reproduced --
  12. -- on all copies and should not be removed. --
  13. -- --
  14. --------------------------------------------------------------------------------
  15. --
  16. -- Abstract : Hantro 8290 Jpeg Encoder API
  17. --
  18. ------------------------------------------------------------------------------*/
  19. /*------------------------------------------------------------------------------
  20. Table of contents
  21. 1. Include headers
  22. 2. Module defines
  23. 3. Data types
  24. 4. Function prototypes
  25. ------------------------------------------------------------------------------*/
  26. #ifndef __JPEGENCAPI_H__
  27. #define __JPEGENCAPI_H__
  28. #ifdef __cplusplus
  29. extern "C"
  30. {
  31. #endif
  32. /*------------------------------------------------------------------------------
  33. 1. Include headers
  34. ------------------------------------------------------------------------------*/
  35. #include "basetype.h"
  36. /*------------------------------------------------------------------------------
  37. 2. Module defines
  38. ------------------------------------------------------------------------------*/
  39. typedef const void *JpegEncInst;
  40. typedef enum
  41. {
  42. JPEGENC_FRAME_READY = 1,
  43. JPEGENC_RESTART_INTERVAL = 2,
  44. JPEGENC_OK = 0,
  45. JPEGENC_ERROR = -1,
  46. JPEGENC_NULL_ARGUMENT = -2,
  47. JPEGENC_INVALID_ARGUMENT = -3,
  48. JPEGENC_MEMORY_ERROR = -4,
  49. JPEGENC_INVALID_STATUS = -5,
  50. JPEGENC_OUTPUT_BUFFER_OVERFLOW = -6,
  51. JPEGENC_EWL_ERROR = -7,
  52. JPEGENC_EWL_MEMORY_ERROR = -8,
  53. JPEGENC_HW_BUS_ERROR = -9,
  54. JPEGENC_HW_DATA_ERROR = -10,
  55. JPEGENC_HW_TIMEOUT = -11,
  56. JPEGENC_HW_RESERVED = -12,
  57. JPEGENC_SYSTEM_ERROR = -13,
  58. JPEGENC_INSTANCE_ERROR = -14,
  59. JPEGENC_HW_RESET = -15
  60. } JpegEncRet;
  61. /* Picture YUV type for initialization */
  62. typedef enum
  63. {
  64. JPEGENC_YUV420_PLANAR = 0, /* YYYY... UUUU... VVVV */
  65. JPEGENC_YUV420_SEMIPLANAR = 1, /* YYYY... UVUVUV... */
  66. JPEGENC_YUV422_INTERLEAVED_YUYV = 2, /* YUYVYUYV... */
  67. JPEGENC_YUV422_INTERLEAVED_UYVY = 3, /* UYVYUYVY... */
  68. JPEGENC_RGB565 = 4, /* 16-bit RGB */
  69. JPEGENC_BGR565 = 5, /* 16-bit RGB */
  70. JPEGENC_RGB555 = 6, /* 15-bit RGB */
  71. JPEGENC_BGR555 = 7, /* 15-bit RGB */
  72. JPEGENC_RGB444 = 8, /* 12-bit RGB */
  73. JPEGENC_BGR444 = 9, /* 12-bit RGB */
  74. JPEGENC_RGB888 = 10, /* 24-bit RGB */
  75. JPEGENC_BGR888 = 11, /* 24-bit RGB */
  76. JPEGENC_RGB101010 = 12, /* 30-bit RGB */
  77. JPEGENC_BGR101010 = 13 /* 30-bit RGB */
  78. } JpegEncFrameType;
  79. /* Picture rotation for initialization */
  80. typedef enum
  81. {
  82. JPEGENC_ROTATE_0 = 0,
  83. JPEGENC_ROTATE_90R = 1, /* Rotate 90 degrees clockwise */
  84. JPEGENC_ROTATE_90L = 2 /* Rotate 90 degrees counter-clockwise */
  85. } JpegEncPictureRotation;
  86. /* Picture color space conversion for RGB input */
  87. typedef enum
  88. {
  89. JPEGENC_RGBTOYUV_BT601 = 0, /* Color conversion according to BT.601 */
  90. JPEGENC_RGBTOYUV_BT709 = 1, /* Color conversion according to BT.709 */
  91. JPEGENC_RGBTOYUV_USER_DEFINED = 2 /* User defined color conversion */
  92. } JpegEncColorConversionType;
  93. typedef enum
  94. {
  95. JPEGENC_WHOLE_FRAME = 0, /* The whole frame is stored in linear memory */
  96. JPEGENC_SLICED_FRAME /* The frame is sliced into restart intervals;
  97. * Input address is given for each slice */
  98. } JpegEncCodingType;
  99. typedef enum
  100. {
  101. JPEGENC_420_MODE = 0, /* Encoding in YUV 4:2:0 mode */
  102. JPEGENC_422_MODE /* Encoding in YUV 4:2:2 mode */
  103. } JpegEncCodingMode;
  104. typedef enum
  105. {
  106. JPEGENC_NO_UNITS = 0, /* No units,
  107. * X and Y specify the pixel aspect ratio */
  108. JPEGENC_DOTS_PER_INCH = 1, /* X and Y are dots per inch */
  109. JPEGENC_DOTS_PER_CM = 2 /* X and Y are dots per cm */
  110. } JpegEncAppUnitsType;
  111. typedef enum
  112. {
  113. JPEGENC_SINGLE_MARKER = 0, /* Luma/Chroma tables are written behind
  114. * one marker */
  115. JPEGENC_MULTI_MARKER /* Luma/Chroma tables are written behind
  116. * one marker/component */
  117. } JpegEncTableMarkerType;
  118. typedef enum
  119. {
  120. JPEGENC_THUMB_JPEG = 0x10, /* Thumbnail coded using JPEG */
  121. JPEGENC_THUMB_PALETTE_RGB8 = 0x11, /* Thumbnail stored using 1 byte/pixel */
  122. JPEGENC_THUMB_RGB24 = 0x13 /* Thumbnail stored using 3 bytes/pixel */
  123. } JpegEncThumbFormat;
  124. /*------------------------------------------------------------------------------
  125. 3. Data types
  126. ------------------------------------------------------------------------------*/
  127. /* Version information */
  128. typedef struct
  129. {
  130. u32 major; /* Encoder API major version */
  131. u32 minor; /* Encoder API minor version */
  132. } JpegEncApiVersion;
  133. typedef struct
  134. {
  135. u32 swBuild; /* Software build ID */
  136. u32 hwBuild; /* Hardware build ID */
  137. } JpegEncBuild;
  138. /* thumbnail info */
  139. typedef struct
  140. {
  141. JpegEncThumbFormat format; /* Format of the thumbnail */
  142. u8 width; /* Width in pixels of thumbnail */
  143. u8 height; /* Height in pixels of thumbnail */
  144. const void *data; /* Thumbnail data */
  145. u16 dataLength; /* Data amount in bytes */
  146. } JpegEncThumb;
  147. /* RGB input to YUV color conversion */
  148. typedef struct
  149. {
  150. JpegEncColorConversionType type;
  151. u16 coeffA; /* User defined color conversion coefficient */
  152. u16 coeffB; /* User defined color conversion coefficient */
  153. u16 coeffC; /* User defined color conversion coefficient */
  154. u16 coeffE; /* User defined color conversion coefficient */
  155. u16 coeffF; /* User defined color conversion coefficient */
  156. } JpegEncColorConversion;
  157. /* Encoder configuration */
  158. typedef struct
  159. {
  160. u32 inputWidth; /* Number of pixels/line in input image */
  161. u32 inputHeight; /* Number of lines in input image */
  162. u32 xOffset; /* Pixels from top-left corner of input image */
  163. u32 yOffset; /* to top-left corner of encoded image */
  164. u32 codingWidth; /* Width of encoded image */
  165. u32 codingHeight; /* Height of encoded image */
  166. u32 restartInterval; /* Restart interval (MCU lines) */
  167. u32 qLevel; /* Quantization level (0 - 9) */
  168. const u8 *qTableLuma; /* Quantization table for luminance [64],
  169. * overrides quantization level, zigzag order */
  170. const u8 *qTableChroma; /* Quantization table for chrominance [64],
  171. * overrides quantization level, zigzag order */
  172. JpegEncFrameType frameType; /* Input frame YUV / RGB format */
  173. JpegEncColorConversion colorConversion; /* RGB to YUV conversion */
  174. JpegEncPictureRotation rotation; /* rotation off/-90/+90 */
  175. JpegEncCodingType codingType; /* Whole frame / restart interval */
  176. JpegEncCodingMode codingMode; /* 4:2:0 / 4:2:2 coding */
  177. JpegEncAppUnitsType unitsType; /* Units for X & Y density in APP0 */
  178. JpegEncTableMarkerType markerType; /* Table marker type */
  179. u32 xDensity; /* Horizontal pixel density */
  180. u32 yDensity; /* Vertical pixel density */
  181. u32 comLength; /* Length of COM header */
  182. const u8 *pCom; /* Comment header pointer */
  183. } JpegEncCfg;
  184. /* Input info */
  185. typedef struct
  186. {
  187. u32 frameHeader; /* Enable/disable creation of frame headers */
  188. u32 busLum; /* Bus address of luminance input (Y) */
  189. u32 busCb; /* Bus address of chrominance input (Cb) */
  190. u32 busCr; /* Bus address of chrominance input (Cr) */
  191. const u8 *pLum; /* Pointer to luminance input (Y) */
  192. const u8 *pCb; /* Pointer to chrominance input (Cb) */
  193. const u8 *pCr; /* Pointer to chrominance input (Cr) */
  194. u8 *pOutBuf; /* Pointer to output buffer */
  195. u32 busOutBuf; /* Bus address of output stream buffer */
  196. u32 outBufSize; /* Size of output buffer (bytes) */
  197. } JpegEncIn;
  198. /* Output info */
  199. typedef struct
  200. {
  201. u32 jfifSize; /* Encoded JFIF size (bytes) */
  202. } JpegEncOut;
  203. /*------------------------------------------------------------------------------
  204. 4. Function prototypes
  205. ------------------------------------------------------------------------------*/
  206. /* Version information */
  207. JpegEncApiVersion JpegEncGetApiVersion(void);
  208. /* Build information */
  209. JpegEncBuild JpegEncGetBuild(void);
  210. /* Initialization & release */
  211. JpegEncRet JpegEncInit(const JpegEncCfg * pEncCfg, JpegEncInst * instAddr);
  212. JpegEncRet JpegEncRelease(JpegEncInst inst);
  213. /* Encoding configuration */
  214. JpegEncRet JpegEncSetPictureSize(JpegEncInst inst,
  215. const JpegEncCfg * pEncCfg);
  216. JpegEncRet JpegEncSetThumbnail(JpegEncInst inst,
  217. const JpegEncThumb * JpegThumb);
  218. /* Jfif generation */
  219. JpegEncRet JpegEncEncode(JpegEncInst inst,
  220. const JpegEncIn * pEncIn, JpegEncOut * pEncOut);
  221. /*------------------------------------------------------------------------------
  222. 5. Encoder API tracing callback function
  223. ------------------------------------------------------------------------------*/
  224. void JpegEnc_Trace(const char *msg);
  225. #ifdef __cplusplus
  226. }
  227. #endif
  228. #endif