0

My resize program is having trouble resizing an unless I use 4 for the scale, which resizes the image perfectly. Using a number like 1, 2, 3, or 5, 10, etc. results in a really crazy image. Here is the relevant code, I'm attempting to use the recopy method for vertical resizing.

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
    // if height for outfile is not completed, go back to previously set position to continue writing
    for (int m = 0; m < scale - 1; m++)
    {
        // iterate over pixels in infile scanline
        for (int n = 0; n < bi.biWidth; n++)
        {
            // temporary storage
            RGBTRIPLE triple;

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

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

        // add new padding to outfile
        for (int p = 0; p < new_padding; p++)
        {
            fputc(0x00, outptr);
        }

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

        // seek to beginning of infile scanline's row
        fseek(inptr, -((bi.biWidth * sizeof(RGBTRIPLE)) + padding), SEEK_CUR);
    }

    // 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
        for (int k = 0; k < scale; k++)
        {
            fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
        }

        // then add new padding to outfiles
        for (int l = 0; l < new_padding; l++)
        {
            fputc(0x00, outptr);
        }
    }

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

Actually, it works only when the padding on the output file is 0. If the input file had a different size padding, the scale factors that would work would be different, but would be every 4th integer of scaling factor.

The problem lies in the placement of a single closing curly brace. In the j loop, the padding is added after every pixel, not at the end of the line. If the padding is 0, it doesn't have any effect. For any non-zero padding, it inserts extra bytes after each pixel. Should be easy enough to fix! ;-)

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

1
  • You're awesome! Thank you, I really do appreciate you taking your time to help me!! :) Aug 17 '18 at 18:50

You must log in to answer this question.

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