0

I would very appreciate your help.

//variables for original width and height int originalWid = bi.biWidth; int originalHei = bi.biHeight;

//update width and height
bi.biWidth = scale * originalWid;
bi.biHeight = scale * originalHei;

 // determine padding for scanlines
int oldPadding =  (4 - (originalWid * sizeof(RGBTRIPLE)) % 4) % 4;
int newPadding = (4 -(bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;


//update image size
bi.biSizeImage = abs(bi.biHeight) * (bi.biWidth * sizeof(RGBTRIPLE)+ newPadding);

//update file size
bf.bfSize = bi.biSizeImage + bf.bfOffBits;

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

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

// iterate over infile's scanlines for (int i = 0, biHeight = abs(originalHei); i < biHeight; i++)

{   //horizontal resize
    for(int s = 0; s < scale; s++)

    {
        //move cursor, 54 is size of header
        fseek(inptr,((54 + originalWid * 3 + oldPadding) * i), SEEK_SET ); 

        // iterate over pixels in scanline
        for (int j = 0; j < originalWid; j++)
        {
            // temporary storage
            RGBTRIPLE triple;

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

            //write to outfile
            for ( int z = 0; z < scale; z++ )
            {
                // write RGB triple to outfile
                fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
            }
        }
    }

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

    // then add it back (to demonstrate how)
    for (int k = 0; k < newPadding; k++)
    {
        fputc(0x00, outptr);
    }
}

// close infile
fclose(inptr);

// close outfile
fclose(outptr);

// that's all folks
return 0;

}

1

This perhaps won't solve the whole problem, but you might want to do these two things:

1) Don't multiply the header size alongside with the size of a scanline when fseeking. You don't want to first skip 0 bytes, then 54 + (1 * the length of a scanline), then 108 + (2 * the length)... you always want to skip 54 bytes + (i * the length of a scaline).

2) Add the padding to the output file every time you add a new scanline to it (every time you go through the for (int s = 0; s < scale; s++) loop). Not after you finish scaling one scanline of the input file.

| improve this answer | |
  • mimo31, it almost works) Now I have black pixel in the upper right corner, and left lower corner. Thank you so much anyway, it`s much better. – Kateryna Jul 29 '16 at 20:33

You must log in to answer this question.

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