Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Commit 41fdead

Browse files
committed
Initial Commit
1 parent cb6730c commit 41fdead

15 files changed

+1362
-0
lines changed

.gitattributes

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.489
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "winforms-image-processor", "winforms-image-processor\winforms-image-processor.csproj", "{11F06003-A488-40FF-BF13-FF7114F9D866}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{11F06003-A488-40FF-BF13-FF7114F9D866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{11F06003-A488-40FF-BF13-FF7114F9D866}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{11F06003-A488-40FF-BF13-FF7114F9D866}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{11F06003-A488-40FF-BF13-FF7114F9D866}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {69161561-A82C-416A-A3D0-9CBAAE32F87D}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
5+
</startup>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Runtime.Serialization;
7+
using System.Runtime.Serialization.Formatters.Binary;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using System.Windows.Forms;
11+
12+
namespace winforms_image_processor
13+
{
14+
/// <summary>
15+
/// The CacheManager Class is responsible for storing caches of image filter states.
16+
/// This greatly saves processing time, but increases load on memory.
17+
/// </summary>
18+
static class CacheManager
19+
{
20+
public static List<string> filterState;
21+
public static Dictionary<List<string>, Bitmap> cachedFilterStates;
22+
23+
public static void InitializeWithOriginal(Bitmap bmp)
24+
{
25+
filterState = new List<string>();
26+
27+
cachedFilterStates = new Dictionary<List<string>, Bitmap>(new StringListEqComparer())
28+
{
29+
{ new List<string>(), DeepCopy(bmp)}
30+
};
31+
}
32+
33+
public static void UpdateFilterState(string filter, bool newChecked)
34+
{
35+
if (newChecked)
36+
filterState.Add(filter);
37+
else
38+
filterState.Remove(filter);
39+
}
40+
41+
public static Bitmap GetBitmapForFilterState() => cachedFilterStates.ContainsKey(filterState) ? cachedFilterStates[filterState] : null;
42+
43+
public static void SetBitmapForFilterState(Bitmap bmp) => cachedFilterStates[filterState] = DeepCopy(bmp);
44+
45+
public static Bitmap GetOriginalImage() => cachedFilterStates[new List<string>()];
46+
47+
private static T DeepCopy<T>(T source)
48+
// Sources used
49+
// Deepcopy w/ stream: https://stackoverflow.com/questions/43039099/creating-a-completely-new-copy-of-bitmap-from-a-bitmap-in-c-sharp/43042865#43042865
50+
{
51+
if (!typeof(T).IsSerializable)
52+
{
53+
throw new ArgumentException("The type must be serializable.", "source");
54+
}
55+
56+
if (Object.ReferenceEquals(source, null))
57+
{
58+
return default(T);
59+
}
60+
61+
IFormatter formatter = new BinaryFormatter();
62+
Stream stream = new MemoryStream();
63+
using (stream)
64+
{
65+
formatter.Serialize(stream, source);
66+
stream.Seek(0, SeekOrigin.Begin);
67+
return (T)formatter.Deserialize(stream);
68+
}
69+
}
70+
}
71+
72+
public class StringListEqComparer : IEqualityComparer<List<string>>
73+
// Sources used
74+
// Custom compare: https://stackoverflow.com/questions/14663168/an-integer-array-as-a-key-for-dictionary
75+
{
76+
public bool Equals(List<string> x, List<string> y)
77+
{
78+
if (x.Count != y.Count)
79+
{
80+
return false;
81+
}
82+
for (int i = 0; i < x.Count; i++)
83+
{
84+
if (x[i] != y[i])
85+
{
86+
return false;
87+
}
88+
}
89+
return true;
90+
}
91+
92+
public int GetHashCode(List<string> obj)
93+
{
94+
int result = 17;
95+
for (int i = 0; i < obj.Count; i++)
96+
{
97+
unchecked
98+
{
99+
result = result * 23 + obj[i].GetHashCode();
100+
}
101+
}
102+
return result;
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)