-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPDNANIFormat.cs
152 lines (146 loc) · 4.81 KB
/
PDNANIFormat.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Decompiled with JetBrains decompiler
// Type: PaintDotNet.Data.PDNANIFormat
// 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.Collections;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using IcoCur.EvanOlds;
using PaintDotNet;
namespace IcoCur;
internal class PDNANIFormat : FileType
{
public PDNANIFormat()
: base("Animated Cursors", new FileTypeOptions
{
SupportsLayers = true,
SupportsCancellation = false,
LoadExtensions = new[] { ".ani" },
SaveExtensions = new[] { ".ani" }
})
{
}
protected override Document OnLoad(Stream input)
{
EvanRIFFFormat evanRiffFormat = new EvanRIFFFormat();
Document document1;
if (evanRiffFormat.InitFromStream(input) != 0)
{
document1 = null;
}
else
{
if (evanRiffFormat.MasterChunk.GetStringHeaderID().ToLower() != "acon")
throw new InvalidDataException("The specified RIFF file is not an animated cursor.");
int ChunkID = 1852793705;
Document document2 = null;
foreach (EvanRIFFFormat.Chunk allChunk in evanRiffFormat.FindAllChunks(ChunkID))
{
input.Seek(allChunk.DataOffset(), SeekOrigin.Begin);
Bitmap image = new EOIcoCurLoader(input).GetImage(0U);
if (image == null)
throw new InvalidDataException("Data within the animated cursor file is corrupt or invalid");
if (document2 == null)
document2 = new Document(image.Width, image.Height);
image.RotateFlip(RotateFlipType.Rotate180FlipX);
Surface surface = Surface.CopyFromBitmap(image);
image.Dispose();
BitmapLayer bitmapLayer = new BitmapLayer(surface);
((ArrayList)document2.Layers).Add(bitmapLayer);
}
document1 = document2;
}
return document1;
}
protected override void OnSave(
Document input,
Stream output,
SaveConfigToken token,
Surface scratchSurface,
ProgressEventHandler callback)
{
ANISaveOptForm aniSaveOptForm = new ANISaveOptForm();
aniSaveOptForm.InitFromDocument(input);
if (aniSaveOptForm.ShowDialog() != DialogResult.OK)
return;
uint animDelay = aniSaveOptForm.GetAnimDelay();
Point hotSpot = aniSaveOptForm.GetHotSpot();
uint dword1 = 4286;
uint num = (uint)(((int)dword1 + 8) * input.Layers.Count);
uint dword2 = num + 60U;
byte[] buffer1 = new byte[4]
{
82,
73,
70,
70
};
output.Write(buffer1, 0, 4);
EOStreamUtility.Write_uint(output, dword2);
byte[] buffer2 = new byte[4]
{
65,
67,
79,
78
};
output.Write(buffer2, 0, 4);
Writeanih(output, (uint)input.Layers.Count, animDelay);
byte[] buffer3 = new byte[4]
{
76,
73,
83,
84
};
output.Write(buffer3, 0, 4);
EOStreamUtility.Write_uint(output, num + 4U);
byte[] buffer4 = new byte[4]
{
102,
114,
97,
109
};
output.Write(buffer4, 0, 4);
for (int index = 0; index < input.Layers.Count; ++index)
{
byte[] buffer5 = new byte[4]
{
105,
99,
111,
110
};
output.Write(buffer5, 0, 4);
EOStreamUtility.Write_uint(output, dword1);
Bitmap bitmapLayerResized = EOPDNUtility.GetBitmapLayerResized(input, index, 32, 32);
new EOIcoCurWriter(output, 1, EOIcoCurWriter.IcoCurType.Cursor).WriteBitmap(bitmapLayerResized, null,
hotSpot);
}
}
private void Writeanih(Stream outS, uint NumFrames, uint FrameRate)
{
byte[] buffer = new byte[4]
{
97,
110,
105,
104
};
outS.Write(buffer, 0, 4);
uint dword = 36;
EOStreamUtility.Write_uint(outS, dword);
EOStreamUtility.Write_uint(outS, dword);
EOStreamUtility.Write_uint(outS, NumFrames);
EOStreamUtility.Write_uint(outS, NumFrames);
EOStreamUtility.Write_uint(outS, 0U);
EOStreamUtility.Write_uint(outS, 0U);
EOStreamUtility.Write_uint(outS, 0U);
EOStreamUtility.Write_uint(outS, 0U);
EOStreamUtility.Write_uint(outS, FrameRate);
EOStreamUtility.Write_uint(outS, 1U);
}
}