Skip to content

Commit 6ed595c

Browse files
Remove BluwolfIcons from NuGet (#119)
1 parent ea7a205 commit 6ed595c

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

Pixed/IO/IconProjectSerializer.cs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ public PixedModel Deserialize(Stream stream, ApplicationData applicationData)
1919

2020
public void Serialize(Stream stream, PixedModel model, bool close)
2121
{
22-
BluwolfIcons.Icon icon = new();
23-
22+
IList<SkiaIconImage> images = [];
2423
if (model.Frames.Count == 1)
2524
{
2625
var bitmap = model.CurrentFrame.Render();
2726

2827
if (IconFormats.Count == 0)
2928
{
30-
icon.Images.Add(new SkiaIconImage(bitmap));
29+
images.Add(new SkiaIconImage(bitmap));
3130
}
3231
else
3332
{
@@ -37,7 +36,7 @@ public void Serialize(Stream stream, PixedModel model, bool close)
3736
{
3837
if (format.X == bitmap.Width && format.Y == bitmap.Height)
3938
{
40-
icon.Images.Add(new SkiaIconImage(bitmap));
39+
images.Add(new SkiaIconImage(bitmap));
4140
}
4241
else
4342
{
@@ -46,7 +45,7 @@ public void Serialize(Stream stream, PixedModel model, bool close)
4645
canvas.Clear(SKColors.Transparent);
4746
canvas.DrawBitmap(bitmap, new SKRect(0, 0, scaledBitmap.Width, scaledBitmap.Height));
4847
canvas.Dispose();
49-
icon.Images.Add(new SkiaIconImage(scaledBitmap));
48+
images.Add(new SkiaIconImage(scaledBitmap));
5049
}
5150
}
5251
}
@@ -55,15 +54,58 @@ public void Serialize(Stream stream, PixedModel model, bool close)
5554
{
5655
foreach (var frame in model.Frames)
5756
{
58-
icon.Images.Add(new SkiaIconImage(frame.Render()));
57+
images.Add(new SkiaIconImage(frame.Render()));
5958
}
6059
}
6160

62-
icon.Save(stream);
61+
Save(stream, images);
6362

6463
if (close)
6564
{
6665
stream.Dispose();
6766
}
6867
}
68+
69+
private static void Save(Stream stream, IList<SkiaIconImage> images)
70+
{
71+
ArgumentNullException.ThrowIfNull(stream);
72+
73+
if (!stream.CanWrite)
74+
throw new ArgumentException("Stream must support writing.", nameof(stream));
75+
76+
using var writer = new BinaryWriter(stream);
77+
// Reserved, always 0.
78+
writer.Write((ushort)0);
79+
// 1 for ICO, 2 for CUR
80+
writer.Write((ushort)1);
81+
writer.Write((ushort)images.Count);
82+
83+
var pendingImages = new Queue<byte[]>();
84+
var offset = 6 + 16 * images.Count; // Header: 6; Each Image: 16
85+
86+
foreach (var image in images)
87+
{
88+
writer.Write((byte)image.Width);
89+
writer.Write((byte)image.Height);
90+
91+
// Number of colors in the palette. Since we always save the image ourselves (with no palette), hardcode this to 0 (No palette).
92+
writer.Write((byte)0);
93+
// Reserved, always 0.
94+
writer.Write((byte)0);
95+
// Color planes. Since we save the images ourselves, this is 1.
96+
writer.Write((ushort)1);
97+
writer.Write((ushort)image.BitsPerPixel);
98+
99+
var data = image.GetData();
100+
101+
writer.Write((uint)data.Length);
102+
writer.Write((uint)offset);
103+
104+
offset += data.Length;
105+
pendingImages.Enqueue(data);
106+
}
107+
108+
while (pendingImages.Count > 0)
109+
writer.Write(pendingImages.Dequeue());
110+
}
69111
}

Pixed/IO/SkiaIconImage.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using BluwolfIcons;
2-
using Pixed.Utils;
1+
using Pixed.Utils;
32
using SkiaSharp;
43
using System.Collections.Generic;
54
using System.IO;
65

76
namespace Pixed.IO;
8-
internal class SkiaIconImage : IIconImage
7+
internal class SkiaIconImage
98
{
109
private readonly SKBitmap _bitmap;
1110

Pixed/Pixed.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.4" />
2626
<PackageReference Include="Avalonia.Themes.Simple" Version="11.1.4" />
2727
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0.4" />
28-
<PackageReference Include="BluwolfIcons" Version="1.0.1" />
2928
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
3029
<PackageReference Include="Deadpikle.AvaloniaProgressRing" Version="0.10.8" />
3130
<PackageReference Include="MateuszNejman.LZMA_SDK" Version="24.8.0" />

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ Create pixel art images with **Pixed**. Use it in a game or wherever you want. P
3232
- Newtonsoft.JSON [JamesNK/Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)
3333
- PixiEditor.ColorPicker [PixiEditor/ColorPicker](https://github.com/PixiEditor/ColorPicker)
3434
- System.Reactive (RX) [dotnet/reactive](https://github.com/dotnet/reactive)
35-
- LZMA SDK [monemihir/LZMA-SDK](https://github.com/monemihir/LZMA-SDK)
35+
- LZMA SDK [Mateusz-Nejman/LZMA_SDK](https://github.com/Mateusz-Nejman/LZMA_SDK)
3636
- AvaloniaProgressRing [Deadpikle/AvaloniaProgressRing](https://github.com/Deadpikle/AvaloniaProgressRing)
3737
- SkiaSharp [mono/SkiaSharp](https://github.com/mono/SkiaSharp)
38-
- BluwolfIcons [Davipb/BluwolfIcons](https://github.com/Davipb/BluwolfIcons)
3938

4039
## Assets
4140
- Icons from IcoMoon [https://icomoon.io/](https://icomoon.io/)

0 commit comments

Comments
 (0)