staticvoid *GetDeviceBufferOfPicture(const PicDesc &picDesc, uint32_t &devPicBufferSize); staticchar *ReadBinFile(std::string fileName, uint32_t &fileSize); static Result SaveDvppOutputData(constchar *fileName, constvoid *devPtr, uint32_t dataSize); voidSetInput(void *inDevBuffer, int inDevBufferSize, int inputWidth, int inputHeight); voidGetOutput(void **outputBuffer, int &outputSize); voidDestroyResource();
Result JPEGD(PicDesc testPic); Result PNGD(PicDesc testPic); Result resize(PicDesc testPic); uint32_tAlignmentHelper(uint32_t origSize, uint32_t alignment);
INFO_LOG("start to process picture:%s", testPic.picName.c_str()); // dvpp process /*3.Read the picture into memory. InDevBuffer_ indicates the memory for storing the input picture, inDevBufferSize indicates the memory size, please apply for the input memory in advance*/ uint32_t devPicBufferSize; void *picDevBuffer = GetDeviceBufferOfPicture(testPic, devPicBufferSize); if (picDevBuffer == nullptr) { ERROR_LOG("get pic device buffer failed,index is 0"); return FAILED; } // 4.Create image data processing channel dvppChannelDesc_ = acldvppCreateChannelDesc(); acldvppCreateChannel(dvppChannelDesc_); INFO_LOG("dvpp init resource success");
acldvppSetPicDescData(decodeOutputDesc_, decodeOutDevBuffer_); // here the format shoud be same with the value you set when you get decodeOutBufferSize from acldvppSetPicDescFormat(decodeOutputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420); acldvppSetPicDescWidth(decodeOutputDesc_, inputWidth_); acldvppSetPicDescHeight(decodeOutputDesc_, inputHeight_); acldvppSetPicDescWidthStride(decodeOutputDesc_, decodeOutWidthStride); acldvppSetPicDescHeightStride(decodeOutputDesc_, decodeOutHeightStride); acldvppSetPicDescSize(decodeOutputDesc_, testPic.jpegDecodeSize);
ret = acldvppJpegDecodeAsync(dvppChannelDesc_, inDevBuffer_, inDevBufferSize_, decodeOutputDesc_, stream_); if (ret != ACL_SUCCESS) { ERROR_LOG("acldvppJpegDecodeAsync failed, ret = %d", ret); return FAILED; }
ret = aclrtSynchronizeStream(stream_); if (ret != ACL_SUCCESS) { ERROR_LOG("aclrtSynchronizeStream failed"); return FAILED; } }
acldvppSetPicDescData(decodeOutputDesc_, decodeOutDevBuffer_); // here the format shoud be same with the value you set when you get decodeOutBufferSize from acldvppSetPicDescFormat(decodeOutputDesc_, PIXEL_FORMAT_RGB_888); acldvppSetPicDescWidth(decodeOutputDesc_, inputWidth_); acldvppSetPicDescHeight(decodeOutputDesc_, inputHeight_); acldvppSetPicDescWidthStride(decodeOutputDesc_, decodeOutWidthStride); acldvppSetPicDescHeightStride(decodeOutputDesc_, decodeOutHeightStride); acldvppSetPicDescSize(decodeOutputDesc_, testPic.jpegDecodeSize);
ret = acldvppPngDecodeAsync(dvppChannelDesc_, inDevBuffer_, inDevBufferSize_, decodeOutputDesc_, stream_); if (ret != ACL_SUCCESS) { ERROR_LOG("acldvppPngDecodeAsync failed, ret = %d", ret); return FAILED; }
ret = aclrtSynchronizeStream(stream_); if (ret != ACL_SUCCESS) { ERROR_LOG("aclrtSynchronizeStream failed"); return FAILED; } }
aclError aclRet = acldvppJpegGetImageInfoV2(inputBuff, inputBuffSize, &picDesc.width, &picDesc.height, nullptr, &format); if (aclRet != ACL_SUCCESS) { ERROR_LOG("get jpeg image info failed, errorCode is %d", static_cast<int32_t>(aclRet)); delete[] inputBuff; fclose(fp); returnnullptr; } // when you run, from the output, we can see that the original format is ACL_JPEG_CSS_420, // so it can be decoded as PIXEL_FORMAT_YUV_SEMIPLANAR_420 or PIXEL_FORMAT_YVU_SEMIPLANAR_420 aclRet = acldvppJpegPredictDecSize(inputBuff, inputBuffSize, PIXEL_FORMAT_YUV_SEMIPLANAR_420, &picDesc.jpegDecodeSize); if (aclRet != ACL_SUCCESS) { ERROR_LOG("get jpeg decode size failed, errorCode is %d", static_cast<int32_t>(aclRet)); delete[] inputBuff; fclose(fp); returnnullptr; } INFO_LOG("get jpeg image info successed, width=%d, height=%d, format=%d, jpegDecodeSize=%d", picDesc.width, picDesc.height, format, picDesc.jpegDecodeSize); }