- moved all plugin-related classes to Eithne.Plugin namespace
[FaRetSys.git] / Plugins / SimpleDB / SimpleDB.cs
blob2ef374b118e6b0a99158a4719774e3cd650907d9
1 using System;
2 using System.Collections;
3 using System.Xml;
4 using Mono.Unix;
6 namespace Eithne
8 public class SimpleDBInfo : IInfo
10 public override string Name
12 get { return Catalog.GetString("Simple Image Database"); }
15 public override string ShortName
17 get { return "SimpleDB"; }
20 public override string Author
22 get { return "Bartosz Taudul"; }
25 public override string Description
27 get { return Catalog.GetString("This plugin allows to pass images to image recognition system."); }
31 public class SimpleDBFactory : IFactory
33 IInfo _info = new SimpleDBInfo();
34 public IInfo Info
36 get { return _info; }
39 public IType Type
41 get { return IType.In; }
44 public void Initialize()
48 public Plugin.Base Create()
50 return new SimpleDBPlugin();
54 public class SimpleDBPlugin : Plugin.In
56 private ArrayList _fl = new ArrayList();
57 private float progress;
59 public SimpleDBPlugin()
61 _info = new SimpleDBInfo();
64 public override XmlNode Config
66 get { return GetConfig(); }
67 set { LoadConfig(value); }
70 public override void Setup()
72 new SimpleDBSetup(_fl, _block);
75 public override void Work()
77 progress = 0;
79 if(_fl.Count == 0)
80 throw new PluginException(Catalog.GetString("No images in list"));
82 int i = 0;
83 IImage[] imgarray = new IImage[_fl.Count];
84 int[] categories = new int[_fl.Count];
86 foreach(string fn in _fl)
88 Gdk.Pixbuf buf = new Gdk.Pixbuf(fn);
90 imgarray[i] = IImage.Create(buf, Utility.IsBW(buf) ? BPP.Grayscale : BPP.RGB);
91 categories[i] = i;
93 i++;
95 progress = (float)i/_fl.Count;
98 _out = new CommSocket(1);
99 _out[0] = new ICommImage(imgarray, imgarray, categories);
101 _workdone = true;
104 private XmlNode GetConfig()
106 XmlNode root = _xmldoc.CreateNode(XmlNodeType.Element, "config", "");
108 foreach(string s in _fl)
110 XmlNode n = _xmldoc.CreateNode(XmlNodeType.Element, "image", "");
111 n.InnerText = s;
112 root.AppendChild(n);
115 return root;
118 private void LoadConfig(XmlNode root)
120 XmlNodeList nl = root.SelectNodes("image");
121 ArrayList errors = new ArrayList();
123 foreach(XmlNode n in nl)
127 new Gdk.Pixbuf(n.InnerText);
129 _fl.Add(n.InnerText);
131 catch(GLib.GException)
133 errors.Add(n.InnerText);
137 if(errors.Count != 0)
138 new LoadError(errors);
141 public override int NumOut { get { return 1; } }
143 public override string DescOut(int n)
145 return Catalog.GetString("Images.");
148 public override float Progress { get { return progress; } }
150 private static string[] matchout = new string[] { "image/rgb", "image/grayscale" };
151 public override string[] MatchOut { get { return matchout; } }