* Re: [9fans] Q: libdraw, loadimage, allocimage
2003-10-21 9:04 [9fans] Q: libdraw, loadimage, allocimage a.b
@ 2003-10-21 14:21 ` mirtchov
2003-10-22 1:22 ` okamoto
0 siblings, 1 reply; 3+ messages in thread
From: mirtchov @ 2003-10-21 14:21 UTC (permalink / raw)
To: 9fans
[-- Attachment #1: Type: text/plain, Size: 684 bytes --]
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
[-- Attachment #2: bmap.c --]
[-- Type: text/plain, Size: 983 bytes --]
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <event.h>
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);
}
}
}
^ permalink raw reply [flat|nested] 3+ messages in thread