Page 1 of 1

Request: Small change to LumpMOD desperately needed!

PostPosted: Mon Jan 16, 2017 11:21 am
by Kroc
Hello all.

In simple terms, I need the help of anybody who knows a bit of C (I don't) to make a small modification to lumpmod (a program to manage the contents of WAD files). I am a programmer (just not C) so can explain precisely what's needed.

I've made DOOM-crusher, a utility to maximally compress PK3/WAD files. The problem with WAD files is that the lumpmod cannot tell me what file-type a lump is without extracting to disk first. The act of extracting every lump and working out the file-type is taking a *really* long time.

Lumpmod has a `list` option that lists the contents of a WAD, and with `-v` lists in each lump as index, name and length.
Here is a link to the exact code location that does this: https://github.com/STJr/SRB2/blob/maste ... #L595-L597

I only need to identify PNG and JPG files and this can be done with just the first four bytes of each lump. What I need is for the (above mentioned) line to also output "PNG"/"JPG" for lumps recognised as such or "LMP" for anything else.

A PNG file can easily be identified if bytes 2-4 read "PNG"
A JPG file has the first two bytes read 0xFF, 0xD8

If anybody could please make this change I'd greatly appreciate it and you'd be contributing to a tool to help all DOOM developers.

Kind regards,
Kroc Camen.

Re: Request: Small change to LumpMOD desperately needed!

PostPosted: Mon Jan 16, 2017 6:45 pm
by Gez
That tool is part of SRB2, which is actively developed, so why not raise an issue with your demand?


Also, can't you use SLADE 3? It's not a command-line application but when it opens an archive it identifies all lumps (see all known data formats here). You could just browse through the entry list to find out which lumps are PNGs or JPGs.

Re: Request: Small change to LumpMOD desperately needed!

PostPosted: Tue Jan 17, 2017 1:08 am
by wildweasel
I suspect he needs something that can be easily automated in a batch utility, so SLADE is likely not that useful for this.

Re: Request: Small change to LumpMOD desperately needed!

PostPosted: Tue Jan 17, 2017 6:18 am
by _mental_
You need to replace lines 595 and 596 in lumpmod.c with the following code:
Code: Select allExpand view
                if(verbose) {
                    const char *format = "LMP";
                    unsigned char *data = curlump->cl->data;
                    if(data && curlump->cl->len > 16)
                        if(data[0] == 0x89 && data[1] == 0x50
                                && data[2] == 0x4E && data[3] == 0x47)
                            format = "PNG";
                        else if(data[0] == 0xFF && data[1] == 0xD8
                                && data[2] == 0xFF)
                            format = "JPG";
                    printf("%5i %-8s %7li %s\n", i,
                        get_lump_name(curlump->cl), curlump->cl->len, format);
                }

Whole modified file is here.

From OP it's not clear what's you need, compiled binary or source code.

Re: Request: Small change to LumpMOD desperately needed!

PostPosted: Tue Jan 17, 2017 4:13 pm
by Kroc
Thank you, thank you one and all for your help.

Gez wrote:That tool is part of SRB2, which is actively developed, so why not raise an issue with your demand?


It's only a dependency that they've included in their repo; not their own source. I can still raise an issue and they may very well consider it, and I hadn't thought to do that so thank you for suggesting it.

wildweasel wrote:I suspect he needs something that can be easily automated in a batch utility, so SLADE is likely not that useful for this.


This is correct. It's unfortunate that SLADE has no command-line control. Automating of DOOM formats is surprisingly difficult.

_mental_ wrote:From OP it's not clear what's you need, compiled binary or source code.


Thank you so very much for providing the fix needed. I can read C but can't write it especially when I don't understand the program. I've compiled a number of projects before as part and parcel of being a developer using a wide variety of tools so I'm just setting up cygwin now to try compile this -- I hope that works.

A special thank you again as this simple modification will reduce 20+ minutes of lump shifting into less than a second!