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
.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)
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
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)
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;
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);
{
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] */