⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capture1.cpp

📁 rfid在wince的平台的驱动
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "stdafx.h"
#include "capture1.h"

#define DISPLAY_PIC

static PVOID VirtualAllocCopy(unsigned size,char *str,PVOID pVirtualAddress);

#define AUTO_ADJUST			//for sensor auto adjust(AGC, AEC)
#define FULL_CAPTURE_SIZE	//for 640*320
//#define RESIZE_SCREEN		//缩放
#define LEFT_SPACE_LINE		(CameraApp.StillWidth-XllpOverlay.OverlayWidth)/2
#define TOP_SPACE_LINE		(CameraApp.StillHeight-XllpOverlay.OverlayHeight)/2


#define QUERYESCSUPPORT				8
// OEM escape code base
#define ESCAPECODEBASE			100000
#define DISPLAYPAGE				(ESCAPECODEBASE + 1)
#define GETPALETTERAMPHYSICAL	(ESCAPECODEBASE + 2)
#define VERTICALBLANKINTERRUPT	(ESCAPECODEBASE + 3)
#define OS_SCREENACCESS			(ESCAPECODEBASE + 4)
#define SCROLL					(ESCAPECODEBASE + 5)
#define OVERLAY2_ENABLE			(ESCAPECODEBASE + 6)
#define OVERLAY2_DISABLE		(ESCAPECODEBASE + 7)
#define OVERLAY1_ENABLE			(ESCAPECODEBASE + 8)
#define OVERLAY1_DISABLE		(ESCAPECODEBASE + 9)
#define GET_OVERLAY1_ADDRESS	(ESCAPECODEBASE + 10)
#define GET_OVERLAY2_ADDRESS	(ESCAPECODEBASE + 11)
#define CAMERA_INITIALIZE		(ESCAPECODEBASE + 12)
#define CAMERA_START_VIDEO_CAPTURE	(ESCAPECODEBASE + 13)
#define CAMERA_STOP_VIDEO_CAPTURE	(ESCAPECODEBASE + 14)
#define CAMERA_RELEASE_FRAME	(ESCAPECODEBASE + 15)
#define CAMERA_SENSOR_IOCTL		(ESCAPECODEBASE + 16)
#define CAMERA_DEINIT			(ESCAPECODEBASE + 17)

// Use the following for configuring YUV overlay format
#define FORMAT_RGB			0x0
#define FORMAT_PACKED_444	0x1
#define FORMAT_PLANAR_444	0x2
#define FORMAT_PLANAR_422	0x3
#define FORMAT_PLANAR_420	0x4
#define FORMAT_RAW_8		0x5

// sensor ioctl
#define LIGHT_CONTROL		0x01
#define WSIZE_CONTROL		0x02
#define REGISTER_CONTROL	0x03
#define CISIZE_CONTROL		0x81
//light control data bit
#define FOC_BIT	(1<<0)
#define LEC_BIT	(1<<1)

#define CAMERA_EVENT_NAME  _T("CameraFrameComplete")

// Use the following for overlay values
#define O_BPP_4				0x2
#define O_BPP_8 			0x3
#define O_BPP_16 			0x4
#define O_BPP_18 			0x5
#define O_BPP_18_PACKED 	0x6
#define O_BPP_19 			0x7
#define O_BPP_19_PACKED		0x8
#define O_BPP_24 			0x9
#define O_BPP_25 			0xA

typedef struct
{
	unsigned long OverlayHeight;	// app fills this in
	unsigned long OverlayWidth;		// app fills this in
	unsigned long X_Position;		// app fills this in
	unsigned long Y_Position;		// app fills this in
	unsigned long Format;			// app fills this in
	unsigned long DegradeBaseFrame; // app fills this in
	unsigned long CH2_Y;			// driver fills this in
	unsigned long CH3_Cb;			// driver fills this in
	unsigned long CH4_Cr;			// driver fills this in
	unsigned long OverlayBPP;		// driver fills this in
	unsigned long TmpBPP;			// driver fills this in
	unsigned long ch2_size;			// driver fills this in
	unsigned long ch3_size;			// driver fills this in
	unsigned long ch4_size;			// driver fills this in
} XLLP_OVERLAY_T, *P_XLLP_OVERLAY_T;


#define MAX_FRAMES 3

typedef struct
{
	unsigned long VideoWidth;		// app fills this in
	unsigned long VideoHeight;		// app fills this in
	unsigned long StillWidth;		// app fills this in
	unsigned long StillHeight;		// app fills this in
	unsigned long CaptureFormat;	// app fills this in
	unsigned long FrameRate;		// app fills this in
	void *ring_buffer_address[MAX_FRAMES]; // driver fills this in
	BOOL	 bFrame_available;		// driver maintains this
	unsigned long frame_nums;		// driver fills this when init
} CAMERA_APP_T, *P_CAMERA_APP_T;
#ifdef DISPLAY_PIC
static XLLP_OVERLAY_T XllpOverlay;
#endif
static CAMERA_APP_T CameraApp;

static BOOL bCapturingVideo = FALSE;
static BOOL bPauseCapture = FALSE;
static BOOL bscale=FALSE;
#ifdef DISPLAY_PIC
static PBYTE	pOverlay2_Y = NULL;
static PBYTE	pOverlay2_Cb = NULL;
static PBYTE	pOverlay2_Cr = NULL;
#endif
static unsigned int frameCount = 0;

static void *ring_buffer_address[MAX_FRAMES];
static HANDLE hEvent = NULL;
static HDC hDC;
static HANDLE hContinueEvent = NULL;
static HANDLE hPausedEvent = NULL;

static int inited = 0;
static int started = 0;

// "Start video capture"
void SetScale(BOOL bs)
{
	bscale = bs;
}
void CameraCaptureThread(long *p)
{
	int cbInput, cbOutput;
	cbInput = sizeof(XLLP_OVERLAY_T);
	cbOutput = 0;

	//CeSetThreadPriority(GetCurrentThread(), 1);

	bCapturingVideo = TRUE;
 
	// The driver has filled in the ring_buffer_address[] to use
	// Now we can start video capture and wait to be signalled to start processing buffers
	// The camera driver has created an event specified by CAMERA_EVENT_NAME.
	// Each time this event is signalled, that means we have at least one new frame of video to process.
	// Because the application processing of the frame is inherently asynchronous to the actual frame capture,
	// a ring buffer is used to store the video frames in order to buffer the data source from the data sink.
	// Because the image acquisition may run faster than our application's ability to process the frames,
	// we need to see if more than one frame is available to us each time we are signalled.
#ifdef DISPLAY_PIC
	memset(pOverlay2_Y, 0, XllpOverlay.ch2_size);
	memset(pOverlay2_Cb, 0x80, XllpOverlay.ch3_size);
	memset(pOverlay2_Cr, 0x80, XllpOverlay.ch4_size);
#endif

	// Give command to start video capture
	//DEBUGMSG(1,(TEXT("ExtEscape start thread\r\n")));
	ExtEscape(hDC, CAMERA_START_VIDEO_CAPTURE, cbInput, (LPCSTR)&CameraApp, cbOutput, NULL);
	while(bCapturingVideo)
	{
		//DEBUGMSG(1,(TEXT("capture thread: before wait event\r\n")));
		WaitForSingleObject(hEvent, INFINITE);
		//DEBUGMSG(1,(TEXT("capture thread: got event\r\n")));
		// Received notification that a frame is ready, let's do something with it.
		// Read out all frames that are waiting in the buffer ( while bFrame_available )
		
		do
		{
			//DEBUGMSG(1,(TEXT("capture thread: copy frame\r\n")));
			// Copy a frame to the YCrCb overlay to display it, or MPEG compress it and stuff it out the network, or...
			//
#ifdef FULL_CAPTURE_SIZE
/*	#ifdef RESIZE_SCREEN			//缩放
			unsigned char * src;
			src = (unsigned char*)(ring_buffer_address[frameCount]);
			SeePic(src);
	#else
			unsigned int i;
			unsigned char * src, * dst;
			src = (unsigned char*)(ring_buffer_address[frameCount]) + ((CameraApp.VideoHeight-XllpOverlay.OverlayHeight)/2)*CameraApp.VideoWidth + ((CameraApp.VideoWidth-XllpOverlay.OverlayWidth)/2);
			dst = pOverlay2_Y;
			for(i=0; i< XllpOverlay.OverlayHeight; i++) {
				memcpy(dst, src, XllpOverlay.OverlayWidth);
				src += CameraApp.VideoWidth;
				dst += XllpOverlay.OverlayWidth;
			}
	#endif
	*/
#ifdef DISPLAY_PIC
			unsigned int i;
			unsigned char * dst;
#endif
			unsigned char * src;
			if (bscale)
			{
				src = (unsigned char*)(ring_buffer_address[frameCount]);
				SeePic(src);
			}
			else
			{
#ifdef DISPLAY_PIC
				src = (unsigned char*)(ring_buffer_address[frameCount]) + ((CameraApp.VideoHeight-XllpOverlay.OverlayHeight)/2)*CameraApp.VideoWidth + ((CameraApp.VideoWidth-XllpOverlay.OverlayWidth)/2);
				dst = pOverlay2_Y;
				for(i=0; i< XllpOverlay.OverlayHeight; i++) {
					memcpy(dst, src, XllpOverlay.OverlayWidth);
					src += CameraApp.VideoWidth;
					dst += XllpOverlay.OverlayWidth;
				}
#endif
			}
#else
#ifdef DISPLAY_PIC
			memcpy(pOverlay2_Y,  ring_buffer_address[frameCount], XllpOverlay.ch2_size);
#endif
#endif
			//memcpy(pOverlay2_Cb, (void *)((BYTE *)ring_buffer_address[frameCount] + XllpOverlay.ch2_size), XllpOverlay.ch3_size);
			//memcpy(pOverlay2_Cr, (void *)((BYTE *)ring_buffer_address[frameCount] + XllpOverlay.ch2_size + XllpOverlay.ch3_size), XllpOverlay.ch4_size);

			if(bPauseCapture) {
				SetEvent(hPausedEvent);
				WaitForSingleObject(hContinueEvent, INFINITE);
			}

			// Now release this frame back to the buffer pool.
			ExtEscape(hDC, CAMERA_RELEASE_FRAME, cbInput, (LPCSTR)&CameraApp, cbOutput, NULL);

			// maintain the frame counter
			frameCount = (frameCount + 1) % CameraApp.frame_nums;

		} while(CameraApp.bFrame_available);
	}
	DEBUGMSG(1,(TEXT("exit thread and stop\r\n")));
	// call the stop capture function... bCapturingVideo set externally to this function
	ExtEscape(hDC, CAMERA_STOP_VIDEO_CAPTURE, cbInput, (LPCSTR)&CameraApp, cbOutput, NULL);

}

void lightcontrol(int foc, int lec)
{
	int cbInput, cbOutput;
	DWORD cmd[2];
	int status;

	cbInput = sizeof(cmd);
	cmd[0] = LIGHT_CONTROL;
	cmd[1] = 0;
	if(foc)	cmd[1] |= FOC_BIT;
	if(lec)	cmd[1] |= LEC_BIT;
	cbOutput = 0;
	status = ExtEscape(hDC, CAMERA_SENSOR_IOCTL, cbInput, (LPCSTR)cmd, cbOutput, NULL);
	if(status <= 0)
		ERRORMSG(1,(TEXT("light control return fail, 0x%x(0x%x)\r\n"), status, GetLastError()));
}

void wsizecontrol()
{
	int cbInput, cbOutput;
	DWORD cmd[2];
	int status;

	cbInput = sizeof(cmd);
	cmd[0] = WSIZE_CONTROL;
	cmd[1] = (0x1a) | (0xba <<8) | (0x03 <<16) | (0xf3 << 24);
	cbOutput = 0;
	status = ExtEscape(hDC, CAMERA_SENSOR_IOCTL, cbInput, (LPCSTR)cmd, cbOutput, NULL);
	if(status <= 0)
		ERRORMSG(1,(TEXT("wsize control return fail, 0x%x(0x%x)\r\n"), status, GetLastError()));
}

void cisizecontrol()
{
	int cbInput, cbOutput;
	DWORD cmd[2];
	int status;

	cbInput = sizeof(cmd);
	cmd[0] = CISIZE_CONTROL;	//just for test
	cmd[1] = (124) | (0 << 8);
	cbOutput = 0;
	status = ExtEscape(hDC, CAMERA_SENSOR_IOCTL, cbInput, (LPCSTR)cmd, cbOutput, NULL);
	if(status <= 0)
		ERRORMSG(1,(TEXT("cisize control return fail, 0x%x(0x%x)\r\n"), status, GetLastError()));
}

void writeregister(unsigned int offset, unsigned int value)
{
	int cbInput, cbOutput;
	DWORD cmd[2];
	int status;

	cbInput = sizeof(cmd);
	cmd[0] = REGISTER_CONTROL;
	cmd[1] = (offset &0xFF) | ((value & 0xFF)<<8);
	cbOutput = 0;
	status = ExtEscape(hDC, CAMERA_SENSOR_IOCTL, cbInput, (LPCSTR)cmd, cbOutput, NULL);
	if(status <= 0)
		ERRORMSG(1,(TEXT("register return fail, 0x%x(0x%x)\r\n"), status, GetLastError()));
}

#define W(r, v)		writeregister(r, v)
void setregisters()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -