[Qt-interest] in fact, QImage::ARGB32 is BGRA32 ?

James Yan jyan972 at gmail.com
Wed Mar 18 09:14:46 CET 2009


OK, I C. :-)
but, in fact my buff-modify function is requested to wrote with in ANSI C,
so no Qt-way available for such case. :(

2009/3/18 Rainer Wiesenfarth <Rainer.Wiesenfarth at inpho.de>

>
> From: qt-interest-bounces at trolltech.com
> > i need to access buff of QImage and modify them directly in
> > ARGB32 format.
> > always, i found i just got error result, so i write a code to
> > test like following:
> >
> >         //play with buff of theTest
> >         unsigned char* p = theTest.bits();
> >         int            w = theTest.width();
> >         int            h = theTest.height();
> >         int            s = theTest.bytesPerLine();
> >         for(int i=0;i<h;i++)
> >         {
> >             for(int j=0;j<w;j++)
> >             {
> >                 int t = i*s + j*4;
> >
> >                 // it works in BGRA32
> >                 p[t + 0] = 0;  // change B
> >                 p[t + 1] = 0;  // change G
> >                 p[t + 2] = 0;  // change R
> >
> >                 /* my original version
> >                 p[t + 1] = 0;  // change R
> >                 p[t + 2] = 0;  // change G
> >                 p[t + 3] = 0;  // change B
> >                */
> >             }
> >         }
> >
> > so, it looks like QImage::ARGB32 is BGRA32 actually?
>
> No, you are on a platform using little endian byte order. :-)
>
> So, p[t+0] is the least significant byte of the 32bit value, and p[t+3] is
> the most significant one. Thus your "my original version" code tries to do
> BGRA32 instead of ARGB32.
>
> For both portability and readability I would like to recommend the "Qt-way"
> to set pixels:
>
>    //play with buff of theTest
>     int            w = theTest.width();
>    int            h = theTest.height();
>     for(int i=0;i<h;i++)
>    {
>          QRgb   *p = (QRgb*) theTest.scanLine(i);
>          for(int j=0;j<w;j++)
>         {
>              p[j] = qRgba (/*red=*/ 0, /*green=*/ 0, /*blue=*/ 0,
> /*alpha=*/
> 255);
>         }
>    }
>
> Best Regards / Mit freundlichen Grüßen
> Rainer Wiesenfarth
>
> --
> INPHO GmbH * Smaragdweg 1 * 70174 Stuttgart * Germany
> phone: +49 711 2288 10 * fax: +49 711 2288 111 * web: www.inpho.de
> place of business: Stuttgart * managing director: Johannes Saile
> commercial register: Stuttgart, HRB 9586
> Leader in Photogrammetry and Digital Surface Modelling
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090318/64af949f/attachment.html 


More information about the Qt-interest-old mailing list