5 get_shape(SDL_Surface *img, struct shape *s)
11 if(img->format->BytesPerPixel != 2) {
12 fprintf(stderr, "get_shape(): not a 16-bit image!\n");
16 s->w = img->w; s->h = img->h;
17 s->mw = ((img->w+31)>>5) * img->h;
18 s->mask = malloc(4*s->mw);
20 fprintf(stderr, "can't malloc bitmask");
26 transp = img->format->colorkey;
28 for(y=0; y<img->h; y++) {
29 for(x=0; x<img->w; x++) {
30 if(*px++ != transp) bits |= 1;
31 if(x == img->w-1 || !(x+1)%32) {
34 } else bits = bits << 1;
36 px = (uint16_t *) ((uint8_t *) px + img->pitch - 2*img->w);
38 SDL_UnlockSurface(img);
42 #define max(a, b) ((a) > (b) ? (a) : (b))
46 #define min(a, b) ((a) < (b) ? (a) : (b))
50 collide(int xdiff, int ydiff, struct shape *r, struct shape *s)
54 if(xdiff >= 0) xov = max(min(r->w-xdiff, s->w), 0);
55 else xov = -max(min(s->w+xdiff, r->w), 0);
57 if(ydiff >= 0) yov = max(min(r->h-ydiff, s->h), 0);
58 else yov = -max(min(s->h+ydiff, r->h), 0);
60 if(xov == 0 && yov == 0) return 0;