From 0d2cc408853504b3dd819c093e60d5a7b5aaec18 Mon Sep 17 00:00:00 2001 From: Hao-Cher Hong Date: Fri, 5 May 2023 19:00:48 +0800 Subject: [PATCH] ensure color format --- lib/ios.dart | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/ios.dart b/lib/ios.dart index 48c7f9227e..1339de35e3 100644 --- a/lib/ios.dart +++ b/lib/ios.dart @@ -395,7 +395,7 @@ List> createImageList(String fileNamePrefix) { return imageList; } -Color _getBackgroundColor(Config config) { +ColorUint8 _getBackgroundColor(Config config) { final backgroundColorHex = config.backgroundColorIOS.startsWith('#') ? config.backgroundColorIOS.substring(1) : config.backgroundColorIOS; @@ -404,7 +404,7 @@ Color _getBackgroundColor(Config config) { } final backgroundByte = int.parse(backgroundColorHex, radix: 16); - return ColorRgba8( + return ColorUint8.rgba( (backgroundByte >> 16) & 0xff, (backgroundByte >> 8) & 0xff, (backgroundByte >> 0) & 0xff, @@ -412,15 +412,18 @@ Color _getBackgroundColor(Config config) { ); } -Color _alphaBlend(Color fg, Color bg) { +Color _alphaBlend(Color fg, ColorUint8 bg) { + if (fg.format != Format.uint8) { + fg = fg.convert(format: Format.uint8); + } if (fg.a == 0) { return bg; } else { final invAlpha = 0xff - fg.a; - return ColorRgba8( - (fg.g * fg.r + invAlpha * bg.g) ~/ 0xff, - (fg.a * fg.r + invAlpha * bg.a) ~/ 0xff, - (fg.b * fg.r + invAlpha * bg.b) ~/ 0xff, + return ColorUint8.rgba( + (fg.a * fg.r + invAlpha * bg.g) ~/ 0xff, + (fg.a * fg.g + invAlpha * bg.a) ~/ 0xff, + (fg.a * fg.b + invAlpha * bg.b) ~/ 0xff, 0xff, ); }