--- deliantra/Deliantra-Client/Client.xs 2006/04/14 23:32:28 1.38 +++ deliantra/Deliantra-Client/Client.xs 2006/04/15 00:04:58 1.39 @@ -68,6 +68,7 @@ GLint name; int w, h; float s, t; + uint8_t r, g, b, a; } mapface; typedef struct { @@ -244,6 +245,8 @@ surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); + assert (surface2->pitch == surface2->w * 4); + EXTEND (SP, 5); PUSHs (sv_2mortal (newSViv (surface2->w))); PUSHs (sv_2mortal (newSViv (surface2->h))); @@ -259,6 +262,34 @@ } void +average (int x, int y, uint32_t *data) + PPCODE: +{ + // only good for x * y < 32768 + uint32_t r = 0, g = 0, b = 0, a = 0; + + x = y = x * y; + + assert (x < 32768); + + while (x--) + { + uint32_t p = *data++; + + r += (p ) & 255; + g += (p >> 8) & 255; + b += (p >> 16) & 255; + a += (p >> 24) & 255; + } + + EXTEND (SP, 4); + PUSHs (sv_2mortal (newSViv (r * 255 / y))); + PUSHs (sv_2mortal (newSViv (g * 255 / y))); + PUSHs (sv_2mortal (newSViv (b * 255 / y))); + PUSHs (sv_2mortal (newSViv (a * 255 / y))); +} + +void fatal (char *message) CODE: #ifdef WIN32 @@ -456,7 +487,7 @@ map_clear (self); void -set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t) +set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t, int r, int g, int b, int a) CODE: { while (self->faces < face) @@ -465,11 +496,17 @@ self->faces *= 2; } - self->face [face].name = name; - self->face [face].w = w; - self->face [face].h = h; - self->face [face].s = s; - self->face [face].t = t; + mapface *f = self->face + face; + + f->name = name; + f->w = w; + f->h = h; + f->s = s; + f->t = t; + f->r = r; + f->g = g; + f->b = b; + f->a = a; } void