Help Center/
Atlas 300 Application (Model 3000)/
DVPP API Reference/
Calling Example/
Implementing the PNGD Function
Updated on 2022-03-13 GMT+08:00
Implementing the PNGD Function
The memory size can be obtained by calling DvppGetOutParameter. The output memory can be specified and freed by the user. The calling example is as follows:
void TEST_PNGD_CUSTOM_MEMORY() { FILE* fpIn = fopen(g_inFileName, "rb"); if (nullptr == fpIn) { HIAI_ENGINE_LOG(HIAI_OPEN_FILE_ERROR, "can not open file %s.", g_inFileName); return; } fseek(fpIn, 0, SEEK_END); uint32_t fileLen = ftell(fpIn); fseek(fpIn, 0, SEEK_SET); void* inbuf = HIAI_DVPP_DMalloc(fileLen); if (inbuf == nullptr) { HIAI_ENGINE_LOG(HIAI_PNGD_CTL_ERROR, "can not alloc input buffer"); fclose(fpIn); fpIn = nullptr; return; } // prepare msg struct PngInputInfoAPI inputPngData; // input data inputPngData.inputData = inbuf; // input png data inputPngData.inputSize = fileLen; // the size of png data HIAI_ENGINE_LOG("inputPngData.address: %p", inputPngData.address); HIAI_ENGINE_LOG("inputPngData.size: %u", inputPngData.size); HIAI_ENGINE_LOG("inputPngData.inputData: %p", inputPngData.inputData); HIAI_ENGINE_LOG("inputPngData.inputSize: %u", inputPngData.inputSize); fread(inputPngData.inputData, 1, fileLen, fpIn); fclose(fpIn); fpIn = nullptr; if (g_transform == 1) { // Whether format conversion inputPngData.transformFlag = 1; // RGBA -> RGB } else { inputPngData.transformFlag = 0; } struct PngOutputInfoAPI outputPngData; // output data int32_t ret = DvppGetOutParameter((void*)(&inputPngData), (void*)(&outputPngData), GET_PNGD_OUT_PARAMETER); if (ret != 0) { HIAI_ENGINE_LOG(HIAI_PNGD_CTL_ERROR, "call DvppGetOutParameter process failed"); HIAI_DVPP_DFree(inbuf); inbuf = nullptr; return; } HIAI_ENGINE_LOG("pngd out size is %d", outputPngData.size); outputPngData.address = HIAI_DVPP_DMalloc(outputPngData.size); if (outputPngData.address == nullptr) { HIAI_ENGINE_LOG(HIAI_PNGD_CTL_ERROR, "can not alloc output buffer"); HIAI_DVPP_DFree(inbuf); inbuf = nullptr; return; } dvppapi_ctl_msg dvppApiCtlMsg; // call the interface msg dvppApiCtlMsg.in = (void*)(&inputPngData); dvppApiCtlMsg.in_size = sizeof(struct PngInputInfoAPI); dvppApiCtlMsg.out = (void*)(&outputPngData); dvppApiCtlMsg.out_size = sizeof(struct PngOutputInfoAPI); // use interface IDVPPAPI *pidvppapi = nullptr; CreateDvppApi(pidvppapi); // create dvppapi if (pidvppapi != nullptr) { // use DvppCtl interface to handle DVPP_CTL_PNGD_PROC for (int i = 0; i < g_loop; i++) { if (-1 == DvppCtl(pidvppapi, DVPP_CTL_PNGD_PROC, &dvppApiCtlMsg)) { HIAI_ENGINE_LOG(HIAI_PNGD_CTL_ERROR, "call dvppctl process failed"); HIAI_DVPP_DFree(inbuf); inbuf = nullptr; HIAI_DVPP_DFree(outputPngData.address); outputPngData.address = nullptr; DestroyDvppApi(pidvppapi); // destory dvppapi return; } } } else { HIAI_ENGINE_LOG(HIAI_PNGD_CTL_ERROR, "can not get dvpp api"); } DestroyDvppApi(pidvppapi); HIAI_ENGINE_LOG("output result"); char* pAddr = (char*)outputPngData.outputData; FILE* fpOut = fopen(g_outFileName, "wb"); if (fpOut == nullptr) { HIAI_ENGINE_LOG(HIAI_OPEN_FILE_ERROR, "can not open file %s.", g_outFileName); HIAI_DVPP_DFree(inbuf); inbuf = nullptr; HIAI_DVPP_DFree(outputPngData.address); outputPngData.address = nullptr; return; } int size = outputPngData.width * 4; if (outputPngData.format == PNGD_RGB_FORMAT_NUM) { size = outputPngData.width * 3; } else if (outputPngData.format == PNGD_RGBA_FORMAT_NUM) { size = outputPngData.width * 4; } // copy valid image data from every line. for (int i = 0; i < outputPngData.high; i++) { fwrite(pAddr + (int)(i * outputPngData.widthAlign), size, 1, fpOut); } fclose(fpOut); fpOut = nullptr; HIAI_DVPP_DFree(inbuf); inbuf = nullptr; HIAI_DVPP_DFree(outputPngData.address); outputPngData.address = nullptr; return; }
Parent topic: Calling Example
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot