|
本帖最后由 myqiang1990 于 2013-8-22 14:49 编辑
这个是舞台灯光LED调光对数,线性和,指数的调光曲线获取算法,生产的是PWM值,下面是资料,但是算法被我改良过的,可以生产3种曲线~~~~只要修改GAMMA值,如果伽马值是1,就是线性,如果小于1就是对数,大于1就是指数,,,,大家对照我的图,自己用delphi做一个,很简单的,只要把算法复制,在对照程序,对照图片自己弄一下就OK乐!!
- //////////////////////////////////////////////////对数调光光曲线生成START//////////////////////////////////////
- //////////////////////////////////////////////////对数调光光曲线生成START//////////////////////////////////////
- procedure TForm1.LightWave(a,b:string; color:byte; style:string; Gamma:Double; show:boolean; func:byte);
- var
- PwmData: array[0..65535] of double;
- //GammaData: array[0..65535] of integer;
- PwmLeves:integer;
- CurveLeves, i,j:integer;
- Ratio, f:Double;
- begin
- //如果当前曲线为要显示指令
- if show = true then
- begin
- PwmLeves := StrToInt(a); //求出PWM级数
- CurveLeves := StrToInt(b); //求出调光级数
- //Ratio := (log10(PwmLeves)) / CurveLeves; //求出系数
- j := 1;
- //求出曲线
- {for i := 0 to CurveLeves - 1 do
- begin
- PwmData[i] := Power(10, (i + 1) * Ratio);
- iXYPlot1.Channel[color].AddXY(i, trunc(PwmData[i])) ;
- end;
- iXYPlot1.Channel[color].AddXY(0, trunc(PwmData[0])) ;//画线性直线
- }
- //对曲线进行GAMMA纠正
- Ratio := 1 / Gamma;
- //GAMMA运算
- for i:= 0 to CurveLeves - 1 do
- begin
- f := (i + 0.5) / PwmLeves * (PwmLeves / CurveLeves);//归一化
- f := Power(f, Ratio);//预补偿
- PwmData[i] := trunc(f * PwmLeves - 0.5);//反归一化
- if((i <> 0) and (PwmData[i] = 0)) then
- PwmData[i] := PwmData[i] + 1;
- iXYPlot1.Channel[color].AddXY(i, PwmData[i]); //GammaData
- end;
- //显示
- RGBshowstr := RGBshowstr+'/////////////////////' + Format('%s',[style]) +'_'+ '对数调光曲线///////////////////////'+#13;
- RGBshowstr := RGBshowstr+'//PWM级数 :' + Format('%d',[PwmLeves])+#13;
- RGBshowstr := RGBshowstr+'//调光级数:' + Format('%d',[CurveLeves])+#13;
- RGBshowstr := RGBshowstr+'//伽马(Gamma)校正值:' + Format('%.5f',[Gamma])+#13;
- //8,16BIT选择
- if checkbox8.Checked = true then
- RGBshowstr := RGBshowstr+'const u16 '+ format('%s', [style])+'_Log_8Bit_LightCurve'+'['+format('%d', [CurveLeves])+']'+' =' + #13 + '{'+#13
- else
- RGBshowstr := RGBshowstr+'const u16 '+ format('%s', [style])+'_Log_16Bit_LightCurve'+'['+format('%d', [CurveLeves])+']'+' =' + #13 + '{' +#13;
- //存储数据
- for i := 0 to CurveLeves - 1 do
- begin
- if style = 'Red' then //调整曲线
- PwmData[i] := PwmData[i] + Red[i]
- else if style = 'Green' then
- PwmData[i] := PwmData[i] + Green[i]
- else if style = 'Blue' then
- PwmData[i] := PwmData[i] + Blue[i];
-
- //判断调整后数据合法性
- if PwmData[i] > PwmLeves then
- PwmData[i] := PwmLeves
- else if PwmData[i] < 0 then
- PwmData[i] := 0;
- //画曲线
- iXYPlot1.Channel[color].AddXY(i, PwmData[i]);
- //显示数据10,16进制
- if checkbox7.Checked = false then
- RGBshowstr := RGBshowstr+ Format('%d, ', [trunc(PwmData[i])])
- else
- RGBshowstr := RGBshowstr+ Format('0x%.4x, ', [trunc(PwmData[i])]) ;
- if ((i+1) mod 20 = 0) then
- begin
- RGBshowstr := RGBshowstr +'//'+format('%d', [ j* 20])+ #13;
- j := j+1;
- end;
- end;
- RGBshowstr := RGBshowstr + #13;
- RGBshowstr := RGBshowstr + '};'+#13;
- memo1.Lines.Text:=RGBshowstr;
- end
- else
- begin
- iXYPlot1.Channel[color].Clear;
- end;
- end;
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
如果想吃一顿饺子,就得从冰箱里取出肉,剁馅儿,倒面粉、揉面、醒面,擀成皮儿,下锅……
一整个繁琐流程,就是为了出锅时那一嘴滚烫流油的热饺子。
如果这个过程,禁不住饿,零食下肚了,饺子出锅时也就不香了……《非诚勿扰3》
|