1 /* grlib.c - skeleton svgalib
2 Copyright (C) 1996-2017 Paul Sheer
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307, USA.
18 */
19
20 #include <config.h>
21
22 /* this is a stripped version of gl from svgalib-1.2.10
23 just to provide dummy setcontext, getcontext
24 and clip functions. It does nothing else really. */
25
26 /* It bares a vague resemblance to : */
27
28 /* Framebuffer Graphics Libary for Linux, Copyright 1993 Harm Hanemaayer */
29 /* grlib.c Main module */
30
31
32 #include <stdlib.h>
33 #include <my_string.h>
34 #include "vgagl.h"
35 #include "mad.h"
36
37
38 #define uchar unsigned char
39 #define swap(x, y) { int temp = x; x = y; y = temp; }
40 #define swapb(x, y) { uchar temp = x; x = y; y = temp; }
41 #define max(x, y) ((x > y) ? x : y)
42 #define min(x, y) ((x > y) ? y : x)
43 #define outside(x, y) (x < __clipx1 || x > __clipx2 || y < __clipy1 \
44 || y > __clipy2)
45 #define x_outside(x) (x < __clipx1 || x > __clipx2)
46 #define y_outside(y) (y < __clipy1 || y > __clipy2)
47 #define clipxleft(x) if (x < __clipx1) x = __clipx1;
48 #define clipxright(x) if (x > __clipx2) x = __clipx2;
49 #define clipytop(y) if (y < __clipy1) y = __clipy1;
50 #define clipybottom(y) if (y > __clipy2) y = __clipy2;
51
52
53 #define setpixel (*(__currentcontext.ff.driver_setpixel_func))
54 #define getpixel (*(__currentcontext.ff.driver_getpixel_func))
55 #define hline (*(__currentcontext.ff.driver_hline_func))
56 #define fillbox (*(__currentcontext.ff.driver_fillbox_func))
57 #define putbox (*(__currentcontext.ff.driver_putbox_func))
58 #define getbox (*(__currentcontext.ff.driver_getbox_func))
59 #define putboxmask (*(__currentcontext.ff.driver_putboxmask_func))
60 #define putboxpart (*(__currentcontext.ff.driver_putboxpart_func))
61 #define getboxpart (*(__currentcontext.ff.driver_getboxpart_func))
62 #define copybox (*(__currentcontext.ff.driver_copybox_func))
63
64
65 #define __currentcontext currentcontext
66
67
68
69 /* Global variables */
70
71 GraphicsContext currentcontext;
72
73 /* Initialization and graphics contexts */
74
gl_setcontextvirtual(int w,int h,int bpp,int bitspp,void * v)75 void gl_setcontextvirtual(int w, int h, int bpp, int bitspp, void *v)
76 {
77 memset(¤tcontext, 0, sizeof(GraphicsContext));
78 WIDTH = w;
79 HEIGHT = h;
80 BYTESPERPIXEL = bpp;
81 BITSPERPIXEL = bitspp;
82 COLORS = 1 << bitspp;
83 BYTEWIDTH = WIDTH * BYTESPERPIXEL;
84 VBUF = v;
85 MODETYPE = CONTEXT_VIRTUAL;
86 MODEFLAGS = 0;
87 __clip = 0;
88 }
89
gl_allocatecontext()90 GraphicsContext * gl_allocatecontext()
91 {
92 return malloc(sizeof(GraphicsContext));
93 }
94
gl_setcontext(GraphicsContext * gc)95 void gl_setcontext(GraphicsContext * gc)
96 {
97 currentcontext = *gc;
98 }
99
gl_getcontext(GraphicsContext * gc)100 void gl_getcontext(GraphicsContext * gc)
101 {
102 *gc = __currentcontext;
103 }
104
gl_freecontext(GraphicsContext * gc)105 void gl_freecontext(GraphicsContext * gc)
106 {
107 if (gc->modetype == CONTEXT_VIRTUAL)
108 free(gc->vbuf);
109 }
110
gl_setcontextwidth(int w)111 void gl_setcontextwidth(int w)
112 {
113 __currentcontext.width = currentcontext.width = w;
114 __currentcontext.bytewidth = currentcontext.bytewidth =
115 w * BYTESPERPIXEL;
116 }
117
gl_setcontextheight(int h)118 void gl_setcontextheight(int h)
119 {
120 __currentcontext.height = currentcontext.height = h;
121 }
122
123
124 /* Clipping */
125
gl_setclippingwindow(int x1,int y1,int x2,int y2)126 void gl_setclippingwindow(int x1, int y1, int x2, int y2)
127 {
128 __clip = 1;
129 __clipx1 = x1;
130 __clipy1 = y1;
131 __clipx2 = x2;
132 __clipy2 = y2;
133 }
134
gl_enableclipping()135 void gl_enableclipping()
136 {
137 __clip = 1;
138 __clipx1 = 0;
139 __clipy1 = 0;
140 __clipx2 = WIDTH - 1;
141 __clipy2 = HEIGHT - 1;
142 }
143
gl_disableclipping()144 void gl_disableclipping()
145 {
146 __clip = 0;
147 }
148
149
gl_setpixel(int x,int y,int c)150 void gl_setpixel(int x, int y, int c)
151 {
152 return;
153 }
154
gl_line(int x1,int y1,int x2,int y2,int c)155 void gl_line(int x1, int y1, int x2, int y2, int c)
156 {
157 return;
158 }
159