]> SALOME platform Git repositories - modules/gui.git/blob - src/OCCViewer/OCCViewer_Utilities.cxx
Salome HOME
Complete French translation file
[modules/gui.git] / src / OCCViewer / OCCViewer_Utilities.cxx
1 // Copyright (C) 2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // internal includes
21 #include "OCCViewer_Utilities.h"
22
23 // KERNEL includes
24 #include <Basics_OCCTVersion.hxx>
25
26 // OCC Includes
27 #include <Image_PixMap.hxx>
28
29 // QT includes
30 #include <QImage>
31
32 /*! Concert QImage to OCCT pixmap*/
33 Handle(Image_PixMap)
34 imageToPixmap( const QImage& anImage )
35 {
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 );
40
41     const uchar* aImageBytes = anImage.bits();
42       
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);
48
49             aPixmapBytes.b() = (Standard_Byte) *aImageBytes++;
50             aPixmapBytes.g() = (Standard_Byte) *aImageBytes++;
51             aPixmapBytes.r() = (Standard_Byte) *aImageBytes++;
52             aPixmapBytes.a() = (Standard_Byte) *aImageBytes++;
53           }
54 #else
55           Image_ColorBGRA* aPixmapBytes = aPixmap->EditData<Image_ColorBGRA>().ChangeRow(aLine);
56         
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++;
63             aPixmapBytes++;
64       }
65 #endif
66     }
67   }
68   return aPixmap;
69 }