[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] canvas-draw and colors

From: Thomas Chust
Subject: Re: [Chicken-users] canvas-draw and colors
Date: Sat, 16 Jul 2016 22:04:11 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0

On 2016-07-16 21:31, Matt Welland wrote:
> [...]
> (define (vg:rgb->number r g b #!key (a 0)) (u32vector-ref
> (blob->u32vector (u8vector->blob (list->u8vector (list a r g b)))) 0))
> [...]


this snippet seems somewhat sub-optimal to say the least. Apart from
being needlessly complicated, it may also be wrong because its result
depends on the endianness of the host platform.

I would suggest to simply use bitwise arithmetic:

    (arithmetic-shift a 24)
    (arithmetic-shift r 16)
    (arithmetic-shift g 8)

Or perhaps just normal arithmetic replacing bitwise-ior by + and
arithmetic-shift by (lambda (x n) (* x (expt 2 n))). This is probably no
less efficient, as the result is going to be a bignum anyway.


When C++ is your hammer, every problem looks like your thumb.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]