3
BITMAPFILEHEADER new_bf;
BITMAPINFOHEADER new_bi;
new_bf = bf;
new_bi = bi;

new_bi.biHeight = bi.biHeight*factor;
new_bi.biWidth = bi.biWidth*factor;

int padding =  (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int new_padding =  (4 - (new_bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;

new_bi.biSizeImage = (new_bi.biWidth *sizeof(RGBTRIPLE) + new_padding) * abs(new_bi.biHeight); 
new_bf.bfSize = new_bi.biSizeImage + 54; 

fwrite(&new_bf, sizeof(BITMAPFILEHEADER), 1, outptr);
fwrite(&new_bi, sizeof(BITMAPINFOHEADER), 1, outptr);

//changed to old_biheight to prevent confusion
for (int i = 0, old_biHeight = abs(bi.biHeight); i < old_biHeight; i++)   
{

   for (int l = 0; l<factor; l++)
   {

    // iterate over pixels in scanline
    // columns within row
       for (int j = 0; j < bi.biWidth; j++)
       {
           // temporary storage
           RGBTRIPLE triple;

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


           for (int r=0; r<factor; r++)
           {
               fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
           }
        }


        fseek(inptr, padding, SEEK_CUR)

        for (int k = 0; k < new_padding; k++)
        {
            fputc(0x00, outptr);
        }

        if (l < factor - 1) 
        {
            fseek(inptr, -(bi.biWidth*sizeof(RGBTRIPLE)+padding), SEEK_CUR);  
        }
    }
}

// close infile
fclose(inptr);

// close outfile
fclose(outptr);

// that's all folks
return 0;
}

Comparing values

When I put in

fseek(inptr, -(bi.biWidth*sizeof(RGBTRIPLE)+padding), SEEK_CUR);  

I ended up getting this error code:

I'm not sure why I'm not getting the right output and this error code

1 Answer 1

5

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 sign and the runtime error will go away.

By the way, your code up there is missing a semicolon at the end of this line: fseek(inptr, padding, SEEK_CUR)

1
  • Thanks buddy, had a similar problem to the one asked, and your idea worked perfectly in my case too. Keep up doing this good work!!!
    – sharpnife
    Commented Jun 12, 2017 at 10:39

You must log in to answer this question.

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