mvi Posted August 16, 2009 Share Posted August 16, 2009 This tutorial will cover the basic structure of R16 and TGAs. It draws from my R16 specification here and the TGA specification hereR16sR16s contain a series of images and some related data. They comprise a 29 byte header, followed by the image data.The image data is 15 bit colour, although stored with 16 bits to make it two nice round bytes. Each two bytes of the image data represents a pixel in the format XRRRRRGG GGGBBBBB, where X is disregarded and each colour channel is allocated 5 bits and therefore 32 combinations each and 32768 possible colours from the RGB channels.To calculate the length of this image data you simply take the width and height specified in the header, then multiply these by two. (Image data length in bytes = width * height * 2)The width and height of the R16 image are at an offset of 1 and 5 respectively, they're stored as standard unsigned 32 bit integers. For example, if we wanted to calculate the length of the image data in a tileset, looking at the width and height in offset 1 and 5 would give us a width and height of 32 pixels. Ergo, the image data length is 2048 bytes and starts at 0x1D. TGAsTGAs store a lot of optional data which I won't go into, such as the developer area, extension area, file footer and some other things. All we're interested here is the TGA header and the image data which follows it. The header is stored as:1 byte - ID field length1 byte - Colour map type1 byte - Image type5 bytes - Colour map specifictaion10 bytes - Image specifictaionThe TutorialFor this tutorial I will be using a tileset (BLOX****.R16), so open it up in your hex editor. Now let's use the first image out of this R16, so check the offsets 1 and 5 for the width and height. These will show a hex value of 0x20 in a little endian format for both. 0x20 is 32 in decimal, so we know the width and height is 32 pixels. Now select the byte at 0x1D. You can calculate the length of the image data by multiplying the width (32) by the height (32) by 2 (so 32 * 32 * 2 = 2048). So select 2048 bytes including current position in your hex editor (in XVI32, you simply select 0x1D, go to Edit->Block <n> chars, and enter the decimal 2048).Next copy this image data to clipboard, (again in XVI32, this is a simple Ctrl-C or Edit->Clipboard->Copy).Now let's create a new file (in XVI32 use File->New), now using the TGA header spec as a guideline:1. Add 00 for the ID field length, as ID fields are optional and we have no use of one.2. Add 00 for the Colour Map type, as we're not using a colour map3. Add 02 for the image type, as we are using an uncompressed true colour specification4. Add 00 00 00 00 00 for the colour map specification, since we're not using one5. Add 00 00 00 00 for the start of the image specification (this sets the image origin to the corner 0 by 0)6. Now we have to add the image width and height, this is stored as a Unsigned Int 16 here (unlike the Int 32 in the R16), so add 20 00 20 007. As the penultimate part of the image specification add 10 (this is 16 in decimal and indicates 16 bit colour (yes I know it's 15 bit!))8. As the final byte of the image specification add 01 for the image descriptor byte (I don't know why)This will give you a header of 00 00 02 00 00 00 00 00 00 00 00 00 20 00 20 00 10 01Now after this, paste in the image data from clipboard (take care not to overwrite the last byte of the header, you may need to create a byte after the header to paste onto.) Done! Now open this up in whatever TGA viewer you have on your PC, remember that both Photoshop and Mozilla Firefox can open up TGAs, but that Windows probably won't be able to on its own.I can include XVI32 screenshots as well if people want. Quote Link to comment Share on other sites More sharing options...
D2k Sardaukar Posted August 16, 2009 Share Posted August 16, 2009 Cool, thanks for this tutorial. I tried it, but it does not work. I just changed the first lines with hex editor into "00 00 02 00 00 00 00 00 00 00 00 00 20 00 20 00 10 01", but irfanview does not read it (after saving as 123.tga).Perhaps a screenshot of XVI32? :)edit: perhaps I should read the tut better first... where is the 0x20? There is no x in the program at all...? Quote Link to comment Share on other sites More sharing options...
mvi Posted August 16, 2009 Author Share Posted August 16, 2009 0x signifies hex values, 0x20 is equal to 32 in decimal. I highly recommend using XVI32 for hex editing, it's very lightweight, fast and powerful (oh and free.) I'll screenshot the process in XVI32, and upload that sometime today. Quote Link to comment Share on other sites More sharing options...
Gruntlord6 Posted August 17, 2009 Share Posted August 17, 2009 http://www.pendriveapps.com/hxd-portable-hex-editor/ Quote Link to comment Share on other sites More sharing options...
mvi Posted August 17, 2009 Author Share Posted August 17, 2009 http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm Quote Link to comment Share on other sites More sharing options...
Gruntlord6 Posted August 17, 2009 Share Posted August 17, 2009 http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htmLINK WARS!http://www.sierra-madre.com/images/logo_ITSON_jpg.jpg Quote Link to comment Share on other sites More sharing options...
mvi Posted August 17, 2009 Author Share Posted August 17, 2009 I'll concede this war now, on account of not wanting to send this topic to be locked. Quote Link to comment Share on other sites More sharing options...
Gruntlord6 Posted August 17, 2009 Share Posted August 17, 2009 I'll concede this war now, on account of not wanting to send this topic to be locked.It will be neutral I suppose, hopefully the peace will be sealed with the release of a new map. Quote Link to comment Share on other sites More sharing options...
D2k Sardaukar Posted August 17, 2009 Share Posted August 17, 2009 Irfanview now opens the tga, so it sorta worked. ;D But it is full with different colours and no real image is there to see. What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
mvi Posted August 17, 2009 Author Share Posted August 17, 2009 I'll post some screenshots today, or possibly a video tutorial. However this will be depicting XVI32. Quote Link to comment Share on other sites More sharing options...
mvi Posted August 17, 2009 Author Share Posted August 17, 2009 Well that video quality came out awfully. But hopefully it might help you. CLICKY Quote Link to comment Share on other sites More sharing options...
mvi Posted August 17, 2009 Author Share Posted August 17, 2009 Alright, since that quality was so awful I've uploaded the original video to my permanent section of my site here. It's 25 meg, but is good quality. The audio is still a second or two out of sync with the video unfortunately, but just think of it as me saying what to do before I show it lol Quote Link to comment Share on other sites More sharing options...
mvi Posted August 18, 2009 Author Share Posted August 18, 2009 Quadruple post, my apologies to the staff.Okay, so I've started on a program which exports all the images in the tileset to tga. I was a little surprised when the program didn't hang at all when I hit export, but it's the start of an R16 editor.Edit: Have just converted R16 images to BMP too now, BMPs have a longer header but aside from the BMP header being 54 bytes compared to the TGAs 18 byte header, it's the exact same. I'm going to try adding this support to the program I wrote.Edit 2: BMP support now added to the program. Just exported a tileset to generate 1600 files (800 bmps, 800 tgas), does it in the blink of an eye. Quote Link to comment Share on other sites More sharing options...
D2k Sardaukar Posted August 18, 2009 Share Posted August 18, 2009 Thanks for the tutorial, I got it working. What I did wrong was copying from 0x1D, oops. I also see now that there are more images in one .r16.Great that the program is working and so fast. You wrote it in C#? Does it have a GUI? Quote Link to comment Share on other sites More sharing options...
mvi Posted August 18, 2009 Author Share Posted August 18, 2009 Yeah, right now you just click a button which brings up the standard Windows open file window, select which R16, then hit Export. Quote Link to comment Share on other sites More sharing options...
mvi Posted August 18, 2009 Author Share Posted August 18, 2009 Some complications with loading the other R16 files, as they don't appear to store all the images in an R16 as 16 bit, which is just damn silly. Quote Link to comment Share on other sites More sharing options...
D2k Sardaukar Posted August 18, 2009 Share Posted August 18, 2009 yeah, same problem here I think, I tried the cursor r16 and changed to 14 pixel by 14 pixel (0x0E), but it displayed the image weird. Like it where two cursors. I did only copy 14*14*2 bits. Quote Link to comment Share on other sites More sharing options...
D2k Sardaukar Posted March 26, 2013 Share Posted March 26, 2013 I have been looking at your tutorial again and it works perfectly for BLOX****.R16, but for all the other r16 is fails. I even wrote a little python to export all the images (proof that is works for BLOX****): What I did discover when looking at the other r16 files is that you actually need 00 00 02 00 00 00 00 00 00 00 00 00 20 00 20 00 10 20 The 20 on the end makes sure that the origin is at the left top. What is very annoying is that it looks so simple (the MOUSE.R16), but I can't figure it out: See looks simple, but I get this: Quote Link to comment Share on other sites More sharing options...
THE AQIB Posted March 27, 2013 Share Posted March 27, 2013 is ther someway to pack it back into an r16 file?? Quote Link to comment Share on other sites More sharing options...
D2k Sardaukar Posted March 27, 2013 Share Posted March 27, 2013 For the BLOX****.R16 you can do that with "Dune 2000 Tile Set Editor" from mvi, for the other .r16 itg crashes while loading. Quote Link to comment Share on other sites More sharing options...
THE AQIB Posted March 27, 2013 Share Posted March 27, 2013 total commander with a plugin game archive something can help you in extracting data.r16 files... Total commander free is only trial... Try searching for cracked version on net for usin it for long tym.. 1 Quote Link to comment Share on other sites More sharing options...
Gruntlord6 Posted March 27, 2013 Share Posted March 27, 2013 total commander with a plugin game archive something can help you in extracting data.r16 files... Total commander free is only trial... Try searching for cracked version on net for usin it for long tym..Is it compatible with d2k? Quote Link to comment Share on other sites More sharing options...
D2k Sardaukar Posted March 27, 2013 Share Posted March 27, 2013 Is it compatible with d2k?According to the website it is: http://forrox.narod.ru/readme.htm#suppform and I can confirm that it extracts the r16 files correctly to the TGA format. Quote Link to comment Share on other sites More sharing options...
Gruntlord6 Posted March 27, 2013 Share Posted March 27, 2013 According to the website it is: http://forrox.narod.ru/readme.htm#suppform and I can confirm that it extracts the r16 files correctly to the TGA format.Interesting, thanks for the find. Quote Link to comment Share on other sites More sharing options...
mvi Posted March 27, 2013 Author Share Posted March 27, 2013 Any chance of screenshots of the extracted contents on some R16s? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.