Hot answers tagged

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....
ChrisG's user avatar
  • 7,376
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 ...
ChrisG's user avatar
  • 7,376
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 ...
Cliff B's user avatar
  • 68.4k
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 ...
Cliff B's user avatar
  • 68.4k
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 ...
Cliff B's user avatar
  • 68.4k
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 ...
hotwebmatter's user avatar
  • 3,050
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 ...
Yuri Laguardia's user avatar
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 ...
curiouskiwi's user avatar
  • 18.6k
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 ...
André Queiroz's user avatar
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 ...
kluvin's user avatar
  • 1,223
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          ...
DinoCoderSaurus's user avatar
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; ...
robert_x44's user avatar
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 ...
Cliff B's user avatar
  • 68.4k
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 ...
Cliff B's user avatar
  • 68.4k
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 ...
Cliff B's user avatar
  • 68.4k
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 ...
Cliff B's user avatar
  • 68.4k
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....
Cliff B's user avatar
  • 68.4k
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 ...
Yuri Laguardia's user avatar
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 ...
Tarmyniatur's user avatar
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(...
bluesmonk's user avatar
  • 131
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 ...
Cliff B's user avatar
  • 68.4k
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(...
Blauelf's user avatar
  • 20.9k
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 ...
Sam Gerber's user avatar
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++)
Sam Gerber's user avatar
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 ...
Cliff B's user avatar
  • 68.4k
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)...
Sam Gerber's user avatar
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 ...
Cliff B's user avatar
  • 68.4k
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 ...
Irene's user avatar
  • 1,687
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 ...
kzidane's user avatar
  • 17.7k
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 ...
SumatranHamster's user avatar

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