0

Here is the code for resize.c I am stuck for quite some time now and i am not able to figure out where i am wrong. please help.

bi.biHeight = height*n;
bi.biWidth = width*n;
// determine new padding for scanlines
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;

bi.biSizeImage = (bi.biWidth*sizeof(RGBTRIPLE) + padding)*abs(bi.biHeight);
bf.bfSize = bi.biSizeImage +54;

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
    for(int p=0;p<n;p++){
        // iterate over pixels in scanline
        for (int j = 0; j < width*n; j++){
            // temporary storage
            RGBTRIPLE triple;
            // read RGB triple from infile
            fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
            for(int wr = 0; wr<n;wr++){
                // write RGB triple to outfile
                fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
            }
        }
        // skip over padding, if any
        fseek(inptr,padding,SEEK_CUR);
        // then add it back (to demonstrate how)
        for (int k = 0; k < padding; k++){
            fputc(0x00, outptr);
        }
    }

}

// close infile
fclose(inptr);

// close outfile
fclose(outptr);

// that's all folks
return 0;

1 Answer 1

0

Without doing an in-depth analysis, one major problem jumps out. You have only calculated the padding for the input file, but you are using it for both. You need to calculate the padding for the output file separately because they are not necessarily the same.

Also, have you verified that your header is being correctly calculated? You didn't say exactly what kinds of problems you are having.

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

2
  • How to calculate the header? and the variable 'padding' here is the new padding for the output file. Am i calculating it wrong? and the main problem i am facing is with the complex loop condition for the RGBTRIPLE values. Please help. Thanks. Commented Apr 18, 2016 at 10:00
  • OK, then if padding is for the output file, where is your calculation for the input file's padding? Also, when I ask if you've verified that your header is correctly calculated, I'm asking if you have verified that the fields that you are calculating in the new header are correct. (I'm not saying they are or they aren't. I'm just asking.) When you run the program with a scaling of 1, does the header of the output file match the input file? Or if you run the same parameters through the staff version of the program, are the results the same as when you run yours?
    – Cliff B
    Commented Apr 18, 2016 at 14:59

You must log in to answer this question.

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