// Include the header#include "hobot/hb_ucp.h"#include "hobot/vp/hb_vp.h"#include "hobot/vp/hb_vp_jpeg_codec.h"// init image_buf, alloc memory for image datahbUCPSysMem image_mem;hbUCPMalloc(&image_mem, yuv_size, 0);hbVPImage image_buf = hbVPImage{HB_VP_IMAGE_FORMAT_YUV420, HB_VP_IMAGE_TYPE_U8C1, width, height, width, image_mem.virAddr, image_mem.phyAddr, nullptr, 0, 0};// init jpeg_bufhbVPArray jpeg_buf{0};// init encoding paramhbVPJPEGEncParam enc_param;// default set backend to HB_UCP_JPU_CORE_0HB_VP_INITIALIZE_JPEG_ENC_PARAM(&enc_param);enc_param.width = width;enc_param.height = height;enc_param.imageFormat = HB_VP_IMAGE_FORMAT_YUV420;// create encoding context and the JPU internally alloc the output bufferhbVPJPEGContext enc_context{nullptr};hbVPCreateJPEGEncContext(&enc_context, &enc_param);// init task handle and schedule paramhbUCPTaskHandle_t task_handle{nullptr};hbUCPSchedParam sched_param;HB_UCP_INITIALIZE_SCHED_PARAM(&sched_param);sched_param.backend = HB_UCP_JPU_CORE_0;// create encoding taskhbVPJPEGEncode(&task_handle, &image_buf, enc_context);// submit encoding taskhbUCPSubmitTask(task_handle, &sched_param);// wait for encoding task donehbUCPWaitTaskDone(task_handle, 0);// get encoded buffer from JPUhbVPGetJPEGEncOutputBuffer(&jpeg_buf, task_handle);// process jpeg data// release task handle and dequeue output buffer from JPU// since the dequeue output buffer process relies on the context,// you must call the hbUCPReleaseTask interface before calling the hbVPReleaseJPEGEncContext interfacehbUCPReleaseTask(task_handle);// release encoding context and the JPU internally release the output bufferhbVPReleaseJPEGEncContext(enc_context);// release memoryhbUCPFree(&image_mem);
// Include the header#include "hobot/hb_ucp.h"#include "hobot/vp/hb_vp.h"#include "hobot/vp/hb_vp_jpeg_codec.h"// init jpeg_buf, alloc memory for jpeg datahbUCPSysMem jpeg_mem;hbUCPMalloc(&jpeg_mem, jpeg_size, 0);hbVPArray jpeg_buf;jpeg_buf.phyAddr = jpeg_mem.phyAddr;jpeg_buf.virAddr = jpeg_mem.virAddr;jpeg_buf.memSize = jpeg_mem.memSize;jpeg_buf.size = jpeg_mem.memSize;// init image_bufhbVPImage image_buf{0};// create decoding context and the JPU internally alloc the output bufferhbVPJPEGDecParam dec_param{};// default set backend to HB_UCP_JPU_CORE_0HB_VP_INITIALIZE_JPEG_DEC_PARAM(&dec_param);hbVPJPEGContext dec_context{nullptr};hbVPCreateJPEGDecContext(&dec_context, &dec_param);// init task handle and schedule paramhbUCPTaskHandle_t task_handle{nullptr};hbUCPSchedParam sched_param;HB_UCP_INITIALIZE_SCHED_PARAM(&sched_param);sched_param.backend = HB_UCP_JPU_CORE_0;// create decoding taskhbVPJPEGDecode(&task_handle, &jpeg_buf, dec_context);// submit decoding taskhbUCPSubmitTask(task_handle, &sched_param);// wait for decoding task donehbUCPWaitTaskDone(task_handle, 0);// get decoded buffer from JPUhbVPGetJPEGDecOutputBuffer(&image_buf, task_handle);// process image data// release task handle and dequeue output buffer from JPU// since the dequeue output buffer process relies on the context,// you must call the hbUCPReleaseTask interface before calling the hbVPReleaseJPEGEncContext interfacehbUCPReleaseTask(task_handle);// release encoding context and the JPU internally release the output bufferhbVPReleaseJPEGDecContext(dec_context);// release memoryhbUCPFree(&jpeg_mem);