Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Better sRGB gamma table for LEDs

  • Loading branch information...
commit 761f98fed65145527708aca6bb182fb6f1cffe38 1 parent 07da474
@suovula suovula authored
View
34 software/arduino/partyhatwork/gammaramp.h
@@ -1,18 +1,30 @@
#ifndef GAMMARAMP_H
#define GAMMARAMP_H
+
#include <avr/pgmspace.h>
+#include <stdint.h>
-// Gamma 2.5
-const uint8_t gammaRamp256Table[256] PROGMEM = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07,
- 0x08, 0x08, 0x08, 0x09, 0x09, 0x09, 0x0a, 0x0a, 0x0a, 0x0b, 0x0b, 0x0b, 0x0c, 0x0c, 0x0d, 0x0d, 0x0e, 0x0e, 0x0e, 0x0f, 0x0f, 0x10, 0x10, 0x11, 0x11, 0x12, 0x12, 0x13, 0x13, 0x14, 0x15, 0x15,
- 0x16, 0x16, 0x17, 0x17, 0x18, 0x19, 0x19, 0x1a, 0x1b, 0x1b, 0x1c, 0x1d, 0x1d, 0x1e, 0x1f, 0x1f, 0x20, 0x21, 0x22, 0x22, 0x23, 0x24, 0x25, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2a, 0x2b, 0x2c,
- 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4d, 0x4e,
- 0x4f, 0x50, 0x52, 0x53, 0x54, 0x55, 0x57, 0x58, 0x59, 0x5b, 0x5c, 0x5d, 0x5f, 0x60, 0x62, 0x63, 0x64, 0x66, 0x67, 0x69, 0x6a, 0x6c, 0x6d, 0x6f, 0x70, 0x72, 0x73, 0x75, 0x77, 0x78, 0x7a, 0x7b,
- 0x7d, 0x7f, 0x80, 0x82, 0x84, 0x85, 0x87, 0x89, 0x8a, 0x8c, 0x8e, 0x90, 0x91, 0x93, 0x95, 0x97, 0x99, 0x9b, 0x9c, 0x9e, 0xa0, 0xa2, 0xa4, 0xa6, 0xa8, 0xaa, 0xac, 0xae, 0xb0, 0xb2, 0xb4, 0xb6,
- 0xb8, 0xba, 0xbc, 0xbe, 0xc0, 0xc2, 0xc5, 0xc7, 0xc9, 0xcb, 0xcd, 0xcf, 0xd2, 0xd4, 0xd6, 0xd8, 0xdb, 0xdd, 0xdf, 0xe2, 0xe4, 0xe6, 0xe9, 0xeb, 0xed, 0xf0, 0xf2, 0xf5, 0xf7, 0xfa, 0xfc, 0xff
+// sRGB to linear, overall gamma is approximately 2.2
+prog_uint16_t gammaTable256to4096[256] PROGMEM = {
+ 0x0000, 0x0001, 0x0002, 0x0004, 0x0005, 0x0006, 0x0007, 0x0009, 0x000a, 0x000b, 0x000c, 0x000e, 0x000f, 0x0010, 0x0012, 0x0014,
+ 0x0015, 0x0017, 0x0019, 0x001b, 0x001d, 0x001f, 0x0021, 0x0023, 0x0025, 0x0028, 0x002a, 0x002d, 0x0030, 0x0032, 0x0035, 0x0038,
+ 0x003b, 0x003e, 0x0042, 0x0045, 0x0048, 0x004c, 0x004f, 0x0053, 0x0057, 0x005b, 0x005f, 0x0063, 0x0067, 0x006b, 0x0070, 0x0074,
+ 0x0079, 0x007e, 0x0083, 0x0088, 0x008d, 0x0092, 0x0097, 0x009c, 0x00a2, 0x00a8, 0x00ad, 0x00b3, 0x00b9, 0x00bf, 0x00c5, 0x00cc,
+ 0x00d2, 0x00d8, 0x00df, 0x00e6, 0x00ed, 0x00f4, 0x00fb, 0x0102, 0x0109, 0x0111, 0x0118, 0x0120, 0x0128, 0x0130, 0x0138, 0x0140,
+ 0x0149, 0x0151, 0x015a, 0x0162, 0x016b, 0x0174, 0x017d, 0x0186, 0x0190, 0x0199, 0x01a3, 0x01ac, 0x01b6, 0x01c0, 0x01ca, 0x01d5,
+ 0x01df, 0x01ea, 0x01f4, 0x01ff, 0x020a, 0x0215, 0x0220, 0x022b, 0x0237, 0x0242, 0x024e, 0x025a, 0x0266, 0x0272, 0x027f, 0x028b,
+ 0x0298, 0x02a4, 0x02b1, 0x02be, 0x02cb, 0x02d8, 0x02e6, 0x02f3, 0x0301, 0x030f, 0x031d, 0x032b, 0x0339, 0x0348, 0x0356, 0x0365,
+ 0x0374, 0x0383, 0x0392, 0x03a1, 0x03b1, 0x03c0, 0x03d0, 0x03e0, 0x03f0, 0x0400, 0x0411, 0x0421, 0x0432, 0x0443, 0x0454, 0x0465,
+ 0x0476, 0x0487, 0x0499, 0x04ab, 0x04bd, 0x04cf, 0x04e1, 0x04f3, 0x0506, 0x0518, 0x052b, 0x053e, 0x0551, 0x0565, 0x0578, 0x058c,
+ 0x05a0, 0x05b3, 0x05c8, 0x05dc, 0x05f0, 0x0605, 0x061a, 0x062e, 0x0643, 0x0659, 0x066e, 0x0684, 0x0699, 0x06af, 0x06c5, 0x06db,
+ 0x06f2, 0x0708, 0x071f, 0x0736, 0x074d, 0x0764, 0x077c, 0x0793, 0x07ab, 0x07c3, 0x07db, 0x07f3, 0x080b, 0x0824, 0x083d, 0x0855,
+ 0x086f, 0x0888, 0x08a1, 0x08bb, 0x08d4, 0x08ee, 0x0908, 0x0923, 0x093d, 0x0958, 0x0973, 0x098e, 0x09a9, 0x09c4, 0x09df, 0x09fb,
+ 0x0a17, 0x0a33, 0x0a4f, 0x0a6c, 0x0a88, 0x0aa5, 0x0ac2, 0x0adf, 0x0afc, 0x0b19, 0x0b37, 0x0b55, 0x0b73, 0x0b91, 0x0baf, 0x0bce,
+ 0x0bec, 0x0c0b, 0x0c2a, 0x0c4a, 0x0c69, 0x0c89, 0x0ca8, 0x0cc8, 0x0ce8, 0x0d09, 0x0d29, 0x0d4a, 0x0d6b, 0x0d8c, 0x0dad, 0x0dcf,
+ 0x0df0, 0x0e12, 0x0e34, 0x0e56, 0x0e79, 0x0e9b, 0x0ebe, 0x0ee1, 0x0f04, 0x0f27, 0x0f4b, 0x0f6e, 0x0f92, 0x0fb6, 0x0fdb, 0x0fff
};
-inline uint8_t gammaRamp256(uint8_t val) { return pgm_read_byte_near(gammaRamp256Table + val); }
+inline uint16_t gamma256to4096(uint8_t val) { return pgm_read_word_near(gammaTable256to4096 + val); }
+inline uint16_t gamma256to256(uint8_t val) { return pgm_read_word_near(gammaTable256to4096 + val) >> 4; }
+
#endif
View
6 software/arduino/partyhatwork/rgb.h
@@ -23,9 +23,9 @@ uint8_t pwmlimit(uint8_t pwm)
*/
void setRGB(uint8_t startpin, uint8_t r, uint8_t g, uint8_t b)
{
- byte rgamma = gammaRamp256(r);
- byte bgamma = gammaRamp256(b);
- byte ggamma = gammaRamp256(g);
+ byte rgamma = gamma256to256(r);
+ byte bgamma = gamma256to256(b);
+ byte ggamma = gamma256to256(g);
analogWrite(startpin, pwmlimit(rgamma));
analogWrite(startpin+1, pwmlimit(ggamma));
analogWrite(startpin+2, pwmlimit(bgamma));
Please sign in to comment.
Something went wrong with that request. Please try again.