From 74783dae294443094f1f6e89a87d267927d857a7 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 24 Oct 2025 01:52:56 +0100 Subject: [PATCH] Refactor sector painting methods and adjust lead-in sector handling --- Aaru.Core/Graphics/Spiral.cs | 210 +++++++++++++++++------------------ 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/Aaru.Core/Graphics/Spiral.cs b/Aaru.Core/Graphics/Spiral.cs index 2293914e3..98352f84b 100644 --- a/Aaru.Core/Graphics/Spiral.cs +++ b/Aaru.Core/Graphics/Spiral.cs @@ -287,109 +287,6 @@ public sealed class Spiral : IMediaGraph public SKBitmap Bitmap { get; } -#region IMediaGraph Members - - /// - /// Paints the segment of the spiral that corresponds to the specified sector in green - /// Sector - public void PaintSectorGood(ulong sector) => PaintSector(sector, SKColors.Green); - - /// - /// Paints the segment of the spiral that corresponds to the specified sector in red - /// Sector - public void PaintSectorBad(ulong sector) => PaintSector(sector, SKColors.Red); - - /// - /// Paints the segment of the spiral that corresponds to the specified sector in yellow - /// Sector - public void PaintSectorUnknown(ulong sector) => PaintSector(sector, SKColors.Yellow); - - /// - /// Paints the segment of the spiral that corresponds to the specified sector in gray - /// Sector - public void PaintSectorUndumped(ulong sector) => PaintSector(sector, SKColors.Gray); - - /// - public void PaintSector(ulong sector, byte red, byte green, byte blue, byte opacity = 255) => - PaintSector(sector, new SKColor(red, green, blue, opacity)); - - /// - public void PaintSectorsUndumped(ulong startingSector, uint length) => - PaintSectors(startingSector, length, SKColors.Gray); - - /// - public void PaintSectorsGood(ulong startingSector, uint length) => - PaintSectors(startingSector, length, SKColors.Green); - - /// - public void PaintSectorsBad(ulong startingSector, uint length) => - PaintSectors(startingSector, length, SKColors.Red); - - /// - public void PaintSectorsUnknown(ulong startingSector, uint length) => - PaintSectors(startingSector, length, SKColors.Yellow); - - /// - public void PaintSectors(ulong startingSector, uint length, byte red, byte green, byte blue, byte opacity = 255) => - PaintSectors(startingSector, length, new SKColor(red, green, blue, opacity)); - - /// - public void PaintSectorsUndumped(IEnumerable sectors) => PaintSectors(sectors, SKColors.Gray); - - /// - public void PaintSectorsGood(IEnumerable sectors) => PaintSectors(sectors, SKColors.Green); - - /// - public void PaintSectorsBad(IEnumerable sectors) => PaintSectors(sectors, SKColors.Red); - - /// - public void PaintSectorsUnknown(IEnumerable sectors) => PaintSectors(sectors, SKColors.Yellow); - - /// - public void PaintSectorsUnknown(IEnumerable sectors, byte red, byte green, byte blue, byte opacity = 255) => - PaintSectors(sectors, new SKColor(red, green, blue, opacity)); - - /// - /// Paints the segment of the spiral that corresponds to the information specific to recordable discs in green - public void PaintRecordableInformationGood() - { - if(_recordableInformationPoints is null) return; - - var path = new SKPath(); - - path.MoveTo(_recordableInformationPoints[0]); - - foreach(SKPoint point in _recordableInformationPoints) path.LineTo(point); - - _canvas.DrawPath(path, - new SKPaint - { - Style = SKPaintStyle.Stroke, - Color = SKColors.Green, - StrokeWidth = 2 - }); - } - - /// - public void WriteTo(string path) - { - using var fs = new FileStream(path, FileMode.Create); - WriteTo(fs); - fs.Close(); - } - - /// - /// Writes the spiral bitmap as a PNG into the specified stream - /// Stream that will receive the spiral bitmap - public void WriteTo(Stream stream) - { - var image = SKImage.FromBitmap(Bitmap); - SKData data = image.Encode(); - data.SaveTo(stream); - } - -#endregion - public static DiscParameters DiscParametersFromMediaType(MediaType mediaType, bool smallDisc = false) => mediaType switch { @@ -629,10 +526,10 @@ public sealed class Spiral : IMediaGraph /// /// Sector within the lead-in (0-based, where 0 is LBA -150 equivalent) /// Color to paint the segment in - public void PaintCdLeadInSector(ulong sector, SKColor color) + public void PaintCdLeadInSector(long sector, SKColor color) { const int cdLeadInSize = 2750; // Approximate CD lead-in sectors (46-50mm at 1.6µm pitch, ~75 sectors/sec) - PaintLeadInSector(sector, color, cdLeadInSize); + PaintLeadInSector((ulong)(sector * -1), color, cdLeadInSize); } /// Gets all the points that are needed to draw a spiral with the specified parameters @@ -699,5 +596,108 @@ public sealed class Spiral : IMediaGraph SKColor DiscColor ); +#endregion + +#region IMediaGraph Members + + /// + /// Paints the segment of the spiral that corresponds to the specified sector in green + /// Sector + public void PaintSectorGood(ulong sector) => PaintSector(sector, SKColors.Green); + + /// + /// Paints the segment of the spiral that corresponds to the specified sector in red + /// Sector + public void PaintSectorBad(ulong sector) => PaintSector(sector, SKColors.Red); + + /// + /// Paints the segment of the spiral that corresponds to the specified sector in yellow + /// Sector + public void PaintSectorUnknown(ulong sector) => PaintSector(sector, SKColors.Yellow); + + /// + /// Paints the segment of the spiral that corresponds to the specified sector in gray + /// Sector + public void PaintSectorUndumped(ulong sector) => PaintSector(sector, SKColors.Gray); + + /// + public void PaintSector(ulong sector, byte red, byte green, byte blue, byte opacity = 255) => + PaintSector(sector, new SKColor(red, green, blue, opacity)); + + /// + public void PaintSectorsUndumped(ulong startingSector, uint length) => + PaintSectors(startingSector, length, SKColors.Gray); + + /// + public void PaintSectorsGood(ulong startingSector, uint length) => + PaintSectors(startingSector, length, SKColors.Green); + + /// + public void PaintSectorsBad(ulong startingSector, uint length) => + PaintSectors(startingSector, length, SKColors.Red); + + /// + public void PaintSectorsUnknown(ulong startingSector, uint length) => + PaintSectors(startingSector, length, SKColors.Yellow); + + /// + public void PaintSectors(ulong startingSector, uint length, byte red, byte green, byte blue, byte opacity = 255) => + PaintSectors(startingSector, length, new SKColor(red, green, blue, opacity)); + + /// + public void PaintSectorsUndumped(IEnumerable sectors) => PaintSectors(sectors, SKColors.Gray); + + /// + public void PaintSectorsGood(IEnumerable sectors) => PaintSectors(sectors, SKColors.Green); + + /// + public void PaintSectorsBad(IEnumerable sectors) => PaintSectors(sectors, SKColors.Red); + + /// + public void PaintSectorsUnknown(IEnumerable sectors) => PaintSectors(sectors, SKColors.Yellow); + + /// + public void PaintSectorsUnknown(IEnumerable sectors, byte red, byte green, byte blue, byte opacity = 255) => + PaintSectors(sectors, new SKColor(red, green, blue, opacity)); + + /// + /// Paints the segment of the spiral that corresponds to the information specific to recordable discs in green + public void PaintRecordableInformationGood() + { + if(_recordableInformationPoints is null) return; + + var path = new SKPath(); + + path.MoveTo(_recordableInformationPoints[0]); + + foreach(SKPoint point in _recordableInformationPoints) path.LineTo(point); + + _canvas.DrawPath(path, + new SKPaint + { + Style = SKPaintStyle.Stroke, + Color = SKColors.Green, + StrokeWidth = 2 + }); + } + + /// + public void WriteTo(string path) + { + using var fs = new FileStream(path, FileMode.Create); + WriteTo(fs); + fs.Close(); + } + + /// + /// Writes the spiral bitmap as a PNG into the specified stream + /// Stream that will receive the spiral bitmap + public void WriteTo(Stream stream) + { + var image = SKImage.FromBitmap(Bitmap); + SKData data = image.Encode(); + data.SaveTo(stream); + } + #endregion } \ No newline at end of file