From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: To: 9fans@cse.psu.edu Subject: Re: [9fans] Q: libdraw, loadimage, allocimage From: mirtchov@cpsc.ucalgary.ca In-Reply-To: <3F94F6B5.000001.15140@file1> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-zoirkbsvtjdfxspjcabzjzhokc" Date: Tue, 21 Oct 2003 08:21:47 -0600 Topicbox-Message-UUID: 7620ca74-eacc-11e9-9e20-41e7f4b1d025 This is a multi-part message in MIME format. --upas-zoirkbsvtjdfxspjcabzjzhokc Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit I had a long winded reply which died with my drawterm, unfortunately... Anyway, take a look at the example I've attached here, and also at the xscr hacks: http://pages.cpsc.ucalgary.ca/~mirtchov/p9/xscr/xscr.tar.gz The key with loadimage() is to avoid using it if possible -- it circumvents optimizations in the draw() design by loading data over the network all the time. Very slow over slow networks. Compare for example 'eruption', which does 'loadimage' for the entire display, rd-bomb, which does loadimage of a 256x256 bitmap, and polyominoes, which uses pre-allocated color palette stored on the display machine and see which one is faster... andrey --upas-zoirkbsvtjdfxspjcabzjzhokc Content-Disposition: attachment; filename=bmap.c Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit #include #include #include #include void eresized(int new) { USED(new); exits("done"); } void main(int argc, char **argv) { Image *img; Mouse m; uchar bmp[256]; ulong tick = 0; int i; USED(argc, argv); if(initdraw(nil, nil, "bmap") < 0) sysfatal("initdraw failed: %r"); einit(Emouse); img = allocimage(display, Rect(0, 0, 16, 16), CMAP8, 1, DCyan); if(img == nil) sysfatal("cannot allocate image: %r\n"); /* set so it replicates over the entire window */ replclipr(img, 1, Rect(0, 0, Dx(screen->r), Dy(screen->r))); for(;;) { for(i = 0; i < 256; i++) bmp[i] = tick++; tick++; /* fill it up with whatever is in bitmap */ loadimage(img, Rect(0, 0, 16, 16), bmp, 16*16); /* draw it over the entire screen */ draw(screen, screen->r, img, nil, ZP); flushimage(display, 1); if(ecanmouse()) { m = emouse(); if(m.buttons) exits(0); } } } --upas-zoirkbsvtjdfxspjcabzjzhokc--