Hot answers tagged

10 votes
Accepted

Explanation of the formula for padding

When bi.Width * sizeof(RGBTRIPLE) is a multiple of 4, the expression (bi.biWidth * sizeof(RGBTRIPLE)) % 4 gets evaluated to 0 which, it turn, gets the expression 4 - [(bi.biWidth * sizeof(RGBTRIPLE)...
  • 17.5k
7 votes
Accepted

pset4 resize - fseek help (I think)

Your approach is correct, but you have three errors to deal with, one of which is irrelevant. First, as you guessed, your calculation for fseek is in error. In simple terms, you've placed parentheses ...
  • 65.5k
5 votes

Explanation of the formula for padding

Let's say that the biWidth is 4. As such, the padding must be 0. Let's say we don't use that last %4 padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4); padding = (4 - (4 * 3) % 4) padding = (4 - ...
  • 18.5k
5 votes
Accepted

Resize's Padding Issue

You are calculating the new bi.biSizeImage incorrectly. bi.biSizeImage is the size in bytes of the raw bmp data, that means the size in bytes of the pixels information plus the padding. So: bi....
  • 1,389
5 votes
Accepted

Pset4, resize, padding

A subtle problem. You probably realized that it had something to do with padding, but couldn't track it down. The problem is that you forgot to account for the padding of the input file when ...
  • 65.5k
5 votes

What exactly is padding in pset4?

as explained per the specs, the size of each scanline in a BMP has to be multiple of 4. padding bytes are appended to each scanline in case its size wasn't multiple of 4 in order to achieve the rule ...
  • 17.5k
4 votes
Accepted

check50 reports resize as incorrect for 1, 2, 3, 5 for seemingly correct code

It's the fact that your biSizeImage calculation is not correct, so whenever there is padding, you get the wrong value in your header bi.biSizeImage = ((bi.biWidth)* abs(bi.biHeight) * sizeof(...
  • 18.5k
3 votes
Accepted

Padding, pset4, resize. weird xxd output

For the strange xxd output, it's because you have given a wrong value for the columns -c flag. Since the small.bmp image has a width of 3 pixels, it has as -c 3 pixels * 3 bytes each pixel == 9 bytes ...
  • 7,366
3 votes
Accepted

Why does copy.c skip padding?

In the demo code that merely copies a bitmap, they are demonstrating how to strip off the padding and then add it back when writing to the outfile because that ability will be needed later. Yes, ...
  • 65.5k
3 votes

PSET 4: Why is padding required?

Row size is a DWORD ie 32 bits/4 bytes. So a the 24 bit pixels must be padded to fit. See also this answer in Stack Overflow... "Because 24 bits is an odd number of bytes (3) and for a variety of ...
  • 151
2 votes
Accepted

what is wrong with my resize?

Your padding calculation is fine (I believe). I think the problem lies on the "logic". Once you've completed scanning the first line, you force the file cursor to skip the infile padding: for (int j =...
  • 1,150
2 votes
Accepted

A question about padding

Remember, each RGB triple is 3 bytes. If the image is 3 pixels wide, it takes 9 bytes per row. The padding is therefore 3 bytes per row, bringing it to 12. If you look further down you'll see they ...
2 votes
Accepted

CS50 Pset4 Resize Padding

The issue is with your fseeks. To understand how this program should work, let's assume the original picture (I’ll call this infile for now) is the following: G G G padding G W G padding G G G ...
2 votes
Accepted

pset4 Resize: Don't understand problems with size and dimensions

You have two problems, one with the header and one with image processing. In the header, you have calculated all the values correctly. (BTW, that was the most unique way I've seen to date to add the ...
  • 65.5k
2 votes
Accepted

pset4 Resize adding padding... and resize in general (HELP ME!)

Your code has a number of problems. Based on what you have said, and what is in the code, I think you'd benefit more from some guidance on how to work through this pset and some general advice. When ...
  • 65.5k
2 votes
Accepted

pset4 resize.c - general struggles

OK there are two definite mistakes, (could be more but can't tell without the full code). First, the following lines: // skip over padding, if any fseek(inptr, scan_padding, SEEK_CUR); should be on ...
  • 7,366
2 votes
Accepted

Problem with horizontal resizing Pset4 resize

fwrite(&triple, sizeof(RGBTRIPLE), n, outptr); will write a chunk of memory containing n pixels, while you need to write the very same triple, n times. You'll have to use another loop for that.
  • 20.8k
2 votes
Accepted

Trouble with padding in resize

Two small problems with significant impact. First, the code calculates the output padding before calculating the output file width. This is disrupting the size of the output padding and two header ...
  • 65.5k
2 votes
Accepted

CS50 Pset4 Resize Padding. again

If you look at the actual data of the output file, certain patterns become obvious. Say that the input file is being scaled up to 2. The first line from the input file is being scaled up correctly, ...
  • 65.5k
1 vote

determine padding for scanlines in copy.c

It's not needed for a padding of 1, 2, or 3 bytes. But imagine what happened if bi.biWidth were a multiple of 4. bi.biWidth * sizeof(RGBTRIPLE) would be a multiple of 4. (bi.biWidth * sizeof(...
  • 20.8k
1 vote

Pset 4 Resize makes a very colorful picture (not green!)--padding problem?

You change bi.biWidth and bi.biHeight to new scale using bi.biWidth = bi.biWidth * enlarge; bi.biHeight = bi.biHeight * enlarge; and then use code that relies on the values to represent the ...
  • 20.8k
1 vote
Accepted

pset4, copy.c padding

Yes, the fseek and padding loop are absolutely necessary. Think about it mathematically. The image portion is composed of 36 bytes (3 lines with 3 3-byte pixels per line plus 3 bytes of padding per ...
1 vote
Accepted

pset4 resize.c error

This code is far from perfect. It incorrectly calculates biSizeImage. biSizeImage cannot simply be raised to a power. The biSizeImage of the new file must be calculated using the new padding size, ...
  • 65.5k
1 vote
Accepted

resize.c problem with padding

It would be easy to say what the problem is, but what fun would that be for you? ;-) The problem is only indirectly related to padding. You still don't have your header calculations right. When you ...
  • 65.5k
1 vote
Accepted

Issues with padding - why am I getting a black image for every outfile?

You should run the staff's version for a couple of files and different values of resize and then run peek on those files to see which are the headers that actually change. Also, take a closer look ...
  • 1,677
1 vote
Accepted

PSET4 Resize: image resizes but fails check50 (PADDING or HEADER???)

You'll see what your problem is if you do this: Think about it for a while and come back here again if this doesn't make it click for you... and I can add other tips.
1 vote
Accepted

pset4 resize fseek() - non proper work

You could use fseek(inptr, -bi.biWidth * sizeof(RGBTRIPLE), SEEK_CUR); (no padding, as you never read some) to go back to the start of the line where you fseek at the moment, and after that loop, ...
  • 20.8k
1 vote
Accepted

Need help with padding in cs50's pset4 resize.c

You have two problems, neither is related to the padding. Look at this line: fseek(inptr, -(bi.biHeight * sizeof(RGBTRIPLE) + inptr_padding ), SEEK_CUR); This line is designed to reposition the ...
  • 65.5k
1 vote

CS50 resize Problems

It does have to do with the padding. There are two issues with it - one is a typo and the other is about program structure. First, look at the following: if (j % resize != 0) { fseek(inptr, -(...
  • 65.5k
1 vote

Yet again, problem with padding

One of the problems is that you're not resizing vertically. What you're doing is: 1) read one triple and write it as many times as needed by resize factor. Repeat this until a whole scanline has been ...
  • 1,677

Only top scored, non community-wiki answers of a minimum length are eligible