24 private Builder _builder;
26#pragma warning disable 649
28 private MenuItem setMin;
30 private MenuItem setMax;
32 private MenuItem setMinAll;
34 private MenuItem setMaxAll;
36 private DrawingArea view;
39#pragma warning restore 649
43 #region Constructors / Destructors
46 Builder builder =
new Builder(
new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) +
"/" +
"Glade/Histogram.glade", FileMode.Open));
47 return new HistogramControl(builder, builder.GetObject(
"histogram").Handle,channel);
49 protected HistogramControl(Builder builder, IntPtr handle, Channel channel) : base(handle)
52 this.channel = channel;
53 builder.Autoconnect(
this);
58 public Channel channel =
null;
62 if (
ImageView.SelectedImage.bitsPerPixel == 8)
69 graphMax = ushort.MaxValue;
72 this.Drawn += HistogramControl_Drawn;
75 this.ScrollEvent += HistogramControl_ScrollEvent;
76 this.DeleteEvent += HistogramControl_DeleteEvent;
77 setMin.ButtonPressEvent += SetMin_ButtonPressEvent;
78 setMax.ButtonPressEvent += SetMax_ButtonPressEvent;
79 setMinAll.ButtonPressEvent += SetMinAll_ButtonPressEvent;
80 setMaxAll.ButtonPressEvent += SetMaxAll_ButtonPressEvent;
82 (EventMask.ButtonPressMask
83 | EventMask.ButtonReleaseMask
84 | EventMask.KeyPressMask
85 | EventMask.PointerMotionMask | EventMask.ScrollMask));
95 private void HistogramControl_DeleteEvent(
object o, DeleteEventArgs args)
106 private void HistogramControl_ScrollEvent(
object o, ScrollEventArgs args)
108 if(args.Event.Direction == Gdk.ScrollDirection.Up)
112 else if (args.Event.Direction == Gdk.ScrollDirection.Down)
124 private void SetMaxAll_ButtonPressEvent(
object o, ButtonPressEventArgs args)
126 foreach (Channel c
in ImageView.SelectedImage.Channels)
128 for (
int i = 0; i < c.range.Length; i++)
130 c.range[i].Max = (int)MouseValX;
134 App.viewer.UpdateImage();
142 private void SetMinAll_ButtonPressEvent(
object o, ButtonPressEventArgs args)
144 foreach (Channel c
in ImageView.SelectedImage.Channels)
146 for (
int i = 0; i < c.range.Length; i++)
148 c.range[i].Min = (int)MouseValX;
152 App.viewer.UpdateImage();
161 private void SetMax_ButtonPressEvent(
object o, ButtonPressEventArgs args)
163 App.channelsTool.SelectedChannel.range[App.channelsTool.SelectedSample].Max = (int)MouseValX;
165 App.viewer.UpdateImage();
174 private void SetMin_ButtonPressEvent(
object o, ButtonPressEventArgs args)
176 App.channelsTool.SelectedChannel.range[App.channelsTool.SelectedSample].Min = (int)MouseValX;
178 App.viewer.UpdateImage();
187 mouseX = (int)args.Event.X;
188 mouseY = (int)args.Event.Y;
190 if(args.Event.Button == 3)
201 mouseValX = (float)args.Event.X / fx;
202 mouseValY = (float)args.Event.Y / fy;
205 public Cairo.Color ToCairoColor(Color c)
207 return new Cairo.Color((
double)c.R / 255.0, (
double)c.G / 255.0, (
double)c.B / 255.0, (
double)c.A / 255.0);
214 private void HistogramControl_Drawn(
object o, DrawnArgs args)
216 Cairo.Context g = args.Cr;
218 graphMax = ushort.MaxValue;
219 g.SetSourceColor(ToCairoColor(Color.LightGray));
224 fx = ((float)this.AllocatedWidth) / ((
float)graphMax);
227 for (
int cc = 0; cc < ImageView.SelectedImage.Channels.Count; cc++)
229 for (
int i = 0; i < ImageView.SelectedImage.Channels[cc].stats.Length; i++)
231 float f = ImageView.SelectedImage.Channels[cc].stats[i].StackMedian;
239 fy = ((float)this.AllocatedHeight) / maxmedian;
240 for (
int c = 0; c < ImageView.SelectedImage.Channels.Count; c++)
244 g.SetSourceColor(ToCairoColor(Color.Black));
246 g.LineTo(mouseX, this.AllocatedHeight);
250 Channel channel = ImageView.SelectedImage.Channels[c];
251 for (
int i = 0; i < channel.range.Length; i++)
254 if (ImageView.SelectedImage.RGBChannelCount == 1)
255 stat = channel.stats[0];
257 stat = channel.stats[i];
259 Cairo.Color black = ToCairoColor(Color.FromArgb(35, 0, 0, 0));
260 Cairo.Color blackd = ToCairoColor(Color.FromArgb(150, 0, 0, 0));
261 Cairo.Color pen =
new Cairo.Color();
262 Cairo.Color pend =
new Cairo.Color();
267 if (ImageView.SelectedImage.bitsPerPixel <= 8)
270 if (channel.Emission != 0)
272 Cairo.Color cc = ToCairoColor(SpectralColor(channel.Emission));
282 pen = ToCairoColor(Color.FromArgb(light, 255, 0, 0));
283 pend = ToCairoColor(Color.FromArgb(dark, 255, 0, 0));
287 pen = ToCairoColor(Color.FromArgb(light, 0, 255, 0));
288 pend = ToCairoColor(Color.FromArgb(dark, 0, 255, 0));
292 pen = ToCairoColor(Color.FromArgb(light, 0, 0, 255));
293 pend = ToCairoColor(Color.FromArgb(dark, 0, 0, 255));
301 PointF? prevs =
null;
303 float f = (float)(gmax - gmin) / (float)this.AllocatedWidth;
304 g.SetSourceColor(pen);
305 for (
float x = gmin; x < gmax; x+=f)
307 if (StackHistogram && c == ImageView.SelectedImage.Channels.Count - 1)
310 float val = (float)ImageView.SelectedImage.Statistics.StackValues[(
int)x];
314 float v = sumbin / binind;
315 float yy = this.AllocatedHeight - (fy * v);
318 g.SetSourceColor(blackd);
319 g.MoveTo(prevs.Value.X, prevs.Value.Y);
320 g.LineTo(fx * x, yy);
323 g.SetSourceColor(black);
324 g.MoveTo(fx * x, this.AllocatedHeight);
325 g.LineTo(fx * x, yy);
327 prevs =
new PointF(fx * x, yy);
333 float rv = stat.StackValues[(int)x];
337 g.SetSourceColor(pend);
338 g.MoveTo(fx * x, this.AllocatedHeight);
339 g.LineTo(fx * x, this.AllocatedHeight - (fy * (sumbins / bininds)));
343 g.MoveTo(prev.Value.X,prev.Value.Y);
344 g.LineTo(fx * x, this.AllocatedHeight - (fy * (sumbins / bininds)));
347 prev =
new PointF(fx * x, this.AllocatedHeight - (fy * (sumbins / bininds)));
355 g.SetSourceColor(ToCairoColor(SpectralColor(channel.Emission)));
356 g.MoveTo((fx * channel.range[i].Max), 0);
357 g.LineTo((fx * channel.range[i].Max),
this.AllocatedHeight);
359 g.MoveTo((fx * channel.range[i].Min), 0);
360 g.LineTo((fx * channel.range[i].Min),
this.AllocatedHeight);
369 g.SetSourceRGB(0, 0, 0);
374 for (
float x = 0; x < graphMax; x += 50)
376 TextExtents ex = g.TextExtents(x.ToString());
377 g.MoveTo((fx * x) - (ex.Width / 2), tick + 10);
378 g.ShowText(x.ToString());
380 g.MoveTo((fx * x), 0);
381 g.LineTo((fx * x), tick);
387 for (
float x = 0; x < graphMax; x += 2000)
389 g.MoveTo((fx * x), 0);
390 g.LineTo((fx * x), tick + 3);
393 for (
float x = 0; x < graphMax; x += 1000)
395 TextExtents ex = g.TextExtents(x.ToString());
396 g.MoveTo((fx * x) - (ex.Width / 2), tick + 10);
397 g.ShowText(x.ToString());
399 g.MoveTo((fx * x), 0);
400 g.LineTo((fx * x), tick);
405 if (graphMax <= 16383)
406 for (
float x = 0; x < graphMax; x += 100)
408 g.MoveTo((fx * x), 0);
409 g.LineTo((fx * x), tick);
414 for (
float x = 0; x < graphMax; x += 50)
416 g.MoveTo((fx * x), 0);
417 g.LineTo((fx * x), 4);
420 for (
float x = 0; x < graphMax; x += 10)
422 g.MoveTo((fx * x), 0);
423 g.LineTo((fx * x), 2);
429 if (ImageView.SelectedImage.RGBChannelCount == 3)
431 if (ImageView.SelectedImage.Channels.Count > 2)
434 "(" + (mouseX / fx).ToString() +
435 ",R:" + ImageView.SelectedImage.Channels[2].stats[2].StackValues[(int)(mouseX / fx)].ToString() +
436 ",G:" + ImageView.SelectedImage.Channels[1].stats[1].StackValues[(int)(mouseX / fx)].ToString() +
437 ",B:" + ImageView.SelectedImage.Channels[0].stats[0].StackValues[(int)(mouseX / fx)].ToString() +
")";
442 "(" + (mouseX / fx).ToString() +
443 ",R:" + ImageView.SelectedImage.Channels[0].stats[2].StackValues[(int)(mouseX / fx)].ToString() +
444 ",G:" + ImageView.SelectedImage.Channels[0].stats[1].StackValues[(int)(mouseX / fx)].ToString() +
445 ",B:" + ImageView.SelectedImage.Channels[0].stats[0].StackValues[(int)(mouseX / fx)].ToString() +
")";
450 int x = (int)(mouseX / fx);
451 if (ImageView.SelectedImage.bitsPerPixel < 8 && ImageView.SelectedImage.Channels[0].stats[0].StackValues.Length < 255)
452 st =
"(" + (mouseX / fx).ToString() +
"," + ImageView.SelectedImage.Channels[0].stats[0].StackValues[x].ToString() +
")";
455 g.MoveTo(mouseX, mouseY);
460 private float bin = 10;
479 channel.range[App.channelsTool.SelectedSample].Min = (int)value;
490 channel.range[App.channelsTool.SelectedSample].Max = (int)value;
494 private int graphMax = ushort.MaxValue;
497 get {
return graphMax; }
498 set { graphMax = value; }
500 private int graphMin = 0;
503 get {
return graphMin; }
504 set { graphMin = value; }
506 private bool stackHistogram =
true;
507 public bool StackHistogram
511 return stackHistogram;
515 stackHistogram = value;
518 private int mouseX = 0;
519 private int mouseY = 0;
534 private float mouseValX = 0;
535 private float mouseValY = 0;
536 public float MouseValX
543 public float MouseValY
551 private bool axisNumbers =
true;
552 public bool AxisNumbers
554 get {
return axisNumbers;}
555 set { axisNumbers = value; }
558 private bool axisTicks =
true;
559 public bool AxisTicks
561 get {
return axisTicks; }
562 set { axisTicks = value; }
565 private float fx = 0;
566 private float fy = 0;
567 private AForge.Bitmap bm;
589 Color SpectralColor(
double l)
595 if ((l >= 400.0) && (l < 410.0)) { t = (l - 400.0) / (410.0 - 400.0); r = +(0.33 * t) - (0.20 * t * t); }
596 else if ((l >= 410.0) && (l < 475.0)) { t = (l - 410.0) / (475.0 - 410.0); r = 0.14 - (0.13 * t * t); }
597 else if ((l >= 545.0) && (l < 595.0)) { t = (l - 545.0) / (595.0 - 545.0); r = +(1.98 * t) - (t * t); }
598 else if ((l >= 595.0) && (l < 650.0)) { t = (l - 595.0) / (650.0 - 595.0); r = 0.98 + (0.06 * t) - (0.40 * t * t); }
599 else if ((l >= 650.0) && (l < 700.0)) { t = (l - 650.0) / (700.0 - 650.0); r = 0.65 - (0.84 * t) + (0.20 * t * t); }
600 if ((l >= 415.0) && (l < 475.0)) { t = (l - 415.0) / (475.0 - 415.0); g = +(0.80 * t * t); }
601 else if ((l >= 475.0) && (l < 590.0)) { t = (l - 475.0) / (590.0 - 475.0); g = 0.8 + (0.76 * t) - (0.80 * t * t); }
602 else if ((l >= 585.0) && (l < 639.0)) { t = (l - 585.0) / (639.0 - 585.0); g = 0.84 - (0.84 * t); }
603 if ((l >= 400.0) && (l < 475.0)) { t = (l - 400.0) / (475.0 - 400.0); b = +(2.20 * t) - (1.50 * t * t); }
604 else if ((l >= 475.0) && (l < 560.0)) { t = (l - 475.0) / (560.0 - 475.0); b = 0.7 - (t) + (0.30 * t * t); }
608 return Color.FromArgb(255, (
int)r, (
int)g, (
int)b);