0

Stuck on PSET4 resize: the file I'm writing is going into overflow and I'm not sure why. I've designed it using nested for loops as you'll see.

It compiles and runs, but then it says the file is too big and the resulting image is 'unsupported'

FWIW, I'd love an invite to the slack channel as it's pretty hard to learn coding in a bubble.

Onto the problems...

My approach is to store each line in an array of RGB Triples, and then print each triple SCALE times horizontally, add padding, and then print each row SCALE times, where SCALE is the scaling argument passed to resize.

I'm pretty sure you can do an array of structs. However, I'm having trouble understanding how you access and point to these structures--a little explanation would be helpful. I've done a nested for loop as described below:

FOR - (The Height of the Original Image)

FOR (Each Line, up to the width of the image)

  // create a story for the triple
        RGBTRIPLE triple;

        // read the triple from the inptr
        fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

        // make the triple the jth element of the array
        line_array[j] = triple;

Is this correct to story the elements in the triple?

Later, I try to grab the elements in the array and print them a number of times.

My control flow may be wrong (to avoid 'fishing for a solution', I'm not pasting my entire code), but I'd first like to check if my data structure and access is roughly correct.

I try to write the data referencing the array here:

                    for (int m = 0; m < scale; m++)
                {
                    fwrite(&line_array[l], sizeof(RGBTRIPLE), 1, outptr);
                }

I chose an array because we can go line by line, and just overwrite the values in the array and it solves the referencing problem more easily.... or so I thought.

Any help much appreciated!

Full Code (Reference Only): http://pastebin.com/Pvu4vpSf

1
  • Quick tip: instead of copying each structure element individually, as you did, you can copy an entire structure at once. bi.new = bi.old;
    – Cliff B
    Jul 6 '16 at 10:23
1

You have an infinite loop because of a typo that is writing to the output file until the system kills it because it has used up the disk space allotment. I'll let you figure out the typo, but it's here:

        for (int n = 0; n < new_padding; k++)

After that, you have at least one issue - the header data is not calculated correctly. Again, since you haven't had a chance to sort it out, I'll leave it to you to try and fix. If you can't, well, that would be a new question. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Thanks Cliff for the help!
    – borker
    Jul 6 '16 at 15:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .