I have a simple algorithm that converts a bayer image channel (BGGR, RGGB, GBRG, GRBG) to rgb (demosaicing, but without neighbors). In my implementation, I have predefined offset vectors that help me translate the bayer channel index into their corresponding rgb channel indices. The only problem is that I get terrible debugging performance using MSVC11. In the release section, to enter 3264X2540 size, the function ends in ~ 60 ms. For the same input in debugging, the function ends in ~ 20,000 ms. This is more than the difference in the X300, and since some developers run my application in debugging, this is unacceptable.
My code is:
void ConvertBayerToRgbImageDemosaic(int* BayerChannel, int* RgbChannel, int Width, int
Height, ColorSpace ColorSpace)
{
int rgbOffsets[4];
std::vector<int> bayerToRgbOffsets[4];
switch (ColorSpace)
{
case ColorSpace::BGGR:
rgbOffsets[0] = 2;
rgbOffsets[1] = 1;
rgbOffsets[2] = 1;
rgbOffsets[3] = 0;
bayerToRgbOffsets[0].push_back(0);
bayerToRgbOffsets[0].push_back(1);
bayerToRgbOffsets[0].push_back(Width);
bayerToRgbOffsets[0].push_back(Width + 1);
bayerToRgbOffsets[1].push_back(-1);
bayerToRgbOffsets[1].push_back(0);
bayerToRgbOffsets[2].push_back(0);
bayerToRgbOffsets[2].push_back(1);
bayerToRgbOffsets[3].push_back(-Width - 1);
bayerToRgbOffsets[3].push_back(-Width);
bayerToRgbOffsets[3].push_back(-1);
bayerToRgbOffsets[3].push_back(0);
break;
... other color spaces
}
for (auto row = 0; row < Height; row++)
{
for (auto col = 0, bayerIndex = row * Width; col < Width; col++, bayerIndex++)
{
auto colorIndex = (row%2)*2 + (col%2);
std::for_each(bayerToRgbOffsets[colorIndex].begin(), bayerToRgbOffsets[colorIndex].end(),
[&](int colorOffset)
{
auto rgbIndex = (bayerIndex + colorOffset) * 3 + rgbOffsets[offset];
RgbChannel[rgbIndex] = BayerChannel[bayerIndex];
});
}
}
}
, :
(/O2) .
for_each for, . , bayer "" rgb ( ), std::vector, debug release ( X2-X3). , std::vector ? , ?