8 internal enum ColorMode
14 internal class FlameState
17 internal int[] frequency;
18 internal double[] reds;
19 internal double[] greens;
20 internal double[] blues;
24 internal double green;
34 internal long NrCalculated = 0;
35 internal ColorMode ColorMode;
36 internal int superSampling;
41 internal FlameState(Random Gen,
double xMin,
double xMax,
double yMin,
double yMax,
42 int Width,
int Height,
int SuperSampling,
long N, ColorMode ColorMode,
ScriptNode Node)
45 this.x = Gen.NextDouble();
46 this.y = Gen.NextDouble();
50 this.ColorMode = ColorMode;
58 this.superSampling = SuperSampling;
59 this.width = Width * SuperSampling;
60 this.height = Height * SuperSampling;
62 this.size = this.width * this.height;
63 this.sx = this.width / (xMax - xMin);
64 this.sy = this.height / (yMax - yMin);
66 this.frequency =
new int[this.size];
67 this.reds =
new double[this.size];
68 this.greens =
new double[this.size];
69 this.blues =
new double[this.size];
72 internal bool IncHistogram()
74 if (this.x < this.xMin || this.x > this.xMax || this.y < this.yMin || this.y > this.yMax)
77 int xi = (int)((this.x - this.xMin) * this.sx + 0.5);
78 int yi = this.height - 1 - (int)((this.y - this.yMin) * this.sy + 0.5);
80 if (xi < 0 || xi >= this.width || yi < 0 || yi >= this.height)
86 xi = this.frequency[yi];
87 if (xi <
int.MaxValue)
88 this.frequency[yi] = xi + 1;
90 switch (this.ColorMode)
93 this.reds[yi] = (this.reds[yi] + this.red) * 0.5;
94 this.greens[yi] = (this.greens[yi] + this.green) * 0.5;
95 this.blues[yi] = (this.blues[yi] + this.blue) * 0.5;
100 double Hue = this.reds[yi];
130 this.greens[yi] = (this.greens[yi] + this.green) * 0.5;
131 this.blues[yi] = (this.blues[yi] + this.blue) * 0.5;
137 internal void Add(FlameState State)
143 for (i = 0; i < this.size; i++)
145 f2 = State.frequency[i];
149 f1 = this.frequency[i];
153 this.frequency[i] = f2;
154 this.reds[i] = State.reds[i];
155 this.greens[i] = State.greens[i];
156 this.blues[i] = State.blues[i];
163 if (f >
int.MaxValue)
164 this.frequency[i] =
int.MaxValue;
166 this.frequency[i] = (int)f;
168 this.reds[i] = (f1 * this.reds[i] + f2 * State.reds[i]) / f;
169 this.greens[i] = (f1 * this.greens[i] + f2 * State.greens[i]) / f;
170 this.blues[i] = (f1 * this.blues[i] + f2 * State.blues[i]) / f;
175 internal PixelInformation RenderBitmapRgba(
double Gamma,
double Vibrancy,
bool Preview, SKColor? Background)
184 Frequency = (
int[])this.frequency.Clone();
185 Reds = (
double[])this.reds.Clone();
186 Greens = (
double[])this.greens.Clone();
187 Blues = (
double[])this.blues.Clone();
191 Frequency = this.frequency;
193 Greens = this.greens;
197 int Width = this.width / this.superSampling;
198 int Height = this.height / this.superSampling;
199 int size = Width * Height * 4;
200 byte[] rgb =
new byte[size];
206 int rowStep = Width * this.superSampling;
207 int rowStep2 = rowStep - this.superSampling;
208 int srcYStep = rowStep * this.superSampling;
211 double r, g, b, s, s2;
212 int freq, maxfreq = 0;
213 double GammaComponent = Gamma * (1 - Vibrancy) + Vibrancy;
214 double GammaAlpha = Gamma * Vibrancy + (1 - Vibrancy);
215 bool HasBg = Background.HasValue;
220 BgR = Background.Value.Red;
221 BgG = Background.Value.Green;
222 BgB = Background.Value.Blue;
227 s2 = Math.Pow(255.0, GammaComponent);
229 if (this.superSampling > 1)
231 for (y = srcY = 0; y < Height; y++, srcY += srcYStep)
233 for (x = 0, src = srcY; x < Width; x++, src += this.superSampling)
239 for (dy = 0; dy < this.superSampling; dy++)
241 for (dx = 0; dx < this.superSampling; dx++, si++)
264 Frequency[src] = freq;
275 foreach (
int F
in Frequency)
285 s = Math.Pow(255.0, GammaAlpha) / Math.Log(maxfreq);
287 GammaComponent = 1.0 / GammaComponent;
288 GammaAlpha = 1.0 / GammaAlpha;
292 for (y = srcY = 0; y < Height; y++, srcY += srcYStep)
294 for (x = 0, src = srcY; x < Width; x++, src += this.superSampling)
319 a = (int)(Math.Pow(Math.Log(i) * s, GammaAlpha));
321 si = (int)Blues[src];
322 si = (si * a + BgB * (255 - a) + 128) / 255;
328 rgb[dst++] = (byte)si;
330 si = (int)Greens[src];
331 si = (si * a + BgG * (255 - a) + 128) / 255;
337 rgb[dst++] = (byte)si;
340 si = (si * a + BgR * (255 - a) + 128) / 255;
346 rgb[dst++] = (byte)si;
352 si = (int)Blues[src];
358 rgb[dst++] = (byte)si;
360 si = (int)Greens[src];
366 rgb[dst++] = (byte)si;
374 rgb[dst++] = (byte)si;
376 a = (int)(Math.Pow(Math.Log(i) * s, GammaAlpha));
382 rgb[dst++] = (byte)a;
388 else if (Vibrancy == 0)
390 for (y = srcY = 0; y < Height; y++, srcY += srcYStep)
392 for (x = 0, src = srcY; x < Width; x++, src += this.superSampling)
417 a = (int)(Math.Log(i) * s);
419 si = (int)Math.Pow(Blues[src], GammaComponent);
420 si = (si * a + BgB * (255 - a) + 128) / 255;
426 rgb[dst++] = (byte)si;
428 si = (int)Math.Pow(Greens[src], GammaComponent);
429 si = (si * a + BgG * (255 - a) + 128) / 255;
435 rgb[dst++] = (byte)si;
437 si = (int)Math.Pow(Reds[src], GammaComponent);
438 si = (si * a + BgR * (255 - a) + 128) / 255;
444 rgb[dst++] = (byte)si;
450 si = (int)Math.Pow(Blues[src], GammaComponent);
456 rgb[dst++] = (byte)si;
458 si = (int)Math.Pow(Greens[src], GammaComponent);
464 rgb[dst++] = (byte)si;
466 si = (int)Math.Pow(Reds[src], GammaComponent);
472 rgb[dst++] = (byte)si;
474 a = (int)(Math.Log(i) * s);
480 rgb[dst++] = (byte)a;
488 for (y = srcY = 0; y < Height; y++, srcY += srcYStep)
490 for (x = 0, src = srcY; x < Width; x++, src += this.superSampling)
515 a = (int)(Math.Pow(Math.Log(i) * s, GammaAlpha));
517 si = (int)Math.Pow(Blues[src], GammaComponent);
518 si = (si * a + BgB * (255 - a) + 128) / 255;
524 rgb[dst++] = (byte)si;
526 si = (int)Math.Pow(Greens[src], GammaComponent);
527 si = (si * a + BgG * (255 - a) + 128) / 255;
533 rgb[dst++] = (byte)si;
535 si = (int)Math.Pow(Reds[src], GammaComponent);
536 si = (si * a + BgR * (255 - a) + 128) / 255;
542 rgb[dst++] = (byte)si;
548 si = (int)Math.Pow(Blues[src], GammaComponent);
554 rgb[dst++] = (byte)si;
556 si = (int)Math.Pow(Greens[src], GammaComponent);
562 rgb[dst++] = (byte)si;
564 si = (int)Math.Pow(Reds[src], GammaComponent);
570 rgb[dst++] = (byte)si;
572 a = (int)(Math.Pow(Math.Log(i) * s, GammaAlpha));
578 rgb[dst++] = (byte)a;
588 internal PixelInformation RenderBitmapHsl(
double Gamma,
double LightFactor,
bool Preview, SKColor? Background)
592 double[] Saturations;
597 Frequency = (
int[])this.frequency.Clone();
598 Hues = (
double[])this.reds.Clone();
599 Saturations = (
double[])this.greens.Clone();
600 Lights = (
double[])this.blues.Clone();
604 Frequency = this.frequency;
606 Saturations = this.greens;
610 int Width = this.width / this.superSampling;
611 int Height = this.height / this.superSampling;
612 int size = Width * Height * 4;
613 byte[] rgb =
new byte[size];
619 int rowStep = Width * this.superSampling;
620 int rowStep2 = rowStep - this.superSampling;
621 int srcYStep = rowStep * this.superSampling;
628 bool HasBg = Background.HasValue;
633 BgR = Background.Value.Red;
634 BgG = Background.Value.Green;
635 BgB = Background.Value.Blue;
641 foreach (
int F
in Frequency)
649 if (this.superSampling == 1)
651 for (y = srcY = 0; y < Height; y++, srcY += srcYStep)
653 for (x = 0, src = srcY; x < Width; x++, src++)
677 S = Math.Pow(Saturations[src], Gamma);
678 L = Math.Pow((Lights[src] * i) / maxfreq, Gamma) * LightFactor;
687 rgb[dst++] = cl.Blue;
688 rgb[dst++] = cl.Green;
697 for (y = srcY = 0; y < Height; y++, srcY += srcYStep)
699 for (x = 0, src = srcY; x < Width; x++, src += this.superSampling)
705 for (dy = 0; dy < this.superSampling; dy++)
707 for (dx = 0; dx < this.superSampling; dx++, si++)
713 S = Math.Pow(Saturations[si], Gamma);
714 L = Math.Pow((Lights[si] * j) / maxfreq, Gamma) * LightFactor;
765 rgb[dst++] = (byte)B2;
766 rgb[dst++] = (byte)G2;
767 rgb[dst++] = (byte)R2;
static SKColor ToColorHSL(double H, double S, double L)
Creates a Color from its HSL representation.
Base class for all nodes in a parsed script tree.