Sign in to follow this  
flammable

trouble with loading .tga files (*solved*)

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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this