From 6a4a9a3c46f3a674f30dd0d5b2569dbdc3f67ff1 Mon Sep 17 00:00:00 2001 From: morkt Date: Fri, 29 Apr 2022 15:07:39 +0400 Subject: [PATCH] (TINK): work-around for PNG images. --- ArcFormats/Cyberworks/ImageTINK.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ArcFormats/Cyberworks/ImageTINK.cs b/ArcFormats/Cyberworks/ImageTINK.cs index d64c6cdb..001f0b39 100644 --- a/ArcFormats/Cyberworks/ImageTINK.cs +++ b/ArcFormats/Cyberworks/ImageTINK.cs @@ -2,7 +2,7 @@ //! \date Fri Jun 17 18:49:04 2016 //! \brief Tinker Bell encrypted image file. // -// Copyright (C) 2016-2017 by morkt +// Copyright (C) 2016-2022 by morkt // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to @@ -28,6 +28,7 @@ using System.Collections.Generic; using System.IO; using System.Windows.Media; using System.Windows.Media.Imaging; +using GameRes.Utility; namespace GameRes.Formats.Cyberworks { @@ -145,11 +146,17 @@ namespace GameRes.Formats.Cyberworks { var size_buf = new byte[4]; input.Read (size_buf, 0 , 4); - if ('c' == type) - input.ReadByte(); - var decoder = new PngBitmapDecoder (input, BitmapCreateOptions.None, - BitmapCacheOption.OnLoad); - BitmapSource frame = decoder.Frames[0]; + int png_size = BigEndian.ToInt32 (size_buf, 0); + BitmapSource frame; + // work-around for possible extra padding before PNG data + using (var membuf = new MemoryStream (png_size+4)) + { + input.CopyTo (membuf); + membuf.Seek (-png_size, SeekOrigin.End); + var decoder = new PngBitmapDecoder (membuf, BitmapCreateOptions.None, + BitmapCacheOption.OnLoad); + frame = decoder.Frames[0]; + } Info.Width = (uint)frame.PixelWidth; Info.Height = (uint)frame.PixelHeight; if (frame.Format.BitsPerPixel != 32)