colour lib needs reviewers

Random D user via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 12 13:29:03 PDT 2016


On Monday, 12 September 2016 at 04:14:27 UTC, Manu wrote:
> I think I'm about as happy with my colour lib as I'm going to 
> be. It really needs reviews.
>
> - Manu

Hi. I'm just a random forum lurker, but here's my feedback.

It needs more docs/examples for the basic usage cases (i.e. how 
to skip docs and start working).

Now at first glance it looks like working with RGBA (most common 
case (with srgb)) is complicated and while reading the docs I 
kind of felt like I'd just write my own.

Few basic things I'd be interested in (examples):
1. How to pack/unpack color into uint/rgba channels. Also can I 
swizzle channels directly? How would I extract a single channel 
from color?
2. Can I just cast an array of bytes into a RGBA array and 
operate on that?
3. How to scale color channels e.g. 5 bits to 8 bits and vice 
versa. How to convert color formats? Can I combine 
scale/conversion with single channel or channel swizzling?
4. Which way are RGBA format names defined ("byte array order" r 
is first byte or "uint order" r is in high bits)?
5. Is it the same for packed rgba formats?
I'm not sure if packedrgb is a necessary distinction. Aren't they 
all kind of packed (small structs)? There's no guarantee that 1 
byte is not just a part of a bigger field.

Btw. Your RGBA8 example is a bit weird:
static assert(RGBA8("0x908000FF") == RGBA8(0x80,0x00,0xFF,0x90));
I'd assume RGBA8(r,g,b,a) would be either "uint order" r(0x90), 
g(0x80), b(0x00), a(0xFF) or "byte array order" (le) r(0xFF), 
g(0x00), b(0x80), a(0x90)

6. Perhaps you should define all the usual color formats, since 
everybody and their cat has their own preference for rgba channel 
orders.
In my experience all these 4 variants for RGBA8888 are pretty 
common:
RGBA8888
BGRA8888
ARGB8888
ABGR8888
and their X and 24bit variants.

For 16 bits fairly common are:
RGB565 and RGBA5551, also sometimes you see one of RGBA4444 
permutations (like RGBA8 above).
Also L16 is pretty common for heightfields or other data 
images/textures.

I guess there are also planar formats, but I think those are more 
of a Image problem space.

Just as a completely random idea - How about aliases for HDR 
formats like HDR10 and Dolby Vision? Kind of looks like they're 
just combinations what you already have.


More information about the Digitalmars-d mailing list