Unheadered (?) TGA and BMP

Textures, recreate headers, conversions, algorithms and parsing of image files
lupus
Posts: 36
Joined: Sun Dec 03, 2017 7:52 am

Unheadered (?) TGA and BMP

Post by lupus »

Hi after unpacking Jungle Storm data (NNG) I have many TGA and BMP pics, but seems it all unheadered.
So, I can see some "image" opening TGA with hex editor. Also I try paste header to BMP from other image and can see some data with i_wiev bat it not correct.
Is it possible to restore headers or convert images for editing?
Samples and executable here:
https://mega.nz/#!5lNRGDja!VkOkvAH8UCbG ... xjLvSzOkX0
Upd
Also i can see some gfx with texture finder.
episoder
Posts: 123
Joined: Fri Oct 27, 2017 7:36 pm

Re: Unheadered (?) TGA and BMP

Post by episoder »

if you got texture finder you can work with it. all the files have the sizes in the broken headers. the ai_somethings are a plain 16-bit rgb. most others have 32-bit palettes with a 8-bit index format (256 colors).

Code: Select all

header_tga
{
   int32   dummy;
   int32   width;
   int32   height;
   int32   nr_pal_entries;
   int32   unk0;
   int32   unk1;
}

then palette

then index bitmap


the bmp have this lil header. a 16-bit palette and 8-bit index format (256 colors).

Code: Select all

header_bmp
{
   byte   unk0;
   int32   width;
   int32   height;
}

then palette

then index bitmap


i gotta write bmses? maybe acewell does again. :)
lupus
Posts: 36
Joined: Sun Dec 03, 2017 7:52 am

Re: Unheadered (?) TGA and BMP

Post by lupus »

Thx! bms script will be great!
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

[N-Gage] Ghost Recon: Jungle Storm (.tga\.bmp)

Post by Acewell »

i guess episoder isn't coming back :P
i don't usually deal with palleted images but i figured i'd play around with these for some experience :)
here is a Noesis python script to at least open the tga and bmp samples which i think look ok now. :D
*script updated December 24, 2017*
tex_GhostReconJungleStorm_NGage_tga_bmp.zip


i looked up "Jungle Storm" and got a hit with "Ghost Recon: Jungle Storm" 2004,
so i labeled the script after that game, and i assume the samples are from "N-Gage" judging by your signature. :)
Last edited by Acewell on Sat Dec 30, 2017 6:19 pm, edited 2 times in total.
lupus
Posts: 36
Joined: Sun Dec 03, 2017 7:52 am

Re: Unheadered (?) TGA and BMP

Post by lupus »

Acewell Oh, thanks man, I'm almost lose the hope! Looks like it works fine with many tga from Ghost Recon but bmp...
Also, I found another gameloft game Splinter Cell Chaos Theory. Looks like it uses similar unheadered tga and bmp, but Noesis can't show it :/

Can I upload samples and pm it to you?
episoder
Posts: 123
Joined: Fri Oct 27, 2017 7:36 pm

Re: Unheadered (?) TGA and BMP

Post by episoder »

ohh. sorry i took detours. i got some behemoth thing i'm trying to do.

nonetheless... i played with those bmps a lil bit just now. it doesn't make a lot of sense. endianness fails. standard palette formats fail. and...

the index map could still be used as a sorta brightness map gimmick. i just... didn't get the obvious thing.

Image

a good morning coffee later :D

nvm: me editing

*snip*

that was code for the rgb4 palette and stuff...
Last edited by episoder on Fri Dec 22, 2017 9:29 am, edited 1 time in total.
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

Re: Unheadered (?) TGA and BMP

Post by Acewell »

lupus wrote:Also, I found another gameloft game Splinter Cell Chaos Theory. Looks like it uses similar unheadered tga and bmp, but Noesis can't show it :/
Can I upload samples and pm it to you?

better if you make a new thread for each game and link samples there, but like i already said,
i don't usually deal with paletted textures and i also don't deal with or discuss research in private,
i believe in open research to share with everyone. :)
episoder
Posts: 123
Joined: Fri Oct 27, 2017 7:36 pm

Re: Unheadered (?) TGA and BMP

Post by episoder »

Acewell wrote:i believe in open research to share with everyone. :)

you too? me too. pretty strict 'no private requests' rule.

well... now... it seems to work. reads the bmps as rgbx4 palette with alpha key index. cpt. obvious failure. :mrgreen:

Code: Select all

log MEMORY_FILE1 0 0 ; out
log MEMORY_FILE2 0 0 ; tpal

goto 1 0
get width long 0
get height long 0
get nr_pals short 0
get alphakey byte 0
get shortcut byte 0

for p = 1 to nr_pals
get pal short
set r pal
math r >> 4
math r & 0xF0
set g pal
math g >> 0
math g & 0xF0
set b pal
math b << 4
math b & 0xF0
put b byte MEMORY_FILE2
put g byte MEMORY_FILE2
put r byte MEMORY_FILE2
put 0xFF byte MEMORY_FILE2 ; alpha is not present but always opaque
next p

xmath ofs_pal "alphakey * 4 + 3"
goto ofs_pal MEMORY_FILE2
put 0 byte MEMORY_FILE2 ; not opaque

put 0 byte MEMORY_FILE1
put 0 byte MEMORY_FILE1
put 2 byte MEMORY_FILE1
put 0 byte MEMORY_FILE1
put 0 byte MEMORY_FILE1
put 0 byte MEMORY_FILE1
put 0 byte MEMORY_FILE1
put 0 byte MEMORY_FILE1
put 0 short MEMORY_FILE1
put 0 short MEMORY_FILE1
put width short MEMORY_FILE1
put height short MEMORY_FILE1
put 32 byte MEMORY_FILE1
put 0x20 byte MEMORY_FILE1

for y = 1 to height
for x = 1 to width
get px byte 0

math ofs_pal = px
math ofs_pal *= 4
goto ofs_pal MEMORY_FILE2
get rgba long MEMORY_FILE2
put rgba long MEMORY_FILE1

next x
next y

get buffer ASIZE MEMORY_FILE1
get name FILENAME 0
string name -= 4
string name += .tga
log name 0 buffer MEMORY_FILE1


edit: redone. should be easier portable to noesis, if you get to set the alpha 0 in that only palette entry.
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

Re: Unheadered (?) TGA and BMP

Post by Acewell »

awesome :D thanks to your script i was able to translate the meat and potatoes to my Noesis python script. :D
so i updated the previous script here to open open those tga and bmp samples :)
viewtopic.php?p=30945#p30945
episoder
Posts: 123
Joined: Fri Oct 27, 2017 7:36 pm

Re: Unheadered (?) TGA and BMP

Post by episoder »

interesting. doesn't wanna download. 0 byte file. and i thought i could learn some noesis stuff. not then.

bug hunt: does the forums break updated file attachements with identical names?
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

Re: Unheadered (?) TGA and BMP

Post by Acewell »

hmm thats strange, i just downloaded the attachment 3 times in a row and they all worked, maybe try again. :)

i am beginning to take some interest in paletted textures now that i have a better understanding
of them thanks to the scripts you share. :D
episoder
Posts: 123
Joined: Fri Oct 27, 2017 7:36 pm

Re: Unheadered (?) TGA and BMP

Post by episoder »

Acewell wrote:i am beginning to take some interest in paletted textures now that i have a better understanding
of them thanks to the scripts you share. :D


yeh. this stuff is neato to puzzle. this alpha key or (color-key) is an old rendering trick. gif files use that too for semi-transparent gifs. how'd you do this script tho? i still can't download the script. could you post the bunch of code lines how you read the bmps palette or the whole file?!?

and... going back in 2017, i've been doing some weird things indeed. this oldschool and console stuff. the resident evil - dead aim (and gits-sac, cavia too) files were probably the sickest to crack with low level assembly. buffer shuffle madness. :D
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

Re: Unheadered (?) TGA and BMP

Post by Acewell »

episoder wrote:i still can't download the script. could you post the bunch of code lines how you read the bmps palette or the whole file?!?

maybe browser cache issue? anyway here is the bmp reading section of the script :)

Code: Select all

    #bmp 
    elif check == 0x8:
        imgWidth = bs.readUInt()
        imgHeight = bs.readUInt()
        num_pals = bs.readUShort()
        alpha_flag = bs.readUByte()
        bs.readByte()
        palette = []
        for i in range(num_pals):
            pal = bs.readUShort()
            red = (pal >> 4) & 0xf0
            green = (pal >> 0) & 0xf0
            blue = (pal << 4) & 0xf0
            palette.append(blue)
            palette.append(green)
            palette.append(red)
            if i != alpha_flag:
                palette.append(0xff)
            else:
                palette.append(0x00)
        palette = bytearray(palette)
        datasize = imgWidth * imgHeight
        bs.seek(len(data) - datasize, NOESEEK_ABS)
        data = bs.readBytes(datasize)
        data = rapi.imageDecodeRawPal(data, palette, imgWidth, imgHeight, 8, "b8 g8 r8 a8")
        texList.append(NoeTexture(rapi.getInputName(), imgWidth, imgHeight, data, noesis.NOESISTEX_RGBA32))



edit
i uploaded the script again, check if it works for you now.
episoder
Posts: 123
Joined: Fri Oct 27, 2017 7:36 pm

Re: Unheadered (?) TGA and BMP

Post by episoder »

nope. not a cache issue. got it now. i wasn't just sure how'd you modify the palette read. i got noesis syntax issues.

Code: Select all

palette = bs.readBytes(num_pals * 2)
for i in range(num_pals):
    short palette[i] |= 0xF000
palette[alpha_flag] &= 0x0FFF
data = rapi.imageDecodeRawPal(data, palette, imgWidth, imgHeight, 8, "b4 g4 r4 a4")

would not work, right? i don't bother trying. lacks the array and short type cast perhaps anyway.

you did it manually too. so... this is clear now. :)