21
votes
Accepted
Pset4 resize.c - bfsize & bisizeimage formulas
Not exactly. If you read the BITMAPINFOHEADER like so
// read infile's BITMAPINFOHEADER
BITMAPINFOHEADER bi;
fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
to get the width, the correct is bi....
10
votes
Accepted
How does “RGBTRIPLE triple;” know whitch pixel to store?
You have mixed them a little in your head but we are here. :)
Firstly, the line
RGBTRIPLE triple;
doesn't get a pixel, it just declares a variable, of type RGBTRIPLE with the name triple. It would ...
10
votes
Accepted
pset4: resize.c - why is biWidth written as bi.biWidth
Welcome to the wonderful world of structures! ;-)
A structure, or a struct, is a collection of individual vars combined into a group. The group has a variable name, and each element in the struct has ...
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 ...
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 ...
5
votes
Accepted
Memory leak in Pset4
Actually, your apparent problem is that you are running valgrind against a different executable binary, also called resize.
~/workspace/ $ which resize
/usr/bin/resize
~/workspace/ $ whatis resize
...
5
votes
Accepted
pset4 resize.c negation of 12 cannot be represented in type unsigned long
fseek() accepts a long int as the second parameter and via arithmetic conversion you're passing unsigned long as a second argument.
Cast it to long int by inserting (long int) right after the minus ...
4
votes
Accepted
pset4: resize - bmp looks good in xxd, won't pass check50
Be sure to verify the values in the headers. you can do this by resizing a test image using the staff version, then your own, and running
~cs50/pset4/peek staff.bmp student.bmp
to compare. you ...
4
votes
Resize: Vertical resizing and padding
newBi.biSizeImage is wrong. Can you see why?
You are writing wrong stuff in the header with fwrite() too. Prob stuff coming from copy.c.
Lastly, you need to understand how the file pointer works.
If ...
4
votes
Accepted
pset4 runtime error: unsigned integer overflow
You are subtracting from bi.biWidth on line 125. Since bi.biWidth is an unsigned long, it cannot contain negative values (-1 and so on), instead it's capacity to store positive values is doubled. So ...
4
votes
Accepted
Pset4 Resize.c Array Overstepping
After edit:
For reference, here is the pseudocode from the walkthrough:
for each row
for each pixel
...
4
votes
Accepted
BITMAPFILEHEADER bf in resize.c
I'm assuming that you are asking why the typedef in bmp.h works. If not, please clarify your question, and I'll update the answer.
In bmp.h:
typedef struct
{
WORD bfType;
DWORD bfSize;
...
3
votes
Accepted
Resize check50 results pset4
Wouldn't it work better if you wrote out the headers after you calculate the new new_bf.bfSize and new_bi.biSizeImage ?
If this answers your question, please click on the ckeck to accept. Let's keep ...
3
votes
Accepted
resize in pset4 - can't figure it out
You have two main problems. First, you have an error in your header. Second, you have overlooked a step in scaling the image.
Let's start with the header. If you ran small.bmp through your program ...
3
votes
Accepted
How does copy.c know which RGBTRIPLE it is supposed to copy?
Without reviewing your code, let me try to explain. Yes, you've got the idea. fread() does cause the file pointer to track location. Let's say you have a file pointer called inptr. Next, let's say ...
3
votes
Accepted
Pset4 resize: don't understand how it works
Let's see if I can answer your questions. I don't think you've got a handle on how the image data is processed and displayed. First, the image will print either from top to bottom, or from bottom to ...
3
votes
Accepted
Pset4 Resize : Compiles but gives error :File size exceeded when I run resize
You have an infinite loop in the third for loop.
for(int l = 0; i < n; l++)
See anything wrong with the test condition????
If this answers your question, please click on the check mark to accept....
3
votes
Error in my pset4 resize.c code
The width of your image is 3. When you use that minus sign here fseek(inptr, -bi.biWidth * sizeof(RGBTRIPLE), SEEK_CUR);
, it becomes -3.
But before the multiplication takes place, C rules of ...
3
votes
in pset4, resize: How does the structs declared in 'bmp.h' know which bytes to get the data from?
How does the structs declared in 'bmp.h' know which bytes to get the data from?
The resize program works with the BMP file format which has a few characteristics which need to be altered, namely ...
3
votes
Choosing pixels in resize (More)
I'm dealing with that at the moment, and as far as I can tell the form is
newArray[i] = oldArray[(int)floor(i / factor)]
Then, if factor = 0.5
floor(0/0.5) = 0 /* newArray[0] = oldArray[0] */
floor(...
3
votes
Accepted
PSET4 resize (less) check50 error
Well, your description is sort of right. The image size is incorrect.
When I ran the code, the headers are fine. The problem is that the image data that's being generated is too large by roughly ...
3
votes
Accepted
I can't figure out the problem in my resize (more) code
That line seems to be the culprit:
for (int i = 0; i < f * outbi.biHeight; i++)
Would have to use abs(outbi.biHeight) or equivalently (int) (f * HeightIn), not f * outbi.biHeight.
The line fseek(...
2
votes
Pset 4 - Premature end of file encountered
First let's look at your headers...
int newwidthP = new_bi.biWidth + newpadding; //Incompatible units being mixed
//biWidth is in pixels, newpadding in ...
2
votes
Accepted
Check50 calls errors with resize
for (int i = 0, biHeight = abs(biOutput.biHeight); i < biHeight; i++)
should be
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
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 ...
2
votes
pset4 resize only works if there is no padding
These are very different, and are likely the cause of the problem. Do you understand the formula?
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int newPadding = ((4 - (bi.biWidth * n)...
2
votes
Accepted
pset4 resize doesn't resize
I see two significant problems. First, it appears that you have only calculated the padding for the input file and are using it for both the input and output files. The two paddings are not related ...
2
votes
Accepted
Resize What to do next?
1) Apart from biWidth and biHeight, there's 2 more headers you're meant to update, you can read the MSDN pages to get an idea of which two they are. They're the only two that will change when the size ...
2
votes
Accepted
Want to make sure I understand struct, malloc, and pointers and how they relate to each other
I originally didn't alloc for the struct, just declared it. It worked,
and from what I understand, it worked because it was created in the
stack? Am I correct?
the type BITMAPINFOHEADER is not a ...
2
votes
Pset4 8x8 smiley only showing 7x7
I realise that this question is over a year old, however other people may still be having the issue so thought I would answer.
I have had exactly the same issue - for me, the problem was caused by ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
resize × 640pset4 × 465
pset3 × 51
pset5 × 48
padding × 44
check50 × 40
cs50x × 36
resize-less × 31
fseek × 26
c × 25
bmp × 24
less × 21
vertical-resizing × 20
pset4resize × 11
lesscomfortable × 10
bitmap × 10
fread × 9
headers × 9
pixels × 8
recopy × 8
help × 7
pset3resize × 7
fwrite × 6
invalid-image-format × 6
copy.c × 6