From c4d7e6060096d8d44c25867e3ee381e4e82ea2c1 Mon Sep 17 00:00:00 2001 From: Daniel Martinek Date: Thu, 26 Mar 2026 13:21:33 +0100 Subject: [PATCH] int2rgb --- more_math/Parser/UnifiedMathVisitor.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/more_math/Parser/UnifiedMathVisitor.py b/more_math/Parser/UnifiedMathVisitor.py index d038907..76bf40e 100644 --- a/more_math/Parser/UnifiedMathVisitor.py +++ b/more_math/Parser/UnifiedMathVisitor.py @@ -3431,4 +3431,20 @@ class UnifiedMathVisitor(MathExprVisitor): raise ValueError(f"{ctx.start.line}:{ctx.start.column}: Cannot convert None to a number") return float(val) - return as_float(ctx,val) \ No newline at end of file + return as_float(ctx,val) + + def visitInt_to_rgb(self,ctx): + val = (yield ctx.expr()) + return i2rgb(val) + + def i2rgb(self,val): + if self._is_list(val): + t = [] + for v in val: + t.append(i2rgb(v)) + return t + r = (val >> 16) & 0xFF + g = (val >> 8) & 0xFF + b = val & 0xFF + if self._is_tensor(val): return torch.stack([r.to(torch.float)/256, g.to(torch.float)/256, b.to(torch.float)/256], dim=-1).contiguous() + return [r/256, g/256, b/256]