9front - general discussion about 9front
 help / color / mirror / Atom feed
* libmemdraw bug?
@ 2019-01-18 17:40 qwx
  0 siblings, 0 replies; only message in thread
From: qwx @ 2019-01-18 17:40 UTC (permalink / raw)
  To: 9front

Hello,

I'm looking at rsc's implementation of pico, which reads in images with
readmemimage().  It only handles 248x248 images, but if extended to
arbitrary dimensions, the images aren't displayed correctly unless their
dimensions don't have the lowest 3 bits set.  In other words, if dx & 7
and/or dy & 7, the image seems to be read/loaded incorrectly.

Pico uses libmemdraw to load and manipulate images, then displays them with
libdraw.  I'm inlining below a simple program that demonstrates the issue.

What is going on?

Thanks,

qwx

/*
; hget http://9front.org/img/ninefront.bit > /tmp/ninefront.bit
; 6c -FTVw test.c && 6l test.6 && 6.out /tmp/ninefront.bit
*/
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>

void
main(int argc, char **argv)
{
	int fd;
	Memimage *m;
	Image *i;

	if(argc != 2)
		sysfatal("usage");
	if(memimageinit() < 0)
		sysfatal("memimageinit: %r");
	if((fd = open(argv[1], OREAD)) < 0)
		sysfatal("open: %r");
	m = readmemimage(fd);
	close(fd);
	if(m == nil)
		sysfatal("readmemimage: %r");
	if(initdraw(nil, nil, nil) < 0)
		sysfatal("initdraw: %r");
	if((i = allocimage(display, m->r, m->chan, 0, DNofill)) == nil)
		sysfatal("allocimage: %r");
	if(loadimage(i, i->r, byteaddr(m, m->r.min), Dx(m->r)*Dy(m->r)*m->depth/8) < 0)
		sysfatal("loadimage: %r");
	draw(screen, screen->r, i, nil, i->r.min);
	flushimage(display, 1);
	for(;;)
		sleep(1);
}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-01-18 17:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-18 17:40 libmemdraw bug? qwx

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).