Your calculation for the destination offset is wrong.
m_pcBMP[i * 3*m_uiWidth + j] = ...
Вопрос
I'm trying to write a program which rearranges pixels from a gray scale raw file according to bmp format. But I think I would make some mistakes I don't know. Could someone tells me what's wrong with the following code? specs says a pixel for BMP format consist of 3 bytes. The first row on a raw image array is placed on the bottom row on a bmp pixel array, the second row is placed on the second bottom row, and so on. so I write the core code like, except GUI code and one for bmp header:
void MyClass_MakeBMP(void)
{
int i,j,k ;
/* m_uiWidth and m_uiHeight are rows and cols for the raw image, respectively. */
m_BMPheader.biWidth = m_uiWidth;
m_BMPheader.biHeight = m_uiHeight;
// raw format buffer -> 2d array.
// bmp format buffer -> 1d array.
// m_pcImgbuf is 1d array for a raw file.
// m_pcBMP is 2d array to be copied from m_pcImgbuf.
for(i = 0 ; i < m_uiHeight; i++)
{
k = -1; // index into m_pcImgbuf.
for(j = 0 ; j < m_uiWidth * 3; j++)
{
if( j % 3 == 0)
k++;
m_pcBMP[i * m_uiHeight + j] = m_pcImgbuf[(m_uiHeight - 1) - i][k];
}
}
}
Also, I don't care about padding, because this program can takes as input, 256*256, 128*128, and 512*512 images. Thank you in advance.
Решение
Your calculation for the destination offset is wrong.
m_pcBMP[i * 3*m_uiWidth + j] = ...