| 97 | } |
| 98 | |
| 99 | void PiuColorDictionary(xsMachine *the, xsSlot* slot, PiuColor color) |
| 100 | { |
| 101 | xsType type = xsTypeOf(*slot); |
| 102 | if ((type == xsIntegerType) || (type == xsNumberType)) { |
| 103 | uint32_t value = xsToUnsigned(*slot); |
| 104 | color->r = (value >> 24) & 0xFF; |
| 105 | color->g = (value >> 16) & 0xFF; |
| 106 | color->b = (value >> 8) & 0xFF; |
| 107 | color->a = value & 0xFF; |
| 108 | } |
| 109 | else { |
| 110 | xsStringValue s = xsToString(*slot); |
| 111 | if ('#' == c_read8(s)) { |
| 112 | xsIntegerValue length = c_strlen(s); |
| 113 | if (length == 4) { |
| 114 | color->r = (uint8_t)PiuStringHexToNum(&s[1], 1) * 17; |
| 115 | color->g = (uint8_t)PiuStringHexToNum(&s[2], 1) * 17; |
| 116 | color->b = (uint8_t)PiuStringHexToNum(&s[3], 1) * 17; |
| 117 | color->a = 255; |
| 118 | return; |
| 119 | } |
| 120 | if (length == 5) { |
| 121 | color->r = (uint8_t)PiuStringHexToNum(&s[1], 1) * 17; |
| 122 | color->g = (uint8_t)PiuStringHexToNum(&s[2], 1) * 17; |
| 123 | color->b = (uint8_t)PiuStringHexToNum(&s[3], 1) * 17; |
| 124 | color->a = (uint8_t)PiuStringHexToNum(&s[1], 1) * 17; |
| 125 | return; |
| 126 | } |
| 127 | if (length == 7) { |
| 128 | color->r = (uint8_t)PiuStringHexToNum(&s[1], 2); |
| 129 | color->g = (uint8_t)PiuStringHexToNum(&s[3], 2); |
| 130 | color->b = (uint8_t)PiuStringHexToNum(&s[5], 2); |
| 131 | color->a = 255; |
| 132 | return; |
| 133 | } |
| 134 | if (length == 9) { |
| 135 | color->r = (uint8_t)PiuStringHexToNum(&s[1], 2); |
| 136 | color->g = (uint8_t)PiuStringHexToNum(&s[3], 2); |
| 137 | color->b = (uint8_t)PiuStringHexToNum(&s[5], 2); |
| 138 | color->a = (uint8_t)PiuStringHexToNum(&s[7], 2); |
| 139 | return; |
| 140 | } |
| 141 | } |
| 142 | else { |
| 143 | xsIntegerValue i; |
| 144 | for (i = 0; i < PiuColorCount; i++) { |
| 145 | if (!c_strcmp(s, PiuColorNames[i])) { |
| 146 | color->r = c_read8(&PiuColorValues[i].r); |
| 147 | color->g = c_read8(&PiuColorValues[i].g); |
| 148 | color->b = c_read8(&PiuColorValues[i].b); |
| 149 | color->a = c_read8(&PiuColorValues[i].a); |
| 150 | return; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | xsErrorPrintf("invalid color"); |
| 155 | } |
| 156 | } |
no test coverage detected