int GetDepthGrHandle(void){
::WaitForSingleObject( m_DepthEvent, INFINITE );
// カメラデータの取得
NUI_IMAGE_FRAME depthFrame;
HRESULT hr = m_pNuiSensor->NuiImageStreamGetNextFrame( m_DepthStreamHandle, 0, &depthFrame );
if ( FAILED( hr ) ) return -1;
// 画像データの取得
INuiFrameTexture * pTextureDepth = depthFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRectDepth;
pTextureDepth->LockRect( 0, &LockedRectDepth, NULL, 0 );
// 初期色
if( GetDepthGrHandleOption.FillTransColor == true ){
int r,g,b;
GetTransColor(&r, &g, &b);
FillSoftImage(softhandle, r,g,b,0);
}else{
FillSoftImage(softhandle, 0,0,0,0);
}
if ( LockedRectDepth.Pitch != 0 ){
// draw the bits to the bitmap
USHORT * pBufferRun = (USHORT *)LockedRectDepth.pBits; // 深度データの取り込み?
USHORT RealDepth; // 深度情報
USHORT Player; // プレイヤーID情報
LONG nx, ny;
BYTE R,G,B;
for(int y=0; BaseDepthImage.Height > y; y++){
for(int x=0; BaseDepthImage.Width > x; x++){
// 深度情報0の領域は描画しない
if(GetDepthGrHandleOption.EnableZeroDepth == false){
if(*pBufferRun == 0){
++pBufferRun;
continue;
}
}
RealDepth = NuiDepthPixelToDepth(*pBufferRun);
Player = NuiDepthPixelToPlayerIndex(*pBufferRun);
BYTE intensity = (BYTE)~(RealDepth >> 5); // 13bit → 8bit (+反転)
// プレイヤー以外の深度情報は無視
if(GetDepthGrHandleOption.DrawBackGround == false){
if(Player == 0){
++pBufferRun;
continue;
}
}
// ズレ補正
if(GetDepthGrHandleOption.EnableCorrection == true){
hr = ::NuiImageGetColorPixelCoordinatesFromDepthPixelAtResolution(NUI_IMAGE_RESOLUTION_640x480,
NUI_IMAGE_RESOLUTION_640x480,
NULL,
x, y, // coordinate in depth image space
0, // The depth value in depth image space.
&nx, &ny);
if( hr != S_OK ){
++pBufferRun;
continue;
}
}else{
nx = x;
ny = y;
}
// プレイヤーに色を付ける
if(GetDepthGrHandleOption.ColorPlayer == true){
R = intensity >> g_IntensityShiftByPlayerR[Player];
G = intensity >> g_IntensityShiftByPlayerG[Player];
B = intensity >> g_IntensityShiftByPlayerB[Player];
}else{
R = intensity;
G = intensity;
B = intensity;
}
DrawPixelSoftImage(softhandle, nx, ny,R, G, B, 0);
++pBufferRun;
}
}
}
else{
OutputDebugString( "Buffer length of received texture is bogus\r\n" );
}
// 前のグラフィックハンドルを削除する
DeleteGraph(DepthGrHandle);
// CPUで扱うイメージからグラフィックハンドルを作成する
DepthGrHandle = CreateGraphFromSoftImage(softhandle);
// カメラデータの解放
pTextureDepth->UnlockRect( 0 );
m_pNuiSensor->NuiImageStreamReleaseFrame( m_DepthStreamHandle, &depthFrame );
return DepthGrHandle;
}
|