0

Okay, my image is coming out a bit shifted and with two dark spots. please help me pinpoint whats going wrong

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

     //temporary storage - RGB triples 

     for(int m=0; m<n;m++)
    {
      // iterate over pixels in scanline
      for (int j = 0; j < bi_o.biWidth; j++)
      {

        // read RGB triple from infile
       fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
       storage[j]=triple;

      }

      for(int k=0;k<bi_o.biWidth;k++)
      {
      for(int f=0;f<n;f++)
      {
       fwrite(&storage[k],sizeof(RGBTRIPLE),1,outptr);
      }
     }

       if(m!=n-1)
      {       
       //set inptr to begginning of line
       fseek(inptr,-(bi_o.biWidth * sizeof(RGBTRIPLE)) , SEEK_CUR);
      }
      else
      {
       // skip over padding, if any
       fseek(inptr, original_padding, SEEK_CUR);
      }


     }


 for (int l= 0; l < padding; l++)
     {
        fputc(0x00, outptr);
     }

   }   
5
  • where did the variable m in the condition if(m!=n-1) come from? If you are trying to use the m variable from the for loop keep in mind the scope of the counter variable. – user1580 Sep 28 '14 at 16:20
  • Also, the line fseek(inptr,-(bi_o.biWidth * sizeof(RGBTRIPLE)) , SEEK_CUR) doesn't really set the input pointer to the beginning of the line. Due to SEEK_CUR it merely skips the number of bytes specified by -(bi_o.biWidth * sizeof(RGBTRIPLE))(and why is this negative??). – user1580 Sep 28 '14 at 16:24
  • Basically m is the count for the vertical resize. So for m!=n-1, the infile pointer is to shift to the beginning of the line(hence the - ) and for the m-1, it shouldn't shift to the beginning of the line, because it needs to skip over the padding in order to move to the next line. – Amrita Sep 28 '14 at 21:13
  • Just to make you clear on my logic: I'm basically iterating over the horizontal iteration n times. Like doing both the things at the same time. And I'm pretty sure that I'm messing up with the file pointer somewhere, but i don't know where! – Amrita Sep 28 '14 at 21:20
  • On a side note. How's the padding in the op file coming along? I presume the last loop with fputc is for the output file. Shouldn't that be in the m loop as well? It seems you're padding only one scanline out of the n scanlines for each original scanline. – user1580 Sep 29 '14 at 4:35

You must log in to answer this question.

Browse other questions tagged .