.gtd graphics. Can anyone help?

Discussion in 'NDS - ROM Hacking and Translations' started by jjjewel, Jan 3, 2011.

Jan 3, 2011
  1. jjjewel
    OP

    Member jjjewel GBAtemp Maniac

    Joined:
    Dec 17, 2009
    Messages:
    1,004
    Country:
    United States
    Got stuck with some buttons in a game. They are .gtd files which I believe are some kind of graphic file, or may be just a packed file.

    This is one of the files for an example.

    Download link-->backnormal.gtd

    And this is what the file in the link is supposed to look like in the game.

    [​IMG]
    (It's a screen shot I cut from the game.)

    When I view the file with hex editor, it seems to be like a paint-by-color graphic,
    but I don't know much about graphic formats. I need to edit it and insert it back to the game.
    (I know how to insert files. Now I just need to find a way to view and edit it.)
    So if anyone can help, I'll really appreciate that. [​IMG]
     
  2. FAST6191

    Reporter FAST6191 Techromancer

    pip
    Joined:
    Nov 21, 2005
    Messages:
    21,748
    Country:
    United Kingdom
    I have about half an hour so stream of conciousness is what you will probably get unless I manage to figure out the format.

    Hmm a deceptively large amount of colours (chances are no bit packing/1bpp). I am going to call no compression for the purposes of pulling this apart at least at first, certainly no LZ or huffman that I can see (even the simplest zip compression drops file size dramatically)- packing/mapping techniques are a different matter.

    Looking at the file the first part of it all appears to be colours (starting at 12 hex- 18 dec if you are playing in tiled 2002)- looking at that image you provided and using the data to palette options of crystaltile2 and tiled 2002 would seem to back that one up- a nice bunch of slightly different blues that to my eye are damn near perfect. It might simply start at 10 and have the first entry as transparent.
    Following this logic the image would appear to start at b0 hex (or more likely b4), I do also want to figure out what 0 to F hex counts for (no magic stamp, no apparent pointers or end of file markers)
    Looking at the later parts of the file nothing is high values hex which would seem to indicate a paint by numbers approach as you say. I am assuming we are not in the 16 bit colours range leaving us with 4 or 8 bit- that the first character in any nibble is not above 1 would seem to point to such a thing.

    60x24 pixels is your image there although I am not treating that as a "this is what it is" in the game- order of magnitude sort of thing. Still each tile is usually 8 pixels wide by 8 high which might help later.

    First though I look for patterns likely to be visible in hex
    The outer edges appear to be a grey rather than straight white
    the blue bars on the outside until you get to the corners are solid blue (after that it becomes a pixel mess)
    The inner bar appears line at least until the edges appears to be a solid white line which upon zooming in a lot is not the same as the outer line.

    To this end we are looking for an outer line a single pixel, two repeats and another single pixel line "mirrored" on the opposing side some 16 pixels away. This might see a packing technique (simple repeated tiles in some map somewhere if they go for 4x4 tiles) though if the outer bars can be repeated. In an 8x8 grid I see no repeated tiles which is nice.

    In the actual "text" the right hand side between the top and first character and the top and middle character appears to be a solid lump of light blue (a different blue to the bars).
    In the middle of the first character there should be a run of a single colour too.

    Likewise a hex values count might help things here- despite the eye being awful at pixel level guesswork I am going for it.
    Nicely the dark section appears to be a variety of pixels, the outer bars should be in the top colours, the text lump colour appears to come up more than a few times, the outer grey looks common too.

    Before putting it together though scanning through the images with palette applied seems to indicate a repeating pattern of sorts- not that I have not seen it before when tile editing (shift a few things, tweak a few colours and suddenly the image appears sort of thing) but I would expect to see something at this point.

    I have to run now anyhow- you have something there but I am not sure what.
     
  3. Phoenix Goddess

    Member Phoenix Goddess The Ninja's Protégée

    Joined:
    Apr 25, 2009
    Messages:
    3,810
    Location:
    Away from civilization.
    Country:
    United States
    I spent almost an hour trying to figure out how to get the image to appear, but all I got were the different shades of blue, as well. I couldn't get past this with CT2, but I may have overlooked other things. I can't really figure it out with one file, cause I'm strange like that XD

    However, I agree when FAST says there is something there, but I can't tell what it is, myself.
     
  4. jjjewel
    OP

    Member jjjewel GBAtemp Maniac

    Joined:
    Dec 17, 2009
    Messages:
    1,004
    Country:
    United States
    I'm pretty sure it's exactly the paint-by-numbers approach but I can't think of a way to extract just the image and edit it.

    Here's what I see when I open the file in CT2 and use Data to Palette function from 0x10.

    (Big picture in the spoiler tag)
    Warning: Spoilers inside!

    The first 2 rows in the palette grids on the left are exactly the colors I need.
    Then the other parts are my image.

    If you look at the hex code from 0x50, that's probably where I need to apply the colors.
    Ex. 00 will match the first palette color 0000 which is black.
    Then 01 will be the second palette color FF7F which is white, etc.
    (The values from 0x50 until the end never exceed Hex 20 which corresponds to the number of colors in the palette (32 which is = Hex 20).
    So I'm pretty sure I got it right but I don't know how to apply the palette to the hex code and extract it as a picture. T_T)

    By the way, anyone has any idea how CT2 generate the color from 2 bytes hex?
    Ex. from the codes from 0x10 to 0x4F, FF7F will come to white, 717F is light blue, etc.
    How do I convert the code to color like CT2 did?

    (I know how to write simple visual Basic program, so if you have any idea how to make a program to generate the color, please help.
    If it's in different programming language, please explain a bit more in details, because I'm such a noob. [​IMG])
     
  5. FAST6191

    Reporter FAST6191 Techromancer

    pip
    Joined:
    Nov 21, 2005
    Messages:
    21,748
    Country:
    United Kingdom
    GBA and DS colour palettes are simple enough

    16 bits (2 bytes)- 5 bits per colour, 1 bit to waste (first value).

    Order is BGR (there is an undocumented RGB function of the GBA and some of the subsystems do odd things if memory serves)

    There are many palettes available for images (4bpp- 16 colours per palette but as said palette can contain any colours it tends not to trouble things) or one combined palette (8bpp- 256 colours from a palette)- the OAM handles all this though so once you figure out encoding method you are sorted.
    The main thing to note is regardless of what the first colour in the palette is (any valid number) the game will consider it transparent.

    http://nocash.emubase.de/gbatek.htm#lcdcolorpalettes
    http://www.cs.rit.edu/~tjh8300/CowBite/Cow...ware%20Overview

    If you want a more worked example then http://gbatemp.net/index.php?showtopic=733...t=0&start=0 has one (end of first post for now at least- I have a plan to sort that sticky out when I get some time).

    Most tile editors will be able to export a palette though.

    The trouble phoenixgoddess27 and I faced though was not palettes but trying to get the image to decode- this is why I was looking for the patterns in the borders and between the character. Even with a messed up palette and a bit of tweaking I should still be able to see something like
    Warning: Spoilers inside!

    Granted image formats are not always simple- they can be odd pixel sizes (one of nice features of crystaltile2), can have headers per tile (another nice feature of crystaltile2) or even complex animations (deufeufeu's site is now down but phoenix wright was a great example of this). It might even be the case that that file/fomat is a combined palette and image layout rather than image itself- the DS sdk has tile, layout and palette files separately.
     
  6. Tricky Upgrade

    Newcomer Tricky Upgrade Member

    Joined:
    Aug 14, 2010
    Messages:
    27
    Location:
    Mozambique
    Country:
    Mozambique
    I think it uses this format: XBBBBBGGGGGRRRRR (taken from Link), where the first byte is XBBBBBGG, the second byte is GGGRRRRR and BGR bits are the RGB values of the color (i don't know what X is).
    I'll give you my code later and explanation once I find it, but it's in C#.
     
  7. jjjewel
    OP

    Member jjjewel GBAtemp Maniac

    Joined:
    Dec 17, 2009
    Messages:
    1,004
    Country:
    United States
    Thank you so much. There's a this NCGR graphic from another part of the game. I believe this one and the one in .gtd file should come out to be very similar (if not the same) picture but in different file format.

    (This is 800x zoom with 8x8 tiles.)
    Warning: Spoilers inside!

    Thank you so much. I'll be looking forward to it. [​IMG]

    My idea is like the program has to read the palette data (from 0x10 to 0x4F) and store them as color array.
    Then it should read the later part from 0x50 until the end and apply color from color array to each code value.
    Then it will draw each dot on a canvas one by one. (I think all the graphics I need to edit have 32 pixels for the width.)
    After that, there should be a way to export the graphic to .bmp or .png, or something.
    And then I need another part of the program to convert the edited .bmp or .png to .gtd.

    (I'm going to find some reference on graphics for Visual Basic too.)
     
  8. trap15

    Newcomer trap15 Newbie

    Joined:
    Jan 4, 2011
    Messages:
    1
    Country:
    United States
    I was linked to this thread earlier today, and I bothered to get around to writing up a tool to decode these images.
    Here's a tool written in C that does it: https://github.com/SquidMan/gtdparse
    You'll need to compile it yourself, and you need libGD.
    Go nuts!

    EDIT: If you want a re-encoder, I can do that too, just give me a heads up.
     
  9. jjjewel
    OP

    Member jjjewel GBAtemp Maniac

    Joined:
    Dec 17, 2009
    Messages:
    1,004
    Country:
    United States
    Thank you so much. But I'm probably too inexperienced for this. T_T

    I downloaded gd-latest-win32 (I believed it's the libGD you mentioned, right?) and then devcpp to compile C program. I copied the gd.h from gd program to devcpp's "include" folder and then compiled (executed) the .c file I downloaded from your link. There were errors when I compiled it.

    Here's the error;
    Warning: Spoilers inside!

    So if anyone could help guide me on how to run this or tell me what I did wrong, I'll really appreciate that.

    Or is it possible that you can make a .exe program so I can run it?

    Also, this is a little embarrassing, but I have no clue how I can eventually select my gtd file and run it. Do I have to use command line or something? I hope someone could give me some more instruction on this, please.
     
  10. trap15

    Newcomer trap15 Newbie

    Joined:
    Jan 4, 2011
    Messages:
    1
    Country:
    United States
    You need to also move the libgd.a (or something along those lines) into lib/
    And yes, you need to run it from command line. just type gtdparse, and it'll tell you how to use it.
     
  11. jjjewel
    OP

    Member jjjewel GBAtemp Maniac

    Joined:
    Dec 17, 2009
    Messages:
    1,004
    Country:
    United States
    Thank you very much. I still couldn't compile the program but I tried writing mine in Visual Basic based on your codes and it worked. Thank you for your neat comments in the codes as well. [​IMG]
     

Share This Page