@@ -14,34 +14,33 @@ */ #include "config.h" #import "OFColor.h" - -#import "once.h" +#import "OFOnce.h" #import "OFInvalidArgumentException.h" @implementation OFColor -#define PREDEFINED_COLOR(name, r, g, b) \ - static OFColor *name##Color = nil; \ - \ - static void \ - initPredefinedColor_##name(void) \ - { \ - name##Color = [[OFColor alloc] initWithRed: r \ - green: g \ - blue: b \ - alpha: 1]; \ - } \ - \ - + (OFColor *)name \ - { \ - static of_once_t onceControl = OF_ONCE_INIT; \ - of_once(&onceControl, initPredefinedColor_##name); \ - \ - return name##Color; \ +#define PREDEFINED_COLOR(name, redValue, greenValue, blueValue) \ + static OFColor *name##Color = nil; \ + \ + static void \ + initPredefinedColor_##name(void) \ + { \ + name##Color = [[OFColor alloc] initWithRed: redValue \ + green: greenValue \ + blue: blueValue \ + alpha: 1]; \ + } \ + \ + + (OFColor *)name \ + { \ + static OFOnceControl onceControl = OFOnceControlInitValue; \ + OFOnce(&onceControl, initPredefinedColor_##name); \ + \ + return name##Color; \ } PREDEFINED_COLOR(black, 0.00f, 0.00f, 0.00f) PREDEFINED_COLOR(silver, 0.75f, 0.75f, 0.75f) PREDEFINED_COLOR(grey, 0.50f, 0.50f, 0.50f) @@ -120,32 +119,32 @@ return true; } - (unsigned long)hash { - uint32_t hash; + unsigned long hash; float tmp; - OF_HASH_INIT(hash); - - tmp = OF_BSWAP_FLOAT_IF_LE(_red); - for (uint_fast8_t i = 0; i < sizeof(float); i++) - OF_HASH_ADD(hash, ((char *)&tmp)[i]); - - tmp = OF_BSWAP_FLOAT_IF_LE(_green); - for (uint_fast8_t i = 0; i < sizeof(float); i++) - OF_HASH_ADD(hash, ((char *)&tmp)[i]); - - tmp = OF_BSWAP_FLOAT_IF_LE(_blue); - for (uint_fast8_t i = 0; i < sizeof(float); i++) - OF_HASH_ADD(hash, ((char *)&tmp)[i]); - - tmp = OF_BSWAP_FLOAT_IF_LE(_alpha); - for (uint_fast8_t i = 0; i < sizeof(float); i++) - OF_HASH_ADD(hash, ((char *)&tmp)[i]); - - OF_HASH_FINALIZE(hash); + OFHashInit(&hash); + + tmp = OFToLittleEndianFloat(_red); + for (uint_fast8_t i = 0; i < sizeof(float); i++) + OFHashAdd(&hash, ((char *)&tmp)[i]); + + tmp = OFToLittleEndianFloat(_green); + for (uint_fast8_t i = 0; i < sizeof(float); i++) + OFHashAdd(&hash, ((char *)&tmp)[i]); + + tmp = OFToLittleEndianFloat(_blue); + for (uint_fast8_t i = 0; i < sizeof(float); i++) + OFHashAdd(&hash, ((char *)&tmp)[i]); + + tmp = OFToLittleEndianFloat(_alpha); + for (uint_fast8_t i = 0; i < sizeof(float); i++) + OFHashAdd(&hash, ((char *)&tmp)[i]); + + OFHashFinalize(&hash); return hash; } - (void)getRed: (float *)red