chicken-users
[Top][All Lists]
Advanced

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

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


From: Matt Welland
Subject: Re: [Chicken-users] canvas-draw and colors
Date: Sat, 16 Jul 2016 13:39:34 -0700

On Sat, Jul 16, 2016 at 1:04 PM, Thomas Chust <address@hidden> wrote:
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))
> [...]

Hello,

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:

  (bitwise-ior
    (arithmetic-shift a 24)
    (arithmetic-shift r 16)
    (arithmetic-shift g 8)
    b)

Nice. Blindingly obvious now that it has been pointed out. Interestingly enough it also appears to be 4x faster.

Thanks!
 
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.

Ciao,
Thomas


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

_______________________________________________
Chicken-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/chicken-users


reply via email to

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