~amavect/whiteboardfs

abfb4835b040164b0790f0b91b05cd3e5cba0c9b — amavect 1 year, 1 month ago 2d38717
fix dryerase crash, fix whiteboardfs non 2^x image size crash, update man page default sizes
5 files changed, 28 insertions(+), 30 deletions(-)

M README
M dryerase.c
M imageload.c
M whiteboardfs.4.man
M whiteboardfs.c
M README => README +0 -3
@@ 20,8 20,5 @@ Dryerase is a program meant to interface with whiteboardfs.
dryerase -c will start it connected to makeu
See man page for usage.

Bugs:
Non-line-aligned writes do not work, breaking non 2^n image widths.

TODO:
make whiteboardfs understand multiple image types

M dryerase.c => dryerase.c +5 -3
@@ 202,6 202,8 @@ updateproc(void*)
	Rectangle r;
	
	threadsetname("updater");
	im = nil;
	
	for(;;){
		n = recv(ups.sendc, &im);
		if(im == nil)


@@ 219,6 221,7 @@ updateproc(void*)
		if(!rectinrect(r, canvas->r))
			error("canvas rectangle changed");
		lockdisplay(display);
		_freeimage1(im);
		stallocimage(im, r, canvas->chan, 0, DNofill);
		unlockdisplay(display);
		readrectimage(im, ups.cfd);


@@ 226,7 229,7 @@ updateproc(void*)
			error("invalid image update read");
		send(ups.recvc, &im);
	}
	yield(); /* if error is due to exiting, we'll exit here */
	yield();  /* if error is due to exiting, we'll exit here */
	if(n < 0){
		error("Whiteboard probably closed.");
	}


@@ 410,7 413,7 @@ threadmain(int argc, char **argv)
	snprint(upath, sizeof(upath), "%s/%s", dir, "update");
	initsendproc(cpath);
	initupdateproc(cpath, upath);
	
	sleep(1000);
	if((mctl = initmouse(nil, screen)) == nil)
		error("cannot initmouse");
	if((kctl = initkeyboard(nil)) == nil)


@@ 568,7 571,6 @@ noflush:
			reading--;
			lockdisplay(display);
			draw(canvas, canvas->r, im, nil, ZP);
			_freeimage1(im);
			unlockdisplay(display);
			send(ups.sendc, &im);
			redraw();

M imageload.c => imageload.c +9 -13
@@ 61,8 61,8 @@ hdrallocmemimage(char *hdr)
 * 
 * currently returns -1 if n is not the same as the block size.
 */
int
blockcloadmemimage(Memimage *i, uchar *buf, int n, int *miny)
u32int
blockcloadmemimage(Memimage *i, uchar *buf, u32int n, int *miny)
{
	int maxy;
	int nb, ncblock;


@@ 94,17 94,17 @@ blockcloadmemimage(Memimage *i, uchar *buf, int n, int *miny)
		return -1;
	}
	*miny = maxy;
	return nb;
	return nb+24;
}

/* 
 * returns number of bytes written. 
 * returns -1 on error, or 0 on no bytes written
 */
int
lineloadmemimage(Memimage *i, uchar *buf, int n, int *miny)
u32int
lineloadmemimage(Memimage *i, uchar *buf, u32int n, int *miny)
{
	int l, dy;
	u32int l, dy;
	
	l = bytesperline(i->r, i->depth);
	if(l <= 0){


@@ 112,12 112,8 @@ lineloadmemimage(Memimage *i, uchar *buf, int n, int *miny)
		return -1;
	}
	dy = n / l;
	if(dy < 0){
		werrstr("blockloadmemimage: n was negative %d", n);
		return -1;
	}else if(dy == 0){
	if(dy == 0)
		return 0;
	}
	if(dy + *miny > i->r.max.y){
		werrstr("blockloadmemimage: buf size too large %d", n);
		return -1;


@@ 130,8 126,8 @@ lineloadmemimage(Memimage *i, uchar *buf, int n, int *miny)
	return dy*l;
}

int
blockloadmemimage(Memimage *i, uchar *buf, int n, int *miny, int comp)
u32int
blockloadmemimage(Memimage *i, uchar *buf, u32int n, int *miny, int comp)
{
	if(comp)
		return blockcloadmemimage(i, buf, n, miny);

M whiteboardfs.4.man => whiteboardfs.4.man +2 -2
@@ 59,10 59,10 @@ Post the service as
.BI /srv/ srvname.
.TP
.BI -x " width"
Set the canvas image width. The default is 256.
Set the canvas image width. The default is 512.
.TP
.BI -y " height"
Set the canvas image height. The default is 256.
Set the canvas image height. The default is 512.
.PD
.PP
.I Dryerase

M whiteboardfs.c => whiteboardfs.c +12 -9
@@ 8,9 8,9 @@
#include <memdraw.h>

extern Memimage *hdrallocmemimage(char *);
extern int blockloadmemimage(Memimage *i, uchar *buf, int n, int *miny, int comp);
extern u32int blockloadmemimage(Memimage *i, uchar *buf, u32int n, int *miny, int comp);

#define DEBUG 0
#define DEBUG 1

enum {
	Qroot,


@@ 316,7 316,7 @@ fswrite(Req *r)
		wq->mi = hdrallocmemimage(r->ifcall.data + n);
		if(wq->mi == nil){
			free(wq);
			respond(r, "bad header");
			responderror(r);
			return;
		}
		if(!rectinrect(wq->mi->r, canvas->r)){


@@ 330,8 330,8 @@ fswrite(Req *r)
		if(wq->comp)
			wq->s = 6025;
		else
			wq->s = bytesperline(wq->mi->r, wq->mi->depth); /* residual buffer size */
		wq->buf = malloc(wq->s); /* residual buffer for uncompressed writes */
			wq->s = bytesperline(wq->mi->r, wq->mi->depth);  /* residual buffer size */
		wq->buf = malloc(wq->s);  /* residual buffer for uncompressed writes */
		if(wq->buf == nil){
			freememimage(wq->mi);
			free(wq);


@@ 345,14 345,16 @@ fswrite(Req *r)
	e = 1;
	while(n < r->ifcall.count && e > 0){
		if(DEBUG) fprint(2, "start: n=%d e=%d wqi=%ulld\n", n, e, wq->i);
		if(wq->i > 0){
		if(wq->i > 0){  /* finish a block or line */
			s = r->ifcall.count - n < wq->s - wq->i ? r->ifcall.count - n : wq->s - wq->i;
			memcpy(wq->buf + wq->i, r->ifcall.data, s);
			wq->i += s;
			e = blockloadmemimage(wq->mi, wq->buf, wq->i, &wq->miny, wq->comp);
			wq->i = 0;
			wq->i -= e;
			n += s;
		}else{
			e = blockloadmemimage(wq->mi, (uchar*)r->ifcall.data+n, r->ifcall.count, &wq->miny, wq->comp);
			e = blockloadmemimage(wq->mi, (uchar*)r->ifcall.data+n, r->ifcall.count-n, &wq->miny, wq->comp);
			n += e;
		}
		if(e < 0){
			freememimage(wq->mi);


@@ 363,8 365,8 @@ fswrite(Req *r)
			respond(r, "error loading image. deleting write request");
			return;
		}
		n += e;
		if(DEBUG) fprint(2, "end: n=%d e=%d wqi=%ulld\n", n, e, wq->i);
		if(DEBUG) fprint(2, "wq->miny: %d, wq->mi->r.max.y: %d\n", wq->miny, wq->mi->r.max.y);
	}
	if(n < r->ifcall.count){
		wq->i = r->ifcall.count - n;


@@ 381,6 383,7 @@ fswrite(Req *r)
		return;
	}
	r->ofcall.count = r->ifcall.count;
	if(DEBUG) fprint(2, "wq->miny: %d, wq->mi->r.max.y: %d\n", wq->miny, wq->mi->r.max.y);
	if(wq->miny < wq->mi->r.max.y){
		respond(r, nil);
		return;