<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
That may be explained by the endianness, though, since ARGB as 32bit uint on little-endian (what most if not all consumer pcs use) would be BGRA in memory.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
In the case of BGRA32, endianness could change it to ARGB but not ABGR or RGBA as in my test.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Either way, it should be documented how raw memory is interpreted (consecutive bytes [big-endian] or one 4 byte word per pixel [cpu dependent]).<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Von:</b> David M. Cotter <dave@kjams.com><br>
<b>Gesendet:</b> Donnerstag, 14. November 2019 21:04<br>
<b>An:</b> interest@qt-project.org <interest@qt-project.org><br>
<b>Cc:</b> Stefan Fabian <stefan.fabian.dev@hotmail.com><br>
<b>Betreff:</b> Re: [Interest] QVideoFrame 32 bit formats byte order</font>
<div> </div>
</div>
<div class="" style="word-wrap:break-word; line-break:after-white-space">I had a similar finding.<br class="">
<div><br class="">
</div>
<div>i find that <span class="" style="font-family:ProFontX; font-size:10px; background-color:rgb(255,255,255)">QImage::Format_ARGB32</span> is always 0xBBGGRRAA on both mac and windows</div>
<div><br class="">
</div>
<div>unrelated to video,  but just allocating a <span class="" style="font-family:ProFontX; font-size:10px; background-color:rgb(255,255,255)">QImage</span></div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Nov 14, 2019, at 11:54 AM, Stefan Fabian <<a href="mailto:stefan.fabian.dev@hotmail.com" class="">stefan.fabian.dev@hotmail.com</a>> wrote:</div>
<br class="x_Apple-interchange-newline">
<div class="">
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
Hey guys,</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
I'm interfacing external camera input to Qt/QML (version 5.9.5 on Ubuntu 18.04).<br class="">
For this, I'm using a custom video source and present the frames using QVideoFrame and QAbstractVideoBuffer.</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
The image is displayed in QML using a VideoOutput.<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
Since not all formats can be mapped directly, I have to do some conversions.<br class="">
The issue:<br class="">
<br class="">
The formats RGB32 and BGR32 don't act as expected.</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
According to the docs, the former is 0xffRRGGBB and the latter 0xBBGGRRff. Unfortunately, it is not specified whether the endianness of the computer is used or big-endian.<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
Here's the conversion to RGB32:<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
<pre class="" style="background-color:rgb(43,43,43); color:rgb(169,183,198); font-family:"DejaVu Sans Mono"; font-size:9pt"><span class="" style="color:rgb(204,120,50)">auto </span>output = <span class="" style="color:rgb(204,120,50)">reinterpret_cast</span><<span class="" style="color:rgb(185,188,209)">uint32_t </span>*>(*data)<span class="" style="color:rgb(204,120,50)">;<br class=""></span>iterateImage( img<span class="" style="color:rgb(204,120,50)">, </span>bytes_per_pixel<span class="" style="color:rgb(204,120,50)">, </span>[ & ]( <span class="" style="color:rgb(204,120,50)">const </span><span class="" style="color:rgb(185,188,209)">uint8_t </span>*stream )<br class="">{<br class="">  *output = (<span class="" style="color:rgb(104,151,187)">255U </span><< <span class="" style="color:rgb(104,151,187)">24U</span>) | (<span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint32_t</span>>(<span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint8_t</span>>(R( stream, 0, 255 ))) << <span class="" style="color:rgb(104,151,187)">16U</span>) |<br class="">            (<span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint32_t</span>>(<span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint8_t</span>>(G( stream, 0, 255 ))) << <span class="" style="color:rgb(104,151,187)">8U</span>) |<br class="">            <span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint32_t</span>>(<span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint8_t</span>>(B( stream, 0, 255 )))<span class="" style="color:rgb(204,120,50)">;<br class=""></span><span class="" style="color:rgb(204,120,50)">  </span>++output<span class="" style="color:rgb(204,120,50)">;<br class=""></span>} )<span class="" style="color:rgb(204,120,50)">;</span></pre>
and this is to BGR32:</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
<pre class="" style="background-color:rgb(43,43,43); color:rgb(169,183,198); font-family:"DejaVu Sans Mono"; font-size:9pt"><span class="" style="color:rgb(204,120,50)">auto </span>output = <span class="" style="color:rgb(204,120,50)">reinterpret_cast</span><<span class="" style="color:rgb(185,188,209)">uint32_t </span>*>(*data)<span class="" style="color:rgb(204,120,50)">;<br class=""></span>iterateImage( img<span class="" style="color:rgb(204,120,50)">, </span>bytes_per_pixel<span class="" style="color:rgb(204,120,50)">, </span>[ & ]( <span class="" style="color:rgb(204,120,50)">const </span><span class="" style="color:rgb(185,188,209)">uint8_t </span>*stream )<br class="">{<br class="">  *output = (<span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint32_t</span>>(<span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint8_t</span>>(B( stream, 0, 255 ))) << <span class="" style="color:rgb(104,151,187)">24U</span>) |<br class="">            (<span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint32_t</span>>(<span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint8_t</span>>(G( stream, 0, 255 ))) << <span class="" style="color:rgb(104,151,187)">16U</span>) |<br class="">            (<span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint32_t</span>>(<span class="" style="color:rgb(204,120,50)">static_cast</span><<span class="" style="color:rgb(185,188,209)">uint8_t</span>>(R( stream, 0, 255 ))) << <span class="" style="color:rgb(104,151,187)">8U</span>) |<br class="">            <span class="" style="color:rgb(104,151,187)">255U</span><span class="" style="color:rgb(204,120,50)">;<br class=""></span><span class="" style="color:rgb(204,120,50)">  </span>++output<span class="" style="color:rgb(204,120,50)">;<br class=""></span>} )<span class="" style="color:rgb(204,120,50)">;</span></pre>
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
The functions B, G, R extract the channels from the pixel at stream and map the values to the given range.</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
The problem:<br class="">
Whereas for RGB32, the image is as expected (gray), for BGR32 for some reason the image is semi-transparent red which shouldn't be possible since the B, G, R functions are the same in this case (input is a single channel image).</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
To test my hypothesis that the order is not as expected I used the following test:</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
<pre class="" style="background-color:rgb(43,43,43); color:rgb(169,183,198); font-family:"DejaVu Sans Mono"; font-size:9pt"><span class="" style="color:rgb(204,120,50)">auto </span>output = <span class="" style="color:rgb(204,120,50)">reinterpret_cast</span><<span class="" style="color:rgb(185,188,209)">uint32_t </span>*>(*data)<span class="" style="color:rgb(204,120,50)">;<br class=""></span><span class="" style="color:rgb(204,120,50)">int </span>count = img.<span class="" style="color:rgb(147,115,165)">width </span>* img.<span class="" style="color:rgb(147,115,165)">height </span>/ <span class="" style="color:rgb(104,151,187)">4</span><span class="" style="color:rgb(204,120,50)">;<br class=""></span><span class="" style="color:rgb(204,120,50)">int </span>i = <span class="" style="color:rgb(104,151,187)">0</span><span class="" style="color:rgb(204,120,50)">;<br class=""></span>iterateImage( img<span class="" style="color:rgb(204,120,50)">, </span>bytes_per_pixel<span class="" style="color:rgb(204,120,50)">, </span>[ & ]( <span class="" style="color:rgb(204,120,50)">const </span><span class="" style="color:rgb(185,188,209)">uint8_t </span>*stream )<br class="">{<br class="">  <span class="" style="color:rgb(204,120,50)">if </span>((i / count) == <span class="" style="color:rgb(104,151,187)">0</span>) *output = <span class="" style="color:rgb(104,151,187)">0xff000000</span><span class="" style="color:rgb(204,120,50)">;<br class=""></span><span class="" style="color:rgb(204,120,50)">  else if </span>((i / count) == <span class="" style="color:rgb(104,151,187)">1</span>) *output = <span class="" style="color:rgb(104,151,187)">0x00ff0000</span><span class="" style="color:rgb(204,120,50)">;<br class=""></span><span class="" style="color:rgb(204,120,50)">  else if </span>((i / count) == <span class="" style="color:rgb(104,151,187)">2</span>) *output = <span class="" style="color:rgb(104,151,187)">0x0000ff00</span><span class="" style="color:rgb(204,120,50)">;<br class=""></span><span class="" style="color:rgb(204,120,50)">  else if </span>((i / count) == <span class="" style="color:rgb(104,151,187)">3</span>) *output = <span class="" style="color:rgb(104,151,187)">0x000000ff</span><span class="" style="color:rgb(204,120,50)">;<br class=""></span><span class="" style="color:rgb(204,120,50)">  </span>++output<span class="" style="color:rgb(204,120,50)">;<br class=""></span><span class="" style="color:rgb(204,120,50)">  </span>++i<span class="" style="color:rgb(204,120,50)">;<br class=""></span>} )<span class="" style="color:rgb(204,120,50)">;</span></pre>
And indeed the image is 4 bars, from top to bottom: black, blue, green and red.<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
It appears as if the format for BGR32 (and BGRA32) is actually either 0xAABBGGRR or 0xRRGGBBAA in big-endian. Is this a (known) bug in the docs/implementation or am I missing something?<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
Best regards,</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Helvetica,sans-serif; font-size:12pt; background-color:rgb(255,255,255)">
Stefan Fabian<br class="">
</div>
<span class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; float:none; display:inline!important">_______________________________________________</span><br class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<span class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; float:none; display:inline!important">Interest
 mailing list</span><br class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<a href="mailto:Interest@qt-project.org" class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">Interest@qt-project.org</a><br class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<a href="https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.qt-project.org%2Flistinfo%2Finterest&data=02%7C01%7C%7Cba776991209a4a8e084408d7693de9e6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637093586959040603&sdata=IREvM74QjgDsDk9ERL68oEjUEtRSVGidAVE8xx%2FfMYA%3D&reserved=0" originalsrc="https://lists.qt-project.org/listinfo/interest" shash="AJAgmg2sxahN8yOJ0p4xZBGjQIDHi0H4zZOjem84YZyuwwEIK0lvr0BgRTIbXXKnIperWrKiwv+zTSrhyEAJ0RJEEt2I2uSkh58zHRtJF7XBiAT751JrSxOjnFHyG7S7S63BFspiUGqT4YYpG+UZ6fp13GS0W5Ej5H7YLY/bibg=" class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">https://lists.qt-project.org/listinfo/interest</a></div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>