bitblt.c - sam - An updated version of the sam text editor.
(HTM) git clone git://vernunftzentrum.de/sam.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
bitblt.c (1958B)
---
1 /* Copyright (c) 1998 Lucent Technologies - All rights reserved. */
2 #include <u.h>
3 #include <libg.h>
4 #include "libgint.h"
5
6 void
7 bitblt(Bitmap *d, Point p, Bitmap *s, Rectangle r, Fcode f)
8 {
9 bitblt2(d, p, s, r, f, _fgpixel, _bgpixel);
10 }
11
12 void
13 bitblt2(Bitmap *d, Point p, Bitmap *s, Rectangle r, Fcode f, uint64_t fg, uint64_t bg)
14 {
15 int sx, sy, dx, dy, bfunc;
16 GC g;
17 uint64_t plane;
18 Bitmap *btmp;
19
20 if (fg == 0)
21 fg = _fgpixel;
22
23 if (bg == 0)
24 bg = _bgpixel;
25
26 if(Dx(r)<=0 || Dy(r)<=0)
27 return;
28 sx = r.min.x;
29 sy = r.min.y;
30 if(s->flag&SHIFT){
31 sx -= s->r.min.x;
32 sy -= s->r.min.y;
33 }
34 dx = p.x;
35 dy = p.y;
36 if(d->flag&SHIFT){
37 dx -= d->r.min.x;
38 dy -= d->r.min.y;
39 }
40 g = _getcopygc2(f, d, s, &bfunc, fg, bg);
41 if(bfunc == UseCopyArea)
42 XCopyArea(_dpy, (Drawable)s->id, (Drawable)d->id, g,
43 sx, sy, Dx(r), Dy(r), dx, dy);
44 else if(bfunc == UseFillRectangle){
45 XFillRectangle(_dpy, (Drawable)d->id, g,
46 dx, dy, Dx(r), Dy(r));
47 }else{
48 /* bfunc == UseCopyPlane */
49 plane = _ld2dmask[s->ldepth];
50 plane &= ~(plane>>1);
51 if(0/*f == S*/)
52 XCopyPlane(_dpy, (Drawable)s->id, (Drawable)d->id, g,
53 sx, sy, Dx(r), Dy(r), dx, dy, plane);
54 else {
55 /*
56 * CopyPlane can only do func code S,
57 * so copy src rect into a bitmap with the same depth
58 * as the dest, then do the bitblt from the tmp.
59 * This won't recurse again because we only get
60 * UseCopyPlane with differing bitmap depths
61 */
62 btmp = _balloc(Rect(0,0,Dx(r),Dy(r)), d->ldepth);
63 XCopyPlane(_dpy, (Drawable)s->id, (Drawable)btmp->id, g,
64 sx, sy, Dx(r), Dy(r), 0, 0, plane);
65 bitblt(d, p, btmp, btmp->r, f);
66 bfree(btmp);
67 }
68 }
69 XFlush(_dpy);
70 }