Skip to content

Commit

Permalink
ensure color format
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoCherHong committed May 5, 2023
1 parent a1fbcae commit 0d2cc40
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ List<Map<String, String>> createImageList(String fileNamePrefix) {
return imageList;
}

Color _getBackgroundColor(Config config) {
ColorUint8 _getBackgroundColor(Config config) {
final backgroundColorHex = config.backgroundColorIOS.startsWith('#')
? config.backgroundColorIOS.substring(1)
: config.backgroundColorIOS;
Expand All @@ -404,23 +404,26 @@ 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,
0xff,
);
}

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,
);
}
Expand Down

0 comments on commit 0d2cc40

Please sign in to comment.