1*a182bd6eSX512 /*
2*a182bd6eSX512 * Copyright 2021, Haiku, Inc.
3*a182bd6eSX512 * Distributed under the terms of the MIT License.
4*a182bd6eSX512 */
5*a182bd6eSX512
6*a182bd6eSX512
7*a182bd6eSX512 #include "graphics.h"
8*a182bd6eSX512
9*a182bd6eSX512
10*a182bd6eSX512 RasBuf32 gFramebuf = {NULL, 0, 0, 0};
11*a182bd6eSX512
12*a182bd6eSX512
13*a182bd6eSX512 void
Clear(RasBuf32 vb,uint32_t c)14*a182bd6eSX512 Clear(RasBuf32 vb, uint32_t c)
15*a182bd6eSX512 {
16*a182bd6eSX512 vb.stride -= vb.width;
17*a182bd6eSX512 for (; vb.height > 0; vb.height--) {
18*a182bd6eSX512 for (int x = 0; x < vb.width; x++) {
19*a182bd6eSX512 *vb.colors = c;
20*a182bd6eSX512 vb.colors++;
21*a182bd6eSX512 }
22*a182bd6eSX512 vb.colors += vb.stride;
23*a182bd6eSX512 }
24*a182bd6eSX512 }
25*a182bd6eSX512
26*a182bd6eSX512
27*a182bd6eSX512 template <typename Color>
28*a182bd6eSX512 RasBuf<Color>
Clip(int x,int y,int w,int h) const29*a182bd6eSX512 RasBuf<Color>::Clip(int x, int y, int w, int h) const
30*a182bd6eSX512 {
31*a182bd6eSX512 RasBuf<Color> vb = *this;
32*a182bd6eSX512 if (x < 0) {w += x; x = 0;}
33*a182bd6eSX512 if (y < 0) {h += y; y = 0;}
34*a182bd6eSX512 if (x + w > vb.width) {w = vb.width - x;}
35*a182bd6eSX512 if (y + h > vb.height) {h = vb.height - y;}
36*a182bd6eSX512 if (w > 0 && h > 0) {
37*a182bd6eSX512 vb.colors += y*vb.stride + x;
38*a182bd6eSX512 vb.width = w;
39*a182bd6eSX512 vb.height = h;
40*a182bd6eSX512 } else {
41*a182bd6eSX512 vb.colors = 0;
42*a182bd6eSX512 vb.width = 0;
43*a182bd6eSX512 vb.height = 0;
44*a182bd6eSX512 }
45*a182bd6eSX512 return vb;
46*a182bd6eSX512 }
47*a182bd6eSX512
48*a182bd6eSX512 template class RasBuf<uint8>;
49*a182bd6eSX512 template class RasBuf<uint32>;
50*a182bd6eSX512
51*a182bd6eSX512
52*a182bd6eSX512 RasBuf8
ThisGlyph(uint32 ch)53*a182bd6eSX512 Font::ThisGlyph(uint32 ch)
54*a182bd6eSX512 {
55*a182bd6eSX512 if (ch < firstChar || ch >= firstChar + charCnt)
56*a182bd6eSX512 return ThisGlyph(' ');
57*a182bd6eSX512
58*a182bd6eSX512 RasBuf8 rb;
59*a182bd6eSX512 rb.colors = data + (ch - firstChar) * charWidth * charHeight;
60*a182bd6eSX512 rb.stride = charWidth;
61*a182bd6eSX512 rb.width = charWidth;
62*a182bd6eSX512 rb.height = charHeight;
63*a182bd6eSX512 return rb;
64*a182bd6eSX512 }
65*a182bd6eSX512
66*a182bd6eSX512
67*a182bd6eSX512 void
BlitMaskRgb(RasBuf32 dst,RasBuf8 src,int32 x,int32 y,uint32_t c)68*a182bd6eSX512 BlitMaskRgb(RasBuf32 dst, RasBuf8 src, int32 x, int32 y, uint32_t c)
69*a182bd6eSX512 {
70*a182bd6eSX512 int dstW, dstH;
71*a182bd6eSX512 uint32_t dc, a;
72*a182bd6eSX512 dstW = dst.width; dstH = dst.height;
73*a182bd6eSX512 dst = dst.Clip(x, y, src.width, src.height);
74*a182bd6eSX512 src = src.Clip(-x, -y, dstW, dstH);
75*a182bd6eSX512 dst.stride -= dst.width;
76*a182bd6eSX512 src.stride -= src.width;
77*a182bd6eSX512 for (; dst.height > 0; dst.height--) {
78*a182bd6eSX512 for (x = dst.width; x > 0; x--) {
79*a182bd6eSX512 dc = *dst.colors;
80*a182bd6eSX512 a = *src.colors;
81*a182bd6eSX512 if (a != 0) {
82*a182bd6eSX512 *dst.colors =
83*a182bd6eSX512 ((((dc >> 0) % 0x100) * (0xff - a) / 0xff
84*a182bd6eSX512 + ((c >> 0) % 0x100) * a / 0xff) << 0)
85*a182bd6eSX512 + ((((dc >> 8) % 0x100) * (0xff - a) / 0xff
86*a182bd6eSX512 + ((c >> 8) % 0x100) * a / 0xff) << 8)
87*a182bd6eSX512 + ((((dc >> 16) % 0x100) * (0xff - a) / 0xff
88*a182bd6eSX512 + ((c >> 16) % 0x100) * a / 0xff) << 16)
89*a182bd6eSX512 + (dc & 0xff000000);
90*a182bd6eSX512 }
91*a182bd6eSX512 dst.colors++;
92*a182bd6eSX512 src.colors++;
93*a182bd6eSX512 }
94*a182bd6eSX512 dst.colors += dst.stride;
95*a182bd6eSX512 src.colors += src.stride;
96*a182bd6eSX512 }
97*a182bd6eSX512 }
98