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 Answer 1

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
    Commented Aug 21, 2017 at 17:08
  • Place the fwrites of the headers just before your loop, especially after you updated all the values.
    – Blauelf
    Commented Aug 22, 2017 at 6:58
  • I still have the unsigned error :(
    – Genevie
    Commented Aug 23, 2017 at 23:40
  • Cast the sizeof result to a signed type like long before the multiplication.
    – Blauelf
    Commented Aug 24, 2017 at 5:36
  • please can u explain what u are saying ? I don t understand (french speaker)
    – Genevie
    Commented Aug 24, 2017 at 21:07

You must log in to answer this question.

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