TGA / JPG loading Bug in OpenGL! (partial fix)

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

TGA / JPG loading Bug in OpenGL! (partial fix)

Post by chromdragon »

when loading a .tga texture (IRR must flip the image so that is right but it does not)

when loading the some img in .jpg format the img si flip correctly!
Last edited by chromdragon on Mon May 08, 2006 12:46 pm, edited 2 times in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

There is a tag in tga which tells the app if the image should be flipped or not. This is not honored by Irrlicht. But, there are also tools which do not set this tag correctly, so even when flipping the image it might still not work with some gfx tools. But yes, should be fixed to be standard conforming.
Is the behavior in JPG also buggy, or did you just meant that with jpg it's working correctly?
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

Post by chromdragon »

A quick hack for now!

Code: Select all

void CImage::flip(bool yup, bool xup)
{
	c8 *cData = (c8 *) Data;
	s32 maxX = Size.Width, maxY = Size.Height;

	if (Format == video::ECF_A8R8G8B8 && yup == true)
	{
		for(s32 y=0; y<maxY/2-1; y++)
		for(s32 x=0; x<maxX; x++)
		{
				c8 oldColor[4];

				oldColor[0] = cData[Size.Width * y*4 + x*4 + 0];
				oldColor[1] = cData[Size.Width * y*4 + x*4 + 1];
				oldColor[2] = cData[Size.Width * y*4 + x*4 + 2];
				oldColor[3] = cData[Size.Width * y*4 + x*4 + 3];

				cData[Size.Width * y*4 + x*4 + 0] = cData[Size.Width * (maxY-y-1)*4 + x*4 + 0];
				cData[Size.Width * y*4 + x*4 + 1] = cData[Size.Width * (maxY-y-1)*4 + x*4 + 1];
				cData[Size.Width * y*4 + x*4 + 2] = cData[Size.Width * (maxY-y-1)*4 + x*4 + 2];
				cData[Size.Width * y*4 + x*4 + 3] = cData[Size.Width * (maxY-y-1)*4 + x*4 + 3];

				cData[Size.Width * (maxY-y-1)*4 + x*4 + 0] = oldColor[0];
				cData[Size.Width * (maxY-y-1)*4 + x*4 + 1] = oldColor[1];
				cData[Size.Width * (maxY-y-1)*4 + x*4 + 2] = oldColor[2];
				cData[Size.Width * (maxY-y-1)*4 + x*4 + 3] = oldColor[3];
		}
	}

	else if (Format == video::ECF_R8G8B8 && yup == true)
	{
		for(s32 y=0; y<maxY/2-1; y++)
		for(s32 x=0; x<maxX; x++)
		{
				c8 oldColor[3];

				oldColor[0] = cData[Size.Width * y*3 + x*3 + 0];
				oldColor[1] = cData[Size.Width * y*3 + x*3 + 1];
				oldColor[2] = cData[Size.Width * y*3 + x*3 + 2];

				cData[Size.Width * y*3 + x*3 + 0] = cData[Size.Width * (maxY-y-1)*3 + x*3 + 0];
				cData[Size.Width * y*3 + x*3 + 1] = cData[Size.Width * (maxY-y-1)*3 + x*3 + 1];
				cData[Size.Width * y*3 + x*3 + 2] = cData[Size.Width * (maxY-y-1)*3 + x*3 + 2];

				cData[Size.Width * (maxY-y-1)*3 + x*3 + 0] = oldColor[0];
				cData[Size.Width * (maxY-y-1)*3 + x*3 + 1] = oldColor[1];
				cData[Size.Width * (maxY-y-1)*3 + x*3 + 2] = oldColor[2];
		}
	}

	if (Format == video::ECF_A8R8G8B8 && xup == true)
	{
		for(s32 y=0; y<maxY; y++)
		for(s32 x=0; x<maxX/2-1; x++)
		{
				c8 oldColor[4];

				oldColor[0] = cData[Size.Width * y*4 + x*4 + 0];
				oldColor[1] = cData[Size.Width * y*4 + x*4 + 1];
				oldColor[2] = cData[Size.Width * y*4 + x*4 + 2];
				oldColor[3] = cData[Size.Width * y*4 + x*4 + 3];

				cData[Size.Width * y*4 + x*4 + 0] = cData[Size.Width * y*4 + (maxX-x-1)*4 + 0];
				cData[Size.Width * y*4 + x*4 + 1] = cData[Size.Width * y*4 + (maxX-x-1)*4 + 1];
				cData[Size.Width * y*4 + x*4 + 2] = cData[Size.Width * y*4 + (maxX-x-1)*4 + 2];
				cData[Size.Width * y*4 + x*4 + 3] = cData[Size.Width * y*4 + (maxX-x-1)*4 + 3];

				cData[Size.Width * y*4 + (maxX-x-1)*4 + 0] = oldColor[0];
				cData[Size.Width * y*4 + (maxX-x-1)*4 + 1] = oldColor[1];
				cData[Size.Width * y*4 + (maxX-x-1)*4 + 2] = oldColor[2];
				cData[Size.Width * y*4 + (maxX-x-1)*4 + 3] = oldColor[3];
		}
	}

	else if (Format == video::ECF_R8G8B8 && xup == true)
	{
		for(s32 y=0; y<maxY; y++)
		for(s32 x=0; x<maxX/2-1; x++)
		{
				c8 oldColor[3];

				oldColor[0] = cData[Size.Width * y*3 + x*3 + 0];
				oldColor[1] = cData[Size.Width * y*3 + x*3 + 1];
				oldColor[2] = cData[Size.Width * y*3 + x*3 + 2];

				cData[Size.Width * y*3 + x*3 + 0] = cData[Size.Width * y*3 + (maxX-x-1)*3 + 0];
				cData[Size.Width * y*3 + x*3 + 1] = cData[Size.Width * y*3 + (maxX-x-1)*3 + 1];
				cData[Size.Width * y*3 + x*3 + 2] = cData[Size.Width * y*3 + (maxX-x-1)*3 + 2];

				cData[Size.Width * y*3 + (maxX-x-1)*3 + 0] = oldColor[0];
				cData[Size.Width * y*3 + (maxX-x-1)*3 + 1] = oldColor[1];
				cData[Size.Width * y*3 + (maxX-x-1)*3 + 2] = oldColor[2];
		}
	}
}
Post Reply