0023426: Tool to compare two runs of tests on the same station
[occt.git] / src / WNT / WNT_PixMap.cxx
CommitLineData
b311480e 1// Created on: 1999-12-20
2// Created by: VKH
3// Copyright (c) 1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21// SZV/GG IMP100701 Add the "depth" field and method
22// to the pixmap object.
23
7fd59977 24
25//-Version
26
27// include windows.h first to have all definitions available
28#include <windows.h>
29
30#include <WNT_PixMap.ixx>
31
32#include <WNT_Window.hxx>
33
692613e5 34extern int DumpBitmapToFile (HBITMAP, const char* );
7fd59977 35
36#include <WNT_GraphicDevice.hxx>
37
38Standard_Integer WNT_PixMap::PreferedDepth(
39 const Handle(Aspect_Window)& aWindow,
40 const Standard_Integer aCDepth) const
41{
42 Standard_Integer theDepth = 32;
43 if (aCDepth <= 1) theDepth = 1;
44 else if (aCDepth <= 4) theDepth = 4;
45 else if (aCDepth <= 8) theDepth = 8;
46 else if (aCDepth <= 16) theDepth = 16;
47 else if (aCDepth <= 24) theDepth = 24;
48
49 return theDepth;
50}
51
52///////////////////////////////////////////////////////////////////////////////////////
692613e5 53WNT_PixMap::WNT_PixMap (const Handle(Aspect_Window)& theWindow,
54 const Standard_Integer theWidth,
55 const Standard_Integer theHeight,
56 const Standard_Integer theDepth)
57: myWND (theWindow),
58 myWidth (theWidth),
59 myHeight (theHeight),
60 myDepth (PreferedDepth (theWindow, theDepth))
7fd59977 61{
692613e5 62 const Handle(WNT_Window)& hWindow = Handle(WNT_Window)::DownCast(theWindow);
7fd59977 63 HDC hdc = GetDC ( (HWND)(hWindow->HWindow()) );
64 HDC hdcMem = CreateCompatibleDC ( hdc );
65 ReleaseDC ( (HWND)(hWindow->HWindow()), hdc );
66 myDC = hdcMem;
67
68 Standard_Integer theNbColors = 0, theFormat = PFD_TYPE_RGBA;
69
70#ifdef BUG // Our OpenGl driver supports only RGB mode.
71 //WIL001: Color table can not be initialized - do not use
72 if (myDepth <= 8)
73 {
74 theNbColors = (1 << myDepth);
75 theFormat = PFD_TYPE_COLORINDEX;
76 }
77#endif
78
79 Standard_Integer sizeBmi = Standard_Integer(sizeof(BITMAPINFO)+sizeof(RGBQUAD)*theNbColors);
80 PBITMAPINFO pBmi = (PBITMAPINFO)(new char[sizeBmi]);
81 ZeroMemory ( pBmi, sizeBmi );
82
83 pBmi->bmiHeader.biSize = sizeof (BITMAPINFOHEADER); //sizeBmi
692613e5 84 pBmi->bmiHeader.biWidth = myWidth;
85 pBmi->bmiHeader.biHeight = myHeight;
7fd59977 86 pBmi->bmiHeader.biPlanes = 1;
87 pBmi->bmiHeader.biBitCount = myDepth; //WIL001: was 24
88 pBmi->bmiHeader.biCompression = BI_RGB;
89
90 LPVOID ppvBits;
91 HBITMAP hBmp = CreateDIBSection ( hdcMem, pBmi, DIB_RGB_COLORS, &ppvBits, NULL, 0 );
92 if ( !hBmp )
93 Aspect_PixmapDefinitionError::Raise ( "CreateDIBSection" );
94 SelectBitmap ( hdcMem, hBmp );
95 myBitmap = hBmp;
96
97 delete[] pBmi;
98
99 if (myDepth > 1) {
100
101 PIXELFORMATDESCRIPTOR pfd;
102 ZeroMemory ( &pfd, sizeof (PIXELFORMATDESCRIPTOR) );
103 pfd.nSize = sizeof (PIXELFORMATDESCRIPTOR);
104 pfd.nVersion = 1;
105 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_BITMAP;
106 pfd.iPixelType = theFormat; //WIL001: was PFD_TYPE_RGBA
107 pfd.cColorBits = myDepth; //WIL001: was 24
108 pfd.cDepthBits = 24;//
109 pfd.iLayerType = PFD_MAIN_PLANE;
110
111 Standard_Integer iPf = ChoosePixelFormat(hdcMem, &pfd);
112 if ( !iPf )
113 Aspect_PixmapDefinitionError::Raise ( "ChoosePixelFormat" );
114
115 if ( !DescribePixelFormat ( hdcMem, iPf, sizeof(PIXELFORMATDESCRIPTOR), &pfd ) )
116 Aspect_PixmapDefinitionError::Raise ( "DescribePixelFormat" );
117
118 if ( !SetPixelFormat(hdcMem, iPf, &pfd) )
119 Aspect_PixmapDefinitionError::Raise ( "SetPixelFormat" );
120 }
121}
122
123///////////////////////////////
124void WNT_PixMap::Destroy ()
125{
126 if ( myDC ) DeleteDC ( (HDC)myDC );
127 if ( myBitmap ) DeleteObject ( (HBITMAP)myBitmap );
128}
129
130////////////////////////////////////////////////////////////
692613e5 131Standard_Boolean WNT_PixMap::Dump (const Standard_CString theFilename,
132 const Standard_Real theGammaValue) const
7fd59977 133{
134 // *** gamma correction must be implemented also on WNT system ...
135 const Handle(WNT_Window) hWindow = Handle(WNT_Window)::DownCast(myWND);
136
137 Handle(WNT_GraphicDevice) dev =
138 Handle ( WNT_GraphicDevice )::DownCast ( hWindow->MyGraphicDevice );
139 if ( dev.IsNull() ) return Standard_False;
140 //Aspect_PixmapError::Raise ( "WNT_GraphicDevice is NULL" );
141
692613e5 142 return DumpBitmapToFile ((HBITMAP)myBitmap, theFilename);
7fd59977 143}
144
145////////////////////////////////////////////////////////////
146Standard_Address WNT_PixMap::PixmapID() const
147{
148 return myDC;
149}
150
151Quantity_Color WNT_PixMap::PixelColor (const Standard_Integer ,
152 const Standard_Integer ) const
153{
154 Aspect_PixmapError::Raise ("PixelColor() method not implemented!");
155 return Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB);
156}