Git Product home page Git Product logo

chroma's People

Contributors

edisile avatar guzba avatar narimiran avatar pietroppeter avatar tonogram avatar treeform avatar vindaar avatar zevv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

chroma's Issues

Oklab inverse transform is broken

The Oklab->RGB transform is currently broken: in the last matrix multiplication it uses the LMS components instead of the LMS^3 ones it calculates just above.

Minimal reproducible example:

import std/strutils, chroma

proc `$`(c: ColorRGB): string = "#" & c.r.toHex(2) & c.g.toHex(2) & c.b.toHex(2)
proc `$`(c: ColorOklab): string = $c.asRgb

let c = ColorRGB(r: 0, g: 255, b: 0)
echo c, c.asOklab

Expected output: #00FF00#00FF00
Actual output: #00FF00#8D0A7F

Mapping to OKLab and back significantly changes the color.

hii!

i'm struggling to use this library for some image processing and palette mapping tasks. I've found that transforming to oklab and back significantly brightens and desaturates colors.

import chroma
echo parseHex("F8DB57").to(ColorOklab).to(ColorRGB).color.toHex()
# output:      FCF4BA

Color #F8DB57 turns into #FCF4BA.

Here's some assorted roundtrips:

import chroma
import random
import strformat

proc chip(c: ColorRGB): string =
    ## nice-looking color chip for github-flavored markdown
    let hex = c.color.toHex()
    fmt"`#{hex}` <img valign='middle' alt='blue' src='https://readme-swatches.vercel.app/{hex}'/>"

randomize()
for _ in 1..10:
    let color = ColorRGB(
        r: random.rand(255).uint8,
        g: random.rand(255).uint8,
        b: random.rand(255).uint8,
    )
    let color2 = color.to(ColorOklab).to(ColorRGB)
    echo fmt"{color.chip} -> {color2.chip}"

Output:

#FF1580 blue -> #1A89CC blue
#B543B5 blue -> #E9A8E6 blue
#DBCA21 blue -> #F1EF99 blue
#28B837 blue -> #9CE9A0 blue
#E254E2 blue -> #FBB5F8 blue
#5103BC blue -> #B06BF8 blue
#3F51B2 blue -> #A0B0E7 blue
#DB26C5 blue -> #0196EF blue
#B44D3E blue -> #EAAEA1 blue
#803A22 blue -> #D09E86 blue

Each pair of colors should be identical (before converting to OkLab and after). But for many of these pairs, even the hue is wildly off.

Release new version

With the doc updates, the additions of the other color spaces and especially the Nim 1.0 release I think it'd be a good idea to release a new version of chroma, so that nimble install gives a reasonably new package.

`spin` func bug

hey, first of all I appreciate your work for Nim community. you made dozens of useful libraries.

i have a sample image named sample.png: [the background is transparent]
image

here's my code:

import pixie, chroma

var img = readImage("./sample.png")

func reverse(clr: Color, reverseAlpha = false): Color=
  Color(
    r: 255 - clr.r,
    g: 255 - clr.g, 
    b: 255 - clr.b,
    a: if reverseAlpha: 1 - clr.a else: clr.a)

for i in 0..<img.data.len:
  template clr: untyped = img.data[i]
  # clr = clr.asColor.spin(0).asRgbx # 1
  # clr = clr.asColor.reverse.asRgbx # 2
  # clr = clr.asColor.reverse.spin(0).asRgbx # 3

img.writeFile("./res.png")
  1. if I comment out the first commented line [#1] I get the same image: [which is obviously correct - it spins the colors 0 degrees]

  2. if I comment out [#2] i get this: [which is correct]
    image

  3. however, if i comment out [#3] i get this: [which is strange]:
    image


I'm really not sure if it's a bug or not, please tell me if I did anything wrong

Create a tagged release

I'm using this package in clr and would appreciate having a tagged release I could specify in my .nimble file (preferably following Semantic Versioning). I'm currently pinning a commit hash there, but it's better to rely on commits which are known to be stable and compatible ๐Ÿ™‚

feature: Grayscale

Support for grey / grayscale uint8, 16, 32, float 32 [0, 1] & alpha

transformations, conversion to: greyscale
equal weight 1/3 * r + 1/3 * g + 1/3 * b
ITU-R BT.709 (HDTV) 0.21 * r + 0.72 * g + 0.07 * b
ITU-R BT.601 (PAL) 0.299 * r + 0.587 * g + 0.114 * b
user defined weight

ITU-R BT.709 (HDTV) as default(?)

convenience operator:
let value = color(0.5,0.5,0.1).gray

in the hope it will trickle into Pixie

`nimble install chroma` lags behind `HEAD` by several commits

This is the root cause of #41.

Running nimble install chroma gets commit b2e7117, which is two years old.

$ nimble install chroma
Downloading https://github.com/treeform/chroma using git
  Verifying dependencies for [email protected]
 Installing [email protected]
  Success:  chroma installed successfully.
$ cat ~/.nimble/pkgs2/chroma-0.2.7-f873f4b97e87a82e27e0b85bf9130fe3e320a2b8/nimblemeta.json
{
  "version": 1,
  "metaData": {
    "url": "https://github.com/treeform/chroma",
    "downloadMethod": "git",
    "vcsRevision": "b2e71179174e040884ebf6a16cbac711c84620b9",
    "files": [
      "/chroma/distance.nim",
      "/chroma/csstint.nim",
      "/chroma/transformations.nim",
      "/chroma/colortypes.nim",
      "/chroma.nim",
      "/chroma/blends.nim",
      "/chroma/temperature.nim",
      "/chroma.nimble",
      "/chroma/names.nim"
    ],
    "binaries": [],
    "specialVersions": [
      "0.2.7"
    ]
  }
}

chroma-0.1.1 causing a compile-time error when attempting to compile to JS using Fidget examples (macOS)

Title says it all. When running nim js bars.nim I get the following error:

/Users/jamen/.nimble/pkgs/chroma-0.1.1/chroma/distance.nim(10, 32)
/usr/local/Cellar/nim/1.2.6/nim/lib/pure/math.nim(1014, 16) ^
/usr/local/Cellar/nim/1.2.6/nim/lib/system/arithmetics.nim(499, 9) *=
/usr/local/Cellar/nim/1.2.6/nim/lib/system/arithmetics.nim(499, 9) Error: unhandled exception: value out of range

I confirmed that this error does not occur on chroma-0.1.0 (there is no distance.nim). This seems to be specific to macOS since Nim Playground doesn't reproduce this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.