Home

Awesome

Run the test suite haxelib

HSLuv - Haxe implementation

Usage

Once imported, use the library by importing HSLuv. Here's an example:

import hsluv.Hsluv;

class ReadmeTest {
    public static function main() {
        var conv = new Hsluv();
        conv.hsluv_h = 10;
        conv.hsluv_s = 75;
        conv.hsluv_l = 65;
        conv.hsluvToHex();
        trace(conv.hex); // Will print "#ec7d82"
    }
}

API functions

The API is designed in a way to avoid heap allocation. The HSLuv class defines the following public fields:

To convert between color spaces, simply set the properties of the source color space, run the conversion methods, then read the properties from the target color space.

Use the following methods to convert to and from RGB:

Use the following methods to do step-by-step conversion:

For advanced usage, we also export the bounding lines in slope-intercept format, two for each RGB channel representing the limit of the gamut.

Development

Recommended editor: VS Code with vshaxe extension.

Note that we have automated Haxe transpilation to multiple targets.

Testing

Prefered way: Haxe's builtin interpreter. Doesn't require any external libs to execute the tests:

haxe -cp src -cp test -main test.RunTests -resource test/snapshot-rev4.json@snapshot-rev4 --interp

Test using Haxe's compiler targets:

# CPP Linux
haxe -cp src -cp test -main test.RunTests -resource test/snapshot-rev4.json@snapshot-rev4 -cpp bin/cpp -cmd bin/cpp/RunTests
# CPP Windows
haxe -cp src -cp test -main test.RunTests -resource test/snapshot-rev4.json@snapshot-rev4 -cpp bin/cpp -cmd bin/cpp/RunTests.exe
# C# Linux
haxe -cp src -cp test -main test.RunTests -resource test/snapshot-rev4.json@snapshot-rev4 -cs bin/cs -cmd "mono bin/cs/bin/RunTests.exe"
# C# Windows
haxe -cp src -cp test -main test.RunTests -resource test/snapshot-rev4.json@snapshot-rev4 -cs bin/cs -cmd bin/cs/RunTests.exe
# Java
haxe -cp src -cp test -main test.RunTests -resource test/snapshot-rev4.json@snapshot-rev4 -java bin/java -cmd "java -jar bin/java/RunTests.jar"
# PHP
haxe -cp src -cp test -main test.RunTests -resource test/snapshot-rev4.json@snapshot-rev4 -php bin/php -cmd "php bin/php/index.php"
# NodeJS
haxe -cp src -cp test -main test.RunTests -resource test/snapshot-rev4.json@snapshot-rev4 -js bin/js/RunTests.js -cmd "node bin/js/RunTests.js"
# Python
haxe -cp src -cp test -main test.RunTests -resource test/snapshot-rev4.json@snapshot-rev4 -python bin/python/RunTests.py -cmd "python3 bin/python/RunTests.py"
# Lua
haxe -cp src -cp test -main test.RunTests -resource test/snapshot-rev4.json@snapshot-rev4 -lua bin/lua/RunTests.lua -cmd "lua bin/lua/RunTests.lua"

Generate snapshot

We only generate a new snapshot when we release a new revision of the color math. Then it can be used for testing this and other implementations.

haxe -cp src -cp test -main test.Snapshot --interp > snapshot.json