Valhalla Legends Forums Archive | Visual Basic Programming | Converting TGA to BMP/JPG

AuthorMessageTime
UserLoser.
Is there any easy way this can be done? Maybe with DirectX as Grok posted before? (If so, how?)

Any comments/suggestions/examples?
February 7, 2004, 9:03 PM
Grok
I thought about this a little more, still haven't tried anything. Regardless of whether DirectX can do it, you could always render the TGA in a window, then convert the resulting DIB to BMP/JPG.

The window need not be visible.
February 8, 2004, 2:18 AM
MesiaH
As you know userloser, i was looking into this for a while.

Each 24 bit targa has a header, containing most of the rest of the information you need, but the problem is getting a function to convert the image to a windows recognizable format, other than that, there are tons of ways to display it, imagebox or picturebox if ur lazy, you cain paint it, set urself a device context, then use that in painting the picture (which is done as a DIB, bitmap)

I saw that one function you used to decompress the image, but its in like german, so i dont understand what variables to pass..

Edit: I could try writing my own, but i am extremely poor with mathematical programming, so id prolly never get it working.
February 9, 2004, 7:16 AM
UserLoser.
What I'm looking to do is have an owner drawn listbox (which is already being a pain in the ass to me), and have the icons (icons.bni) drawn for each user..
February 9, 2004, 4:48 PM
Grok
I use this library at work. It supports TGA, and BMP, JPG, etc. Using it you could convert TGA to DIB and then save the DIB to another format.

http://www.jpg.com/imagxpressview.htm
February 9, 2004, 5:39 PM
Adron
[quote author=MesiaH link=board=31;threadid=5157;start=0#msg43278 date=1076311003]
As you know userloser, i was looking into this for a while.

Each 24 bit targa has a header, containing most of the rest of the information you need, but the problem is getting a function to convert the image to a windows recognizable format, other than that, there are tons of ways to display it, imagebox or picturebox if ur lazy, you cain paint it, set urself a device context, then use that in painting the picture (which is done as a DIB, bitmap)

I saw that one function you used to decompress the image, but its in like german, so i dont understand what variables to pass..

Edit: I could try writing my own, but i am extremely poor with mathematical programming, so id prolly never get it working.
[/quote]

It's not hard at all. Try it!
February 9, 2004, 6:51 PM
Grok
Heh, gogo Blizzard. Their icons.bni is a broken TGA. According to the Truevision specification, find out if you have a valid TGA file by inspecting the last 26 bytes of the file. Bytes 8-23 should be 'TRUEVISION-XFILE'.

Blizzard wrote it to bytes 9-24. Ugh. So, Pegasus ImagXpress won't even recognize it.
February 9, 2004, 7:52 PM
TheMinistered
http://www.wotsit.org/search.asp?s=text
February 9, 2004, 11:15 PM
Grok
[quote author=TheMinistered link=board=31;threadid=5157;start=0#msg43399 date=1076368527]
http://www.wotsit.org/search.asp?s=text
[/quote]

Did you try icons.bni with that resource?
February 10, 2004, 5:59 AM
Yoni
[quote author=Grok link=board=31;threadid=5157;start=0#msg43342 date=1076356349]
Heh, gogo Blizzard. Their icons.bni is a broken TGA. According to the Truevision specification, find out if you have a valid TGA file by inspecting the last 26 bytes of the file. Bytes 8-23 should be 'TRUEVISION-XFILE'.

Blizzard wrote it to bytes 9-24. Ugh. So, Pegasus ImagXpress won't even recognize it.
[/quote]No, Blizzard did it right.
The "bytes 8-23" in the Truevision docs are 0-based, the "bytes 9-24" in your count are 1-based. That's the same thing...
The reason Pegasus couldn't read it is because it's a .bni, not a .tga.
icons.bni is a Blizzard-specific format (bni = Battle.net Icons, probably) that consists of a "BNI header" + a TGA file appended to it.

Here's how to extract the TGA:
1. Open icons.bni in a hex editor.
2. Examine the contents of the 4th dword in the file (bytes 13-16 as a little-endian dword). For example, in
C:\Misc\Battle.net\BinaryChat\icons.bni on my computer, the value is 384.
3. Delete that many bytes from the beginning of the file. (In my case, 384)
4. Save as a .tga and open with anything that reads .tga files.
February 18, 2004, 11:03 PM
Grok
What is a BNI header? I mean, I know its something Blizzard added, but what does it do? Layout?
February 18, 2004, 11:28 PM
Adron
The BNI header defines for what product or for what flags to use each particular icon in the file. There are as many entries as there are icons in the file. IIRC, the entries are one size for product icons and 4 bytes less for flags icons.
February 18, 2004, 11:33 PM
Skywing
You could also use IconView to grab the .tga.
February 19, 2004, 6:48 AM
UserLoser.
[quote author=Skywing link=board=31;threadid=5157;start=0#msg45003 date=1077173312]
You could also use IconView to grab the .tga.
[/quote]

I have that already, but thanks anyways

I can output the entire TGA to a file, but I'm still looking how to split up each image whenever I want to draw one to the listbox

I believe I have some ideas on how to do this - I just don't have the time because this week and probably the next few months will be very busy for me
February 20, 2004, 12:13 AM
K
[quote author=UserLoser. link=board=31;threadid=5157;start=0#msg45102 date=1077235994]
[quote author=Skywing link=board=31;threadid=5157;start=0#msg45003 date=1077173312]
You could also use IconView to grab the .tga.
[/quote]

I have that already, but thanks anyways

I can output the entire TGA to a file, but I'm still looking how to split up each image whenever I want to draw one to the listbox

I believe I have some ideas on how to do this - I just don't have the time because this week and probably the next few months will be very busy for me
[/quote]

IIRC, the BNI header for each product/flag includes the icon width and height - why not split them up into seperate images when you first load the BNI file, then reference those images? As someone previously mentioned, the task of drawing the TGA onto a surface is not difficult at all. Simply reference Kane's excellent BNI format page and a TGA format page if required.
February 20, 2004, 1:54 AM
Adron
[quote author=UserLoser. link=board=31;threadid=5157;start=0#msg45102 date=1077235994]
I can output the entire TGA to a file, but I'm still looking how to split up each image whenever I want to draw one to the listbox
[/quote]

There are GDI functions to copy only part of a bitmap (by passing in coordinates).
February 20, 2004, 7:52 PM

Search