1 /* 2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HI_GO_DECODE_H 17 #define HI_GO_DECODE_H 18 19 #include "hi_type.h" 20 #include "hi_go_comm.h" 21 #include "hi_go_surface.h" 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif /* __cplusplus */ 27 #endif /* __cplusplus */ 28 29 /* Decoding type of the decoding instance, */ 30 typedef enum { 31 HIGO_DEC_IMGTYPE_JPEG = HIGO_IMGTYPE_JPEG, 32 /* jpeg picture, */ 33 HIGO_DEC_IMGTYPE_GIF = HIGO_IMGTYPE_GIF, 34 /* gif picture, */ 35 HIGO_DEC_IMGTYPE_BMP = HIGO_IMGTYPE_BMP, 36 /* bmp picture, */ 37 HIGO_DEC_IMGTYPE_PNG = HIGO_IMGTYPE_PNG, 38 /* png picture, */ 39 HIGO_DEC_IMGTYPE_RLE = HIGO_IMGTYPE_RLE, 40 /* rle picture, */ 41 HIGO_DEC_IMGTPYE_BUTT 42 } HIGO_DEC_IMGTYPE_E; 43 44 /* Stream source, */ 45 typedef enum { 46 HIGO_DEC_SRCTYPE_FILE = 0, 47 /* Streams are derived from files. */ 48 HIGO_DEC_SRCTYPE_MEM, 49 /* Streams are derived from the memory. */ 50 HIGO_DEC_SRCTYPE_STREAM, 51 /* Streams are derived from stream data. */ 52 HIGO_DEC_SRCTYPE_BUTT 53 } HIGO_DEC_SRCTYPE_E; 54 55 typedef struct { 56 HIGO_MEMTYPE_E MemType; 57 HI_BOOL IsPubPalette; /* 58 * Decoder uses common Palette or not, 59 * 60 */ 61 } HIGO_DEC_SURINFO_S; 62 63 typedef HI_S32 (*PTR_Dec_WriteStreamCB_FN)(unsigned long ClientData, unsigned long Offset); 64 65 /* Detailed information about the stream source, */ 66 typedef union { 67 /* 68 * The following information is required if the input source is the memory. 69 * 70 */ 71 struct { 72 HI_CHAR *pAddr; /* Memory pointer address, */ 73 HI_U32 Length; /* Length, */ 74 } MemInfo; 75 76 /* Picture name, */ 77 const HI_CHAR *pFileName; 78 struct { 79 PTR_Dec_WriteStreamCB_FN pWriteCB; 80 unsigned long ClientData; /* Save client data. */ 81 } Stream; 82 } HIGO_DEC_SRCINFO_U; 83 84 /* Parameters for creating a decoding instance. */ 85 typedef struct { 86 HIGO_DEC_SRCTYPE_E SrcType; /* Type of the input stream. */ 87 HIGO_DEC_SRCINFO_U SrcInfo; /* Information about the input source. */ 88 } HIGO_DEC_ATTR_S; 89 90 /* Major information after decoding, */ 91 typedef struct { 92 HI_U32 Count; /* Number of pictures, */ 93 HIGO_DEC_IMGTYPE_E ImgType; /* Type of the input source. */ 94 HI_U32 ScrWidth; 95 /* 96 * <Screen width. The screen refers to that of the picture. The value 0 indicates "invalid". 97 */ 98 HI_U32 ScrHeight; 99 /* 100 * Screen height. The screen refers to that of the picture. The value 0 indicates "invalid". 101 */ 102 HI_BOOL IsHaveBGColor; /* Whether there is any background color. */ 103 HI_COLOR BGColor; /* Background color, */ 104 } HIGO_DEC_PRIMARYINFO_S; 105 106 /* Index picture format, */ 107 typedef struct { 108 HI_U32 OffSetX; 109 /* 110 * <X offset value on the screen. The screen mentioned in this document refers to that of the picture. 111 */ 112 HI_U32 OffSetY; /* offset value on the screen. */ 113 HI_U32 Width; /* Width of the original picture, */ 114 HI_U32 Height; /* Height of the original picture, */ 115 HI_U8 Alpha; 116 /* 117 * <Information about channel alpha used for overlaying pictures. The alpha value ranges from 0 to 255. 118 */ 119 HI_BOOL IsHaveKey; /* 120 * Key enable. HI_FALSE: disabled; HI_TRUE: enabled, 121 * 122 */ 123 HI_COLOR Key; /* 124 * Information about colorkey used for overlaying pictures, 125 * 126 */ 127 HIGO_PF_E Format; /* Pixel format of the picture source, */ 128 HI_U32 DelayTime; /* 129 * <Time interval between this picture and the previous one (10 ms). 130 * The value 0 indicates that the parameter is invalid. 131 * 132 */ 133 HI_U32 DisposalMethod; /* 134 * Processing method of the current frame. 135 * This application programming interface (API) is valid for only GIF pictures. 136 * 0: customized processing method; 1: no processing method; 137 2: use the background color. 138 * 139 0:ûʽ1:2:ʹñɫ 140 */ 141 } HIGO_DEC_IMGINFO_S; 142 143 /* Picture attributes after decoding, */ 144 typedef struct { 145 HI_U32 Width; /* Expected width after decoding, */ 146 HI_U32 Height; /* Expected height after decoding, */ 147 HIGO_PF_E Format; /* Expected pixel format after decoding, */ 148 } HIGO_DEC_IMGATTR_S; 149 150 /* Extended data format type, */ 151 typedef enum { 152 HIGO_DEC_EXTEND_EXIF = 0, 153 /* Extended-data in EXIF format, */ 154 HIGO_DEC_EXTEND_EXIF_BUTT 155 } HIGO_DEC_EXTENDTYPE_E; 156 157 /* Basic picture information, */ 158 typedef struct { 159 HI_U32 Width; /* Picture width, */ 160 HI_U32 Height; /* Picture height, */ 161 HIGO_PF_E PixelFormat; /* Pixel format, */ 162 HI_U32 VirAddr[3]; /* 163 * Virtual address. If the address is in RGB format, only the first VirAddr[0] is the start 164 * address, and VirAddr[1] and VirAddr[2] are invalid. If the address is in YC format, 165 * VirAddr[0] indicates the start address of the Y component, VirAddr[1] indicates the 166 * start address of the C component, and VirAddr[2] is invalid. 167 * 168 * VirAddr[1]VirAddr[2]ЧYCʽ 169 * VirAddr[0]ʾYʼַVirAddr[1]ʾCʼַ 170 * VirAddr[2]Ч 171 */ 172 HI_U32 PhyAddr[3]; /* 173 * Physical address. The usage principles are the same as previous ones. 174 * 175 */ 176 HI_U32 Pitch[3]; /* 177 * Pitch. The usage principles are the same as previous ones. 178 * 179 */ 180 HI_U32 Palate[256]; /* Palette, */ 181 } HIGO_DEC_IMGDATA_S; 182 183 typedef struct { 184 HI_VOID *StreamBuf; /* Virtual start address of streams, */ 185 HI_U32 StreamLen; /* Actual read stream length, */ 186 HI_U32 ExpectStreamLen; /* Expect read stream length, */ 187 } HIGO_DEC_WRITESTREAM_S; 188 189 /* 190 * \brief Initializes the decoder. 191 * \attention \n 192 * ::HI_GO_Init already calls the interface 193 * \param N/A 194 * \retval ::HI_SUCCESS 195 * \retval ::HI_FAILURE 196 * \retval ::HIGO_ERR_DEPEND_TDE 197 * \see \n 198 * ::HI_GO_Init \n 199 * ::HI_GO_DeinitDecoder 200 */ 201 HI_S32 HI_GO_InitDecoder(HI_VOID); 202 203 /* 204 * \brief Deinitializes the decoder. 205 * \attention \n 206 * When ::HI_GO_Deinit is called, this API is also called. 207 * \param N/A. 208 * \retval ::HI_SUCCESS 209 * \retval ::HIGO_ERR_NOTINIT 210 * \see \n 211 * ::HI_GO_Deinit \n 212 * ::HI_GO_InitDecoder 213 */ 214 HI_S32 HI_GO_DeinitDecoder(HI_VOID); 215 216 /* 217 * \brief Creates a decoding handle. 218 * \attention \n 219 * Currently, the formats of .bmp, .png, .jpeg, and .gif are supported. 220 * The picture input source can be the memory, files 221 * , and streams. The picture input source of streams is only applicable to the .jpeg format. 222 * 223 * \param[in] pSrcDesc Information about the input source. This parameter cannot be empty. 224 * The type of the input stream must match the information about the input source. For example, 225 * corresponding file names must be entered for the file stream, and the memory address and memory size 226 * must be entered 227 * for the memory stream. 228 * ҪԴϸϢһһƥ䣬FILEҪӦļ\n 229 * MemoryҪmemoryĵַԼ CNend 230 * \param[out] pDecoder Pointer of the decoding instance handle. This parameter cannot be empty. 231 * ʵָ룬Ϊ CNend 232 * \retval ::HI_SUCCESS 233 * \retval ::HIGO_ERR_NULLPTR 234 * \retval ::HIGO_ERR_NOTINIT 235 * \retval ::HIGO_ERR_NOMEM 236 * \retval ::HIGO_ERR_INVHANDLE 237 * \retval ::HIGO_ERR_INVFILE 238 * \retval ::HIGO_ERR_INVSRCTYPE 239 * \retval ::HIGO_ERR_INVIMAGETYPE 240 * \retval ::HIGO_ERR_INVIMGDATA 241 * \see \n 242 * ::HI_GO_DestroyDecoder 243 */ 244 HI_S32 HI_GO_CreateDecoder(const HIGO_DEC_ATTR_S *pSrcDesc, HI_HANDLE *pDecoder); 245 246 /* 247 * \brief Destroys a decoding handle. 248 * \attention \n 249 * N/A. 250 * \param[in] Decoder Handle of the decoding instance. 251 * \retval ::HI_SUCCESS 252 * \retval ::HIGO_ERR_INVHANDLE 253 * \see \n 254 * ::HI_GO_CreateDecoder 255 */ 256 HI_S32 HI_GO_DestroyDecoder(HI_HANDLE Decoder); 257 258 /* 259 * \brief Stream API 260 * \attention \n 261 * N/A. 262 * \param[in] Decoder Handle of the decoding instance. 263 * \param[in] pStream Pointer to the stream information. This parameter cannot be empty. 264 * 265 * \retval ::HI_SUCCESS 266 * \retval ::HI_FAILURE 267 * \retval ::HIGO_ERR_NULLPTR 268 * \retval ::HIGO_ERR_INVHANDLE 269 * \retval ::HIGO_ERR_UNSUPPORTED 270 * \see \n 271 * ::HI_GO_CreateDecoder 272 */ 273 HI_S32 HI_GO_DecWriteStream(HI_HANDLE Decoder, HIGO_DEC_WRITESTREAM_S *pStream); 274 275 /* 276 * \brief Reset decoding. 277 * \attention only support jpeg decode\n 278 * N/A. 279 * \param[in] Decoder Handle of the decoding instance. 280 * \retval ::HI_SUCCESS 281 * \retval ::HIGO_ERR_INVHANDLE 282 * \retval ::HIGO_ERR_INVIMAGETYPE 283 * \see sample_dec_stream.c\n 284 * ::HI_GO_ResetDecoder 285 */ 286 HI_S32 HI_GO_ResetDecoder(HI_HANDLE Decoder); 287 288 /* 289 * \brief Obtains the major information about pictures. 290 * \attention 291 * N/A. 292 * \param[in] Decoder Handle of the decoding instance. 293 * \param[out] pPrimaryInfo Pointer to the major information about the decoded picture. This parameter cannot be 294 * empty. 295 * \retval ::HI_SUCCESS 296 * \retval ::HIGO_ERR_INVHANDLE 297 * \retval ::HIGO_ERR_NULLPTR 298 * \retval ::HI_NULL 299 * \retval ::HIGO_ERR_INVIMGDATA 300 * \see \n 301 * ::HI_GO_DecImgInfo 302 */ 303 HI_S32 HI_GO_DecCommInfo(HI_HANDLE Decoder, HIGO_DEC_PRIMARYINFO_S *pPrimaryInfo); 304 305 /* 306 * \brief Obtains the information about the specified picture. You can customize the picture format. 307 * ȡָͼƬϢͬʱûͼʽ CNend \attention \n N/A. 308 * 309 * Handle of the decoding instance. 310 * For .jpeg pictures, 311 * the index number of the main picture is 0, and index numbers of thumbnails start from 1. The index numbers of GIF 312 * pictures start from 0 and increase by 1 according to the sequence of the pictures stored in a file. 313 * ͼƬšJPEGʽͼƬͼ0ͼ1ʼ\n 314 * GIFʽͼƬļеĴ洢˳0ʼݼ 315 * CNend \param[out] pImgInfo Picture information. This parameter cannot be empty. 316 * 317 * \retval ::HI_SUCCESS 318 * \retval ::HIGO_ERR_NULLPTR 319 * \retval ::HIGO_ERR_INVHANDLE 320 * \retval ::HIGO_ERR_INVINDEX 321 * \retval ::HI_FAILURE 322 * \retval ::HI_NULL 323 * \retval ::HIGO_ERR_INVIMGDATA 324 * \see \n 325 * ::HI_GO_DecCommInfo 326 */ 327 HI_S32 HI_GO_DecImgInfo(HI_HANDLE Decoder, HI_U32 Index, HIGO_DEC_IMGINFO_S *pImgInfo); 328 329 /* 330 * \brief Obtains the data of a picture. 331 * \attention \n 332 * The format in the destination picture attributes does not support the macro block 333 * format. 334 * \param[in] Decoder Handle of the decoding instance. 335 * \param[in] Index Index number of a picture, starting from 0. 336 * \param[in] pImgAttr Attribute of the destination picture. If the value is empty, it indicates that the original 337 * picture attributes are retained. 338 * \param[out] pSurface Handle of the surface where the decoded data is stored. 339 * CNend 340 * \retval ::HI_SUCCESS 341 * \retval ::HIGO_ERR_NULLPTR 342 * \retval ::HIGO_ERR_INVHANDLE 343 * \retval ::HIGO_ERR_INVINDEX 344 * \retval ::HI_FAILURE 345 * \retval ::HI_NULL 346 * \retval ::HIGO_ERR_INVIMGDATA 347 * \retval ::HIGO_ERR_NOMEM 348 * \retval ::HIGO_ERR_UNSUPPORTED 349 * \see \n 350 * ::HI_GO_DecCommInfo 351 */ 352 HI_S32 HI_GO_DecImgData(HI_HANDLE Decoder, HI_U32 Index, const HIGO_DEC_IMGATTR_S *pImgAttr, HI_HANDLE *pSurface); 353 354 /* 355 * \brief Obtains the extended data. 356 * \attention \n 357 * Hi3110E does not support the API. 358 * \param[in] Decoder Handle of the decoding instance. 359 * \param[in] DecExtendType 360 * Type of the obtained extended data. Currently, only the EXIF information in .jpeg format is available. 361 * 362 * \param[out] ppData Pointer to the extended data pointer. 363 * \param[out] pLength ppData Length. 364 * \retval ::HI_SUCCESS 365 * \retval ::HIGO_ERR_NULLPTR 366 * \retval ::HIGO_ERR_INVHANDLE 367 * \retval ::HIGO_ERR_UNSUPPORTED 368 * \see \n 369 * ::HI_GO_ReleaseDecExtendData 370 */ 371 HI_S32 HI_GO_DecExtendData(HI_HANDLE Decoder, HIGO_DEC_EXTENDTYPE_E DecExtendType, HI_VOID **ppData, HI_U32 *pLength); 372 373 /* 374 * \brief Releases extended data. 375 * \attention \n 376 * Hi3110E does not support the API. 377 * \param[in] Decoder Decoder handle. 378 * \param[in] DecExtendType Type of the obtained extended data. Currently, 379 * only the EXIF information in .jpeg format is 380 * available. 381 * \param[in] pData Pointer to the extended data. 382 * \retval ::HI_SUCCESS 383 * \retval ::HIGO_ERR_NULLPTR 384 * \retval ::HIGO_ERR_UNSUPPORTED 385 * \see \n 386 * ::HI_GO_DecExtendData 387 */ 388 HI_S32 HI_GO_ReleaseDecExtendData(HI_HANDLE Decoder, HIGO_DEC_EXTENDTYPE_E DecExtendType, HI_VOID *pData); 389 390 /* 391 * \brief Decodes a picture to a specified surface. 392 * \attention \n 393 * The decoded surface is scaled automatically based on the size of the target surface. In addition, 394 * the decoded surface 395 * modifies the attributes of the target surface, such as colorkey, alpha value, and palette. 396 * 397 * ALPHAԼɫ CNend 398 * \param[in] Decoder Handle of the decoding instance. 399 * \param[in] Index Index number of a decoded picture. 400 * \param[out] Surface Decoded target surface. 401 * \retval ::HI_SUCCESS 402 * \retval ::HIGO_ERR_INVHANDLE 403 * \retval ::HIGO_ERR_INVINDEX 404 * \retval ::HIGO_ERR_NULLPTR 405 * \retval ::HI_FAILURE 406 * \retval ::HI_NULL 407 * \retval ::HIGO_ERR_INVIMGDATA 408 * \retval ::HIGO_ERR_NOMEM 409 * \retval ::HIGO_ERR_UNSUPPORTED 410 * \see \n 411 * N/A. 412 */ 413 HI_S32 HI_GO_DecImgToSurface(HI_HANDLE Decoder, HI_U32 Index, HI_HANDLE Surface); 414 415 /* 416 * \brief Decodes a specified file, and generates a new surface. 417 * 418 * \attention \n 419 * If there are multiple pictures in the file (such as .gif animation, .jpeg main picture, and .jpeg thumbnail), 420 * only the .jpeg main picture and the first picture of the .gif animation are decoded. 421 * In addition, the surface size is the same as the picture size. 422 * 423 * JPEGֻͼGIFһͼƬsurfaceĴСͼƬĴСһ CNend 424 * \param[in] pszFile Picture name. The picture can be in the format of .gif, .png, .jpg, or 425 * .bmp. 426 * pictures. 427 * \retval ::HI_SUCCESS 428 * \retval ::HI_FAILURE 429 * \retval ::HIGO_ERR_INVHANDLE 430 * \retval ::HIGO_ERR_INVINDEX 431 * \retval ::HIGO_ERR_NULLPTR 432 * \retval ::HI_NULL 433 * \retval ::HIGO_ERR_INVIMGDATA 434 * \retval ::HIGO_ERR_NOMEM 435 * \retval ::HIGO_ERR_UNSUPPORTED 436 * \retval ::HIGO_ERR_INVFILE 437 * \retval ::HIGO_ERR_INVSRCTYPE 438 * \retval ::HIGO_ERR_INVIMAGETYPE 439 * \see \n 440 * N/A. 441 */ 442 HI_S32 HI_GO_DecodeFile(const HI_CHAR *pszFile, HI_HANDLE *pSurface); 443 444 /* 445 * \brief Set the attribute of Decoder out Surface memrory. 446 * \attention \n 447 * N/A. 448 * \param[in] Decoder handle. 449 * \param[in] pSurfInfo. 450 * \retval ::HI_SUCCESS 451 * \retval ::HIGO_ERR_INVHANDLE 452 * \see \n 453 * N/A. 454 */ 455 HI_S32 HI_GO_SetDecSurfInfo(HI_HANDLE Decoder, const HIGO_DEC_SURINFO_S *pSurfInfo); 456 457 #ifdef __cplusplus 458 #if __cplusplus 459 } 460 #endif /* __cplusplus */ 461 #endif /* __cplusplus */ 462 463 #endif /* HI_GO_DECODE_H */ 464