static int planarToNv12Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
                               int srcSliceH, uint8_t* dstParam[], int dstStride[])
{
    uint8_t *dst = dstParam[1] + dstStride[1]*srcSliceY/2;

    copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
              dstParam[0], dstStride[0]);

    if (c->dstFormat == PIX_FMT_NV12)
        interleaveBytes(src[1], src[2], dst, c->srcW/2, srcSliceH/2, srcStride[1], srcStride[2], dstStride[0]);
    else
        interleaveBytes(src[2], src[1], dst, c->srcW/2, srcSliceH/2, srcStride[2], srcStride[1], dstStride[0]);

    return srcSliceH;
}
    void CVideoRendererDX9::RenderFrame( void* pData )
    {
        if ( pData )
        {
            // if no img then frame was dropped

#if defined(USE_SEPERATEMEMORY)
            vpx_image_t* img = ( vpx_image_t* )pData;
            SAlphaGenParam ap;
            YV12_2_TEX( img->planes[VPX_PLANE_Y], img->planes[VPX_PLANE_U], img->planes[VPX_PLANE_V], NULL, m_nSourceWidth, m_nSourceHeight, ( uint32_t* ) m_pData, m_nSourceWidth, img->stride[VPX_PLANE_Y], img->stride[VPX_PLANE_V], img->stride[VPX_PLANE_U], 0, ap );
            //YV12_2_TEX( img->planes[VPX_PLANE_Y], img->planes[VPX_PLANE_U], img->planes[VPX_PLANE_V], img->planes[VPX_PLANE_Y], m_nSourceWidth, m_nSourceHeight, ( uint32_t* ) m_pData, m_nSourceWidth, img->stride[VPX_PLANE_Y], img->stride[VPX_PLANE_V], img->stride[VPX_PLANE_U], img->stride[VPX_PLANE_Y], ap );
            m_bDirty = true;
#else
            D3DLOCKED_RECT LockedRect;
            memset( &LockedRect, 0, sizeof( LockedRect ) );

            if ( m_pTex )
            {
                // Rendertarget is present
                IDirect3DSurface9* surfaceTemp = NULL;
                HRESULT hr = m_pTex->GetSurfaceLevel( 0, &surfaceTemp );

                if ( SUCCEEDED( hr ) && surfaceTemp )
                {
                    if ( m_pSurfaceYUV )
                    {
                        // Hardware YUV Conversion:
                        // YV12 source -> copyPlane -> YV12 surface -> StretchRect -> X8R8G8B8 render target surface
                        hr = m_pSurfaceYUV->LockRect( &LockedRect, NULL, USE_DISCARD );

                        if ( SUCCEEDED( hr ) )
                        {
                            unsigned char* pPict = ( unsigned char* ) LockedRect.pBits; // Pointer to the locked bits.

                            if ( pPict )
                            {
                                vpx_image_t* img = ( vpx_image_t* )pData;

                                // divisible by RESBASE (ATI YUV hardware conversion compatible)
                                unsigned int w = ( img->d_w >> RESBASE ) << RESBASE;
                                unsigned int h = ( img->d_h >> RESBASE ) << RESBASE;
                                unsigned int w2 = w >> 1;
                                unsigned int h2 = h >> 1;

                                pPict = copyPlane( w,    h,  pPict, LockedRect.Pitch,        img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y] );
                                pPict = copyPlane( w2,   h2, pPict, LockedRect.Pitch >> 1,   img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V] );
                                pPict = copyPlane( w2,   h2, pPict, LockedRect.Pitch >> 1,   img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U] );
                            }

                            m_pSurfaceYUV->UnlockRect();

                            if ( pPict )
                            {
                                hr = m_pD3DDevice->StretchRect( m_pSurfaceYUV, NULL, surfaceTemp, NULL, D3DTEXF_POINT );
                            }
                        }
                    }

                    else if ( m_pStagingSurface )
                    {
                        hr = m_pStagingSurface->LockRect( &LockedRect, NULL, USE_DISCARD );

                        if ( SUCCEEDED( hr ) )
                        {
                            unsigned char* pPict = ( unsigned char* ) LockedRect.pBits; // Pointer to the locked bits.

                            if ( pPict )
                            {
                                vpx_image_t* img = ( vpx_image_t* )pData;

                                // divisible by RESBASE (ATI YUV hardware conversion compatible)
                                unsigned int w = ( img->d_w >> RESBASE ) << RESBASE;
                                unsigned int h = ( img->d_h >> RESBASE ) << RESBASE;

                                SAlphaGenParam ap;
                                YV12_2_TEX( img->planes[VPX_PLANE_Y], img->planes[VPX_PLANE_U], img->planes[VPX_PLANE_V], NULL, w, h, ( uint32_t* ) pPict, LockedRect.Pitch >> 2, img->stride[VPX_PLANE_Y], img->stride[VPX_PLANE_V], img->stride[VPX_PLANE_U], 0, ap );
                            }

                            m_pStagingSurface->UnlockRect();

                            if ( pPict )
                            {
#if defined(USE_UPDATE_SURFACE)
                                hr = m_pD3DDevice->UpdateSurface( m_pStagingSurface, NULL, surfaceTemp, NULL );
#else
                                hr = m_pD3DDevice->StretchRect( m_pStagingSurface, NULL, surfaceTemp, NULL, D3DTEXF_POINT );
#endif
                            }
                        }
                    }
                }

                if ( FAILED( hr ) )
                {
                    outputError( hr );
                }

                SAFE_RELEASE( surfaceTemp );
            }

#endif
        }
示例#3
0
int testPlane() {
	int numErr = 0;

	logMessage(_T("TESTING  -  class GM_3dPlane ...\n\n"));

	// Default constructor, plane must be invalid
	GM_3dPlane p;
	if (p.isValid()) {
		logMessage(_T("\tERROR - Default constructor creates valid plane\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Default constructor creates invalid plane\n"));
	}

	// Constructor (coeff)
	GM_3dPlane p1(getRandomDouble(), getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dPlane pNull(0.0, 0.0, 0.0, getRandomDouble());
	if (!p1.isValid() || pNull.isValid()) {
		logMessage(_T("\tERROR - Coeff. constructor not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Coeff. constructor working\n"));
	}

	// Copy constructor
	GM_3dPlane copyPlane(p1);
	if (!copyPlane.isValid() || copyPlane != p1) {
		logMessage(_T("\tERROR - Copy constructor not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Copy constructor working\n"));
	}

	// Constructor (coeff vector)
	double pointsVect[4];
	for (int i = 0 ; i < 4 ; i++) {
		pointsVect[i] = getRandomDouble();
	}
	GM_3dPlane p2(pointsVect);
	if (!p2.isValid()) {
		logMessage(_T("\tERROR - Coeff. vector constructor not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Coeff. vector constructor working\n"));
	}

	// Constructor (points)
	GM_3dPoint pt1(getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dPoint pt2(getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dPoint pt3(getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dLine ln(getRandomDouble(), getRandomDouble(), getRandomDouble(),getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dPoint ptLn1 = ln.begin();
	GM_3dPoint ptLn2 = ln.center();
	GM_3dPoint ptLn3 = ln.end();
	GM_3dPlane p3(pt1, pt2, pt3);
	GM_3dPlane pLine(ptLn2, ptLn2, ptLn3);
	double distPt1 = pt1.x()*p3[0] + pt1.y()*p3[1] + pt1.z()*p3[2] + p3[3];
	double distPt2 = pt2.x()*p3[0] + pt2.y()*p3[1] + pt2.z()*p3[2] + p3[3];
	double distPt3 = pt3.x()*p3[0] + pt3.y()*p3[1] + pt3.z()*p3[2] + p3[3];
	if (!p3.isValid() || pLine.isValid() || fabs(distPt1) > GM_NULL_TOLERANCE || fabs(distPt2) > GM_NULL_TOLERANCE || fabs(distPt3) > GM_NULL_TOLERANCE) {
		logMessage(_T("\tERROR - Points constructor not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Points constructor working\n"));
	}

	// Point distance
	GM_3dPlane p4(getRandomDouble(), getRandomDouble(), getRandomDouble(),getRandomDouble());
	GM_3dPoint checkPoint(getRandomDouble(), getRandomDouble(), getRandomDouble());
	if (fabs(p4[0]) > GM_NULL_TOLERANCE) {
		checkPoint.x(-(checkPoint.y()*p4[1] + checkPoint.z()*p4[2] + p4[3]) / p4[0]);
	}
	else if (fabs(p4[1]) > GM_NULL_TOLERANCE) {
		checkPoint.y(-(checkPoint.x()*p4[0] + checkPoint.z()*p4[2] + p4[3]) / p4[1]);
	}
	else if (fabs(p4[2]) > GM_NULL_TOLERANCE) {
		checkPoint.z(-(checkPoint.x()*p4[0] + checkPoint.y()*p4[1] + p4[3]) / p4[2]);
	}
	else {
		p4.invalidate();
	}
	double checkSignedDist = getRandomDouble();
	double checkDist = fabs(checkSignedDist);
	GM_3dVector p4Norm = p4.normalVector();
	checkPoint = (GM_3dVector)checkPoint + (p4Norm * checkSignedDist);
	GM_3dPoint checkPointOnPlane1;
	GM_3dPoint checkPointOnPlane2;
	double dist = p4.pointDistance(checkPoint);
	double signedDist = p4.pointDistanceSgn(checkPoint);
	double signedDistOnPlane = p4.pointDistanceSgn(checkPoint, checkPointOnPlane1);
	double distOnPlane = p4.pointDistance(checkPoint, checkPointOnPlane2);
	
	distPt1 = checkPointOnPlane1.x()*p4[0] + checkPointOnPlane1.y()*p4[1] + checkPointOnPlane1.z()*p4[2] + p4[3];
	distPt2 = checkPointOnPlane2.x()*p4[0] + checkPointOnPlane2.y()*p4[1] + checkPointOnPlane2.z()*p4[2] + p4[3];
	
	if (!p4.isValid() || !checkPointOnPlane1.isValid() || !checkPointOnPlane2.isValid() ||
		fabs(distPt1) > GM_NULL_TOLERANCE || fabs(distPt2) > GM_NULL_TOLERANCE ||
		fabs(distOnPlane - checkDist) > GM_NULL_TOLERANCE || fabs(signedDistOnPlane - checkSignedDist) > GM_NULL_TOLERANCE ||
		fabs(dist - checkDist) > GM_NULL_TOLERANCE || fabs(signedDist - checkSignedDist) > GM_NULL_TOLERANCE) {
		logMessage(_T("\tERROR - Point distance computation not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Point distance computation working\n"));
	}

	// XY Angle
	double angle = ((((double)rand()) / ((double)RAND_MAX)) * GM_PI) - (GM_PI / 2.0);
	GM_3dVector normVector(angle/* + GM_HALFPI*/);
	normVector.z(normVector.y());
	normVector.y(0.0);
	GM_3dPlane angleP(normVector, GM_3dPoint(getRandomDouble(), getRandomDouble(), getRandomDouble()));
	double checkAngle = angleP.xyAngle();
	if (checkAngle > GM_PI) {
		checkAngle -= 2.0 * GM_PI;
	}
	if (!angleP.isValid() || fabs(angle - checkAngle) > GM_NULL_TOLERANCE) {
		logMessage(_T("\tERROR - XY angle computation not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - XY angle computation working\n"));
	}


	return numErr;
}