Jump to content
  • Advertisement

Archived

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

Viscous-Flow

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

This topic is 6092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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);
}

free(Buffer);
}

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!