0

I have been struggling with resize (less). I can't seem to make sense of how to put the value of triple that is being read into an array (rewrite method) Any help will be appreciated

// iterate over infile's scanlines
 for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
 {
     //storing pixels in scanline here
     RGBTRIPLE pixel[bi.biWidth * n];


     // iterate over pixels in scanline
     for (j = 0; j < bi.biWidth; j++)
     {
         // temporary storage
         RGBTRIPLE triple;

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

        // save triple into an array of pixel
        //TODO
     }

     // write line vertically n times
     for (int vertical = 0; vertical < n; vertical++)
     {
         //write array to file 
         for (hor = 0; hor < outbi.biWidth; hor++)
         {
             fwrite(&pixel, sizeof(RGBTRIPLE), 1, outptr);    
         }

         // write padding for outfile if neccessary
         for (int pad = 0; pad < outpadding; pad++)
         {
             fputc(0x00, outptr);
         }


     }

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

 }

 // close infile
 fclose(inptr);

 // close outfile
 fclose(outptr);

 // success
 return 0;
}
2

(already answered on reddit, just for this question to have an answer)

Instead of

fwrite(&pixel, sizeof(RGBTRIPLE), 1, outptr);

use

fwrite(&pixel[hor], sizeof(RGBTRIPLE), 1, outptr);

or equivalently

fwrite(pixel + hor, sizeof(RGBTRIPLE), 1, outptr);

&pixel[hor] and pixel + hor both represent the memory address of the horth element of pixel.

You must log in to answer this question.

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