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 fprint(2, "nil dstflush\n");
285 if(l->screen->image->data != screenimage->data)
287 r = rectaddpt(r, l->delta);
288 l = l->screen->image->layer;
297 _flushmemscreen(flushrect);
298 flushrect = Rect(10000, 10000, -10000, -10000);
311 drawcmp(char *a, char *b, int n)
315 return memcmp(a, b, n);
320 drawlookupname(int n, char *str)
325 ename = &name[sdraw.nname];
326 for(; name<ename; name++)
327 if(drawcmp(name->name, str, n) == 0)
334 drawgoodname(DImage *d)
338 /* if window, validate the screen's own images */
340 if(drawgoodname(d->dscreen->dimage) == 0
341 || drawgoodname(d->dscreen->dfill) == 0)
345 n = drawlookupname(strlen(d->name), d->name);
346 if(n==nil || n->vers!=d->vers)
353 drawlookup(Client *client, int id, int checkname)
357 d = client->dimage[id&HASHMASK];
361 * BUG: should error out but too hard.
364 if(checkname && !drawgoodname(d))
375 drawlookupdscreen(int id)
390 drawlookupscreen(Client *client, int id, CScreen **cs)
396 if(s->dscreen->id == id){
402 /* caller must check! */
408 drawinstall(Client *client, int id, Memimage *i, DScreen *dscreen)
412 d = mallocz(sizeof(DImage), 1);
425 d->dscreen = dscreen;
426 d->next = client->dimage[id&HASHMASK];
427 client->dimage[id&HASHMASK] = d;
433 drawinstallscreen(Client *client, DScreen *d, int id, DImage *dimage, DImage *dfill, int public)
438 c = mallocz(sizeof(CScreen), 1);
439 if(dimage && dimage->image && dimage->image->chan == 0){
440 fprint(2, "bad image %p in drawinstallscreen", dimage->image);
447 d = mallocz(sizeof(DScreen), 1);
452 s = mallocz(sizeof(Memscreen), 1);
462 s->image = dimage->image;
467 s->fill = dfill->image;
480 c->next = client->cscreen;
487 drawdelname(DName *name)
492 memmove(name, name+1, (sdraw.nname-(i+1))*sizeof(DName));
498 drawfreedscreen(DScreen *this)
504 fprint(2, "negative ref in drawfreedscreen\n");
509 dscreen = this->next;
512 while(next = ds->next){ /* assign = */
514 ds->next = this->next;
520 * Should signal Enodrawimage, but too hard.
526 drawfreedimage(this->dimage);
528 drawfreedimage(this->dfill);
535 drawfreedimage(DImage *dimage)
543 fprint(2, "negative ref in drawfreedimage\n");
548 for(i=0; i<sdraw.nname; )
549 if(sdraw.name[i].dimage == dimage)
550 drawdelname(sdraw.name+i);
553 if(dimage->fromname){ /* acquired by name; owned by someone else*/
554 drawfreedimage(dimage->fromname);
557 ds = dimage->dscreen;
559 dimage->dscreen = nil; /* paranoia */
562 if(l->data == screenimage->data)
563 addflush(l->layer->screenr);
564 if(l->layer->refreshfn == drawrefresh) /* else true owner will clean up */
565 free(l->layer->refreshptr);
566 l->layer->refreshptr = nil;
567 if(drawgoodname(dimage))
575 else if(--l->screenref==0)
585 drawuninstallscreen(Client *client, CScreen *this)
589 cs = client->cscreen;
591 client->cscreen = this->next;
592 drawfreedscreen(this->dscreen);
596 while(next = cs->next){ /* assign = */
598 cs->next = this->next;
599 drawfreedscreen(this->dscreen);
609 drawuninstall(Client *client, int id)
613 for(l=&client->dimage[id&HASHMASK]; (d=*l) != nil; l=&d->next){
625 drawaddname(Client *client, DImage *di, int n, char *str, char **err)
627 DName *name, *ename, *new, *t;
631 ename = &name[sdraw.nname];
632 for(; name<ename; name++)
633 if(drawcmp(name->name, str, n) == 0){
634 *err = "image name in use";
637 t = mallocz((sdraw.nname+1)*sizeof(DName), 1);
639 if(t == nil || ns == nil){
642 *err = "out of memory";
645 memmove(t, sdraw.name, sdraw.nname*sizeof(DName));
648 new = &sdraw.name[sdraw.nname++];
650 memmove(new->name, str, n);
653 new->client = client;
654 new->vers = ++sdraw.vers;
659 drawclientop(Client *cl)
670 drawimage(Client *client, uchar *a)
674 d = drawlookup(client, BGLONG(a), 1);
676 return nil; /* caller must check! */
682 drawrectangle(Rectangle *r, uchar *a)
684 r->min.x = BGLONG(a+0*4);
685 r->min.y = BGLONG(a+1*4);
686 r->max.x = BGLONG(a+2*4);
687 r->max.y = BGLONG(a+3*4);
692 drawpoint(Point *p, uchar *a)
694 p->x = BGLONG(a+0*4);
695 p->y = BGLONG(a+1*4);
700 drawchar(Memimage *dst, Point p, Memimage *src, Point *sp, DImage *font, int index, int op)
706 fc = &font->fchar[index];
707 r.min.x = p.x+fc->left;
708 r.min.y = p.y-(font->ascent-fc->miny);
709 r.max.x = r.min.x+(fc->maxx-fc->minx);
710 r.max.y = r.min.y+(fc->maxy-fc->miny);
711 sp1.x = sp->x+fc->left;
712 sp1.y = sp->y+fc->miny;
713 memdraw(dst, r, src, sp1, font->image, Pt(fc->minx, fc->miny), op);
721 drawcoord(uchar *p, uchar *maxp, int oldx, int *newx)
746 _drawmsgread(void *a, int n)
752 if(cl->readdata == nil){
753 werrstr("no draw data");
756 if(n < cl->nreaddata){
757 werrstr("short read");
761 memmove(a, cl->readdata, cl->nreaddata);
773 _drawmsgwrite(void *v, int n)
775 char cbuf[40], *err, ibuf[12*12+1], *s;
776 int c, ci, doflush, dstid, e0, e1, esize, j, m;
777 int ni, nw, oesize, oldn, op, ox, oy, repl, scrnid, y;
778 uchar *a, refresh, *u;
782 DImage *di, *ddst, *dsrc, *font, *ll;
786 Memimage *dst, *i, *l, **lp, *mask, *src;
801 /* print("msgwrite %d(%c)...", n, *a); */
804 /*fprint(2, "bad command %d\n", *a); */
805 err = "bad draw command";
808 /* allocate: 'b' id[4] screenid[4] refresh[1] chan[4] repl[1]
809 R[4*4] clipR[4*4] rrggbbaa[4]
812 m = 1+4+4+1+4+1+4*4+4*4+4;
816 scrnid = BGSHORT(a+5);
820 drawrectangle(&r, a+15);
821 drawrectangle(&clipr, a+31);
822 value = BGLONG(a+47);
823 if(drawlookup(client, dstid, 0))
826 dscrn = drawlookupscreen(client, scrnid, &cs);
829 scrn = dscrn->screen;
830 if(repl || chan!=scrn->image->chan){
831 err = "image parameters incompatibile with screen";
839 reffn = memlnorefresh;
845 err = "unknown refresh method";
848 l = memlalloc(scrn, r, reffn, 0, value);
851 addflush(l->layer->screenr);
853 rectclip(&l->clipr, r);
854 if(drawinstall(client, dstid, l, dscrn) == 0){
861 if(reffn == drawrefresh){
862 refx = mallocz(sizeof(Refx), 1);
864 if(drawuninstall(client, dstid) < 0)
868 refx->client = client;
869 refx->dimage = drawlookup(client, dstid, 1);
871 memlsetrefresh(l, reffn, refx);
875 i = allocmemimage(r, chan);
882 rectclip(&i->clipr, r);
883 if(drawinstall(client, dstid, i, 0) == 0){
887 memfillcolor(i, value);
890 /* allocate screen: 'A' id[4] imageid[4] fillid[4] public[1] */
898 if(drawlookupdscreen(dstid))
900 ddst = drawlookup(client, BGLONG(a+5), 1);
901 dsrc = drawlookup(client, BGLONG(a+9), 1);
902 if(ddst==0 || dsrc==0)
904 if(drawinstallscreen(client, 0, dstid, ddst, dsrc, a[13]) == 0)
908 /* set repl and clip: 'c' dstid[4] repl[1] clipR[4*4] */
913 ddst = drawlookup(client, BGLONG(a+1), 1);
917 err = "can't change repl/clipr of shared image";
923 drawrectangle(&dst->clipr, a+6);
926 /* draw: 'd' dstid[4] srcid[4] maskid[4] R[4*4] P[2*4] P[2*4] */
928 m = 1+4+4+4+4*4+2*4+2*4;
931 dst = drawimage(client, a+1);
933 src = drawimage(client, a+5);
934 mask = drawimage(client, a+9);
935 if(!dst || !src || !mask)
937 drawrectangle(&r, a+13);
940 op = drawclientop(client);
941 memdraw(dst, r, src, p, mask, q, op);
942 dstflush(dstid, dst, r);
945 /* toggle debugging: 'D' val[1] */
953 /* ellipse: 'e' dstid[4] srcid[4] center[2*4] a[4] b[4] thick[4] sp[2*4] alpha[4] phi[4]*/
956 m = 1+4+4+2*4+4+4+4+2*4+2*4;
959 dst = drawimage(client, a+1);
961 src = drawimage(client, a+5);
968 err = "invalid ellipse semidiameter";
973 err = "negative ellipse thickness";
977 drawpoint(&sp, a+29);
983 op = drawclientop(client);
984 /* high bit indicates arc angles are present */
985 if(ox & ((ulong)1<<31)){
986 if((ox & ((ulong)1<<30)) == 0)
987 ox &= ~((ulong)1<<31);
988 memarc(dst, p, e0, e1, c, src, sp, ox, oy, op);
990 memellipse(dst, p, e0, e1, c, src, sp, op);
991 dstflush(dstid, dst, Rect(p.x-e0-j, p.y-e1-j, p.x+e0+j+1, p.y+e1+j+1));
994 /* free: 'f' id[4] */
999 ll = drawlookup(client, BGLONG(a+1), 0);
1000 if(ll && ll->dscreen && ll->dscreen->owner != client)
1001 ll->dscreen->owner->refreshme = 1;
1002 if(drawuninstall(client, BGLONG(a+1)) < 0)
1006 /* free screen: 'F' id[4] */
1011 if(!drawlookupscreen(client, BGLONG(a+1), &cs))
1013 drawuninstallscreen(client, cs);
1016 /* initialize font: 'i' fontid[4] nchars[4] ascent[1] */
1021 dstid = BGLONG(a+1);
1023 err = "can't use display as font";
1026 font = drawlookup(client, dstid, 1);
1029 if(font->image->layer){
1030 err = "can't use window as font";
1034 if(ni<=0 || ni>4096){
1035 err = "bad font size (4096 chars max)";
1038 free(font->fchar); /* should we complain if non-zero? */
1039 font->fchar = mallocz(ni*sizeof(FChar), 1);
1040 if(font->fchar == 0){
1041 err = "no memory for font";
1044 memset(font->fchar, 0, ni*sizeof(FChar));
1046 font->ascent = a[9];
1049 /* set image 0 to screen image */
1054 if(drawlookup(client, 0, 0))
1056 drawinstall(client, 0, screenimage, 0);
1060 /* get image info: 'I' */
1065 if(client->infoid < 0)
1067 if(client->infoid == 0){
1072 di = drawlookup(client, client->infoid, 1);
1077 ni = sprint(ibuf, "%11d %11d %11s %11d %11d %11d %11d %11d"
1078 " %11d %11d %11d %11d ",
1081 chantostr(cbuf, i->chan),
1082 (i->flags&Frepl)==Frepl,
1083 i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y,
1084 i->clipr.min.x, i->clipr.min.y,
1085 i->clipr.max.x, i->clipr.max.y);
1086 free(client->readdata);
1087 client->readdata = malloc(ni);
1088 if(client->readdata == nil)
1090 memmove(client->readdata, ibuf, ni);
1091 client->nreaddata = ni;
1092 client->infoid = -1;
1095 /* load character: 'l' fontid[4] srcid[4] index[2] R[4*4] P[2*4] left[1] width[1] */
1097 m = 1+4+4+2+4*4+2*4+1+1;
1100 font = drawlookup(client, BGLONG(a+1), 1);
1103 if(font->nfchar == 0)
1105 src = drawimage(client, a+5);
1109 if(ci >= font->nfchar)
1111 drawrectangle(&r, a+11);
1112 drawpoint(&p, a+27);
1113 memdraw(font->image, r, src, p, memopaque, p, S);
1114 fc = &font->fchar[ci];
1123 /* draw line: 'L' dstid[4] p0[2*4] p1[2*4] end0[4] end1[4] radius[4] srcid[4] sp[2*4] */
1125 m = 1+4+2*4+2*4+4+4+4+4+2*4;
1128 dst = drawimage(client, a+1);
1129 dstid = BGLONG(a+1);
1131 drawpoint(&q, a+13);
1136 err = "negative line width";
1139 src = drawimage(client, a+33);
1142 drawpoint(&sp, a+37);
1143 op = drawclientop(client);
1144 memline(dst, p, q, e0, e1, j, src, sp, op);
1145 /* avoid memlinebbox if possible */
1146 if(dstid==0 || dst->layer!=nil){
1147 /* BUG: this is terribly inefficient: update maximal containing rect*/
1148 r = memlinebbox(p, q, e0, e1, j);
1149 dstflush(dstid, dst, insetrect(r, -(1+1+j)));
1153 /* create image mask: 'm' newid[4] id[4] */
1164 /* attach to a named image: 'n' dstid[4] j[1] name[j] */
1170 if(j == 0) /* give me a non-empty name please */
1175 dstid = BGLONG(a+1);
1176 if(drawlookup(client, dstid, 0))
1178 dn = drawlookupname(j, (char*)a+6);
1184 if(drawinstall(client, dstid, dn->dimage->image, 0) == 0)
1186 di = drawlookup(client, dstid, 0);
1189 di->vers = dn->vers;
1191 di->fromname = dn->dimage;
1192 di->fromname->ref++;
1193 memmove(di->name, a+6, j);
1195 client->infoid = dstid;
1198 /* name an image: 'N' dstid[4] in[1] j[1] name[j] */
1205 if(j == 0) /* give me a non-empty name please */
1210 di = drawlookup(client, BGLONG(a+1), 0);
1216 if(drawaddname(client, di, j, (char*)a+7, &err) < 0)
1219 dn = drawlookupname(j, (char*)a+7);
1222 if(dn->dimage != di)
1228 /* position window: 'o' id[4] r.min [2*4] screenr.min [2*4] */
1233 dst = drawimage(client, a+1);
1238 drawpoint(&q, a+13);
1239 r = dst->layer->screenr;
1240 ni = memlorigin(dst, p, q);
1242 err = "image origin failed";
1247 addflush(dst->layer->screenr);
1248 ll = drawlookup(client, BGLONG(a+1), 1);
1249 drawrefreshscreen(ll, client);
1254 /* set compositing operator for next draw operation: 'O' op */
1262 /* filled polygon: 'P' dstid[4] n[2] wind[4] ignore[2*4] srcid[4] sp[2*4] p0[2*4] dp[2*2*n] */
1263 /* polygon: 'p' dstid[4] n[2] end0[4] end1[4] radius[4] srcid[4] sp[2*4] p0[2*4] dp[2*2*n] */
1266 m = 1+4+2+4+4+4+4+2*4;
1269 dstid = BGLONG(a+1);
1270 dst = drawimage(client, a+1);
1273 err = "negative cout in polygon";
1282 err = "negative polygon line width";
1286 src = drawimage(client, a+19);
1289 drawpoint(&sp, a+23);
1290 drawpoint(&p, a+31);
1292 pp = mallocz(ni*sizeof(Point), 1);
1296 if(dstid==0 || (dst->layer && dst->layer->screen->image->data == screenimage->data))
1297 doflush = 1; /* simplify test in loop */
1301 for(y=0; y<ni; y++){
1304 u = drawcoord(u, a+n, ox, &p.x);
1307 u = drawcoord(u, a+n, oy, &p.y);
1316 c = memlineendsize(e0);
1321 c = memlineendsize(e1);
1326 if(*a=='P' && e0!=1 && e0 !=~0)
1329 r = Rect(q.x-oesize, q.y-oesize, q.x+oesize+1, q.y+oesize+1);
1330 combinerect(&r, Rect(p.x-esize, p.y-esize, p.x+esize+1, p.y+esize+1));
1332 if(rectclip(&r, dst->clipr)) /* should perhaps be an arg to dstflush */
1333 dstflush(dstid, dst, r);
1338 dstflush(dstid, dst, Rect(p.x-esize, p.y-esize, p.x+esize+1, p.y+esize+1));
1339 op = drawclientop(client);
1341 mempoly(dst, pp, ni, e0, e1, j, src, sp, op);
1343 memfillpoly(dst, pp, ni, e0, src, sp, op);
1348 /* read: 'r' id[4] R[4*4] */
1353 i = drawimage(client, a+1);
1356 drawrectangle(&r, a+5);
1357 if(!rectinrect(r, i->r))
1359 c = bytesperline(r, i->depth);
1361 free(client->readdata);
1362 client->readdata = mallocz(c, 0);
1363 if(client->readdata == nil){
1364 err = "readimage malloc failed";
1367 client->nreaddata = memunload(i, r, client->readdata, c);
1368 if(client->nreaddata < 0){
1369 free(client->readdata);
1370 client->readdata = nil;
1371 err = "bad readimage call";
1376 /* string: 's' dstid[4] srcid[4] fontid[4] P[2*4] clipr[4*4] sp[2*4] ni[2] ni*(index[2]) */
1377 /* 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]) */
1380 m = 1+4+4+4+2*4+4*4+2*4+2;
1386 dst = drawimage(client, a+1);
1387 dstid = BGLONG(a+1);
1388 src = drawimage(client, a+5);
1391 font = drawlookup(client, BGLONG(a+9), 1);
1394 if(font->nfchar == 0)
1396 drawpoint(&p, a+13);
1397 drawrectangle(&r, a+21);
1398 drawpoint(&sp, a+37);
1406 op = drawclientop(client);
1408 /* paint background */
1409 l = drawimage(client, a+47);
1412 drawpoint(&q, a+51);
1414 r.min.y = p.y-font->ascent;
1416 r.max.y = r.min.y+Dy(font->image->r);
1420 if(ci<0 || ci>=font->nfchar){
1424 r.max.x += font->fchar[ci].width;
1427 memdraw(dst, r, l, q, memopaque, ZP, op);
1433 if(ci<0 || ci>=font->nfchar){
1437 q = drawchar(dst, q, src, &sp, font, ci, op);
1441 p.y -= font->ascent;
1442 dstflush(dstid, dst, Rect(p.x, p.y, q.x, p.y+Dy(font->image->r)));
1445 /* use public screen: 'S' id[4] chan[4] */
1450 dstid = BGLONG(a+1);
1453 dscrn = drawlookupdscreen(dstid);
1454 if(dscrn==0 || (dscrn->public==0 && dscrn->owner!=client))
1456 if(dscrn->screen->image->chan != BGLONG(a+5)){
1457 err = "inconsistent chan";
1460 if(drawinstallscreen(client, dscrn, 0, 0, 0, 0) == 0)
1464 /* top or bottom windows: 't' top[1] nw[2] n*id[4] */
1477 lp = mallocz(nw*sizeof(Memimage*), 1);
1480 for(j=0; j<nw; j++){
1481 lp[j] = drawimage(client, a+1+1+2+j*4);
1487 if(lp[0]->layer == 0){
1488 err = "images are not windows";
1493 if(lp[j]->layer->screen != lp[0]->layer->screen){
1494 err = "images not on same screen";
1499 memltofrontn(lp, nw);
1501 memltorearn(lp, nw);
1502 if(lp[0]->layer->screen->image->data == screenimage->data)
1504 addflush(lp[j]->layer->screenr);
1506 ll = drawlookup(client, BGLONG(a+1+1+2), 1);
1507 drawrefreshscreen(ll, client);
1516 /* write: 'y' id[4] R[4*4] data[x*1] */
1517 /* write from compressed data: 'Y' id[4] R[4*4] data[x*1] */
1523 dstid = BGLONG(a+1);
1524 dst = drawimage(client, a+1);
1527 drawrectangle(&r, a+5);
1528 if(!rectinrect(r, dst->r))
1530 y = memload(dst, r, a+m, n-m, *a=='Y');
1532 err = "bad writeimage call";
1535 dstflush(dstid, dst, r);
1544 err = "unknown id for draw image";
1547 err = "unknown id for draw screen";
1550 err = "short draw message";
1554 err = "draw read too short";
1558 err = "image id in use";
1561 err = "screen id in use";
1564 err = "image memory allocation failed";
1567 err = "readimage outside image";
1570 err = "writeimage outside image";
1573 err = "image not a font";
1576 err = "character index out of range";
1580 err = "no such draw client";
1583 err = "image has bad depth";
1586 err = "image name in use";
1590 err = "no image with that name";
1593 err = "named image no longer valid";
1596 err = "image already has name";
1599 err = "wrong name for image";
1602 err = "out of memory";
1605 err = "bad argument in draw message";