• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Ralle needs developer help - PNG to BLP1 with JPEG compression

Ralle

Owner
Level 77
Joined
Oct 6, 2004
Messages
10,101
I need some help.

I've been using a tool to create paleted BLP files from PNG for a couple of years now, but I need it to make JPEG BLP files instead as the quality is superior. This is for the Icon Borderiser as well as the embedded version of it when uploading icons.

These days I'm using this tool to create the PNG from BLP, but it does not support generating a BLP.

If someone could make it go reverse, just for PNG -> BLP1 with JPEG encoding, I would be very happy. Even if you just make a separate tool that does exactly that (with similar CLI-like dependencies)

I looked into this tool but it's buggy and the JPEG BLPs it creates are seemingly invalid. However it would be a good starting point if you want to familiarise yourself with Rust in the process of helping me out :).

CC:
@BogdanW3 @ScrewTheTrees @MindWorX @eejin @TriggerHappy @Dr Super Good @Mustang
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
I looked into this tool but it's buggy and the JPEG BLPs it creates are seemingly invalid. However it would be a good starting point if you want to familiarise yourself with Rust in the process of helping me out :).
This certainly seems to be derived from my specs in that it is aware of 1 and 4 bit alpha modes for palleted BLPs. As such it might be a viable option to use such project as a base and then work to debug/fix it rather than trying to write something from scratch.

I think it might be possible to adapt this PHP code by @TriggerHappy (Hive is in PHP) to make it work with creating BLPs.
If I recall, due to limitations with the underlying JPEG APIs it is possible this implementation introduces a magnitude 1 error into the colour components due to losses introduced when dealing with the forced colour space conversions. As far as I am aware there is no work around for this since Imagick does not support the low level access with JPEG files required to process BGRA values directly.
 

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
539
I found the source here.
To compile blpaletter you need to modify common/blp/jpgwrapper.h like this:
Diff:
--- a/common/blp/jpgwrapper.h
+++ b/common/blp/jpgwrapper.h
@@ -5,7 +5,7 @@
        #include <cstring>
        #include <csetjmp>
 
-       #include "libjpeg/jpeglib.h"
+       #include <jpeglib.h>
        #include "../buffer.h"
 
        GLOBAL(bool)ConvertToJpg(Buffer &source, Buffer &target, int width, int height, int bytespp, int quality, bool bottomUp);
And compile it like this:
Bash:
g++ BLPaletter/main.cpp common/blp/jpgwrapper.cpp common/blp/quantizer.cpp -ljpeg -o blpaletter
You of course need to have installed libjpeg-dev or something alike on your machine. It does run but i haven't tested if it actually handles the images correctly. It was originally built against an older libjpeg version.
 
Level 1
Joined
Apr 27, 2023
Messages
2
Seems like you're in a bit of a bind, but fret not, assistance is on the horizon! Upgrading to JPEG BLP files for your Icon Borderiser project could indeed enhance quality. While your current tool falls short, crafting a new one or tweaking an existing tool might just do the trick.

Diving into Rust could be a fruitful endeavor, though tread carefully around those buggy tools! And hey, optimizing those JPEGs for web use is a breeze with jpg compress tools. They'll help keep your file sizes in check without sacrificing image quality.
 
Last edited:
Do any of our Hive contributors have the source code to BLPLab? Maybe it's not related, but in 2012 or so I reached out to its author asking for CLI blp conversion for my model editor project, and he replied back pretty quickly with a blplabcl.exe that was usable for batch conversions, or in my case, for use within my model editor project.

Years later I changed to using DSG's code so that I wouldn't need to invoke sub-processes and instead would convert entirely within one language and one process. But that came with caveats of the issues where certain BLPs would break or whatever. Always seemed like the further back in time we go to get our software, the better it works.

Anyway, if that guy was still around somewhere, maybe he could recompile blplabcl to linux? Perhaps that's crazy talk, but it's a thought.
 
Top