--- deliantra/Deliantra-Client/Client.xs 2006/04/12 20:06:36 1.22 +++ deliantra/Deliantra-Client/Client.xs 2006/04/12 20:42:52 1.23 @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -103,6 +104,61 @@ pango_context_set_font_description (context, font); } +void +load_image_inline (SV *image_) + ALIAS: + load_image_file = 1 + PPCODE: +{ + STRLEN image_len; + char *image = (char *)SvPVbyte (image_, image_len); + SDL_Surface *surface, *surface2; + SDL_PixelFormat fmt; + SDL_RWops *rw = ix + ? SDL_RWFromFile (image, "r") + : SDL_RWFromConstMem (image, image_len); + + if (!rw) + croak ("load_image: unable to open file"); + + surface = IMG_Load_RW (rw, 1); + if (!surface) + croak ("load_image: unable to read file"); + + fmt.palette = NULL; + fmt.BitsPerPixel = 32; + fmt.BytesPerPixel = 4; + fmt.Rmask = 0x000000ff; + fmt.Gmask = 0x0000ff00; + fmt.Bmask = 0x00ff0000; + fmt.Amask = 0xff000000; + fmt.Rloss = 0; + fmt.Gloss = 0; + fmt.Bloss = 0; + fmt.Aloss = 0; + fmt.Rshift = 0; + fmt.Gshift = 8; + fmt.Bshift = 16; + fmt.Ashift = 24; + fmt.colorkey = 0; + fmt.alpha = 0; + + surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); + + EXTEND (SP, 5); + PUSHs (sv_2mortal (newSViv (surface2->w))); + PUSHs (sv_2mortal (newSViv (surface2->h))); + SDL_LockSurface (surface2); + PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); + SDL_UnlockSurface (surface2); + PUSHs (sv_2mortal (newSViv (surface->format->Amask ? GL_RGBA : GL_RGB))); + PUSHs (sv_2mortal (newSViv (GL_RGBA))); + PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_INT_8_8_8_8_REV))); + + SDL_FreeSurface (surface); + SDL_FreeSurface (surface2); +} + MODULE = CFClient PACKAGE = CFClient::Layout CFClient::Layout