Guest User

EO hair/helm gfx manipulation_

a guest
Oct 4th, 2017
93
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bool Video::SetTransparentPixel(SDL_Surface *surface,SDL_Color color)
  2. {
  3.     if(!surface) return false;
  4.  
  5.     unsigned int *pixels = (unsigned int *)surface->pixels;
  6.     unsigned int pixel = 0;
  7.     int pixelnum = surface->w * surface->h;
  8.     unsigned char r;
  9.     unsigned char g;
  10.     unsigned char b;
  11.  
  12.     for(int i = 0; i < pixelnum; i++)
  13.     {
  14.         pixel = *((unsigned int *)surface->pixels + i);
  15.         SDL_GetRGB(pixel, surface->format, &r, &g, &b);
  16.  
  17.         if(color.r == r && color.b == b && color.g == g)
  18.         {
  19.             pixels[i] = SDL_MapRGB(surface->format, 0, 0, 0);
  20.  
  21.         }
  22.     }
  23.  
  24.     return true;
  25. }
  26.  
  27.  
  28. bool Video::GetTransparentPixel(SDL_Surface *surface,SDL_Color color)
  29. {
  30.     if(!surface) return false;
  31.  
  32.     unsigned int pixel = 0;
  33.     int pixelnum = surface->w * surface->h;
  34.  
  35.     unsigned char r;
  36.     unsigned char g;
  37.     unsigned char b;
  38.  
  39.     for(int i = 0; i < pixelnum; i++)
  40.     {
  41.         pixel = *((unsigned int *)surface->pixels + i);
  42.         SDL_GetRGB(pixel, surface->format, &r, &g, &b);
  43.  
  44.         if(color.r == r && color.b == b && color.g == g)
  45.         {
  46.             return true;
  47.         }
  48.     }
  49.  
  50.     return false;
  51. }
  52.  
  53. std::vector<std::pair<int,int>> Video::MapNonTransparentPixels(SDL_Surface *surface,SDL_Color color)
  54. {
  55.     unsigned int pixel = 0;
  56.     std::vector<std::pair<int,int>> pix_xy;
  57.     unsigned char r;
  58.     unsigned char g;
  59.     unsigned char b;
  60.     int i = -1;
  61.  
  62.     for(int y = 0;y < surface->h;++y)
  63.     {
  64.         for(int x = 0;x < surface->w;++x)
  65.         {
  66.             i = y * surface->pitch / 4 + x;
  67.             pixel = *((unsigned int *)surface->pixels + i);
  68.             SDL_GetRGB(pixel, surface->format, &r, &g, &b);
  69.  
  70.             if(color.r != r || color.b != b  || color.g != g)
  71.             {
  72.                 pix_xy.push_back(std::make_pair(x,y));
  73.             }
  74.         }
  75.     }
  76.  
  77.     return pix_xy;
  78. }
  79.  
  80. std::vector<std::pair<int,int>> Video::MapTransparentPixels(SDL_Surface *surface,SDL_Color color)
  81. {
  82.     unsigned int pixel = 0;
  83.     std::vector<std::pair<int,int>> pix_xy;
  84.     unsigned char r;
  85.     unsigned char g;
  86.     unsigned char b;
  87.     int i = -1;
  88.  
  89.     for(int y = 0;y < surface->h;++y)
  90.     {
  91.         for(int x = 0;x < surface->w;++x)
  92.         {
  93.             i = y * surface->pitch / 4 + x;
  94.             pixel = *((unsigned int *)surface->pixels + i);
  95.             SDL_GetRGB(pixel, surface->format, &r, &g, &b);
  96.  
  97.             if(color.r == r && color.b == b  && color.g == g)
  98.             {
  99.                 pix_xy.push_back(std::make_pair(x,y));
  100.             }
  101.         }
  102.     }
  103.  
  104.     return pix_xy;
  105. }
  106. /*
  107. EndlessClient uses a special method of rendering hair to ensure that face masks are rendered one way,
  108. hoods/helmets are rendered a second way, and hats that should clip hair are rendered a third way.
  109. */
  110. bool Video::ReplacePixels(SDL_Surface *surface,std::vector<std::pair<int,int>> pix_xy)
  111. {
  112.     if(!surface || pix_xy.empty()) return false;
  113.  
  114.     unsigned int *pixels = (unsigned int *)surface->pixels;
  115.  
  116.      int i = -1;
  117.  
  118.     for(int y = 0;y < surface->h;++y)
  119.     {
  120.         for(int x = 0;x < surface->w;++x)
  121.         {
  122.             i = y * surface->pitch / 4 + x;
  123.             for(unsigned int s = 0; s < pix_xy.size();++s)
  124.             {
  125.                 if(pix_xy[s].first == x && pix_xy[s].second == y)
  126.                 {
  127.                      pixels[i] = SDL_MapRGB(surface->format, 0, 0,0);
  128.                      break;
  129.                 }
  130.             }
  131.         }
  132.     }
  133.  
  134.     return true;
  135. }
RAW Paste Data