colour lib needs reviewers

Manu via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 12 06:04:49 PDT 2016


On 12 September 2016 at 19:30, Basile B. via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> 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.
>>
>> I'm not sure what else should be in the scope of this lib.
>>
>> PR: https://github.com/dlang/phobos/pull/2845
>> dub: https://code.dlang.org/packages/color
>> docs:
>> http://dtest.thecybershadow.net/artifact/website-04a64e024cf75be39700bebd3a50d26f6c7bd163-7185c8ec7b15c9e785880cab6d512e6f/web/library-prerelease/std/experimental/color.html
>>
>> [...]
>> - Manu
>
>
> 1. Maybe that the each package ddoc comment should mention that everything
> is always @safe nothrow @nogc...For me it wasn't directly clear:
> - seen that there's opCast: Q: safe ?
> - seen in the sources that opCast call a templatized function
> - seen that the unittest for this function are not annotated
> - then only seen that the leading "@safe nothrow @nogc:" at the beg of the
> package.

How do you think this should this look? (it's best to leave these
comments on the PR)


> 2. Q: is there anything to convert a color to grey scale ?

This isn't a short-answer question :) .. There are many ways depending
on the job.

A simple way might be:
  L8 grey = cast(L8)RGB8(r, g, b); // L8 is luminance only, casting
will do the right thing

This is the 'normal' way, but there are better ways...

A superior way if you want a top-quality result would be to use the
Lab luminance value, since Lab is perceptually uniform, when you
desaturate, it maintains the colors relative luminance correctly,
something like:

  Lab!float lab = cast(Lab!float)RGB8(r, g, b); // cast your color to Lab
  lab.a = 0; // eliminate saturation on a axis
  lab.b = 0; // eliminate saturation on b axis
  // lab.L is now pure luminance
  RGB8 c = cast(RGB8)lab; // cast it back to RGB, and your RGB will be
greyscale, but with more perceptually correct conversion.

Lots of pow's in that conversion, so it's slower.

This link demonstrates some competing techniques:
https://en.wikipedia.org/wiki/HSL_and_HSV#/media/File:Fire-breather_CIELAB_L*.jpg
Press left/right to cycle through them.
The first method (cast to L8) is: Rec. 601 luma Y′.  (or more
accurately, my code above would be: sRGB luma Y')
The second method (Lab.L) is: CIELAB L*.

L* performs much better in low light.



More information about the Digitalmars-d mailing list