imageworsener
imageworsener copied to clipboard
ImageWorsener corrupts image when used as optimization tool in FileOptimizerFull
Hello,
I'm the owner of DeveImageOptimizerWPF which uses https://nikkhokkho.sourceforge.io/static.php?page=FileOptimizer to optimize images. (But in parallel with some additional image verification after the optimization has completed).
When optimizing a certain .bmp image though the resulting image that was created by imagew was not equal to the input image:
Original | Optimized |
---|---|
![]() |
![]() |
The command that was used is:
imagew.exe -noresize -zipcmprlevel 9 -outfmt bmp -compress "rle" "MonoGameIcon.bmp" "MonoGameIconOriginal_Optimized.bmp"
I've also attached the Original bmp and Optimized bmp files in a zip file (can't attach them directly as .bmp).
MonoGameIcon.bmp is a 32-bit bmp with alpha, and the thumbnail fails to reflect that (transparency shown as black).
I'm not positive but I don't think 8 bit bmp's support transparency so it would have to flatten it, and no background color was specified.
Hmmm that could be the reason. All imaging tools I've used do display the image as expected though so I would hope this tool could have the same result.
Thanks for the report. I think it's technically working as intended, but I can see there's sort of an issue here.
Your source image is in BMPv5 format, which supports transparency. By default, Imagew only writes the more portable BMPv3 format, which does not support transparency. So there's a problem.
If you want to only write portable BMPv3, then transparency has to be sacrificed. You could use "-bkgd 000", for example.
If you want to only write BMPv5, use "-opt bmp:version=5", and then it will "work". But unfortunately, it will unconditionally use BMPv5 format, which is probably not what you want.
I don't think there's a way to get Imagew to intelligently choose the BMP version. Maybe there should be. Though I'm not sure exactly how it should work. Should it depend on whether the image has transparency, or on the BMP version of the source image, or what?
Hey @jsummers , thanks for your response :).
I think the way it should work is that it that it should use BMPv3 in all cases except if a feature is used in the original that can only be saved in the v5 format.
I'm not sure if there's more features like transparency that BMPv3 doesn't support.
Let me know what you think 😄
Edit: I could imagine the code being something like:
outputFormat = BMPv3;
if (inputImage.UsesFeatureABC)
{
outputFormat = BMPv4;
}
if (inputImage.UsesTransparency)
{
outputFormat = BMPv5;
}
if (inputImage.UsesFeatureXYZ)
{
outputFormat = BMPv5;
}
@jsummers, Do you think this is something that could be implemented possibly?
I'm thinking that I'll add an option, probably "-opt bmp:version=auto", that will cause BMPv5 to be written if the image has transparency, otherwise BMPv3. Just need to figure out how to do that.
I'm not sure that making it the default behavior is a good idea, for compatibility reasons. Then again, maybe BMPv5 is so widely supported nowadays that it could be done. I dunno.
The thing is that if the original image had transparency it must've been v5 so why not have the output v5 as well.
Input formats other than BMP have to be accounted for.
While I am considering having Imagew remember whether the original image was in a BMPv5 file, that would be quirky, and not very consistent with the rest of the software. I'd prefer to avoid things like that.
Ok makes sense. Let me know if you've made progress on this. I can then let Nikkho from file optimizer know so he can update the cli command.
I added the "-opt bmp:version=auto" feature (commit daa9283699). If you can test it, please do.
Could you provide me with a windows compiled executable? I can then test if it fixes the problem.
@jsummers , I did some playing around with compiling the source code myself but having to manually include all the library's etc. took a bit too much time so I gave up. Do you think you could help me provide a compiled .exe file so I can try if the issue is resolved?
Try the attached file. imagew-test41.zip
Just verified it and it works!
Thank you for the fix.
@jsummers, can you maybe release a new official version 1.3.5 for imageworsener?
I know, it's overdue. I'll make a new release within a week or so.
Thanks :)