File: box.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 (117 lines) | stat: -rw-r--r-- 3,060 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
/* $Id: box.c,v 1.1.1.1 2001/05/12 23:01:42 cegger Exp $
******************************************************************************

   Graphics library for GGI. Boxes.

   Copyright (C) 1999 Marcus Sundberg	[marcus@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 <string.h>

#include "lin24lib.h"


int GGI_lin24_drawbox(ggi_visual *vis, int origx, int y, int origw, int h)
{
	uint32 colors[3], *dest32;
	uint8 *colp, *dest8;
	int i, linediff;
	
	LIBGGICLIP_XYWH(vis, origx, y, origw, h);
	PREPARE_FB(vis);

	colp = (uint8*) colors;
	for (i = 0; i < 4; i++) {
		*colp++ = LIBGGI_GC_FGCOLOR(vis)      ;
		*colp++ = LIBGGI_GC_FGCOLOR(vis) >>  8;
		*colp++ = LIBGGI_GC_FGCOLOR(vis) >> 16;
	}
	colp = (uint8*) colors;

	dest8 = (uint8*)LIBGGI_CURWRITE(vis)
		+ y*LIBGGI_FB_W_STRIDE(vis) + origx*3;
	linediff = LIBGGI_FB_W_STRIDE(vis) - origw*3;

	while (h) {
		int x = origx+y*LIBGGI_FB_W_STRIDE(vis);
		int w = origw;
		while ((x & 3)) {
			*dest8++ = colp[0];
			*dest8++ = colp[1];
			*dest8++ = colp[2];
			x++;
			w--;
			if (!w) goto end_of_loop;
		}
		dest32 = (uint32*)dest8;
		while (w > 3) {
			*dest32++ = colors[0];
			*dest32++ = colors[1];
			*dest32++ = colors[2];
			w -= 4;
		}
		dest8 = (uint8*)dest32;
		while (w) {
			*dest8++ = colp[0];
			*dest8++ = colp[1];
			*dest8++ = colp[2];
			w--;
		}
	  end_of_loop:
		h--;
		dest8 += linediff;
	}

	return 0;
}


int GGI_lin24_putbox(ggi_visual *vis, int x, int y, int w, int h, void *buffer)
{
	uint8 *src = buffer;
	uint8 *dest;
	int srcwidth = w*3;
	int destwidth = LIBGGI_FB_W_STRIDE(vis);

	LIBGGICLIP_PUTBOX(vis,x,y,w,h,src,srcwidth, *3);
	PREPARE_FB(vis);
	
	dest = (uint8 *)LIBGGI_CURWRITE(vis) + (y*destwidth + x*3);

	/* Width should be in bytes */
	w *= 3;

	/* Optimized full-width case */
	if (w == destwidth && x == 0) {
		memcpy(dest, src, w*h);
		return 0;
	}
	
	while (h > 0) {
		memcpy(dest, src, w);
		dest += destwidth;
		src += srcwidth;
		h--;
	}
	return 0;
}