JuliaGraphics / ColorTypes.jl

Basic color definitions and traits
Other
77 stars 35 forks source link

InvertedGray needed for TIFF MINISWHITE #295

Closed mkitti closed 1 week ago

mkitti commented 7 months ago

I'm considering an InvertedGray <: AbstractGray type that has the intepretation that lower values correspond to white.

I encountered this need in https://github.com/tlnagy/TiffImages.jl/pull/134

mkitti commented 7 months ago

Further thought: perhaps a general Inverted{T} type would be a good idea.

tlnagy commented 7 months ago

I would support adding a general Inverted{T} type, but are there any examples of inverted RGB, etc? I haven't seen such a thing.

mkitti commented 7 months ago

I believe there is a general concept of inverting a RGB value.

https://pinetools.com/invert-color

Also we already have ColorVectorSpace.complement.

julia> using ColorVectorSpace

julia> complement(Gray(1))
Gray{N0f8}(0.0)

julia> complement(RGB(0.75, 0.25, 0))
RGB{Float64}(0.25,0.75,1.0)

Maybe this should be called Complement{T} and be a lazy version of complement?

mkitti commented 7 months ago

Now I'm wondering if we're at the wrong package. Maybe this should also be in ColorVectorSpace.jl?

tlnagy commented 7 months ago

Honestly @timholy or @johnnychen94 would know better than me, but a lazy complement might be a general solution to this.

timholy commented 7 months ago

Yeah, given that complement is in ColorVectorSpace, let's add a Complement{T,N,C<:Colorant{T,N}}} <: Colorant{T,N} there. It's a bit of a pity that we can't just call this Complement{C} and preserve the subtyping, but perhaps there's some clever typealiasing that could be done?

mkitti commented 7 months ago

Prototype is here: https://github.com/JuliaGraphics/ColorVectorSpace.jl/pull/189

kimikage commented 2 months ago

A practical case, where inverted representations other than Gray are used is CMYK. However, I am against implementing CMYK in ColorTypes.jl. (cf. https://github.com/JuliaGraphics/ColorTypes.jl/issues/179#issuecomment-616886589)

(Note that CMYK in TIFF is not a situation where Complement is needed, since TIFF recommends mapping 255 to 100% ink coverage, i.e., follows the "main-stream" representation.)

mkitti commented 1 week ago

Closing xref: https://github.com/JuliaGraphics/ColorVectorSpace.jl/pull/189#issuecomment-2198438118