- moved all plugin-related classes to Eithne.Plugin namespace
[FaRetSys.git] / Plugins / ImageView / ImageView.cs
blob7cd82acc9cdf0d6e808251bac55ad1406325de67
1 using System;
2 using System.Xml;
3 using Mono.Unix;
5 namespace Eithne
7 public class ImageViewInfo : IInfo
9 public override string Name
11 get { return Catalog.GetString("Image View"); }
14 public override string ShortName
16 get { return "ImgView"; }
19 public override string Author
21 get { return "Bartosz Taudul"; }
24 public override string Description
26 get { return Catalog.GetString("This plugin displays images it receives on input."); }
30 public class ImageViewFactory : IFactory
32 IInfo _info = new ImageViewInfo();
33 public IInfo Info
35 get { return _info; }
38 public IType Type
40 get { return IType.Out; }
43 public void Initialize()
47 public Plugin.Base Create()
49 return new ImageViewPlugin();
53 public class ImageViewPlugin : Plugin.Out
55 Gdk.Pixbuf[] images = null;
56 Gdk.Pixbuf[] thumbs = null;
57 int[] cat = null;
58 bool invert = false;
60 public ImageViewPlugin()
62 _info = new ImageViewInfo();
65 public override XmlNode Config
67 get { return GetConfig(); }
68 set { LoadConfig(value); }
71 private void UpdateValue(bool invert)
73 this.invert = invert;
75 _block.Invalidate();
78 public override void Setup()
80 new ImageSetup(invert, UpdateValue);
83 public override bool HasSetup
85 get { return true; }
88 public override void DisplayResults()
90 if(!_workdone)
91 throw new PluginException(Catalog.GetString("Plugin is not ready to display images."));
93 new ImageViewWindow(images, thumbs, cat);
96 public override void Work()
98 ICommImage socket = (ICommImage)_in[0];
99 IImage[] img = socket.Images;
101 images = new Gdk.Pixbuf[img.Length];
102 thumbs = new Gdk.Pixbuf[img.Length];
103 cat = socket.Categories;
105 double scale;
107 for(int i=0; i<img.Length; i++)
109 IImage _img = new IImage(img[i].BPP, img[i].W, img[i].H, img[i].Data, invert);
110 if(invert)
111 _img.Invert();
113 images[i] = _img.CreatePixbuf();
115 if(_img.W > _img.H)
116 scale = _img.W / 64.0;
117 else
118 scale = _img.H / 64.0;
120 thumbs[i] = images[i].ScaleSimple(Scale(_img.W, scale), Scale(_img.H, scale), Gdk.InterpType.Bilinear);
123 _workdone = true;
126 private int Scale(int s, double scale)
128 int val = (int)(s/scale);
130 if(val == 0)
131 return 1;
132 else
133 return val;
136 private XmlNode GetConfig()
138 XmlNode root = _xmldoc.CreateNode(XmlNodeType.Element, "config", "");
140 if(invert)
141 root.InnerText = "true";
142 else
143 root.InnerText = "false";
145 return root;
148 private void LoadConfig(XmlNode root)
150 if(root.InnerText == "true")
151 UpdateValue(true);
152 else
153 UpdateValue(false);
156 public override int NumIn { get { return 1; } }
158 public override string DescIn(int n)
160 return Catalog.GetString("Images to be viewed.");
163 private static string[] matchin = new string[] { "image" };
164 public override string[] MatchIn { get { return matchin; } }