Livt packages

Eccelerators.Matrix

Version 1.0.1

Reusable RGB matrix drawing, color conversion, animation pacing, and HUB75 display components for Livt.

Published files (48)

src/ColorGain.lvt

namespace Eccelerators.Matrix

using Livt.Math.Arithmetic

/**
 * Internal percentage scaler using Livt.Math's exact scheduled division API.
 * Requires percent in 0..100; callers validate configuration before rendering.
 * One serialized caller in the inherited context. Returns round(value*percent/100).
 */
component ColorGain
{
	// Owned divider: the largest rounded numerator, 255*100+50, fits fifteen bits.
	divider: UnsignedDivision<15>

	/**
	 * Owns one divider worker, shared by the serialized channel conversions.
	 */
	new()
	{
		divider = new UnsignedDivision<15>()
	}

	/**
	 * Returns trivial identity/zero results directly. Otherwise registers the
	 * bounded product, then divides exactly through Livt.Math.
	 * The worker performs fifteen bit steps plus setup/handshake cycles.
	 * The constant divisor is nonzero and both operands fit the configured width.
	 */
	public fn Scale(value: byte, percent: byte) byte
	{
		if (percent == 100) {
			return value
		}

		if (percent == 0 || value == 0) {
			return 0
		}

		var numerator: logic[15]

		state {
			numerator = ((value as uint) * (percent as uint) + 50) as logic[15]
		}

		var quotient = divider.Divide(numerator as uint, 100 as uint)
		return quotient as byte
	}
}