9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: mirtchov@cpsc.ucalgary.ca
To: 9fans@cse.psu.edu
Subject: Re: [9fans] Q: libdraw, loadimage, allocimage
Date: Tue, 21 Oct 2003 08:21:47 -0600	[thread overview]
Message-ID: <b4041927b5d95a8367f644ef5eb5cf72@plan9.ucalgary.ca> (raw)
In-Reply-To: <3F94F6B5.000001.15140@file1>

[-- 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);
		}
	}

}

  reply	other threads:[~2003-10-21 14:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-21  9:04 a.b
2003-10-21 14:21 ` mirtchov [this message]
2003-10-22  1:22   ` okamoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b4041927b5d95a8367f644ef5eb5cf72@plan9.ucalgary.ca \
    --to=mirtchov@cpsc.ucalgary.ca \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).