# pset4 resize - bfSize value

``````I think that i have the right code for calculating the bfSize. But its not the same as the cs50 in ~cs50/pset4/resize that gives 0x132 for n
= 3, and i get 0x144 with the following formula:

if ((bi.biWidth * sizeof(RGBTRIPLE)) % 4 == 0)
{
bf.bfSize *= n * n + 54;
}
else
{
bf.bfSize = (((bi.biWidth * n) + (bi.biWidth * n % 4)) * (bi.biWidth * n)) * sizeof(RGBTRIPLE) + 54;
}

What i'm i doing wrong?

Cheers

Luis
``````

Simplifying, for better understanding:

Imagine a rectangle.

oxxp ---> 3 pixel > 9 bytes
xoop ---> 3 pixel > 9 bytes

Padding = 1 pixel = 3 bytes

bf.bfSize= [3 pixel(width) + 1 pixel(padding)] * 2 pixel(height) = 8 pixel * 3 bytes = 24 bytes + 3 bytes (padding) + 54 bytes (header) = 81 bytes

n = 2

ooxxxxpp ---> 6 pixel > 18 bytes
ooxxxxpp ---> 6 pixel > 18 bytes
xxoooopp ---> 6 pixel > 18 bytes
xxoooopp ---> 6 pixel > 18 bytes

padding = 2 pixel = 6 bytes

bf.bfSize = [6 pixel(width) + 2 pixel(padding)] * 4 pixel(height) = 32 pixel * 3 bytes = 96 bytes + 54 bytes(header) = 150 bytes

Is this correct? If so. So this is:

``````bf.bfSize = (((bi.biWidth * n * sizeof(RGBTRIPLE)) + ((bi.biWidth * n * sizeof(RGBTRIPLE)) % 4) * sizeof(RGBTRIPLE)) * (bi.biWidth * n * sizeof(RGBTRIPLE)) + 54;
``````

I got it Irene!

The correct code is:

``````int a = bi.biWidth * n * sizeof(RGBTRIPLE);
int b = (4 - (bi.biWidth * n * sizeof(RGBTRIPLE)) % 4) % 4;
int c = abs(bi.biHeight) * n;
bf.bfSize = ((a + b) * c) + 54;
``````

This way is clearer to read. The main problem was with padding.

Thanks for trying ;)

Cheers Luis

No idea what you're trying to do there. Also, i don't know how you're calculating biSizeImage. bfSize is the full size of the file, that means: The size of the bitmap + the size of the two headers. The size of the headers is, indeed, 54. The rest is wrong. The size of the bitmap will have to take into account width and height, and padding

• The Code tthat i'm using: bf.bfSize = (((bi.biWidth * n) + (bi.biWidth * n % 4)) * (bi.biWidth * n)) * 3 + 54; Can be expressed as: Size of File = (((Width of image * n) + padding)) * (Height of image * n)) * 3 + 54. So that i have the full size of the file. – Luís Alves Oct 31 '15 at 5:40
• The first version is wrong. As for the second, it may be correct, although it's confusing with so many brackets. Why don't you use the updated height and width? :) – Irene Oct 31 '15 at 19:59