-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes conversion to/from Ufixed* types #63
Conversation
_convert{CV<:AbstractRGB}(::Type{CV}, c::DIN99) = _convert(CV, convert(XYZ{eltype(c)}, c)) | ||
_convert{CV<:AbstractRGB}(::Type{CV}, c::DIN99o) = _convert(CV, convert(XYZ{eltype(c)}, c)) | ||
_convert{CV<:AbstractRGB}(::Type{CV}, c::DIN99d) = _convert(CV, convert(XYZ{eltype(c)}, c)) | ||
_convert{CV<:AbstractRGB}(::Type{CV}, c::LMS) = _convert(CV, convert(XYZ{eltype(c)}, c)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the change I'm least sure about.
Previously, when converting to, e.g., RGB{Ufixed8}
, the first conversion was to, e.g., XYZ{Ufixed8}
, followed by a conversion to RGB{Ufixed8}
. This caused a loss of precision, or failure (e.g., with Lab{Ufixed8}
).
Now, the function will convert, e.g., xyY{Float32}
to XYZ{Float32}
, then to RGB{Float32}
, presumably without much loss of precision (but possibly some in the least significant digits). Would it be better to use Float64
directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt Float64
is necessary. Our dynamic range of color perception does not extend to 16 decimals of precision. Probably Float16
is sufficient...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, presumably eltype(c)
is sufficient here?
Thanks for this, it's obviously a step forward. Getting the logic of these conversions right, with so many different types, is surprisingly tricky. Thanks for cleaning up my mess! |
NP! I had actually worked my way here from julia> convert(Image{Lab}, img)
ERROR: type: Lab: in T, expected T<:FloatingPoint, got Type{UfixedBase{Uint8,8}}
in _convert at /home/kevin/.julia/v0.4/Images/src/core.jl:204
in convert at /home/kevin/.julia/v0.4/Images/src/core.jl:200 You have some pretty convoluted code in there to try to mimic triangle dispatch. :-) I worked through it somewhat, but it looks like the Color array conversion should be moved to this package, and then dealt with in a similar way to this patch. Thoughts? |
I've updated according to your comments, Tim. If there's nothing else, I'll squash and merge in a little while. |
* Previously, conversions were attempting to force conversion to, e.g., HSV{Ufixed8}, which is not a valid type
bfb34ed
to
b558a50
Compare
Looks great to me. |
Yes, the type handling was easily the trickiest part about the recent migration. If there had been an easier syntax for triangular dispatch, it would indeed have been simpler. Regarding stuff to move here, are you referring to some of the functions in |
Fixes conversion to/from Ufixed* types
ColorValue{Ufixed}
types to abstractColorValue
s (i.e., without a specified type parameter) failed (these conversions are allowed fromColorValue{FloatingPoint}
types)ColorValue{Ufixed}
toColorValue{FloatingPoint}
did not round trip well (e.g.,RGB{Ufixed8}
->Lab{Float64}
->RGB{Ufixed8}
)Previously:
With this PR:
While the behavior is obviously better, this may not be the right fix, so I would appreciate feedback.
Cc: @timholy