嵌入式专题: S5PV210: 用FIMC进行图像转换

三星的设计人员不知道怎么想的,它里面的图像格式是恐怖的NV12T,这种莫名其妙的格式。要说是NV12还稍微可以是解,但是NV12T就太变态了。各种处理都不方便的。<p>它的FIMC硬件是可以转换图片的,虽然可以转换,但还是很难受的。因为FIMC需要提供物理内存,用虚拟内存不行。所以又得借用它的s3c-mem这个设备。</p><p> </p><p>这个话题有点小众,就直接贴代码吧。</p>
 
#ifndef _HW_IMAGE_CONV_H
#define _HW_IMAGE_CONV_H

#include "../s3c/S3CMem.h"
#include "../s3c/SecFimc.h"

class HwImageConv
{
public:
	HwImageConv();
	~HwImageConv();

	int Open();
	void Close();

	int Convert();

public:
	char* inbuf_vir, *outbuf_vir;
	char* inbuf_phy, *outbuf_phy;
	int   inlen, outlen;

private:
	s3c_mem_alloc m_addr;
	SecFimc m_fimc;
	S3CMem  m_memtool;
};



#endif


#include <stdio.h>
#include <string.h>
#include "HwImageConv.h"

HwImageConv::HwImageConv()
{
	inbuf_vir = NULL;
	
}

HwImageConv::~HwImageConv()
{
	Close();
}

int HwImageConv::Open()
{
	if(m_memtool.open() < 0)
	{
		printf("failed to use s3c-mem!\n");
		return -1;
	}

	m_addr.size = 640*480 * 4;
	if(m_memtool.aquire(&m_addr) < 0)
	{
		printf("failed to acquire memory.\n");
		return -1;
	}

	// 得到物理地址与虚拟地址
	inlen  = 640 * 480 * 2;   // YUYV
	outlen = 640 * 480 * 3/2; // NV12
	inbuf_phy = (char*)m_addr.phy_addr;
	inbuf_vir = (char*)m_addr.vir_addr;
	outbuf_phy = inbuf_phy + inlen;
	outbuf_vir = inbuf_vir + inlen;
	printf("inbuf_phy: %08X, inbuf_vir: %08X \n",
		inbuf_phy, inbuf_vir);

	// FIMC转换格式
	if(! m_fimc.create(SecFimc::FIMC_DEV0, 0, 1) )
	{
		printf("failed to create ..\n");
		return -1;
	}

	// 格式
	printf("set format ... \n");
	unsigned int width  = 640;
	unsigned int height = 480;
	unsigned int cropWidth = width, cropHeight= height;
	m_fimc.setSrcParams(width, height, 0, 0, &cropWidth, &cropHeight,
		HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_I);
	m_fimc.setDstParams(width, height, 0, 0, &cropWidth, &cropHeight,
		// HAL_PIXEL_FORMAT_YCbCr_420_P  // YUV420
		HAL_PIXEL_FORMAT_YCrCb_420_SP  // NV12
		);

	printf("set phy address \n");
	// 地址
	m_fimc.setSrcPhyAddr((unsigned int)inbuf_phy);
	m_fimc.setDstPhyAddr((unsigned int)outbuf_phy);

	return 0;
}

void HwImageConv::Close()
{
	if(inbuf_vir != NULL)
	{
		inbuf_vir = NULL;
		m_memtool.release(&m_addr);

		m_memtool.close();
		m_fimc.destroy();		
	}

}

int HwImageConv::Convert()
{
	if(! m_fimc.handleOneShot())
		return -1;
	return 0;
}




 

 

你可能感兴趣的:(嵌入式专题: S5PV210: 用FIMC进行图像转换)