3

I am struggling with the vertical resizing using the recopy approach. I read a pseudocode in an answer to another question in this forum and am trying to code it. I feel I am near but something is not working. Could you help? Thank you very much

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(BHold); i < biHeight; i++)
{
 for (int j = 0; j < coeficiente; j++)
 {
     if (j != 0) 
     fseek(inptr, -BWold, SEEK_CUR);

     // iterate over pixels in scanline
     for (int k = 0; k < BWviejo; k++)
     {
         // temporary storage
         RGBTRIPLE triple;

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

         //escribir n veces cada pixel
         for (int l = 0; l < coeficiente; l++)
            fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);

    }
    // agregar el nuevo padding
    for (int k = 0; k < newpadding; k++)
       fputc(0x00, outptr);
 }    

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

}
3

Assuming BWold is the width of the original image, this value represents the number of pixels in every row of the image, you need to consider that a pixel (or RGBTRIPLE) is three bytes.

So in the same way you are using fseek to read from the file, reading the size of a RGBTRIPLE for every pixel, to move the cursor back a row of pixels you have to do it BOld times the size of a RGBTRIPLE. Then your fseek() call should be something like this:

fseek(inptr, -(BWold * sizeof(RGBTRIPLE)), SEEK_CUR);
| improve this answer | |
  • Solved, thanks! I forgot width was measured in pixels and the pointer movement has to be indicated in bytes. – Federico Dec 14 '14 at 14:32
  • OMG! 5 hours looking into my broken fseek code are finally ended!!! Thanks both Federico and wallek876!!! Cheers guys! :) – Alex Zamai Mar 1 '15 at 8:43

You must log in to answer this question.

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