#include <draw.h>
Image*
-allocimage(Display *d, Rectangle r, ulong chan, int repl, ulong val)
+allocimage(Display *d, Rectangle r, ulong chan, int repl, ulong col)
{
- Image* i;
+ Image *i;
- i = _allocimage(nil, d, r, chan, repl, val, 0, 0);
- if (i)
+ i = _allocimage(nil, d, r, chan, repl, col, 0, 0);
+ if(i != nil)
setmalloctag(i, getcallerpc(&d));
return i;
}
Image*
-_allocimage(Image *ai, Display *d, Rectangle r, ulong chan, int repl, ulong val, int screenid, int refresh)
+_allocimage(Image *ai, Display *d, Rectangle r, ulong chan, int repl, ulong col, int screenid, int refresh)
{
uchar *a;
char *err;
int id;
int depth;
- err = 0;
- i = 0;
+ err = nil;
+ i = nil;
+ if(badrect(r)){
+ werrstr("bad rectangle");
+ return nil;
+ }
if(chan == 0){
werrstr("bad channel descriptor");
return nil;
if(depth == 0){
err = "bad channel descriptor";
Error:
- if(err)
+ if(err != nil)
werrstr("allocimage: %s", err);
else
werrstr("allocimage: %r");
free(i);
- return 0;
+ return nil;
}
- /* flush pending data so we don't get error allocating the image */
- flushimage(d, 0);
a = bufimage(d, 1+4+4+1+4+1+4*4+4*4+4);
- if(a == 0)
+ if(a == nil)
goto Error;
d->imageid++;
id = d->imageid;
BPLONG(a+35, clipr.min.y);
BPLONG(a+39, clipr.max.x);
BPLONG(a+43, clipr.max.y);
- BPLONG(a+47, val);
- if(flushimage(d, 0) < 0)
- goto Error;
+ BPLONG(a+47, col);
- if(ai)
+ if(ai != nil)
i = ai;
else{
i = malloc(sizeof(Image));
if(i == nil){
a = bufimage(d, 1+4);
- if(a){
+ if(a != nil){
a[0] = 'f';
BPLONG(a+1, id);
flushimage(d, 0);
i->r = r;
i->clipr = clipr;
i->repl = repl;
- i->screen = 0;
- i->next = 0;
+ i->screen = nil;
+ i->next = nil;
return i;
}
int id, n;
ulong chan;
- err = 0;
- i = 0;
+ err = nil;
+ i = nil;
n = strlen(name);
if(n >= 256){
err = "name too long";
Error:
- if(err)
+ if(err != nil)
werrstr("namedimage: %s", err);
else
werrstr("namedimage: %r");
- if(i)
- free(i);
- return 0;
+ free(i);
+ return nil;
}
/* flush pending data so we don't get error allocating the image */
flushimage(d, 0);
a = bufimage(d, 1+4+1+n);
- if(a == 0)
+ if(a == nil)
goto Error;
d->imageid++;
id = d->imageid;
if(i == nil){
Error1:
a = bufimage(d, 1+4);
- if(a){
+ if(a != nil){
a[0] = 'f';
BPLONG(a+1, id);
flushimage(d, 0);
i->clipr.min.y = atoi(buf+9*12);
i->clipr.max.x = atoi(buf+10*12);
i->clipr.max.y = atoi(buf+11*12);
- i->screen = 0;
- i->next = 0;
+ i->screen = nil;
+ i->next = nil;
return i;
}
n = strlen(name);
a = bufimage(i->display, 1+4+1+1+n);
- if(a == 0)
+ if(a == nil)
return 0;
a[0] = 'N';
BPLONG(a+1, i->id);
Display *d;
Image *w;
- if(i == 0 || i->display == 0)
+ if(i == nil || i->display == nil)
return 0;
- /* make sure no refresh events occur on this if we block in the write */
d = i->display;
- /* flush pending data so we don't get error deleting the image */
- flushimage(d, 0);
- a = bufimage(d, 1+4);
- if(a == 0)
- return -1;
- a[0] = 'f';
- BPLONG(a+1, i->id);
- if(i->screen){
+ if(i->screen != nil){
w = d->windows;
if(w == i)
d->windows = i->next;
else
- while(w){
+ while(w != nil){
if(w->next == i){
w->next = i->next;
break;
w = w->next;
}
}
- if(flushimage(d, i->screen!=0) < 0)
+ a = bufimage(d, 1+4);
+ if(a == nil)
return -1;
-
+ a[0] = 'f';
+ BPLONG(a+1, i->id);
return 0;
}