Advertisement
Guest User

resize no vertical

a guest
Apr 26th, 2015
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.12 KB | None | 0 0
  1.     int padding =  (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
  2.     int oldPadding =  (4 - (oldWidth * sizeof(RGBTRIPLE)) % 4) % 4;
  3.  
  4.     long inposit = ftell(inptr);
  5.     long outposit = ftell(outptr);
  6.      
  7.     // iterate over infile's scanlines
  8.     for(int i = 0; i < abs(oldHeight); i++)
  9.     {
  10.         //iterate over the scanlines n times
  11.         for(int j = 0; j < n; j++)
  12.         {
  13.             //iterate over the pixels
  14.             for(int k = 0; k < abs(oldWidth); k++)
  15.             {
  16.                 //get temp var
  17.                 RGBTRIPLE triple;
  18.                  
  19.                 //store file position
  20.                 //inposit = ftell(inptr);
  21.                  
  22.                 //set the correct position to read from
  23.                 fseek(inptr, inposit, SEEK_SET);
  24.                  
  25.                 //read pixel into infile
  26.                 fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
  27.                  
  28.                 //store file position
  29.                 inposit = ftell(inptr);
  30.                  
  31.                 //set the correct position to write to
  32.                 fseek(outptr, outposit, SEEK_SET);
  33.                  
  34.                 //write n times to outfile
  35.                 for(int l = 0; l < n; l++)
  36.                 {
  37.                     fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
  38.                 }
  39.                  
  40.                 outposit = ftell(outptr);
  41.             }
  42.              
  43.              
  44.             // then add it back (to demonstrate how)
  45.             for (int k = 0; k < padding; k++)
  46.             {
  47.                 fputc(0x00, outptr);
  48.             }
  49.  
  50.             //send outptr to the next line
  51.             fseek(outptr, padding, SEEK_CUR);
  52.              
  53.             //return to start of line for reading
  54.             fseek(inptr, 0 - oldWidth, SEEK_CUR);
  55.              
  56.             //update inposit and outposit
  57.             //inposit = ftell(inptr);
  58.             outposit = ftell(outptr);
  59.              
  60.         }
  61.          
  62.         //move input fileposition to the next line
  63.         // skip over padding, if any
  64.         fseek(inptr, oldWidth + oldPadding, SEEK_CUR);
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement