0

I am pretty certain that my problem in this problem is my fseek in my vertical resizing for loop. Basically my idea is to print out horizontally resized code once per scan line always, then depending on factor size repeat the line by going back with that first fseek line. I don't think I would have to add the padding to the offset of fseek (fputc wouldn't move the fseek cursor right?), but I tried it anyways and it didn't work. I want to try to debug this with gdb or debug50, but I don't really know how to approach it in this program. Any thoughts?

// creates offset that is size of infile that vertical scaling wants to go back by
long offset = bi.biWidth * sizeof(RGBTRIPLE);

// iterate over infile's scanlines (rows)
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
    // write pixels (columns)
    for (int j = 0; j < bi.biWidth; j++)
    {
        RGBTRIPLE triple;

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

        // write triple to outfile n times for horizontal scaling
        for( int n = 0; n < factor; n++)
        {
            fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
        }
    }

    // put outpadding value to outfile (diff from inpadding remember)
    for (int k = 0; k < outPadding; k++)
    {
        fputc(0x00, outptr);
    }

    // if factor is greater than 1, need to repeat scan line factor - 1 times
    // remember this whole for loop is optional and simply repeats row any time
    // that it needs to scale up, if factor is 10 this loop will execute 9 times
    // because the outermost for loop makes sure to write it once if factor is 1
    for (int t = 0; t < factor - 1; t++)
    {
        fseek(inptr, -offset, SEEK_CUR);
        // iterate over pixels in scanline (columns)
        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
            // scale horizontally by writing each pixel factor times across
            for (int n = 0; n < factor; n++)
            {
                fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
            }
        }

        // add padding to outfile
        for (int k = 0; k < outPadding; k++)
        {
            fputc(0x00, outptr);
        }
        // remember that fseek is to change the cursor for the inFile
        // here I want to go back
        //if (t != bi.biWidth - 1)
      //  {
      //      fseek(inptr, -offset, SEEK_CUR);
      //  }

    }

    // skipp inPadding which sets up cursor for next part in file
    fseek(inptr, inPadding, SEEK_CUR);

}
0

Actually as it happens fseek here does work as intended. This is because on each time you want to resize vertically using the for loop

for (int t = 0; t < factor - 1; t++)

you first fseek back the appropriate amount of units via the calculation from offset that is

long offset = bi.biWidth * sizeof(RGBTRIPLE);

So if there isn't a problem with fseek and there is still an image with black pixels, or all around messed up image, then there very likely is an issue with the padding. You can use gdb or debug50 in this case to print the padding when it is created and along in the program to see if it changes or does something wacky. The way you originally commented out fseek at the bottom in the if loop would work as long as the vertical scaling for loop was first so that the pointer for the infile would then be at the end of the file for each pass until the very last so that in the outermost for loop the infile pointer would not start at the beginning of the last line.

You must log in to answer this question.

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