From b3eb2e7f96a77a55f80831301dca454db8d4eed1 Mon Sep 17 00:00:00 2001 From: LastBattle Date: Thu, 10 Dec 2020 17:29:11 +0800 Subject: [PATCH] [WzLib] Decoding image of type 257 http://forum.ragezone.com/f702/wz-png-format-decode-code-1114978/index2.html#post9053713 --- MapleLib/WzLib/WzProperties/WzPngProperty.cs | 33 ++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/MapleLib/WzLib/WzProperties/WzPngProperty.cs b/MapleLib/WzLib/WzProperties/WzPngProperty.cs index 1093ddd5..21b91840 100644 --- a/MapleLib/WzLib/WzProperties/WzPngProperty.cs +++ b/MapleLib/WzLib/WzProperties/WzPngProperty.cs @@ -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; } @@ -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