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 ...
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 ...
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
...
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
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
Accepted
getting runtime error: unsigned integer overflow
About the overflow, read this:
Error in my pset4 resize.c code
Apart from that, what's happening is that you're copying the headers to bi and bf, but you're not copying those headers also to bfNew ...
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 ...
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 ...
2
votes
Accepted
pset4/resize. problem with resize code and i don't know what to do
Well, you seem to be almost there, so I won't review all of your code, just give you some pointers:
The first and most crucial tip is that you need to pass fseek() the number of BYTES as the second ...
2
votes
in pset4, resize: How does the structs declared in 'bmp.h' know which bytes to get the data from?
fread does really tell the computer where to start getting the data:
// read infile's BITMAPFILEHEADER
BITMAPFILEHEADER bf;
fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
// read infile's ...
2
votes
Accepted
ps4 resize error
I see three issues with your code. The good news is that you're pretty much on target.
Two of the problems are related to the backwards fseek near the end of the for loops. The fseek backwards ...
2
votes
Accepted
pset4 resize file header question
*= and += (same for many other operators) are combined assignment operators. a += b is like a = a + b, a *= b is like a = a * b, and so on.
In the line newbi.biWidth = bi.biWidth *= n; you also use ...
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.
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 ...
2
votes
Accepted
resize.c unsupported format or invalid image error
bmp starts with BITMAPFILEHEADER, then BITMAPINFOHEADER. You read in reverse order.
2
votes
Accepted
Issue with padding when horizontally resizing. (pset4, resize (less))
It seems that every second question about resize(less) is about the same mistake: People first multiply bi.biWidth and bi.biHeight by n and than iterate in infile over new width and height, while it ...
2
votes
Accepted
fread() and fwrite() problem
The third element, nmemb, is the number of elements to write, not the number of times to write the same element.
Say that argv[1] is 5. This code, fwrite(&triple, sizeof(RGBTriple), atoi(argv[1])...
2
votes
Accepted
Resize(less comfortable)
It works for increase = 1, but not for anything larger. There are two problems there. First, the header isn't being processed correctly. Certain header values have to be calculated from numerous ...
2
votes
Accepted
Resize Invalid Image Format
There is a significant flaw in the code. The header vars are changed (probably correctly) but then stored in the original headers for the input file, bi, bf. Then the output file headers are written ...
2
votes
Accepted
Could someone please tell me where I'm going wrong here in resize-less(pset4)?
There are two major issue. First, the code is using biWidth and biHeight for the output file to control reading from the input file.
Second, there's no actual code to handle vertical scaling.
...
2
votes
Accepted
Invalid or Unsupported Image Format (Recover)
Your calculation for bi.biSizeImage is wrong. The number of bytes per line is bi.biWidth * sizeof(RGBTRIPLE) + outputPadding, and there are abs(bi.biHeight) lines.
2
votes
Accepted
PSET 4 - resize.c less
You're on the right track, and oh, so close!
So tell me, when you're repositioning the pointer in the input file to reprocess a line, which padding value should you use?
If this answers your ...
2
votes
Accepted
Problem Set 3 (Resize) Help
Not exactly clear what you're asking in your first question, but I know what you should be asking, so here goes. ;-)
The file can't simply be multiplied by some scaling factor. Each line of pixels (...
2
votes
Accepted
Pset 3: Resize gives me green vertical strip and black vertical strip
Error is with this code:
// write RGB triple to array n times
for (int l = 0; l < n; l++)
{
scanlinearray[l] = triple;
}
This will ...
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