private void ConvertBayerToRgb32(int width, int height)
{
// Demosaic using a basic nearest-neighbor algorithm, operating on groups of four pixels.
for (int y = 0; y < height; y += 2)
{
for (int x = 0; x < width; x += 2)
{
int firstRowOffset = (y * width) + x;
int secondRowOffset = firstRowOffset + width;
// Cache the Bayer component values.
byte red = rawPixelData[firstRowOffset + 1];
byte green1 = rawPixelData[firstRowOffset];
byte green2 = rawPixelData[secondRowOffset + 1];
byte blue = rawPixelData[secondRowOffset];
// Adjust offsets for RGB.
firstRowOffset *= 4;
secondRowOffset *= 4;
// Top left
pixelData[firstRowOffset] = blue;
pixelData[firstRowOffset + 1] = green1;
pixelData[firstRowOffset + 2] = red;
// Top right
pixelData[firstRowOffset + 4] = blue;
pixelData[firstRowOffset + 5] = green1;
pixelData[firstRowOffset + 6] = red;
// Bottom left
pixelData[secondRowOffset] = blue;
pixelData[secondRowOffset + 1] = green2;
pixelData[secondRowOffset + 2] = red;
// Bottom right
pixelData[secondRowOffset + 4] = blue;
pixelData[secondRowOffset + 5] = green2;
pixelData[secondRowOffset + 6] = red;
}
}
}