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

📄 pinhardware.cpp

📁 三星2440原版bsp
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//

// This file contains all the "virtual" functions that are hardware specific.
// Customizing the driver to a specific hardware should only be a matter of
// changing the functions implemented in this file

#define EXTERN_PROP_VALUES
#include <windows.h>
#include <Msgqueue.h>
#include <pwinbase.h>
#include <camera.h>
#include "CameraDriver.h"
#include "adapterprops.h"
#include "PinDriver.h"
#include "wchar.h"

//#defineoRETAILMSG		RETAILMSG
#define RETAIL_ON		0

#define PREVIEW_X					(240)
#define PREVIEW_Y					(180)
#define PIX_SIZE					(2)		//2 bytes= 16-bit
#define CAM_OUTPUT_SIZE				PREVIEW_X * PREVIEW_Y * PIX_SIZE

#define WHITE_DATA					0xFF	//used for filling up the input buffer in case of any error

CSPROPERTY_BUFFER_MODE CPinDevice::GetCurrentMemoryModel()
{
    return m_dwMemoryModel;
}


DWORD CPinDevice::GetMaxBufferCount()
{
    return MAX_BUFFER_COUNT;
}


ULONG 
CPinDevice ::BufferFill( PUCHAR pImage, PCS_VIDEOINFOHEADER pCsVideoInfoHdr, IMAGECOMMAND Command, bool FlipHorizontal, LPVOID lpParam )
{
	UINT biWidth        	= pCsVideoInfoHdr->bmiHeader.biWidth;
	UINT biHeight       	= pCsVideoInfoHdr->bmiHeader.biHeight;
	UINT biSizeImage    	= pCsVideoInfoHdr->bmiHeader.biSizeImage;
	UINT biWidthBytes   	= CS_DIBWIDTHBYTES (pCsVideoInfoHdr->bmiHeader);
	UINT biBitCount     	= pCsVideoInfoHdr->bmiHeader.biBitCount;
	UINT LinesToCopy    	= abs (biHeight);
	DWORD biCompression = pCsVideoInfoHdr->bmiHeader.biCompression;	

	RETAILMSG(RETAIL_ON,(TEXT("BufferFill -> 0\r")));
	
	//memcpy( pImage, pLineBuffer, biWidthBytes);
	if(CAPTURE == m_ulPinId)
	{
		DWORD dwYSize, dwCSize;

		dwYSize = biWidth * LinesToCopy;
		dwCSize = dwYSize >> 2;		
		
		RETAILMSG(RETAIL_ON,(TEXT("2 ")));		
#if 0	//{
		static DWORD dwYAddress 		= 0;
		static DWORD dwCBAddress 	= 0;
		static DWORD dwCRddress 		= 0;
		static INT nFrameCount = 0;
		RETAILMSG(RETAIL_ON,(TEXT("3 ")));
		PINGPONG camdata;
		m_pCamAdapter->Samsung_camcoder((UCHAR*)&camdata);
		if(1 == camdata.flag)
		{
			SetKMode(TRUE);
			RETAILMSG(1,(TEXT("Frame#%d --> Y = 0x%x, CB = 0x%x, CR = 0x%x\r\n"), ++nFrameCount, camdata.y_address, camdata.cb_address, camdata.cr_address));
			
			memcpy(pImage, (unsigned char*)camdata.y_address, dwYSize);
			memcpy(pImage + dwYSize, (unsigned char*)camdata.cb_address, dwCSize);
			memcpy(pImage + dwYSize + dwCSize, (unsigned char*)camdata.cr_address, dwCSize);

			dwYAddress 	= camdata.y_address;
			dwCBAddress	= camdata.cb_address;
			dwCRddress	= camdata.cr_address;
			
			SetKMode(FALSE);
		}
		else
		{
			RETAILMSG(1,(TEXT("***** Frame not found *****\r\n")));	
			//if there wasn't a valid frame in this call to Samsung_camcoder, 
			//fill in the last frame
			SetKMode(TRUE);
			memcpy(pImage, (unsigned char*)dwYAddress, dwYSize);
			memcpy(pImage + dwYSize, (unsigned char*)dwCBAddress, dwCSize);
			memcpy(pImage + dwYSize + dwCSize, (unsigned char*)dwCRddress, dwCSize);
			SetKMode(FALSE);
		}
#else
		DWORD dwYAddress 		= 0;
		DWORD dwCBAddress 	= 0;
		DWORD dwCRddress 		= 0;
		static INT nFrameCount = 0;
		if(WAIT_OBJECT_0 == WaitForSingleObject(CCameraDevice::m_hCodecData, INFINITE))
		{
			SetKMode(TRUE);
			m_pCamAdapter->GetCurrentCBufferAddress(&dwYAddress, &dwCBAddress, &dwCRddress);

			// 05.08.10 queen
			RETAILMSG(RETAIL_ON,(TEXT("Frame#%d --> dwYAddress = 0x%x, %d; dwCBAddress = 0x%x, %d; dwCRAddress = 0x%x\r\n"),
						++nFrameCount, dwYAddress, dwYSize, dwCBAddress, dwCSize, dwCRddress));	

			/*
			RETAILMSG(1,(TEXT("CIGCTRL= 0x%x, CICOSA1= 0x%x, CICOSA2=0x%x, CISRCFMT=0x%x,
				                         CICOTRGFMT=0x%x, CICOSCPRERATIO=0x%x, CICOSCCTRL=0x%x, CICOSTATUS=0x%x,CIIMGCPT=0x%x\r\n"),
							    m_rS2440CAM->CIGCTRL,m_rS2440CAM->CICOSA1,m_rS2440CAM->CICOSA2,m_rS2440CAM->CISRCFMT,
							    m_rS2440CAM->CICOTRGFMT,m_rS2440CAM->CICOSCPRERATIO,m_rS2440CAM->CICOSCCTRL,m_rS2440CAM->CICOSTATUS,m_rS2440CAM->CIIMGCPT));
			*/
			
			memcpy(pImage, (unsigned char*)dwYAddress, dwYSize);
			memcpy(pImage + dwYSize, (unsigned char*)dwCRddress, dwCSize);
			memcpy(pImage + dwYSize + dwCSize, (unsigned char*)dwCBAddress, dwCSize);
			SetKMode(FALSE);
		}
		else
		{
			RETAILMSG(1, (TEXT("**** Camera codec data wait failed ****")));
			memset(pImage, WHITE_DATA, dwYSize);
			memset(pImage + dwYSize, WHITE_DATA, dwCSize);
			memset(pImage + dwYSize + dwCSize, WHITE_DATA, dwCSize);
		}
#endif	//}		
		RETAILMSG(RETAIL_ON,(TEXT("7 ")));	
	}
	else if(PREVIEW == m_ulPinId)
	{
		RETAILMSG(RETAIL_ON,(TEXT("PREVIEW\r\n")));
		DWORD dwPAddress = 0;
		if(WAIT_OBJECT_0 == WaitForSingleObject(CCameraDevice::m_hPrevData, INFINITE))
		{
			m_pCamAdapter->GetCurrentPBufferAddress(&dwPAddress);
			SetKMode(TRUE);
			memcpy(pImage, (BYTE*)dwPAddress, CAM_OUTPUT_SIZE);
			SetKMode(FALSE);
		}
		else
		{
			RETAILMSG(1,(TEXT("**** Camera preview data wait failed ****")));
			memset(pImage, WHITE_DATA, CAM_OUTPUT_SIZE);
		}
	}
	else
	{
		RETAILMSG(1, (TEXT("\n################ There is a problem !!!!##############\n")));
	}
	
	// return the size of the image filled
	RETAILMSG(RETAIL_ON,(TEXT("\n")));
	return(biSizeImage);

}

/*
UINT
BufferFill( PUCHAR pImage, PCS_VIDEOINFOHEADER pCsVideoInfoHdr, IMAGECOMMAND Command, bool FlipHorizontal, LPVOID lpParam )
{
    UINT biWidth        = pCsVideoInfoHdr->bmiHeader.biWidth;
    UINT biHeight       = pCsVideoInfoHdr->bmiHeader.biHeight;
    UINT biSizeImage    = pCsVideoInfoHdr->bmiHeader.biSizeImage;
    UINT biWidthBytes   = CS_DIBWIDTHBYTES (pCsVideoInfoHdr->bmiHeader);
    UINT biBitCount     = pCsVideoInfoHdr->bmiHeader.biBitCount;
    UINT LinesToCopy    = abs (biHeight);
    DWORD biCompression = pCsVideoInfoHdr->bmiHeader.biCompression;

    UINT   Line;
    PUCHAR pLineBuffer;

    // 
    // Synthesize a single line of image data, which will then be replicated
    //

    pLineBuffer = reinterpret_cast<PUCHAR>( new UCHAR[ biWidthBytes ] ) ;
    if ( NULL == pLineBuffer )
    {
        RETAILMSG(RETAIL_ON, (_T("BufferFill: OOM\r\n"))) ;
        return -1;
    }

    // this controls the value that the buffer is filled with, and the timing between the different pins
    ULONG ulGrayValue = GetTickCount() >> 4;

    if ((biCompression & ~BI_SRCPREROTATE) == CS_BI_BITFIELDS)
    {
        switch (Command)
        {
        case IMAGE_NTSC_EIA_100AMP_100SAT:
            // 100% saturation
            {
                UINT x, col;
                PUCHAR pT = pLineBuffer;
        
                for (x = 0; x < biWidth; x++) 
                {
                    col = (x * 8) / biWidth;
                    col = FlipHorizontal ? (7 - col) : col;
                    
                    *pT++ = NTSCColorBars100Amp100SatRGB24[0][col]; // Red
                    *pT++ = NTSCColorBars100Amp100SatRGB24[1][col]; // Green
                    *pT++ = NTSCColorBars100Amp100SatRGB24[2][col]; // Blue
                }
            }
            break;
    
        case IMAGE_NTSC_EIA_75AMP_100SAT:
            // 75% Saturation
            {
                UINT x, col;
                PUCHAR pT = pLineBuffer;
        
                for (x = 0; x < biWidth; x++) 
                {
                    col = (x * 8) / biWidth;
                    col = FlipHorizontal ? (7 - col) : col;

                    *pT++ = NTSCColorBars75Amp100SatRGB24[0][col]; // Red
                    *pT++ = NTSCColorBars75Amp100SatRGB24[1][col]; // Green
                    *pT++ = NTSCColorBars75Amp100SatRGB24[2][col]; // Blue
                }
            }
            break;
    
        case IMAGE_BLACK:
            // Camma corrected Grayscale ramp
            {
                UINT x, col;
                PUCHAR pT = pLineBuffer;
        
                for (x = 0; x < biWidth; x++) 
                {
                    col = (255 * (x * 10) / biWidth) / 10;
                    col = FlipHorizontal ? (255 - col) : col;

                    *pT++ = (BYTE) col; // Red
                    *pT++ = (BYTE) col; // Green
                    *pT++ = (BYTE) col; // Blue
                }
            }
            break;
    
        case IMAGE_WHITE:
            // All white
            memset( pLineBuffer, (UCHAR) 255, biWidthBytes );
            break;
    
        case IMAGE_GRAY_INCREASING:
            // grayscale increasing with each image captured
            if(biBitCount > 16)
            {
                memset( pLineBuffer, (UCHAR) (ulGrayValue++ * 8), biWidthBytes ) ;
            }
            else if(biBitCount == 16)
            {
                UCHAR uc = (UCHAR) ((ulGrayValue++ * 2) & 0xF8);
                WCHAR wc = (uc << 8) | (uc << 3) | (uc >> 3);
                wmemset((PWCHAR) pLineBuffer, wc, biWidthBytes / 2 );
            }
            else 
            {
                RETAILMSG(RETAIL_ON, (_T("BufferFill: Unknown bit depth in FillBuffer\r\n"))) ;
            }

            break;
    
        default:
            break;
        }
    } // endif RGB24

    else if ((biBitCount == 16) && (biCompression == FOURCC_YUV422))
	{

        switch (Command) {
    
        case IMAGE_NTSC_EIA_100AMP_100SAT:
        default:
            {
                UINT x, col;
                PUCHAR pT = pLineBuffer;
        
                for (x = 0; x < (biWidth / 2); x++) 
                {
                    col = (x * 8) / (biWidth / 2);
                    col = FlipHorizontal ? (7 - col) : col;

                    *pT++ = NTSCColorBars100Amp100SatYUV[0][col]; // U
                    *pT++ = NTSCColorBars100Amp100SatYUV[1][col]; // Y
                    *pT++ = NTSCColorBars100Amp100SatYUV[2][col]; // V
                    *pT++ = NTSCColorBars100Amp100SatYUV[3][col]; // Y
                }
            }
            break;
        }
    } 

    else 
    {
        RETAILMSG(RETAIL_ON, (_T("BufferFill: Unknown Format in FillBuffer\r\n"))) ;
    }

    // 
    // Copy the single line synthesized to all rows of the image
    //

    __try
    {
        for (Line = 0; Line < LinesToCopy; Line++, pImage += biWidthBytes) {

            // Show some action on an otherwise static image
            // This will be a changing grayscale horizontal band
            // at the bottom of an RGB image and a changing color band at the 
            // top of a YUV image

            if (Line >= 3 && Line <= 6)
            {
                if(biBitCount > 16)
                {
                    memset( pImage, (UCHAR) (ulGrayValue), biWidthBytes ) ;
                }
                else if(biBitCount == 16)
                {
                    UCHAR uc = (UCHAR) ((ulGrayValue) & 0xF8);
                    WCHAR wc = (uc << 8) | (uc << 3) | (uc >> 3);
                    wmemset((PWCHAR) pImage, wc, biWidthBytes/2);
                }
                else 
                {
                    RETAILMSG(RETAIL_ON, (_T("BufferFill: Unknown bit depth in FillBuffer\r\n"))) ;
                }
                continue;
            }

            // Copy the synthesized line

            memcpy( pImage, pLineBuffer, biWidthBytes);
        }
    }
    __except ( EXCEPTION_EXECUTE_HANDLER )
    {
    }

    // free our single line temporary buffer now that the primary buffer is populated
    if ( NULL != pLineBuffer )
        delete[] pLineBuffer ;

    // return the size of the image filled
    return(biSizeImage);

}
*/

⌨️ 快捷键说明

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