6 allocimage(Display *d, Rectangle r, ulong chan, int repl, ulong col)
10 i = _allocimage(nil, d, r, chan, repl, col, 0, 0);
12 setmalloctag(i, getcallerpc(&d));
17 _allocimage(Image *ai, Display *d, Rectangle r, ulong chan, int repl, ulong col, int screenid, int refresh)
30 werrstr("bad rectangle");
34 werrstr("bad channel descriptor");
38 depth = chantodepth(chan);
40 err = "bad channel descriptor";
43 werrstr("allocimage: %s", err);
45 werrstr("allocimage: %r");
50 a = bufimage(d, 1+4+4+1+4+1+4*4+4*4+4);
57 BPLONG(a+5, screenid);
61 BPLONG(a+15, r.min.x);
62 BPLONG(a+19, r.min.y);
63 BPLONG(a+23, r.max.x);
64 BPLONG(a+27, r.max.y);
66 /* huge but not infinite, so various offsets will leave it huge, not overflow */
67 clipr = Rect(-0x3FFFFFFF, -0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF);
70 BPLONG(a+31, clipr.min.x);
71 BPLONG(a+35, clipr.min.y);
72 BPLONG(a+39, clipr.max.x);
73 BPLONG(a+43, clipr.max.y);
79 i = malloc(sizeof(Image));
103 namedimage(Display *d, char *name)
106 char *err, buf[12*12+1];
116 err = "name too long";
119 werrstr("namedimage: %s", err);
121 werrstr("namedimage: %r");
125 /* flush pending data so we don't get error allocating the image */
127 a = bufimage(d, 1+4+1+n);
135 memmove(a+6, name, n);
136 if(flushimage(d, 0) < 0)
139 if(pread(d->ctlfd, buf, sizeof buf, 0) < 12*12)
143 i = malloc(sizeof(Image));
146 a = bufimage(d, 1+4);
156 if((chan=strtochan(buf+2*12))==0){
157 werrstr("bad channel '%.12s' from devdraw", buf+2*12);
161 i->depth = chantodepth(chan);
162 i->repl = atoi(buf+3*12);
163 i->r.min.x = atoi(buf+4*12);
164 i->r.min.y = atoi(buf+5*12);
165 i->r.max.x = atoi(buf+6*12);
166 i->r.max.y = atoi(buf+7*12);
167 i->clipr.min.x = atoi(buf+8*12);
168 i->clipr.min.y = atoi(buf+9*12);
169 i->clipr.max.x = atoi(buf+10*12);
170 i->clipr.max.y = atoi(buf+11*12);
177 nameimage(Image *i, char *name, int in)
183 a = bufimage(i->display, 1+4+1+1+n);
190 memmove(a+7, name, n);
191 if(flushimage(i->display, 0) < 0)
197 _freeimage1(Image *i)
203 if(i == nil || i->display == nil)
206 if(i->screen != nil){
209 d->windows = i->next;
219 a = bufimage(d, 1+4);
232 ret = _freeimage1(i);