Skip to content

Commit

Permalink
Fixed bugs in saving out icon resource groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkinsella committed Aug 18, 2016
1 parent 4f1eb52 commit 5ba8ba7
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Src/Workshell.PE.Resources/Graphics/IconGroupResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public IconGroup ToGroup(uint languageId)
{
byte[] data = GetBytes(languageId);

using (MemoryStream mem = new MemoryStream())
using (MemoryStream mem = new MemoryStream(data))
{
NEWHEADER header = Utils.Read<NEWHEADER>(mem);

Expand All @@ -241,7 +241,7 @@ public IconGroup ToGroup(uint languageId)
}
}

public void Save(string fileName, uint languageId, IconSaveFormat format)
public void Save(string fileName, uint languageId, IconGroupSaveFormat format)
{
using (FileStream file = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
Expand All @@ -250,9 +250,9 @@ public void Save(string fileName, uint languageId, IconSaveFormat format)
}
}

public void Save(Stream stream, uint languageId, IconSaveFormat format)
public void Save(Stream stream, uint languageId, IconGroupSaveFormat format)
{
if (format == IconSaveFormat.Raw)
if (format == IconGroupSaveFormat.Raw)
{
Save(stream, languageId);
}
Expand All @@ -278,18 +278,17 @@ public void Save(Stream stream, uint languageId, IconSaveFormat format)
{
IconGroupEntry entry = group[i];

ulong color_count = Convert.ToUInt64(Math.Pow(2, entry.BitCount));

if (color_count >= 256)
color_count = 0;

Utils.Write(Convert.ToByte(entry.Width >= 256 ? 0 : entry.Width), stream);
Utils.Write(Convert.ToByte(entry.Height >= 256 ? 0 : entry.Height), stream);
Utils.Write(Convert.ToByte(entry.ColorCount), stream);
Utils.Write(Convert.ToByte(color_count), stream);
Utils.Write(Convert.ToByte(0), stream);
Utils.Write(Convert.ToUInt16(1), stream);

ushort colors = Convert.ToUInt16(Math.Log(entry.ColorCount) / Math.Log(2));

if (colors >= 256)
colors = 0;

Utils.Write(colors, stream);
Utils.Write(entry.BitCount, stream);
Utils.Write(entry.BytesInRes, stream);
Utils.Write(offsets[i], stream);
}
Expand Down

0 comments on commit 5ba8ba7

Please sign in to comment.