Skip to content

Commit

Permalink
Adding initial code
Browse files Browse the repository at this point in the history
  • Loading branch information
technosf committed Jan 29, 2019
1 parent 52a97a3 commit 20d0006
Show file tree
Hide file tree
Showing 7 changed files with 943 additions and 100 deletions.
55 changes: 31 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ESPxRGB

ESPxRGB is an Arduino library of RGB, RGBW, HSV conversion functions and Gamma Correction written in Xtensa assembler for ESP SoCs.
ESPxRGB is an Arduino library of RGB, RGBW, HSV conversion functions and correction functions for Gamma and Chromiance written in Xtensa assembler for ESP SoCs.

The objective of the library is to be as fast and efficient as possible.

## Table of Contents

Expand All @@ -13,52 +15,57 @@ ESPxRGB is an Arduino library of RGB, RGBW, HSV conversion functions and Gamma C

## Why an assembler RGB manipulation library

Looking to use small, low-powered SoCs to drive long strings of LEDs with the optimum speed and power efficiency requires efficient algorythms and code. Assembler is as efficient as you can get. The ESP SoCs are great given their feature set, conectivity, power and price. Plus, they are easy to program.
Looking to use small, low-powered _SoCs_ to drive long strings of LEDs with the optimum speed and power efficiency requires efficient algorythms and code. Assembler is as efficient as you can get. The ESP SoCs are great given their feature set, conectivity, power and price. Plus, they are easy to program.

## Features

ESPxRGB works in the 8-bit RGB/W space. It covers functions supporting:
_ RGB to RGBW
_ _HSV to RGB and RGBW, with a choice of four HSV algorythms
_ RGB gamma correction (for normalizing the perception of pulsing luminance)
_ RGB chroma correction (for normalizing the perception of luminance across the spectrum)
plus intersections of all the above.

External **C** headers provide regular Arduino and ESP-IDF code access to the functions.
* RGB to RGBW
* HSV to RGB and RGBW, with a choice of four HSV algorythms
* RGB gamma correction (for normalizing the perception of pulsing luminance)
* RGB chroma correction (for normalizing the perception of luminance across the spectrum)

Plus intersections of all the above.

Externalized _**C**_ headers provide regular Arduino and ESP-IDF code access to the functions.

## Options and Use

Drop the library into your *~Arduino/libraries* folder and include the *ESPxRGB.h* header in your project.
The library is compiled based on flags in the *src/options.h* file:
The functions are grouped and can be included/excluded in the compiled code as dictated by pre-processor definitions.
The library is compiled based on flags in the *src/options.h* file; The functions are grouped and can be included/excluded in the compiled code as dictated by pre-processor definitions.

The *examples* folder contains *sketches* than can test the functions and generate look-up tables used by the code.
The *examples* folder contains *sketches* than can test the functions and generate look-up tables used by the code. Look-up tables in the _*.S*_ files can be replaced as desired.

### Functions

#### Conrection
#### Correction

_ *xgamma8* Normalizes the value of a single 8-bit color value
_ *xgammaarray8* Normalizes a range of 8-bit color values
_ *xrgbgamma8* Normalizes a set of 8-bit RGB values
_ *xrgbwgamma8* Normalizes a set of 8-bit RGBW values
* _xgamma8_ - Normalizes the value of a single 8-bit color value
* _xgammaarray8_ - Normalizes a range of 8-bit color values
* _xrgbgamma8_ - Normalizes a set of 8-bit RGB values
* _xrgbwgamma8_ - Normalizes a set of 8-bit RGBW values

#### Conversion

_ *xrgb2rgbw8* RGB to RGBW
_ *xhsv2rgb8s* HSV to RGB using the Spectrum algorythm
_ *xhsv2rgb8e* HSV to RGB using a power efficient function
_ *xhsv2rgbwt* HSV to RGB using a tweaked function aproximating FastLED Rainbow HSV
_ *xhsv2rgb8w* HSV to RGB using a (sine) wave function
* _xrgb2rgbw8_ - RGB to RGBW
* _xhsv2rgb8s_ - HSV to RGB using the Spectrum algorythm
* _xhsv2rgb8e_ - HSV to RGB using a power efficient function
* _xhsv2rgbwt_ - HSV to RGB using a tweaked function aproximating FastLED Rainbow HSV
* _xhsv2rgb8w_ - HSV to RGB using a (sine) wave function
* _xhsv2rgb8_ - A default HSV to RGB that rferences one of the implemented function. Change as needed.

#### Combined

_ *xhsv2rgbgamma8* HSV to RGB with gamma correction
_ *xhsv2rgbwgamma8* HSV to RGB with gamma correction
_ *xrgb2rgbwgamma8* RGB to RGBW with gamma correction
* _xhsv2rgbw8_ - HSV to RGBW using default HSV function
* _xhsv2rgbgamma8_ - HSV to RGB with gamma correction using default HSV function
* _xhsv2rgbwgamma8_ - HSV to RGB with gamma correction using default HSV function
* _xrgb2rgbwgamma8_ - RGB to RGBW with gamma correction

## History

* _v0.1.0_ - Initial check-in and config as a library.

## References

## License
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ xhsv2rgbw8s KEYWORD2
xhsv2rgbw8e KEYWORD2
xhsv2rgbw8w KEYWORD2
xhsv2rgbw8t KEYWORD2
xhsv2rgbw8 KEYWORD2

xrgb2rgbw8 KEYWORD2

Expand Down
100 changes: 41 additions & 59 deletions src/ESPxRGB.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
ESPxRGB Library Header
------------------------------------------------------------------------------------------------
v0.1.0
Copyright 2019 technosf [https://github.com/technosf]
Copyright 2019 technosf [https://github.com/technosf]
Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 or greater (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 or greater (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.gnu.org/licenses/lgpl-3.0.en.html
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
https://www.gnu.org/licenses/lgpl-3.0.en.html
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
*/


#ifndef ESPXRGB_H
#define ESPXRGB_H

Expand All @@ -32,122 +31,105 @@ extern "C"
/*
Gamma correction on an 8-bit range
*/
uint8_t xgamma8( uint8_t val );
uint8_t xgamma8(uint8_t val);

/*
Gamma correction over an array of 8-bit values
*/
void xgammaarray8( uint8_t *pntr, uint8_t count );

void xgammaarray8(uint8_t *pntr, uint8_t count);

/*
Gamma correction on RGB in 8-bit range
*/
void xrgbgamma8( uint8_t *r, uint8_t *g , uint8_t *b );

/*
/*
Gamma correction on RGB in 8-bit range
*/
// void xrgbgammashift8( uint8_t *r, uint8_t *g , uint8_t *b );
void xrgbgamma8(uint8_t *r, uint8_t *g, uint8_t *b);

/*
Gamma correction on RGBW in 8-bit range
*/
void xrgbwgamma8( uint8_t *r, uint8_t *g , uint8_t *b, uint8_t *w );

/*
Luma shift on RGB in 8-bit range
*/
// void xrgbluma8( uint8_t *r, uint8_t *g , uint8_t *b, int8_t shift );

/*
Luma shift over an array of 8-bit values
*/
// void xlumaarray8( uint8_t *pntr, uint8_t count, int8_t shift );
void xrgbwgamma8(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *w);

#endif // __GAMMA__


#ifdef __HSV__

/*
HSV to RGB for 8-bit range
*/
void xhsv2rgb8s( uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g , uint8_t *b );
void xhsv2rgb8e( uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g , uint8_t *b );
void xhsv2rgb8w( uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g , uint8_t *b );
void xhsv2rgb8t( uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g , uint8_t *b );
void xhsv2rgb8s(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b);
void xhsv2rgb8e(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b);
void xhsv2rgb8w(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b);
void xhsv2rgb8t(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b);

#endif // __HSV__
/*
* Provide a default xhsv2rgb8 function
*/
void xhsv2rgb8(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b)
{
return xhsv2rgb8s(h, s, v, r, g, b);
}

#endif // __HSV__

#ifdef __RGBW__

/*
RGB to RGBW conversion on 8-bit range
*/
void xrgb2rgbw8( uint8_t *r, uint8_t *g , uint8_t *b, uint8_t *w ); // Done
void xrgb2rgbw8(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *w); // Done

#endif // __RGBW__


// ------------------- Convienence functions ------------------------------


#ifdef __GAMMA_RGBW__

/*
RGB to RGBW with Gamma Correction for 8-bit range
*/
void xrgb2rgbwgamma8( uint8_t *r, uint8_t *g , uint8_t *b, uint8_t *w )
void xrgb2rgbwgamma8(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *w)
{
xrgb2rgbw8( r, g, b, w );
xrgbwgamma8( r, g, b, w );
xrgb2rgbw8(r, g, b, w);
xrgbwgamma8(r, g, b, w);
}

#endif // __GAMMA__RGBW__

#endif // __GAMMA__RGBW__

#ifdef __HSV_RGBW__

/*
HSV to RGBW for 8-bit range
*/
void xhsv2rgbw8( uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b , uint8_t *w )
void xhsv2rgbw8(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *w)
{
//xhsv2rgb8( h, s, v, r, g, b );
xrgb2rgbw8( r, g, b, w );
xhsv2rgb8(h, s, v, r, g, b);
xrgb2rgbw8(r, g, b, w);
}

#endif


#ifdef __GAMMA_HSV_RGBW__

/*
HSV to RGB conversion with Gamma correction for 8-bit range
*/
void xhsv2rgbgamma8( uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g , uint8_t *b )
void xhsv2rgbgamma8(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b)
{
xhsv2rgb8s( h, s, v, r, g, b );
xrgbgamma8( r, g, b );
xhsv2rgb8(h, s, v, r, g, b);
xrgbgamma8(r, g, b);
}

/*
HSV to RGBW with Gamma Correction for 8-bit range
*/
void xhsv2rgbwgamma8( uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g , uint8_t *b, uint8_t *w )
void xhsv2rgbwgamma8(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *w)
{
xhsv2rgb8s( h, s, v, r, g, b );
xrgb2rgbw8( r, g, b, w );
xrgbwgamma8( r, g, b, w );
xhsv2rgb8(h, s, v, r, g, b);
xrgb2rgbw8(r, g, b, w);
xrgbwgamma8(r, g, b, w);
}

#endif // __GAMMA_HSV_RGBW__

}

#endif // ESPXRGB_H
17 changes: 0 additions & 17 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,3 @@
//

#endif // __GAMMA__


#ifdef __HSV__
/*
* HSV configuration
*/
#define HSV_SEXTANTS 6
#define HSV_HUE_SEXTANT 256
#define HSV_HUE_STEPS (HSV_SEXTANTS * HSV_HUE_SEXTANT)
#define HSV_HUE_MIN 0
#define HSV_HUE_MAX (HSV_HUE_STEPS - 1)
#define HSV_SAT_MIN 0
#define HSV_SAT_MAX 255
#define HSV_VAL_MIN 0
#define HSV_VAL_MAX 255

#endif // __HSV__
Loading

0 comments on commit 20d0006

Please sign in to comment.