| 173 | } |
| 174 | |
| 175 | HBITMAP LoadJPEGFile(LPCWSTR filePath) { |
| 176 | if (!$WICConvertBitmapSource) { |
| 177 | HMODULE windowscodecs = LoadLibrary(L"windowscodecs.dll"); |
| 178 | if (windowscodecs) { |
| 179 | $WICConvertBitmapSource = (_WICConvertBitmapSource)GetProcAddress(windowscodecs, "WICConvertBitmapSource"); |
| 180 | } |
| 181 | if (!$WICConvertBitmapSource) { |
| 182 | return NULL; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | if (!$SHCreateStreamOnFileEx) { |
| 187 | HMODULE shlwapi = LoadLibrary(L"shlwapi.dll"); |
| 188 | if (shlwapi) { |
| 189 | $SHCreateStreamOnFileEx = (_SHCreateStreamOnFileEx)GetProcAddress(shlwapi, "SHCreateStreamOnFileEx"); |
| 190 | } |
| 191 | if (!$SHCreateStreamOnFileEx) { |
| 192 | return NULL; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | IStream *imageStream = NULL; |
| 197 | HRESULT hr = $SHCreateStreamOnFileEx(filePath, STGM_READ, FILE_ATTRIBUTE_NORMAL, FALSE, NULL, &imageStream); |
| 198 | if (!SUCCEEDED(hr)) { |
| 199 | CHECK_HR(L"SHCreateStreamOnFileEx failed"); |
| 200 | return NULL; |
| 201 | } |
| 202 | |
| 203 | IWICBitmapSource *bitmap = GetWICBitmap(imageStream, &CLSID_WICJpegDecoder); |
| 204 | if (!bitmap) { |
| 205 | hr = HRESULT_FROM_WIN32(GetLastError()); |
| 206 | CHECK_HR(L"GetWICBitmap failed"); |
| 207 | IStream_Release(imageStream); |
| 208 | return NULL; |
| 209 | } |
| 210 | |
| 211 | HBITMAP result = GetHBitmapForWICBitmap(bitmap); |
| 212 | IWICBitmapSource_Release(bitmap); |
| 213 | IStream_Release(imageStream); |
| 214 | return result; |
| 215 | } |
| 216 | |
| 217 | BOOL ScaleAndWriteToBMP(HBITMAP hBitmap, DWORD width, DWORD height, LPCWSTR outputPath) { |
| 218 | BOOL result = FALSE; |
no test coverage detected