Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
color / color-srgb-to-hwbOpenRuns on Liberas

sRGB to HWB

HWB of 8-bit sRGB color, exactly: {h, x: w, y: b}, with whiteness w and blackness b in 1e-2 percent (0–10000). max and min are the largest and smallest of r, g, b (0–255) and d = max − min. h, in 1e-2 degrees: none when d = 0; else H = 6000 × (g − b), plus 36000 × d when g < b, if max = r; H = 6000 × (b − r) + 12000 × d if max = g ≠ r; else H = 6000 × (r − g) + 24000 × d; h = rnd(H ÷ d), and 36000 becomes 0. w = rnd(10000 × min ÷ 255); b = rnd(10000 × (255 − max) ÷ 255). rnd(n ÷ m) is the exact quotient of non-negative integers rounded half up, so the result is exact. This is CSS Color 4's rgbToHwb of r ÷ 255, g ÷ 255, b ÷ 255 in exact arithmetic (hue none exactly when w + b reaches 100%).

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init color-srgb-to-hwb --lang rust
cd color-srgb-to-hwb && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)28 lines›
color-srgb-to-hwb.wit
package root:component;

world root {
  import liberas:color/types@0.1.0;

  export liberas:color/to-polar@0.1.0;
}
package liberas:color@0.1.0 {
  interface types {
    record rgb8 {
      r: u8,
      g: u8,
      b: u8,
    }

    record polar-e2 {
      h: option<u32>,
      x: u32,
      y: u32,
    }
  }
  interface to-polar {
    use types.{rgb8, polar-e2};

    convert: func(color: rgb8) -> polar-e2;
  }
}
Test vectors18›
color-srgb-to-hwb.cases.json
[
  {
    "args": {
      "color": {
        "b": 0,
        "g": 0,
        "r": 255
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 0,
        "g": 255,
        "r": 0
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 255,
        "g": 0,
        "r": 0
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 255,
        "g": 255,
        "r": 255
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 0,
        "g": 0,
        "r": 0
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 128,
        "g": 128,
        "r": 128
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 153,
        "g": 51,
        "r": 102
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 0,
        "g": 255,
        "r": 255
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 255,
        "g": 255,
        "r": 0
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 255,
        "g": 0,
        "r": 255
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 0,
        "g": 0,
        "r": 1
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 1,
        "g": 0,
        "r": 0
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 255,
        "g": 254,
        "r": 255
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 114,
        "g": 128,
        "r": 250
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 180,
        "g": 130,
        "r": 70
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 99,
        "g": 200,
        "r": 12
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 200,
        "g": 12,
        "r": 200
      }
    }
  },
  {
    "args": {
      "color": {
        "b": 1,
        "g": 0,
        "r": 255
      }
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 18 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 1,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.