MCPcopy Create free account
hub / github.com/DentonW/DevIL / LoadImage

Method LoadImage

DevIL/test/DDrawTest/SOURCE/beSurface.cpp:98–167  ·  view source on GitHub ↗

============================================================// LoadImage() ============================================================//

Source from the content-addressed store, hash-verified

96// LoadImage()
97//============================================================//
98bool beSurface::LoadImage(HBITMAP image, bool bSystemMemory)
99{
100 HRESULT result;
101 HBITMAP oldBitmap;
102
103 // release old surface
104 beSafeRelease(m_pSurface);
105
106 // get DirectDraw interface
107 if (m_pScreen == NULL) return false;
108
109 beDirectDraw * p_dd = m_pScreen->GetDirectDraw();
110 if (p_dd == NULL) return false;
111
112 HDC srcDC = NULL;
113 HDC destDC = NULL;
114
115 if (image == NULL)
116 goto RELEASE;
117
118 // get bitmap description
119 BITMAP bmpDesc;
120 ::GetObject(image, sizeof(bmpDesc), &bmpDesc);
121
122 // create surface
123 if (!CreateSurface(bmpDesc.bmWidth, bmpDesc.bmHeight, bSystemMemory))
124 goto RELEASE;
125
126 // copy image into surface
127 result = m_pSurface->GetDC(&destDC);
128 if (FAILED(result)) goto RELEASE;
129
130 // create GDI DC
131 srcDC = CreateCompatibleDC(NULL);
132 if (srcDC == NULL) goto RELEASE;
133
134 // blit image into surface
135 oldBitmap = (HBITMAP) SelectObject(srcDC, image);
136 BitBlt(destDC, 0, 0, bmpDesc.bmWidth, bmpDesc.bmHeight, srcDC, 0, 0, SRCCOPY);
137 SelectObject(srcDC, oldBitmap);
138
139 m_iWidth = bmpDesc.bmWidth;
140 m_iHeight = bmpDesc.bmHeight;
141
142 // delete GDI DC
143 DeleteDC(srcDC);
144 srcDC = NULL;
145
146 // release surface DC
147 m_pSurface->ReleaseDC(destDC);
148 destDC = NULL;
149
150 // delete DIB section
151 //::DeleteObject(image);
152
153 return true;
154
155RELEASE:

Callers 2

WndProcFunction · 0.45
InitAppFunction · 0.45

Calls 1

GetDirectDrawMethod · 0.80

Tested by

no test coverage detected