Implementation of image.NRGBA64

137 views
Skip to first unread message

Scott Pakin

unread,
Sep 27, 2021, 1:53:28 PM9/27/21
to golang-nuts
I'm curious: Why does image.NRGBA64 define Pix as a []uint8 and perpetually pack pairs of uint8 values into a uint16?  Wouldn't it have been easier and faster to define Pix as a []uint16 and Stride to be a stride in uint16s rather than uint8s?

— Scott

Nigel Tao

unread,
Sep 28, 2021, 7:02:48 PM9/28/21
to Scott Pakin, golang-nuts
On Tue, Sep 28, 2021 at 3:53 AM Scott Pakin <scot...@pakin.org> wrote:
I'm curious: Why does image.NRGBA64 define Pix as a []uint8 and perpetually pack pairs of uint8 values into a uint16?  Wouldn't it have been easier and faster to define Pix as a []uint16 and Stride to be a stride in uint16s rather than uint8s?

It would have been easier for some things, but it would make it harder to work with the encoders and decoders. The compress/* and io packages work with []uint8, not []uint16.

There didn't seem to be perfect solution, only trade-offs.

Scott Pakin

unread,
Sep 28, 2021, 10:46:14 PM9/28/21
to golang-nuts
Thanks for the response.  It strikes me that the primitive NRGBA operations (get pixel, set pixel, and the like) would occur far more common in practice than encoders, decoders, compress/*, and io, but maybe that's just how I tend to use images.
Reply all
Reply to author
Forward
0 new messages