-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolours.cpp
66 lines (36 loc) · 1.09 KB
/
colours.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "pch.h"
// C++ Implementation
unsigned int colourTextToInt(const char *text) {
int red = colourDigitToByte(text[3]);
int green = colourDigitToByte(text[4]);
int blue = colourDigitToByte(text[5]);
int alpha = colourDigitToByte(text[6]);
int argb = alpha;
argb = (argb << 8) + red;
argb = (argb << 8) + green;
argb = (argb << 8) + blue;
return argb;
}
int colourDigitToByte(char typedValue) {
float maxTypedValue = 0xF;
float maxEncodedValue = 0xFF;
int typedValueAsInt;
if (typedValue >= 'a') {
typedValueAsInt = 10 + (typedValue - 'a');
} else if (typedValue >= 'A') {
typedValueAsInt = 10 + (typedValue - 'A');
} else {
typedValueAsInt = typedValue - '0';
}
float typedValueAsFloat = (float) typedValueAsInt;
return (typedValueAsFloat / maxTypedValue) * maxEncodedValue;
}
// x86 Assembly Implementation
unsigned int x86_colourTextToInt(const char *text) {
unsigned int result;
__asm {
#include "colours.asm"
mov result, eax
}
return result;
}