Advertisement
Guest User

Untitled

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