SkiaEncoder.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using BlurHashSharp.SkiaSharp;
  6. using MediaBrowser.Common.Configuration;
  7. using MediaBrowser.Controller.Drawing;
  8. using MediaBrowser.Controller.Extensions;
  9. using MediaBrowser.Model.Drawing;
  10. using Microsoft.Extensions.Logging;
  11. using SkiaSharp;
  12. using static Jellyfin.Drawing.Skia.SkiaHelper;
  13. namespace Jellyfin.Drawing.Skia
  14. {
  15. /// <summary>
  16. /// Image encoder that uses <see cref="SkiaSharp"/> to manipulate images.
  17. /// </summary>
  18. public class SkiaEncoder : IImageEncoder
  19. {
  20. private static readonly HashSet<string> _transparentImageTypes
  21. = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".png", ".gif", ".webp" };
  22. private readonly ILogger<SkiaEncoder> _logger;
  23. private readonly IApplicationPaths _appPaths;
  24. /// <summary>
  25. /// Initializes a new instance of the <see cref="SkiaEncoder"/> class.
  26. /// </summary>
  27. /// <param name="logger">The application logger.</param>
  28. /// <param name="appPaths">The application paths.</param>
  29. public SkiaEncoder(
  30. ILogger<SkiaEncoder> logger,
  31. IApplicationPaths appPaths)
  32. {
  33. _logger = logger;
  34. _appPaths = appPaths;
  35. }
  36. /// <inheritdoc/>
  37. public string Name => "Skia";
  38. /// <inheritdoc/>
  39. public bool SupportsImageCollageCreation => true;
  40. /// <inheritdoc/>
  41. public bool SupportsImageEncoding => true;
  42. /// <inheritdoc/>
  43. public IReadOnlyCollection<string> SupportedInputFormats =>
  44. new HashSet<string>(StringComparer.OrdinalIgnoreCase)
  45. {
  46. "jpeg",
  47. "jpg",
  48. "png",
  49. "dng",
  50. "webp",
  51. "gif",
  52. "bmp",
  53. "ico",
  54. "astc",
  55. "ktx",
  56. "pkm",
  57. "wbmp",
  58. // TODO: check if these are supported on multiple platforms
  59. // https://github.com/google/skia/blob/master/infra/bots/recipes/test.py#L454
  60. // working on windows at least
  61. "cr2",
  62. "nef",
  63. "arw"
  64. };
  65. /// <inheritdoc/>
  66. public IReadOnlyCollection<ImageFormat> SupportedOutputFormats
  67. => new HashSet<ImageFormat>() { ImageFormat.Webp, ImageFormat.Jpg, ImageFormat.Png };
  68. /// <summary>
  69. /// Check if the native lib is available.
  70. /// </summary>
  71. /// <returns>True if the native lib is available, otherwise false.</returns>
  72. public static bool IsNativeLibAvailable()
  73. {
  74. try
  75. {
  76. // test an operation that requires the native library
  77. SKPMColor.PreMultiply(SKColors.Black);
  78. return true;
  79. }
  80. catch (Exception)
  81. {
  82. return false;
  83. }
  84. }
  85. private static bool IsTransparent(SKColor color)
  86. => (color.Red == 255 && color.Green == 255 && color.Blue == 255) || color.Alpha == 0;
  87. /// <summary>
  88. /// Convert a <see cref="ImageFormat"/> to a <see cref="SKEncodedImageFormat"/>.
  89. /// </summary>
  90. /// <param name="selectedFormat">The format to convert.</param>
  91. /// <returns>The converted format.</returns>
  92. public static SKEncodedImageFormat GetImageFormat(ImageFormat selectedFormat)
  93. {
  94. switch (selectedFormat)
  95. {
  96. case ImageFormat.Bmp:
  97. return SKEncodedImageFormat.Bmp;
  98. case ImageFormat.Jpg:
  99. return SKEncodedImageFormat.Jpeg;
  100. case ImageFormat.Gif:
  101. return SKEncodedImageFormat.Gif;
  102. case ImageFormat.Webp:
  103. return SKEncodedImageFormat.Webp;
  104. default:
  105. return SKEncodedImageFormat.Png;
  106. }
  107. }
  108. private static bool IsTransparentRow(SKBitmap bmp, int row)
  109. {
  110. for (var i = 0; i < bmp.Width; ++i)
  111. {
  112. if (!IsTransparent(bmp.GetPixel(i, row)))
  113. {
  114. return false;
  115. }
  116. }
  117. return true;
  118. }
  119. private static bool IsTransparentColumn(SKBitmap bmp, int col)
  120. {
  121. for (var i = 0; i < bmp.Height; ++i)
  122. {
  123. if (!IsTransparent(bmp.GetPixel(col, i)))
  124. {
  125. return false;
  126. }
  127. }
  128. return true;
  129. }
  130. private SKBitmap CropWhiteSpace(SKBitmap bitmap)
  131. {
  132. var topmost = 0;
  133. for (int row = 0; row < bitmap.Height; ++row)
  134. {
  135. if (IsTransparentRow(bitmap, row))
  136. {
  137. topmost = row + 1;
  138. }
  139. else
  140. {
  141. break;
  142. }
  143. }
  144. int bottommost = bitmap.Height;
  145. for (int row = bitmap.Height - 1; row >= 0; --row)
  146. {
  147. if (IsTransparentRow(bitmap, row))
  148. {
  149. bottommost = row;
  150. }
  151. else
  152. {
  153. break;
  154. }
  155. }
  156. int leftmost = 0, rightmost = bitmap.Width;
  157. for (int col = 0; col < bitmap.Width; ++col)
  158. {
  159. if (IsTransparentColumn(bitmap, col))
  160. {
  161. leftmost = col + 1;
  162. }
  163. else
  164. {
  165. break;
  166. }
  167. }
  168. for (int col = bitmap.Width - 1; col >= 0; --col)
  169. {
  170. if (IsTransparentColumn(bitmap, col))
  171. {
  172. rightmost = col;
  173. }
  174. else
  175. {
  176. break;
  177. }
  178. }
  179. var newRect = SKRectI.Create(leftmost, topmost, rightmost - leftmost, bottommost - topmost);
  180. using (var image = SKImage.FromBitmap(bitmap))
  181. using (var subset = image.Subset(newRect))
  182. {
  183. return SKBitmap.FromImage(subset);
  184. }
  185. }
  186. /// <inheritdoc />
  187. /// <exception cref="ArgumentNullException">The path is null.</exception>
  188. /// <exception cref="FileNotFoundException">The path is not valid.</exception>
  189. /// <exception cref="SkiaCodecException">The file at the specified path could not be used to generate a codec.</exception>
  190. public ImageDimensions GetImageSize(string path)
  191. {
  192. if (!File.Exists(path))
  193. {
  194. throw new FileNotFoundException("File not found", path);
  195. }
  196. using (var codec = SKCodec.Create(path, out SKCodecResult result))
  197. {
  198. EnsureSuccess(result);
  199. var info = codec.Info;
  200. return new ImageDimensions(info.Width, info.Height);
  201. }
  202. }
  203. /// <inheritdoc />
  204. /// <exception cref="ArgumentNullException">The path is null.</exception>
  205. /// <exception cref="FileNotFoundException">The path is not valid.</exception>
  206. /// <exception cref="SkiaCodecException">The file at the specified path could not be used to generate a codec.</exception>
  207. public string GetImageBlurHash(int xComp, int yComp, string path)
  208. {
  209. if (path == null)
  210. {
  211. throw new ArgumentNullException(nameof(path));
  212. }
  213. // Any larger than 128x128 is too slow and there's no visually discernible difference
  214. return BlurHashEncoder.Encode(xComp, yComp, path, 128, 128);
  215. }
  216. private static bool HasDiacritics(string text)
  217. => !string.Equals(text, text.RemoveDiacritics(), StringComparison.Ordinal);
  218. private bool RequiresSpecialCharacterHack(string path)
  219. {
  220. for (int i = 0; i < path.Length; i++)
  221. {
  222. if (char.GetUnicodeCategory(path[i]) == UnicodeCategory.OtherLetter)
  223. {
  224. return true;
  225. }
  226. }
  227. if (HasDiacritics(path))
  228. {
  229. return true;
  230. }
  231. return false;
  232. }
  233. private string NormalizePath(string path)
  234. {
  235. if (!RequiresSpecialCharacterHack(path))
  236. {
  237. return path;
  238. }
  239. var tempPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + Path.GetExtension(path));
  240. Directory.CreateDirectory(Path.GetDirectoryName(tempPath));
  241. File.Copy(path, tempPath, true);
  242. return tempPath;
  243. }
  244. private static SKEncodedOrigin GetSKEncodedOrigin(ImageOrientation? orientation)
  245. {
  246. if (!orientation.HasValue)
  247. {
  248. return SKEncodedOrigin.TopLeft;
  249. }
  250. switch (orientation.Value)
  251. {
  252. case ImageOrientation.TopRight:
  253. return SKEncodedOrigin.TopRight;
  254. case ImageOrientation.RightTop:
  255. return SKEncodedOrigin.RightTop;
  256. case ImageOrientation.RightBottom:
  257. return SKEncodedOrigin.RightBottom;
  258. case ImageOrientation.LeftTop:
  259. return SKEncodedOrigin.LeftTop;
  260. case ImageOrientation.LeftBottom:
  261. return SKEncodedOrigin.LeftBottom;
  262. case ImageOrientation.BottomRight:
  263. return SKEncodedOrigin.BottomRight;
  264. case ImageOrientation.BottomLeft:
  265. return SKEncodedOrigin.BottomLeft;
  266. default:
  267. return SKEncodedOrigin.TopLeft;
  268. }
  269. }
  270. /// <summary>
  271. /// Decode an image.
  272. /// </summary>
  273. /// <param name="path">The filepath of the image to decode.</param>
  274. /// <param name="forceCleanBitmap">Whether to force clean the bitmap.</param>
  275. /// <param name="orientation">The orientation of the image.</param>
  276. /// <param name="origin">The detected origin of the image.</param>
  277. /// <returns>The resulting bitmap of the image.</returns>
  278. internal SKBitmap? Decode(string path, bool forceCleanBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)
  279. {
  280. if (!File.Exists(path))
  281. {
  282. throw new FileNotFoundException("File not found", path);
  283. }
  284. var requiresTransparencyHack = _transparentImageTypes.Contains(Path.GetExtension(path));
  285. if (requiresTransparencyHack || forceCleanBitmap)
  286. {
  287. using (var codec = SKCodec.Create(NormalizePath(path)))
  288. {
  289. if (codec == null)
  290. {
  291. origin = GetSKEncodedOrigin(orientation);
  292. return null;
  293. }
  294. // create the bitmap
  295. var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height, !requiresTransparencyHack);
  296. // decode
  297. _ = codec.GetPixels(bitmap.Info, bitmap.GetPixels());
  298. origin = codec.EncodedOrigin;
  299. return bitmap;
  300. }
  301. }
  302. var resultBitmap = SKBitmap.Decode(NormalizePath(path));
  303. if (resultBitmap == null)
  304. {
  305. return Decode(path, true, orientation, out origin);
  306. }
  307. // If we have to resize these they often end up distorted
  308. if (resultBitmap.ColorType == SKColorType.Gray8)
  309. {
  310. using (resultBitmap)
  311. {
  312. return Decode(path, true, orientation, out origin);
  313. }
  314. }
  315. origin = SKEncodedOrigin.TopLeft;
  316. return resultBitmap;
  317. }
  318. private SKBitmap? GetBitmap(string path, bool cropWhitespace, bool forceAnalyzeBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)
  319. {
  320. if (cropWhitespace)
  321. {
  322. using (var bitmap = Decode(path, forceAnalyzeBitmap, orientation, out origin))
  323. {
  324. if (bitmap == null)
  325. {
  326. return null;
  327. }
  328. return CropWhiteSpace(bitmap);
  329. }
  330. }
  331. return Decode(path, forceAnalyzeBitmap, orientation, out origin);
  332. }
  333. private SKBitmap? GetBitmap(string path, bool cropWhitespace, bool autoOrient, ImageOrientation? orientation)
  334. {
  335. if (autoOrient)
  336. {
  337. var bitmap = GetBitmap(path, cropWhitespace, true, orientation, out var origin);
  338. if (bitmap != null && origin != SKEncodedOrigin.TopLeft)
  339. {
  340. using (bitmap)
  341. {
  342. return OrientImage(bitmap, origin);
  343. }
  344. }
  345. return bitmap;
  346. }
  347. return GetBitmap(path, cropWhitespace, false, orientation, out _);
  348. }
  349. private SKBitmap OrientImage(SKBitmap bitmap, SKEncodedOrigin origin)
  350. {
  351. switch (origin)
  352. {
  353. case SKEncodedOrigin.TopRight:
  354. {
  355. var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
  356. using (var surface = new SKCanvas(rotated))
  357. {
  358. surface.Translate(rotated.Width, 0);
  359. surface.Scale(-1, 1);
  360. surface.DrawBitmap(bitmap, 0, 0);
  361. }
  362. return rotated;
  363. }
  364. case SKEncodedOrigin.BottomRight:
  365. {
  366. var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
  367. using (var surface = new SKCanvas(rotated))
  368. {
  369. float px = (float)bitmap.Width / 2;
  370. float py = (float)bitmap.Height / 2;
  371. surface.RotateDegrees(180, px, py);
  372. surface.DrawBitmap(bitmap, 0, 0);
  373. }
  374. return rotated;
  375. }
  376. case SKEncodedOrigin.BottomLeft:
  377. {
  378. var rotated = new SKBitmap(bitmap.Width, bitmap.Height);
  379. using (var surface = new SKCanvas(rotated))
  380. {
  381. float px = (float)bitmap.Width / 2;
  382. float py = (float)bitmap.Height / 2;
  383. surface.Translate(rotated.Width, 0);
  384. surface.Scale(-1, 1);
  385. surface.RotateDegrees(180, px, py);
  386. surface.DrawBitmap(bitmap, 0, 0);
  387. }
  388. return rotated;
  389. }
  390. case SKEncodedOrigin.LeftTop:
  391. {
  392. // TODO: Remove dual canvases, had trouble with flipping
  393. using (var rotated = new SKBitmap(bitmap.Height, bitmap.Width))
  394. {
  395. using (var surface = new SKCanvas(rotated))
  396. {
  397. surface.Translate(rotated.Width, 0);
  398. surface.RotateDegrees(90);
  399. surface.DrawBitmap(bitmap, 0, 0);
  400. }
  401. var flippedBitmap = new SKBitmap(rotated.Width, rotated.Height);
  402. using (var flippedCanvas = new SKCanvas(flippedBitmap))
  403. {
  404. flippedCanvas.Translate(flippedBitmap.Width, 0);
  405. flippedCanvas.Scale(-1, 1);
  406. flippedCanvas.DrawBitmap(rotated, 0, 0);
  407. }
  408. return flippedBitmap;
  409. }
  410. }
  411. case SKEncodedOrigin.RightTop:
  412. {
  413. var rotated = new SKBitmap(bitmap.Height, bitmap.Width);
  414. using (var surface = new SKCanvas(rotated))
  415. {
  416. surface.Translate(rotated.Width, 0);
  417. surface.RotateDegrees(90);
  418. surface.DrawBitmap(bitmap, 0, 0);
  419. }
  420. return rotated;
  421. }
  422. case SKEncodedOrigin.RightBottom:
  423. {
  424. // TODO: Remove dual canvases, had trouble with flipping
  425. using (var rotated = new SKBitmap(bitmap.Height, bitmap.Width))
  426. {
  427. using (var surface = new SKCanvas(rotated))
  428. {
  429. surface.Translate(0, rotated.Height);
  430. surface.RotateDegrees(270);
  431. surface.DrawBitmap(bitmap, 0, 0);
  432. }
  433. var flippedBitmap = new SKBitmap(rotated.Width, rotated.Height);
  434. using (var flippedCanvas = new SKCanvas(flippedBitmap))
  435. {
  436. flippedCanvas.Translate(flippedBitmap.Width, 0);
  437. flippedCanvas.Scale(-1, 1);
  438. flippedCanvas.DrawBitmap(rotated, 0, 0);
  439. }
  440. return flippedBitmap;
  441. }
  442. }
  443. case SKEncodedOrigin.LeftBottom:
  444. {
  445. var rotated = new SKBitmap(bitmap.Height, bitmap.Width);
  446. using (var surface = new SKCanvas(rotated))
  447. {
  448. surface.Translate(0, rotated.Height);
  449. surface.RotateDegrees(270);
  450. surface.DrawBitmap(bitmap, 0, 0);
  451. }
  452. return rotated;
  453. }
  454. default: return bitmap;
  455. }
  456. }
  457. /// <inheritdoc/>
  458. public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, ImageOrientation? orientation, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
  459. {
  460. if (inputPath.Length == 0)
  461. {
  462. throw new ArgumentException("String can't be empty.", nameof(inputPath));
  463. }
  464. if (outputPath.Length == 0)
  465. {
  466. throw new ArgumentException("String can't be empty.", nameof(outputPath));
  467. }
  468. var skiaOutputFormat = GetImageFormat(selectedOutputFormat);
  469. var hasBackgroundColor = !string.IsNullOrWhiteSpace(options.BackgroundColor);
  470. var hasForegroundColor = !string.IsNullOrWhiteSpace(options.ForegroundLayer);
  471. var blur = options.Blur ?? 0;
  472. var hasIndicator = options.AddPlayedIndicator || options.UnplayedCount.HasValue || !options.PercentPlayed.Equals(0);
  473. using (var bitmap = GetBitmap(inputPath, options.CropWhiteSpace, autoOrient, orientation))
  474. {
  475. if (bitmap == null)
  476. {
  477. throw new InvalidDataException($"Skia unable to read image {inputPath}");
  478. }
  479. var originalImageSize = new ImageDimensions(bitmap.Width, bitmap.Height);
  480. if (!options.CropWhiteSpace
  481. && options.HasDefaultOptions(inputPath, originalImageSize)
  482. && !autoOrient)
  483. {
  484. // Just spit out the original file if all the options are default
  485. return inputPath;
  486. }
  487. var newImageSize = ImageHelper.GetNewImageSize(options, originalImageSize);
  488. var width = newImageSize.Width;
  489. var height = newImageSize.Height;
  490. using (var resizedBitmap = new SKBitmap(width, height, bitmap.ColorType, bitmap.AlphaType))
  491. {
  492. // scale image
  493. bitmap.ScalePixels(resizedBitmap, SKFilterQuality.High);
  494. // If all we're doing is resizing then we can stop now
  495. if (!hasBackgroundColor && !hasForegroundColor && blur == 0 && !hasIndicator)
  496. {
  497. Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
  498. using (var outputStream = new SKFileWStream(outputPath))
  499. using (var pixmap = new SKPixmap(new SKImageInfo(width, height), resizedBitmap.GetPixels()))
  500. {
  501. pixmap.Encode(outputStream, skiaOutputFormat, quality);
  502. return outputPath;
  503. }
  504. }
  505. // create bitmap to use for canvas drawing used to draw into bitmap
  506. using (var saveBitmap = new SKBitmap(width, height)) // , bitmap.ColorType, bitmap.AlphaType))
  507. using (var canvas = new SKCanvas(saveBitmap))
  508. {
  509. // set background color if present
  510. if (hasBackgroundColor)
  511. {
  512. canvas.Clear(SKColor.Parse(options.BackgroundColor));
  513. }
  514. // Add blur if option is present
  515. if (blur > 0)
  516. {
  517. // create image from resized bitmap to apply blur
  518. using (var paint = new SKPaint())
  519. using (var filter = SKImageFilter.CreateBlur(blur, blur))
  520. {
  521. paint.ImageFilter = filter;
  522. canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint);
  523. }
  524. }
  525. else
  526. {
  527. // draw resized bitmap onto canvas
  528. canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height));
  529. }
  530. // If foreground layer present then draw
  531. if (hasForegroundColor)
  532. {
  533. if (!double.TryParse(options.ForegroundLayer, out double opacity))
  534. {
  535. opacity = .4;
  536. }
  537. canvas.DrawColor(new SKColor(0, 0, 0, (byte)((1 - opacity) * 0xFF)), SKBlendMode.SrcOver);
  538. }
  539. if (hasIndicator)
  540. {
  541. DrawIndicator(canvas, width, height, options);
  542. }
  543. Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
  544. using (var outputStream = new SKFileWStream(outputPath))
  545. {
  546. using (var pixmap = new SKPixmap(new SKImageInfo(width, height), saveBitmap.GetPixels()))
  547. {
  548. pixmap.Encode(outputStream, skiaOutputFormat, quality);
  549. }
  550. }
  551. }
  552. }
  553. }
  554. return outputPath;
  555. }
  556. /// <inheritdoc/>
  557. public void CreateImageCollage(ImageCollageOptions options)
  558. {
  559. double ratio = (double)options.Width / options.Height;
  560. if (ratio >= 1.4)
  561. {
  562. new StripCollageBuilder(this).BuildThumbCollage(options.InputPaths, options.OutputPath, options.Width, options.Height);
  563. }
  564. else if (ratio >= .9)
  565. {
  566. new StripCollageBuilder(this).BuildSquareCollage(options.InputPaths, options.OutputPath, options.Width, options.Height);
  567. }
  568. else
  569. {
  570. // TODO: Create Poster collage capability
  571. new StripCollageBuilder(this).BuildSquareCollage(options.InputPaths, options.OutputPath, options.Width, options.Height);
  572. }
  573. }
  574. private void DrawIndicator(SKCanvas canvas, int imageWidth, int imageHeight, ImageProcessingOptions options)
  575. {
  576. try
  577. {
  578. var currentImageSize = new ImageDimensions(imageWidth, imageHeight);
  579. if (options.AddPlayedIndicator)
  580. {
  581. PlayedIndicatorDrawer.DrawPlayedIndicator(canvas, currentImageSize);
  582. }
  583. else if (options.UnplayedCount.HasValue)
  584. {
  585. UnplayedCountIndicator.DrawUnplayedCountIndicator(canvas, currentImageSize, options.UnplayedCount.Value);
  586. }
  587. if (options.PercentPlayed > 0)
  588. {
  589. PercentPlayedDrawer.Process(canvas, currentImageSize, options.PercentPlayed);
  590. }
  591. }
  592. catch (Exception ex)
  593. {
  594. _logger.LogError(ex, "Error drawing indicator overlay");
  595. }
  596. }
  597. }
  598. }