Added gamma 2.5 corrected 3.0 table added fade mode.

The fade mode is using one gamma correction table and fades with a time
offset to create a nice moving fade.
This commit is contained in:
Piotr Esden-Tempski 2010-02-22 15:06:28 +01:00
parent c713c02e9d
commit da2b9d94fb

View File

@ -21,9 +21,20 @@
#include <libopenstm32/gpio.h>
#include <libopenstm32/timer.h>
//#define COMPARE
#define MOVING_FADE
#ifdef COMPARE
#define GAMMA_LINEAR
#define GAMMA_1_3
#define GAMMA_2_5
#define GAMMA_3_0
#endif
#ifdef MOVING_FADE
#define GAMMA_3_0
#define GAMMA_TABLE gamma_table_3_0
#endif
/*
* Gamma correction table
@ -106,41 +117,79 @@ static const uint16_t gamma_table_1_3[] = {
};
#endif
#ifdef GAMMA_2_5
static const uint16_t gamma_table_2_5[] = {
// gamma = 2.5
0, 0, 0, 1, 2, 4, 6, 8,
11, 15, 20, 25, 31, 38, 46, 55,
65, 75, 87, 99, 113, 128, 143, 160,
178, 197, 218, 239, 262, 286, 311, 338,
366, 395, 425, 457, 491, 526, 562, 599,
639, 679, 722, 765, 811, 857, 906, 956,
1007, 1061, 1116, 1172, 1231, 1291, 1352, 1416,
1481, 1548, 1617, 1688, 1760, 1834, 1910, 1988,
2068, 2150, 2233, 2319, 2407, 2496, 2587, 2681,
2776, 2874, 2973, 3075, 3178, 3284, 3391, 3501,
3613, 3727, 3843, 3961, 4082, 4204, 4329, 4456,
4585, 4716, 4850, 4986, 5124, 5264, 5407, 5552,
5699, 5849, 6001, 6155, 6311, 6470, 6632, 6795,
6962, 7130, 7301, 7475, 7650, 7829, 8009, 8193,
8379, 8567, 8758, 8951, 9147, 9345, 9546, 9750,
9956, 10165, 10376, 10590, 10806, 11025, 11247, 11472,
11699, 11929, 12161, 12397, 12634, 12875, 13119, 13365,
13614, 13865, 14120, 14377, 14637, 14899, 15165, 15433,
15705, 15979, 16256, 16535, 16818, 17104, 17392, 17683,
17978, 18275, 18575, 18878, 19184, 19493, 19805, 20119,
20437, 20758, 21082, 21409, 21739, 22072, 22407, 22746,
23089, 23434, 23782, 24133, 24487, 24845, 25206, 25569,
25936, 26306, 26679, 27055, 27435, 27818, 28203, 28592,
28985, 29380, 29779, 30181, 30586, 30994, 31406, 31820,
32239, 32660, 33085, 33513, 33944, 34379, 34817, 35258,
35702, 36150, 36602, 37056, 37514, 37976, 38441, 38909,
39380, 39856, 40334, 40816, 41301, 41790, 42282, 42778,
43277, 43780, 44286, 44795, 45308, 45825, 46345, 46869,
47396, 47927, 48461, 48999, 49540, 50085, 50634, 51186,
51742, 52301, 52864, 53431, 54001, 54575, 55153, 55734,
56318, 56907, 57499, 58095, 58695, 59298, 59905, 60515,
61130, 61748, 62370, 62995, 63624, 64258, 64894, 65535
};
#endif
#ifdef GAMMA_3_0
static const uint16_t gamma_table_3_0[] = {
// gamma = 3.0014
0, 1, 4, 9, 16, 25, 36, 49,
64, 81, 100, 121, 145, 170, 197, 226,
257, 290, 325, 362, 402, 443, 486, 531,
579, 628, 679, 732, 788, 845, 904, 966,
1029, 1094, 1162, 1231, 1303, 1376, 1451, 1529,
1608, 1690, 1773, 1859, 1946, 2036, 2127, 2221,
2317, 2414, 2514, 2615, 2719, 2825, 2932, 3042,
3154, 3267, 3383, 3501, 3621, 3742, 3866, 3992,
4120, 4250, 4382, 4516, 4651, 4789, 4929, 5071,
5215, 5361, 5509, 5659, 5811, 5965, 6121, 6279,
6439, 6601, 6766, 6932, 7100, 7270, 7442, 7616,
7793, 7971, 8151, 8333, 8518, 8704, 8892, 9083,
9275, 9469, 9666, 9864, 10065, 10267, 10472, 10678,
10887, 11097, 11310, 11524, 11741, 11959, 12180, 12403,
12627, 12854, 13082, 13313, 13546, 13781, 14017, 14256,
14497, 14740, 14984, 15231, 15480, 15731, 15984, 16239,
16496, 16755, 17016, 17279, 17544, 17811, 18080, 18351,
18624, 18899, 19176, 19455, 19736, 20019, 20304, 20592,
20881, 21172, 21465, 21761, 22058, 22357, 22658, 22962,
23267, 23574, 23884, 24195, 24509, 24824, 25142, 25461,
25783, 26106, 26432, 26759, 27089, 27420, 27754, 28090,
28427, 28767, 29109, 29452, 29798, 30146, 30495, 30847,
31201, 31557, 31915, 32275, 32636, 33000, 33366, 33734,
34104, 34476, 34850, 35226, 35604, 35984, 36366, 36750,
37136, 37524, 37915, 38307, 38701, 39097, 39495, 39896,
40298, 40702, 41108, 41517, 41927, 42339, 42754, 43170,
43589, 44009, 44431, 44856, 45282, 45711, 46141, 46574,
47008, 47445, 47884, 48324, 48767, 49212, 49658, 50107,
50558, 51010, 51465, 51922, 52381, 52841, 53304, 53769,
54236, 54705, 55176, 55649, 56124, 56601, 57080, 57561,
58044, 58529, 59016, 59505, 59996, 60489, 60984, 61481,
61981, 62482, 62985, 63490, 63998, 64507, 65018, 65531
// gamma = 3.0
0, 0, 0, 0, 0, 0, 1, 1,
2, 3, 4, 5, 7, 9, 11, 13,
16, 19, 23, 27, 32, 37, 42, 48,
55, 62, 69, 78, 87, 96, 107, 118,
130, 142, 155, 169, 184, 200, 217, 234,
253, 272, 293, 314, 337, 360, 385, 410,
437, 465, 494, 524, 556, 588, 622, 658,
694, 732, 771, 812, 854, 897, 942, 988,
1036, 1085, 1136, 1189, 1243, 1298, 1356, 1415,
1475, 1538, 1602, 1667, 1735, 1804, 1876, 1949,
2024, 2100, 2179, 2260, 2343, 2427, 2514, 2603,
2693, 2786, 2881, 2978, 3078, 3179, 3283, 3389,
3497, 3607, 3720, 3835, 3952, 4072, 4194, 4319,
4446, 4575, 4707, 4842, 4979, 5118, 5261, 5405,
5553, 5703, 5856, 6011, 6169, 6330, 6494, 6660,
6830, 7002, 7177, 7355, 7536, 7719, 7906, 8096,
8289, 8484, 8683, 8885, 9090, 9298, 9510, 9724,
9942, 10163, 10387, 10614, 10845, 11079, 11317, 11557,
11802, 12049, 12300, 12555, 12813, 13074, 13339, 13608,
13880, 14156, 14435, 14718, 15005, 15295, 15589, 15887,
16189, 16494, 16803, 17117, 17433, 17754, 18079, 18408,
18740, 19077, 19418, 19762, 20111, 20464, 20821, 21182,
21547, 21917, 22290, 22668, 23050, 23436, 23827, 24222,
24621, 25025, 25433, 25845, 26262, 26683, 27109, 27539,
27974, 28413, 28857, 29306, 29759, 30217, 30680, 31147,
31619, 32095, 32577, 33063, 33554, 34050, 34551, 35056,
35567, 36082, 36602, 37128, 37658, 38194, 38734, 39280,
39830, 40386, 40947, 41513, 42084, 42661, 43243, 43830,
44422, 45019, 45622, 46231, 46844, 47463, 48088, 48718,
49353, 49994, 50641, 51293, 51950, 52614, 53282, 53957,
54637, 55323, 56014, 56712, 57415, 58123, 58838, 59558,
60285, 61017, 61755, 62499, 63249, 64005, 64767, 65535
};
#endif
@ -264,13 +313,14 @@ int main(void)
gpio_setup();
tim_setup();
#ifdef COMPARE
j0=0;
d0=1;
j1=0;
d1=1;
j2=0;
d2=1;
j3=128;
j3=0;
d3=1;
while (1)
{
@ -282,7 +332,7 @@ int main(void)
j1+=d1;
if(j1==255) d1=-1;
if(j1==0) d1=1;
TIM3_CCR3= gamma_table_3_0[j2];
TIM3_CCR3= gamma_table_2_5[j2];
j2+=d2;
if(j2==255) d2=-1;
if(j2==0) d2=1;
@ -292,6 +342,38 @@ int main(void)
if(j3==0) d3=1;
for(i=0; i< 50000; i++){}
}
#endif
#ifdef MOVING_FADE
j0=0;
d0=1;
j1=64;
d1=1;
j2=128;
d2=1;
j3=192;
d3=1;
while (1)
{
TIM3_CCR1= GAMMA_TABLE[j0];
j0+=d0;
if(j0==255) d0=-1;
if(j0==0) d0=1;
TIM3_CCR2= GAMMA_TABLE[j1];
j1+=d1;
if(j1==255) d1=-1;
if(j1==0) d1=1;
TIM3_CCR3= GAMMA_TABLE[j2];
j2+=d2;
if(j2==255) d2=-1;
if(j2==0) d2=1;
TIM3_CCR4= GAMMA_TABLE[j3];
j3+=d3;
if(j3==255) d3=-1;
if(j3==0) d3=1;
for(i=0; i< 50000; i++){}
}
#endif
return 0;
}