Advertisement
tic

Gdip_FilterColor

tic
Nov 19th, 2012
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. int Gdip_FilterColor(unsigned char * Bitmap, int w, int h, int Stride, unsigned int Color, unsigned int ReplaceColor, int v)
  2. {
  3.     unsigned int p, A1, R1, G1, B1, A2, R2, G2, B2, tA, tR, tG, tB;
  4.  
  5.     A1 = (Color & 0xff000000) >> 24;
  6.     R1 = (Color & 0x00ff0000) >> 16;
  7.     G1 = (Color & 0x0000ff00) >> 8;
  8.     B1 = Color & 0x000000ff;
  9.  
  10.     A2 = (ReplaceColor & 0xff000000) >> 24;
  11.     R2 = (ReplaceColor & 0x00ff0000) >> 16;
  12.     G2 = (ReplaceColor & 0x0000ff00) >> 8;
  13.     B2 = ReplaceColor & 0x000000ff;
  14.  
  15.     for (int y = 0; y < h; ++y)
  16.     {
  17.         for (int x = 0; x < w; ++x)
  18.         {
  19.             p = (4*x)+(y*Stride);
  20.  
  21.             tA = Bitmap[3+p];
  22.             tR = Bitmap[2+p];
  23.             tG = Bitmap[1+p];
  24.             tB = Bitmap[p];
  25.            
  26.             if ((tA <= A1+v && tA >= A1-v) && (tR <= R1+v && tR >= R1-v) && (tG <= G1+v && tG >= G1-v) && (tB <= B1+v && tB >= B1-v))
  27.             {
  28.                 Bitmap[3+p] = A2;
  29.                 Bitmap[2+p] = R2;
  30.                 Bitmap[1+p] = G2;
  31.                 Bitmap[p] = B2;
  32.             }
  33.            
  34.         }
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement