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 ...
- 66.7k
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.6k
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 ...
- 66.7k
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, ...
- 66.7k
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
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
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 ...
- 58
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 ...
- 66.7k
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 ...
- 66.7k
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
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
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 ...
- 66.7k
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, ...
- 66.7k
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, ...
- 66.7k
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 ...
- 66.7k
1
vote
Accepted
pset4 - resize: padding issue
I didn't go deep into your program because there's something you need to fix that will have a big effect on what is happening. I think this is more about technique than anything else, based on the ...
- 66.7k
1
vote
Accepted
Understanding padding and fseek()
While we think of an image as pixels and lines, i.e., a two dimensional array like a checkerboard, the data is stored in the file as a single linear string of data. Adding the padding all at once ...
- 66.7k
1
vote
Accepted
CS50 Pset4 Resize - Vertical Sizing
Have you looked at the raw image data using xxd? The image data for anything larger than n=1 is far too much! The code is using the output file's biHeight and biWidth to control reading the input ...
- 66.7k
1
vote
Accepted
pset 4: resize adding in black pixels
fseek(inptr, bf.bfOffBits + ((oldWidth * 3) * i) + newPadding, SEEK_SET);
You want to go to the start of i line of infile. Each infile line is (oldWidth * 3 + oldPadding) bytes. Multiply it by i and ...
- 1,139
1
vote
Accepted
pset4 resize.c : output matches staff's but colour of square is always grey/white!
Please note that biHeight_original = bi.biHeight are both negative. So you do not do a single iteration, as i < biHeight_original is false.
- 1,139
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 ...
- 27.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.
- 2,595
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 ...
- 66.7k
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, -(...
- 66.7k
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