DirectOutputR1
DirectOutput framework R1 for virtual pinball cabinets.
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
RGBALayerDictionary.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using DirectOutput.Cab.Color;
6 
7 namespace DirectOutput.Cab.Toys.Layer
8 {
12  public class RGBALayerDictionary : SortedDictionary<int, RGBALayer>
13  {
23  public new RGBALayer this[int LayerNr]
24  {
25  get
26  {
27  try
28  {
29  return base[LayerNr];
30  }
31  catch
32  {
33  RGBALayer L = new RGBALayer();
34  Add(LayerNr, L);
35  return L;
36  }
37  }
38  set
39  {
40  base[LayerNr] = value;
41  }
42  }
43 
44 
49  public RGBColor GetResultingColor()
50  {
51  if (Count > 0)
52  {
53  float Red = 0;
54  float Green = 0;
55  float Blue = 0;
56  foreach (KeyValuePair<int, RGBALayer> KV in this)
57  {
58  int Alpha = KV.Value.Alpha;
59  if (Alpha != 0)
60  {
61  int NegAlpha = 255 - Alpha;
62  Red = AlphaMappingTable.AlphaMapping[NegAlpha, (int)Red] + AlphaMappingTable.AlphaMapping[Alpha, KV.Value.Red];
63  Green = AlphaMappingTable.AlphaMapping[NegAlpha, (int)Green] + AlphaMappingTable.AlphaMapping[Alpha, KV.Value.Green];
64  Blue = AlphaMappingTable.AlphaMapping[NegAlpha, (int)Blue] + AlphaMappingTable.AlphaMapping[Alpha, KV.Value.Blue];
65  }
66  }
67 
68  return new RGBColor((int)Red, (int)Green, (int)Blue);
69  }
70  else
71  {
72  return new RGBColor(0, 0, 0);
73  }
74  }
75  }
76 }