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#include "libmythbase/mythconfig.h"
6
7#define DRAWMETHOD_NORMAL(adr,col) {*(adr) = (col);}
8
9#if HAVE_MMX
10#include "mmx.h"
11
12#define DRAWMETHOD_PLUS(_out,_backbuf,_col) \
13{\
14movd_m2r (_backbuf, mm0); \
15paddusb_m2r (_col, mm0); \
16movd_r2m (mm0, _out); \
17}
18
19#else
20#define DRAWMETHOD_PLUS(_out,_backbuf,_col) \
21{\
22 int tra=0;\
23 int i=0;\
24 unsigned char *bra = (unsigned char*)&(_backbuf);\
25 unsigned char *dra = (unsigned char*)&(_out);\
26 unsigned char *cra = (unsigned char*)&(_col);\
27 for (;i<4;i++) {\
28 tra = *cra;\
29 tra += *bra;\
30 if (tra>255) tra=255;\
31 *dra = tra;\
32 ++dra;++cra;++bra;\
33 }\
34}
35#endif
36
37#define DRAWMETHOD_OR(adr,col) {*(adr)|=(col);}
38
39#if HAVE_MMX
40#define DRAWMETHOD_DONE() {__asm__ __volatile__ ("emms");}
41#else
42#define DRAWMETHOD_DONE() {}
43#endif
44
45#ifndef DRAWMETHOD
46#define DRAWMETHOD DRAWMETHOD_PLUS(*p,*p,col)
47
48static void draw_line (int *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny) {
49 int x = 0; // am, tmp
50 int y = 0;
51 int dx = 0;
52 int dy = 0;
53 int *p = nullptr;
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++) {
78 p += screenx;
79 }
80 }
81 else {
82 p = &(data[(screenx * y2) + x1]);
83 for (y = y2; y <= y1; y++) {
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++) {
96 p++;
97 }
98 return;
99 }
100 p = &(data[(screenx * y1) + x2]);
101 for (x = x2; x <= x1; x++) {
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 int xx = x >> 16;
117 p = &(data[(screenx * y) + xx]);
119#if 0
120 if (xx < (screenx - 1)) {
121 p++;
122 }
123#endif
124 x += dx;
125 }
126 return;
127 }
128 /* shallow */
129 dy = ((dy << 16) / dx);
130 y = y1 << 16;
131 for (x = x1; x <= x2; x++) {
132 int yy = y >> 16;
133 p = &(data[(screenx * yy) + x]);
135 y += dy;
136 }
137 }
138 /* 2 */
139
140 /* 1 */
141 else {
142 /* steep */
143 if (-dy > dx) {
144 dx = ((dx << 16) / -dy);
145 x = (x1 + 1) << 16;
146 for (y = y1; y >= y2; y--) {
147 int xx = x >> 16;
148 p = &(data[(screenx * y) + xx]);
150#if 0
151 if (xx < (screenx - 1)) {
152 p--;
153 }
154#endif
155 x += dx;
156 }
157 return;
158 }
159 /* shallow */
160 dy = ((dy << 16) / dx);
161 y = y1 << 16;
162 for (x = x1; x <= x2; x++) {
163 int yy = y >> 16;
164 p = &(data[(screenx * yy) + x]);
166 y += dy;
167 }
168 return;
169 }
170}
171#endif
172
173#endif // DRAWMETHODS_H
static void draw_line(int *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny)
Definition: drawmethods.h:48
#define DRAWMETHOD
Definition: drawmethods.h:46
static int x1
Definition: mythsocket.cpp:54
static int x2
Definition: mythsocket.cpp:55