0

I know I have to do this:

//resize headers
    biWidth = biWidth * n
    biHeight = biHeight * n
    biSizeImage = (biHeight*3) * (biWidth*3) + padding
    bfSize = biSizeImage + 54

But I don't know how to do it in actual code, and I can't find the information anywhere. If someone knows of a website that would be great.

More specifically, these are the questions I have:

  1. How do I rename (for example) biWidth old_biWidth while keeping the value the same.
  2. How do I make sure that fwrite uses the new values.

And as an aside: 3. I know I need the "bi." and "bf." before the name but I'm not sure why.

0

Given the following BMP image

00FF00 00FF00 00FF00 000000
00FF00 FFFFFF 00FF00 000000
00FF00 00FF00 00FF00 000000

The width of this BMP image is 3px which is 9 bytes (excluding the padding). The height of this BMP image is also 3px. The size of this BMP image (including the padding) is 36 bytes -- (3px width * 3px height * 3 bytes) + 9 bytes padding (in total).

According to your formula for calculating the size of the image, and assuming that what you mean by padding is the calculated padding for a single scanline, this would result in an incorrect result -- (3 * 3) * (3 * 3) + 3 = 84 which is definitely incorrect. That's one thing.

How do I rename (for example) biWidth old_biWidth while keeping the value the same.

Technically speaking, you can't "rename" a variable. Instead, you can create another variable, name it whatever you want (keeping it descriptive) and storing the appropriate value in it as you desire.

Given that biWidth and biHeight are of type LONG which is defined in bmp.h as a synonym to int32_t which is, in turn, defined in stdint.h, and assuming you're including bmp.h atop your program, you may create two variables of type LONG like that

LONG oldBiWidth;
LONG oldBiHeight;

How do I make sure that fwrite uses the new values.

Assuming you're gonna modify the members of bf and bi respectively which are declared and initialized in the distribution code for this pset for you already, keeping in mind that you should backup any values that you think you'll use later in your program the way we've shown up here, you may use gdb to print the values of the desired variables right before the call to fwrite() making sure these values are correct. Also, using printf() would be an alternative approach.

I know I need the "bi." and "bf." before the name but I'm not sure why.

bi and bf are variables of types BITMAPINFOHEADER and BITMAPFILEHEADER respectively. They contain data about the BMP image and the BMP file as a whole. The data in these variables which originally belongs to the original BMP file will be the same for the new BMP file except for some specific parts that you'll need to modify (e.g., the biWidth, the biHeight, etc). So, basically, these variables are gonna be written to the new BMP file after the modifications.

For more information about the structure of BMP files, you may read this section!

9
  • Thanks a lot! I think I get it now. The answer for the size of the image is supposed to be 108 right? Just checking. – Sofia Sep 6 '14 at 23:17
  • @user1353 which image exactly? What are the dimensions of this image? What is n? – Kareem Sep 6 '14 at 23:40
  • sorry, your example, the first part of your answer, the one that isn't 84 :) – Sofia Sep 7 '14 at 1:49
  • @user1353 if you read carefully, I already calculated it at the beginning of the answer. – Kareem Sep 7 '14 at 7:51
  • oh sorry, thanks – Sofia Sep 7 '14 at 19:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .