r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / quicktime / decore50 / gen_draw.c
bloba223c3e3936b9bd1ecc4364d5b342ac0b51c05c1
1 // gen_draw.c //
3 #include "mp4_decoder.h"
5 #include "gen_draw.h"
7 /**
9 **/
11 extern int MV[2][6][MBR+1][MBC+2]; // motion vectors
12 extern int modemap[MBR+1][MBC+2]; // macroblock modes
14 /***/
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);
20 /***/
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;
26 int mb_xpos, mb_ypos;
27 int bnum;
29 mb_xsize = xsize>>4;
30 mb_ysize = ysize>>4;
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);
42 break;
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);
50 break;
51 default:
52 break;
58 /***/
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)
63 int mvx, mvy;
64 int xpos = mb_xpos<<4;
65 int ypos = mb_ypos<<4;
67 if (bnum == -1) {
68 xpos += 8;
69 ypos += 8;
70 bnum = 0; // retrieve correct block number for MV extraction
72 else {
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);
83 /***/
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) {
88 int y1 = y0 + dy;
89 int x1 = x0 + dx;
90 int stepx, stepy;
91 int fraction;
93 if (dy < 0) {
94 dy = -dy; stepy = -stride;
96 else {
97 stepy = stride;
99 if (dx < 0) {
100 dx = -dx; stepx = -1;
101 } else {
102 stepx = 1;
105 // retrieve pixel coord
106 dy <<= 1;
107 dx <<= 1;
109 // retrieve image coordinates
110 y0 *= stride;
111 y1 *= stride;
113 check_and_colour(buff, x0, y0, xsize, ysize, colour);
114 if (dx > dy) {
115 fraction = dy - (dx >> 1);
116 while (x0 != x1) {
117 if (fraction >= 0) {
118 y0 += stepy;
119 fraction -= dx;
121 x0 += stepx;
122 fraction += dy;
123 check_and_colour(buff, x0, y0, xsize, ysize, colour);
125 } else {
126 fraction = dx - (dy >> 1);
127 while (y0 != y1) {
128 if (fraction >= 0) {
129 x0 += stepx;
130 fraction -= dy;
132 y0 += stepy;
133 fraction += dx;
134 check_and_colour(buff, x0, y0, xsize, ysize, colour);
139 /***/
141 static void check_and_colour(unsigned char *buff, int x0, int y0, int xsize, int ysize, char colour)
143 if (x0 < 0)
144 return;
145 if (x0 > xsize)
146 return;
147 if (y0 < 0)
148 return;
149 if (y0 > (xsize*(ysize-1)))
150 return;
152 buff[x0+y0] = colour;