9front - general discussion about 9front
 help / color / mirror / Atom feed
From: qwx <qwx@sciops.net>
To: 9front@9front.org
Subject: libmemdraw bug?
Date: Fri, 18 Jan 2019 18:40:02 +0100	[thread overview]
Message-ID: <29BD3DBBC18C327BB8A22649EADF6E77@wopr.sciops.net> (raw)

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


                 reply	other threads:[~2019-01-18 17:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=29BD3DBBC18C327BB8A22649EADF6E77@wopr.sciops.net \
    --to=qwx@sciops.net \
    --cc=9front@9front.org \
    /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).