Closed timholy closed 10 years ago
I also included an update to the documentation in this PR. Sorry I didn't do that earlier.
Also CCing @kmsquire, since this might help with VideoIO.
Yup, definitely useful. I'm not sure how common the various formats are in the wild, but ffmpeg/libav define all of RGBA, ARGB, BGRA, ABGR, RGB, and BGR (and possibly more), in both big endian and little endian forms (choosing the appropriate version depending on the platform).
On a little endian machine, Cairo's Uint32 colors correspond to BGRA
. But I'm wrestling with whether I want to import images (with an alpha channel) into this format by default. I think I do, but still mulling it over.
This allows one to define new concrete types that can match the memory layout expected by C libraries. I don't believe it interferes in any way with the fundamental colorimetry purpose of Color.jl. Other than inserting a layer of abstraction, I'm not adding any new types; I'm just trying to make it possible for other packages to define them and get the goodness of the conversion functions in this package.
Cairo, for example, encodes color as a Uint32. Concretely, the rule is
a<<24 | r<<16 | g<<8 | b
, which on a little-endian machine corresponds to an immutable that might look like this:You can represent this as an
AlphaColorValue{BGR{Ufixed8}, Ufixed8}
given a suitable definition ofBGR
.What's interesting is that all the colorimetry formulas remain the same, regardless of layout. All of the AbstractRGB types are to be initialized in order
(r,g,b)
, and then the type constructor is responsible for swapping the order as necessary. This preserves the "meaning" of the inputs, regardless of internal representation.This PR does include some examples of using this functionality in the new
test/layout.jl
file, but the types it defines for testing purposes are not actually in the Color module.Also in the course of thinking about memory layout, I realized that my formerly-named RGBA32 really should have been called ARGB32. So I renamed it and inserted a couple of deprecations.
CC @SimonDanisch.