6 allocimage(Display *d, Rectangle r, ulong chan, int repl, ulong val)
10 i = _allocimage(nil, d, r, chan, repl, val, 0, 0);
12 setmalloctag(i, getcallerpc(&d));
17 _allocimage(Image *ai, Display *d, Rectangle r, ulong chan, int repl, ulong val, 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 /* flush pending data so we don't get error allocating the image */
52 a = bufimage(d, 1+4+4+1+4+1+4*4+4*4+4);
59 BPLONG(a+5, screenid);
63 BPLONG(a+15, r.min.x);
64 BPLONG(a+19, r.min.y);
65 BPLONG(a+23, r.max.x);
66 BPLONG(a+27, r.max.y);
68 /* huge but not infinite, so various offsets will leave it huge, not overflow */
69 clipr = Rect(-0x3FFFFFFF, -0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF);
72 BPLONG(a+31, clipr.min.x);
73 BPLONG(a+35, clipr.min.y);
74 BPLONG(a+39, clipr.max.x);
75 BPLONG(a+43, clipr.max.y);
77 if(flushimage(d, 0) < 0)
83 i = malloc(sizeof(Image));
107 namedimage(Display *d, char *name)
110 char *err, buf[12*12+1];
120 err = "name too long";
123 werrstr("namedimage: %s", err);
125 werrstr("namedimage: %r");
129 /* flush pending data so we don't get error allocating the image */
131 a = bufimage(d, 1+4+1+n);
139 memmove(a+6, name, n);
140 if(flushimage(d, 0) < 0)
143 if(pread(d->ctlfd, buf, sizeof buf, 0) < 12*12)
147 i = malloc(sizeof(Image));
150 a = bufimage(d, 1+4);
160 if((chan=strtochan(buf+2*12))==0){
161 werrstr("bad channel '%.12s' from devdraw", buf+2*12);
165 i->depth = chantodepth(chan);
166 i->repl = atoi(buf+3*12);
167 i->r.min.x = atoi(buf+4*12);
168 i->r.min.y = atoi(buf+5*12);
169 i->r.max.x = atoi(buf+6*12);
170 i->r.max.y = atoi(buf+7*12);
171 i->clipr.min.x = atoi(buf+8*12);
172 i->clipr.min.y = atoi(buf+9*12);
173 i->clipr.max.x = atoi(buf+10*12);
174 i->clipr.max.y = atoi(buf+11*12);
181 nameimage(Image *i, char *name, int in)
187 a = bufimage(i->display, 1+4+1+1+n);
194 memmove(a+7, name, n);
195 if(flushimage(i->display, 0) < 0)
201 _freeimage1(Image *i)
207 if(i == nil || i->display == nil)
211 if(i->screen != nil){
214 d->windows = i->next;
224 a = bufimage(d, 1+4);
229 if(flushimage(d, i->screen!=nil) < 0)
240 ret = _freeimage1(i);