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/WhiteBalanceColorConverter.lvt

namespace Eccelerators.Matrix

/**
 * Scales RGB888 channels in their existing color space. Prefer linear-light input.
 * Gains are percentages 0..100, default 100 after reset. Round to nearest byte.
 * One serialized caller; configure only between complete images.
 */
component WhiteBalanceColorConverter : IColorConverter
{
	// Owned bounded arithmetic and active channel gain configuration.
	gain: ColorGain
	red: byte
	green: byte
	blue: byte

	/**
	 * Initializes unity gain in the inherited context.
	 */
	new()
	{
		gain = new ColorGain()
		red = 100
		green = 100
		blue = 100
	}

	/**
	 * Accepts percentages 0..100. Invalid input leaves all settings unchanged.
	 */
	public fn Configure(red: uint, green: uint, blue: uint) bool
	{
		if (red > 100 || green > 100 || blue > 100) {
			return false
		}

		this.red = red as byte
		this.green = green as byte
		this.blue = blue as byte
		return true
	}

	/**
	 * Scales each byte with round-to-nearest arithmetic; output remains RGB888.
	 */
	override fn Convert(rgb: logic[24]) logic[24]
	{
		var value = rgb as uint
		var r = gain.Scale((value / 65536 % 256) as byte, red)
		var g = gain.Scale((value / 256 % 256) as byte, green)
		var b = gain.Scale((value % 256) as byte, blue)
		return MatrixColor.Rgb(r, g, b)
	}
}