-
Notifications
You must be signed in to change notification settings - Fork 1
/
PDNCursorFormat.cs
64 lines (57 loc) · 2.21 KB
/
PDNCursorFormat.cs
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
// Decompiled with JetBrains decompiler
// Type: PaintDotNet.Data.PDNCursorFormat
// Assembly: IcoCur, Version=4.0.1.0, Culture=neutral, PublicKeyToken=null
// MVID: EEB2FED8-625F-4555-8E27-7F881F458B17
// Assembly location: C:\src\cs\Paint.net\IcoCur.dll
using System.Drawing;
using System.IO;
using IcoCur.EvanOlds;
using PaintDotNet;
using PaintDotNet.Data;
using PaintDotNet.Rendering;
namespace IcoCur;
internal class PDNCursorFormat : FileType
{
public PDNCursorFormat()
: base("Cursors", new FileTypeOptions
{
SupportsLayers = true,
SupportsCancellation = false,
SaveExtensions = new[] { ".cur" },
LoadExtensions = new[] { ".cur" }
})
{
}
protected override Document OnLoad(Stream input) => PDNIcoCurFormat.GeneralLoad(input);
protected override SaveConfigToken OnCreateDefaultSaveConfigToken() => new CurSaveConfigToken();
public override SaveConfigWidget CreateSaveConfigWidget() => new CurSaveConfigWidget();
protected override void OnSave(
Document input,
Stream output,
SaveConfigToken token,
Surface scratchSurface,
ProgressEventHandler callback)
{
CurSaveConfigToken curSaveConfigToken = (CurSaveConfigToken)token;
EOIcoCurWriter eoIcoCurWriter = new EOIcoCurWriter(output, 1, EOIcoCurWriter.IcoCurType.Cursor);
Surface surf = new Surface(input.Width, input.Height);
surf.Fill(ColorBgra.FromBgra(byte.MaxValue, byte.MaxValue, byte.MaxValue, 0));
EOPDNUtility.RenderClear(input, surf);
if (surf.Width != 32 || surf.Height != 32)
{
Surface surface = EOPDNUtility.ResizeSurface(new Size(32, 32), surf);
surf.Dispose();
surf = surface;
}
Bitmap aliasedBitmap = surf.CreateAliasedBitmap();
if (curSaveConfigToken.EightBit)
{
Bitmap img = Quantize(surf, 8, byte.MaxValue, false, null);
eoIcoCurWriter.WriteBitmap(img, aliasedBitmap, curSaveConfigToken.HotSpot);
}
else
eoIcoCurWriter.WriteBitmap(aliasedBitmap, aliasedBitmap, curSaveConfigToken.HotSpot);
aliasedBitmap.Dispose();
surf.Dispose();
}
}