From 9632d173d8cf2593ad57fbe369b643bbb2d607b9 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Mon, 14 Nov 2022 20:27:34 +0100 Subject: [PATCH] add changelog.md (#5) * add changelog.md * fix BGR() bug --- .arduino-ci.yml | 17 ++++++++ CHANGELOG.md | 37 +++++++++++++++++ Kelvin2RGB.cpp | 84 ++++++++++++++++++++++++++++++-------- Kelvin2RGB.h | 92 +++++++++++++++++++++--------------------- README.md | 64 ++++++++++++++++------------- keywords.txt | 31 ++++++++++++++ library.json | 2 +- library.properties | 2 +- test/unit_test_001.cpp | 2 +- 9 files changed, 239 insertions(+), 92 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.arduino-ci.yml b/.arduino-ci.yml index cecf585..10c0e10 100644 --- a/.arduino-ci.yml +++ b/.arduino-ci.yml @@ -1,3 +1,18 @@ +platforms: + rpipico: + board: rp2040:rp2040:rpipico + package: rp2040:rp2040 + gcc: + features: + defines: + - ARDUINO_ARCH_RP2040 + warnings: + flags: + +packages: + rp2040:rp2040: + url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json + compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: @@ -9,3 +24,5 @@ compile: - esp32 # - esp8266 # - mega2560 + - rpipico + diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d9387e8 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,37 @@ +# Change Log Kelvin2RGB + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + + +## [0.1.5] - 2022-11-14 +- Add RP2040 support to build-CI. +- Add CHANGELOG.md +- extended keywords.txt +- move all code to .cpp +- fix bug in **BGR()** +- fix unit test BGR-bug + + +## [0.1.4] - 2021-12-20 +- update library.json +- update license +- minor edits + +## [0.1.3] - 2021-11-06 +- update build-CI +- add badges +- add setRGB(), CMYK(), BGR(), reset(); + +## [0.1.2] - 2021-06-01 +- add RGB565() - 16 bit colour - output + +## [0.1.1] - 2020-12-30 +- ?? + +## [0.1.0] - 2018-01-31 +- initial version + + diff --git a/Kelvin2RGB.cpp b/Kelvin2RGB.cpp index 681290f..db1ebd5 100644 --- a/Kelvin2RGB.cpp +++ b/Kelvin2RGB.cpp @@ -1,18 +1,12 @@ // // FILE: Kelvin2RGB.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.4 +// VERSION: 0.1.5 // DATE: 2018-01-31 // PURPOSE: Arduino library for converting temperature to RGB values // URL: https://github.com/RobTillaart/Kelvin2RGB - -// HISTORY -// 0.1.0 2018-01-31 initial version -// 0.1.1 2020-12-30 ?? -// 0.1.2 2021-06-01 add RGB565() - 16 bit colour - output -// 0.1.3 2021-11-06 update build-CI, badges -// add setRGB(), CMYK(), BGR(), reset(); -// 0.1.4 2021-12-20 update library.json, license, minor edits +// +// HISTORY: see changelog.md #include "Kelvin2RGB.h" @@ -23,14 +17,19 @@ Kelvin2RGB::Kelvin2RGB() { - begin(); + reset(); } - +// empty function for now, remove? void Kelvin2RGB::begin() +{ +} + + +void Kelvin2RGB::reset() { _temperature = 0; - _brightness = 0; // default = darkness + _brightness = 0; // default = darkness _red = 0; _green = 0; _blue = 0; @@ -38,7 +37,10 @@ void Kelvin2RGB::begin() } -// Tanner Helland formulas +//////////////////////////////////////////////////////////////// +// +// Tanner Helland formulas +// void Kelvin2RGB::convert_TH(float temperature, float brightness) { _temperature = constrain(temperature, 0, 65500); @@ -68,7 +70,10 @@ void Kelvin2RGB::convert_TH(float temperature, float brightness) } -// Neil Bartlett formulas +//////////////////////////////////////////////////////////////// +// +// Neil Bartlett formulas +// void Kelvin2RGB::convert_NB(float temperature, float brightness) { _temperature = constrain(temperature, 0, 65500); @@ -102,6 +107,41 @@ void Kelvin2RGB::convert_NB(float temperature, float brightness) } +//////////////////////////////////////////////////////////////// +// +// Other functions +// + +float Kelvin2RGB::temperature() +{ + return _temperature; +}; + + +float Kelvin2RGB::brightness() +{ + return _brightness; +}; + + +float Kelvin2RGB::red() +{ + return _red; +}; + + +float Kelvin2RGB::green() +{ + return _green; +}; + + +float Kelvin2RGB::blue() +{ + return _blue; +}; + + uint32_t Kelvin2RGB::setRGB(float red, float green, float blue, float brightness) { _brightness = brightness; @@ -113,7 +153,19 @@ uint32_t Kelvin2RGB::setRGB(float red, float green, float blue, float brightness } -// 16 bit colour - of last conversion. +// +// 32 bit colour (only 3 bytes used) +// +uint32_t Kelvin2RGB::RGB() +{ + return _rgb; +}; + + + +// +// 16 bit colour - of last conversion. +// uint16_t Kelvin2RGB::RGB565() { uint16_t val = 0; @@ -142,7 +194,7 @@ uint32_t Kelvin2RGB::CMYK() uint32_t Kelvin2RGB::BGR() { - return round(_blue) * 65536UL + round(_green) * 256UL + round(_red); + return round(255 * _blue) * 65536UL + round(255 * _green) * 256UL + round(255 * _red); } diff --git a/Kelvin2RGB.h b/Kelvin2RGB.h index a26a7da..e41b198 100644 --- a/Kelvin2RGB.h +++ b/Kelvin2RGB.h @@ -2,53 +2,53 @@ // // FILE: Kelvin2RGB.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.4 +// VERSION: 0.1.5 // DATE: 2018-01-31 // PURPOSE: Arduino library for converting temperature to RGB values // URL: https://github.com/RobTillaart/Kelvin2RGB // -#define KELVIN2RGB_LIB_VERSION (F("0.1.4")) +#define KELVIN2RGB_LIB_VERSION (F("0.1.5")) #include "Arduino.h" // -// Based upon article Tanner Helland and Neil Bartlett -// http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/ -// http://www.zombieprototypes.com/?p=210 -// https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting +// Based upon article Tanner Helland and Neil Bartlett +// http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/ +// http://www.zombieprototypes.com/?p=210 +// https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting // // -// based on https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting +// based on https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting // // DAY LIGHT SETTING TEMPERATURE // -#define DLS_dark 0 -#define DLS_match 1700 -#define DLS_sodiumLamp 1700 -#define DLS_candleFlame 1850 -#define DLS_sunrise 1850 -#define DLS_sunset 1850 -#define DLS_bulb 2400 -#define DLS_bulbSoftWhite 2550 -#define DLS_LEDlamp 2700 -#define DLS_warmWhite 3000 -#define DLS_studioLight 3200 -#define DLS_studioCPlight 3350 -#define DLS_daylightHorizon 5000 -#define DLS_flashLight 5700 -#define DLS_xenonLight 6200 -#define DLS_dayLightBright 6500 -#define DLS_normal 6500 -#define DLS_screenlow 6500 -#define DLS_screenMed 8000 -#define DLS_screenHigh 9500 -#define DLS_polewardSky0 15000 -#define DLS_polewardSky1 19000 -#define DLS_polewardSky2 23000 -#define DLS_polewardSky3 27000 +#define DLS_dark 0 +#define DLS_match 1700 +#define DLS_sodiumLamp 1700 +#define DLS_candleFlame 1850 +#define DLS_sunrise 1850 +#define DLS_sunset 1850 +#define DLS_bulb 2400 +#define DLS_bulbSoftWhite 2550 +#define DLS_LEDlamp 2700 +#define DLS_warmWhite 3000 +#define DLS_studioLight 3200 +#define DLS_studioCPlight 3350 +#define DLS_daylightHorizon 5000 +#define DLS_flashLight 5700 +#define DLS_xenonLight 6200 +#define DLS_dayLightBright 6500 +#define DLS_normal 6500 +#define DLS_screenlow 6500 +#define DLS_screenMed 8000 +#define DLS_screenHigh 9500 +#define DLS_polewardSky0 15000 +#define DLS_polewardSky1 19000 +#define DLS_polewardSky2 23000 +#define DLS_polewardSky3 27000 @@ -57,36 +57,36 @@ class Kelvin2RGB public: Kelvin2RGB(); - void begin(); // empty function - obsolete? + void begin(); // empty function for now, remove? void reset(); - // temp = 0..65500 brightness = 0.0 .. 100.0% - void convert_TH(float temperature, float brightness = 100); - void convert_NB(float temperature, float brightness = 100); + // temperature = 0..65500 brightness = 0.0 .. 100.0% + void convert_TH(float temperature, float brightness = 100.0); + void convert_NB(float temperature, float brightness = 100.0); - float temperature() { return _temperature; }; - float brightness() { return _brightness; }; + float temperature(); + float brightness();; // returns 0.0 .. 1.0 - float red() { return _red; }; - float green() { return _green; }; - float blue() { return _blue; }; + float red(); + float green(); + float blue(); // red, green, blue should be in 0 .. 1.0 range // brightness should be in 0..100%, Default = 100%, // returns RGB. - uint32_t setRGB(float red, float green, float blue, float brightness = 100); + uint32_t setRGB(float red, float green, float blue, float brightness = 100.0); - uint32_t RGB() { return _rgb; }; // 32 bit colour - uint16_t RGB565(); // 16 bit colour + uint32_t RGB(); // 32 bit colour (only 3 bytes used) + uint16_t RGB565(); // 16 bit colour - // experimental 0.1.3 + // Experimental 0.1.3 uint32_t CMYK(); uint32_t BGR(); private: - void _normalize(); + void _normalize(); float _temperature = 0; float _brightness = 0; @@ -96,4 +96,6 @@ class Kelvin2RGB uint32_t _rgb = 0; }; + // -- END OF FILE -- + diff --git a/README.md b/README.md index 0d18fb9..2940980 100644 --- a/README.md +++ b/README.md @@ -16,24 +16,24 @@ Arduino library for converting temperature and brightness to RGB values. This library is based upon an article of Tanner Helland and a related story by Neil Bartlett http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/ -http://www.zombieprototypes.com/?p=210 +http://www.zombieprototypes.com/?p=210 https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting -There are more approximation formulas, some claim to be better, +There are more approximation formulas, some claim to be better, however these are not investigated. On request these can be added. ## Description -The library converts a temperature in Kelvin and a brightness (0..100%) +The library converts a temperature in Kelvin and a brightness (0..100%) to 3 numbers red, green and blue. These numbers are weights can be used to correct a colour image for virtual white temperature. -There are 2 convert functions where the **convert_NB()** is claimed to be +There are 2 convert functions where the **convert_NB()** is claimed to be the more accurate one. With the numbers R,G,B calculated one can convert images so they will look -more like taken with candle light, sunrise or sunset etc. +more like taken with candle light, sunrise or sunset etc. **pseudo code** @@ -51,7 +51,7 @@ for each pixel in image } ``` -The numbers can also be used to reduce the blue channel so it has less effect +The numbers can also be used to reduce the blue channel so it has less effect on "getting sleepy". The library uses floats for the R,G and B weights to keep values as accurate as possible. @@ -65,46 +65,54 @@ The interface is straightforward: - **Kelvin2RGB()** constructor - **void begin()** empty function for now. -- **void reset()** resets all internal values to 0. -- **void convert_TH(float temperature, float brightness = 100)** - temperature = 0..65500 temperature below 1000 is not well defined. - brightness = 0..100%, -- **void convert_NB(float temperature, float brightness = 100)** - temperature = 0..65500 temperature below 1000 is not well defined. - brightness = 0..100%, +- **void reset()** resets all internal values to 0. +All colours, brightness and temperature. +- **void convert_TH(float temperature, float brightness = 100)** + temperature = 0..65500 temperature below 1000 is not well defined. + brightness = 0..100%, +- **void convert_NB(float temperature, float brightness = 100)** + temperature = 0..65500 temperature below 1000 is not well defined. + brightness = 0..100%, Is a bit more accurate and slightly slower (few %). Read link above for more information. - **float temperature()** returns temperature, to check the value used. - **float brightness()** returns brightness, to check the value used. -- **float red()** returns red channel weight 0.0 .. 1.0 +- **float red()** returns red channel weight 0.0 .. 1.0 note this is different from Helland / Bartlett who both use an integer value 0 .. 255 - **float green()** returns green channel weight 0.0 .. 1.0 - **float blue()** returns blue channel weight 0.0 .. 1.0 -- **uint32_t setRGB(float red, float green, float blue, float brightness = 100)** sets RGB values +- **uint32_t setRGB(float red, float green, float blue, float brightness = 100)** sets RGB values red, green, blue should be in 0 .. 1.0 range. brightness should be in 0..100%, Default = 100%. -returns a 24 bit RGB value, +returns a 24 bit RGB value, - **uint32_t RGB()** returns a 24 bit RGB value, 0 .. 16777215 -more efficient than 3 floats for communication. -- **uint16_t RGB565()** returns a 16 bit RGB value, +more efficient than 3 floats for communication. +- **uint16_t RGB565()** returns a 16 bit RGB value, 5 bits for red, 6 for green and 5 for blue. - **uint32_t BGR()** returns a 24 bit BGR value, 0 .. 16777215 -- **uint32_t CMYK()** returns a 32 bit = 4 byte CMYK value, +- **uint32_t CMYK()** returns a 32 bit = 4 byte CMYK value, + + +## Operations + +See examples ## Future -- separate brightness per colour channel to mimic "artificial illumination" (0.2.0 ?) +#### must +- add examples + - CMYK() + - BGR() + +#### should - define constants like candleLight as parameter. - investigate other formulas. - investigate timing and performance - investigate usability for RGB led strip. -- remove begin() ? -- add examples - - CMYK() - - BGR() - - Led-strip() - +- investigate **RGB_10_12_10()** -## Operations +#### could +- separate brightness per colour channel to mimic "artificial illumination" (0.2.0 ?) +- remove begin() ? +- example Led-strip() -See examples diff --git a/keywords.txt b/keywords.txt index e52d28a..a3e0a65 100644 --- a/keywords.txt +++ b/keywords.txt @@ -24,4 +24,35 @@ CMYK KEYWORD2 KELVIN2RGB_LIB_VERSION LITERAL1 +DLS_dark LITERAL1 +DLS_match LITERAL1 +DLS_sodiumLamp LITERAL1 +DLS_candleFlame LITERAL1 + +DLS_sunrise LITERAL1 +DLS_sunset LITERAL1 +DLS_bulb LITERAL1 +DLS_bulbSoftWhite LITERAL1 + +DLS_LEDlamp LITERAL1 +DLS_warmWhite LITERAL1 +DLS_studioLight LITERAL1 +DLS_studioCPlight LITERAL1 + +DLS_daylightHorizon LITERAL1 +DLS_flashLight LITERAL1 +DLS_xenonLight LITERAL1 +DLS_dayLightBright LITERAL1 + +DLS_normal LITERAL1 +DLS_screenlow LITERAL1 +DLS_screenMed LITERAL1 +DLS_screenHigh LITERAL1 + +DLS_polewardSky0 LITERAL1 +DLS_polewardSky1 LITERAL1 +DLS_polewardSky2 LITERAL1 +DLS_polewardSky3 LITERAL1 + + diff --git a/library.json b/library.json index b251737..3514cff 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/Kelvin2RGB.git" }, - "version": "0.1.4", + "version": "0.1.5", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index acfb165..b194dec 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Kelvin2RGB -version=0.1.4 +version=0.1.5 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for converting temperature to RGB values diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index 5dc68e7..ebec4bb 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -157,7 +157,7 @@ unittest(test_colour_spaces) assertEqualFloat(0.900, tempColor.green(), 0.0001); assertEqualFloat(0.675, tempColor.blue(), 0.0001); assertEqual(7595692, tempColor.RGB()); - assertEqual(65792, tempColor.BGR()); + assertEqual(11331187, tempColor.BGR()); assertEqual(2130722560, tempColor.CMYK()); assertEqual(30517, tempColor.RGB565()); }