Skip to content

How to convert to float? / add standard convert methods? #447

@tbenst

Description

@tbenst

I don't know how to convert a RGB to a tuple of UInts/Ints/floats, and it's surprisingly hard to figure this out. I don't see it documented, and when I try to find pertinent methods: methodswith(typeof(RGB{N0f8}(100/255,2/255,20/255)), supertypes=true), I get promising hits like float64 and these convert methods:

[85] convert(::Type{C}, c::Color, alpha) where C<:TransparentColor in ColorTypes at /home/tyler/.julia/packages/ColorTypes/RF8lb/src/conversions.jl:78
[86] convert(::Type{C}, c::C) where C<:Colorant in ColorTypes at /home/tyler/.julia/packages/ColorTypes/RF8lb/src/conversions.jl:72
[87] convert(::Type{C}, c::Colorant) where C<:Colorant in ColorTypes at /home/tyler/.julia/packages/ColorTypes/RF8lb/src/conversions.jl:73

float64 does not return primitive values for example. The closest I've figured out is reinterpret(UInt8, gray(Gray(RGB{N0f8}(100/255,2/255,20/255)))) but that of course isn't all three channels and seems very hard for such a simple task.

Any tips? And perhaps this should be a feature request too for these convert methods to be added

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions