0

I have a program which sends images over the network. I manually create pixels (using QRgb class) and I insert them into QDataStream. It is quite easy when there are 16 or 32 bits per pixel (I can insert quint16 or quint32), but in RGB888 (24 bits per pixel) I have to use three quint8 variables. But I'm not sure the order of bytes when QDataStream has:

// output is QDataStream object
output.setByteOrder(QDataStream::BigEndian);

Should I insert in that order to correctly read this stream later?

// red, green and blue are quints8
output << blue;
output << green;
output << red;

EDIT: I know that setting BigEndian doesn't matter when I use only quint8 but I want to put colors in such order, as in the case when Qt makes byte resorting (quint32 and setByteOrder).

trivelt
  • 1,913
  • 3
  • 22
  • 44
  • If you write blue, green, red as quint8 then the byte order setting makes no difference. :-/ Byte order only matters when writing out things that are more than one byte long. So the only issue you need to deal with is who is reading. Are you writing the reading code also? If not, you have to deal with the expectations the reader has. If you are writing it, then just read in the same order you wrote. Note that BigEndian is the default; you don't need to set that. – HostileFork says dont trust SE Oct 23 '14 at 09:30
  • No, I don't write reading code. Person, who will be reading it, knows endianness, number of bits per pixel and format (RGB888, ARGB etc.) so way of reading should be the same regardless of format. – trivelt Oct 23 '14 at 09:46
  • 2
    Then it's not clear what your question is. That will put a blue byte, then a green byte, then a red byte. If that's the order the reader expects (and they are expecting a 24 bit color value in the first place), then it is the right order. If they expect a different order, it's wrong. The reader's expectation entirely defines what you have to do...if you cannot change it. They won't receive any indication of what byte order you set inside the QDataStream object; that affects the writing side only. – HostileFork says dont trust SE Oct 23 '14 at 09:50

0 Answers0