summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2013-11-12 21:42:05 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2013-11-12 21:42:05 +0100
commitd56a6fadc5118e7fddba6294245a355ef2d3def9 (patch)
tree1a1044396fac969735fbaf3490c504f4ff6e8c1a /sys
parentdef87d60167d13c92328b6f0f81800787eedf03a (diff)
libmemdraw: change memimageinit() to return integer error (for kernel), minor cleanups
Diffstat (limited to 'sys')
-rw-r--r--sys/include/memdraw.h2
-rw-r--r--sys/man/2/memdraw5
-rw-r--r--sys/src/libmemdraw/alloc.c2
-rw-r--r--sys/src/libmemdraw/draw.c26
-rw-r--r--sys/src/libmemdraw/fillpoly.c2
5 files changed, 16 insertions, 21 deletions
diff --git a/sys/include/memdraw.h b/sys/include/memdraw.h
index 6e527696a..997cbbea5 100644
--- a/sys/include/memdraw.h
+++ b/sys/include/memdraw.h
@@ -149,7 +149,7 @@ extern void memarc(Memimage*, Point, int, int, int, Memimage*, Point, int, int,
extern Rectangle memlinebbox(Point, Point, int, int, int);
extern int memlineendsize(int);
extern void _memmkcmap(void);
-extern void memimageinit(void);
+extern int memimageinit(void);
/*
* Subfont management
diff --git a/sys/man/2/memdraw b/sys/man/2/memdraw
index ac1b73961..df68b699d 100644
--- a/sys/man/2/memdraw
+++ b/sys/man/2/memdraw
@@ -94,7 +94,7 @@ int drawdebug;
.PP
.ft L
.nf
-void memimageinit(void)
+int memimageinit(void)
ulong* wordaddr(Memimage *i, Point p)
uchar* byteaddr(Memimage *i, Point p)
void memimagemove(void *from, void *to)
@@ -213,7 +213,8 @@ as well as the replicated solid color images
and
.BR memwhite .
It should be called before referring to any of these images
-and before calling any of the other library functions.
+and before calling any of the other library functions. It
+returns non-zero on error.
.PP
Each
.B Memimage
diff --git a/sys/src/libmemdraw/alloc.c b/sys/src/libmemdraw/alloc.c
index d2852c3c4..aa3597f71 100644
--- a/sys/src/libmemdraw/alloc.c
+++ b/sys/src/libmemdraw/alloc.c
@@ -121,7 +121,7 @@ freememimage(Memimage *i)
{
if(i == nil)
return;
- if(i->data->ref-- == 1 && i->data->allocd){
+ if(--i->data->ref == 0 && i->data->allocd){
if(i->data->base)
poolfree(imagmem, i->data->base);
free(i->data);
diff --git a/sys/src/libmemdraw/draw.c b/sys/src/libmemdraw/draw.c
index 5a15e4dae..96cb01e44 100644
--- a/sys/src/libmemdraw/draw.c
+++ b/sys/src/libmemdraw/draw.c
@@ -6,7 +6,6 @@
extern Pool* imagmem;
int drawdebug;
-static int tablesbuilt;
/* perfect approximation to NTSC = .299r+.587g+.114b when 0 ≤ r,g,b < 256 */
#define RGB2K(r,g,b) ((156763*(r)+307758*(g)+59769*(b))>>19)
@@ -54,16 +53,15 @@ Memimage *memopaque;
int _ifmt(Fmt*);
-void
+int
memimageinit(void)
{
static int didinit = 0;
if(didinit)
- return;
-
- didinit = 1;
+ return 0;
+ if(imagmem != nil)
if(strcmp(imagmem->name, "Image") == 0 || strcmp(imagmem->name, "image") == 0)
imagmem->move = memimagemove;
@@ -75,22 +73,25 @@ memimageinit(void)
fmtinstall('b', _ifmt);
memones = allocmemimage(Rect(0,0,1,1), GREY1);
+ memzeros = allocmemimage(Rect(0,0,1,1), GREY1);
+ if(memones == nil || memzeros == nil)
+ return -1;
+
memones->flags |= Frepl;
memones->clipr = Rect(-0x3FFFFFF, -0x3FFFFFF, 0x3FFFFFF, 0x3FFFFFF);
*byteaddr(memones, ZP) = ~0;
- memzeros = allocmemimage(Rect(0,0,1,1), GREY1);
memzeros->flags |= Frepl;
memzeros->clipr = Rect(-0x3FFFFFF, -0x3FFFFFF, 0x3FFFFFF, 0x3FFFFFF);
*byteaddr(memzeros, ZP) = 0;
- if(memones == nil || memzeros == nil)
- assert(0 /*cannot initialize memimage library */); /* RSC BUG */
-
memwhite = memones;
memblack = memzeros;
memopaque = memones;
memtransparent = memzeros;
+
+ didinit = 1;
+ return 0;
}
static ulong imgtorgba(Memimage*, ulong);
@@ -354,13 +355,6 @@ mktables(void)
{
int i, j, mask, sh, small;
- if(tablesbuilt)
- return;
-
- fmtinstall('R', Rfmt);
- fmtinstall('P', Pfmt);
- tablesbuilt = 1;
-
/* bit replication up to 8 bits */
for(i=0; i<256; i++){
for(j=0; j<=8; j++){ /* j <= 8 [sic] */
diff --git a/sys/src/libmemdraw/fillpoly.c b/sys/src/libmemdraw/fillpoly.c
index 6d5370a9a..6ecccc0a1 100644
--- a/sys/src/libmemdraw/fillpoly.c
+++ b/sys/src/libmemdraw/fillpoly.c
@@ -79,7 +79,7 @@ _memfillpolysc(Memimage *dst, Point *vert, int nvert, int w, Memimage *src, Poin
Point p0;
int i;
- if(nvert == 0)
+ if(nvert <= 0)
return;
seg = malloc((nvert+2)*sizeof(Seg*));