File: hline.c

package info (click to toggle)
libggi 1%3A2.0.1-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,072 kB
  • ctags: 5,274
  • sloc: ansic: 42,720; sh: 6,508; makefile: 666
file content (171 lines) | stat: -rw-r--r-- 3,795 bytes parent folder | download | duplicates (2)
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
/* $Id: hline.c,v 1.1.1.1 2001/05/12 23:01:39 cegger Exp $
******************************************************************************

   Linear 1 horizontal lines.

   Copyright (C) 1995 Andreas Beck   [becka@ggi-project.org]
   Copyright (C) 1998 Andrew Apted  [andrew@ggi-project.org]

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
   IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************************************************
*/

#include "lin1lib.h"


int GGI_lin1_drawhline_nc(ggi_visual *vis,int x,int y,int w)
{
	uint8 *adr;
	int i,j,mask,color;

	PREPARE_FB(vis);

	color=(LIBGGI_GC_FGCOLOR(vis)&1)*0xFF;

	adr=((uint8 *)(LIBGGI_CURWRITE(vis)));
	adr+=(x/8+y*LIBGGI_FB_W_STRIDE(vis));

	/* Draw 'front' pixels */ 
	j=w;
	if ((i=x&7)) {
		if ((j=j+i-8)<=0) {
			mask=(0xff>>i)&(0xff<<-j); 
			*adr   = (*adr & ~mask) | (color & mask);
			return 0;
		} else {
			mask=(0xff>>i);
			*adr = (*adr & ~mask) | (color & mask);
			adr++;
		}
	}
	
	while ((j-=8)>=0) {
		*adr = color;
		adr++;
	}
    
	/* Draw `back` pixels if necessary */
	mask=~(0xff>>(j&7));
	*adr = (*adr & ~mask) | (color & mask);

	return 0;
}

int GGI_lin1_puthline(ggi_visual *vis,int x,int y,int w,void *buffer)
{ 
	uint8 *adr,*buff=(uint8 *)buffer;
	int mask,i,j,diff=0;
	uint8 foo,color;

	/* Clipping */
	if (y<(LIBGGI_GC(vis)->cliptl.y) || y>=(LIBGGI_GC(vis)->clipbr.y)) return 0;
	if (x< (LIBGGI_GC(vis)->cliptl.x)) {
		diff=(LIBGGI_GC(vis)->cliptl.x)-x;
		x+=diff;w-=diff;
		buff+=(diff>>3);diff&=7;
	}
	if (x+w>(LIBGGI_GC(vis)->clipbr.x)) {
		w=(LIBGGI_GC(vis)->clipbr.x)-x;
	}
	if (w<=0) return 0;

	PREPARE_FB(vis);

	adr=((uint8 *)(LIBGGI_CURWRITE(vis)));
	adr+=(x/8+y*LIBGGI_FB_W_STRIDE(vis));

	color=buff[0];
	if ((i=x&7)) {
		if ((j=w+i-8)<0) {
			mask=(0xff>>i)&(0xff<<-j); 
		} else {
			mask=0xff>>i;
		}

		foo = (*adr & ~mask);
		*adr = foo | ((color >> (i+=diff)) & mask);

		if (j<0)
			return 0;
		else
			adr++;
	} else
		j=w;i+=diff;

	while ((j-=8)>=0) {
		color <<= (8-i);
		color |= *(++buff) >> i;
		*adr = color;
	}

    
	if (j&=7) {
		color <<= (8-i);
		color |= *(++buff) >> i;

		mask=~(0xff>>j);
		foo = (*adr & ~mask);
		*adr = foo | ((color >> i) & mask);
	}
  
	return 0;
}

int GGI_lin1_gethline(ggi_visual *vis,int x,int y,int w,void *buffer)
{ 
	uint8 *adr,*buff=(uint8 *)buffer;
	int mask,i,j;
	uint8 color;

	PREPARE_FB(vis);

	adr=((uint8 *)(LIBGGI_CURREAD(vis)));
	adr+=(x/8+y*LIBGGI_FB_R_STRIDE(vis));

	if ((i=x&7)) {
		if ((j=w+i-8)<0) {
			mask=(0xff>>i)&(0xff<<-j); 
		} else {
			mask=0xff>>i;
		}

		*buff = (*adr & mask) << (8-i);

		if (j<0)
			return 0;
		else
			adr++;
	} else
		j=w;
	

	while ((j-=8)>=0) {
		color = *adr;
		*(buff++) |= color >> i;
		*(buff) = (color << (8-i));
	}

    
	if (j&=7) {
		mask=~(0xff>>j);
		*buff |= (*adr & mask) >> i;
	}
  
	return 0;
}