Debian Codegraph @

shortencolor.go

raw symbols SCIP
1 package png2svg
2
3 // shortenColorLossy optimizes hexadecimal color strings in a lossy way
4 func shortenColorLossy(hexColorBytes []byte) []byte {
5 if len(hexColorBytes) != 7 { // Only accept colors in the format #aabbcc
6 return hexColorBytes
7 }
8 // Just keep the first digits of each 2 digit hex number
9 return []byte{'#', hexColorBytes[1], hexColorBytes[3], hexColorBytes[5]}
10 }
11
12 // shortenColorLossless optimizes hexadecimal color strings in a lossless way
13 func shortenColorLossless(hexColorBytes []byte) []byte {
14 if len(hexColorBytes) != 7 { // Only accept colors in the format #aabbcc
15 return hexColorBytes
16 }
17 // Check for lossless compression
18 if hexColorBytes[1] == hexColorBytes[2] && hexColorBytes[3] == hexColorBytes[4] && hexColorBytes[5] == hexColorBytes[6] {
19 return []byte{'#', hexColorBytes[1], hexColorBytes[3], hexColorBytes[5]}
20 }
21 // Return the original color
22 return hexColorBytes
23 }