Script-powered graphics converter

Do you know a tool, link or website for working on a specific game files or to help game research? Let's collect them here!
puggsoy
Posts: 161
Joined: Sat Dec 13, 2014 1:01 am

Script-powered graphics converter

Post by puggsoy »

Over time I've made various programs to convert certain graphics formats into a usable form (i.e. PNG). The two most recent examples were for GXT and PNGB/TGAB. I've noticed that it's become a bit tedious, since the majority of the code is similar and I have to recompile every time I change anything. I used to do this with archives as well, but since I started using QuickBMS a while ago it's made it much quicker and easier to extract them (and sharing the script is also easier). So I thought, "why not have a program like QuickBMS but for converting graphics?"

Therefore I am considering making something like this. That way you can make converters for complex graphic files which graphics viewers such as TiledGGD cannot handle easily (or at all). This would be especially useful for formats that may have images displayed in chunks.

An example script may be something like this:

Code: Select all

get SIZE long
get WIDTH short
get HEIGHT short
savepos OFFSET

setformat ARGB32 #this means the pixel data is read as 32-bit ARGB
readpxls IMG OFFSET SIZE WIDTH HEIGHT #stores the image data into an object called IMG
save IMG "myImg.png"

This is just a simple example of how the scripts might work, you can probably figure out what it would do. I would allow custom pixel formats, but there would be presets for common formats like ARGB32. You could do additional things to IMG before saving such as flipping or combining with other images to form a bigger image (I have seen some formats that store images in parts). However as you can see things like reading numbers would be similar to QuickBMS, this would make it relatively easy to learn for people who already use QuickBMS.

I just want to know, do you guys think this is a good idea, and would you find it useful? I think it's good and I would personally use it but it would be nice to have some input and opinions. Suggestions are also welcome :)
Teancum
Posts: 94
Joined: Mon Sep 22, 2014 5:13 pm

Re: Script-powered graphics converter

Post by Teancum »

I love this idea, especially if we can re-inject a texture back into a container. It would have to have the same original attributes (size, height, pixel depth, alpha channel, etc). I don't think anyone needs to go nuts accepting tons of formats for import, but man, there are so many games I'd like to mod textures on.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Script-powered graphics converter

Post by aluigi »

I know that it's not related to the post but, regarding quickbms, there are at least a couple of things many people probably don't know and may be useful while writing complex scripts.

1) callfunction supports arguments, they have the same name of the function followed by "_ARG" + number:

Code: Select all

callfunction TEST 0 "this is the first argument" 2 0x000003 four

startfunction TEST
    print "%TEST_ARG1%"
    print "%TEST_ARG2%"
    print "%TEST_ARG3%"
    print "%TEST_ARG4%"
endfunction


2) quickbms allows to include other scripts and this is a technique that AlphaTwentyThree uses a lot to put some generic "utils" functions in one or more scripts that are loaded in the final script specific for a game, example:

Code: Select all

include "utils_functions.bms"
include "graphic_functions.bms"
get ...


I repeat that this is OT with the topic and quickbms is probably not the best solution for this type of stuff (I'm sure you have experienced difficulties in making graphic converters with bms scripts), but I think there are ways to make this task easier, after all usually it's just a matter of "get" from input and "put" to MEMORY_FILE :)
puggsoy
Posts: 161
Joined: Sat Dec 13, 2014 1:01 am

Re: Script-powered graphics converter

Post by puggsoy »

Yeah, there are ways to do it with QuickBMS, but I've concluded that that usually takes more effort than just making a whole program :P Technically I could probably make a number of intertwining BMS scripts that make it easier but I think a custom program is the best choice.

Thanks for pointing it out anyway, I wasn't aware that you could include external scripts in QuickBMS, that might be useful in the future.

Teancum wrote:I love this idea, especially if we can re-inject a texture back into a container. It would have to have the same original attributes (size, height, pixel depth, alpha channel, etc).

Yes, I would try and make it support reverse conversion using the same script, similar to QuickBMS's reimport feature. I'm not sure how difficult this might be though, most scripts won't handle every single valye in a file's header so you may have to explicitly choose an existing file to use as a base.
Yeah I'm not sure how I'd make it work exactly, but it's definitely a feature I want it to have.
Last edited by puggsoy on Fri Mar 13, 2015 11:17 am, edited 1 time in total.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Script-powered graphics converter

Post by aluigi »

I agree with you that a specific tool just for this task is necessary.

Do you have a specific programming language in mind?

Have you already evaluated if there are other existent solutions?
I mean custom tools and doing the same in pure Python/Ruby/Perl.
puggsoy
Posts: 161
Joined: Sat Dec 13, 2014 1:01 am

Re: Script-powered graphics converter

Post by puggsoy »

The programming language I would use is Haxe; it's the language I use for my existing conversion programs and I think it would work well for this.

To my knowledge there is no program that already does this. I think the closest might be ImageMagick, but its focus is more on complex image manipulation rather than conversion/extraction. From what I can tell, to add a new format you need to either ask the developers to do it or code it in C yourself :?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Script-powered graphics converter

Post by aluigi »

Does Haxe have any runtime dependency?

For example the python/ruby/perl scripts obviously require that the final user has the whole interpreter installed (very annoying), and .net is the same although it's installed by default on Windows but sometimes there are problems with the required version or some components, Java requires JRE installed.
VisualBasic has lot of dependencies (ocx, dll and so on), just like the MFC programs.
puggsoy
Posts: 161
Joined: Sat Dec 13, 2014 1:01 am

Re: Script-powered graphics converter

Post by puggsoy »

Well Haxe can compile to multiple targets (like Flash) but for command-line programs like this I just do it to a native Windows executable. It does require a number of .dll and .ndll files to be packed with it but otherwise it runs natively, it doesn't need you to install any runtime environment or virtual machine.

EDIT: I tested some stuff and it's actually possible to compile so that it needs little or no extra files next to it, so it's just a single .exe. That's handy :)
Xiron
Posts: 104
Joined: Sat Sep 12, 2015 7:09 am

Re: Script-powered graphics converter

Post by Xiron »

Has much progress been done on this since March? I do think it's a great idea which is why I'm interested and asking.
puggsoy
Posts: 161
Joined: Sat Dec 13, 2014 1:01 am

Re: Script-powered graphics converter

Post by puggsoy »

I'm currently very busy with study, however I am trying to spend some time on this when I can. The biggest hurdle is making good and stable script interpretation and implementing stuff like variables, once that's done adding commands and features should go relatively smoothly.

Anyway, it's going a bit slowly right now but once my exams are over in November I will have a lot of time on my hands, and will try and dedicate a large chunk of that to getting this done. I'm personally very excited to finish this since I know it will be useful for myself as well as others.