Debian Codegraph @

plugins/actor/oinksie/gfx-misc.c

raw
1 /* Libvisual-plugins - Standard plugins for libvisual
2 *
3 * Copyright (C) 2002, 2003, 2004, 2005, 2006 Dennis Smit <[email protected]>
4 *
5 * Authors: Dennis Smit <[email protected]>
6 *
7 * $Id: gfx-misc.c,v 1.9 2006/01/31 16:42:47 synap Exp $
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <string.h>
25
26 #include <math.h>
27
28 #include "common.h"
29 #include "config.h"
30 #include "audio.h"
31 #include "table.h"
32 #include "screen.h"
33 #include "gfx-misc.h"
34
35 int _oink_gfx_pixel_get (OinksiePrivate *priv, uint8_t *buf, int x, int y)
36 {
37 int pos = (y * priv->screen_width) + x;
38
39 if (pos < priv->screen_size && pos > 0)
40 return buf[pos];
41
42 return 0;
43 }
44
45 void _oink_gfx_pixel_set (OinksiePrivate *priv, uint8_t *buf, int color, int x, int y)
46 {
47 int pos = (y * priv->screen_width) + x;
48
49 if (pos < priv->screen_size && pos > 0)
50 buf[pos] = color;
51
52 }
53
54 /* FIXME this routine shows errors */
55 void _oink_gfx_line (OinksiePrivate *priv, uint8_t *buf, int color, int x0, int y0, int x1, int y1)
56 {
57 register int dy = y1 - y0;
58 register int dx = x1 - x0;
59 register int stepx, stepy, stepy_;
60 register int fraction;
61 register int bp;
62 register int x;
63 register int y;
64
65 if (x0 < 0 || x0 > priv->screen_width - 1 || x1 < 0 || x1 > priv->screen_width - 1||
66 y0 < 0 || y0 > priv->screen_height - 1 || y1 < 0 || y1 > priv->screen_height - 1)
67 {
68 if (x0 < 0)
69 x0 = 0;
70 else if (x0 > priv->screen_width - 1)
71 x0 = priv->screen_width - 1;
72
73 if (x1 < 0)
74 x1 = 0;
75 else if (x1 > priv->screen_width - 1)
76 x1 = priv->screen_width - 1;
77
78 if (y0 < 0)
79 y0 = 0;
80 else if (y0 > priv->screen_height - 1);
81 y0 = priv->screen_height - 1;
82
83 if (y1 < 0)
84 y1 = 0;
85 else if (y1 > priv->screen_height - 1);
86 y1 = priv->screen_height - 1;
87
88 return; /* FIXME */
89 }
90
91 if (dy < 0)
92 {
93 dy = -dy;
94 stepy_ = -priv->screen_width;
95 stepy = -1;
96 }
97 else
98 {
99 stepy = 1;
100 stepy_ = priv->screen_width;
101 }
102
103 if (dx < 0)
104 {
105 dx = -dx;
106 stepx = -1;
107 }
108 else
109 {
110 stepx = 1;
111 }
112
113 dy <<= 1;
114 dx <<= 1;
115
116 bp = x0 + y0 * priv->screen_width;
117
118 _oink_gfx_pixel_set (priv, buf, color, x0, y0);
119
120 x = x0;
121 y = y0;
122
123 if (dx > dy)
124 {
125 fraction = dy - (dx >> 1);
126 while (x0 != x1)
127 {
128 if (fraction >= 0)
129 {
130 bp += stepy_;
131 fraction -= dx;
132 }
133 x0 += stepx;
134 bp += stepx;
135 fraction += dy;
136
137 buf[bp] = color;
138 }
139 }
140 else
141 {
142 fraction = dx - (dy >> 1);
143 while (y0 != y1)
144 {
145 if (fraction >= 0)
146 {
147 bp += stepx;
148 x0 += stepx;
149 fraction -= dy;
150 }
151 y0 += stepy;
152 bp += stepy_;
153 fraction += dx;
154
155 buf[bp] = color;
156 }
157 }
158 }
159
160 void _oink_gfx_hline (OinksiePrivate *priv, uint8_t *buf, int color, int y, int x1, int x2)
161 {
162 int firstx = x1 < x2 ? x1 : x2;
163 int endx = x1 > x2 ? x1 : x2;
164 int begin;
165
166 if (firstx > priv->screen_width - 1)
167 firstx = priv->screen_width - 1;
168 else if (firstx < 0)
169 firstx = 0;
170
171 if (endx > priv->screen_width - 1)
172 endx = priv->screen_width - 1;
173 else if (endx < 0)
174 endx = 0;
175
176 if (y < 0 || y > priv->screen_height - 1)
177 return;
178
179 if (firstx == endx)
180 {
181 _oink_gfx_pixel_set (priv, buf, color, firstx, y);
182 return;
183 }
184
185 begin = (y * priv->screen_width) + firstx;
186 visual_mem_set (buf + begin, color, endx - firstx);
187 }
188
189 void _oink_gfx_vline (OinksiePrivate *priv, uint8_t *buf, int color, int x, int y1, int y2)
190 {
191 int y;
192
193 if (y1 < y2)
194 {
195 for (y = y1; y <= y2; y++)
196 _oink_gfx_pixel_set (priv, buf, color, x, y);
197 }
198 else if (y2 < y1)
199 {
200 for (y = y2; y <= y1; y++)
201 _oink_gfx_pixel_set (priv, buf, color, x, y);
202 }
203 else
204 {
205 _oink_gfx_pixel_set (priv, buf, color, x, y1);
206 }
207 }
208
209 void _oink_gfx_circle_filled (OinksiePrivate *priv, uint8_t *buf, int color, int size, int x, int y)
210 {
211 int i;
212 int sizei = (size * PI) > 0 ? (size * PI) : 1;
213 int sini;
214 int cosi;
215
216 float adder = (float) ((float) OINK_TABLE_LARGE_SIZE / (float) sizei) / 4.00000;
217 float tab = 0;
218
219 for (i = 0; i < sizei; i++)
220 {
221 cosi = _oink_table_sinlarge[(int) tab] * size;
222 sini = _oink_table_coslarge[(int) tab] * size;
223
224 _oink_gfx_hline (priv, buf, color, cosi + y, -sini + x, sini + x);
225 _oink_gfx_hline (priv, buf, color, -cosi + y, -sini + x, sini + x);
226
227 tab += adder;
228 }
229 }
230
231 void _oink_gfx_circle (OinksiePrivate *priv, uint8_t *buf, int color, int xsize, int ysize, int x, int y)
232 {
233 int i;
234 int size = 300;
235
236 int tabx = OINK_TABLE_NORMAL_SIZE / size;
237 int taby = OINK_TABLE_NORMAL_SIZE / size;
238
239 for (i = 0; i < size; i++)
240 {
241 _oink_gfx_pixel_set (priv, buf, color, (int) (_oink_table_sin[i * tabx] * xsize) + x,
242 (int) (_oink_table_cos[i * taby] * ysize) + y);
243 }
244 }
245