protected int OnExecute(CommandLineApplication app) { OutputImz = OutputImz ?? InputFile; Directory.CreateDirectory(Path.GetDirectoryName(OutputImz)); var images = File.OpenRead(OutputImz).Using(stream => Imgz.Read(stream).ToArray()); var fixedCount = 0; var fixedImages = images .Select( image => { var expetectedLen = ImgdSanityChecking.GetExpectedDataLen(image); if (true && expetectedLen != null && expetectedLen < image.Data.Length && Imaging.PixelFormat.Indexed4 == image.PixelFormat ) { var fixedData = new byte[expetectedLen.Value]; Buffer.BlockCopy(image.Data, 0, fixedData, 0, expetectedLen.Value); fixedCount++; return(new Imgd( image.Size, image.PixelFormat, fixedData, image.Clut, isSwizzled: false )); } else { return(image); } } ) .ToArray(); var buffer = new MemoryStream(); Imgz.Write(buffer, fixedImages); File.WriteAllBytes(OutputImz, buffer.ToArray()); Console.WriteLine($"Fixed {fixedCount} images."); return(0); }
internal static ImgdSummary From(Imgd it) { return(new ImgdSummary { PixelFormat = it.PixelFormat.ToString(), Width = it.Size.Width, Height = it.Size.Height, IsSwizzled = it.IsSwizzled, ExpectedDataLen = ImgdSanityChecking.GetExpectedDataLen(it), ActualDataLen = it.Data.Length, ActualClutLen = it.Clut?.Length, }); }