JuliaGraphics / ColorTypes.jl

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

Added Color to Array convert functions and tests #223

Closed cfitz25 closed 3 years ago

cfitz25 commented 3 years ago

Created convert functions to turn ColorTypes into Arrays, as most languages i have used typically treat colours as arrays i thought it would be useful to allow the same with Julia.

codecov[bot] commented 3 years ago

Codecov Report

Merging #223 (646cb01) into master (8d9df01) will increase coverage by 0.10%. The diff coverage is 97.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #223      +/-   ##
==========================================
+ Coverage   95.38%   95.48%   +0.10%     
==========================================
  Files           8        8              
  Lines         758      798      +40     
==========================================
+ Hits          723      762      +39     
- Misses         35       36       +1     
Impacted Files Coverage Δ
src/conversions.jl 88.63% <97.50%> (+3.85%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8d9df01...646cb01. Read the comment docs.

kimikage commented 3 years ago

I agree that this kind of conversion can be useful in specific use cases. However, in the Julia or JuliaImages ecosystem, it is not necessarily a best practice.

If you "really" need the array, it is better to construct it explicitly. As long as the convert is called directly by the user, I don't think there will be much confusion, but I'm not sure if it will be consistent when called from other methods implicitly.

cfitz25 commented 3 years ago

Any ideas what functions may break from this? I did try with converting 2d arrays of RGB to a 3d array (or more a 2d array of 1d arrays) and that appeared to work correctly atleast. Also how would i explicitly construct the array, i couldnt see how to do so? I built this to deal with frames from VideoIO which are 2d arrays of Color types, i needed to use the pixel values as arrays to apply a mathematical function.

timholy commented 3 years ago

There's an ambiguity about whether you want to reinterpret or use the constructor order. Consider ARGB: the A comes first in the list and memory order, but when constructing colors we always have the user specify the alpha channel last.

ImageCore has utilities for this: it exports reinterpretc and channelview, so you have explicit control over these things.

cfitz25 commented 3 years ago

@timholy thank you for pointing me in the right direction

timholy commented 3 years ago

OK to close this?