Skip to content

Commit

Permalink
Blurbox - Settings now in webUI
Browse files Browse the repository at this point in the history
Added tag engine (hit 'e' to view title/author
Added tag filtering engine
Added tag filtering to webview
Some stability fixes
  • Loading branch information
Geektoolkit committed May 26, 2021
1 parent 5956915 commit 9cb00d0
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 62 deletions.
28 changes: 27 additions & 1 deletion AppSettings.cs
Expand Up @@ -56,6 +56,13 @@ private AppSettings()
DynaframeIP = Helpers.GetIP(); // Dynaframe IP Address
SlideShowPaused = false; // Pause Slideshow on / off
EnableLogging = true; // Enables logging...should be set to false by default at some point.

// Tag settings
InclusiveTagFilters = ""; // Semicolon delimited list of images to include. Blank string means 'all'
// Blurbox Settings
BlurBoxSigmaX = 10; // See BlurboxImage.axaml.cs for usage
BlurBoxSigmaY = 10; // Used in line: blurPaint.ImageFilter = SKImageFilter.CreateBlur(50, 50);
BlurBoxMargin = -500; // Set to negative to scale the background image
}

private static string _jsonSource;
Expand Down Expand Up @@ -144,7 +151,7 @@ public void Save()
/// </summary>
public int InfoBarFontSize { get; set; }

public enum InfoBar { Clock, FileInfo, DateTime, Error, IP, OFF, InitialIP }
public enum InfoBar { Clock, FileInfo, DateTime, Error, IP, OFF, InitialIP, ExifData }
public InfoBar InfoBarState { get; set; }

/// <summary>
Expand Down Expand Up @@ -245,10 +252,29 @@ public enum InfoBar { Clock, FileInfo, DateTime, Error, IP, OFF, InitialIP }
/// </summary>
public string IgnoreFolders { get; set; }

public string InclusiveTagFilters { get; set; }

/// <summary>
/// Allows the enabling or disabling of logging. Defaulting to disabled, this can be turned on
/// to help troubleshoot issues.
/// </summary>
public bool EnableLogging { get; set; }

// BLURBOX Settings

/// <summary>
/// SigmaX amount of blur applied for an SKPaint blur effect
/// </summary>
public float BlurBoxSigmaX { get; set; }

/// <summary>
/// SigmaY amount of blur applied for an SKPaint blur effect
/// </summary>
public float BlurBoxSigmaY { get; set; }

/// <summary>
/// The margin the blurbox should use when displayed. Setting this to negative can scale the background to hide text/edges.
/// </summary>
public double BlurBoxMargin { get; set; }
}
}
1 change: 1 addition & 0 deletions Dynaframe3.csproj
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<AssemblyName>Dynaframe</AssemblyName>
<Version>2.21</Version>
<Authors>Joe Farro</Authors>
Expand Down
8 changes: 0 additions & 8 deletions FancyImageControl.axaml

This file was deleted.

19 changes: 0 additions & 19 deletions FancyImageControl.axaml.cs

This file was deleted.

39 changes: 39 additions & 0 deletions Helpers.cs
Expand Up @@ -166,6 +166,45 @@ public static int SetIntAppSetting(string querystring, string property)
}
return 0;
}
/// <summary>
/// Parses out a value as an int and sets it based on the query string.
/// </summary>
/// <param name="querystring"></param>
/// <param name="property"></param>
/// <returns>0 if a value was not found, 1 if a value was set</returns>
public static int SetFloatAppSetting(string querystring, string property)
{
if (querystring != null)
{
float i = 0;
if (float.TryParse(querystring, out i))
{
typeof(AppSettings).GetProperty(property).SetValue(AppSettings.Default, i);
}
return 1;
}
return 0;
}
/// <summary>
/// Parses out a value as an int and sets it based on the query string.
/// </summary>
/// <param name="querystring"></param>
/// <param name="property"></param>
/// <returns>0 if a value was not found, 1 if a value was set</returns>
public static int SetDoubleAppSetting(string querystring, string property)
{
if (querystring != null)
{
double i = 0;
if (double.TryParse(querystring, out i))
{
typeof(AppSettings).GetProperty(property).SetValue(AppSettings.Default, i);
}
return 1;
}
return 0;
}


/// <summary>
/// Takes in a string value and returns a 0/1 based on if a setting was found
Expand Down
2 changes: 1 addition & 1 deletion ImagePresenters/BlurBoxImage.axaml
Expand Up @@ -5,7 +5,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Dynaframe3.ImagePresenters.BlurBoxImage" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<Grid>
<Image Name="backgroundImage" Stretch="Fill"/>
<Image Name="backgroundImage" Stretch="Fill" />
<Image Name="foregroundImage" />
</Grid>
</UserControl>
16 changes: 8 additions & 8 deletions ImagePresenters/BlurBoxImage.axaml.cs
Expand Up @@ -28,7 +28,7 @@ public partial class BlurBoxImage : UserControl
public string ImageString { get; set; }
public BlurBoxImage()
{
ClipToBounds = true;
ClipToBounds = false;
InitializeComponent();
ImageString = "";
backgroundImage = this.FindControl<Image>("backgroundImage");
Expand All @@ -37,8 +37,11 @@ public BlurBoxImage()
// Frontloading some allocations
blurInfo = new SKImageInfo(640, 480);
blurredbitmap = new SKBitmap(blurInfo);

blurPaint = new SKPaint();
blurPaint.ImageFilter = SKImageFilter.CreateBlur(20, 20);
blurPaint.ImageFilter = SKImageFilter.CreateBlur(AppSettings.Default.BlurBoxSigmaX, AppSettings.Default.BlurBoxSigmaY);

backgroundImage.Margin = new Thickness(AppSettings.Default.BlurBoxMargin);
}

/// <summary>
Expand Down Expand Up @@ -67,6 +70,8 @@ public void UpdateImage()
public void UpdateImage(string newImagePath)
{
ImageString = newImagePath;
backgroundImage.Margin = new Thickness(AppSettings.Default.BlurBoxMargin);
blurPaint.ImageFilter = SKImageFilter.CreateBlur(AppSettings.Default.BlurBoxSigmaX, AppSettings.Default.BlurBoxSigmaY);
ShowBitmapWithBlurbox();
}

Expand All @@ -77,23 +82,18 @@ private void ShowBitmapWithBlurbox()
bitmap.ScalePixels(blurredbitmap, SKFilterQuality.Medium);

SKCanvas canvas = new SKCanvas(blurredbitmap);
canvas.DrawBitmap(blurredbitmap, new SKPoint(0, 0), blurPaint);
canvas.DrawBitmap(blurredbitmap, new SKPoint(0,0), blurPaint);

SKData data = SKImage.FromBitmap(blurredbitmap).Encode(SKEncodedImageFormat.Jpeg, 100);

bitmapData = new Bitmap(data.AsStream());
backgroundImage.Source = null;
foregroundImage.Source = null;

backgroundImage.Source = bitmapData;
foregroundImage.Source = new Bitmap(ImageString);

bitmap.Dispose();
//blurredbitmap.Dispose();
canvas.Dispose();
//blurPaint.Dispose();
data.Dispose();

}
}
}
25 changes: 25 additions & 0 deletions MainWindow.axaml.cs
Expand Up @@ -176,6 +176,13 @@ public void GoToFirstImage()
tb.Transitions.Clear();
playListEngine.GetPlayListItems();
AppSettings.Default.RefreshDirctories = false;
Logger.LogComment("Going to sleep while loading playlist...");
while (playListEngine.PlaylistState == PlayListEngine.PlaylistStates.Loading)
{
Thread.Sleep(100);
}
Logger.LogComment("Waking up and continuing playing files..");

PlayImageFile(500, playListEngine.CurrentPlayListItem.Path);
lastUpdated = DateTime.Now;
tb.Transitions.Add(fadeTransition);
Expand Down Expand Up @@ -235,6 +242,10 @@ private void MainWindow_KeyDown(object sender, Avalonia.Input.KeyEventArgs e)
{
AppSettings.Default.InfoBarState = AppSettings.InfoBar.IP;
}
if (e.Key == Avalonia.Input.Key.E)
{
AppSettings.Default.InfoBarState = AppSettings.InfoBar.ExifData;
}
if (e.Key == Avalonia.Input.Key.C)
{
AppSettings.Default.InfoBarState = AppSettings.InfoBar.DateTime;
Expand Down Expand Up @@ -312,6 +323,14 @@ private void Timer_Tick(object sender, EventArgs e)
//
AppSettings.Default.RefreshDirctories = false;
playListEngine.GetPlayListItems();

Logger.LogComment("Going to sleep while loading playlist...");
while (playListEngine.PlaylistState == PlayListEngine.PlaylistStates.Loading)
{
Thread.Sleep(100);
}
Logger.LogComment("Waking up and continuing playing files..");

Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
{
Logger.LogComment("Timer_Tick: GetFiles is called. Should update next image...");
Expand Down Expand Up @@ -464,6 +483,12 @@ private void UpdateInfoBar()
tb.Opacity = 0;
break;
}
case (AppSettings.InfoBar.ExifData):
{
tb.Opacity = 1;
tb.Text = playListEngine.CurrentPlayListItem.Title + "\r\n" + playListEngine.CurrentPlayListItem.Artist;
break;
}
default:
{
tb.Text = "";
Expand Down
81 changes: 68 additions & 13 deletions PlayListEngine.cs
@@ -1,5 +1,7 @@
using MetadataExtractor;
using MetadataExtractor.Formats.Exif;
using MetadataExtractor.Formats.Iptc;
using MetadataExtractor.Formats.Xmp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -26,6 +28,9 @@ class PlayListEngine
public List<PlayListItem> CurrentPlayListItems { get; set; }
//List<PlayListItem> playListItems;

public enum PlaylistStates { Loading, Loaded }
public PlaylistStates PlaylistState = PlaylistStates.Loaded;

public PlayListEngine()
{
CurrentPlayListItems = new List<PlayListItem>();
Expand Down Expand Up @@ -101,14 +106,57 @@ public void GetPlayListItems()
// - goes through a passed in folder list
// - adds files from each folder to the temp playlist
// - adds the temp playlist to the main playlist called "CurrentplaylistItems"

PlaylistState = PlaylistStates.Loading;
Logger.LogComment("GetPlayListItems: Clearing item list..");
CurrentPlayListItems.Clear();

Logger.LogComment("GetPlayListItems: Getting playlist Items...");
GetPlayListItems(AppSettings.Default.CurrentPlayList, SearchOption.AllDirectories);
GetPlayListItems(AppSettings.Default.SearchDirectories, SearchOption.TopDirectoryOnly);
GetPlayListItems(AppSettings.Default.CurrentPlayList, SearchOption.AllDirectories); // This gets images in subfolders
GetPlayListItems(AppSettings.Default.SearchDirectories, SearchOption.TopDirectoryOnly); // This gets the images in the 'root' folder. TODO: Make optional.

List<PlayListItem> filteredList = new List<PlayListItem>();
// Filter playlist items based on tags
for (int i = 0; i < CurrentPlayListItems.Count; i++)
{
IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(CurrentPlayListItems[i].Path);
MetadataExtractor.Directory? dir = directories.Where(d => d.Name == "Exif IFD0").FirstOrDefault();
if (dir != null)
{
CurrentPlayListItems[i].Title = GetTagByName("Windows XP Title", dir);
CurrentPlayListItems[i].Artist = GetTagByName("Windows XP Author", dir);
CurrentPlayListItems[i].Comment = GetTagByName("Windows XP Comment", dir);
CurrentPlayListItems[i].Software = GetTagByName("Software", dir);
CurrentPlayListItems[i].Keywords = GetTagByName("Windows XP Keywords", dir);
}

if (AppSettings.Default.InclusiveTagFilters != "")
{
// Filters enabled...start filtering!
string[] filters = AppSettings.Default.InclusiveTagFilters.Split(';');
foreach (string filter in filters)
{
if ((CurrentPlayListItems[i].Keywords != null) && (CurrentPlayListItems[i].Keywords.Contains(filter)))
{
if (!filteredList.Contains(CurrentPlayListItems[i]))
{
filteredList.Add(CurrentPlayListItems[i]);
}
}
}
}
}

if (AppSettings.Default.InclusiveTagFilters != "")
{
Logger.LogComment("List filtered to tags: " + AppSettings.Default.InclusiveTagFilters);
Logger.LogComment("Original List: " + CurrentPlayListItems.Count);
Logger.LogComment("Filtered List: " + filteredList.Count);
CurrentPlayListItems.Clear();
CurrentPlayListItems = filteredList;
}


// List filtered, now sort it.
if (AppSettings.Default.Shuffle)
{
Random r = new Random((int)DateTime.Now.Ticks);
Expand Down Expand Up @@ -136,16 +184,14 @@ public void GetPlayListItems()
for (int i = 0; i < CurrentPlayListItems.Count; i++)
{
Logger.LogComment(CurrentPlayListItems[i].ItemType + ":" + CurrentPlayListItems[i].Path);
if (CurrentPlayListItem.ItemType == PlayListItemType.Image)
if (CurrentPlayListItems[i].ItemType == PlayListItemType.Image)
{
IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(CurrentPlayListItem.Path);
var subIfdDirectory = directories.OfType<ExifSubIfdDirectory>().FirstOrDefault();
var dateTime = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagDateTimeOriginal);
if (dateTime != null)
{
Logger.LogComment("Datetime: Datetime: " + dateTime);
}

Logger.LogComment("--------Tag dump-------------");
Logger.LogComment("Title: " + CurrentPlayListItems[i].Title);
Logger.LogComment("Artist: " + CurrentPlayListItems[i].Artist);
Logger.LogComment("Comment: " + CurrentPlayListItems[i].Comment);
Logger.LogComment("Keywords: " + CurrentPlayListItems[i].Keywords);
Logger.LogComment("--------END END-------------");
}
}
}
Expand All @@ -157,9 +203,18 @@ public void GetPlayListItems()
sw.Stop();

Logger.LogComment("------------------- END PLAYLIST DUMP Took: " + sw.ElapsedMilliseconds + " ms. -----------------");

PlaylistState = PlaylistStates.Loaded;
}

public string GetTagByName(string tagName, MetadataExtractor.Directory dir)
{
Tag?val = dir.Tags.Where(t => t.Name == tagName).FirstOrDefault();
if (val != null)
{
return val.Description;
}
return "";
}
/// <summary>
/// Goes to Next Playlist Item. Will rebuild Playlist if nothing is found.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions PlayListItem.cs
Expand Up @@ -9,6 +9,13 @@ public class PlayListItem : IEquatable<PlayListItem>
{
public string Path { get; set; }
public PlayListItemType ItemType { get; set; }
public string Title { get; set; }
public string Keywords { get; set; }
public string Software { get; set; }
public string Artist { get; set; }
public string Comment { get; set; }



/// <summary>
/// Returns true if the path and itemtime are equal
Expand Down

0 comments on commit 9cb00d0

Please sign in to comment.