Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: UserLoser. on February 07, 2004, 03:03 PM

Title: Converting TGA to BMP/JPG
Post by: UserLoser. on February 07, 2004, 03:03 PM
Is there any easy way this can be done?  Maybe with DirectX as Grok posted before? (If so, how?)

Any comments/suggestions/examples?
Title: Re:Converting TGA to BMP/JPG
Post by: Grok on February 07, 2004, 08:18 PM
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.
Title: Re:Converting TGA to BMP/JPG
Post by: Mesiah / haiseM on February 09, 2004, 01:16 AM
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.
Title: Re:Converting TGA to BMP/JPG
Post by: UserLoser. on February 09, 2004, 10:48 AM
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..
Title: Re:Converting TGA to BMP/JPG
Post by: Grok on February 09, 2004, 11:39 AM
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 (http://www.jpg.com/imagxpressview.htm)
Title: Re:Converting TGA to BMP/JPG
Post by: Adron on February 09, 2004, 12:51 PM
Quote from: MesiaH on February 09, 2004, 01:16 AM
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.

It's not hard at all. Try it!
Title: Re:Converting TGA to BMP/JPG
Post by: Grok on February 09, 2004, 01:52 PM
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.
Title: Re:Converting TGA to BMP/JPG
Post by: TheMinistered on February 09, 2004, 05:15 PM
http://www.wotsit.org/search.asp?s=text
Title: Re:Converting TGA to BMP/JPG
Post by: Grok on February 09, 2004, 11:59 PM
Quote from: TheMinistered on February 09, 2004, 05:15 PM
http://www.wotsit.org/search.asp?s=text

Did you try icons.bni with that resource?
Title: Re:Converting TGA to BMP/JPG
Post by: Yoni on February 18, 2004, 05:03 PM
Quote from: Grok on February 09, 2004, 01:52 PM
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.
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.
Title: Re:Converting TGA to BMP/JPG
Post by: Grok on February 18, 2004, 05:28 PM
What is a BNI header?  I mean, I know its something Blizzard added, but what does it do?  Layout?
Title: Re:Converting TGA to BMP/JPG
Post by: Adron on February 18, 2004, 05:33 PM
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.
Title: Re:Converting TGA to BMP/JPG
Post by: Skywing on February 19, 2004, 12:48 AM
You could also use IconView (http://www.valhallalegends.com/skywing/files/IconView/IconView.zip) to grab the .tga.
Title: Re:Converting TGA to BMP/JPG
Post by: UserLoser. on February 19, 2004, 06:13 PM
Quote from: Skywing on February 19, 2004, 12:48 AM
You could also use IconView (http://www.valhallalegends.com/skywing/files/IconView/IconView.zip) to grab the .tga.

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
Title: Re:Converting TGA to BMP/JPG
Post by: K on February 19, 2004, 07:54 PM
Quote from: UserLoser. on February 19, 2004, 06:13 PM
Quote from: Skywing on February 19, 2004, 12:48 AM
You could also use IconView (http://www.valhallalegends.com/skywing/files/IconView/IconView.zip) to grab the .tga.

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

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.
Title: Re:Converting TGA to BMP/JPG
Post by: Adron on February 20, 2004, 01:52 PM
Quote from: UserLoser. on February 19, 2004, 06:13 PM
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

There are GDI functions to copy only part of a bitmap (by passing in coordinates).