0

Still working on this... headers are fine as no matter what I put in as factor the header files match with the staff implementation. Now I'm getting a square of the right size but only the top half is green. Here is the part of my code where I'm reading the pixels and printing them out... I'm so close, but clueless.

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
    // 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 y = 0; y <= number; y++)
        {
            fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
            fseek(inptr, bi.biWidth * sizeof(RGBTRIPLE), SEEK_CUR);
        }

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

        // Add a new padding
          for (int l = 0; l < out_padding; l++)
          fputc(0x00, outptr);

        // Return to the beginning of a scanline
        fseek(inptr, -(bi.biWidth * sizeof(RGBTRIPLE) + padding), SEEK_CUR);
    }

}
0

You need to spend some time and carefully examine what you are doing with all those fseek commands. The code reads a single RGBTRIPLE, writes out that triple, skips forward a full line in the input file, less padding (repeating the write and the skip forward 'number' times), skips forward in the input file an amount equal to the padding (assuming it is correct), and then skips backward in the input file one line including padding - all this before processing the second RGBTRIPLE! The code needs to process an entire line of pixels before moving back to the beginning of the line.

Simply put, the code is just jumping around too much in the input file to get anything right. You need to rethink the logic of what is being done and when. Since that is the core of the assignment, I leave it to you to sort out, now that you have a pointer to what is wrong.

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

1
  • ok took a look and got rid of some lines of code. My output now is a properly sized square with the top 3 lines in green, and in the center of the top line is the white part. Am I on the right track thinking i have a problem in one of my for loops... horizontal sizing?
    – uddane
    Apr 20 '16 at 1:03

You must log in to answer this question.

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