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 yy = 0;
52  int xx = 0;
53  int *p = NULL;
54 
55 
56  if ((y1 < 0) || (y2 < 0) || (x1 < 0) || (x2 < 0) || (y1 >= screeny) || (y2 >= screeny) || (x1 >= screenx) || (x2 >= screenx))
57  return;
58 
59  dx = x2 - x1;
60  dy = y2 - y1;
61  if (x1 > x2) {
62  int tmp = x1;
63  x1 = x2;
64  x2 = tmp;
65  tmp = y1;
66  y1 = y2;
67  y2 = tmp;
68  dx = x2 - x1;
69  dy = y2 - y1;
70  }
71 
72  /* vertical line */
73  if (dx == 0) {
74  if (y1 < y2) {
75  p = &(data[(screenx * y1) + x1]);
76  for (y = y1; y <= y2; y++) {
77  DRAWMETHOD;
78  p += screenx;
79  }
80  }
81  else {
82  p = &(data[(screenx * y2) + x1]);
83  for (y = y2; y <= y1; y++) {
84  DRAWMETHOD;
85  p += screenx;
86  }
87  }
88  return;
89  }
90  /* horizontal line */
91  if (dy == 0) {
92  if (x1 < x2) {
93  p = &(data[(screenx * y1) + x1]);
94  for (x = x1; x <= x2; x++) {
95  DRAWMETHOD;
96  p++;
97  }
98  return;
99  }
100  p = &(data[(screenx * y1) + x2]);
101  for (x = x2; x <= x1; x++) {
102  DRAWMETHOD;
103  p++;
104  }
105  return;
106  }
107  /* 1 */
108 
109  /* 2 */
110  if (y2 > y1) {
111  /* steep */
112  if (dy > dx) {
113  dx = ((dx << 16) / dy);
114  x = x1 << 16;
115  for (y = y1; y <= y2; y++) {
116  xx = x >> 16;
117  p = &(data[(screenx * y) + xx]);
118  DRAWMETHOD;
119  if (xx < (screenx - 1)) {
120  p++;
121  }
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  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  xx = x >> 16;
146  p = &(data[(screenx * y) + xx]);
147  DRAWMETHOD;
148  if (xx < (screenx - 1)) {
149  p--;
150  }
151  x += dx;
152  }
153  return;
154  }
155  /* shallow */
156  dy = ((dy << 16) / dx);
157  y = y1 << 16;
158  for (x = x1; x <= x2; x++) {
159  yy = y >> 16;
160  p = &(data[(screenx * yy) + x]);
161  DRAWMETHOD;
162  y += dy;
163  }
164  return;
165  }
166 }
167 #endif
168 
169 #endif
#define NULL
Definition: H264Parser.h:62
static guint32 * tmp
Definition: goom_core.c:35
static int x2
Definition: mythsocket.cpp:61
static void draw_line(int *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny)
Definition: drawmethods.h:46
#define DRAWMETHOD
Definition: drawmethods.h:44
static int x1
Definition: mythsocket.cpp:60