-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathGenerateBitmaps.ps1
91 lines (84 loc) · 2.56 KB
/
GenerateBitmaps.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Create needle bitmaps from a screenshot.
#
# This should really be written in AHK with the Gdip library, but that
# library has problems accessing the GDI+ encoders. This uses .NET and
# produces reliable results :)
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[String]$ScreenshotPath,
[Parameter(Mandatory=$true)]
[ValidateSet("Windowed", "Fullscreen")]
[String]$WindowType
)
# Enforce best practices.
Set-StrictMode -Version Latest
# Stop on first error.
$ErrorActionPreference = 'Stop'
function EnsureDir($Dir) {
if (Test-Path -LiteralPath $Dir -PathType Container) {
return
}
mkdir $Dir | Out-Null
Write-Verbose "Created $dir"
}
function FormatSize($Size) {
"$($Size.Width)x$($Size.Height)"
}
Add-Type -AssemblyName System.Drawing
# .NET doesn't pick up the PowerShell working directory, so pass it an
# absolute path.
$ScreenshotAbspath = (Resolve-Path $ScreenshotPath).Path
try {
$ScreenshotBitmap = New-Object System.Drawing.Bitmap($ScreenshotAbspath)
}
catch
{
throw "Could not create bitmap from '$ScreenshotAbspath'. Ensure the image exists."
}
$RequiredSize = New-Object System.Drawing.Size(800, 600)
if ( $ScreenshotBitmap.Size -ne $RequiredSize) {
throw "Image has dimensions $(FormatSize($ScreenshotBitmap.Size)); expected $(FormatSize($RequiredSize))"
}
$SizeCoords = @{
'Minor' = @(431, 327, 5, 15);
'Light' = @(459, 328, 7, 14);
'Regular' = @(488, 326, 7, 16);
'Greater' = @(517, 326, 8, 16);
'Super' = @(547, 323, 6, 19);
}
$Coords = @{}
$TypeIndex = 0
foreach ($Type in @('Healing', 'Mana')) {
$Coords[$Type] = @{}
foreach ($SizeItem in $SizeCoords.GetEnumerator()) {
$Size = $SizeItem.Name
$Arr = $SizeItem.Value.Clone()
# Pixel offset of the second inventory row
$Arr[1] += $TypeIndex * 29
$Coords[$Type][$Size] = $Arr
}
++$TypeIndex
}
$Coords['Rejuvenation'] = @{
'Regular' = @(430, 386, 8, 13);
'Full' = @(454, 382, 12, 18);
}
# Again, we need an absolute path for passing to .NET.
$ImagesDir = [System.IO.Path]::GetFullPath((Join-Path (Join-Path (Get-Location) Images) $WindowType))
EnsureDir($ImagesDir)
foreach ($TypeItem in $Coords.GetEnumerator()) {
$Type = $TypeItem.Name
$TypeDir = Join-Path $ImagesDir $Type
EnsureDir($TypeDir)
foreach ($SizeItem in $TypeItem.Value.GetEnumerator()) {
$Size = $SizeItem.Name
$Rect = New-Object System.Drawing.Rectangle($SizeItem.Value)
$Needle = $ScreenshotBitmap.Clone($Rect, [System.Drawing.Imaging.PixelFormat]::DontCare)
$NeedlePath = Join-Path $TypeDir "$Size.png"
$Needle.Save($NeedlePath)
$Needle.Dispose()
Write-Verbose "Wrote $NeedlePath"
}
}
$ScreenshotBitmap.Dispose()