MCPcopy Create free account
hub / github.com/Aleksoid1978/VideoRenderer / SaveToImage

Function SaveToImage

Source/Helper.cpp:1075–1167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1073}
1074
1075HRESULT SaveToImage(BYTE* src, const UINT pitch, const UINT width, const UINT height, const UINT bitdepth, const std::wstring_view filename)
1076{
1077 if (!src) {
1078 return E_POINTER;
1079 }
1080
1081 if (!pitch || !width || !height || !filename.length()) {
1082 return E_INVALIDARG;
1083 }
1084
1085 WICPixelFormatGUID format = {};
1086 if (bitdepth == 32) {
1087 format = GUID_WICPixelFormat32bppBGR;
1088 }
1089 else if (bitdepth == 24) {
1090 format = GUID_WICPixelFormat24bppBGR;
1091 }
1092 else if (bitdepth == 8) {
1093 format = GUID_WICPixelFormat8bppGray;
1094 }
1095 else {
1096 return E_INVALIDARG;
1097 }
1098
1099 GUID wicFormat = {};
1100 std::wstring ext;
1101 ext.assign(filename, filename.find_last_of(L"."));
1102 str_tolower(ext);
1103 if (ext == L".bmp") {
1104 wicFormat = GUID_ContainerFormatBmp;
1105 }
1106 else if (ext == L".png") {
1107 wicFormat = GUID_ContainerFormatPng;
1108 }
1109 else if (ext == L".jpg" || ext == L".jpeg") {
1110 wicFormat = GUID_ContainerFormatJpeg;
1111 }
1112 else if (ext == L".tif" || ext == L".tiff") {
1113 wicFormat = GUID_ContainerFormatTiff;
1114 }
1115 else {
1116 return E_INVALIDARG;
1117 }
1118
1119 CComPtr<IWICImagingFactory> pWICFactory;
1120 CComPtr<IWICBitmapEncoder> pEncoder;
1121 CComPtr<IWICBitmapFrameEncode> pFrame;
1122 CComPtr<IWICStream> pStream;
1123
1124 HRESULT hr = CoCreateInstance(
1125 CLSID_WICImagingFactory1, // we use CLSID_WICImagingFactory1 to support Windows 7 without Platform Update
1126 nullptr,
1127 CLSCTX_INPROC_SERVER,
1128 IID_IWICImagingFactory,
1129 (LPVOID*)&pWICFactory
1130 );
1131
1132 if (SUCCEEDED(hr)) {

Callers

nothing calls this directly

Calls 3

str_tolowerFunction · 0.85
SetSizeMethod · 0.80
InitializeMethod · 0.45

Tested by

no test coverage detected