I made an encoder using WIC. then i tryied to use thread for the most time consuming part. which is
/*Encodes a bitmap source*/
hr = piBitmapFrame->WriteSource(
piBitmapSrc, /*bitmap source*/
rc /*area which need to be wrote*/
);
piBitmapSrc → WICBitmap
rc → WICRect, rectangle area to do the work
This is how i tryied.
HRESULT writeSrc(
IWICBitmapFrameEncode *piBitmapFrame,
IWICBitmap *piBitmapSrc,
WICRect *rc
)
{
/*Encodes a bitmap source*/
hr = piBitmapFrame->WriteSource(
piBitmapSrc, /*bitmap source*/
rc /*area which need to be wrote*/
);
return hr;
}
and then I call it like this
const int numberOfThreads = 4;
std::thread t[numberOfThreads];
int ht = (lHeight / numberOfThreads);
WICRect rc;
rc.X = 0;
rc.Height = ht;
rc.Width = lWidth;
rc.Y = 0;
t[0] = std::thread(writeSrc, piBitmapFrame, piBitmapSrc, &rc);
rc.Y += ht;
t[1] = std::thread(writeSrc, piBitmapFrame, piBitmapSrc, &rc);
rc.Y += ht;
t[2] = std::thread(writeSrc, piBitmapFrame, piBitmapSrc, &rc);
rc.Y += ht;
rc.Height = (lHeight - (3*ht));
t[3] = std::thread(writeSrc, piBitmapFrame, piBitmapSrc, &rc);
t[0].join();
t[1].join();
t[2].join();
t[3].join();
problem is, piBitmapFrame->WriteSource()
called 4 times but only 1 returns S_OK. other 3 returns following error codes
WINCODEC_ERR_STREAMWRITE
or
WINCODEC_ERR_CODECTOOMANYSCANLINES
why is that. and how could i correctly use threads to do that