0

i take the re-copy approach guys and badly stuck in that problem .. everything my code is fine just writing pixel is wrong somewhere. i'm posting my writing snippet of my resize please give me some hints for that.

// here is my code for writing pixels using re-copy approach . please help

  for ( int i = 0 , biHeight = abs ( bi_new.biHeight ) ; i < biHeight ; i++ ) 
  {
     for ( int j = 0 ; j < bi_new.biWidth ; j++ ) 
     {
        // temp storage 
        RGBTRIPLE triple ;

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

        // write to outfile 
        fwrite ( &triple , sizeof ( RGBTRIPLE ) * size , 1 , outptr ) ;
     }

     // add padding 
     for ( int k = 0 ; k < padding_new ; k++ )
     {
        fputc ( 0x00 , outptr ) ;
     }
     // skip over padding if any 
     fseek ( inptr , padding_old , SEEK_CUR ) ;
     if ( size != 1 ) 
     {
     // write vertical pixels
     fseek ( inptr , bi.biWidth , SEEK_SET ) ;
     for ( int l = 0 ; l < bi_new.biWidth ; l++ ) 
     {
       //temp storage
       RGBTRIPLE triple1;

       // read from inline
       fread ( &triple1 , sizeof ( RGBTRIPLE ) , 1 , inptr ) ;

       // write to outfile 
       fwrite ( &triple1 , sizeof ( RGBTRIPLE ) * size , 1 , outptr ) ;
     }
     //add padding 
     for ( int m = 0 ; m < padding_new ; m++ ) 
     {
        fputc ( 0x00 , outptr ) ;
     }
     // skip over padding
     fseek ( inptr , padding_old , SEEK_CUR ) ;

   }
}
2
  • What's not working properly? How is it different from what you expect? Is there any error message?
    – Air
    Sep 26, 2014 at 21:58
  • no there is no error. but the picture is seem so messed up. i want to resize the picture vertically and horizontally. please help Sep 27, 2014 at 4:24

1 Answer 1

2

Why are you vertically resizing twice? Your nested for loop at the top should take care of both your vertical and horizontal iterations. The other for loop you have at the bottom appears completely redundant.

When writing the rgb triple, unfortunately you can't just say, "write it *4 times". C isn't that smart. It writes it once and then fills the other 3 times with garbage values or unknown values...which is why your colors are strange.

To resize, pseudocode below:

//iterate over infile scanlines for loop
    //for loop for vertical resize   
       //if this isn't the first time through this row to resize vertically
          //use fseek to reset the cursor back to the start of the row
       //for loop for horizontal resize
          //read a single RGB triple in
          //for loop to write that triple n number of times
          //add new padding
//skip old padding
11
  • so how do i resize it vertically ? .. i don't get the desired output picture. the output picture is messed up with unknown colours Sep 27, 2014 at 4:23
  • Revised above Answer
    – lethaljd
    Sep 27, 2014 at 21:45
  • thank you problem is now solved .. thank you guys Oct 2, 2014 at 21:11
  • Can anyone help me? I don't know how to express condition //if this isn't the first time through this row to resize vertically ? Nov 14, 2014 at 15:11
  • tried with if vertical loop modulo n not equal 0 and some other combination but cant figure out the right way Nov 14, 2014 at 15:35

You must log in to answer this question.

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