{"id":18334778,"url":"https://github.com/importryan/oklab","last_synced_at":"2025-09-13T15:43:43.064Z","repository":{"id":107425649,"uuid":"348501049","full_name":"importRyan/Oklab","owner":"importRyan","description":"Björn Ottosson's Oklab perceptual color space in Swift","archived":false,"fork":false,"pushed_at":"2021-05-30T22:18:38.000Z","size":18,"stargazers_count":39,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-06T04:33:39.470Z","etag":null,"topics":["color","colorspace","colorspaces","oklab","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/importRyan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-16T21:49:14.000Z","updated_at":"2025-03-26T03:03:01.000Z","dependencies_parsed_at":"2023-05-17T11:00:31.459Z","dependency_job_id":null,"html_url":"https://github.com/importRyan/Oklab","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importRyan%2FOklab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importRyan%2FOklab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importRyan%2FOklab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importRyan%2FOklab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/importRyan","download_url":"https://codeload.github.com/importRyan/Oklab/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importRyan%2FOklab/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259053511,"owners_count":22798438,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color","colorspace","colorspaces","oklab","swift"],"created_at":"2024-11-05T19:52:23.394Z","updated_at":"2025-06-10T10:07:45.575Z","avatar_url":"https://github.com/importRyan.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Oklab\n\nSwift implementation of Björn Ottosson's Oklab perceptual color space for image processing.\n\nLearn more:\n\n- [From Björn](https://bottosson.github.io/posts/oklab/)\n- [Review by Raph Levien](https://raphlinus.github.io/color/2021/01/18/oklab-critique.html)\n\u003cbr\u003e\u003cbr\u003e\n\n![Color space Munsell comparisons](https://i.imgur.com/6oUoU1Q.png \"Comparisons\")\n\u003cbr\u003e\u003cbr\u003e\n\n## How to use\n\nInits move any `NSColor` `UIColor` `Color` `CIColor` or `CGColor` to the Oklab color space. Conversion uses `simd`. \n\n```swift\nimport Oklab\n\nlet black      = NSColor.black\n\nlet oklab      = OklabColor(ns: black)\nlet stillBlack = NSColor(oklab)\n\nlet polar      = OklabColorPolar(ns: black)\nlet stillBlack = NSColor(polar)\n```\n\nManipulating hue and chroma is easy with a polar Oklab color. The idea behind Oklab is that shifts in hue do not change perceived brightness or chroma. While hue is stored in radians, a few functions help manipulate hue in degrees.\n\n```swift\nlet pink = OklabColorPolar(lightness: 0.5, chroma: 0.24, hueDegrees: 0)\nlet blue = pink.withHueRotatedBy(degrees: 240)\n\nlet cartesian = OklabColor(lightness: 0.5, a: 0.2, b: 0.1, alpha: 1)\nvar polar     = OklabColorPolar(cartesian)\npolar.setHueTo(degrees: 120)\npolar.setHueRotatedBy(degrees: -90)\n\n// Cartesian colors also report chroma and hue\nlet hueAngle = cartesian.getHueAngleDegrees()\nlet hueAngle = cartesian.getHueAngleRadians()\nlet chroma   = cartesian.getChroma()\n```\n\n\nThe `OklabColor` and `OklabPolarColor` structs are defined as below. `Channel` is a typealias for `Float`. For an idea about the ranges for the `a` and `b` channels, see Björn's Munsell plot preserved above or [on his GitHub.](https://bottosson.github.io/img/oklab/oklab_munsell.png)\n\n```swift\nstruct OklabColor {\n\n    /// Perceptual lightness. To achieve pure black or white, \n    /// also adjust chroma (polar) or a/b channels (cartesian).\n    var lightness: Channel\n    \n    /// Green to red. \n    /// Range can span about -0.6...0.6 in medium brightness.\n    var a: Channel\n    \n    /// Yellow to blue. \n    /// Range can span about -0.55...0.8 in medium brightness.\n    var b: Channel\n    \n    /// Opacity 0...1\n    var alpha: Channel\n    \n    /// Vector construct of Lab channels for SIMD-based calculations\n    var vector: SIMD3\u003cChannel\u003e {\n        SIMD3\u003cChannel\u003e(lightness, a, b)\n    }\n}\n\n```\n```swift\nstruct OklabColorPolar {\n    \n    /// Perceived lightness\n    var lightness: Channel\n    \n    ///  Chroma\n    var chroma: Channel\n    \n    /// Set in the 0...2π range when converted from a cartesian color\n    var hueRadians: Channel\n    \n    var hueDegrees: Channel {\n        var degrees = hueRadians * 180 / .pi\n        \n        while degrees \u003c 0   { degrees += 360 }\n        while degrees \u003e 360 { degrees -= 360 }\n        return degrees\n    }\n    \n    /// Alpha 0...1\n    var alpha: Channel\n}\n```\n\nThat's all folks.\n\u003cbr\u003e\u003cbr\u003e\n\n## License (\"MIT\")\n\nSwift implementation is Copyright (c) 2021 Ryan Ferrell under the license below.\n\nOklab is Copyright (c) 2020 Björn Ottosson. \n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimportryan%2Foklab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimportryan%2Foklab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimportryan%2Foklab/lists"}