## Recommended Posts

After taking a deep breath I've rewritten the piece of code and everything works now. I can't delete this post (deleting time is expired) and I don't think this topic is useful for anybody so I think it can be deleted. maby it can be useful if I tell what I did wrong: this was my FlipVertical function:
void TgaImage::FlipVertical()
{
if (myValid == false)
return;

unsigned int RowDataSize = myWidth * myBpp;
byte* Temp = new byte[RowDataSize];
unsigned int Top;
unsigned int Bottom;

for (int i = 0 ; i < (myHeight / 2) ; ++i)
{
Top = i * RowDataSize;
Bottom = (myHeight * RowDataSize) - (i * RowDataSize);

memcpy(Temp, &myData[Top], RowDataSize);
memcpy(&myData[Top], &myData[Bottom], RowDataSize);
memcpy(&myData[Bottom], Temp, RowDataSize);
}

delete [] Temp;
}

what I did wrong is: (myHeight * RowDataSize) gives the end of the data. When i = 0 (i * RowDataSize) = 0 too. so myData[Bottom] will be pointing behind the boundaries of myData. To solve this I needed to do something like:((myHeight - 1) * RowDataSize) - (i * RowDataSize). [Edited by - flammable on March 18, 2009 9:51:38 AM]

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627736
• Total Posts
2978856

• 10
• 10
• 21
• 14
• 12