[go: up one dir, main page]

File: cbitmap.c

package info (click to toggle)
svgalib 1%3A1.4.3-33
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,012 kB
  • sloc: ansic: 60,381; makefile: 1,138; asm: 630; sh: 86; perl: 54; pascal: 49
file content (186 lines) | stat: -rw-r--r-- 4,182 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* Framebuffer Graphics Libary for Linux, Copyright 1993 Harm Hanemaayer */
/* cbitmap.c    Compiled bitmaps */


#include <stdio.h>
#include <stdlib.h>
#include <vga.h>
#include "inlstring.h"		/* include inline string operations */

#include "vgagl.h"
#include "def.h"



void gl_compileboxmask(int w, int h, void *_dp1, void *_dp2)
{
/* Compiled format: <bytes_to_skip (0-254)><number_of_pixels (0-255)> */
/*                  <pixel_data>[<end_of_line(255)>]... */
    uchar *dp1 = _dp1;
    uchar *dp2 = _dp2;
    int i;
    for (i = 0; i < h; i++) {
	int x = 0;
	while (x < w) {
	    int count;
	    /* count zeroes */
	    count = 0;
	    while (x < w && *(dp1 + count) == 0 && count < 254) {
		count++;
		x++;
	    }
	    dp1 += count;
	    if (x < w) {
		*dp2++ = count;
		/* count nonzeroes */
		count = 0;
		while (x < w && *(dp1 + count) != 0 && count < 255) {
		    *(dp2 + count + 1) = *(dp1 + count);
		    count++;
		    x++;
		}
		*dp2 = count;
		dp2 += count + 1;
		dp1 += count;
	    }
	}
	*dp2++ = 0xff;
    }
}

int gl_compiledboxmasksize(int w, int h, void *_dp1)
{
/* Compiled format: <bytes_to_skip (0-254)><number_of_pixels (0-255)> */
/*                  <pixel_data>[<end_of_line(255)>]... */
    uchar *dp1 = _dp1;
    int size = 0;
    int i;
    for (i = 0; i < h; i++) {
	int x = 0;
	while (x < w) {
	    int count;
	    /* count zeroes */
	    count = 0;
	    while (x < w && *(dp1 + count) == 0 && count < 254) {
		count++;
		x++;
	    }
	    size++;
	    dp1 += count;
	    /* count nonzeroes */
	    if (x < w) {
		count = 0;
		while (x < w && *(dp1 + count) != 0 && count < 255) {
		    count++;
		    x++;
		}
		size += count + 1;
		dp1 += count;
	    }
	}
	size++;
    }
    return size;
}

static void gl_putboxmaskcompiledclip(int nx, int ny, int nw, int nh, int _x,
				      int _y, int w, int h, void *_dp)
{
/* Special case costly clipping */
    uchar *dp = _dp;
    uchar *vp, *vpline;
    int y;
    vpline = VBUF + _y * BYTEWIDTH + _x;
    for (y = _y; y < ny + nh; y++) {
	int x = _x;
	vp = vpline;
	for (;;) {
	    int count = *dp++;
	    if (count == 0xff)
		break;		/* end of line */
	    vp += count;
	    x += count;
	    count = *dp++;
	    /* __memcpy gives severe bug here */
	    if (y >= ny) {
		if (x >= nx)
		    if (x + count > __clipx2 + 1) {
			if (x <= __clipx2)
			    __memcpyb(vp, dp, __clipx2 - x + 1);
		    } else
			__memcpyb(vp, dp, count);
		else if (x + count > __clipx1) {
		    if (x + count > __clipx2 + 1)
			__memcpyb(vp + __clipx1 - x,
				  dp + __clipx1 - x,
				  __clipx2 - __clipx1 + 1);
		    else
			__memcpy(vp + __clipx1 - x,
				 dp + __clipx1 - x,
				 count - __clipx1 + x);
                };
            };
	    x += count;
	    vp += count;
	    dp += count;
	}
	vpline += BYTEWIDTH;
    }
}

#define ADJUSTBITMAPBOX() \
	nw = w; nh = h; nx = x; ny = y;				\
	if (nx + nw < __clipx1 || nx > __clipx2)		\
		return;						\
	if (ny + nh < __clipy1 || ny > __clipy2)		\
		return;						\
	if (nx < __clipx1) {		/* left adjust */	\
		nw += nx - __clipx1;				\
		nx = __clipx1;					\
	}							\
	if (ny < __clipy1) {		/* top adjust */	\
		nh += ny - __clipy1;				\
		ny = __clipy1;					\
	}							\
	if (nx + nw > __clipx2)		/* right adjust */	\
		nw = __clipx2 - nx + 1;				\
	if (ny + nh > __clipy2)		/* bottom adjust */	\
		nh = __clipy2 - ny + 1;				\


void gl_putboxmaskcompiled(int x, int y, int w, int h, void *_dp)
{
/* no clipping */
    uchar *dp = _dp;
    uchar *vp, *vpline;
    int i;
    if (MODETYPE != CONTEXT_LINEAR && MODETYPE != CONTEXT_VIRTUAL) {
	printf("vgagl: putboxmaskcompiled only supported in linear framebuffer\n");
	return;
    }
    if (__clip) {
	int nx, ny, nw, nh;
	ADJUSTBITMAPBOX();
	if (nw != w || nh != h) {
	    gl_putboxmaskcompiledclip(nx, ny, nw, nh, x, y, w, h,
				      dp);
	    return;
	}
    }
    vpline = VBUF + y * BYTEWIDTH + x;
    for (i = 0; i < h; i++) {
	vp = vpline;
	for (;;) {
	    int count = *dp++;
	    if (count == 0xff)
		break;		/* end of line */
	    vp += count;
	    count = *dp++;
	    /* __memcpy gives severe bug here */
	    __memcpyb(vp, dp, count);
	    vp += count;
	    dp += count;
	}
	vpline += BYTEWIDTH;
    }
}