fix(convert): zero-pad each channel in RgbToHex
RgbToHex emitted a single hex digit for channel values below 0x10 because strconv.FormatInt produces the minimal representation. This broke the fixed-width hex format, the round-trip with HexToRgb, and the hex2basicMap fast path in Rgb2basic. Format each channel with %02x, matching RgbTo256.
This commit is contained in:
1 parent
9df61ac4fe
commit
f78554106d
3 files changed
+84
-1
No files matched your search
+4
-1
@@ -483,7 +483,10 @@ func RgbToHex(rgb []int) string {
|
||||
hexNodes := make([]string, 0, len(rgb))
|
||||
|
||||
for _, v := range rgb {
|
||||
hexNodes = append(hexNodes, strconv.FormatInt(int64(v), 16))
|
||||
// each channel must be two hex digits, otherwise channels below 0x10
|
||||
// are emitted as a single digit and break both the fixed-width hex
|
||||
// format and the round-trip with HexToRgb.
|
||||
hexNodes = append(hexNodes, fmt.Sprintf("%02x", v))
|
||||
}
|
||||
return strings.Join(hexNodes, "")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user