1 // Created on: 1999-12-20
3 // Copyright (c) 1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
21 // SZV/GG IMP100701 Add the "depth" field and method
22 // to the pixmap object.
27 // include windows.h first to have all definitions available
30 #include <WNT_PixMap.ixx>
32 #include <WNT_Window.hxx>
34 extern int DumpBitmapToFile (HBITMAP, const char* );
36 #include <WNT_GraphicDevice.hxx>
38 Standard_Integer WNT_PixMap::PreferedDepth(
39 const Handle(Aspect_Window)& aWindow,
40 const Standard_Integer aCDepth) const
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;
52 ///////////////////////////////////////////////////////////////////////////////////////
53 WNT_PixMap::WNT_PixMap (const Handle(Aspect_Window)& theWindow,
54 const Standard_Integer theWidth,
55 const Standard_Integer theHeight,
56 const Standard_Integer theDepth)
60 myDepth (PreferedDepth (theWindow, theDepth))
62 const Handle(WNT_Window)& hWindow = Handle(WNT_Window)::DownCast(theWindow);
63 HDC hdc = GetDC ( (HWND)(hWindow->HWindow()) );
64 HDC hdcMem = CreateCompatibleDC ( hdc );
65 ReleaseDC ( (HWND)(hWindow->HWindow()), hdc );
68 Standard_Integer theNbColors = 0, theFormat = PFD_TYPE_RGBA;
70 #ifdef BUG // Our OpenGl driver supports only RGB mode.
71 //WIL001: Color table can not be initialized - do not use
74 theNbColors = (1 << myDepth);
75 theFormat = PFD_TYPE_COLORINDEX;
79 Standard_Integer sizeBmi = Standard_Integer(sizeof(BITMAPINFO)+sizeof(RGBQUAD)*theNbColors);
80 PBITMAPINFO pBmi = (PBITMAPINFO)(new char[sizeBmi]);
81 ZeroMemory ( pBmi, sizeBmi );
83 pBmi->bmiHeader.biSize = sizeof (BITMAPINFOHEADER); //sizeBmi
84 pBmi->bmiHeader.biWidth = myWidth;
85 pBmi->bmiHeader.biHeight = myHeight;
86 pBmi->bmiHeader.biPlanes = 1;
87 pBmi->bmiHeader.biBitCount = myDepth; //WIL001: was 24
88 pBmi->bmiHeader.biCompression = BI_RGB;
91 HBITMAP hBmp = CreateDIBSection ( hdcMem, pBmi, DIB_RGB_COLORS, &ppvBits, NULL, 0 );
93 Aspect_PixmapDefinitionError::Raise ( "CreateDIBSection" );
94 SelectBitmap ( hdcMem, hBmp );
101 PIXELFORMATDESCRIPTOR pfd;
102 ZeroMemory ( &pfd, sizeof (PIXELFORMATDESCRIPTOR) );
103 pfd.nSize = sizeof (PIXELFORMATDESCRIPTOR);
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;
111 Standard_Integer iPf = ChoosePixelFormat(hdcMem, &pfd);
113 Aspect_PixmapDefinitionError::Raise ( "ChoosePixelFormat" );
115 if ( !DescribePixelFormat ( hdcMem, iPf, sizeof(PIXELFORMATDESCRIPTOR), &pfd ) )
116 Aspect_PixmapDefinitionError::Raise ( "DescribePixelFormat" );
118 if ( !SetPixelFormat(hdcMem, iPf, &pfd) )
119 Aspect_PixmapDefinitionError::Raise ( "SetPixelFormat" );
123 ///////////////////////////////
124 void WNT_PixMap::Destroy ()
126 if ( myDC ) DeleteDC ( (HDC)myDC );
127 if ( myBitmap ) DeleteObject ( (HBITMAP)myBitmap );
130 ////////////////////////////////////////////////////////////
131 Standard_Boolean WNT_PixMap::Dump (const Standard_CString theFilename,
132 const Standard_Real theGammaValue) const
134 // *** gamma correction must be implemented also on WNT system ...
135 const Handle(WNT_Window) hWindow = Handle(WNT_Window)::DownCast(myWND);
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" );
142 return DumpBitmapToFile ((HBITMAP)myBitmap, theFilename);
145 ////////////////////////////////////////////////////////////
146 Standard_Address WNT_PixMap::PixmapID() const
151 Quantity_Color WNT_PixMap::PixelColor (const Standard_Integer ,
152 const Standard_Integer ) const
154 Aspect_PixmapError::Raise ("PixelColor() method not implemented!");
155 return Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB);