[SOLVED] problem creating IImage from .TGA files

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

[SOLVED] problem creating IImage from .TGA files

Postby xirtamatrix » Thu Dec 16, 2010 1:08 pm

hi,

I'm creating an IImage from the texture and then writing it to a file.
here's the code:

Code: Select all
IImage *image = driver->createImageFromFile(node->getMaterial(i).getTexture(0)->getName().getPath());

if (!driver->writeImageToFile(image, targetFolderName.toStdString().c_str()  ) )
{
               QMessageBox::warning(this, tr("Oops..."),
                          tr("Cannot write file %1 \n")
                         .arg(targetFolderName));
   writer->drop();
   image->drop();
   return false;
}



It works fine with .jpg and .png images but when using .TGA it seems createImageFromFile() fails to create an IImage.

Any idea why and/or what I'm doing wrong?

/regards
Last edited by xirtamatrix on Mon Dec 20, 2010 10:05 am, edited 1 time in total.
to live, is natural; to die, is not!
xirtamatrix
 
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Postby hybrid » Thu Dec 16, 2010 1:49 pm

Probably the tga file is broken or contains unsupported feated. Check the console log.
hybrid
Admin
 
Posts: 13942
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Postby xirtamatrix » Thu Dec 16, 2010 2:13 pm

hybrid wrote:Probably the tga file is broken or contains unsupported feated. Check the console log.


Thanks hybrid! No the TGA is ok, I've tested this with many different TGAs and same problem, also, no output in console.

It just occured to me that maybe the problem is not with creating the IImage at all, but how do I really check that? Right now nothing comming to my head. I tried doing:
Code: Select all
IImage *image = 0;
image = driver->createImageFromFile(node->getMaterial(i).getTexture(0)->getName().getPath());
if(!image)
{
   printf("FATAL ERROR: Failed to create image!!! \n");
   return false;
}


but the printf never gets executed, humn... so which means something is getting into *image afterall... but problem is when I'm doing:
Code: Select all
if (!driver->writeImageToFile(image, targetFolderName.toStdString().c_str()  ) )

the if always gets true so meaning the image never gets written. Can't be any problem with paths because in case of .jpg and .png everything working perfectly.

weird! ( scrathing head...)
to live, is natural; to die, is not!
xirtamatrix
 
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Postby hybrid » Thu Dec 16, 2010 3:36 pm

Ok, that's a different thing then. So first, check if the image is correctly loaded. E.g. by exporting it into a jpg instead. And also check if a corerct tga is created. Maybe it's just the return code that is wrong. If everything works fine, I'll check the image writer code.
hybrid
Admin
 
Posts: 13942
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Postby xirtamatrix » Fri Dec 17, 2010 5:04 pm

ok, did as you suggested and I can confirm the IImage is created correctly from the source TGA and it is written correctly if writing as .jpg

The problem appears when trying to write it as .tga, so... the problem lies somewhere with writeImageToFile() I suspect.

/regards
to live, is natural; to die, is not!
xirtamatrix
 
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Postby xirtamatrix » Mon Dec 20, 2010 8:43 am

hybrid wrote:Ok, that's a different thing then. So first, check if the image is correctly loaded. E.g. by exporting it into a jpg instead. And also check if a corerct tga is created. Maybe it's just the return code that is wrong. If everything works fine, I'll check the image writer code.


I also checked writing a .png from the same TGA file and it also works fine and retains transparency.

So the problem really is somewhere in the TGA writer. Would much appeciate if you could take a look at it.
to live, is natural; to die, is not!
xirtamatrix
 
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Postby CuteAlien » Mon Dec 20, 2010 9:49 am

Ok, thanks - it was really a bug in the writer (a wrong check for success in CImageWriterTGA::writeImage). It's fixed now in Irrlicht 1.7 release branch (r3515).

If you want to fix it locally on your Irrlicht - change in the last line in
CImageWriterTGA::writeImage the < into <=

Code: Select all
return imageHeader.ImageHeight <= y;
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5349
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Postby xirtamatrix » Mon Dec 20, 2010 10:04 am

CuteAlien wrote:Ok, thanks - it was really a bug in the writer (a wrong check for success in CImageWriterTGA::writeImage). It's fixed now in Irrlicht 1.7 release branch (r3515).

If you want to fix it locally on your Irrlicht - change in the last line in
CImageWriterTGA::writeImage the < into <=

Code: Select all
return imageHeader.ImageHeight <= y;


wow! that was fast :)
Thank you very much really! I fixed it and working fine now.

/regards
to live, is natural; to die, is not!
xirtamatrix
 
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest