0

I'm currently trying to figure out what am I doing wrong while resizing the pixels, the weird location of the pixels suggests me that something is wrong with the padding, but I'm not sure. And it seems that I'm not resizing horizontally at all. I'm currently stuck, I've tried fixing it and reading current entries of why it might be wrong, but not a clue. Thank you in advance for your help.

/* update headers file */

//update width
bi.biWidth *= n;

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

//update height
bi.biHeight *= n;

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

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

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

//update file size
bf.bfSize = bi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);


// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
    // resize vertically
    for (int x = 0; x < n; x++)
    {
        // iterate over pixels in scanline
        for (int j = 0; j < bi.biWidth; j++)
        {
            // temporary storage
            RGBTRIPLE triple;

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

            // write RGB triple to outfile n times (aka resize horizontally)
            fwrite(&triple, sizeof(RGBTRIPLE), n, outptr);

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

        }
    }
    // 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);
}

1 Answer 1

1

I see the calculation of the padding for the output file. Where's the calculation for the input file's padding? Both need to be calculated.

The code also needs to use separate values from the headers for the input files and the output files.

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

2
  • I've added the output file's headers, but now my code when run, the IDE warns me that the output image is of an unsupported format. Why could that be the case?
    – DCBuilder
    Commented Jan 2, 2018 at 10:55
  • Already finished the challenge! You don't need to give me the answer, I already figured it out, it was a typo while assigning values to the headers.
    – DCBuilder
    Commented Jan 2, 2018 at 11:37

You must log in to answer this question.

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