]> granicus.if.org Git - graphviz/commitdiff
support an alpha channel when parsing HSV colors
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 29 Jan 2023 01:26:44 +0000 (17:26 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 29 Jan 2023 02:02:09 +0000 (18:02 -0800)
Mysteriously c4205c6e132efe64f23211fe885ff37209bc6ac0 implemented this, but only
for GVPR programs. As a result, full HSVA colors could be used in GVPR programs
but specifying an HSVA color in DOT required manually translating the color to
RGBA.

This change aligns DOT color parsing with how GVPR color parsing works.

Gitlab: closes #510
Reported-by: Ryan Schmidt <gitlab@ryandesign.com>
CHANGELOG.md
lib/common/colxlate.c
tests/test_regression.py

index 6d2c0b1c09e0b978682a722ec3b1268ab1b4faa2..a5db79d68fcac2d6ca4ed70343f32c14e09c0295 100644 (file)
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased (8.0.0)]
 
+### Added
+
+- When specifying a color in HSV format, it is now possible to give an
+  additional fourth component for the alpha channel (opacity). #510
+
 ### Changed
 
 - The VML output renderer has been removed. This format has been superseded by
index 85aa74f918c5bc9fed6fdd37f89d60ea7c725125..c4e3d5b28b4d84a9b537952127b4cb209ecc9d67 100644 (file)
@@ -326,24 +326,26 @@ int colorxlate(char *str, gvcolor_t * color, color_type_t target_type)
        }
        *q = '\0';
 
-       if (sscanf(canon, "%lf%lf%lf", &H, &S, &V) == 3) {
+       A = 1.0; // default
+       if (sscanf(canon, "%lf%lf%lf%lf", &H, &S, &V, &A) >= 3) {
            /* clip to reasonable values */
            H = fmax(fmin(H, 1.0), 0.0);
            S = fmax(fmin(S, 1.0), 0.0);
            V = fmax(fmin(V, 1.0), 0.0);
+           A = fmax(fmin(A, 1.0), 0.0);
            switch (target_type) {
            case HSVA_DOUBLE:
                color->u.HSVA[0] = H;
                color->u.HSVA[1] = S;
                color->u.HSVA[2] = V;
-               color->u.HSVA[3] = 1.0; /* opaque */
+               color->u.HSVA[3] = A;
                break;
            case RGBA_BYTE:
                hsv2rgb(H, S, V, &R, &G, &B);
                color->u.rgba[0] = (int) (R * 255);
                color->u.rgba[1] = (int) (G * 255);
                color->u.rgba[2] = (int) (B * 255);
-               color->u.rgba[3] = 255; /* opaque */
+               color->u.rgba[3] = (int) (A * 255);
                break;
            case CMYK_BYTE:
                hsv2rgb(H, S, V, &R, &G, &B);
@@ -358,14 +360,14 @@ int colorxlate(char *str, gvcolor_t * color, color_type_t target_type)
                color->u.rrggbbaa[0] = (int) (R * 65535);
                color->u.rrggbbaa[1] = (int) (G * 65535);
                color->u.rrggbbaa[2] = (int) (B * 65535);
-               color->u.rrggbbaa[3] = 65535;   /* opaque */
+               color->u.rrggbbaa[3] = (int) (A * 65535);
                break;
            case RGBA_DOUBLE:
                hsv2rgb(H, S, V, &R, &G, &B);
                color->u.RGBA[0] = R;
                color->u.RGBA[1] = G;
                color->u.RGBA[2] = B;
-               color->u.RGBA[3] = 1.0; /* opaque */
+               color->u.RGBA[3] = A;
                break;
            case COLOR_STRING:
                break;
index a486f82d79cc29c207b38c96850d0efa26b3b66c..f47efb7a57ad326da39fb3850b6eefb15efd23ba 100644 (file)
@@ -325,7 +325,6 @@ def test_358():
     assert m is not None, \
       f"font characteristic {1 << i} not enabled in xdot 1.7"
 
-@pytest.mark.xfail(strict=True)
 def test_510():
   """
   HSV colors should also support an alpha channel