From 38533cdc4af15d25fe507fcd73ae993a2d323946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 30 Mar 2014 21:40:51 +0200 Subject: [PATCH] fixed instability in table packing/unpacking as suggested in #184 --- src/main/scala/li/cil/oc/util/PackedColor.scala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/scala/li/cil/oc/util/PackedColor.scala b/src/main/scala/li/cil/oc/util/PackedColor.scala index 99a67a448..f7756b737 100644 --- a/src/main/scala/li/cil/oc/util/PackedColor.scala +++ b/src/main/scala/li/cil/oc/util/PackedColor.scala @@ -47,16 +47,16 @@ object PackedColor { private val rScale = 255.0 / ((1 << rBits) - 1) def inflate(value: Int) = { - val r = ((((value & rMask) >>> rShift) * rScale).toInt << rShift32) & rMask32 - val g = ((((value & gMask) >>> gShift) * gScale).toInt << gShift32) & gMask32 - val b = ((((value & bMask) >>> bShift) * bScale).toInt << bShift32) & bMask32 + val r = ((((value & rMask) >>> rShift) * rScale + 0.5).toInt << rShift32) & rMask32 + val g = ((((value & gMask) >>> gShift) * gScale + 0.5).toInt << gShift32) & gMask32 + val b = ((((value & bMask) >>> bShift) * bScale + 0.5).toInt << bShift32) & bMask32 r | g | b } def deflate(value: Int) = { - val r = ((((value & rMask32) >>> rShift32) / rScale).toInt << rShift) & rMask - val g = ((((value & gMask32) >>> gShift32) / gScale).toInt << gShift) & gMask - val b = ((((value & bMask32) >>> bShift32) / bScale).toInt << bShift) & bMask + val r = ((((value & rMask32) >>> rShift32) / rScale + 0.5).toInt << rShift) & rMask + val g = ((((value & gMask32) >>> gShift32) / gScale + 0.5).toInt << gShift) & gMask + val b = ((((value & bMask32) >>> bShift32) / bScale + 0.5).toInt << bShift) & bMask r | g | b } }