primeに登録してから、最近見た映画はprimeばっかりだなぁ。最近聞く音楽もprimeばっかりだし、嗜好がamazonに制御される。
***
さて、本題のIron palette。前回、最後にちらっと書いた、「正弦波2個じゃなくて、正弦波1個と直線で良いんじゃね?」をやってみました。
いい感じです。
FLIRのスペクトルとよく似ているので、FLIRも正弦波+直線で作っているのかもしれません。
正弦波2個を作るには、パラメータが4+4で8個必要でした。正弦波1個だと、パラメータは4+2で6個で済みます。3割ほど、パラメータで使うROM領域が少なくて済みます。96byteが72byteになったところで、誤差の範囲ですけど。チープな組み込みなら24byteも大きいですが、なら三角関数とか使うな、という話で。
***
C# src
public class Iron_palette
{
protected const float R_f = 1.5879f;
protected const float G_f = 4.2124f;
protected const float B_f = 2.2251f;
protected const float R_p = 3.161f;
protected const float G_p = 0.8156f;
protected const float B_p = 3.1285f;
protected const float R_g = 0.4042f;
protected const float G_g = 1.0976f;
protected const float B_g = 1.9342f;
protected const float R_o = 0.0027f;
protected const float G_o = -1.5174f;
protected const float B_o = 1.9635f;
protected const float R_a = 1.9869f;
protected const float G_a = -0.1639f;
protected const float B_a = 2.2419f;
protected const float R_b = -3.9506f;
protected const float G_b = -0.17f;
protected const float B_b = 0.1099f;
public static Color to_color(double value)
{
if (value < 0 || value > 1)
{
throw (new ArgumentOutOfRangeException());
}
return (Color.FromArgb(
(int)(
(Math.Sin(value * R_f + R_p) * R_g + R_o) *
(value * R_a + R_b) *
255),
(int)(
(Math.Sin(value * G_f + G_p) * G_g + G_o) *
(value * G_a + G_b) *
255),
(int)(
(Math.Sin(value * B_f + B_p) * B_g + B_o) *
(value * B_a + B_b) *
255)));
}
}


0 件のコメント:
コメントを投稿