Hi all,
i wanna share this function i done in c++ with all the users need to change the VIOLET color to another one to change the clothes or the skin sprite or what you need.
It work also with antialiasing and gradient.
All you need is to give to a part of the sprite the violet color (255, 0, 255) or a gradient with it in.
Feel free to modify it and make it better, but publish it below!
void ChangeVioletIMG(int image, int to_R, int to_G, int to_B){
//Now i get the image an create a memblock
int _mem = agk::CreateMemblockFromImage(image);
//int width = agk::GetMemblockInt(_mem, 0);
//int height = agk::GetMemblockInt(_mem, 4);
int size = agk::GetMemblockSize(_mem);
for(int c = 12; c < size; c += 4){
int R = agk::GetMemblockByte(_mem, c);
int G = agk::GetMemblockByte(_mem, c + 1);
int B = agk::GetMemblockByte(_mem, c + 2);
int A = agk::GetMemblockByte(_mem, c + 3);
int new_R = R;
int new_G = G;
int new_B = B;
int new_A = A;
if(A > 0){
//NSLog(@"R : %i - G : %i - B : %i - A : %i", R, G, B, A);
if(R > 100 && B > 100 && G < 100){ //Viola
if(to_R > 0 && to_G == 0 && to_B == 0){ //Rosso
new_R = to_R;
new_G = 255 - ((G + B) / 2);
new_B = 255 - ((G + B) / 2);
} else if(to_R == 0 && to_G > 0 && to_B == 0){ //Verde
new_R = 255 - ((R + B) / 2);
new_G = to_G;
new_B = 255 - ((R + B) / 2);
} else if(to_R == 0 && to_G == 0 && to_B > 0){ //Blu
new_R = 255 - ((R + G) / 2);
new_G = 255 - ((R + G) / 2);
new_B = to_B;
}/* else if(to_R > 0 && to_G > 0 && to_B == 0){ //Rosso - Verde
new_R = to_R;
new_G = to_G;
new_B = to_B;
} else if(to_R == 0 && to_G > 0 && to_B > 0){ //Verde - Blu
new_R = to_R;
new_G = to_G;
new_B = to_B;
} else if(to_R > 0 && to_G == 0 && to_B > 0){ //Rosso - Blu
new_R = to_R;
new_G = to_G;
new_B = to_B;
}*/ else {
new_R = to_R;
new_G = to_G;
new_B = to_B;
}
new_A = (R + G + B) / 3;
}
if(new_R > 255) new_R = 255;
if(new_G > 255) new_G = 255;
if(new_B > 255) new_B = 255;
if(new_A > 255) new_A = 255;
agk::SetMemblockByte(_mem, c, new_R);
agk::SetMemblockByte(_mem, c + 1, new_G);
agk::SetMemblockByte(_mem, c + 2, new_B);
agk::SetMemblockByte(_mem, c + 3, new_A);
}
}
agk::CreateImageFromMemblock(image, _mem);
agk::DeleteMemblock(_mem);
}
I done it fast but please if you found a better way, with a special formula, post it.
Thx.
Long life to Steve!