GTKD Cairo get pixel color

TheDGuy via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 5 08:25:01 PST 2016


On Tuesday, 5 January 2016 at 16:16:39 UTC, Basile B. wrote:
> On Tuesday, 5 January 2016 at 15:04:57 UTC, TheDGuy wrote:
>> But i get "only one index allowed to index char". So it looks 
>> like there is no 2D array but just a char.
>> If i try like this:
>
> The data is just a contiguous memory area. You have to 
> implement your own opIndexAssign()/opIndex() to write/read a 
> pixel at [line, column].
>
> This is basically `dataPtr + (line * width + column) * 4`.
>
> ---
> auto opIndex(size_t line, size_t column)
> {
>     auto ptr = basePtr + (line * width + column) * 4;
>     // return something at "ptr".
> }
>
> void opIndexAssign(T)(auto ref T t, size_t line, size_t column)
> {
>     auto ptr = basePtr + (line * width + column) * 4;
>     // assign t at "ptr".
> }
> ---
>
> (assuming format is ARGB, so 32bit, so "*4").

But how do i know which line or column my pixel is in? And what 
is 't' in 'opIndexAssign'?


More information about the Digitalmars-d-learn mailing list