MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
mythtv/libs/libmythtv/visualisations/goom/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, y, dx, dy, yy, xx; // am, tmp;
48  int *p;
49 
50 
51  if ((y1 < 0) || (y2 < 0) || (x1 < 0) || (x2 < 0) || (y1 >= screeny) || (y2 >= screeny) || (x1 >= screenx) || (x2 >= screenx))
52  return;
53 
54  dx = x2 - x1;
55  dy = y2 - y1;
56  if (x1 > x2) {
57  int tmp;
58 
59  tmp = x1;
60  x1 = x2;
61  x2 = tmp;
62  tmp = y1;
63  y1 = y2;
64  y2 = tmp;
65  dx = x2 - x1;
66  dy = y2 - y1;
67  }
68 
69  /* vertical line */
70  if (dx == 0) {
71  if (y1 < y2) {
72  p = &(data[(screenx * y1) + x1]);
73  for (y = y1; y <= y2; y++) {
74  DRAWMETHOD;
75  p += screenx;
76  }
77  }
78  else {
79  p = &(data[(screenx * y2) + x1]);
80  for (y = y2; y <= y1; y++) {
81  DRAWMETHOD;
82  p += screenx;
83  }
84  }
85  return;
86  }
87  /* horizontal line */
88  if (dy == 0) {
89  if (x1 < x2) {
90  p = &(data[(screenx * y1) + x1]);
91  for (x = x1; x <= x2; x++) {
92  DRAWMETHOD;
93  p++;
94  }
95  return;
96  }
97  else {
98  p = &(data[(screenx * y1) + x2]);
99  for (x = x2; x <= x1; x++) {
100  DRAWMETHOD;
101  p++;
102  }
103  return;
104  }
105  }
106  /* 1 */
107 
108  /* 2 */
109  if (y2 > y1) {
110  /* steep */
111  if (dy > dx) {
112  dx = ((dx << 16) / dy);
113  x = x1 << 16;
114  for (y = y1; y <= y2; y++) {
115  xx = x >> 16;
116  p = &(data[(screenx * y) + xx]);
117  DRAWMETHOD;
118  if (xx < (screenx - 1)) {
119  p++;
120  }
121  x += dx;
122  }
123  return;
124  }
125  /* shallow */
126  else {
127  dy = ((dy << 16) / dx);
128  y = y1 << 16;
129  for (x = x1; x <= x2; x++) {
130  yy = y >> 16;
131  p = &(data[(screenx * yy) + x]);
132  DRAWMETHOD;
133  if (yy < (screeny - 1)) {
134  p += screeny;
135  }
136  y += dy;
137  }
138  }
139  }
140  /* 2 */
141 
142  /* 1 */
143  else {
144  /* steep */
145  if (-dy > dx) {
146  dx = ((dx << 16) / -dy);
147  x = (x1 + 1) << 16;
148  for (y = y1; y >= y2; y--) {
149  xx = x >> 16;
150  p = &(data[(screenx * y) + xx]);
151  DRAWMETHOD;
152  if (xx < (screenx - 1)) {
153  p--;
154  }
155  x += dx;
156  }
157  return;
158  }
159  /* shallow */
160  else {
161  dy = ((dy << 16) / dx);
162  y = y1 << 16;
163  for (x = x1; x <= x2; x++) {
164  yy = y >> 16;
165  p = &(data[(screenx * yy) + x]);
166  DRAWMETHOD;
167  if (yy < (screeny - 1)) {
168  p += screeny;
169  }
170  y += dy;
171  }
172  return;
173  }
174  }
175 }
176 #endif
177 
178 #endif