很郁闷~再开源一个对数,线性,指数LED调光曲线获取算法

2019-12-09 20:04发布

本帖最后由 myqiang1990 于 2013-8-22 14:49 编辑

这个是舞台灯光LED调光对数,线性和,指数的调光曲线获取算法,生产的是PWM值,下面是资料,但是算法被我改良过的,可以生产3种曲线~~~~只要修改GAMMA值,如果伽马值是1,就是线性,如果小于1就是对数,大于1就是指数,,,,大家对照我的图,自己用delphi做一个,很简单的,只要把算法复制,在对照程序,对照图片自己弄一下就OK乐!!
截图00.jpg (673.27 KB, 下载次数: 21) 下载附件 2013-8-22 14:43 上传
Gamma校正的快速算法及其C语言实现.pdf (442.44 KB, 下载次数: 944) 2013-8-22 14:44 上传 点击文件名下载附件


  1. //////////////////////////////////////////////////对数调光光曲线生成START//////////////////////////////////////
  2. //////////////////////////////////////////////////对数调光光曲线生成START//////////////////////////////////////
  3. procedure TForm1.LightWave(a,b:string; color:byte; style:string; Gamma:Double; show:boolean; func:byte);
  4. var
  5.   PwmData: array[0..65535] of double;
  6.   //GammaData: array[0..65535] of integer;

  7.   PwmLeves:integer;
  8.   CurveLeves, i,j:integer;
  9.   Ratio, f:Double;
  10. begin
  11. //如果当前曲线为要显示指令
  12. if  show = true then
  13. begin
  14.    PwmLeves   := StrToInt(a); //求出PWM级数
  15.    CurveLeves := StrToInt(b);  //求出调光级数

  16.    //Ratio :=  (log10(PwmLeves)) / CurveLeves; //求出系数
  17.    j := 1;
  18.    //求出曲线
  19.    {for i := 0 to  CurveLeves - 1 do
  20.     begin
  21.      PwmData[i] := Power(10, (i + 1) * Ratio);
  22.      iXYPlot1.Channel[color].AddXY(i, trunc(PwmData[i])) ;
  23.     end;
  24.      iXYPlot1.Channel[color].AddXY(0, trunc(PwmData[0])) ;//画线性直线
  25.      }
  26.     //对曲线进行GAMMA纠正
  27.       Ratio := 1 / Gamma;
  28.       //GAMMA运算
  29.       for i:= 0 to CurveLeves - 1 do
  30.       begin
  31.        f := (i + 0.5) / PwmLeves * (PwmLeves / CurveLeves);//归一化
  32.        f := Power(f, Ratio);//预补偿
  33.        PwmData[i] := trunc(f * PwmLeves - 0.5);//反归一化
  34.        if((i <> 0)  and (PwmData[i] = 0)) then
  35.          PwmData[i] := PwmData[i] + 1;
  36.        iXYPlot1.Channel[color].AddXY(i, PwmData[i]);  //GammaData
  37.       end;
  38.       //显示
  39.       RGBshowstr := RGBshowstr+'/////////////////////' + Format('%s',[style]) +'_'+ '对数调光曲线///////////////////////'+#13;
  40.       RGBshowstr := RGBshowstr+'//PWM级数 :' + Format('%d',[PwmLeves])+#13;
  41.       RGBshowstr := RGBshowstr+'//调光级数:' + Format('%d',[CurveLeves])+#13;
  42.       RGBshowstr := RGBshowstr+'//伽马(Gamma)校正值:' + Format('%.5f',[Gamma])+#13;
  43.       //8,16BIT选择
  44.       if checkbox8.Checked = true then
  45.         RGBshowstr := RGBshowstr+'const u16 '+ format('%s', [style])+'_Log_8Bit_LightCurve'+'['+format('%d', [CurveLeves])+']'+' =' + #13 + '{'+#13
  46.       else
  47.         RGBshowstr := RGBshowstr+'const u16 '+ format('%s', [style])+'_Log_16Bit_LightCurve'+'['+format('%d', [CurveLeves])+']'+' =' + #13 + '{' +#13;
  48.     //存储数据

  49.     for i := 0 to CurveLeves - 1 do
  50.      begin
  51.       if style = 'Red' then    //调整曲线
  52.         PwmData[i] := PwmData[i] + Red[i]
  53.       else if style = 'Green' then
  54.         PwmData[i] := PwmData[i] + Green[i]
  55.       else if style = 'Blue' then
  56.         PwmData[i] := PwmData[i] + Blue[i];
  57.       
  58.           //判断调整后数据合法性
  59.            if  PwmData[i] >  PwmLeves then
  60.               PwmData[i] := PwmLeves
  61.            else if  PwmData[i] < 0 then
  62.              PwmData[i] := 0;
  63.            //画曲线
  64.           iXYPlot1.Channel[color].AddXY(i, PwmData[i]);
  65.           //显示数据10,16进制
  66.           if checkbox7.Checked = false then
  67.            RGBshowstr := RGBshowstr+ Format('%d, ', [trunc(PwmData[i])])
  68.           else
  69.            RGBshowstr := RGBshowstr+ Format('0x%.4x, ', [trunc(PwmData[i])]) ;

  70.        if ((i+1) mod 20 = 0) then
  71.         begin
  72.          RGBshowstr := RGBshowstr +'//'+format('%d', [ j* 20])+ #13;
  73.          j := j+1;
  74.         end;
  75.       end;

  76.     RGBshowstr := RGBshowstr + #13;
  77.     RGBshowstr := RGBshowstr + '};'+#13;
  78.     memo1.Lines.Text:=RGBshowstr;

  79.     end
  80.     else
  81.     begin
  82.       iXYPlot1.Channel[color].Clear;
  83.     end;
  84. end;
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。