This topic is now archived and is closed to further replies.


How to inverse the origin of a TGA file (flip it upside down)?

Recommended Posts

Hello, I have tried to flip a TGA upside down, but I can''t get it to work. I essentially do something like this:
unsigned char t;
for (int z = 0, y = tgaImageSize-1; z < tgaImageSize; z++, y--)
	t = tgaImageData[y];
	tgaImageData[y] = tgaImageData[z];
	tgaImageData[z] = t;
It just displays the texture as it looked before I did this. Any help would be greatly appreciated!

Share this post

Link to post
Share on other sites
From my engine:
void rRawInfo::FlipVert(void) {
rByte *Buffer;
unsigned int a, b, c, d;

b = Width*BytesPP;
c = Height/2;

Buffer = (rByte *) malloc(b);

for(a=0; a<c; a++) {
d = ((Height-1)-a)*b;
memcpy(Buffer, &Data[a*b], b);
memcpy(&Data[a*b], &Data[d], b);
memcpy(&Data[d], Buffer, b);


It''s not super-optimized, but it works for me. I don''t load too many targas or bitmaps anyway, I use my own image format that has them up right by default.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post

Link to post
Share on other sites
Wow, never realized how much code from the C-version of my engine was still in the new version, heh. I'll have to replace that malloc with new now . 3 posts in one thread before a response, heh...

[EDIT: I guess you did respond in time ]

[Resist Windows XP's Invasive Production Activation Technology!]

Edited by - Null and Void on October 18, 2001 8:52:44 PM

Share this post

Link to post
Share on other sites