1 // Copyright (C) 2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "OCCViewer_Utilities.h"
24 #include <Basics_OCCTVersion.hxx>
27 #include <Image_PixMap.hxx>
32 /*! Concert QImage to OCCT pixmap*/
34 imageToPixmap( const QImage& anImage )
36 Handle(Image_PixMap) aPixmap = new Image_PixMap();
37 if ( !anImage.isNull() ) {
38 aPixmap->InitTrash( Image_PixMap::ImgBGRA, anImage.width(), anImage.height() );
39 aPixmap->SetTopDown( Standard_True );
41 const uchar* aImageBytes = anImage.bits();
43 for ( int aLine = anImage.height() - 1; aLine >= 0; --aLine ) {
44 #if OCC_VERSION_LARGE > 0x06070100
45 // convert pixels from ARGB to renderer-compatible RGBA
46 for ( int aByte = 0; aByte < anImage.width(); ++aByte ) {
47 Image_ColorBGRA& aPixmapBytes = aPixmap->ChangeValue<Image_ColorBGRA>(aLine, aByte);
49 aPixmapBytes.b() = (Standard_Byte) *aImageBytes++;
50 aPixmapBytes.g() = (Standard_Byte) *aImageBytes++;
51 aPixmapBytes.r() = (Standard_Byte) *aImageBytes++;
52 aPixmapBytes.a() = (Standard_Byte) *aImageBytes++;
55 Image_ColorBGRA* aPixmapBytes = aPixmap->EditData<Image_ColorBGRA>().ChangeRow(aLine);
57 // convert pixels from ARGB to renderer-compatible RGBA
58 for ( int aByte = 0; aByte < anImage.width(); ++aByte ) {
59 aPixmapBytes->b() = (Standard_Byte) *aImageBytes++;
60 aPixmapBytes->g() = (Standard_Byte) *aImageBytes++;
61 aPixmapBytes->r() = (Standard_Byte) *aImageBytes++;
62 aPixmapBytes->a() = (Standard_Byte) *aImageBytes++;