Hello,
Here is the brief description of what you need:
#include <gdiplus.h>
#pragma comment(lib,"gdiplus.lib")
ULONG _token;
Gdiplus::GdiplusStartupInput _input;
Gdiplus::GdiplusStartup(&_token, &_input, NULL);
Gdiplus::GdiplusShutdown(_token);
Gdiplus::Bitmap * LoadImage(LPCWSTR pszFilePath)
{
return Gdiplus::Bitmap::FromFile(pszFilePath);
}
void RGB24GrayOMP(LPBYTE pRGB,CONST INT _width,CONST INT _height)
{
omp_set_num_threads(omp_get_max_threads());
#pragma omp parallel firstprivate(pRGB,_width,_height) default(none)
{
const int _thread = omp_get_thread_num();
const int _count = omp_get_num_threads();
int _last = (_height / _count);
const int _first = _last * _thread;
if (_thread == _count - 1) _last += _height % _count;
const int nStride = _width * 3;
LPBYTE pTarget = pRGB + _first * nStride;
double luma;
for (int y = 0; y < _last; y++) {
for (int x = 0; x < _width; x++) {
int pos = x * 3;
luma = (0.257 * pTarget[pos + 2]) + (0.504 * pTarget[pos + 1]) + (0.098 * pTarget[pos + 0]) + 16;
if (luma > 255) luma = 255;
pTarget[pos + 0] = (BYTE)luma;
pTarget[pos + 1] = (BYTE)luma;
pTarget[pos + 2] = (BYTE)luma;
}
pTarget += nStride;
}
}
#pragma omp barrier
}
void UpdateImage(Gdiplus::Bitmap * _bitmap)
{
using namespace Gdiplus;
BitmapData * _data = new BitmapData();
Rect _rect(0,0,_bitmap->GetWidth(),_bitmap->GetHeight());
if (Ok == _bitmap->LockBits(&_rect,ImageLockModeRead | ImageLockModeWrite,PixelFormat24bppRGB,_data))
{
RGB24GrayOMP((LPBYTE)_data->Scan0,_data->Width,_data->Height);
_bitmap->UnlockBits(_data);
}
delete _data;
}
Regards,
Maxim.