【Qt-Camera】大华相机显示线程

// 显示线程
void CammerWidget::DisplayThreadProc(Dahua::Infra::CThreadLite& lite)
{
	while (lite.looping())
	{
		CFrameInfo frameInfo;

		if (false == m_qDisplayFrameQueue.get(frameInfo, 500))
		{
			continue;
		}

		// 判断是否要显示。超过显示上限(30帧),就不做转码、显示处理
		if (!isTimeToDisplay())
		{
			/* 释放内存 */
			free(frameInfo.m_pImageBuf);
			continue;
		}

		/* mono8格式可不做转码,直接显示,其他格式需要经过转码才能显示 */
        if (Dahua::GenICam::gvspPixelMono8 == frameInfo.m_ePixelType)
		{
            //显示线程中发送显示信号,在主线程中显示图像
			emit signalShowImage(frameInfo.m_pImageBuf, frameInfo.m_nWidth, frameInfo.m_nHeight, frameInfo.m_ePixelType);

		}
		else
		{
			/* 转码 */
			uint8_t *pRGBbuffer = NULL;
			int nRgbBufferSize = 0;
			nRgbBufferSize = frameInfo.m_nWidth * frameInfo.m_nHeight * 3;
			pRGBbuffer = (uint8_t *)malloc(nRgbBufferSize);
			if (pRGBbuffer == NULL)
			{
				/* 释放内存 */
				free(frameInfo.m_pImageBuf);
				printf("RGBbuffer malloc failed.\n");
				continue;
			}

			IMGCNV_SOpenParam openParam;
			openParam.width = frameInfo.m_nWidth;
			openParam.height = frameInfo.m_nHeight;
			openParam.paddingX = frameInfo.m_nPaddingX;
			openParam.paddingY = frameInfo.m_nPaddingY;
			openParam.dataSize = frameInfo.m_nBufferSize;
            openParam.pixelForamt = frameInfo.m_ePixelType;

			IMGCNV_EErr status = IMGCNV_ConvertToRGB24(frameInfo.m_pImageBuf, &openParam, pRGBbuffer, &nRgbBufferSize);
			if (IMGCNV_SUCCESS != status)
			{
				/* 释放内存 */
				printf("IMGCNV_ConvertToRGB24 failed.\n");
				free(frameInfo.m_pImageBuf);
				free(pRGBbuffer);
				return;
			}

			/* 释放内存 */
			free(frameInfo.m_pImageBuf);

            //显示线程中发送显示信号,在主线程中显示图像
			emit signalShowImage(pRGBbuffer, openParam.width, openParam.height, openParam.pixelForamt);

		}
	}
}
/**
    *  ~chinese  
	*  @brief  转换为RGB24的转换函数
	*  @param[in] pSrcData		:源数据
	*  @param[in] pOpenParam	:IMGCNV_SOpenParam结构体,格式转换所需要的参数
	*  @param[out]pDstData		:转换后的数据	
	*  @param[out]pDstDataSize	:转换后数据的长度	
	*  @Return:   IMGCNV_ERR_E  : 图像格式转换接口返回值
	*  - IMGCNV_SUCCESS 表示执行成功
	*  - 其他值见IMGCNV_ERR_E枚举
	*  特别说明
	*  像素格式为YUV411Packed的时,图像宽须能被4整除
	*  像素格式为YUV422Packed的时,图像宽须能被2整除
	*  像素格式为YUYVPacked的时,图像宽须能被2整除
	*  转换后的图像:数据存储是从最上面第一行开始的,这个是相机数据的默认存储方向
	*  ~english  
	*  @brief  convert to RGB24
	*  @param[in] pSrcData		:source data
	*  @param[in] pOpenParam	:conversion required paraneters
	*  @param[out]pDstData		:converted data
	*  @param[out]pDstDataSize	:length of converted data 
	*  @Return:   IMGCNV_ERR_E	:return value
	*  - IMGCNV_SUCCESS return ok
	*  - Other values refers to enumeration of IMGCNV_ERR_E 
	*  Special note
	*  pixelFormat:YUV411Packed,the image width is divisible by 4
	*  pixelFormat:YUV422Packed,the image width is divisible by 2
	*  pixelFormat:YUYVPacked,the image width is divisible by 2
	*  converted image:The first row of the image is located at the start of the image buffer.This is the default for image taken by a camera.
	*/
	IMGCNV_API IMGCNV_EErr CALLMETHOD IMGCNV_ConvertToRGB24(unsigned char* pSrcData, IMGCNV_SOpenParam* pOpenParam, unsigned char* pDstData, int* pDstDataSize);

 

你可能感兴趣的:(《Qt》)