Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct Block16x16
- {
- BYTE data[16][16];
- } Block16x16;
- //Compute_SAD
- // computes sad value between two blocks
- //Input 16x16 block1
- //Output 16x16 block2
- //return int sadValue
- int Compute_SAD(BYTE block1[16][16], BYTE block2[16][16])
- {
- int sadValue = 0;
- for (int i = 0; i < 16; i++)
- {
- for (int j = 0; j < 16; j++)
- {
- BYTE value1 = block1[i][j];
- BYTE value2 = block2[i][j];
- sadValue += abs(value1 - value2);
- }
- }
- return sadValue;
- }
- //startI, startJ are assumed to be multiples of 16
- Block16x16 get16x16Block(BYTE *frame, int frameWidth, int startI, int startJ)
- {
- Block16x16 block;
- for (int j = 0; j < 16; j++)
- {
- for (int i = 0; i < 16; i++)
- {
- block.data[i][j] = *(frame + (startI + i) + (startJ + j) * frameWidth);
- }
- }
- return block;
- }
- // Compute_MV
- // computes motionVector
- // Input 8x8 block [Y/U/V]
- // Output 8x8 Iframe[YFrame,UFrame,VFrame]
- MV Compute_MV(Block16x16 block, BYTE *frame)
- {
- int offset = 0;
- int maxWidth = Y_frame_width;
- int maxHeight = Y_frame_height;
- int minValue = 65535;
- BYTE minI = 0, minJ = 0;
- for (int macroblock_Ypos = 0; macroblock_Ypos < maxHeight; macroblock_Ypos += 16)
- {
- for (int macroblock_Xpos = 0; macroblock_Xpos < maxWidth; macroblock_Xpos += 16)
- {
- Block16x16 frameBlock = get16x16Block(frame, maxWidth, macroblock_Xpos, macroblock_Ypos);
- int sad = Compute_SAD(block.data, frameBlock.data);
- if (sad < minValue)
- {
- minI = macroblock_Xpos;
- minJ = macroblock_Ypos;
- minValue = sad;
- }
- }
- }
- MV mv = {(MyDataSize)(minI/16), (MyDataSize)(minJ/16)};
- return mv;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement