MythTV  master
drawmethods.h
Go to the documentation of this file.
1 #ifndef DRAWMETHODS_H
2 #define DRAWMETHODS_H
3 
4 #include "goomconfig.h"
5 
6 #define DRAWMETHOD_NORMAL(adr,col) {*(adr) = (col);}
7 
8 #ifdef MMX
9 #include "mmx.h"
10 
11 #define DRAWMETHOD_PLUS(_out,_backbuf,_col) \
12 {\
13 movd_m2r (_backbuf, mm0); \
14 paddusb_m2r (_col, mm0); \
15 movd_r2m (mm0, _out); \
16 }
17 
18 #else
19 #define DRAWMETHOD_PLUS(_out,_backbuf,_col) \
20 {\
21  int tra=0,i=0;\
22  unsigned char *bra = (unsigned char*)&(_backbuf);\
23  unsigned char *dra = (unsigned char*)&(_out);\
24  unsigned char *cra = (unsigned char*)&(_col);\
25  for (;i<4;i++) {\
26  tra = *cra;\
27  tra += *bra;\
28  if (tra>255) tra=255;\
29  *dra = tra;\
30  ++dra;++cra;++bra;\
31  }\
32 }
33 #endif
34 
35 #define DRAWMETHOD_OR(adr,col) {*(adr)|=(col);}
36 
37 #ifdef MMX
38 #define DRAWMETHOD_DONE() {__asm__ __volatile__ ("emms");}
39 #else
40 #define DRAWMETHOD_DONE() {}
41 #endif
42 
43 #ifndef DRAWMETHOD
44 #define DRAWMETHOD DRAWMETHOD_PLUS(*p,*p,col)
45 
46 static void draw_line (int *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny) {
47  int x = 0; // am, tmp
48  int y = 0;
49  int dx = 0;
50  int dy = 0;
51  int *p = nullptr;
52 
53 
54  if ((y1 < 0) || (y2 < 0) || (x1 < 0) || (x2 < 0) || (y1 >= screeny) || (y2 >= screeny) || (x1 >= screenx) || (x2 >= screenx))
55  return;
56 
57  dx = x2 - x1;
58  dy = y2 - y1;
59  if (x1 > x2) {
60  int tmp = x1;
61  x1 = x2;
62  x2 = tmp;
63  tmp = y1;
64  y1 = y2;
65  y2 = tmp;
66  dx = x2 - x1;
67  dy = y2 - y1;
68  }
69 
70  /* vertical line */
71  if (dx == 0) {
72  if (y1 < y2) {
73  p = &(data[(screenx * y1) + x1]);
74  for (y = y1; y <= y2; y++) {
75  DRAWMETHOD;
76  p += screenx;
77  }
78  }
79  else {
80  p = &(data[(screenx * y2) + x1]);
81  for (y = y2; y <= y1; y++) {
82  DRAWMETHOD;
83  p += screenx;
84  }
85  }
86  return;
87  }
88  /* horizontal line */
89  if (dy == 0) {
90  if (x1 < x2) {
91  p = &(data[(screenx * y1) + x1]);
92  for (x = x1; x <= x2; x++) {
93  DRAWMETHOD;
94  p++;
95  }
96  return;
97  }
98  p = &(data[(screenx * y1) + x2]);
99  for (x = x2; x <= x1; x++) {
100  DRAWMETHOD;
101  p++;
102  }
103  return;
104  }
105  /* 1 */
106 
107  /* 2 */
108  if (y2 > y1) {
109  /* steep */
110  if (dy > dx) {
111  dx = ((dx << 16) / dy);
112  x = x1 << 16;
113  for (y = y1; y <= y2; y++) {
114  int xx = x >> 16;
115  p = &(data[(screenx * y) + xx]);
116  DRAWMETHOD;
117 #if 0
118  if (xx < (screenx - 1)) {
119  p++;
120  }
121 #endif
122  x += dx;
123  }
124  return;
125  }
126  /* shallow */
127  dy = ((dy << 16) / dx);
128  y = y1 << 16;
129  for (x = x1; x <= x2; x++) {
130  int yy = y >> 16;
131  p = &(data[(screenx * yy) + x]);
132  DRAWMETHOD;
133  y += dy;
134  }
135  }
136  /* 2 */
137 
138  /* 1 */
139  else {
140  /* steep */
141  if (-dy > dx) {
142  dx = ((dx << 16) / -dy);
143  x = (x1 + 1) << 16;
144  for (y = y1; y >= y2; y--) {
145  int xx = x >> 16;
146  p = &(data[(screenx * y) + xx]);
147  DRAWMETHOD;
148 #if 0
149  if (xx < (screenx - 1)) {
150  p--;
151  }
152 #endif
153  x += dx;
154  }
155  return;
156  }
157  /* shallow */
158  dy = ((dy << 16) / dx);
159  y = y1 << 16;
160  for (x = x1; x <= x2; x++) {
161  int yy = y >> 16;
162  p = &(data[(screenx * yy) + x]);
163  DRAWMETHOD;
164  y += dy;
165  }
166  return;
167  }
168 }
169 #endif
170 
171 #endif // DRAWMETHODS_H
draw_line
static void draw_line(int *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny)
Definition: drawmethods.h:46
x2
static int x2
Definition: mythsocket.cpp:51
goomconfig.h
mmx.h
tmp
static guint32 * tmp
Definition: goom_core.cpp:26
hardwareprofile.config.p
p
Definition: config.py:33
x1
static int x1
Definition: mythsocket.cpp:50
DRAWMETHOD
#define DRAWMETHOD
Definition: drawmethods.h:44