Skip to content

Commit

Permalink
Merge pull request #82 from Makuna/HtmlColorInit
Browse files Browse the repository at this point in the history
HtmlColor Support
  • Loading branch information
Makuna committed Mar 6, 2016
2 parents 6eba5a9 + 5568070 commit 22f5e71
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 9 deletions.
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RgbwColor KEYWORD1
RgbColor KEYWORD1
HslColor KEYWORD1
HsbColor KEYWORD1
HtmlColor KEYWORD1
NeoGrbFeature KEYWORD1
NeoRgbwFeature KEYWORD1
NeoRgbFeature KEYWORD1
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=NeoPixelBus by Makuna
version=2.0.2
version=2.0.3
author=Michael C. Miller ([email protected])
maintainer=Michael C. Miller ([email protected])
sentence=A library that makes controlling NeoPixels (WS2811, WS2812 & SK6812) easy.
Expand Down
1 change: 1 addition & 0 deletions src/NeoPixelBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ License along with NeoPixel. If not, see
#include "internal/RgbColor.h"
#include "internal/HslColor.h"
#include "internal/HsbColor.h"
#include "internal/HtmlColor.h"
#include "internal/RgbwColor.h"
#include "internal/NeoColorFeatures.h"

Expand Down
2 changes: 1 addition & 1 deletion src/internal/HsbColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ License along with NeoPixel. If not, see
#include "HsbColor.h"


HsbColor::HsbColor(RgbColor color)
HsbColor::HsbColor(const RgbColor& color)
{
// convert colors to float between (0.0 - 1.0)
float r = color.R / 255.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/internal/HsbColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct HsbColor
// ------------------------------------------------------------------------
// Construct a HsbColor using RgbColor
// ------------------------------------------------------------------------
HsbColor(RgbColor color);
HsbColor(const RgbColor& color);

// ------------------------------------------------------------------------
// Construct a HsbColor that will have its values set in latter operations
Expand Down
2 changes: 1 addition & 1 deletion src/internal/HslColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ License along with NeoPixel. If not, see
#include "HslColor.h"


HslColor::HslColor(RgbColor color)
HslColor::HslColor(const RgbColor& color)
{
// convert colors to float between (0.0 - 1.0)
float r = color.R / 255.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/internal/HslColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct HslColor
// ------------------------------------------------------------------------
// Construct a HslColor using RgbColor
// ------------------------------------------------------------------------
HslColor(RgbColor color);
HslColor(const RgbColor& color);

// ------------------------------------------------------------------------
// Construct a HslColor that will have its values set in latter operations
Expand Down
74 changes: 74 additions & 0 deletions src/internal/HtmlColor.h
Original file line number Diff line number Diff line change
@@ -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;
};

10 changes: 8 additions & 2 deletions src/internal/RgbColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ License along with NeoPixel. If not, see
#include "RgbColor.h"
#include "HslColor.h"
#include "HsbColor.h"
#include "HtmlColor.h"

static float _CalcColor(float p, float q, float t)
{
Expand All @@ -47,7 +48,12 @@ static float _CalcColor(float p, float q, float t)
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 g;
Expand Down Expand Up @@ -76,7 +82,7 @@ RgbColor::RgbColor(HslColor color)
B = (uint8_t)(b * 255.0f);
}

RgbColor::RgbColor(HsbColor color)
RgbColor::RgbColor(const HsbColor& color)
{
float r;
float g;
Expand Down
10 changes: 8 additions & 2 deletions src/internal/RgbColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ License along with NeoPixel. If not, see

struct HslColor;
struct HsbColor;
struct HtmlColor;

// ------------------------------------------------------------------------
// RgbColor represents a color object that is represented by Red, Green, Blue
Expand All @@ -55,15 +56,20 @@ struct RgbColor
{
};

// ------------------------------------------------------------------------
// Construct a RgbColor using HtmlColor
// ------------------------------------------------------------------------
RgbColor(const HtmlColor& color);

// ------------------------------------------------------------------------
// Construct a RgbColor using HslColor
// ------------------------------------------------------------------------
RgbColor(HslColor color);
RgbColor(const HslColor& color);

// ------------------------------------------------------------------------
// Construct a RgbColor using HsbColor
// ------------------------------------------------------------------------
RgbColor(HsbColor color);
RgbColor(const HsbColor& color);

// ------------------------------------------------------------------------
// Construct a RgbColor that will have its values set in latter operations
Expand Down

0 comments on commit 22f5e71

Please sign in to comment.