• Welcome to Valhalla Legends Archive.
 

Targa Decompression

Started by FrostWraith, July 16, 2008, 04:55 PM

Previous topic - Next topic

FrostWraith

I decided to write a utility to do a number of things with a targa image, one of which is to decompress it.

Using the targa image that is contained in icons.bni, I am looking at the encoding it has.

00      00      0A      00      00      00      00      00      00      00
00      00      1C      00      18      01      18      00      01      BD
AD      6F      B5      A8      6E      81      88      81      5A      02


This snippet contains the tga header and a small amount of pixel data.
Noting the 0x0A (10), it has run-length encoding.

Question #1
From what I have read about RLE, I have found tutorials that are completely opposite of each other.  I am not sure which result is correct:

Example:
Data - AAAAAAAAAAAAABBCCCCCCCCCCCC

Would this be encoded as:
13A2B12C
or as
A13B2C12

Question #2
Looking at the data above, you can see the pixel data starts with this snippet:
01      BD      AD      6F      B5      A8      6E      81      88      81      5A      02
How would i separate this out?
1 pixel of BD, AD, 6F?
181 pixels! of  A8, 6E, 81?

Hdx

#1

Info length: 0
Map type: 0
Image Type: 10
Color Map Origin: 0
Color Map Length: 0
Color Map Entry Size: 0
Start: 0, 0
Size: 28x280
Depth: 24
Descriptor: 0

There is your header which leaves 01 BD AD 6F B5 A8 6E 81 88 81 5A 02 as your data.
Lets get started:
0x01 - 1 byte of raw pixel data, (189, 173, 111)
0xB5 - Since its > 128 [meaning it's highest bit is set] its RLE, 0xB5 - 128 = 53. So you have 53 pixel of (168, 110, 129)
0x88 - Since its > 128 its RLE, 0x88 - 128 = 8. 8 pixels of (129, 90, 2)

BUT to answer your question.
Let:
A = (1, 2, 3)
B = (4, 5, 6)
C = (7, 8, 9)
D = (10, 11, 12)
Image AAAAAAAAAAAAABBCCCCCCCCCCCCD Would be encoded as such:
8D 01 02 03 82 04 05 06 8C 07 08 09 01 0A 0B 0C

get it?

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

FrostWraith

#2
Quote0x01 - 1 byte of raw pixel data, (189, 173, 111)
0xB5 - Since its > 128 [meaning it's highest bit is set] its RLE, 0xB5 - 128 = 53. So you have 53 pixel of (168, 110, 129)
0x88 - Since its > 128 its RLE, 0x88 - 128 = 8. 8 pixels of (129, 90, 2)
I decided to use a premade tool to convert the image to a bmp and open it in paint to look at the pixels.  That first pixel is correct, but there aren't 53 consecutive pixels of the same color from the where the start is specified (bottom left i believe).

Hdx

Well, From what you gave me it should be. Unless I did my math wrong.
My Java Implementation
Google cache of the document I worked off of
Why not just try coding it as such and then see what you get.

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

MyndFyre

QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.