-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tiemonl
committed
Jun 26, 2018
1 parent
6aff0ad
commit 0fd064a
Showing
78 changed files
with
5,224 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27004.2002 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fisher", "fisher\fisher.csproj", "{93668F5E-8746-4070-AE80-19D2609EDE78}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{93668F5E-8746-4070-AE80-19D2609EDE78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{93668F5E-8746-4070-AE80-19D2609EDE78}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{93668F5E-8746-4070-AE80-19D2609EDE78}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{93668F5E-8746-4070-AE80-19D2609EDE78}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {10017706-D0A3-4594-BD5E-4DFBFA8ED2D2} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Drawing; | ||
using System.Drawing.Imaging; | ||
|
||
namespace fisher { | ||
class FindWeight { | ||
//static void Main(string[] args) { | ||
// Bitmap need = new Bitmap("C:\\Users\\Liam\\Dropbox\\Coding Shit\\Bit Heroes Fishing\\Weight\\zero.bmp"); | ||
// Bitmap hay = new Bitmap("C:\\Users\\Liam\\Dropbox\\Coding Shit\\Bit Heroes Fishing\\fisher\\fisher\\bin\\Debug\\screenie.bmp"); | ||
// Point? pt = Find(hay, need); | ||
// Console.WriteLine(pt.ToString()); | ||
// Console.ReadLine(); | ||
//} | ||
public static Point? Find(Bitmap haystack, Bitmap needle) { | ||
if (null == haystack || null == needle) { | ||
return null; | ||
} | ||
if (haystack.Width < needle.Width || haystack.Height < needle.Height) { | ||
return null; | ||
} | ||
|
||
var haystackArray = GetPixelArray(haystack); | ||
var needleArray = GetPixelArray(needle); | ||
|
||
foreach (var firstLineMatchPoint in FindMatch(haystackArray.Take(haystack.Height - needle.Height), needleArray[0])) { | ||
if (IsNeedlePresentAtLocation(haystackArray, needleArray, firstLineMatchPoint, 1)) { | ||
return firstLineMatchPoint; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static int[][] GetPixelArray(Bitmap bitmap) { | ||
var result = new int[bitmap.Height][]; | ||
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, | ||
PixelFormat.Format32bppArgb); | ||
|
||
for (int y = 0; y < bitmap.Height; ++y) { | ||
result[y] = new int[bitmap.Width]; | ||
Marshal.Copy(bitmapData.Scan0 + y * bitmapData.Stride, result[y], 0, result[y].Length); | ||
} | ||
|
||
bitmap.UnlockBits(bitmapData); | ||
|
||
return result; | ||
} | ||
private static IEnumerable<Point> FindMatch(IEnumerable<int[]> haystackLines, int[] needleLine) { | ||
var y = 0; | ||
foreach (var haystackLine in haystackLines) { | ||
for (int x = 0, n = haystackLine.Length - needleLine.Length; x < n; ++x) { | ||
if (ContainSameElements(haystackLine, x, needleLine, 0, needleLine.Length)) { | ||
yield return new System.Drawing.Point(x, y); | ||
} | ||
} | ||
y += 1; | ||
} | ||
} | ||
|
||
private static bool ContainSameElements(int[] first, int firstStart, int[] second, int secondStart, int length) { | ||
for (int i = 0; i < length; ++i) { | ||
if (i == 19) { | ||
System.Diagnostics.Debugger.Break(); | ||
} | ||
if (second[i + secondStart].Equals(-1)) { | ||
continue; | ||
} | ||
if (first[i + firstStart] != second[i + secondStart]) { | ||
|
||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private static bool IsNeedlePresentAtLocation(int[][] haystack, int[][] needle, Point point, int alreadyVerified) { | ||
//we already know that "alreadyVerified" lines already match, so skip them | ||
for (int y = alreadyVerified; y < needle.Length; ++y) { | ||
if (!ContainSameElements(haystack[y + point.Y], point.X, needle[y], 0, needle[0].Length)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.