Skip to content

Commit 2510474

Browse files
committed
0.2.2 GAMMA
1 parent 76c77a2 commit 2510474

File tree

15 files changed

+351
-139
lines changed

15 files changed

+351
-139
lines changed

libraries/GAMMA/README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ The library has a **setGamma(float gamma)** function that allows an application
3131
to change the gamma value runtime.
3232
This allows adjustments that a fixed table does not have.
3333

34-
The class can be used to dump the internal table e.g. to place in PROGMEM.
34+
The class provides **dump()** to create a table e.g. to place in PROGMEM.
35+
Since 0.2.2 the library also has **dumpArray()** to generate a C-style array.
3536

3637
Note: tested on UNO and ESP32 only.
3738

@@ -42,38 +43,50 @@ Note: tested on UNO and ESP32 only.
4243

4344
- **GAMMA(uint16_t size = 32)** constructor, gets the size of the internal
4445
array as parameter. The default for size = 32 as this is a good balance between performance
45-
and size of the internal array. The size parameter must be in {2, 4, 8, 16, 32, 64, 128, 256 }.
46-
- **begin()** The array is initialized with a gamma == 2.8 which is an often used value.
47-
**begin()** must be called before any other function.
48-
- **setGamma(float gamma)** calculates and fills the array with new values.
49-
This can be done runtime so runtime adjustment of gamma mapping.
50-
This function takes relative quite some time.
46+
and size of the internal array.
47+
The size parameter must be in {2, 4, 8, 16, 32, 64, 128, 256 }.
48+
- **~GAMMA()** destructor.
49+
- **void begin()** The internal array is allocated and initialized with a gamma == 2.8.
50+
This is an often used value to adjust light to human eye responses.
51+
Note that **begin()** must be called before any other function.
52+
- **void setGamma(float gamma)** calculates and fills the array with new values.
53+
This can be done runtime so runtime adjustment of gamma mapping is possible.
54+
This calculation are relative expensive and takes quite some time (depending on size).
55+
If the array already is calculated for gamma, the calculation will be skipped.
5156
The parameter **gamma** must be > 0. The value 1 gives an 1:1 mapping.
52-
- **getGamma()** returns the set gamma value.
53-
- **operator \[\]** allows the GAMMA object to be accessed as an array.
54-
like ```x = G[40];``` Makes it easy to switch with a real array.
57+
- **float getGamma()** returns the set gamma value.
58+
- **uint8_t operator \[\]** allows the GAMMA object to be accessed as an array.
59+
like ```x = G[40];``` Makes it easy to switch with a real array.
60+
The value returned is in the range 0 .. 255, so the user may need to scale it e.g. to 0.0 - 1.0
5561

5662

5763
### Development functions
5864

59-
- **size()** returns size of the internal array.
60-
- **distinct()** returns the number of distinct values in the table.
61-
Especially with larger internal tables rhere will be duplicate numbers in the table.
62-
- **dump()** dumps the internal table to Serial. Can be useful to create
63-
an array in RAM, PROGMEM or wherever.
65+
- **uint16_t size()** returns size of the internal array.
66+
This is always a power of 2.
67+
- **uint16_t distinct()** returns the number of distinct values in the table.
68+
Especially with larger internal tables there will be duplicate numbers in the table.
69+
- **void dump(Stream \*str = &Serial)** dumps the internal table to a stream, default Serial.
70+
Useful to create an array in RAM, PROGMEM, EEPROM, in a file or wherever.
71+
- **void dumpArray(Stream \*str = &Serial)** dumps the internal table to a stream, default Serial, as a C-style array. See example.
6472

6573

6674
## Operation
6775

68-
See example
76+
See example.
6977

7078

7179
## Future ideas
7280

7381
- improve documentation
7482
- test other platforms
75-
- look for optimizations
83+
- look for optimizations
84+
- getter \[\]
85+
- setGamma -> pow() is expensive
86+
- improvements (0.3.0)
87+
- return bool => begin() + setGamma() + dump()?
88+
- check \_table != NULL in functions
89+
- add gamma<=0 check in setGamma()
7690
- uint16 version?
77-
- **dumpAsArray()** - generate a C style array
7891
-
7992

libraries/GAMMA/examples/GammaErrorAnalysis/GammaErrorAnalysis.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// FILE: GammaErrorAnalysis.ino
33
// AUTHOR: Rob Tillaart
44
// PURPOSE: demo
5-
// DATE: 2020-08-08
65

76

87
#include "gamma.h"
@@ -24,7 +23,10 @@ volatile int x;
2423
void setup()
2524
{
2625
Serial.begin(115200);
26+
Serial.println();
2727
Serial.println(__FILE__);
28+
Serial.print("GAMMA_LIB_VERSION: ");
29+
Serial.println(GAMMA_LIB_VERSION);
2830

2931
gt1.begin();
3032
gt2.begin();

libraries/GAMMA/examples/GammaPerformance/GammaPerformance.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// FILE: gammaPerformance.ino
33
// AUTHOR: Rob Tillaart
44
// PURPOSE: demo
5-
// DATE: 2020-08-08
65

76

87
#include "gamma.h"
@@ -21,7 +20,10 @@ volatile int x;
2120
void setup()
2221
{
2322
Serial.begin(115200);
23+
Serial.println();
2424
Serial.println(__FILE__);
25+
Serial.print("GAMMA_LIB_VERSION: ");
26+
Serial.println(GAMMA_LIB_VERSION);
2527

2628
gt1.begin();
2729
gt2.begin();
@@ -99,3 +101,4 @@ void loop()
99101

100102

101103
// -- END OF FILE --
104+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Arduino UNO
2+
IDE 1.8.19
3+
4+
GammaPerformance.ino
5+
GAMMA_LIB_VERSION: 0.2.1
6+
7+
timing in microseconds
8+
9+
SETGAMMA
10+
SIZE TIME TIME per element
11+
257 85868 334.12
12+
129 42712 331.10
13+
65 21200 326.15
14+
33 10448 316.61
15+
17 5084 299.06
16+
17+
SETGAMMA II
18+
SIZE TIME TIME per element
19+
257 12 0.05
20+
129 8 0.06
21+
65 4 0.06
22+
33 8 0.24
23+
17 8 0.47
24+
25+
GET[]
26+
SIZE TIME TIME per element
27+
257 356 1.39
28+
129 876 3.42
29+
65 1116 4.36
30+
33 1328 5.19
31+
17 1524 5.95
32+
33+
34+
done...
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Arduino UNO
2+
IDE 1.8.19
3+
4+
GammaPerformance.ino
5+
GAMMA_LIB_VERSION: 0.2.2
6+
7+
timing in microseconds
8+
9+
SETGAMMA
10+
SIZE TIME TIME per element
11+
257 85868 334.12
12+
129 42708 331.07
13+
65 21200 326.15
14+
33 10456 316.85
15+
17 5084 299.06
16+
17+
SETGAMMA II
18+
SIZE TIME TIME per element
19+
257 16 0.06
20+
129 8 0.06
21+
65 8 0.12
22+
33 4 0.12
23+
17 8 0.47
24+
25+
GET[]
26+
SIZE TIME TIME per element
27+
257 360 1.41
28+
129 872 3.41
29+
65 1124 4.39
30+
33 1332 5.20
31+
17 1520 5.94
32+
33+
34+
done...

libraries/GAMMA/examples/gammaFast/gammaFast.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//
22
// FILE: gammaFast.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.2.0
54
// PURPOSE: demo
6-
// DATE: 2020-08-08
75

86

97
#include "gamma.h"
@@ -42,6 +40,10 @@ int fastGamma(uint8_t idx)
4240
void setup()
4341
{
4442
Serial.begin(115200);
43+
Serial.println();
44+
Serial.println(__FILE__);
45+
Serial.print("GAMMA_LIB_VERSION: ");
46+
Serial.println(GAMMA_LIB_VERSION);
4547

4648
gt1.begin();
4749
gt1.setGamma(2.8);

libraries/GAMMA/examples/gammaTest/gammaTest.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// FILE: gammaTest.ino
33
// AUTHOR: Rob Tillaart
44
// PURPOSE: demo
5-
// DATE: 2020-08-08
65

76

87
#include "gamma.h"
@@ -18,6 +17,10 @@ GAMMA gt5(16);
1817
void setup()
1918
{
2019
Serial.begin(115200);
20+
Serial.println();
21+
Serial.println(__FILE__);
22+
Serial.print("GAMMA_LIB_VERSION: ");
23+
Serial.println(GAMMA_LIB_VERSION);
2124

2225
gt1.begin();
2326
gt2.begin();

libraries/GAMMA/examples/gammaTest2/gammaTest2.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// FILE: gammaTest2.ino
33
// AUTHOR: Rob Tillaart
44
// PURPOSE: demo setGamma
5-
// DATE: 2020-08-08
65

76
// Use Arduino Plotter to see the different curves.
87

@@ -15,7 +14,10 @@ GAMMA gt; // uses default 32 size
1514
void setup()
1615
{
1716
Serial.begin(115200);
18-
Serial.println("gammaTest2.ino");
17+
Serial.println();
18+
Serial.println(__FILE__);
19+
Serial.print("GAMMA_LIB_VERSION: ");
20+
Serial.println(GAMMA_LIB_VERSION);
1921

2022
gt.begin();
2123

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// FILE: gamma_dump_array.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: demo
5+
6+
7+
#include "gamma.h"
8+
9+
10+
GAMMA gt1(256);
11+
GAMMA gt2(128);
12+
GAMMA gt3(64);
13+
GAMMA gt4(32); // default
14+
GAMMA gt5(16);
15+
16+
17+
void setup()
18+
{
19+
Serial.begin(115200);
20+
Serial.println();
21+
Serial.println(__FILE__);
22+
Serial.print("GAMMA_LIB_VERSION: ");
23+
Serial.println(GAMMA_LIB_VERSION);
24+
25+
gt1.begin();
26+
gt2.begin();
27+
gt3.begin();
28+
gt4.begin();
29+
gt5.begin();
30+
31+
gt1.setGamma(2.8);
32+
gt2.setGamma(2.8);
33+
gt3.setGamma(2.8);
34+
gt4.setGamma(2.8);
35+
gt5.setGamma(2.8);
36+
37+
gt1.dumpArray();
38+
gt2.dumpArray();
39+
gt3.dumpArray();
40+
gt4.dumpArray();
41+
gt5.dumpArray();
42+
43+
Serial.println("\ndone...\n");
44+
}
45+
46+
47+
void loop()
48+
{
49+
}
50+
51+
52+
// -- END OF FILE --

0 commit comments

Comments
 (0)