GaryHuan9 / Echo

An awesome ray traced 3D renderer build in C# from scratch!
MIT License
18 stars 3 forks source link

Implement ParseRGB and ParseHDR for RGBA128.Parser #11

Closed ClemensU42 closed 2 years ago

ClemensU42 commented 2 years ago

RGBA128.Parser is a ref struct that helps converting from a string that is representing a color into an actual RGBA128. It is designed to support three modes: HEX, RGB, and HDR. Currently the mode detection and HEX mode are already implemented, but the implementation for RGB and HDR are missing.


RGB mode: Input string format rgb(123, 456, 789) where 123, 456, and 789 can be any integer between 0 (inclusive) and 256 (exclusive). After the preprocessing that determines the mode, the content field will contain the version with stripped prefix and postfix: 123, 456, 789. Determine the separation between each integer based on the comma , character. Note that there can be optional white spaces between the numbers and the commas. Use the YieldError method if any input error occurs.


HDR mode: Similar input string format hdr(0.123, 0.456, 0.789) where 0.123, 0.456, and 0.789 can be any decimal larger than or equals to 0 (no upper bound). The content field will also contain the stripped version after preprocessing: 0.123, 0.456, 0.789. Optional white spaces are also allowed.


Implement the ParseRGB and ParseHDR methods in RGBA128.Parser.