forked from Makuna/NeoPixelBus
HtmlColor
This commit is contained in:
@@ -11,6 +11,7 @@ RgbwColor KEYWORD1
|
|||||||
RgbColor KEYWORD1
|
RgbColor KEYWORD1
|
||||||
HslColor KEYWORD1
|
HslColor KEYWORD1
|
||||||
HsbColor KEYWORD1
|
HsbColor KEYWORD1
|
||||||
|
HtmlColor KEYWORD1
|
||||||
NeoGrbFeature KEYWORD1
|
NeoGrbFeature KEYWORD1
|
||||||
NeoRgbwFeature KEYWORD1
|
NeoRgbwFeature KEYWORD1
|
||||||
NeoRgbFeature KEYWORD1
|
NeoRgbFeature KEYWORD1
|
||||||
|
@@ -30,6 +30,7 @@ License along with NeoPixel. If not, see
|
|||||||
#include "internal/RgbColor.h"
|
#include "internal/RgbColor.h"
|
||||||
#include "internal/HslColor.h"
|
#include "internal/HslColor.h"
|
||||||
#include "internal/HsbColor.h"
|
#include "internal/HsbColor.h"
|
||||||
|
#include "internal/HtmlColor.h"
|
||||||
#include "internal/RgbwColor.h"
|
#include "internal/RgbwColor.h"
|
||||||
#include "internal/NeoColorFeatures.h"
|
#include "internal/NeoColorFeatures.h"
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ License along with NeoPixel. If not, see
|
|||||||
#include "HsbColor.h"
|
#include "HsbColor.h"
|
||||||
|
|
||||||
|
|
||||||
HsbColor::HsbColor(RgbColor color)
|
HsbColor::HsbColor(const RgbColor& color)
|
||||||
{
|
{
|
||||||
// convert colors to float between (0.0 - 1.0)
|
// convert colors to float between (0.0 - 1.0)
|
||||||
float r = color.R / 255.0f;
|
float r = color.R / 255.0f;
|
||||||
|
@@ -45,7 +45,7 @@ struct HsbColor
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Construct a HsbColor using RgbColor
|
// Construct a HsbColor using RgbColor
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
HsbColor(RgbColor color);
|
HsbColor(const RgbColor& color);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Construct a HsbColor that will have its values set in latter operations
|
// Construct a HsbColor that will have its values set in latter operations
|
||||||
|
@@ -28,7 +28,7 @@ License along with NeoPixel. If not, see
|
|||||||
#include "HslColor.h"
|
#include "HslColor.h"
|
||||||
|
|
||||||
|
|
||||||
HslColor::HslColor(RgbColor color)
|
HslColor::HslColor(const RgbColor& color)
|
||||||
{
|
{
|
||||||
// convert colors to float between (0.0 - 1.0)
|
// convert colors to float between (0.0 - 1.0)
|
||||||
float r = color.R / 255.0f;
|
float r = color.R / 255.0f;
|
||||||
|
@@ -47,7 +47,7 @@ struct HslColor
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Construct a HslColor using RgbColor
|
// Construct a HslColor using RgbColor
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
HslColor(RgbColor color);
|
HslColor(const RgbColor& color);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Construct a HslColor that will have its values set in latter operations
|
// Construct a HslColor that will have its values set in latter operations
|
||||||
|
74
src/internal/HtmlColor.h
Normal file
74
src/internal/HtmlColor.h
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
HtmlColor provides a color object that can be directly consumed by NeoPixelBus
|
||||||
|
|
||||||
|
Written by Michael C. Miller.
|
||||||
|
|
||||||
|
I invest time and resources providing this open source code,
|
||||||
|
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------
|
||||||
|
This file is part of the Makuna/NeoPixelBus library.
|
||||||
|
|
||||||
|
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
NeoPixelBus is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with NeoPixel. If not, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
-------------------------------------------------------------------------*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "RgbColor.h"
|
||||||
|
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// HtmlColor represents a color object that is represented by a single uint32
|
||||||
|
// value. It contains minimal routines and used primarily as a helper to
|
||||||
|
// initialize other color objects
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
struct HtmlColor
|
||||||
|
{
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Construct a HtmlColor using a single value (0-0xffffff)
|
||||||
|
// This works well for hexidecimal color definitions
|
||||||
|
// 0xff0000 = red, 0x00ff00 = green, and 0x0000ff = blue
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
HtmlColor(uint32_t color) :
|
||||||
|
Color(color)
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Construct a HtmlColor using RgbColor
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
HtmlColor(const RgbColor& color)
|
||||||
|
{
|
||||||
|
Color = color.R << 16 | color.G << 8 | color.B;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Construct a HtmlColor that will have its values set in latter operations
|
||||||
|
// CAUTION: The Color member is not initialized and may not be consistent
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
HtmlColor()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Color member (0-0xffffff) where
|
||||||
|
// 0xff0000 is red
|
||||||
|
// 0x00ff00 is green
|
||||||
|
// 0x0000ff is blue
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
uint32_t Color;
|
||||||
|
};
|
||||||
|
|
@@ -27,6 +27,7 @@ License along with NeoPixel. If not, see
|
|||||||
#include "RgbColor.h"
|
#include "RgbColor.h"
|
||||||
#include "HslColor.h"
|
#include "HslColor.h"
|
||||||
#include "HsbColor.h"
|
#include "HsbColor.h"
|
||||||
|
#include "HtmlColor.h"
|
||||||
|
|
||||||
static float _CalcColor(float p, float q, float t)
|
static float _CalcColor(float p, float q, float t)
|
||||||
{
|
{
|
||||||
@@ -47,7 +48,12 @@ static float _CalcColor(float p, float q, float t)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
RgbColor::RgbColor(HslColor color)
|
RgbColor::RgbColor(const HtmlColor& color) :
|
||||||
|
R((color.Color >> 16) & 0xff), G((color.Color >> 8) & 0xff), B(color.Color & 0xff)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
RgbColor::RgbColor(const HslColor& color)
|
||||||
{
|
{
|
||||||
float r;
|
float r;
|
||||||
float g;
|
float g;
|
||||||
@@ -76,7 +82,7 @@ RgbColor::RgbColor(HslColor color)
|
|||||||
B = (uint8_t)(b * 255.0f);
|
B = (uint8_t)(b * 255.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
RgbColor::RgbColor(HsbColor color)
|
RgbColor::RgbColor(const HsbColor& color)
|
||||||
{
|
{
|
||||||
float r;
|
float r;
|
||||||
float g;
|
float g;
|
||||||
|
@@ -29,6 +29,7 @@ License along with NeoPixel. If not, see
|
|||||||
|
|
||||||
struct HslColor;
|
struct HslColor;
|
||||||
struct HsbColor;
|
struct HsbColor;
|
||||||
|
struct HtmlColor;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// RgbColor represents a color object that is represented by Red, Green, Blue
|
// RgbColor represents a color object that is represented by Red, Green, Blue
|
||||||
@@ -55,15 +56,20 @@ struct RgbColor
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Construct a RgbColor using HtmlColor
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
RgbColor(const HtmlColor& color);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Construct a RgbColor using HslColor
|
// Construct a RgbColor using HslColor
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
RgbColor(HslColor color);
|
RgbColor(const HslColor& color);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Construct a RgbColor using HsbColor
|
// Construct a RgbColor using HsbColor
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
RgbColor(HsbColor color);
|
RgbColor(const HsbColor& color);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Construct a RgbColor that will have its values set in latter operations
|
// Construct a RgbColor that will have its values set in latter operations
|
||||||
|
Reference in New Issue
Block a user