No way to set components of a PixelRGB?


#1

It seems there’s no way to individually set the colour components of PixelRGB and PixelARGB.

This is a shame, because the only efficient way to leverage the blend() and other functions is to cast a local array of uint[3] to a PixelRGB*, which looks like ass.


#2

I guess I just never needed to do that, so never added it. I’ve no objection to adding setR(), setG() etc


#3

It’d be convenient if the data members were simply made public. This is my code now:

  void operator () (uint8* dest, uint8 const* src) const
  {
    uint8 result[3];

    result[0] = uint8 (m_mode (src[0], dest[0]));
    result[1] = uint8 (m_mode (src[1], dest[1]));
    result[2] = uint8 (m_mode (src[2], dest[2]));

    ((PixelRGB*)dest)->blend (*((PixelRGB*)result), m_alpha);
  }

I would use “PixelRGB result” instead of uint8[3].


#4

Seconded


#5

It’s not quite that simple - in PixelARGB the components are held inside a union via a struct, which is different from PixelRGB, so just exposing the members would be both messy and inconsistent in the different pixel classes.

How about an “inline uint8& getRed()” to return a reference you can write to?


#6

That works too


#7

Already checked in :slight_smile:


#8

Question about the in-memory layout of ARGB pixels. Given:

uint8 pixel [4];

where pixel represents an ARGB pixel, is it the case for all platforms that pixel[0] == blue, and pixel[3] == alpha?


#9

[quote=“TheVinn”]Question about the in-memory layout of ARGB pixels. Given:

uint8 pixel [4];

where pixel represents an ARGB pixel, is it the case for all platforms that pixel[0] == blue, and pixel[3] == alpha?[/quote]

No, there are endianness differences. That’s why I always use the PixelARGB as a wrapper around the components.


#10

Well it looks like these colour component accessor functions have arrived just in time then!


#11

I hate to bring up such a nitpick but would you be horribly opposed to adding another extra set of accessors using only the first letter (R, G, B) instead of the full colour name? i.e.

uint8& PixelRGB::getA ()
uint8& PixelRGB::getR ()
uint8& PixelRGB::getG ()
uint8& PixelRGB::getB ()

This way blending code lines up without having to add whitespace


#12

Oh come on! Honestly, I’ve got better things to do!