0

Please, as I wrote, I tried both for long integer in fseek but still I have the unsigned integer overflow message. Can u help me pls ? tsk here the code :

    // data increase by the n value for enhance
    BITMAPFILEHEADER bf_n;
    BITMAPINFOHEADER bi_n;

    bf_n = bf;
    bi_n = bi;

    // dimensions from enhance with n size for bitmapinfoheader
    bi_n.biWidth = n * bi.biWidth;
    bi_n.biHeight = n * bi.biHeight;


    // write outfile's BITMAPFILEHEADER
    fwrite(&bf_n, sizeof(BITMAPFILEHEADER), 1, outptr);

    // write outfile's BITMAPINFOHEADER
    fwrite(&bi_n, sizeof(BITMAPINFOHEADER), 1, outptr);


    // determine padding for scanlines
    int padding_new = (4 - (bi_n.biWidth * sizeof(RGBTRIPLE)) %4) %4;
    int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;


    //new dimension of biSizeImage
    //bi_n.biSizeImage = bi_n.biWidth * bi_n.biHeight;

    //bf_n.bfSize = 54 + bi_n.biSizeImage + padding_new;
    bf_n.bfSize = 54 + (bi_n.biWidth * sizeof(RGBTRIPLE) + padding_new) * bi_n.biHeight;
    bi_n.biSizeImage = bf_n.bfSize - 54;

    // iterate over infile's scanlines
    for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++) // abs means positive value
    {
        // each row will be copy until n number enhance
        for (int j = 0; j <= n; j++)
        {

            for (int g = 0; g < bi.biWidth; g++)
            {
                // temporary storage
                RGBTRIPLE triple;

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

                // each RGB triple copy until n number for enhance
                for (int z = 0; z <= n; z++)
                {
                    fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
                }

                // add new padding to outfile (to demonstrate how
                for (int k = 0; k < padding_new; k++)
                {
                    fputc(0x00, outptr);
                }
                if ( j < n - 1)
                {

                   //seek back to the beggining of the row in input file
                   fseek(inptr, -(long int)(bi.biWidth*sizeof(RGBTRIPLE) + padding), SEEK_CUR);
                }

                 //skip over padding if any
                fseek(inptr, padding, SEEK_CUR);
            }
        }
    }

    // close infile
    fclose(inptr);

    // close outfile
    fclose(outptr);

    // success
    return 0;
}
1

For me, -((long)bi.biWidth * (long)sizeof(RGBTRIPLE) + padding) worked earlier.

Somewhat unrelated, instead of <= n use < n, and most of that code does not belong within the bi.biWidth loop, but after.

Also, you write bi_n and bf_n before you update bi_n.biSizeImage and bf_n.bfSize, so your updated values won't reflect in the written data.

7
  • ''you write bi_n and bf_n before you update sizeimage and bfsize'' : but i need to define bi_n and bf_n before using them in the formula ? So How i am supposed to update SizeImage and bfSize than?
    – Genevie
    Aug 21 '17 at 17:08
  • Place the fwrites of the headers just before your loop, especially after you updated all the values.
    – Blauelf
    Aug 22 '17 at 6:58
  • I still have the unsigned error :(
    – Genevie
    Aug 23 '17 at 23:40
  • Cast the sizeof result to a signed type like long before the multiplication.
    – Blauelf
    Aug 24 '17 at 5:36
  • please can u explain what u are saying ? I don t understand (french speaker)
    – Genevie
    Aug 24 '17 at 21:07

You must log in to answer this question.

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