Overview
Comment: | Add OFColor
This is useful so that multiple libraries using ObjFW can share the same |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f484fedee23187bd095e1f1d8f9f18a1 |
User & Date: | js on 2018-03-10 19:05:24 |
Other Links: | manifest | tags |
Context
2018-03-10
| ||
19:31 | platform.h: Add AmigaOS 4 check-in: 2d0da271bf user: js tags: trunk | |
19:05 | Add OFColor check-in: f484fedee2 user: js tags: trunk | |
2018-03-09
| ||
22:53 | OFLocalization: Prevent calling -[init] twice check-in: defee30139 user: js tags: trunk | |
Changes
Modified src/Makefile from [e42131bfba] to [9229e6eeb1].
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 | LIB_MINOR = ${OBJFW_LIB_MINOR} SRCS = OFApplication.m \ OFArray.m \ OFAutoreleasePool.m \ OFBlock.m \ OFCharacterSet.m \ OFConstantString.m \ OFCountedSet.m \ OFData.m \ OFData+CryptoHashing.m \ OFData+MessagePackValue.m \ OFDate.m \ OFDictionary.m \ | > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | LIB_MINOR = ${OBJFW_LIB_MINOR} SRCS = OFApplication.m \ OFArray.m \ OFAutoreleasePool.m \ OFBlock.m \ OFCharacterSet.m \ OFColor.m \ OFConstantString.m \ OFCountedSet.m \ OFData.m \ OFData+CryptoHashing.m \ OFData+MessagePackValue.m \ OFDate.m \ OFDictionary.m \ |
︙ | ︙ |
Added src/OFColor.h version [d358be0818].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 67 68 69 70 71 72 73 74 75 76 77 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFColor OFColor.h ObjFW/OFColor.h * * @brief A class for storing a color. */ @interface OFColor: OFObject { float _red, _green, _blue, _alpha; } /*! * @brief Creates a new color with the specified red, green, blue and alpha * value. * * @param red The red value of the color, between 0.0 and 1.0 * @param green The green value of the color, between 0.0 and 1.0 * @param blue The blue value of the color, between 0.0 and 1.0 * @param alpha The alpha value of the color, between 0.0 and 1.0 * @return A new color with the specified red, green, blue and alpha value */ + (instancetype)colorWithRed: (float)red green: (float)green blue: (float)blue alpha: (float)alpha; /*! * @brief Initializes an already allocated color with the specified red, green, * blue and alpha value. * * @param red The red value of the color, between 0.0 and 1.0 * @param green The green value of the color, between 0.0 and 1.0 * @param blue The blue value of the color, between 0.0 and 1.0 * @param alpha The alpha value of the color, between 0.0 and 1.0 * @return A color initialized with the specified red, green, blue and alpha * value */ - (instancetype)initWithRed: (float)red green: (float)green blue: (float)blue alpha: (float)alpha; /*! * @brief Returns the red, green, blue and alpha value of the color. * * @param red A pointer to store the red value of the color * @param green A pointer to store the green value of the color * @param blue A pointer to store the blue value of the color * @param alpha An optional pointer to store the alpha of the color */ - (void)getRed: (float *)red green: (float *)green blue: (float *)blue alpha: (nullable float *)alpha; @end OF_ASSUME_NONNULL_END |
Added src/OFColor.m version [8b53b10443].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFColor.h" #import "OFInvalidArgumentException.h" @implementation OFColor + (instancetype)colorWithRed: (float)red green: (float)green blue: (float)blue alpha: (float)alpha { return [[[self alloc] initWithRed: red green: green blue: blue alpha: alpha] autorelease]; } - (instancetype)initWithRed: (float)red green: (float)green blue: (float)blue alpha: (float)alpha { self = [super init]; @try { if (red < 0.0 || red > 1.0 || green < 0.0 || green > 1.0 || blue < 0.0 || blue > 1.0 || alpha < 0.0 || alpha > 1.0) @throw [OFInvalidArgumentException exception]; _red = red; _green = green; _blue = blue; _alpha = alpha; } @catch (id e) { [self release]; @throw e; } return self; } - (bool)isEqual: (id)object { OFColor *other; if (![object isKindOfClass: [OFColor class]]) return false; other = object; if (other->_red != _red) return false; if (other->_green != _green) return false; if (other->_blue != _blue) return false; if (other->_alpha != _alpha) return false; return true; } - (uint32_t)hash { uint32_t hash; union { float f; unsigned char b[sizeof(float)]; } f; OF_HASH_INIT(hash); f.f = OF_BSWAP_FLOAT_IF_LE(_red); for (uint_fast8_t i = 0; i < sizeof(float); i++) OF_HASH_ADD(hash, f.b[i]); f.f = OF_BSWAP_FLOAT_IF_LE(_green); for (uint_fast8_t i = 0; i < sizeof(float); i++) OF_HASH_ADD(hash, f.b[i]); f.f = OF_BSWAP_FLOAT_IF_LE(_blue); for (uint_fast8_t i = 0; i < sizeof(float); i++) OF_HASH_ADD(hash, f.b[i]); f.f = OF_BSWAP_FLOAT_IF_LE(_alpha); for (uint_fast8_t i = 0; i < sizeof(float); i++) OF_HASH_ADD(hash, f.b[i]); OF_HASH_FINALIZE(hash); return hash; } - (void)getRed: (float *)red green: (float *)green blue: (float *)blue alpha: (float *)alpha { *red = _red; *green = _green; *blue = _blue; if (alpha != NULL) *alpha = _alpha; } @end |
Modified src/OFNumber.m from [15e27ceca1] to [25c5c7f684].
︙ | ︙ | |||
1082 1083 1084 1085 1086 1087 1088 | } d; if (isnan([self doubleValue])) return 0; d.d = OF_BSWAP_DOUBLE_IF_BE([self doubleValue]); | | | 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 | } d; if (isnan([self doubleValue])) return 0; d.d = OF_BSWAP_DOUBLE_IF_BE([self doubleValue]); for (uint_fast8_t i = 0; i < sizeof(double); i++) OF_HASH_ADD(hash, d.b[i]); } else if (type & OF_NUMBER_TYPE_SIGNED) { intmax_t v = [self intMaxValue] * -1; while (v != 0) { OF_HASH_ADD(hash, v & 0xFF); v >>= 8; |
︙ | ︙ |
Modified src/ObjFW.h from [a25671fef1] to [8e512daaa9].
︙ | ︙ | |||
46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #import "OFInvocation.h" #import "OFIntrospection.h" #import "OFNumber.h" #import "OFDate.h" #import "OFURL.h" #import "OFURLHandler.h" #import "OFStream.h" #import "OFStdIOStream.h" #import "OFInflateStream.h" #import "OFInflate64Stream.h" #import "OFGZIPStream.h" #import "OFTarArchive.h" | > | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #import "OFInvocation.h" #import "OFIntrospection.h" #import "OFNumber.h" #import "OFDate.h" #import "OFURL.h" #import "OFURLHandler.h" #import "OFColor.h" #import "OFStream.h" #import "OFStdIOStream.h" #import "OFInflateStream.h" #import "OFInflate64Stream.h" #import "OFGZIPStream.h" #import "OFTarArchive.h" |
︙ | ︙ |