From 1f827214d287e02f4527535c5349db6afbae902f Mon Sep 17 00:00:00 2001 From: Steven Robertson Date: Sun, 18 Dec 2011 11:30:52 -0500 Subject: [PATCH] Round and clamp palette before encoding --- cuburn/genome.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cuburn/genome.py b/cuburn/genome.py index 27857bd..6b60985 100644 --- a/cuburn/genome.py +++ b/cuburn/genome.py @@ -105,7 +105,8 @@ def palette_encode(data, format='rgb8'): """ if format != 'rgb8': raise NotImplementedError - enc = base64.b64encode(np.uint8(data[:,:3]*255.0)) + clamp = np.maximum(0, np.minimum(255, np.round(data[:,:3]*255.0))) + enc = base64.b64encode(np.uint8(clamp)) return ['rgb8'] + [enc[i:i+64] for i in range(0, len(enc), 64)] class _AttrDict(dict):