Example #1
0
int main (int argc, char **argv)
{
  struct sockaddr_in sa;
  int    rc, i;

  if (argc != 2)
  {
    printf ("Usage: %s num-sockets", argv[0]);
    return (0);
  }
  max_socks = atoi (argv[1]);
  if (max_socks == 0)
  {
    printf ("Usage: %s num-sockets", argv[0]);
    return (0);
  }

  setup();
  socks = calloc (max_socks, sizeof(int));
  assert (socks != NULL);

  for (i = 0; i < max_socks; i++)
  {
    PROFILE_START ("socket");
    socks[i] = socket (AF_INET, SOCK_STREAM, 0);
    PROFILE_STOP();
    if (socks[i] < 0)
    {
      perror ("socket");
      max_socks = i;
      break;
    }
  }

  for (i = 0; i < max_socks; i++)
  {
    sa.sin_family      = AF_INET;
    sa.sin_port        = htons (test_port);
    sa.sin_addr.s_addr = INADDR_ANY;
    PROFILE_START ("bind");
    rc = bind (socks[i], (struct sockaddr*)&sa, sizeof(sa));
    PROFILE_STOP();
    if (rc < 0)
    {
      perror ("bind");
      break;
    }
  }

  for (i = 0; i < max_socks; i++)
  {
    PROFILE_START ("close_s");
    close_s (socks[i]);
    PROFILE_STOP();
  }
  free (socks);
  return (0);
}
void GroupOfPlanes::SearchMVs(MVGroupOfFrames *pSrcGOF, MVGroupOfFrames *pRefGOF,
                              SearchType searchType, int nSearchParam, int nPelSearch, int nLambda,
                              int lsad, int pnew, int plevel, bool global, int flags,
							  int *out, short *outfilebuf, int fieldShift, DCTClass * _DCT, int pzero, int pglobal, int badSAD, int badrange)
{
	int i;

   nFlags |= flags;

   // write group's size
   out[0] = GetArraySize();

   // write validity : 1 in that case
   out[1] = 1;

   out += 2;

   int fieldShiftCur = (nLevelCount - 1 == 0) ? fieldShift : 0; // may be non zero for finest level only

   VECTOR globalMV; // create and init global motion vector as zero
   globalMV.x = zeroMV.x;
   globalMV.y = zeroMV.y;
   globalMV.sad = zeroMV.sad;

   if (!global)
        pglobal = pzero;

   int meanLumaChange = 0;

	// Search the motion vectors, for the low details interpolations first
	// Refining the search until we reach the highest detail interpolation.
//         DebugPrintf("SearchMV level %i", nLevelCount-1);
   planes[nLevelCount - 1]->SearchMVs(pSrcGOF->GetFrame(nLevelCount-1),
                                      pRefGOF->GetFrame(nLevelCount-1),
                                      searchType, nSearchParam, nLambda, lsad, pnew, plevel, flags,
									  out, &globalMV, outfilebuf, fieldShiftCur, _DCT, &meanLumaChange, divideExtra,
									  pzero, pglobal, badSAD, badrange);

   out += planes[nLevelCount - 1]->GetArraySize(divideExtra);

	for ( i = nLevelCount - 2; i >= 0; i-- )
	{
	    int nSearchParamLevel = (i==0) ? nPelSearch : nSearchParam; // special case for finest level
         PROFILE_START(MOTION_PROFILE_PREDICTION);
		if (global)
		{
		   planes[i+1]->EstimateGlobalMVDoubled(&globalMV); // get updated global MV (doubled)
//        DebugPrintf("SearchMV globalMV %i, %i", globalMV.x, globalMV.y);
		}
		planes[i]->InterpolatePrediction(*(planes[i+1]));
         PROFILE_STOP(MOTION_PROFILE_PREDICTION);
	    fieldShiftCur = (i == 0) ? fieldShift : 0; // may be non zero for finest level only
 //        DebugPrintf("SearchMV level %i", i);
		planes[i]->SearchMVs(pSrcGOF->GetFrame(i), pRefGOF->GetFrame(i),
              searchType, nSearchParamLevel, nLambda, lsad, pnew, plevel, flags,
			  out, &globalMV, outfilebuf, fieldShiftCur, _DCT, &meanLumaChange, divideExtra,
			  pzero, pglobal, badSAD, badrange);
      out += planes[i]->GetArraySize(divideExtra);
	}
}
static void
TestFIA_IOLoadColourArrayData(CuTest* tc)
{
	FIBITMAP *dib1 = NULL, *dib2 = NULL;
	FREE_IMAGE_TYPE type;
	int bpp, err;
    
	const char *file = "C:\\cup.tif";
	dib1 = FIA_LoadFIBFromFile(file);

	CuAssertTrue(tc, dib1 != NULL);

	dib2 = FreeImage_AllocateT (FIT_BITMAP, FreeImage_GetWidth(dib1), FreeImage_GetHeight(dib1), 8, 0, 0, 0);

	PROFILE_START("CopyColourBytesToFIBitmap");

	for(int i=0; i < 1000; i++) {

		//FIA_CopyColourBytesToFIBitmap (dib2, FreeImage_GetBits(dib1), 0, 1, COLOUR_ORDER_RGB);
		FIA_CopyColourBytesTo8BitFIBitmap (dib2, FreeImage_GetBits(dib1), 24, FI_RGBA_RED, 0, 1);

	}

	PROFILE_STOP("CopyColourBytesToFIBitmap");

	FIA_SaveFIBToFile (dib2, TEST_DATA_OUTPUT_DIR "/IO/save-colour-test.bmp", BIT8);

	FreeImage_Unload(dib1);
	FreeImage_Unload(dib2);
}
Example #4
0
/**
 * Combined threads and events loop.
 *
 * The loop processes first threads (_prepare_cb), then events
 * (ev_stat_cb, ev_io_cb). It sleeps until the earliest thread resume
 * time, or an I/O event occurs.
 *
 */
int
mrkthr_loop(void)
{
    int res;

    PROFILE_START(mrkthr_sched0_p);
    res = ev_run(the_loop, 0);
    PROFILE_STOP(mrkthr_sched0_p);
    return res;
}
static void
TestFIA_ErosionTest(CuTest* tc)
{
	const char *file = TEST_DATA_DIR "\\morpholology_test.bmp";

	FIBITMAP *dib1 = FIA_LoadFIBFromFile(file);
	
	CuAssertTrue(tc, dib1 != NULL);
	
	FIBITMAP *threshold_dib = FreeImage_Threshold(dib1, 20);

	CuAssertTrue(tc, threshold_dib != NULL);

	FIBITMAP *threshold_8bit_dib = FreeImage_ConvertTo8Bits(threshold_dib);

	CuAssertTrue(tc, threshold_8bit_dib != NULL);

	FIABITMAP *border_dib = FIA_SetBorder(threshold_8bit_dib, 2, 2
        , BorderType_Constant, 0.0);

	PROFILE_START("ErosionFilter");

	FilterKernel kernel = FIA_NewKernel(2, 2, kernel_values, 1.0);

	FIBITMAP* result_dib = FIA_BinaryErosion(border_dib, kernel);

	CuAssertTrue(tc, result_dib != NULL);

	PROFILE_STOP("ErosionFilter");

	FIA_SaveFIBToFile(result_dib, TEST_DATA_OUTPUT_DIR "\\erosion_result.jpg", BIT24);

	result_dib = FIA_BinaryInnerBorder(threshold_8bit_dib);

	FIA_SimpleSaveFIBToFile(result_dib, TEST_DATA_OUTPUT_DIR "morphology/inner_border_result.bmp");

	FreeImage_Unload(dib1);
	FreeImage_Unload(threshold_dib);
	FreeImage_Unload(threshold_8bit_dib);
	FIA_Unload(border_dib);
	FreeImage_Unload(result_dib);
}
static void TestFIA_HistogramTest(CuTest* tc)
{
    const char *file= TEST_DATA_DIR "drone-bee-greyscale.jpg";
    
    FIBITMAP *dib = FIA_LoadFIBFromFile(file);
    
    CuAssertTrue(tc, dib != NULL);
    
    unsigned long hist[256];
    
    PROFILE_START("FreeImageAlgorithms_Histogram");
    
    if (FIA_Histogram(dib, 0, 255, 2, hist) == FIA_ERROR) {
        CuFail(tc, "Failed");
    }
    
    PROFILE_STOP("FreeImageAlgorithms_Histogram");
    
    FreeImage_Unload(dib);
}
static void TestFIA_CentroidTest(CuTest* tc)
{
    const char *file= TEST_DATA_DIR "drone-bee-greyscale.jpg";
    
    FIBITMAP *dib = FIA_LoadFIBFromFile(file);
    
    CuAssertTrue(tc, dib != NULL);
    
    PROFILE_START("FreeImageAlgorithms_StatisticReport");
    
    float x_centroid, y_centroid;
    
    if (FIA_Centroid(dib, &x_centroid, &y_centroid) == FIA_ERROR) {
        CuFail(tc, "Failed");
    }
    
    PROFILE_STOP("FreeImageAlgorithms_StatisticReport");
    
    FreeImage_Unload(dib);
}
Example #8
0
std::string cache_read() {
	PROFILE_FUNC();

	std::string data;

	PROFILE_START(action_find); // Starts new action which will be inner to ACTION_READ
	bool found = find_record();
	PROFILE_STOP(action_find);

	if (!found) {
		PROFILE_BLOCK(load_from_disk);

		data = read_from_disk();
		put_into_cache(data);
		return data; // Here all action guards are destructed and actions are correctly finished
	}
	data = load_from_cache();

	return data;
}
Example #9
0
void MVFlowInter::ProcessFrameIntoGroupOfFrames(PMVGroupOfFrames *srcGOF, PVideoFrame *src, PVideoFrame *src2x, 
                                                int const Sharp, int const pixelType, int const nHeight, int const nWidth, 
                                                int const nPel, bool const isse)
{
    (*srcGOF)->ConvertVideoFrame(src, src2x, pixelType, nWidth, nHeight, nPel, isse);

    PROFILE_START(MOTION_PROFILE_INTERPOLATION);

    if (*src2x) {
        // do nothing
    }
    else {
        (*srcGOF)->Pad(YUVPLANES);
        (*srcGOF)->Refine(YUVPLANES, Sharp);
    }

    PROFILE_STOP(MOTION_PROFILE_INTERPOLATION);

    // set processed
    (*srcGOF)->SetProcessed();
}
Example #10
0
/*
 * Our WinPcap send function.
 * Not sure if partial writes are possible with NPF. Retry if rc != length.
 */
int pkt_send (const void *tx, int length)
{
  const ADAPTER *adapter;
  PACKET pkt;
  int    tx_cnt, rc = 0;

  ASSERT_PKT_INF (0);

  adapter = (const ADAPTER*) _pkt_inf->adapter;

  PROFILE_START ("pkt_send");

  for (tx_cnt = 1 + pkt_txretries; tx_cnt > 0; tx_cnt--)
  {
    pkt.Buffer = (void*) tx;
    pkt.Length = length;
    if (PacketSendPacket (adapter, &pkt, TRUE))
    {
      rc = length;
      break;
    }
    STAT (macstats.num_tx_retry++);
  }

  if (rc == length)
  {
    num_tx_pkt++;
    num_tx_bytes += length;
  }
  else
  {
    num_tx_errors++;  /* local copy */
    STAT (macstats.num_tx_err++);
  }
  PROFILE_STOP();
  return (rc);
}
Example #11
0
int
poller_resume(mrkthr_ctx_t *ctx)
{
    int res;

    /*
     * Can only be the result of yield or start, ie, the state cannot be
     * dormant or resumed.
     */
    if (!(ctx->co.state & CO_STATE_RESUMABLE)) {
        /* This is an error (currently no reason is known, though) */
        sleepq_remove(ctx);
        /* not sure if we can push it here ... */
        push_free_ctx(ctx);
        TRRET(RESUME + 1);
    }

    ctx->co.state = CO_STATE_RESUMED;

    me = ctx;

#ifdef TRACE_VERBOSE
    CTRACE("resuming >>>");
    //mrkthr_dump(ctx);
#endif

    PROFILE_STOP(mrkthr_sched0_p);
    PROFILE_START(mrkthr_swap_p);
    res = swapcontext(&main_uc, &me->co.uc);
    PROFILE_STOP(mrkthr_swap_p);
    PROFILE_START(mrkthr_sched0_p);

#ifdef TRACE_VERBOSE
    CTRACE("back from resume <<<");
    //mrkthr_dump(me);
#endif

    if (errno == EINTR) {
        CTRACE("ignoring EINTR");
#ifdef TRACE_VERBOSE
        //mrkthr_dump(ctx);
#endif
        errno = 0;
        return 0;
    }
    /* no one in the thread context may touch me */
    assert(me == ctx);
    me = NULL;

    if (ctx->co.state & CO_STATE_RESUMABLE) {
        return ctx->co.rc;

    } else if (ctx->co.state == CO_STATE_RESUMED) {
        /*
         * This is the case of the exited (dead) thread.
         */
#ifdef TRACE_VERBOSE
        CTRACE("Assuming exited (dead) ...");
        //mrkthr_dump(ctx);
#endif
        sleepq_remove(ctx);
        push_free_ctx(ctx);
        //TRRET(RESUME + 2);
        //return MRKTHR_CO_RC_EXITED;
        return ctx->co.rc;

    } else {
        CTRACE("Unknown case:");
        mrkthr_dump(ctx);
        FAIL("resume");
    }

    return res;
}
PVideoFrame __stdcall MVAnalyse::GetFrame(int n, IScriptEnvironment* env)
{
	const unsigned char *pSrcY, *pSrcU, *pSrcV;
	const unsigned char *pRefY, *pRefU, *pRefV;
	unsigned char *pDst;
	int nSrcPitchY, nSrcPitchUV;
	int nRefPitchY, nRefPitchUV;

    int minframe, maxframe, nref;

    if (analysisData.nDeltaFrame > 0)
    {
        minframe = ( analysisData.isBackward ) ? 0 : analysisData.nDeltaFrame;
        maxframe = ( analysisData.isBackward ) ? vi.num_frames - analysisData.nDeltaFrame : vi.num_frames;
    int offset = ( analysisData.isBackward ) ? analysisData.nDeltaFrame : -analysisData.nDeltaFrame;
        nref = n + offset;
    }
    else // special static mode
    {
        nref = - analysisData.nDeltaFrame; // positive fixed frame number
        minframe = 0;
        maxframe = vi.num_frames;
    }

//	DebugPrintf("MVAnalyse: Get src frame %d",n);
	PVideoFrame src = child->GetFrame(n, env); // v2.0
	bool paritysrc = child->GetParity(n);

      PROFILE_START(MOTION_PROFILE_YUY2CONVERT);
	if ( (analysisData.pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 )
	{
        // planer data packed to interleaved format (same as interleved2planar by kassandro) - v2.0.0.5
		pSrcY = src->GetReadPtr();
		pSrcU = pSrcY + src->GetRowSize()/2;
		pSrcV = pSrcU + src->GetRowSize()/4;
		nSrcPitchY  = src->GetPitch();
		nSrcPitchUV  = nSrcPitchY;
	}
	else
	{
		pSrcY = src->GetReadPtr(PLANAR_Y);
	    pSrcU = src->GetReadPtr(PLANAR_U);
	    pSrcV = src->GetReadPtr(PLANAR_V);
		nSrcPitchY = src->GetPitch(PLANAR_Y);
	    nSrcPitchUV = src->GetPitch(PLANAR_U);
	}
      PROFILE_STOP(MOTION_PROFILE_YUY2CONVERT);

	PVideoFrame	dst;

	dst = env->NewVideoFrame(vi);
	pDst = dst->GetWritePtr();

    // write analysis parameters as a header to frame

    memcpy(pDst, &headerSize, sizeof(int));

    if (divideExtra)
        memcpy(pDst+sizeof(int), &analysisDataDivided, sizeof(analysisData));
    else
        memcpy(pDst+sizeof(int), &analysisData, sizeof(analysisData));

    pDst += headerSize;

//    DebugPrintf("MVAnalyse: Get ref frame %d",n + offset);
//        DebugPrintf("MVAnalyse frame %i backward=%i", n, analysisData.isBackward);


	if (( n < maxframe ) && ( n >= minframe ))
	{
		PVideoFrame ref = child->GetFrame(nref, env);
		bool parityref = child->GetParity(nref);

		int fieldShift = 0;
		if (vi.IsFieldBased() && analysisData.nPel > 1 && (analysisData.nDeltaFrame %2 != 0))
		{
				fieldShift = (paritysrc && !parityref) ? analysisData.nPel/2 : ( (parityref && !paritysrc) ? -(analysisData.nPel/2) : 0);
				// vertical shift of fields for fieldbased video at finest level pel2
		}
      PROFILE_START(MOTION_PROFILE_YUY2CONVERT);
		if ( (analysisData.pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 )
		{
        // planer data packed to interleaved format (same as interleved2planar by kassandro) - v2.0.0.5
		pRefY = ref->GetReadPtr();
		pRefU = pRefY + ref->GetRowSize()/2;
		pRefV = pRefU + ref->GetRowSize()/4;
		nRefPitchY  = ref->GetPitch();
		nRefPitchUV  = nRefPitchY;
		}
		else
		{
		  pRefY = ref->GetReadPtr(PLANAR_Y);
		  pRefU = ref->GetReadPtr(PLANAR_U);
		  pRefV = ref->GetReadPtr(PLANAR_V);
		  nRefPitchY = ref->GetPitch(PLANAR_Y);
		  nRefPitchUV = ref->GetPitch(PLANAR_U);
		}
      PROFILE_STOP(MOTION_PROFILE_YUY2CONVERT);

      pSrcGOF->Update(nModeYUV, (BYTE*)pSrcY, nSrcPitchY, (BYTE*)pSrcU, nSrcPitchUV, (BYTE*)pSrcV, nSrcPitchUV); // v2.0
      pRefGOF->Update(nModeYUV, (BYTE*)pRefY, nRefPitchY, (BYTE*)pRefU, nRefPitchUV, (BYTE*)pRefV, nRefPitchUV); // v2.0

	  if (outfile != NULL) {
			fwrite( &n, sizeof( int ), 1, outfile );// write frame number
	  }

    int *pVecPrevOrNull = nVecPrev==n-1 ? pVecPrev : 0; // temporal predictor dst if prev frame was really prev

      vectorFields->SearchMVs(pSrcGOF, pRefGOF, searchType, nSearchParam, nPelSearch, nLambda, lsad, pnew, plevel, global,
		  analysisData.nFlags, reinterpret_cast<int*>(pDst), outfilebuf, fieldShift, DCTc, pzero, pglobal, badSAD, badrange, meander, pVecPrevOrNull, tryMany);

    if (divideExtra) {
      // make extra level with divided sublocks with median (not estimated) motion
      vectorFields->ExtraDivide(reinterpret_cast<int*>(pDst), analysisData.nFlags);
    }

//      PROFILE_CUMULATE();
		if (outfile != NULL)
			fwrite( outfilebuf, sizeof(short)* analysisData.nBlkX*analysisData.nBlkY*4, 1, outfile );

	}
	else
	{
		vectorFields->WriteDefaultToArray(reinterpret_cast<int*>(pDst));
	}

	if (pVecPrev) {
        memcpy(pVecPrev, reinterpret_cast<int*>(pDst), vectorFields->GetArraySize()); // store previous vectors for use as predictor in next frame
        nVecPrev = n;
	}
	return dst;
}
Example #13
0
void ProcessAdjacentMapTile(Path& thePath, Tile* tile, Map* map, const IntVec2& start, const IntVec2& goal ){
	UNUSED(start);

	PROFILE_SECTION();
	if (tile == NULL)
		return;

	//8 Get adjacent pos
	MapPosition& adjacentNodePos = tile->m_mapPosition;

	//float newFinalCostCheck = newPathNode->m_nodeCost.h;
	//if (newFinalCostCheck < 2.0f * map->m_size.x * map->m_size.y){

	//9 if (adjacent pos on closed list) //continue;

	Tile* tileToCheckID = map->GetTileAtMapPosition(adjacentNodePos);
	bool tileCheckID;
	//tilesPathIDCritSec.Enter();
	tileCheckID = (tileToCheckID->m_inClosedListOfPathID == thePath.m_id);
	//tilesPathIDCritSec.Exit();
	if (tileCheckID){
	//if (thePath.IsMapPositionInClosedList(adjacentNodePos)){
		return;
	}
	else{
		//10 & 11 decently fast
		// 10 if (not on open list){ 
		if(tileToCheckID->m_inOpenListOfPathID != thePath.m_id){
		//if (!thePath.IsMapPositionInOpenList(adjacentNodePos)){
			PROFILE_START(step 10 and 11);
			//11 build new pathnode(local G, parentG = ActiveNode.G) //	Add to OpenList
			PathNode* newPathNode = new PathNode(tile, thePath.m_activeNode, goal, thePath.m_bestAvoidCost); //this bit of path node has a memory leak
	
			thePath.AddToOpenList(newPathNode);

			tilesPathIDOpenCritSec.Enter();
			tile->m_inOpenListOfPathID = thePath.m_id;
			tilesPathIDOpenCritSec.Exit();

			PROFILE_STOP();
			return;
		}
		else{
			//is on openList
			float altTotalG;
			float tileAvoidCost;
			float currentG;
			PathNode* nodeInOpenList;

			PROFILE_START(step 12 and 13); //doesn't seem to ever get called
			tileAvoidCost = tile->m_tileAvoidanceCost;
			nodeInOpenList = thePath.GetPathNodeAtMapPositionFromOpenList(adjacentNodePos);
			if (!nodeInOpenList){
				return;
			}
			//12 calc newG as calc hypothetical G to this node
			altTotalG = CalcHypotheticalGCostToAdjacentNodePosition(thePath.m_activeNode, adjacentNodePos, tileAvoidCost);
			//13 compare to G in openList for node holding this position	
			currentG = nodeInOpenList->m_nodeCost.g;
			PROFILE_STOP();
			
			//14 if better <
			if (altTotalG < currentG){
				//15 update openListNode, update localG, parent, 
				PROFILE_START(step 15);
				ReplaceOpenListPathNode(thePath, nodeInOpenList, tileAvoidCost);
				PROFILE_STOP();
				return;
			}
			else{
				//16 if worse or equal >= //throw out
				return;
			}//end of inside if/else

		}//end of if/else

	}//end of outer if/else

}
Example #14
0
PVideoFrame __stdcall MVSuper::GetFrame(int n, IScriptEnvironment* env)
{
	const unsigned char *pSrcY, *pSrcU, *pSrcV;
	unsigned char *pDstY, *pDstU, *pDstV;
	const unsigned char *pSrcPelY, *pSrcPelU, *pSrcPelV;
//	unsigned char *pDstYUY2;
	int nSrcPitchY, nSrcPitchUV;
	int nDstPitchY, nDstPitchUV;
	int nSrcPelPitchY, nSrcPelPitchUV;
//	int nDstPitchYUY2;

	DebugPrintf("MSuper: Get src frame %d clip %d",n,child);

	PVideoFrame src = child->GetFrame(n, env);
	PVideoFrame srcPel;
	if (usePelClip)
	srcPel = pelclip->GetFrame(n, env);

	PVideoFrame	dst = env->NewVideoFrame(vi);

	PROFILE_START(MOTION_PROFILE_YUY2CONVERT);
	if ( (pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 )
	{
		if (!planar)
		{
			pSrcY = SrcPlanes->GetPtr();
			pSrcU = SrcPlanes->GetPtrU();
			pSrcV = SrcPlanes->GetPtrV();
			nSrcPitchY  = SrcPlanes->GetPitch();
			nSrcPitchUV  = SrcPlanes->GetPitchUV();
			YUY2ToPlanes(src->GetReadPtr(), src->GetPitch(), nWidth, nHeight,
			pSrcY, nSrcPitchY, pSrcU, pSrcV, nSrcPitchUV, isse);
			if (usePelClip)
			{
				pSrcPelY = SrcPelPlanes->GetPtr();
				pSrcPelU = SrcPelPlanes->GetPtrU();
				pSrcPelV = SrcPelPlanes->GetPtrV();
				nSrcPelPitchY  = SrcPelPlanes->GetPitch();
				nSrcPelPitchUV  = SrcPelPlanes->GetPitchUV();
				YUY2ToPlanes(srcPel->GetReadPtr(), srcPel->GetPitch(), srcPel->GetRowSize()/2, srcPel->GetHeight(),
				pSrcPelY, nSrcPelPitchY, pSrcPelU, pSrcPelV, nSrcPelPitchUV, isse);
			}
		}
		else
		{
			pSrcY = src->GetReadPtr();
			pSrcU = pSrcY + src->GetRowSize()/2;
			pSrcV = pSrcU + src->GetRowSize()/4;
			nSrcPitchY  = src->GetPitch();
			nSrcPitchUV  = nSrcPitchY;
			if (usePelClip)
			{
				pSrcPelY = srcPel->GetReadPtr();
				pSrcPelU = pSrcPelY + srcPel->GetRowSize()/2;
				pSrcPelV = pSrcPelU + srcPel->GetRowSize()/4;
				nSrcPelPitchY  = srcPel->GetPitch();
				nSrcPelPitchUV  = nSrcPelPitchY;
			}
		}
//		pDstY = DstPlanes->GetPtr();
//		pDstU = DstPlanes->GetPtrU();
//		pDstV = DstPlanes->GetPtrV();
//		nDstPitchY  = DstPlanes->GetPitch();
//		nDstPitchUV  = DstPlanes->GetPitchUV();
		// planer data packed to interleaved format (same as interleved2planar by kassandro) - v2.0.0.5
		pDstY = dst->GetWritePtr();
		pDstU = pDstY + nSuperWidth;
		pDstV = pDstU + nSuperWidth/2;
		nDstPitchY = dst->GetPitch();
		nDstPitchUV = nDstPitchY;
	}
	else
	{
		pSrcY = src->GetReadPtr(PLANAR_Y);
		pSrcU = src->GetReadPtr(PLANAR_U);
		pSrcV = src->GetReadPtr(PLANAR_V);
		nSrcPitchY = src->GetPitch(PLANAR_Y);
		nSrcPitchUV = src->GetPitch(PLANAR_U);
		if (usePelClip)
		{
			pSrcPelY = srcPel->GetReadPtr(PLANAR_Y);
			pSrcPelU = srcPel->GetReadPtr(PLANAR_U);
			pSrcPelV = srcPel->GetReadPtr(PLANAR_V);
			nSrcPelPitchY = srcPel->GetPitch(PLANAR_Y);
			nSrcPelPitchUV = srcPel->GetPitch(PLANAR_U);
		}
		pDstY = dst->GetWritePtr(PLANAR_Y);
		pDstU = dst->GetWritePtr(PLANAR_U);
		pDstV = dst->GetWritePtr(PLANAR_V);
		nDstPitchY  = dst->GetPitch(PLANAR_Y);
		nDstPitchUV  = dst->GetPitch(PLANAR_U);
	}
	PROFILE_STOP(MOTION_PROFILE_YUY2CONVERT);

	PROFILE_START(MOTION_PROFILE_INTERPOLATION);

	pSrcGOF->Update(YUVPLANES, pDstY, nDstPitchY, pDstU, nDstPitchUV, pDstV, nDstPitchUV);

	pSrcGOF->SetPlane(pSrcY, nSrcPitchY, YPLANE);
	pSrcGOF->SetPlane(pSrcU, nSrcPitchUV, UPLANE);
	pSrcGOF->SetPlane(pSrcV, nSrcPitchUV, VPLANE);

	pSrcGOF->Reduce(nModeYUV);
	pSrcGOF->Pad(nModeYUV);

	if (usePelClip)
	{
		MVFrame *srcFrames = pSrcGOF->GetFrame(0);
		MVPlane *srcPlaneY = srcFrames->GetPlane(YPLANE);
		if (nModeYUV & YPLANE) srcPlaneY->RefineExt(pSrcPelY, nSrcPelPitchY, isPelClipPadded);
		MVPlane *srcPlaneU = srcFrames->GetPlane(UPLANE);
		if (nModeYUV & UPLANE) srcPlaneU->RefineExt(pSrcPelU, nSrcPelPitchUV, isPelClipPadded);
		MVPlane *srcPlaneV = srcFrames->GetPlane(VPLANE);
		if (nModeYUV & VPLANE) srcPlaneV->RefineExt(pSrcPelV, nSrcPelPitchUV, isPelClipPadded);
	}
	else
	{
		pSrcGOF->Refine(nModeYUV);
	}

	PROFILE_STOP(MOTION_PROFILE_INTERPOLATION);


/*
	PROFILE_START(MOTION_PROFILE_YUY2CONVERT);

	if ( (pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 )
	{
		pDstYUY2 = dst->GetWritePtr();
		nDstPitchYUY2 = dst->GetPitch();
		YUY2FromPlanes(pDstYUY2, nDstPitchYUY2, nSuperWidth, nSuperHeight,
			pDstY, nDstPitchY, pDstU, pDstV, nDstPitchUV, isse);
	}
	PROFILE_STOP(MOTION_PROFILE_YUY2CONVERT);
*/

	PROFILE_CUMULATE();

	return dst;
}
Example #15
0
PVideoFrame __stdcall MVDegrain1::GetFrame(int n, IScriptEnvironment* env)
{
	int nWidth_B = nBlkX*(nBlkSizeX - nOverlapX) + nOverlapX;
	int nHeight_B = nBlkY*(nBlkSizeY - nOverlapY) + nOverlapY;

	PVideoFrame	src	= child->GetFrame(n, env);
	PVideoFrame dst;
	BYTE *pDst[3], *pDstCur[3];
	const BYTE *pSrcCur[3];
	const BYTE *pSrc[3];
	const BYTE *pRefB[3];
	const BYTE *pRefF[3];
	int nDstPitches[3], nSrcPitches[3];
	int nRefBPitches[3], nRefFPitches[3];
	unsigned char *pDstYUY2;
	const unsigned char *pSrcYUY2;
	int nDstPitchYUY2;
	int nSrcPitchYUY2;
	bool isUsableB, isUsableF;
	int tmpPitch = nBlkSizeX;
	int nLogPel = (nPel==4) ? 2 : (nPel==2) ? 1 : 0;
	// nLogPel=0 for nPel=1, 1 for nPel=2, 2 for nPel=4, i.e. (x*nPel) = (x<<nLogPel)

	PVideoFrame mvF = mvClipF.GetFrame(n, env);
	mvClipF.Update(mvF, env);
	isUsableF = mvClipF.IsUsable();
	mvF = 0; // v2.0.9.2 -  it seems, we do not need in vectors clip anymore when we finished copiing them to fakeblockdatas
	PVideoFrame mvB = mvClipB.GetFrame(n, env);
	mvClipB.Update(mvB, env);
	isUsableB = mvClipB.IsUsable();
	mvB = 0;

	int				lsb_offset_y = 0;
	int				lsb_offset_u = 0;
	int				lsb_offset_v = 0;

//   int sharp = mvClipB.GetSharp();
	int ySubUV = (yRatioUV == 2) ? 1 : 0;
//   if ( mvClipB.IsUsable() && mvClipF.IsUsable() && mvClipB2.IsUsable() && mvClipF2.IsUsable() )
//   {
	dst = env->NewVideoFrame(vi);
	if ( (pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 )
	{
		if (!planar)
		{
			pDstYUY2 = dst->GetWritePtr();
			nDstPitchYUY2 = dst->GetPitch();
			pDst[0] = DstPlanes->GetPtr();
			pDst[1] = DstPlanes->GetPtrU();
			pDst[2] = DstPlanes->GetPtrV();
			nDstPitches[0]  = DstPlanes->GetPitch();
			nDstPitches[1]  = DstPlanes->GetPitchUV();
			nDstPitches[2]  = DstPlanes->GetPitchUV();
			pSrcYUY2 = src->GetReadPtr();
			nSrcPitchYUY2 = src->GetPitch();
			pSrc[0] = SrcPlanes->GetPtr();
			pSrc[1] = SrcPlanes->GetPtrU();
			pSrc[2] = SrcPlanes->GetPtrV();
			nSrcPitches[0]  = SrcPlanes->GetPitch();
			nSrcPitches[1]  = SrcPlanes->GetPitchUV();
			nSrcPitches[2]  = SrcPlanes->GetPitchUV();
			YUY2ToPlanes(pSrcYUY2, nSrcPitchYUY2, nWidth, nHeight,
			pSrc[0], nSrcPitches[0], pSrc[1], pSrc[2], nSrcPitches[1], isse);
		}
		else
		{
			pDst[0] = dst->GetWritePtr();
			pDst[1] = pDst[0] + nWidth;
			pDst[2] = pDst[1] + nWidth/2;
			nDstPitches[0] = dst->GetPitch();
			nDstPitches[1] = nDstPitches[0];
			nDstPitches[2] = nDstPitches[0];
			pSrc[0] = src->GetReadPtr();
			pSrc[1] = pSrc[0] + nWidth;
			pSrc[2] = pSrc[1] + nWidth/2;
			nSrcPitches[0] = src->GetPitch();
			nSrcPitches[1] = nSrcPitches[0];
			nSrcPitches[2] = nSrcPitches[0];
		}
	}
	else
	{
		pDst[0] = YWPLAN(dst);
		pDst[1] = UWPLAN(dst);
		pDst[2] = VWPLAN(dst);
		nDstPitches[0] = YPITCH(dst);
		nDstPitches[1] = UPITCH(dst);
		nDstPitches[2] = VPITCH(dst);
		pSrc[0] = YRPLAN(src);
		pSrc[1] = URPLAN(src);
		pSrc[2] = VRPLAN(src);
		nSrcPitches[0] = YPITCH(src);
		nSrcPitches[1] = UPITCH(src);
		nSrcPitches[2] = VPITCH(src);
	}

	lsb_offset_y = nDstPitches [0] *  nHeight;
	lsb_offset_u = nDstPitches [1] * (nHeight / yRatioUV);
	lsb_offset_v = nDstPitches [2] * (nHeight / yRatioUV);

	if (lsb_flag)
	{
		memset (pDst [0] + lsb_offset_y, 0, lsb_offset_y);
		if (! planar)
		{
			memset (pDst [1] + lsb_offset_u, 0, lsb_offset_u);
			memset (pDst [2] + lsb_offset_v, 0, lsb_offset_v);
		}
	}

//	MVFrames *pFrames = mvCore->GetFrames(nIdx);
	PVideoFrame refB, refF;

//	PVideoFrame refB2x, refF2x;

	mvClipF.use_ref_frame (refF, isUsableF, super, n, env);
	mvClipB.use_ref_frame (refB, isUsableB, super, n, env);

	if ( (pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 )
	{
		// planar data packed to interleaved format (same as interleved2planar by kassandro) - v2.0.0.5
		if (isUsableF)
		{
			pRefF[0] = refF->GetReadPtr();
			pRefF[1] = pRefF[0] + refF->GetRowSize()/2;
			pRefF[2] = pRefF[1] + refF->GetRowSize()/4;
			nRefFPitches[0]  = refF->GetPitch();
			nRefFPitches[1]  = nRefFPitches[0];
			nRefFPitches[2]  = nRefFPitches[0];
		}
		if (isUsableB)
		{
			pRefB[0] = refB->GetReadPtr();
			pRefB[1] = pRefB[0] + refB->GetRowSize()/2;
			pRefB[2] = pRefB[1] + refB->GetRowSize()/4;
			nRefBPitches[0]  = refB->GetPitch();
			nRefBPitches[1]  = nRefBPitches[0];
			nRefBPitches[2]  = nRefBPitches[0];
		}
	}
	else
	{
		if (isUsableF)
		{
			pRefF[0] = YRPLAN(refF);
			pRefF[1] = URPLAN(refF);
			pRefF[2] = VRPLAN(refF);
			nRefFPitches[0] = YPITCH(refF);
			nRefFPitches[1] = UPITCH(refF);
			nRefFPitches[2] = VPITCH(refF);
		}
		if (isUsableB)
		{
			pRefB[0] = YRPLAN(refB);
			pRefB[1] = URPLAN(refB);
			pRefB[2] = VRPLAN(refB);
			nRefBPitches[0] = YPITCH(refB);
			nRefBPitches[1] = UPITCH(refB);
			nRefBPitches[2] = VPITCH(refB);
		}
	}



	MVPlane *pPlanesB[3] = { 0 };
	MVPlane *pPlanesF[3] = { 0 };

	if (isUsableF)
	{
		pRefFGOF->Update(YUVplanes, (BYTE*)pRefF[0], nRefFPitches[0], (BYTE*)pRefF[1], nRefFPitches[1], (BYTE*)pRefF[2], nRefFPitches[2]);
		if (YUVplanes & YPLANE)
			pPlanesF[0] = pRefFGOF->GetFrame(0)->GetPlane(YPLANE);
		if (YUVplanes & UPLANE)
			pPlanesF[1] = pRefFGOF->GetFrame(0)->GetPlane(UPLANE);
		if (YUVplanes & VPLANE)
			pPlanesF[2] = pRefFGOF->GetFrame(0)->GetPlane(VPLANE);
	}
	if (isUsableB)
	{
		pRefBGOF->Update(YUVplanes, (BYTE*)pRefB[0], nRefBPitches[0], (BYTE*)pRefB[1], nRefBPitches[1], (BYTE*)pRefB[2], nRefBPitches[2]);// v2.0
		if (YUVplanes & YPLANE)
			pPlanesB[0] = pRefBGOF->GetFrame(0)->GetPlane(YPLANE);
		if (YUVplanes & UPLANE)
			pPlanesB[1] = pRefBGOF->GetFrame(0)->GetPlane(UPLANE);
		if (YUVplanes & VPLANE)
			pPlanesB[2] = pRefBGOF->GetFrame(0)->GetPlane(VPLANE);
	}

	PROFILE_START(MOTION_PROFILE_COMPENSATION);
	pDstCur[0] = pDst[0];
	pDstCur[1] = pDst[1];
	pDstCur[2] = pDst[2];
	pSrcCur[0] = pSrc[0];
	pSrcCur[1] = pSrc[1];
	pSrcCur[2] = pSrc[2];

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// LUMA plane Y

	if (!(YUVplanes & YPLANE))
	{
		BitBlt(pDstCur[0], nDstPitches[0], pSrcCur[0], nSrcPitches[0], nWidth, nHeight, isse);
	}

	else
	{
		if (nOverlapX==0 && nOverlapY==0)
		{
			for (int by=0; by<nBlkY; by++)
			{
				int xx = 0;
				for (int bx=0; bx<nBlkX; bx++)
				{
					int i = by*nBlkX + bx;
					const BYTE * pB, *pF;
					int npB, npF;
					int WSrc, WRefB, WRefF;

					use_block_y (pB , npB , WRefB , isUsableB , mvClipB , i, pPlanesB  [0], pSrcCur [0], xx, nSrcPitches [0]);
					use_block_y (pF , npF , WRefF , isUsableF , mvClipF , i, pPlanesF  [0], pSrcCur [0], xx, nSrcPitches [0]);
					norm_weights (WSrc, WRefB, WRefF);

					// luma
					DEGRAINLUMA(pDstCur[0] + xx, pDstCur[0] + lsb_offset_y + xx,
						lsb_flag, nDstPitches[0], pSrcCur[0]+ xx, nSrcPitches[0],
						pB, npB, pF, npF, WSrc, WRefB, WRefF);

					xx += (nBlkSizeX);

					if (bx == nBlkX-1 && nWidth_B < nWidth) // right non-covered region
					{
						// luma
						BitBlt(pDstCur[0] + nWidth_B, nDstPitches[0],
							pSrcCur[0] + nWidth_B, nSrcPitches[0], nWidth-nWidth_B, nBlkSizeY, isse);
					}
				}	// for bx

				pDstCur[0] += ( nBlkSizeY ) * (nDstPitches[0]);
				pSrcCur[0] += ( nBlkSizeY ) * (nSrcPitches[0]);

				if (by == nBlkY-1 && nHeight_B < nHeight) // bottom uncovered region
				{
					// luma
					BitBlt(pDstCur[0], nDstPitches[0], pSrcCur[0], nSrcPitches[0], nWidth, nHeight-nHeight_B, isse);
				}
			}	// for by
		}	// nOverlapX==0 && nOverlapY==0

// -----------------------------------------------------------------

		else // overlap
		{
			unsigned short *pDstShort = DstShort;
			int *pDstInt = DstInt;
			const int tmpPitch = nBlkSizeX;

			if (lsb_flag)
			{
				MemZoneSet(reinterpret_cast<unsigned char*>(pDstInt), 0,
					nWidth_B*4, nHeight_B, 0, 0, dstIntPitch*4);
			}
			else
			{
				MemZoneSet(reinterpret_cast<unsigned char*>(pDstShort), 0,
					nWidth_B*2, nHeight_B, 0, 0, dstShortPitch*2);
			}

			for (int by=0; by<nBlkY; by++)
			{
				int wby = ((by + nBlkY - 3)/(nBlkY - 2))*3;
				int xx = 0;
				for (int bx=0; bx<nBlkX; bx++)
				{
					// select window
					int wbx = (bx + nBlkX - 3)/(nBlkX - 2);
					short *			winOver = OverWins->GetWindow(wby + wbx);

					int i = by*nBlkX + bx;
					const BYTE * pB, *pF;
					int npB, npF;
					int WSrc, WRefB, WRefF;

					use_block_y (pB , npB , WRefB , isUsableB , mvClipB , i, pPlanesB  [0], pSrcCur [0], xx, nSrcPitches [0]);
					use_block_y (pF , npF , WRefF , isUsableF , mvClipF , i, pPlanesF  [0], pSrcCur [0], xx, nSrcPitches [0]);
					norm_weights (WSrc, WRefB, WRefF);

					// luma
					DEGRAINLUMA(tmpBlock, tmpBlockLsb, lsb_flag, tmpPitch, pSrcCur[0]+ xx, nSrcPitches[0],
						pB, npB, pF, npF, WSrc, WRefB, WRefF);
					if (lsb_flag)
					{
						OVERSLUMALSB(pDstInt + xx, dstIntPitch, tmpBlock, tmpBlockLsb, tmpPitch, winOver, nBlkSizeX);
					}
					else
					{
						OVERSLUMA(pDstShort + xx, dstShortPitch, tmpBlock, tmpPitch, winOver, nBlkSizeX);
					}

					xx += (nBlkSizeX - nOverlapX);
				}	// for bx

				pSrcCur[0] += (nBlkSizeY - nOverlapY) * (nSrcPitches[0]);
				pDstShort += (nBlkSizeY - nOverlapY) * dstShortPitch;
				pDstInt += (nBlkSizeY - nOverlapY) * dstIntPitch;
			}	// for by
			if (lsb_flag)
			{
				Short2BytesLsb(pDst[0], pDst[0] + lsb_offset_y, nDstPitches[0], DstInt, dstIntPitch, nWidth_B, nHeight_B);
			}
			else
			{
				Short2Bytes(pDst[0], nDstPitches[0], DstShort, dstShortPitch, nWidth_B, nHeight_B);
			}
			if (nWidth_B < nWidth)
			{
				BitBlt(pDst[0] + nWidth_B, nDstPitches[0],
					pSrc[0] + nWidth_B, nSrcPitches[0],
					nWidth-nWidth_B, nHeight_B, isse);
			}
			if (nHeight_B < nHeight) // bottom noncovered region
			{
				BitBlt(pDst[0] + nHeight_B*nDstPitches[0], nDstPitches[0],
					pSrc[0] + nHeight_B*nSrcPitches[0], nSrcPitches[0],
					nWidth, nHeight-nHeight_B, isse);
			}
		}	// overlap - end

		if (nLimit < 255)
		{
			if (isse)
			{
				LimitChanges_sse2(pDst[0], nDstPitches[0], pSrc[0], nSrcPitches[0], nWidth, nHeight, nLimit);
			}
			else
			{
				LimitChanges_c(pDst[0], nDstPitches[0], pSrc[0], nSrcPitches[0], nWidth, nHeight, nLimit);
			}
		}
	}

//----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// CHROMA plane U

	process_chroma (
		UPLANE & nSuperModeYUV,
		pDst [1], pDstCur [1], nDstPitches [1], pSrc [1], pSrcCur [1], nSrcPitches [1],
		isUsableB, isUsableF, pPlanesB [1], pPlanesF [1],
		lsb_offset_u, nWidth_B, nHeight_B
	);

//----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// CHROMA plane V

	process_chroma (
		VPLANE & nSuperModeYUV,
		pDst [2], pDstCur [2], nDstPitches [2], pSrc [2], pSrcCur [2], nSrcPitches [2],
		isUsableB, isUsableF, pPlanesB [2], pPlanesF [2],
		lsb_offset_v, nWidth_B, nHeight_B
	);

//--------------------------------------------------------------------------------

	_mm_empty ();	// (we may use double-float somewhere) Fizick

	PROFILE_STOP(MOTION_PROFILE_COMPENSATION);


	if ( (pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 && !planar)
	{
		YUY2FromPlanes(pDstYUY2, nDstPitchYUY2, nWidth, nHeight * height_lsb_mul,
					  pDst[0], nDstPitches[0], pDst[1], pDst[2], nDstPitches[1], isse);
	}
   return dst;
}
Example #16
0
Path& ProcessOneStepOfPath(Path& thePath, Map* map, const IntVec2& start, const IntVec2& goal, bool ignoreEntities ){
	PROFILE_SECTION();
	if (!thePath.m_initialized && map){
		thePath = Path(map, start, goal);
	}
	
	if (!thePath.IsOpenListEmpty() && !thePath.m_isComplete){

		thePath.m_iterations++;

		PROFILE_START(steps 1 to 4);
		//1 pick lowest f on openList check
		//2 remove from open list check
		PathNode* lowestFCostInThePath = thePath.PopLowestFCostInOpenList();

		//3 add lowest cost to closed list check
		Tile* tileToCheckID = map->GetTileAtMapPosition(lowestFCostInThePath->m_position);
		tilesPathIDOpenCritSec.Enter();
		tileToCheckID->m_inOpenListOfPathID = -1;
		tilesPathIDOpenCritSec.Exit();

		//tilesPathIDCritSec.Enter();
		if (tileToCheckID->m_inClosedListOfPathID != thePath.m_id){
			
			thePath.AddToClosedList(lowestFCostInThePath);
			CRITICAL_SECTION_SCOPE(tilesPathIDClosedCritSec);
			tileToCheckID->m_inClosedListOfPathID = thePath.m_id;
		}
		//tilesPathIDCritSec.Exit();

// 		if (!thePath.IsMapPositionInClosedList(lowestFCostInThePath->m_position)){
// 
// 			thePath.AddToClosedList(lowestFCostInThePath);
// 
// 		}

		//4 set lowest f node to active
		thePath.m_activeNode = lowestFCostInThePath;
		PROFILE_STOP();

		//5 check if node is goal, break;
		if (thePath.m_activeNode->m_position == goal){
			thePath.m_isComplete = true;
			//ConsoleGenericMessageBox("YAY Path is found.");

			thePath.m_openList.clear();

			return thePath;
		}
		else{
			TilePtrs adjacentTilePtrs;
			PROFILE_START(step 6);
			//6 ask "map" for adjacent positions of active node
			Tile* activeTile = map->GetTileAtMapPosition(thePath.m_activeNode->m_position);
			if (activeTile){
				adjacentTilePtrs = map->GetValidAdjacentTiles(activeTile, ignoreEntities);
			}
			PROFILE_STOP();

			//this is the longest part of pathing
			ProcessAdjacentMapTiles(thePath, map, start, goal, adjacentTilePtrs);

		}

	}//end of final outer if
	
// 	else if (thePath.IsOpenListEmpty()){
// 		//ConsoleGenericMessageBox("No Path =(");
// 
// 		//the path is impossible
// 		thePath.m_isImpossible = true;
// 
// 		return thePath;
// 	}
	
	return thePath;
}
Example #17
0
PVideoFrame __stdcall MVRecalculate::GetFrame(int n, IScriptEnvironment* env)
{
	const unsigned char *pSrcY, *pSrcU, *pSrcV;
	const unsigned char *pRefY, *pRefU, *pRefV;
//	const unsigned char *pSrc2xY, *pSrc2xU, *pSrc2xV;
//	const unsigned char *pRef2xY, *pRef2xU, *pRef2xV;
	unsigned char *pDst;
	int nSrcPitchY, nSrcPitchUV;
	int nRefPitchY, nRefPitchUV;
//	int nSrc2xPitchY, nSrc2xPitchUV;
//	int nRef2xPitchY, nRef2xPitchUV;

	int minframe = ( analysisData.isBackward ) ? 0 : analysisData.nDeltaFrame;
	int maxframe = ( analysisData.isBackward ) ? vi.num_frames - analysisData.nDeltaFrame : vi.num_frames;
	int offset = ( analysisData.isBackward ) ? analysisData.nDeltaFrame : -analysisData.nDeltaFrame;

//	DebugPrintf("MVRecalculate: Get src frame %d",n);
	PVideoFrame src = child->GetFrame(n, env);
	bool paritysrc = child->GetParity(n);
//	PVideoFrame src2x;
//	if (analysisData.usePelClip)
//		src2x = pelclip->GetFrame(n, env);

      PROFILE_START(MOTION_PROFILE_YUY2CONVERT);
	if ( (analysisData.pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 )
	{
        // planer data packed to interleaved format (same as interleved2planar by kassandro) - v2.0.0.5
		pSrcY = src->GetReadPtr();
		pSrcU = pSrcY + src->GetRowSize()/2;
		pSrcV = pSrcU + src->GetRowSize()/4;
		nSrcPitchY  = src->GetPitch();
		nSrcPitchUV  = nSrcPitchY;
	}
	else
	{
		pSrcY = src->GetReadPtr(PLANAR_Y);
	    pSrcU = src->GetReadPtr(PLANAR_U);
	    pSrcV = src->GetReadPtr(PLANAR_V);
		nSrcPitchY = src->GetPitch(PLANAR_Y);
	    nSrcPitchUV = src->GetPitch(PLANAR_U);
	}
      PROFILE_STOP(MOTION_PROFILE_YUY2CONVERT);

	PVideoFrame	dst;

	dst = env->NewVideoFrame(vi);
	pDst = dst->GetWritePtr();

    // write analysis parameters as a header to frame

    memcpy(pDst, &headerSize, sizeof(int));

    if (divideExtra)
        memcpy(pDst+sizeof(int), &analysisDataDivided, sizeof(analysisData));
    else
        memcpy(pDst+sizeof(int), &analysisData, sizeof(analysisData));

    pDst += headerSize;

//    DebugPrintf("MVRecalculate: Get ref frame %d",n + offset);

	PVideoFrame mvn = mvClip.GetFrame(n, env); // get pointer to vectors
    mvClip.Update(mvn, env); // force calulation of vectors

	if (mvClip.IsUsable() && ( n < maxframe ) && ( n >= minframe ))
	{
		PVideoFrame ref = child->GetFrame(n + offset, env);
		bool parityref = child->GetParity(n + offset);
//		PVideoFrame ref2x;
//		if (analysisData.usePelClip)
//			ref2x = pelclip->GetFrame(n + offset, env);

		int fieldShift = 0;
		if (vi.IsFieldBased() && analysisData.nPel > 1 && (analysisData.nDeltaFrame %2 != 0))
		{
				fieldShift = (paritysrc && !parityref) ? analysisData.nPel/2 : ( (parityref && !paritysrc) ? -(analysisData.nPel/2) : 0);
				// vertical shift of fields for fieldbased video at finest level pel2
		}
      PROFILE_START(MOTION_PROFILE_YUY2CONVERT);
		if ( (analysisData.pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 )
		{
        // planer data packed to interleaved format (same as interleved2planar by kassandro) - v2.0.0.5
		pRefY = ref->GetReadPtr();
		pRefU = pRefY + ref->GetRowSize()/2;
		pRefV = pRefU + ref->GetRowSize()/4;
		nRefPitchY  = ref->GetPitch();
		nRefPitchUV  = nRefPitchY;
		}
		else
		{
		  pRefY = ref->GetReadPtr(PLANAR_Y);
		  pRefU = ref->GetReadPtr(PLANAR_U);
		  pRefV = ref->GetReadPtr(PLANAR_V);
		  nRefPitchY = ref->GetPitch(PLANAR_Y);
		  nRefPitchUV = ref->GetPitch(PLANAR_U);
		}
      PROFILE_STOP(MOTION_PROFILE_YUY2CONVERT);

/*
      MVFrames *pFrames = mvCore->GetFrames(analysisData.nIdx);

      PROFILE_START(MOTION_PROFILE_INTERPOLATION);
      PMVGroupOfFrames pSrcGOF = pFrames->GetFrame(n);
      pSrcGOF->SetPlane(pSrcY, nSrcPitchY, YPLANE);
      pSrcGOF->SetPlane(pSrcU, nSrcPitchUV, UPLANE);
      pSrcGOF->SetPlane(pSrcV, nSrcPitchUV, VPLANE);
//      pSrcGOF->Reduce(); // disabled in v1.11.02 - we use top level only here
      pSrcGOF->Pad(YUVPLANES);

	  if (analysisData.usePelClip)
	  {
		  MVFrame *srcFrames = pSrcGOF->GetFrame(0);
		  MVPlane *srcPlaneY = srcFrames->GetPlane(YPLANE);
		  srcPlaneY->RefineExt(pSrc2xY, nSrc2xPitchY);
		  MVPlane *srcPlaneU = srcFrames->GetPlane(UPLANE);
		  srcPlaneU->RefineExt(pSrc2xU, nSrc2xPitchUV);
		  MVPlane *srcPlaneV = srcFrames->GetPlane(VPLANE);
		  srcPlaneV->RefineExt(pSrc2xV, nSrc2xPitchUV);
	  }
	  else
		  pSrcGOF->Refine(YUVPLANES, analysisData.sharp);


      PMVGroupOfFrames pRefGOF = pFrames->GetFrame(n + offset);
      pRefGOF->SetPlane(pRefY, nRefPitchY, YPLANE);
      pRefGOF->SetPlane(pRefU, nRefPitchUV, UPLANE);
      pRefGOF->SetPlane(pRefV, nRefPitchUV, VPLANE);
//      pRefGOF->Reduce();
      pRefGOF->Pad(YUVPLANES);

	  if (analysisData.usePelClip)
	  {
		  MVFrame *refFrames = pRefGOF->GetFrame(0);
		  MVPlane *refPlaneY = refFrames->GetPlane(YPLANE);
		  refPlaneY->RefineExt(pRef2xY, nRef2xPitchY);
		  MVPlane *refPlaneU = refFrames->GetPlane(UPLANE);
		  refPlaneU->RefineExt(pRef2xU, nRef2xPitchUV);
		  MVPlane *refPlaneV = refFrames->GetPlane(VPLANE);
		  refPlaneV->RefineExt(pRef2xV, nRef2xPitchUV);
	  }
	  else
	      pRefGOF->Refine(YUVPLANES, analysisData.sharp);

      PROFILE_STOP(MOTION_PROFILE_INTERPOLATION);
*/
	  if (outfile != NULL) {
			fwrite( &n, sizeof( int ), 1, outfile );// write frame number
	  }


      pSrcGOF->Update(nModeYUV, (BYTE*)pSrcY, nSrcPitchY, (BYTE*)pSrcU, nSrcPitchUV, (BYTE*)pSrcV, nSrcPitchUV); // v2.0
      pRefGOF->Update(nModeYUV, (BYTE*)pRefY, nRefPitchY, (BYTE*)pRefU, nRefPitchUV, (BYTE*)pRefV, nRefPitchUV); // v2.0


      vectorFields->RecalculateMVs(mvClip, pSrcGOF, pRefGOF, searchType, nSearchParam, nLambda, lsad, pnew,
		  analysisData.nFlags, reinterpret_cast<int*>(pDst), outfilebuf, fieldShift, thSAD, DCTc, smooth);

    if (divideExtra) {
      // make extra level with divided sublocks with median (not estimated) motion
      vectorFields->ExtraDivide(reinterpret_cast<int*>(pDst), analysisData.nFlags);
    }

//      PROFILE_CUMULATE();
		if (outfile != NULL)
			fwrite( outfilebuf, sizeof(short)* analysisData.nBlkX*analysisData.nBlkY*4, 1, outfile );

	}
	else
	{
		vectorFields->WriteDefaultToArray(reinterpret_cast<int*>(pDst));
	}

	return dst;
}