cmisip
Posts: 100
Joined: Tue Aug 25, 2015 12:38 am

Indexing into the motion vector array in C++

Sat Sep 15, 2018 9:23 pm

I want to make sure that I am properly assigning coordinates to the motion vector frames. This is what I am doing.

Get the number of macroblocks. For a 640x360 frame:

Code: Select all

    int frame_width=monitor->Width()+16;  //add the extra column, resulting in 656
    int frame_height=((monitor->Height()+16)/16)*16;  //make sure the height is a multiple of 16, resulting in 368
    int numblocks= (frame_width*frame_height)/256;  //divide by 16*16;
 


Assign the coordinates of the macroblocks top left pixel.
The vectors come in as an array of size numblocks of 4 bytes each. The first macroblock is top left, then in sequence left to right, then go down one row and then go left to right again, and so on.

Code: Select all

   coords=(Coord*)zm_mallocaligned(32,sizeof(Coord)*numblocks);
   for ( int i=0; i< numblocks; i++) {
	   coords[i].X()=(i*16) % (frame_width);  //frame_width already has +16 for the extra column
	   coords[i].Y()=((i*16)/(frame_width))*16;	
	}	
Is this correct?

Thanks,
Chris

pkfox
Posts: 24
Joined: Thu Oct 11, 2012 8:22 am

Re: Indexing into the motion vector array in C++

Thu Sep 27, 2018 6:22 am

I take it X and Y are struct or class members ? why are you using () to assign a value ?

cmisip
Posts: 100
Joined: Tue Aug 25, 2015 12:38 am

Re: Indexing into the motion vector array in C++

Fri Sep 28, 2018 1:07 am

I needed to change the value of private members of Coord class from another class that is neither a friend or derived. That line is a Coord class public member function call that returns a reference to the private member x or y that is assignable a value ( can be on the left side of an assignment operator ).

I can confirm also that the code for indexing into the macroblock array is correct.

Chris

Return to “Advanced users”