8
votes
Accepted
pset4 resize, invalid or unsupported image format
The immediate problem lies with your header structures. You have created bi_new and modified two of it's fields, but you forgot to copy the contents of bi to bi_new, so all of the unmodified fields ...
- 66.2k
7
votes
Accepted
How to interpret biHeight data
That is because biHeight in this case is a negative number, and the representation in binary is made by the two's complement in this case, this can be a bit confusing but you can take a look at the ...
- 1,389
5
votes
Why is RGBTRIPLE in our bitmap 3 bytes? Is that defined somewhere?
If you take a look in bmp.h, which is included as a header file to copy.c, you'll see a definition for structures named RGBTRIPLE:
typedef struct
{
BYTE rgbtBlue;
BYTE rgbtGreen;
BYTE ...
- 253
4
votes
How to create a BMP image that is compatible with resize?
Your BMP needs to be 24 bits BMP image. I never used Paintbrush and Seashore, but try to find more options as you export your BMP in them.
If you cannot manage to do that, you may use a tool like ...
- 17.6k
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
How to interpret biHeight data
From MSDN,
biHeight
The height of the bitmap, in pixels. If biHeight is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, the bitmap is a ...
- 17.6k
2
votes
Accepted
fseek in pset4(whodunit)
Given that padding cannot be read by fread
Who says the padding can't be read by fread? Of course it can and that's the main reason you need to skip it — in order to make fread read the first pixel ...
- 17.6k
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,160
2
votes
PS4 Resize makes random colors
There are several problems in the code, but the biggest is this:
//GO BACK TO BEGINNING OF SCANLINE
fseek(inptr, (i * bi.biWidth), SEEK_SET);
The third parameter is the starting ...
- 66.2k
2
votes
Accepted
Odd IDE behavior during pset4
The problem lies early in your code:
if (argc != 4 || !isdigit(argv[1]))
The isdigit() function is designed to check whether a single character is a digit, not a string. This code is trying to ...
- 66.2k
2
votes
Why is RGBTRIPLE in our bitmap 3 bytes? Is that defined somewhere?
The missing part of Dr.Queso's response is this. A pixel is made of 3 parts - one red, one green and one blue. Each of these is represented by a number that determines it's intensity. The range for ...
- 66.2k
2
votes
Accepted
Having trouble with PSet4 resize problem
Two issues I think I see are:
1) You change the value of BiWidth to BiWidth = BiWidth * scale (and same for BiHeight) for use in changing the header values but then you use those updated values in the ...
- 50
2
votes
Accepted
nothing can be done for whodunit. Even though I have my bmp.h file still it shows me that the file doesn't exist. help me out
You may have the file, but it isn't in the same directory as your source code file and/or the directory where you are executing your make command. You must be in the same directory on the command line ...
- 66.2k
2
votes
2019 CS50 PSet 4 Filter Less
Have you watched the "Walkthrough" videos yet? It looks like there's only one video, but there are actually several (just kind of hidden because they will play one after another, and you can select ...
- 63
1
vote
Accepted
PSET3 Resize (more comfortable), resizing f > 1 correctly, but pixels are different colors. Does not work when f < 1
Actually, no, the code doesn't work correctly at all.
First, the header data is incorrect. Two fields are not calculated correctly.
Second, even at resize of 1, the image output is incorrect. ...
- 66.2k
1
vote
Accepted
CS50 pset3 i want to resize this image, code is working for some and not for others? Can anyone tell me whats the problem?
The problems revolve around how the pointer is moved at the end of each line in the input file and how padding is added to the output file. There are two issues.
First, the output file padding. It ...
- 66.2k
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
Accepted
Problem interpreting BMP file structure
Bytes inside the fields are the other way around. Citing Wikipedia on BMP format:
All of the integer values are stored in little-endian format (i.e. least-significant byte first).
- 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
can't pass check50
There is definitely an issue with your code. You should first test with scale factor of 1, make sure the headers are right, then check the image data, using the peek and xxd tools. Once those are ...
- 66.2k
1
vote
Accepted
pset4 resize: how to copy a row
"Everyone's looking for a zebra. I see the injured horse."
All of the file reads and writes are using the outptr output file pointer. The only reference to the input file pointer inptr is the fclose ...
- 66.2k
1
vote
Accepted
pset4 malloc() approach. Help with size of buffer
It has nothing to do with the malloc call itself. The problem lies in what you think you are checking. Look at the following:
RGBTRIPLE* row = ...
int sizeRow = sizeof(row);
row is declared as a ...
- 66.2k
1
vote
Pset4 Resize Error
Can you say "typo = infinite loop" ?
// replicate pixel n times to outfile
for(int l = 0; l < n; i++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1,...
- 66.2k
1
vote
Accepted
pset4 resize premature end of file encountered
I think maybe the relationship between biSize, biSizeImage, and bfSize is not reflected properly in the code. Here's reference from MSDN:
bfSize: The size, in bytes, of the bitmap file.
~ MSDN ...
- 834
1
vote
pset4 - resize.c - Cannot get vertical resizing to work
I see at least one issue, maybe three.
First, your final fseek() that is supposed to go back to the beginning of the line is outside the for( k ) loop when it should be inside. Move it above the ...
- 66.2k
1
vote
Accepted
Pset4: How does fread add properly to the struct?
fread() knows nothing about the structure. All it knows is the size of the block to read and the address of the memory block where it will put the bytes it reads.
It's up to you to make sure that ...
- 18.5k
1
vote
Accepted
Resize not working (writes RGBTRIPLE too many times)
char *n = argv[1]; explains the problem. Your goal is to get a number as input, but that's not what you are doing here. Remember that all arguments in argv[] are strings. You have essentially ...
- 66.2k
1
vote
Accepted
Why is biSizeImage a random number?
Ah, but it is not random at all! In fact, it's almost correct!
It looks like you are unaware of a couple features that are going on. I bet that the actual hex number that you're seeing for ...
- 66.2k
1
vote
Accepted
resize pset 4 confused on number of things
There are a number of issues that need to be fixed. Since the philosophy of this forum is to guide people to solutions and not just to fix code, I'll point you at two subtle but major issues that will ...
- 66.2k
1
vote
Accepted
Why should we assume that the size of the output BMP file does not exceed 4 GB?
The spec you're quoting does not actually say that "size of a bmp can't exceed 2^32 -1" as you are (mis)interpreting.
It says that, in order to code your implementation of resize.c, you may assume ...
- 1,160
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
bmp × 35resize × 24
pset4 × 21
padding × 6
pset5 × 5
cs50x × 3
fseek × 3
c × 2
malloc × 2
structs × 2
file-io × 2
rgbtriple × 2
segmentation-fault × 1
whodunit × 1
fread × 1
resize-less × 1
headers × 1
morecomfortable × 1
c++ × 1
bitmap × 1
buffer × 1
copy.c × 1
eof × 1
copy × 1
fault × 1