3 #include "mp4_decoder.h"
11 extern int MV
[2][6][MBR
+1][MBC
+2]; // motion vectors
12 extern int modemap
[MBR
+1][MBC
+2]; // macroblock modes
16 static void colorBlock_mv(unsigned char *buff
, int stride
, int mb_xpos
, int mb_ypos
, int bnum
, int xsize
, int ysize
);
17 static void drawline(int stride
, int x0
, int y0
, int dx
, int dy
, unsigned char *buff
, char colour
, int xsize
, int ysize
);
18 static void check_and_colour(unsigned char *buff
, int x0
, int y0
, int xsize
, int ysize
, char colour
);
22 // Purpose: draw motion vectors in a displayable buffer
23 void colorBuffer_mv(unsigned char *buff
, int stride
, int xsize
, int ysize
)
25 int mb_xsize
, mb_ysize
;
32 for (mb_ypos
= 0; mb_ypos
< mb_ysize
; mb_ypos
++)
34 for (mb_xpos
= 0; mb_xpos
< mb_xsize
; mb_xpos
++)
36 switch (modemap
[mb_xpos
+1][mb_ypos
+1])
38 case MODE_INTER
: case MODE_INTER_Q
:
40 colorBlock_mv(buff
, stride
, mb_xpos
, mb_ypos
, -1, xsize
, ysize
);
43 case MODE_INTER4V
: case MODE_INTER4V_Q
:
45 for (bnum
= 0; bnum
< 4; bnum
++)
47 colorBlock_mv(buff
, stride
, mb_xpos
, mb_ypos
, bnum
, xsize
, ysize
);
60 // Purpose: draw motion vector for this block, bnum is -1 if it's an entire macroblock
61 static void colorBlock_mv(unsigned char *buff
, int stride
, int mb_xpos
, int mb_ypos
, int bnum
, int xsize
, int ysize
)
64 int xpos
= mb_xpos
<<4;
65 int ypos
= mb_ypos
<<4;
70 bnum
= 0; // retrieve correct block number for MV extraction
73 xpos
+= (bnum
& 1) ? 12 : 4;
74 ypos
+= (bnum
& 2) ? 12 : 4;
77 mvx
= MV
[0][bnum
][mb_xpos
+1][mb_ypos
+1];
78 mvy
= MV
[1][bnum
][mb_xpos
+1][mb_ypos
+1];
80 drawline(stride
, xpos
, ypos
, mvx
, mvy
, buff
, 0, xsize
, ysize
);
85 // John Funnell < johnf@mail.nu >
86 // Purpose: line drawing function - pilfered from the Net
87 static void drawline(int stride
, int x0
, int y0
, int dx
, int dy
, unsigned char *buff
, char colour
, int xsize
, int ysize
) {
94 dy
= -dy
; stepy
= -stride
;
100 dx
= -dx
; stepx
= -1;
105 // retrieve pixel coord
109 // retrieve image coordinates
113 check_and_colour(buff
, x0
, y0
, xsize
, ysize
, colour
);
115 fraction
= dy
- (dx
>> 1);
123 check_and_colour(buff
, x0
, y0
, xsize
, ysize
, colour
);
126 fraction
= dx
- (dy
>> 1);
134 check_and_colour(buff
, x0
, y0
, xsize
, ysize
, colour
);
141 static void check_and_colour(unsigned char *buff
, int x0
, int y0
, int xsize
, int ysize
, char colour
)
149 if (y0
> (xsize
*(ysize
-1)))
152 buff
[x0
+y0
] = colour
;