Writing binary file to SD (creating BMP files)

I was lazy so I just hard coded 24.

Each row must be a multiple of four bytes so I think the correct expressions for rowSize and fileSize are

  int rowSize = 4*((3*w +3)/4);
  int fileSize = 54 + h*rowSize;

This depends on truncation of integer divide.

The number of padding bytes at the end of a row would be:

  int nPad = rowSize - 3*w;

In your case rowSize is 12 bytes and fileSize is 78 = (54 + 2*12).

Padding at the end of a row is three bytes.

I have not really tested this very well, just ran this sketch:

void setup() {
  Serial.begin(9600);
  int h = 2;
  for (int w = 0; w < 10; w++) {
    Serial.print(w);
    Serial.write(' ');
    int rowSize = 4*((3*w +3)/4);
    int fileSize = 54 + h*rowSize;
    int nPad = rowSize - 3*w;
    Serial.print(rowSize);
    Serial.write(' ');
    Serial.print(nPad);
    Serial.write(' ');
    Serial.println(fileSize);
  }
}
void loop() {}

and got this result:

0 0 0 54
1 4 1 62
2 8 2 70
3 12 3 78
4 12 0 78
5 16 1 86
6 20 2 94
7 24 3 102
8 24 0 102
9 28 1 110