View Single Post
Old 04-20-2007, 07:20 PM   #22
tk102
Well past expiration date
 
tk102's Avatar
 
Join Date: Jan 2004
Posts: 5,766
Current Game: Dragon Age: Origins
Forum Veteran Helpful! Notable contributor 
The fwrite function is writing row by row starting at the end of the array. Think of the array as the image mirrored vertically. (Left-right is maintained but top-bottom is reversed.) I'm sorry for confusing you by saying byte-by-byte earlier.

Here's the declaration for fwrite
Code:
size_t fwrite(const void *ptr, size_t size, size_t nitems,
    FILE *stream);
We are using size=4, and nitems=pitch (the width in pixels of the iamge), so each fwrite is writing 4*pitch bytes. The fwrite function returns the number of items (not bytes) which should be equal to pitch in our case. The array's memory address begins at file->pixels, so at the beginning of the loop to write the last row from the array the offset would be (pitch*(ysz-1)). The next to last row would begin at (pitch*(ysz-2)).

HTH and sorry for not having the concentration earlier.

Last edited by tk102; 04-21-2007 at 11:19 AM.
tk102 is offline   you may: quote & reply,