7 public class PluginException
: Exception
9 public PluginException(string msg
) : base(msg
)
15 public static string Version
17 get { return "0.4.0"; }
31 public interface IBlock
37 public abstract class IInfo
39 public abstract string Name { get; }
40 public abstract string ShortName { get; }
41 public abstract string Author { get; }
42 public abstract string Description { get; }
44 public virtual string Version
46 get { return Program.Version; }
50 public interface IFactory
55 void Initialize(); // TODO: remove?
59 public abstract class IPlugin
61 protected IInfo _info
;
62 private object _source
;
63 protected XmlDocument _xmldoc
;
64 protected bool _workdone
= false;
65 protected IBlock _block
= null;
66 protected CommSocket _in
= null, _out
= null;
68 public virtual IInfo Info { get { return _info; }
}
69 public XmlDocument XmlDoc { set { _xmldoc = value; }
}
73 get { return _source; }
74 set { _source = value; }
77 public virtual XmlNode Config
83 public virtual bool WorkDone
85 get { return _workdone; }
86 set { _workdone = value; }
91 set { _block = value; }
94 public abstract void Setup();
95 public abstract void Work();
97 public virtual void Invalidate()
103 protected void ClearInput()
107 for(int i
=0; i
<_in
.Length
; i
++)
113 protected void ClearOutput()
117 for(int i
=0; i
<_out
.Length
; i
++)
123 public virtual bool HasSetup
128 public abstract int NumIn { get; }
129 public abstract int NumOut { get; }
136 public CommSocket Out
141 public abstract string DescIn(int n
);
142 public abstract string DescOut(int n
);
144 public abstract string[] MatchIn { get; }
145 public abstract string[] MatchOut { get; }
148 public abstract class IInPlugin
: IPlugin
150 public override int NumIn { get { return 0; }
}
151 public override string DescIn(int n
) { return null; }
152 public override string[] MatchIn { get {return null; }
}
155 public abstract class IOutPlugin
: IPlugin
157 public override void Setup()
160 public override bool HasSetup
162 get { return false; }
165 public abstract void DisplayResults();
167 public override int NumOut { get { return 0; }
}
168 public override string DescOut(int n
) { return null; }
169 public override string[] MatchOut { get { return null; }
}
172 public abstract class IImgProcPlugin
: IPlugin
175 public abstract class IResProcPlugin
: IPlugin
178 public abstract class IComparatorPlugin
: IPlugin
181 public abstract class IOtherPlugin
: IPlugin
184 public class CommSocket
186 private ICommObject
[] obj
;
188 public CommSocket(int n
)
190 obj
= new ICommObject
[n
];
193 public ICommObject
this [int n
]
195 get { return obj[n]; }
196 set { obj[n] = value; }
201 get { return obj.Length; }
205 public interface ICommObject
214 public IImage(int bpp
, int w
, int h
, byte[] data
)
216 RecreateImage(bpp
, w
, h
, data
, false);
219 public IImage(int bpp
, int w
, int h
, byte[] data
, bool copy
)
221 RecreateImage(bpp
, w
, h
, data
, copy
);
224 private void RecreateImage(int bpp
, int w
, int h
, byte[] data
, bool copy
)
226 if(bpp
!= 1 && bpp
!= 3 && bpp
!= 4)
227 throw new Exception(Catalog
.GetString("BPP must be 1, 3 or 4"));
235 this.data
= new byte[w
* h
* bpp
];
236 for(int i
=0; i
<w
*h
*bpp
; i
++)
237 this.data
[i
] = data
[i
];
243 public IImage(int bpp
, int w
, int h
)
245 if(bpp
!= 1 && bpp
!= 3 && bpp
!= 4)
246 throw new Exception(Catalog
.GetString("BPP must be 1, 3 or 4"));
252 data
= new byte[w
* h
* bpp
];
258 for(int x
=0; x
<w
; x
++)
259 for(int y
=0; y
<h
; y
++)
260 PutPixel(x
, y
, (byte)(255 - (byte)GetPixel(x
, y
)));
262 for(int x
=0; x
<w
; x
++)
263 for(int y
=0; y
<h
; y
++)
265 int c
= (int)GetPixel(x
, y
);
267 byte r
= (byte)((c
& 0xFF0000) >> 16);
268 byte g
= (byte)((c
& 0x00FF00) >> 8);
269 byte b
= (byte)(c
& 0x0000FF);
275 PutPixel(x
, y
, (r
<< 16) + (g
<< 8) + b
);
278 throw new Exception(Catalog
.GetString("Image inversion not supported for floating point data"));
281 // zwracamy object, bo nie wiadomo czy będzie bajt, czy int, czy float, ale wewnątrz wszystko
282 // jest jako int traktowane
283 public object this [int x
, int y
]
285 get { return GetPixel(x, y); }
286 set { PutPixel(x, y, value); }
309 private unsafe object GetPixel(int x
, int y
)
312 return data
[x
+ w
*y
];
314 return (data
[(x
+ w
*y
)*3] << 16) + (data
[(x
+ w
*y
)*3 + 1] << 8) + data
[(x
+ w
*y
)*3 + 2];
316 fixed(byte *ptr
= data
)
318 return *(((float*)ptr
) + x
+ w
*y
);
322 private unsafe void PutPixel(int x
, int y
, object val
)
325 data
[x
+ w
*y
] = (byte)val
;
328 data
[(x
+ w
*y
)*3] = (byte)(((int)val
& 0xFF0000) >> 16);
329 data
[(x
+ w
*y
)*3 + 1] = (byte)(((int)val
& 0x00FF00) >> 8);
330 data
[(x
+ w
*y
)*3 + 2] = (byte)((int)val
& 0x0000FF);
333 fixed(byte *ptr
= data
)
335 *(((float*)ptr
) + x
+ w
*y
) = (float)val
;
340 public class ICommImage
: ICommObject
342 private readonly IImage
[] images
;
343 private readonly IImage
[] orig
;
344 private readonly int[] categories
;
346 public ICommImage(IImage
[] images
, IImage
[] orig
, int[] categories
)
348 this.images
= images
;
350 this.categories
= categories
;
353 public IImage
this [int n
]
355 get { return images[n]; }
356 set { images[n] = value; }
361 get { return images.Length; }
364 public IImage
[] Images
366 get { return images; }
369 public IImage
[] OriginalImages
374 public IImage
OriginalImage(int n
)
379 public int[] Categories
381 get { return categories; }
384 public int Category(int n
)
386 return categories
[n
];
392 private readonly double[] data
;
394 public IResult(double[] data
)
399 public double this [int i
]
401 get { return data[i]; }
406 get { return data.Length; }
415 public class ICommResult
: ICommObject
417 private readonly double identity
;
418 private readonly IImage
[] origbase
;
419 private readonly IImage
[] origtest
;
420 private readonly IResult
[] res
;
421 private readonly int[] catbase
;
422 private readonly int[] cattest
;
423 private readonly bool[] match
;
425 public ICommResult(IResult
[] res
, double identity
, IImage
[] origbase
, IImage
[] origtest
, int[] catbase
, int[] cattest
)
427 this.identity
= identity
;
429 this.origbase
= origbase
;
430 this.origtest
= origtest
;
431 this.catbase
= catbase
;
432 this.cattest
= cattest
;
434 match
= new bool[res
.Length
];
436 for(int i
=0; i
<res
.Length
; i
++)
440 public ICommResult(IResult
[] res
, double identity
, IImage
[] origbase
, IImage
[] origtest
, int[] catbase
, int[] cattest
,
443 this.identity
= identity
;
445 this.origbase
= origbase
;
446 this.origtest
= origtest
;
447 this.catbase
= catbase
;
448 this.cattest
= cattest
;
452 public double this [int itest
, int ibase
]
454 get { return res[itest][ibase]; }
457 public IResult
this [int n
]
459 get { return res[n]; }
464 get { return res.Length; }
467 public double Identity
469 get { return identity; }
472 public IImage
[] OriginalBaseImages
474 get { return origbase; }
477 public IImage
[] OriginalTestImages
479 get { return origtest; }
482 public int[] TestCategories
484 get { return cattest; }
487 public int[] BaseCategories
489 get { return catbase; }
494 get { return match; }
497 public int TestCategory(int n
)
502 public int BaseCategory(int n
)
507 public double Difference(int itest
, int ibase
)
509 return Math
.Abs(identity
- this[itest
, ibase
]);