Have a look at these lines of your code.
PIXEL **pixelArray = (PIXEL **)malloc(sizeof(PIXEL*)*(bitmapInfoHeader.biWidth*M));
PIXEL **pixelArray1 = (PIXEL **)malloc(sizeof(PIXEL*)*(bitmapInfoHeader.biWidth*M));
for(i = 0; i < (bitmapInfoHeader.biWidth*M); i++)
{
pixelArray[i] = (PIXEL *)malloc(sizeof(PIXEL)*(bitmapInfoHeader.biHeight*N));
pixelArray1[i] = (PIXEL *)malloc(sizeof(PIXEL)*(bitmapInfoHeader.biHeight*N));
}
Are you sure the height should be multiplied by the size of a pixel? Is the RGB information stored horizontal and also vertical? :confused:
Good luck!