summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@google.com>2026-06-10 08:42:45 -0700
committerRose Hogenson <rhogenson@google.com>2026-06-10 08:42:45 -0700
commit04723f34560234b1ab9aa0251ecd90a02de95c13 (patch)
tree19ad2920d2f6ecb14f09c17f87d504ce81533aa8
parent08056e02cc5332b8c2ed464e19df9ab67757cd0c (diff)
downloadsixel-04723f34560234b1ab9aa0251ecd90a02de95c13.tar.zst
Revert "Round for greater color accuracy"
This reverts commit 08056e02cc5332b8c2ed464e19df9ab67757cd0c.
-rw-r--r--sixel.go10
1 files changed, 3 insertions, 7 deletions
diff --git a/sixel.go b/sixel.go
index 04c500b..180d28c 100644
--- a/sixel.go
+++ b/sixel.go
@@ -13,16 +13,12 @@ import (
"slices"
)
-func divRound(n, d uint32) uint32 {
- return (n + d/2) / d
-}
-
type sixelRGB struct {
r, g, b int8
}
func (c sixelRGB) RGBA() (r, g, b, a uint32) {
- return divRound(uint32(c.r)*0xffff, 100), divRound(uint32(c.g)*0xffff, 100), divRound(uint32(c.b)*0xffff, 100), 0xffff
+ return uint32(c.r) * 0xffff / 100, uint32(c.g) * 0xffff / 100, uint32(c.b) * 0xffff / 100, 0xffff
}
var defaultSixelPalette color.Palette
@@ -31,7 +27,7 @@ func init() {
defaultSixelPalette = slices.Grow(color.Palette{color.Transparent}, len(palette.WebSafe))
for _, c := range palette.WebSafe {
r, g, b, _ := c.RGBA()
- defaultSixelPalette = append(defaultSixelPalette, sixelRGB{int8(divRound(r*100, 0xffff)), int8(divRound(g*100, 0xffff)), int8(divRound(b*100, 0xffff))})
+ defaultSixelPalette = append(defaultSixelPalette, sixelRGB{int8(r * 100 / 0xffff), int8(g * 100 / 0xffff), int8(b * 100 / 0xffff)})
}
}
@@ -44,7 +40,7 @@ func sixelizePalette(p color.Palette) color.Palette {
includeTransparent = true
continue
}
- result = append(result, sixelRGB{r: int8(divRound(r*100, 0xffff)), g: int8(divRound(g*100, 0xffff)), b: int8(divRound(b*100, 0xffff))})
+ result = append(result, sixelRGB{r: int8(r * 100 / 0xffff), g: int8(g * 100 / 0xffff), b: int8(b * 100 / 0xffff)})
}
if includeTransparent {
result = append(color.Palette{color.Transparent}, result...)