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
|
/* Copyright (c) 1992 AT&T - All rights reserved. */
#include <libc.h>
#include <libg.h>
#include "libgint.h"
#include <X11/Intrinsic.h>
#ifndef XtSpecificationRelease
#define R3
#endif
#include <stdio.h>
void
wrbitmap(Bitmap *b, int miny, int maxy, unsigned char *data)
{
XImage *im;
int w, h, inld, outld, l, offset, px;
GC g;
char *tdata;
w = Dx(b->r);
h = maxy - miny;
inld = b->ldepth;
outld = (b->ldepth == 0) ? 0 : screen.ldepth;
px = 1<<(3-outld); /* pixels per byte */
/* set l to number of bytes of data per scan line */
if(b->r.min.x >= 0)
offset = b->r.min.x % px;
else
offset = px - b->r.min.x % px;
l = (-b->r.min.x+px-1)/px;
if(b->r.max.x >= 0)
l += (b->r.max.x+px-1)/px;
else
l -= b->r.max.x/px;
l *= h;
tdata = (char *)malloc(l);
if (tdata == (char *) 0)
berror("wrbitmap malloc");
if (inld == outld)
memcpy((void*)tdata, (void*)data, l);
else
_ldconvert((char*)data, inld, tdata, outld, w, h);
im = XCreateImage(_dpy, 0, 1 << outld, ZPixmap, 0, tdata, w, h, 8, 0);
/* Botched interface to XCreateImage doesn't let you set these: */
im->bitmap_bit_order = MSBFirst;
im->byte_order = MSBFirst;
g = _getfillgc(S, b, ~0);
XSetBackground(_dpy, g, b->flag&DP1 ? 0 : _bgpixel);
XPutImage(_dpy, (Drawable)b->id, g, im, offset, 0, 0, miny - b->r.min.y, w-offset, h);
XDestroyImage(im);
}
|