Repository navigation
[csslib] Fix Rgba/Hsla ARGB conversions and keep exact alpha #2826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2884aab
[csslib] Fix Rgba/Hsla ARGB conversions and keep exact alpha
palmoni5 2f97d68
Cover alpha bytes >= 0x80 in ARGB round-trip tests
palmoni5 25a9a58
Address review feedback
palmoni5 e11a6c2
Merge remote-tracking branch 'origin/main' into land-2826
kevmoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'package:csslib/parser.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| void main() { | ||
| test('ARGB channel extraction preserves all four channels', () { | ||
| final rgba = Rgba.fromArgbValue(0x804080c0); | ||
| expect(rgba.r, 0x40); | ||
| expect(rgba.g, 0x80); | ||
| expect(rgba.b, 0xc0); | ||
| expect(rgba.a, closeTo(128 / 255, 0.00001)); | ||
| expect(rgba.argbValue, 0x804080c0); | ||
| expect(rgba.toHexArgbString(), '804080c0'); | ||
| }); | ||
|
|
||
| test('RGBA fractional alpha is encoded into 8-bit ARGB', () { | ||
| expect(Rgba(0xff, 0, 0, 0.5).argbValue, 0x80ff0000); | ||
| expect(Rgba(0xff, 0, 0, 0).argbValue, 0x00ff0000); | ||
| expect(Rgba(0xff, 0, 0, 1).argbValue, 0xffff0000); | ||
| }); | ||
|
|
||
| test('HSL to Color preserves hue and saturation', () { | ||
| expect(Hsla(0, 1, 0.5, 1).color.toHexArgbString(), 'ffff0000'); | ||
| expect(Hsla(1 / 3, 1, 0.5).color.toHexArgbString(), '00ff00'); | ||
| }); | ||
|
|
||
| test('grayscale HSL conversion preserves alpha', () { | ||
| final gray = Hsla.fromRgba(Rgba(128, 128, 128, 0.5)); | ||
| expect(gray.alpha, 0.5); | ||
| expect(gray.color.toHexArgbString(), '80808080'); | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.