0

I finally got resize to work, but I have a few questions to help understand the code. First, the following line was breaking my code and took me forever to figure out:

bi.biSizeImage = abs(bi.biHeight) * (sizeof(RGBTRIPLE) * bi.biWidth + sizeof(padding));

Removing the sizeof() on padding fixed the code. I put sizeof as a "safety" assuming padding was one byte (and thus sizeof(padding) should also be one byte?). So I'm confused why bi.biSizeImage = abs(bi.biHeight) * (sizeof(RGBTRIPLE) * bi.biWidth + padding); produces a different result.

My second question is what is the purpose of the following line:

// temporary storage 
RGBTRIPLE triple;

I kept it in there because it is in copy.c, and I assumed removing it wasn't a great idea but never truly understood that lines purpose.

Any help would be greatly appreciated.

1
  • Welcome! These are great questions, but please try to keep your questions to one topic at a time. Focused questions lead to answers which are more concise, making them more beneficial to the community. Your second question would make a great post by itself. – Luke Van In Jul 12 '16 at 9:42
0

biSizeImage is the size of the image data, excluding headers, in bytes. The two variables, biWidth and padding are measured in different units. biWidth is measured in pixels or RGBTRIPLEs - 3 bytes each - so biWidth is multiplied by sizeof(RGBTRIPLE) to get bytes. However, padding is measured in bytes, so no need to multiply.

Now, think about what sizeof(padding) produces. padding is an int variable, so sizeof(padding) produces the size of an integer variable, which has nothing to do with what you are trying to calculate. (BTW, I think it's 4 bytes, but is architecture dependent.) Finally, the padding can be anything from 0 to 3 bytes, depending on the size of the file.

As for triple, it is a variable to store a single pixel, something very useful in this program.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Thanks... this was helpful. I'm still a little confused on the triple. It seems the syntax 'STRUCT "random word"/variable;' tells the computer to setup a section of memory for this struct to be accessed later with &variable. Could you not just omit this line and use &STRUCT? Hopefully that makes sense – Brandon Terry Jul 12 '16 at 0:36

You must log in to answer this question.

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