DirectOuput Framework R2
DirectOutput framework R2 for virtual pinball cabinets
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
MatrixBitmapEffectBase.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.General;
6 
7 using DirectOutput.General.BitmapHandling;
8 using System.IO;
9 
10 namespace DirectOutput.FX.MatrixFX
11 {
15  public abstract class MatrixBitmapEffectBase<MatrixElementType> : MatrixEffectBase<MatrixElementType>
16  {
17 
18  private int _BitmapFrameNumber = 0;
19 
26  public int BitmapFrameNumber
27  {
28  get { return _BitmapFrameNumber; }
29  set { _BitmapFrameNumber = value; }
30  }
31 
32  private int _BitmapTop = 0;
33 
40  public int BitmapTop
41  {
42  get { return _BitmapTop; }
43  set { _BitmapTop = value; }
44  }
45 
46  private int _BitmapLeft = 0;
47 
54  public int BitmapLeft
55  {
56  get { return _BitmapLeft; }
57  set { _BitmapLeft = value; }
58  }
59 
60  private int _BitmapWidth = -1;
61 
68  public int BitmapWidth
69  {
70  get { return _BitmapWidth; }
71  set { _BitmapWidth = value; }
72  }
73 
74  private int _BitmapHeight = -1;
75 
82  public int BitmapHeight
83  {
84  get { return _BitmapHeight; }
85  set { _BitmapHeight = value; }
86  }
87 
88 
89  private FastBitmapDataExtractModeEnum _DataExtractMode = FastBitmapDataExtractModeEnum.BlendPixels;
90 
97  public FastBitmapDataExtractModeEnum DataExtractMode
98  {
99  get { return _DataExtractMode; }
100  set { _DataExtractMode = value; }
101  }
102 
103 
104  private FilePattern _BitmapFilePattern;
105 
112  public FilePattern BitmapFilePattern
113  {
114  get { return _BitmapFilePattern; }
115  set { _BitmapFilePattern = value; }
116  }
117 
118  private PixelData[,] Pixels;
119 
120  private void OutputBitmap(int FadeValue)
121  {
122  if (FadeMode == FadeModeEnum.OnOff) FadeValue = (FadeValue < 1 ? 0 : 255);
123 
124 
125  for (int y = 0; y < AreaHeight; y++)
126  {
127  int yd = y + AreaTop;
128  for (int x = 0; x < AreaWidth; x++)
129  {
130  int xd = x + AreaLeft;
131  MatrixLayer[xd, yd] = GetEffectValue(FadeValue, Pixels[x, y]);
132  }
133  }
134 
135 
136  }
137 
145  public abstract MatrixElementType GetEffectValue(int TriggerValue, PixelData Pixel);
146 
151  public override void Trigger(Table.TableElementData TableElementData)
152  {
153  if (InitOK)
154  {
155  OutputBitmap(TableElementData.Value);
156  }
157 
158  }
159 
160  private bool InitOK = false;
161 
162 
168  public override void Init(Table.Table Table)
169  {
170  InitOK = false;
171  Pixels = null;
172  base.Init(Table);
173 
174  //TODO: Insert replace values for file pattern
175  if (BitmapFilePattern.IsValid)
176  {
177  FileInfo FI = BitmapFilePattern.GetFirstMatchingFile();
178  if (FI!=null && FI.Exists)
179  {
180  FastImage BM;
181  try
182  {
183  BM = Table.Bitmaps[FI.FullName];
184  }
185  catch (Exception E)
186  {
187  Log.Exception("MatrixBitmapEffectBase {0} cant initialize. Could not load file {1}.".Build(Name, FI.FullName), E);
188  return;
189  }
190 
191  if (BM.Frames.ContainsKey(BitmapFrameNumber))
192  {
193  Pixels = BM.Frames[BitmapFrameNumber].GetClip(AreaWidth, AreaHeight, BitmapLeft, BitmapTop, BitmapWidth, BitmapHeight, DataExtractMode).Pixels;
194 
195  }
196  else
197  {
198  Log.Warning("MatrixBitmapEffectBase {0} cant initialize. Frame {1} does not exist in source image {2}.".Build(Name, BitmapFrameNumber, FI.FullName));
199 
200  }
201  }
202  else
203  {
204  Log.Warning("MatrixBitmapEffectBase {0} cant initialize. No file matches the BitmapFilePattern {1} is invalid".Build(Name, BitmapFilePattern.ToString()));
205  }
206  }
207  else
208  {
209  Log.Warning("MatrixBitmapEffectBase {0} cant initialize. The BitmapFilePattern {1} is invalid".Build(Name, BitmapFilePattern.ToString()));
210  }
211 
212 
213  InitOK = (Pixels != null && MatrixLayer != null);
214 
215  }
216 
220  public override void Finish()
221  {
222  Pixels = null;
223  base.Finish();
224  }
225  }
226 }