Mercurial > hg > Game > Cerium
changeset 1166:38111db531e0 draft
bmp's black has 0 alpha value for compatibility
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 21 May 2011 22:03:31 +0900 |
parents | ab8ed4d1d211 |
children | d8b5648668bb |
files | Renderer/Engine/SceneGraph.cc Renderer/Engine/SceneGraph.h |
diffstat | 2 files changed, 51 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraph.cc Sat May 21 21:32:57 2011 +0900 +++ b/Renderer/Engine/SceneGraph.cc Sat May 21 22:03:31 2011 +0900 @@ -449,8 +449,50 @@ } } +static int +is_bmp(char *name) { + int bmp = 0; + + while(*name) { + if (bmp==0 && *name=='.') bmp = 1; + else if (bmp==1 && (*name=='b' || *name=='B')) bmp = 2; + else if (bmp==2 && (*name=='m' || *name=='M')) bmp = 3; + else if (bmp==3 && (*name=='p' || *name=='P')) bmp = 4; + else bmp = 0; + name++; + } + return bmp==4; +} + +#if (__LITTLE_ENDIAN__) +#define LITTLEENDIAN 1 +#else +#define LITTLEENDIAN 0 +#endif + +static void +make_black_alpha(SDL_Surface *texture_image) +{ + int tex_w = texture_image->w; + int tex_h = texture_image->h; +#if LITTLEENDIAN + uint32 alpha = 0x000000ff; +#else + uint32 alpha = 0xff000000; +#endif + + uint32 *pixels = (uint32*)texture_image->pixels; + int i; + for(i=0;i<tex_w*tex_h;i++) { + uint32 pixel = pixels[i] & ~alpha; + if (pixel==0) { + pixels[i] = 0; + } + } +} + SDL_Surface* -SceneGraph::load_decode_image(char *image_name, xmlNodePtr cur) +SceneGraph::load_decode_image(char *file_name, char *image_name, xmlNodePtr cur) { int fd = mkstemp(image_name); FILE *outfile = fdopen(fd, "wb"); @@ -465,6 +507,8 @@ decode(cont, outfile); fclose(outfile); + int alpha_black = is_bmp(file_name); + /** * image を 32bit(RGBA) に変換する @@ -479,7 +523,6 @@ //= SDL_CreateRGBSurface(SDL_HWSURFACE, 0, // 0, 32, redMask, // greenMask, blueMask, alphaMask); - SDL_Surface *converted; converted = SDL_ConvertSurface(texture_image, tmpImage->format, SDL_HWSURFACE); @@ -491,6 +534,10 @@ texture_image = converted; } + if (alpha_black) { + make_black_alpha(texture_image); + } + // this->gl_tex = SDL_GL_LoadTexture(texture_image); return texture_image; } @@ -561,7 +608,7 @@ int tex_id; if (!texture_hash.hash_regist(filename, tex_id)) { - SDL_Surface *texture_image = load_decode_image(image_name, cur); + SDL_Surface *texture_image = load_decode_image(filename, image_name, cur); if (texture_image==0) { printf("Can't load image %s\n",filename); exit(0);
--- a/Renderer/Engine/SceneGraph.h Sat May 21 21:32:57 2011 +0900 +++ b/Renderer/Engine/SceneGraph.h Sat May 21 22:03:31 2011 +0900 @@ -115,7 +115,7 @@ void get_data(TaskManager *manager, xmlNodePtr cur); void delete_data(void); - SDL_Surface* load_decode_image(char *image_name, xmlNodePtr cur); + SDL_Surface* load_decode_image(char *filename, char *image_name, xmlNodePtr cur); int makeTapestries(TaskManager *manager, SDL_Surface *texture_image, int id); void get_image(TaskManager *manager, xmlNodePtr cur); };