| 610 | } |
| 611 | |
| 612 | Vec4B Color::hexToVec4B(StringView s) { |
| 613 | Array<uint8_t, 4> cbytes; |
| 614 | |
| 615 | if (s.utf8Size() == 3) { |
| 616 | nibbleDecode(s.utf8Ptr(), 3, (char*)cbytes.data(), 4); |
| 617 | cbytes[0] = (cbytes[0] << 4) | cbytes[0]; |
| 618 | cbytes[1] = (cbytes[1] << 4) | cbytes[1]; |
| 619 | cbytes[2] = (cbytes[2] << 4) | cbytes[2]; |
| 620 | cbytes[3] = 255; |
| 621 | } else if (s.utf8Size() == 4) { |
| 622 | nibbleDecode(s.utf8Ptr(), 4, (char*)cbytes.data(), 4); |
| 623 | cbytes[0] = (cbytes[0] << 4) | cbytes[0]; |
| 624 | cbytes[1] = (cbytes[1] << 4) | cbytes[1]; |
| 625 | cbytes[2] = (cbytes[2] << 4) | cbytes[2]; |
| 626 | cbytes[3] = (cbytes[3] << 4) | cbytes[3]; |
| 627 | } else if (s.utf8Size() == 6) { |
| 628 | hexDecode(s.utf8Ptr(), 6, (char*)cbytes.data(), 4); |
| 629 | cbytes[3] = 255; |
| 630 | } else if (s.utf8Size() == 8) { |
| 631 | hexDecode(s.utf8Ptr(), 8, (char*)cbytes.data(), 4); |
| 632 | } else { |
| 633 | throw ColorException(strf("Improper size {} for hex string '{}' in Color::hexToVec4B", s.utf8Size(), s), false); |
| 634 | } |
| 635 | |
| 636 | return Vec4B(std::move(cbytes)); |
| 637 | } |
| 638 | |
| 639 | } |