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

📄 digicam pocket pc.cpp

📁 intel xscale pxa270的完整wince4.2 BSP包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DigiCam Pocket PC.cpp : Defines the entry point for the application.
//

#include <windows.h>
#include <windowsx.h>
#include <aygshell.h>
#include "resource.h"

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

HINSTANCE g_hInst = NULL;  // Local copy of hInstance

#define ARRAYSIZE(a)   (sizeof(a)/sizeof(*a))

const TCHAR* g_szAppWndClass = TEXT("DigiCam");

TCHAR g_szMessage[30];

#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)

// 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 CAMERA_EVENT_NAME  _T("CameraFrameComplete")

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
} CAMERA_APP_T, *P_CAMERA_APP_T;

XLLP_OVERLAY_T XllpOverlay;
CAMERA_APP_T CameraApp;

BOOL bDegraded=FALSE;
BOOL bCapturingVideo = FALSE;
unsigned char *fbpY;
unsigned char *fbpCr;
unsigned char *fbpCb;
PBYTE	pOverlay2_Y = NULL;
PBYTE	pOverlay2_Cb = NULL;
PBYTE	pOverlay2_Cr = NULL;
unsigned int frameCount = 0;

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

// "Start video capture"
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.
	if (hEvent)
	{
		// Give command to start video capture
		ExtEscape(hDC, CAMERA_START_VIDEO_CAPTURE, cbInput, (LPCSTR)&CameraApp, cbOutput, NULL);
		while(bCapturingVideo)
		{
			WaitForSingleObject(hEvent, INFINITE);
			// 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
			{
				// Copy a frame to the YCrCb overlay to display it, or MPEG compress it and stuff it out the network, or...
				memcpy(fbpY,  ring_buffer_address[frameCount], XllpOverlay.ch2_size);
				memcpy(fbpCb, (void *)((BYTE *)ring_buffer_address[frameCount] + XllpOverlay.ch2_size), XllpOverlay.ch3_size);
				memcpy(fbpCr, (void *)((BYTE *)ring_buffer_address[frameCount] + XllpOverlay.ch2_size + XllpOverlay.ch3_size), XllpOverlay.ch4_size);

				// 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) % MAX_FRAMES;

			} while(CameraApp.bFrame_available);
		}
		// call the stop capture function... bCapturingVideo set externally to this function
		ExtEscape(hDC, CAMERA_STOP_VIDEO_CAPTURE, cbInput, (LPCSTR)&CameraApp, cbOutput, NULL);
	} 
}

void StartCapture()
{
	HANDLE	hthrd;

	int cbInput, cbOutput;

	cbInput = 0;
	cbOutput = 0;

	cbInput = sizeof(XLLP_OVERLAY_T);

	if (bCapturingVideo == FALSE)
	{
		ExtEscape(hDC, OVERLAY2_ENABLE, cbInput, (LPCSTR)&XllpOverlay, cbOutput, NULL);

		hthrd = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)CameraCaptureThread,NULL,0,NULL);
		CloseHandle(hthrd);
	}
}

void StopCapture()
{
	int cbInput, cbOutput;

	cbInput = 0;
	cbOutput = 0;

	cbInput = sizeof(XLLP_OVERLAY_T);

	// can't disable when the L clk is too high
	ExtEscape(hDC, OVERLAY2_DISABLE, cbInput, (LPCSTR)&XllpOverlay, cbOutput, NULL);

	bCapturingVideo = FALSE;
}

/**************************************************************************************

   OnCreate

 **************************************************************************************/
LRESULT OnCreate(
    HWND hwnd,
    CREATESTRUCT* lParam
    )
{
    // create the menu bar
    SHMENUBARINFO mbi;
    ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
    mbi.cbSize = sizeof(SHMENUBARINFO);
    mbi.hwndParent = hwnd;
    mbi.nToolBarId = IDR_HELLO_MENUBAR;
    mbi.hInstRes = g_hInst;

    if(!SHCreateMenuBar(&mbi))
    {
        // Couldn't create the menu bar.  Fail creation of the window.
        return(-1);
    }

    // Get our message text.
    if(0 == LoadString(g_hInst, IDS_START, g_szMessage, ARRAYSIZE(g_szMessage)))
    {
        // Couldn't load the string.  Fail creation of the window.
        return(-1);
    }

	int cbInput, cbOutput, i;
	cbInput = sizeof(XLLP_OVERLAY_T);
	cbOutput = 0;
	hDC = CreateDC(NULL, NULL, NULL, NULL);

	// Fill in the overlay parameters, then query for the dynamic address of the overlay channels
	XllpOverlay.OverlayWidth = 144;
	XllpOverlay.OverlayHeight = 176;
	XllpOverlay.X_Position = (240 - XllpOverlay.OverlayWidth) / 2;
	XllpOverlay.Y_Position = 25;
	XllpOverlay.Format = FORMAT_PLANAR_422;
	XllpOverlay.DegradeBaseFrame = bDegraded;

	ExtEscape(hDC, GET_OVERLAY2_ADDRESS, cbInput, (LPCSTR)&XllpOverlay, cbOutput, NULL);

	// Copy YUV data to buffers pointed to by .CH2, .CH3, .CH4 (addresses filled in by video driver)
	pOverlay2_Y = (PBYTE)VirtualAllocCopy(320*240,"pOverlay2_Y",(PVOID)(XllpOverlay.CH2_Y));
	pOverlay2_Cb = (PBYTE)VirtualAllocCopy(320*240,"pOverlay2_Cb",(PVOID)(XllpOverlay.CH3_Cb));
	pOverlay2_Cr = (PBYTE)VirtualAllocCopy(320*240,"pOverlay2_Cr",(PVOID)(XllpOverlay.CH4_Cr));

	fbpY=(unsigned char  *)pOverlay2_Y;
	fbpCb=(unsigned char  *)pOverlay2_Cb;
	fbpCr=(unsigned char  *)pOverlay2_Cr;

	cbInput = sizeof(XLLP_OVERLAY_T);


	CameraApp.VideoWidth = XllpOverlay.OverlayWidth;
	CameraApp.VideoHeight = XllpOverlay.OverlayHeight;
	CameraApp.StillWidth = 640;
	CameraApp.StillHeight = 480;
	CameraApp.CaptureFormat = FORMAT_PLANAR_422;
	CameraApp.FrameRate = 0; // 0 = max frame rate available
	
	// Initialize the Camera with our settings
	cbInput = sizeof(CAMERA_APP_T);
	ExtEscape(hDC, CAMERA_INITIALIZE, cbInput, (LPCSTR)&CameraApp, cbOutput, NULL);

	for (i = 0; i < MAX_FRAMES; i++)
	{
		ring_buffer_address[i] = (void *)VirtualAllocCopy(CameraApp.VideoWidth * CameraApp.VideoHeight * 2 ,"ringbuffer",(PVOID)(CameraApp.ring_buffer_address[i]));
	}

	// capture thread waits on this event for each frame
	hEvent = CreateEvent(NULL, FALSE, FALSE, CAMERA_EVENT_NAME);

⌨️ 快捷键说明

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