2 * /dev/draw simulator -- handles the messages prepared by the draw library.
3 * Doesn't simulate the file system part, just the messages.
13 extern void _flushmemscreen(Rectangle);
16 #define HASHMASK (NHASH-1)
18 typedef struct Client Client;
19 typedef struct Draw Draw;
20 typedef struct DImage DImage;
21 typedef struct DScreen DScreen;
22 typedef struct CScreen CScreen;
23 typedef struct FChar FChar;
24 typedef struct Refresh Refresh;
25 typedef struct Refx Refx;
26 typedef struct DName DName;
43 DImage* dimage[NHASH];
80 int minx; /* left edge of bits */
81 int maxx; /* right edge of bits */
82 uchar miny; /* first non-zero scan-line */
83 uchar maxy; /* last non-zero scan-line + 1 */
84 schar left; /* offset of baseline */
85 uchar width; /* width of baseline */
89 * Reference counts in DImages:
90 * one per open by original client
91 * one per screen image or fill
92 * one per image derived from this one by name
104 DScreen* dscreen; /* 0 if not a window */
105 DImage* fromname; /* image this one is derived from, by name */
128 static Client *client0;
129 static Memimage *screenimage;
130 static Rectangle flushrect;
132 static DScreen* dscreen;
133 static int drawuninstall(Client*, int);
134 static Memimage* drawinstall(Client*, int, Memimage*, DScreen*);
135 static void drawfreedimage(DImage*);
138 _initdisplaymemimage(Memimage *m)
142 client0 = mallocz(sizeof(Client), 1);
144 fprint(2, "initdraw: allocating client0: out of memory");
148 client0->clientid = ++sdraw.clientid;
149 client0->op = SoverD;
150 sdraw.client[0] = client0;
152 sdraw.softscreen = 1;
156 _drawreplacescreenimage(Memimage *m)
159 * Replace the screen image because the screen
162 * In theory there should only be one reference
163 * to the current screen image, and that's through
164 * client0's image 0, installed a few lines above.
165 * Once the client drops the image, the underlying backing
166 * store freed properly. The client is being notified
167 * about the resize through external means, so all we
168 * need to do is this assignment.
176 if(om && --om->screenref == 0){
184 drawrefreshscreen(DImage *l, Client *client)
186 while(l != nil && l->dscreen == nil)
188 if(l != nil && l->dscreen->owner != client)
189 l->dscreen->owner->refreshme = 1;
194 drawrefresh(Memimage *m, Rectangle r, void *v)
208 for(ref=c->refresh; ref; ref=ref->next)
209 if(ref->dimage == d){
210 combinerect(&ref->r, r);
213 ref = mallocz(sizeof(Refresh), 1);
217 ref->next = c->refresh;
223 addflush(Rectangle r)
228 if(sdraw.softscreen==0 || !rectclip(&r, screenimage->r))
231 if(flushrect.min.x >= flushrect.max.x){
237 combinerect(&nbb, r);
239 abb = Dx(flushrect)*Dy(flushrect);
240 anbb = Dx(nbb)*Dy(nbb);
242 * Area of new waste is area of new bb minus area of old bb,
243 * less the area of the new segment, which we assume is not waste.
244 * This could be negative, but that's OK.
246 waste += anbb-abb - ar;
251 * total area is small
252 * waste is less than half total area
255 if(anbb<=1024 || waste*2<anbb || rectXrect(flushrect, r)){
259 /* emit current state */
260 if(flushrect.min.x < flushrect.max.x)
261 _flushmemscreen(flushrect);
268 dstflush(int dstid, Memimage *dst, Rectangle r)
273 combinerect(&flushrect, r);
276 /* how can this happen? -rsc, dec 12 2002 */
278 print("nil dstflush\n");
285 if(l->screen->image->data != screenimage->data)
287 r = rectaddpt(r, l->delta);
288 l = l->screen->image->layer;
297 if(flushrect.min.x < flushrect.max.x)
298 _flushmemscreen(flushrect);
299 flushrect = Rect(10000, 10000, -10000, -10000);
304 drawcmp(char *a, char *b, int n)
308 return memcmp(a, b, n);
313 drawlookupname(int n, char *str)
318 ename = &name[sdraw.nname];
319 for(; name<ename; name++)
320 if(drawcmp(name->name, str, n) == 0)
327 drawgoodname(DImage *d)
331 /* if window, validate the screen's own images */
333 if(drawgoodname(d->dscreen->dimage) == 0
334 || drawgoodname(d->dscreen->dfill) == 0)
338 n = drawlookupname(strlen(d->name), d->name);
339 if(n==nil || n->vers!=d->vers)
346 drawlookup(Client *client, int id, int checkname)
350 d = client->dimage[id&HASHMASK];
354 * BUG: should error out but too hard.
357 if(checkname && !drawgoodname(d))
368 drawlookupdscreen(int id)
383 drawlookupscreen(Client *client, int id, CScreen **cs)
389 if(s->dscreen->id == id){
395 /* caller must check! */
401 drawinstall(Client *client, int id, Memimage *i, DScreen *dscreen)
405 d = mallocz(sizeof(DImage), 1);
418 d->dscreen = dscreen;
419 d->next = client->dimage[id&HASHMASK];
420 client->dimage[id&HASHMASK] = d;
426 drawinstallscreen(Client *client, DScreen *d, int id, DImage *dimage, DImage *dfill, int public)
431 c = mallocz(sizeof(CScreen), 1);
432 if(dimage && dimage->image && dimage->image->chan == 0){
433 print("bad image %p in drawinstallscreen", dimage->image);
440 d = mallocz(sizeof(DScreen), 1);
445 s = mallocz(sizeof(Memscreen), 1);
455 s->image = dimage->image;
460 s->fill = dfill->image;
473 c->next = client->cscreen;
480 drawdelname(DName *name)
485 memmove(name, name+1, (sdraw.nname-(i+1))*sizeof(DName));
491 drawfreedscreen(DScreen *this)
497 print("negative ref in drawfreedscreen\n");
502 dscreen = this->next;
505 while(next = ds->next){ /* assign = */
507 ds->next = this->next;
513 * Should signal Enodrawimage, but too hard.
519 drawfreedimage(this->dimage);
521 drawfreedimage(this->dfill);
528 drawfreedimage(DImage *dimage)
536 print("negative ref in drawfreedimage\n");
541 for(i=0; i<sdraw.nname; )
542 if(sdraw.name[i].dimage == dimage)
543 drawdelname(sdraw.name+i);
546 if(dimage->fromname){ /* acquired by name; owned by someone else*/
547 drawfreedimage(dimage->fromname);
550 ds = dimage->dscreen;
552 dimage->dscreen = nil; /* paranoia */
555 if(l->data == screenimage->data)
556 addflush(l->layer->screenr);
557 if(l->layer->refreshfn == drawrefresh) /* else true owner will clean up */
558 free(l->layer->refreshptr);
559 l->layer->refreshptr = nil;
560 if(drawgoodname(dimage))
568 else if(--l->screenref==0)
578 drawuninstallscreen(Client *client, CScreen *this)
582 cs = client->cscreen;
584 client->cscreen = this->next;
585 drawfreedscreen(this->dscreen);
589 while(next = cs->next){ /* assign = */
591 cs->next = this->next;
592 drawfreedscreen(this->dscreen);
602 drawuninstall(Client *client, int id)
606 for(l=&client->dimage[id&HASHMASK]; (d=*l) != nil; l=&d->next){
618 drawaddname(Client *client, DImage *di, int n, char *str, char **err)
620 DName *name, *ename, *new, *t;
624 ename = &name[sdraw.nname];
625 for(; name<ename; name++)
626 if(drawcmp(name->name, str, n) == 0){
627 *err = "image name in use";
630 t = mallocz((sdraw.nname+1)*sizeof(DName), 1);
632 if(t == nil || ns == nil){
635 *err = "out of memory";
638 memmove(t, sdraw.name, sdraw.nname*sizeof(DName));
641 new = &sdraw.name[sdraw.nname++];
643 memmove(new->name, str, n);
646 new->client = client;
647 new->vers = ++sdraw.vers;
652 drawclientop(Client *cl)
663 drawimage(Client *client, uchar *a)
667 d = drawlookup(client, BGLONG(a), 1);
669 return nil; /* caller must check! */
675 drawrectangle(Rectangle *r, uchar *a)
677 r->min.x = BGLONG(a+0*4);
678 r->min.y = BGLONG(a+1*4);
679 r->max.x = BGLONG(a+2*4);
680 r->max.y = BGLONG(a+3*4);
685 drawpoint(Point *p, uchar *a)
687 p->x = BGLONG(a+0*4);
688 p->y = BGLONG(a+1*4);
693 drawchar(Memimage *dst, Point p, Memimage *src, Point *sp, DImage *font, int index, int op)
699 fc = &font->fchar[index];
700 r.min.x = p.x+fc->left;
701 r.min.y = p.y-(font->ascent-fc->miny);
702 r.max.x = r.min.x+(fc->maxx-fc->minx);
703 r.max.y = r.min.y+(fc->maxy-fc->miny);
704 sp1.x = sp->x+fc->left;
705 sp1.y = sp->y+fc->miny;
706 memdraw(dst, r, src, sp1, font->image, Pt(fc->minx, fc->miny), op);
714 drawcoord(uchar *p, uchar *maxp, int oldx, int *newx)
739 _drawmsgread(void *a, int n)
745 if(cl->readdata == nil){
746 werrstr("no draw data");
749 if(n < cl->nreaddata){
750 werrstr("short read");
754 memmove(a, cl->readdata, cl->nreaddata);
766 _drawmsgwrite(void *v, int n)
768 char cbuf[40], *err, ibuf[12*12+1], *s;
769 int c, ci, doflush, dstid, e0, e1, esize, j, m;
770 int ni, nw, oesize, oldn, op, ox, oy, repl, scrnid, y;
771 uchar *a, refresh, *u;
775 DImage *di, *ddst, *dsrc, *font, *ll;
779 Memimage *dst, *i, *l, **lp, *mask, *src;
794 /*fprint(2, "msgwrite %d(%d)...", n, *a); */
797 /*fprint(2, "bad command %d\n", *a); */
798 err = "bad draw command";
801 /* allocate: 'b' id[4] screenid[4] refresh[1] chan[4] repl[1]
802 R[4*4] clipR[4*4] rrggbbaa[4]
805 m = 1+4+4+1+4+1+4*4+4*4+4;
809 scrnid = BGSHORT(a+5);
813 drawrectangle(&r, a+15);
814 drawrectangle(&clipr, a+31);
815 value = BGLONG(a+47);
816 if(drawlookup(client, dstid, 0))
819 dscrn = drawlookupscreen(client, scrnid, &cs);
822 scrn = dscrn->screen;
823 if(repl || chan!=scrn->image->chan){
824 err = "image parameters incompatibile with screen";
832 reffn = memlnorefresh;
838 err = "unknown refresh method";
841 l = memlalloc(scrn, r, reffn, 0, value);
844 addflush(l->layer->screenr);
846 rectclip(&l->clipr, r);
847 if(drawinstall(client, dstid, l, dscrn) == 0){
854 if(reffn == drawrefresh){
855 refx = mallocz(sizeof(Refx), 1);
857 if(drawuninstall(client, dstid) < 0)
861 refx->client = client;
862 refx->dimage = drawlookup(client, dstid, 1);
864 memlsetrefresh(l, reffn, refx);
868 i = allocmemimage(r, chan);
875 rectclip(&i->clipr, r);
876 if(drawinstall(client, dstid, i, 0) == 0){
880 memfillcolor(i, value);
883 /* allocate screen: 'A' id[4] imageid[4] fillid[4] public[1] */
891 if(drawlookupdscreen(dstid))
893 ddst = drawlookup(client, BGLONG(a+5), 1);
894 dsrc = drawlookup(client, BGLONG(a+9), 1);
895 if(ddst==0 || dsrc==0)
897 if(drawinstallscreen(client, 0, dstid, ddst, dsrc, a[13]) == 0)
901 /* set repl and clip: 'c' dstid[4] repl[1] clipR[4*4] */
906 ddst = drawlookup(client, BGLONG(a+1), 1);
910 err = "can't change repl/clipr of shared image";
916 drawrectangle(&dst->clipr, a+6);
919 /* draw: 'd' dstid[4] srcid[4] maskid[4] R[4*4] P[2*4] P[2*4] */
921 m = 1+4+4+4+4*4+2*4+2*4;
924 dst = drawimage(client, a+1);
926 src = drawimage(client, a+5);
927 mask = drawimage(client, a+9);
928 if(!dst || !src || !mask)
930 drawrectangle(&r, a+13);
933 op = drawclientop(client);
934 memdraw(dst, r, src, p, mask, q, op);
935 dstflush(dstid, dst, r);
938 /* toggle debugging: 'D' val[1] */
946 /* ellipse: 'e' dstid[4] srcid[4] center[2*4] a[4] b[4] thick[4] sp[2*4] alpha[4] phi[4]*/
949 m = 1+4+4+2*4+4+4+4+2*4+2*4;
952 dst = drawimage(client, a+1);
954 src = drawimage(client, a+5);
961 err = "invalid ellipse semidiameter";
966 err = "negative ellipse thickness";
970 drawpoint(&sp, a+29);
976 op = drawclientop(client);
977 /* high bit indicates arc angles are present */
978 if(ox & ((ulong)1<<31)){
979 if((ox & ((ulong)1<<30)) == 0)
980 ox &= ~((ulong)1<<31);
981 memarc(dst, p, e0, e1, c, src, sp, ox, oy, op);
983 memellipse(dst, p, e0, e1, c, src, sp, op);
984 dstflush(dstid, dst, Rect(p.x-e0-j, p.y-e1-j, p.x+e0+j+1, p.y+e1+j+1));
987 /* free: 'f' id[4] */
992 ll = drawlookup(client, BGLONG(a+1), 0);
993 if(ll && ll->dscreen && ll->dscreen->owner != client)
994 ll->dscreen->owner->refreshme = 1;
995 if(drawuninstall(client, BGLONG(a+1)) < 0)
999 /* free screen: 'F' id[4] */
1004 if(!drawlookupscreen(client, BGLONG(a+1), &cs))
1006 drawuninstallscreen(client, cs);
1009 /* initialize font: 'i' fontid[4] nchars[4] ascent[1] */
1014 dstid = BGLONG(a+1);
1016 err = "can't use display as font";
1019 font = drawlookup(client, dstid, 1);
1022 if(font->image->layer){
1023 err = "can't use window as font";
1027 if(ni<=0 || ni>4096){
1028 err = "bad font size (4096 chars max)";
1031 free(font->fchar); /* should we complain if non-zero? */
1032 font->fchar = mallocz(ni*sizeof(FChar), 1);
1033 if(font->fchar == 0){
1034 err = "no memory for font";
1037 memset(font->fchar, 0, ni*sizeof(FChar));
1039 font->ascent = a[9];
1042 /* set image 0 to screen image */
1047 if(drawlookup(client, 0, 0))
1049 drawinstall(client, 0, screenimage, 0);
1053 /* get image info: 'I' */
1058 if(client->infoid < 0)
1060 if(client->infoid == 0){
1065 di = drawlookup(client, client->infoid, 1);
1070 ni = sprint(ibuf, "%11d %11d %11s %11d %11d %11d %11d %11d"
1071 " %11d %11d %11d %11d ",
1074 chantostr(cbuf, i->chan),
1075 (i->flags&Frepl)==Frepl,
1076 i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y,
1077 i->clipr.min.x, i->clipr.min.y,
1078 i->clipr.max.x, i->clipr.max.y);
1079 free(client->readdata);
1080 client->readdata = malloc(ni);
1081 if(client->readdata == nil)
1083 memmove(client->readdata, ibuf, ni);
1084 client->nreaddata = ni;
1085 client->infoid = -1;
1088 /* load character: 'l' fontid[4] srcid[4] index[2] R[4*4] P[2*4] left[1] width[1] */
1090 m = 1+4+4+2+4*4+2*4+1+1;
1093 font = drawlookup(client, BGLONG(a+1), 1);
1096 if(font->nfchar == 0)
1098 src = drawimage(client, a+5);
1102 if(ci >= font->nfchar)
1104 drawrectangle(&r, a+11);
1105 drawpoint(&p, a+27);
1106 memdraw(font->image, r, src, p, memopaque, p, S);
1107 fc = &font->fchar[ci];
1116 /* draw line: 'L' dstid[4] p0[2*4] p1[2*4] end0[4] end1[4] radius[4] srcid[4] sp[2*4] */
1118 m = 1+4+2*4+2*4+4+4+4+4+2*4;
1121 dst = drawimage(client, a+1);
1122 dstid = BGLONG(a+1);
1124 drawpoint(&q, a+13);
1129 err = "negative line width";
1132 src = drawimage(client, a+33);
1135 drawpoint(&sp, a+37);
1136 op = drawclientop(client);
1137 memline(dst, p, q, e0, e1, j, src, sp, op);
1138 /* avoid memlinebbox if possible */
1139 if(dstid==0 || dst->layer!=nil){
1140 /* BUG: this is terribly inefficient: update maximal containing rect*/
1141 r = memlinebbox(p, q, e0, e1, j);
1142 dstflush(dstid, dst, insetrect(r, -(1+1+j)));
1146 /* create image mask: 'm' newid[4] id[4] */
1157 /* attach to a named image: 'n' dstid[4] j[1] name[j] */
1163 if(j == 0) /* give me a non-empty name please */
1168 dstid = BGLONG(a+1);
1169 if(drawlookup(client, dstid, 0))
1171 dn = drawlookupname(j, (char*)a+6);
1177 if(drawinstall(client, dstid, dn->dimage->image, 0) == 0)
1179 di = drawlookup(client, dstid, 0);
1182 di->vers = dn->vers;
1184 di->fromname = dn->dimage;
1185 di->fromname->ref++;
1186 memmove(di->name, a+6, j);
1188 client->infoid = dstid;
1191 /* name an image: 'N' dstid[4] in[1] j[1] name[j] */
1198 if(j == 0) /* give me a non-empty name please */
1203 di = drawlookup(client, BGLONG(a+1), 0);
1209 if(drawaddname(client, di, j, (char*)a+7, &err) < 0)
1212 dn = drawlookupname(j, (char*)a+7);
1215 if(dn->dimage != di)
1221 /* position window: 'o' id[4] r.min [2*4] screenr.min [2*4] */
1226 dst = drawimage(client, a+1);
1231 drawpoint(&q, a+13);
1232 r = dst->layer->screenr;
1233 ni = memlorigin(dst, p, q);
1235 err = "image origin failed";
1240 addflush(dst->layer->screenr);
1241 ll = drawlookup(client, BGLONG(a+1), 1);
1242 drawrefreshscreen(ll, client);
1247 /* set compositing operator for next draw operation: 'O' op */
1255 /* filled polygon: 'P' dstid[4] n[2] wind[4] ignore[2*4] srcid[4] sp[2*4] p0[2*4] dp[2*2*n] */
1256 /* polygon: 'p' dstid[4] n[2] end0[4] end1[4] radius[4] srcid[4] sp[2*4] p0[2*4] dp[2*2*n] */
1259 m = 1+4+2+4+4+4+4+2*4;
1262 dstid = BGLONG(a+1);
1263 dst = drawimage(client, a+1);
1266 err = "negative cout in polygon";
1275 err = "negative polygon line width";
1279 src = drawimage(client, a+19);
1282 drawpoint(&sp, a+23);
1283 drawpoint(&p, a+31);
1285 pp = mallocz(ni*sizeof(Point), 1);
1289 if(dstid==0 || (dst->layer && dst->layer->screen->image->data == screenimage->data))
1290 doflush = 1; /* simplify test in loop */
1294 for(y=0; y<ni; y++){
1297 u = drawcoord(u, a+n, ox, &p.x);
1300 u = drawcoord(u, a+n, oy, &p.y);
1309 c = memlineendsize(e0);
1314 c = memlineendsize(e1);
1319 if(*a=='P' && e0!=1 && e0 !=~0)
1322 r = Rect(q.x-oesize, q.y-oesize, q.x+oesize+1, q.y+oesize+1);
1323 combinerect(&r, Rect(p.x-esize, p.y-esize, p.x+esize+1, p.y+esize+1));
1325 if(rectclip(&r, dst->clipr)) /* should perhaps be an arg to dstflush */
1326 dstflush(dstid, dst, r);
1331 dstflush(dstid, dst, Rect(p.x-esize, p.y-esize, p.x+esize+1, p.y+esize+1));
1332 op = drawclientop(client);
1334 mempoly(dst, pp, ni, e0, e1, j, src, sp, op);
1336 memfillpoly(dst, pp, ni, e0, src, sp, op);
1341 /* read: 'r' id[4] R[4*4] */
1346 i = drawimage(client, a+1);
1349 drawrectangle(&r, a+5);
1350 if(!rectinrect(r, i->r))
1352 c = bytesperline(r, i->depth);
1354 free(client->readdata);
1355 client->readdata = mallocz(c, 0);
1356 if(client->readdata == nil){
1357 err = "readimage malloc failed";
1360 client->nreaddata = memunload(i, r, client->readdata, c);
1361 if(client->nreaddata < 0){
1362 free(client->readdata);
1363 client->readdata = nil;
1364 err = "bad readimage call";
1369 /* string: 's' dstid[4] srcid[4] fontid[4] P[2*4] clipr[4*4] sp[2*4] ni[2] ni*(index[2]) */
1370 /* stringbg: 'x' dstid[4] srcid[4] fontid[4] P[2*4] clipr[4*4] sp[2*4] ni[2] bgid[4] bgpt[2*4] ni*(index[2]) */
1373 m = 1+4+4+4+2*4+4*4+2*4+2;
1379 dst = drawimage(client, a+1);
1380 dstid = BGLONG(a+1);
1381 src = drawimage(client, a+5);
1384 font = drawlookup(client, BGLONG(a+9), 1);
1387 if(font->nfchar == 0)
1389 drawpoint(&p, a+13);
1390 drawrectangle(&r, a+21);
1391 drawpoint(&sp, a+37);
1399 op = drawclientop(client);
1401 /* paint background */
1402 l = drawimage(client, a+47);
1405 drawpoint(&q, a+51);
1407 r.min.y = p.y-font->ascent;
1409 r.max.y = r.min.y+Dy(font->image->r);
1413 if(ci<0 || ci>=font->nfchar){
1417 r.max.x += font->fchar[ci].width;
1420 memdraw(dst, r, l, q, memopaque, ZP, op);
1426 if(ci<0 || ci>=font->nfchar){
1430 q = drawchar(dst, q, src, &sp, font, ci, op);
1434 p.y -= font->ascent;
1435 dstflush(dstid, dst, Rect(p.x, p.y, q.x, p.y+Dy(font->image->r)));
1438 /* use public screen: 'S' id[4] chan[4] */
1443 dstid = BGLONG(a+1);
1446 dscrn = drawlookupdscreen(dstid);
1447 if(dscrn==0 || (dscrn->public==0 && dscrn->owner!=client))
1449 if(dscrn->screen->image->chan != BGLONG(a+5)){
1450 err = "inconsistent chan";
1453 if(drawinstallscreen(client, dscrn, 0, 0, 0, 0) == 0)
1457 /* top or bottom windows: 't' top[1] nw[2] n*id[4] */
1470 lp = mallocz(nw*sizeof(Memimage*), 1);
1473 for(j=0; j<nw; j++){
1474 lp[j] = drawimage(client, a+1+1+2+j*4);
1480 if(lp[0]->layer == 0){
1481 err = "images are not windows";
1486 if(lp[j]->layer->screen != lp[0]->layer->screen){
1487 err = "images not on same screen";
1492 memltofrontn(lp, nw);
1494 memltorearn(lp, nw);
1495 if(lp[0]->layer->screen->image->data == screenimage->data)
1497 addflush(lp[j]->layer->screenr);
1499 ll = drawlookup(client, BGLONG(a+1+1+2), 1);
1500 drawrefreshscreen(ll, client);
1509 /* write: 'y' id[4] R[4*4] data[x*1] */
1510 /* write from compressed data: 'Y' id[4] R[4*4] data[x*1] */
1516 dstid = BGLONG(a+1);
1517 dst = drawimage(client, a+1);
1520 drawrectangle(&r, a+5);
1521 if(!rectinrect(r, dst->r))
1523 y = memload(dst, r, a+m, n-m, *a=='Y');
1525 err = "bad writeimage call";
1528 dstflush(dstid, dst, r);
1537 err = "unknown id for draw image";
1540 err = "unknown id for draw screen";
1543 err = "short draw message";
1547 err = "draw read too short";
1551 err = "image id in use";
1554 err = "screen id in use";
1557 err = "image memory allocation failed";
1560 err = "readimage outside image";
1563 err = "writeimage outside image";
1566 err = "image not a font";
1569 err = "character index out of range";
1573 err = "no such draw client";
1576 err = "image has bad depth";
1579 err = "image name in use";
1583 err = "no image with that name";
1586 err = "named image no longer valid";
1589 err = "image already has name";
1592 err = "wrong name for image";
1595 err = "out of memory";
1598 err = "bad argument in draw message";