Skip to content

Commit

Permalink
[WzLib] Decoding image of type 257
Browse files Browse the repository at this point in the history
  • Loading branch information
LastBattle committed Dec 10, 2020
1 parent a2293a1 commit b3eb2e7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions MapleLib/WzLib/WzProperties/WzPngProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,22 @@ internal void ParsePng()
byte[] decoded = GetPixelDataDXT3(decBuf, width, height);

Marshal.Copy(decoded, 0, bmpData.Scan0, width * height);
bmp.UnlockBits(bmpData);
break;
}
case 257: // http://forum.ragezone.com/f702/wz-png-format-decode-code-1114978/index2.html#post9053713
{
bmp = new Bitmap(width, height, PixelFormat.Format16bppArgb1555);
BitmapData bmpData = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);
// "Npc.wz\\2570101.img\\info\\illustration2\\face\\0"

int uncompressedSize = width * height * 2;
byte[] decBuf = new byte[uncompressedSize];
zlib.Read(decBuf, 0, uncompressedSize);
zlib.Close();

CopyBmpDataWithStride(decBuf, bmp.Width * 2, bmpData);

bmp.UnlockBits(bmpData);
break;
}
Expand Down Expand Up @@ -572,6 +588,23 @@ private static void SetPixel(byte[] pixelData, int x, int y, int width, Color co
pixelData[offset + 2] = color.R;
pixelData[offset + 3] = alpha;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void CopyBmpDataWithStride(byte[] source, int stride, BitmapData bmpData)
{
if (bmpData.Stride == stride)
{
Marshal.Copy(source, 0, bmpData.Scan0, source.Length);
}
else
{
for (int y = 0; y < bmpData.Height; y++)
{
Marshal.Copy(source, stride * y, bmpData.Scan0 + bmpData.Stride * y, stride);
}
}

}
#endregion

#region DXT1 Color
Expand Down

0 comments on commit b3eb2e7

Please sign in to comment.