30.09.2010, 14:45
(
Последний раз редактировалось Kyosaur; 30.09.2010 в 14:56.
)
RGBAToInt(red,green,blue,alpha) by kyoshiro aka kyosaur
What is it?This define does exactly as it's name implies, it converts rgba values into a single integer which can be used for colors. I haven't seen one posted here yet, so i made 3 different versions and ran speed tests.
Here's the fastest (for those who dont care about the tests):
Code
pawn Код:
#define RGBAToInt(%0,%1,%2,%3) ((16777216 * (%0)) + (65536 * (%1)) + (256 * (%2)) + (%3))
Here are the tests and all three functions for those who were curious:
pawn Код:
#define RGBAToInt1(%0,%1,%2,%3) (((%0) << 24) | ((%1) << 16) | ((%2) << 8 | (%3)))
#define RGBAToInt2(%0,%1,%2,%3) ((16777216 * (%0)) + (65536 * (%1)) + (256 * (%2)) + (%3))
#define RGBAToInt3(%0,%1,%2,%3) ((16777216 * (%0)) | (65536 * (%1)) | (256 * (%2)) | (%3))
pawn Код:
//test 1
RGBAToInt (1): Number = 946968831 || Time = 3006 ms
RGBAToInt (2): Number = 946968831 || Time = 2762 ms
RGBAToInt (3): Number = 946968831 || Time = 2894 ms
//test 2
RGBAToInt (1): Number = -2070156545 || Time = 3038 ms
RGBAToInt (2): Number = -2070156545 || Time = 2764 ms
RGBAToInt (3): Number = -2070156545 || Time = 2897 ms
//test 3
RGBAToInt (1): Number = 1266655999 || Time = 3029 ms
RGBAToInt (2): Number = 1266655999 || Time = 2764 ms
RGBAToInt (3): Number = 1266655999 || Time = 2900 ms