Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. ypedef struct Block16x16
  2. {
  3.     BYTE data[16][16];
  4. } Block16x16;
  5.  
  6. typedef struct MV
  7. {
  8.     BYTE x;
  9.     BYTE y;
  10. } MV;
  11.  
  12. //Compute_SAD
  13. // computes sad value between two blocks
  14. //Input   16x16 block1
  15. //Output  16x16 block2
  16. //return  int sadValue
  17. int Compute_SAD(BYTE block1[16][16], BYTE block2[16][16])
  18. {
  19.     int sadValue = 0;
  20.     for (int i = 0; i < 16; i++)
  21.     {
  22.         for (int j = 0; j < 16; j++)
  23.         {
  24.             BYTE value1 = block1[i][j];
  25.             BYTE value2 = block2[i][j];
  26.             sadValue += abs(value1 - value2);
  27.         }
  28.     }
  29.     return sadValue;
  30. }
  31.  
  32. //startI, startJ are assumed to be multiples of 16
  33. Block16x16 get16x16Block(BYTE *frame, int frameWidth, int startI, int startJ)
  34. {
  35.     Block16x16 block;
  36.     for (int j = 0; j < 16; j++)
  37.     {
  38.         for (int i = 0; i < 16; i++)
  39.         {
  40.             block.data[i][j] = *(frame + (startI + i) + (startJ + j) * frameWidth);
  41.         }
  42.     }
  43.     return block;
  44. }
  45.  
  46. // Compute_MV
  47. // computes motionVectors
  48. // Input   16*16 block
  49. // frame  redframe[YFrame,UFrame,VFrame]
  50. // output returns motion vectors like {0,1}
  51. MV Compute_MV(Block16x16 block, BYTE *frame)
  52. {
  53.     int offset = 0;
  54.     int maxWidth = Y_frame_width;
  55.     int maxHeight = Y_frame_height;    
  56.     int minValue = 65535;
  57.     BYTE minI = 0, minJ = 0;
  58.  
  59.     for (int macroblock_Ypos = 0; macroblock_Ypos < maxHeight; macroblock_Ypos += 16)
  60.     {
  61.         for (int macroblock_Xpos = 0; macroblock_Xpos < maxWidth; macroblock_Xpos += 16)
  62.         {
  63.             Block16x16 frameBlock = get16x16Block(frame, maxWidth, macroblock_Xpos, macroblock_Ypos);
  64.             int sad = Compute_SAD(block.data, frameBlock.data);
  65.             if (sad < minValue)
  66.             {
  67.                 minI = macroblock_Xpos;
  68.                 minJ = macroblock_Ypos;
  69.                 minValue = sad;
  70.             }
  71.         }
  72.     }
  73.  
  74.     MV mv = {(MyDataSize)(minI/16), (MyDataSize)(minJ/16)};
  75.     return mv;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement