Coder Social home page Coder Social logo

Comments (9)

timholy avatar timholy commented on May 24, 2024

History-wise, I think these were added by people who are mostly doing HTML stuff and thus writing out JSON strings.

But we did eventually develop a more Julian approach:

julia> using Colors

julia> colorant"indianred"
RGB{N0f8}(0.804,0.361,0.361)

This actually does the work at compile-time, so performance-wise is equivalent to inserting the constant RGB{N0f8}(0.804,0.361,0.361). However, it requires an explicit color name; if you want to parse this for a variable, then use parse(Colorant, cname) where cname is a string.

I see the docs make this a bit confusing. Would you by any chance be willing to submit a pull request that clarifies this?

from colors.jl.

scls19fr avatar scls19fr commented on May 24, 2024

PR submitted.

but maybe this part of doc could be a good place to show how to convert to RGB{N0f32} (for example)

but it could also be in https://github.com/JuliaGraphics/ColorTypes.jl

from colors.jl.

scls19fr avatar scls19fr commented on May 24, 2024
RGB{N0f32}(colorant"indianred")

from colors.jl.

timholy avatar timholy commented on May 24, 2024

@scls19fr, why would convert to RGB{N0f32}? Do you realize that is 96-bit color? Did you actually mean to convert to RGB24 by any chance?

from colors.jl.

scls19fr avatar scls19fr commented on May 24, 2024

oh yes... that's a bit overkilled

from colors.jl.

scls19fr avatar scls19fr commented on May 24, 2024

Given values in tuples, I'm wondering if

https://github.com/JuliaGraphics/Colors.jl/blob/0f4c744902f22fb73776e50e839a2bf8ebfdc9d6/src/names_data.jl

shouldn't be changed from Int64 to UInt8

from colors.jl.

timholy avatar timholy commented on May 24, 2024

I'm less worried about the data type and more about the value; should we use 1.0 instead of 255?

The current conversions (including reinterpreting as N0f8) are done algorithmically here:

Colors.jl/src/parse.jl

Lines 108 to 110 in 33ce6c0

return RGB{N0f8}(reinterpret(N0f8, UInt8(c[1])),
reinterpret(N0f8, UInt8(c[2])),
reinterpret(N0f8, UInt8(c[3])))
.

from colors.jl.

scls19fr avatar scls19fr commented on May 24, 2024

Working with float can lead to numerical issues...

this kind of values should be stored in a structure which can store for example fractional values (1/3 for example)

My 2 cts

from colors.jl.

timholy avatar timholy commented on May 24, 2024

Just FYI that table is only for internal use anyway, I don't think there's anything about it that leaks out to the user. By reinterpreting as N0f8 we're effectively storing all of them at ratios with denominator 255.

julia> colorant"indianred"
RGB{N0f8}(0.804,0.361,0.361)

julia> dump(colorant"indianred")
RGB{FixedPointNumbers.Normed{UInt8,8}}
  r: FixedPointNumbers.Normed{UInt8,8}
    i: UInt8 0xcd
  g: FixedPointNumbers.Normed{UInt8,8}
    i: UInt8 0x5c
  b: FixedPointNumbers.Normed{UInt8,8}
    i: UInt8 0x5c

from colors.jl.

Related Issues (20)

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.